Get rxNorm drug data into Excel and Google Apps Script
Aside from being a little specialized, today’s API is another quite unusual one. Normally apis allow you select the format of the output through a URI parameter, but
http://rxnav.nlm.nih.gov/RxNormAPI.html needs you specify it in the GET headers of your request. More about that later. This a single query API, populating multiple rows in a spreadsheet based on a query you provide. You just name the columns to match any data you want to retrieve and go. Here’s the results of query on the drug Amoxil. This example can be found in the cDataSet.xlsm and downloaded from here
These are the changes that were made in the code to support the need to specify the output format in the header.This API requires that the output format is specified in the header through the accept parameter. The code looks like this. The full code for the updated cBrowser class can be found here.
If accept <> vbNullString Then oHttp.SetRequestHeader "Accept", accept End If
var options = {} ; if (accept) options = {"headers" : { "Accept" : accept}}; this.xResult = UrlFetchApp.fetch(this.xHtml,options);
With .add("rxNorm drugs") .add "restType", erSingleQuery .add "url", "http://rxnav.nlm.nih.gov/REST/drugs?name=" .add "results", "drugGroup.conceptgroup.2.conceptProperties" .add "treeSearch", True .add "ignore", vbNullString .add "accept", "application/json" End With
And the execution code looks like this
Public Sub testrxNormDrug() generalQuery "rxNorm Drugs", "rxNorm Drugs", _ InputBox("Enter your rxNorm Drug name query") End Sub
and for Google apps script
function testrxNormDrug() { mcpher.generalQuery ("rxNorm Drugs", "rxNorm Drugs", mcpher.InputBox("Enter your rxNorm Drug name query")); }