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, vote for it on google moderator or contact me on our forum

Author: bm082975

Leave a Reply

Your email address will not be published. Required fields are marked *