Skip to content

Instantly share code, notes, and snippets.

@joshbooker
Last active February 3, 2016 16:25
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save joshbooker/ed5ddad079dc8f71bb1b to your computer and use it in GitHub Desktop.
Save joshbooker/ed5ddad079dc8f71bb1b to your computer and use it in GitHub Desktop.
/*
https://jsfiddle.net/7tt7fw04/14/
Let's make a function to call RXNorm 'Related' endpoint to get ingredients as seen here:
http://mor.nlm.nih.gov/download/rxnav/RxNormAPIREST.html#uLink=RxNorm_REST_getRelatedByRelationship
The request url: for Plavix (rxcui: 174742) is this:
https://rxnav.nlm.nih.gov/REST/rxcui/174742/related?rela=tradename_of+has_precise_ingredient
*/
//make sure jquery is working - required for ajax
$("#message").text("jQuery Loaded");
//set base url
var uri = "https://rxnav.nlm.nih.gov/REST/rxcui/"
//our function
var getPreciseIngredient = function(rxcui){
var requestUri = uri + rxcui +
"/related.json?rela=tradename_of+has_precise_ingredient"
//alert(requestUri);
$.ajax({
url: requestUri
})
.done(function( data ) {
$("#label").text("Ingredients:");
var ingredients = "";
data.relatedGroup.conceptGroup.forEach(function(c){
ingredients += c.conceptProperties[0].name + "\r\n";
});
alert(ingredients);
$("#message").text(ingredients);
})
.fail(function(jqXHR, textStatus, errorThrown) {
alert( "error" + ": " + textStatus + ": " + errorThrown );
})
.always(function() {
alert( "complete" );
});
};
var result = getPreciseIngredient(174742);
/*
https://jsfiddle.net/r8vcxt53/4/
Let's make a function to call RXNorm 'Interactions' endpoint to as seen here:
http://mor.nlm.nih.gov/download/rxnav/InteractionAPIREST.html#uLink=Interaction_REST_findInteractionsFromList
In the following example, the interactions between Diflucan 50 mg oral tablet (RxCUI=207106), Zocor 40 mg oral tablet (RxCUI=152923) and bosentan 125 mg oral tablet (RxCUI=656659) are returned.
https://rxnav.nlm.nih.gov/REST/interaction/list.json?rxcuis=207106+152923+656659
*/
//make sure jquery is working - required for ajax
$("#message").text("jQuery Loaded");
//set base url
var uri = "https://rxnav.nlm.nih.gov/REST/interaction/list.json"
//our function
var getInteractions = function(rxcuis){
var requestUri = uri + "?rxcuis=" + rxcuis
alert(requestUri);
$.ajax({
url: requestUri
})
.done(function( data ) {
$("#label").text("Interactions:");
var interactions = "";
data.fullInteractionTypeGroup[0].fullInteractionType.forEach(function(i){
interactions += i.interactionPair[0].description + "\r\n";
});
alert(interactions);
$("#message").text(interactions);
})
.fail(function(jqXHR, textStatus, errorThrown) {
alert( "error" + ": " + textStatus + ": " + errorThrown );
})
.always(function() {
alert( "complete" );
});
};
var result = getInteractions("207106+152923+656659");
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment