USCDI – RxNorm Code – Allergy / Medication (Mirth API)
In this example – I’m trying to call an GET API, where we provide a drug name and we get an RxNorm code back.
Now, what is a point of doing this activity?.
- In real-time most EHR system’s have different code compatible with Drugs, not just RxNorm Codes. Or even if they provide the support for the RxNorm – Hospital’s those use the EHR might be using a local code system so they might not even use RxNorm.
- But imagine a scenario where your creating a CCDA document and your building an Allergy Section on the CCDA XML and the EHR is sending you the Drug name but not the corresponding durg’s code.
- In the middle of an XML generation code you basically need to call another function that will fetch you the code and you will insert that into your XML that your building.
Mirth Javascript Code
function getRxNormCodeBasedOnName(drugName){
var url = new java.net.URL('https://rxnav.nlm.nih.gov/REST/rxcui.xml?name=' + drugName);
var conn = url.openConnection();
conn.setRequestMethod('GET');
var inputStream = conn.getInputStream();
var streamReader = new java.io.InputStreamReader(inputStream);
var respStream = new java.io.BufferedReader(streamReader);
var buffer = new java.lang.StringBuffer();
var line = null;
while ((line = respStream.readLine()) != null) {
buffer.append(line + '\n');
}
respStream.close();
var parseRxNormID = new XML(buffer.toString());
var rxnormId = parseRxNormID.idGroup.rxnormId.toString();
logger.debug('rxnormId ->>> '+rxnormId);
return rxnormId.toString();
}
How to use in code
Create a variable as allergy_code and call this function you just created. Make sure that you’re URL encoding the Drug Name you pass as a parameter.
For example – If you want to get the RxNorm code of the Drug “Penicillin G”, you will call the above function Like this
var allergy_code = getRxNormCodeBasedOnName(encodeURI('Penicillin G'));
logger.debug('allergy_code ->>> '+allergy_code);