diff --git a/commands/openFDA/openFDA.js b/commands/openFDA/openFDA.js index 6968809..6b04c13 100644 --- a/commands/openFDA/openFDA.js +++ b/commands/openFDA/openFDA.js @@ -1,5 +1,5 @@ const Discord = require('discord.js'); -const { findDrug } = require('../../helpers/OpenFDA') +const { findDrug, adverseEvent } = require('../../helpers/OpenFDA') module.exports = { @@ -7,7 +7,7 @@ module.exports = { aliases: ['openFDA'], description: 'fids drug based on proprietary name', async execute(message, args) { - if(args[0] == "find" || args[0] == "Find"){ + if(args[0].toLowerCase() == "find"){ let res = await findDrug(args[1]) if(res == 'Couldnt find the Medicine Specified'){ message.reply(res) @@ -16,7 +16,7 @@ module.exports = { .setColor('#0099ff') .setTitle('Name: '+res.results[0].proprietary_name) .addFields( - { name:"application_number_or_citation", value: res.results[0].application_number_or_citation}, + {name:"application_number_or_citation", value: res.results[0].application_number_or_citation}, {name:"product_type", value: res.results[0].product_type}, {name:"marketing_start_date", value: res.results[0].marketing_start_date}, {name:"package_ndc", value: res.results[0].package_ndc}, @@ -29,6 +29,9 @@ module.exports = { .setFooter('heh nice'); message.reply(embed) } + }else if(args[0].toLowerCase() == "adverseevent"){ + let res = await adverseEvent(args[1]) + console.log(res) } }, diff --git a/helpers/OpenFDA.js b/helpers/OpenFDA.js index 1a43289..e9ef375 100644 --- a/helpers/OpenFDA.js +++ b/helpers/OpenFDA.js @@ -1,12 +1,28 @@ const https = require('https') const got = require('got') - +const apikey= process.env.APIKEY async function findDrug(drug){ let query = "proprietary_name:"+drug let res try{ - res = await got("https://api.fda.gov/other/nsde.json?api_key=IbMkYkBOkuTRvQZDaXgfjxYP2wzDtySmg8477KvA&search="+query,{ + res = await got("https://api.fda.gov/other/nsde.json?api_key="+apikey+"&search="+query,{ + dnsLookupIpVersion: 'ipv4' + }); + res = res.body + res = JSON.parse(res) + } catch(err){ + console.log(err) + res = 'Couldnt find the Medicine Specified' + } + return res +} +async function adverseEvent(drug){ + //https://api.fda.gov/other/event.json?search=patient.drug.activesubstance.activesubstancename:Prozac + let query = "patient.drug.medicinalproduct:"+drug + let res + try{ + res = await got("https://api.fda.gov/drug/event.json?api_key="+apikey+"&search="+query,{ dnsLookupIpVersion: 'ipv4' }); res = res.body @@ -18,7 +34,7 @@ async function findDrug(drug){ return res } - module.exports = { - findDrug + findDrug, + adverseEvent }