Sending cURL to OpenFDA Returns Drug Interaction to Side Effects. Those who still uses Microsoft Windows, they may install cURL for Windows. Here is Basics on OpenFDA API to Fetch Drug Details as JSON Response.
OpenFDA API to Fetch Drug Details as JSON : Official Documentation
In older publications, we talked about JSON, API and some drug related API as resources. Official help can be found at :
1 | https://open.fda.gov/api/reference/ |
StackExhance has kind of unofficial support :
---
1 | https://opendata.stackexchange.com/questions/tagged/openfda |
OpenFDA API to Fetch Drug Details as JSON : Example
You can open this URL on browser :
1 | https://api.fda.gov/drug/label.json/?search=brand_name:augmentin |
Basic example with cURL on OS X and GNU/Linux can be this with search against the brand Augmentin :
1 | curl -s https://api.fda.gov/drug/label.json/?search=brand_name:augmentin |
With cURL, we can do the same in a practical way :
1 | curl -s https://api.fda.gov/drug/label.json/?search=brand_name:augmentin > augmentin.html |
If you open that augmentin.html
file, it will be somewhat human readable file. In OS X, simply running open augmentin.html
will do the trick.
OpenFDA API to Fetch Drug Details as JSON : Example With PHP
As PHP is one of the most commonly used language, here is an example PHP script with OpenFDA’s official example with an example query, which searches for adverse events in the drug/event endpoint. This query searches for records listing a non steroidal anti-inflammatory drug and returns a count of the most frequently reported patient reactions. Search for records where openfda.pharm_class_epc
(pharmacologic class) contains non steroidal anti-inflammatory drug
, count the field patient.reaction.reactionmeddrapt
(patient reactions) :
1 2 3 4 5 6 7 8 9 10 11 | <?php $ch = curl_init('https://api.fda.gov/drug/event.json?search=patient.drug.openfda.pharm_class_epc:"nonsteroidal+anti-inflammatory+drug"&count=patient.reaction.reactionmeddrapt.exact'); curl_exec($ch); if(!curl_errno($ch)) { $info = curl_getinfo($ch); echo 'Took ' . $info['total_time'] . ' seconds to send a request to ' . $info['url']; } curl_close($ch); ?> |
If the file is saved as fda1.php
, it is possible to run php fda1.php
command from terminal to check the PHP script. This is too basic example. We are not sanitizing JSON output with pretty print. You can create a PHP script and ultimately render data as HTML table. You can copy-paste the JSON output in this web service to view as table and get an idea what you are going to do :
1 | http://chris.photobooks.com/json/default.htm |