rxNorm Drug API: The Daily REST library entry for Excel and GAScript

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

 

Requesting the format in the xmlHttp header

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
The equivalent update for Google Apps Script is
  var options = {} ;
  if (accept) options = {"headers" : { "Accept" : accept}};
  this.xResult = UrlFetchApp.fetch(this.xHtml,options);

 

Where accept has been set in the library entry. The full code for the restLibrary is here.
        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"));
}

The rest library is itself implemented as REST API and can be queried like this.
For more stuff like this, visit the ramblings site or the associated blog. If you have suggestion for particular API or contact me on our forum
About brucemcp 225 Articles
I am a Google Developer Expert and decided to investigate Google Apps Script in my spare time. The more I investigated the more content I created so this site is extremely rich. Now, in 2019, a lot of things have disappeared or don’t work anymore due to Google having retired some stuff. I am however leaving things as is and where I came across some deprecated stuff, I have indicated it. I decided to write a book about it and to also create videos to teach developers who want to learn Google Apps Script. If you find the material contained in this site useful, you can support me by buying my books and or videos.