How to parse Allergy Contents of a NIST validated CCD?

Hi Everyone,

Here is another Continuity of Care Document post. In this blog post I will provide you the code that can we used to parse the Allergy Section of a NIST validated CCD. This CCD will is a NIST standard validated CCD. You can refer this link for the NIST validation tool

Allergy Section:

An Allergy section in the CCD document will contain the following details:

  1. Allergy substance (Allergy causing substance – Medication for patients)
  2. Reaction for Allergy (What reaction the substance causes)
  3. Start date of the allergy
  4. End date of the allergy

 

/* Parse Allergy Section of CCD */
var component = msg[‘component’][‘structuredBody’][‘component’];
// Loop through the <component>
for (i = 0; i < component.length(); i++) {
// 2.16.840.1.113883.10.20.22.4.30 – OID for Allergy section
var getAllergyTemplateId = component[i][‘section’][‘templateId’][‘@root’].toString();
if ((getAllergyTemplateId != null) && (getAllergyTemplateId != ”)) {
// Patient will be allergic to various substance (multiple <entry>)
var entries = component[i][‘section’][‘entry’];
for (j = 0; j < entries.length(); j++) {
// <participant> contains the substance causing allergy
var participant = entries[j][‘act’][‘entryRelationship’][‘observation’][‘participant’];
// <participant><playingEntity> may occur in multiple places so check for ”
if (((participant != null) || (participant != undefined)) && (participant[‘participantRole’][‘playingEntity’][‘name’].toString() != ”)) {
substaceForAllergy = participant[‘participantRole’][‘playingEntity’][‘name’].toString();
logger.debug(“Allergy Substance : ” + substaceForAllergy);
}
var entryRelations = entries[j][‘act’][‘entryRelationship’][‘observation’][‘entryRelationship’];
// Within each <entry> there will be multiple <entryRelationship>
for (k = 0; k < entryRelations.length(); k++) {
if ((entryRelations[k][‘observation’] != null) || (entryRelations[k][‘observation’] != undefined)) {
// 2.16.840.1.113883.10.20.22.4.28 – OID specific for Allergy Status
if (entryRelations[k][‘observation’][‘templateId’][‘@root’].toString() == ‘2.16.840.1.113883.10.20.22.4.28’) {
allergyStatus = entryRelations[k][‘observation’][‘value’][‘@displayName’].toString();
logger.debug(“reaction Status: ” + allergyStatus);
}
// 2.16.840.1.113883.10.20.22.4.9 – OID specific for Allergy Reaction
if ((entryRelations[k][‘observation’][‘text’].toString() != ”) && (entryRelations[k][‘observation’][‘templateId’][‘@root’].toString() == “2.16.840.1.113883.10.20.22.4.9”)) {
// Fetches <text> along with <reference>
var getAllergyReaction = entryRelations[k][‘observation’][‘text’].toString();
// remove <reference>
var splitReferenceTag = getAllergyReaction.split(‘<‘);
// remove <text xmlns=”> namespace
var splitTextTag = splitReferenceTag[1].split(‘>’);
// Get only reaction for specific allergy
reactionForAllergy = splitTextTag[1];
logger.debug(“Allergy Reaction : ” + reactionForAllergy);
// Allergy start Date
if (entryRelations[k][‘observation’][‘effectiveTime’][‘low’][‘@value’].toString() != ”) {
var reactionStartDate = entryRelations[k][‘observation’][‘effectiveTime’][‘low’][‘@value’].toString();
//logger.debug(“reaction Start Date: ” + reactionStartDate);
}
// Allergy End Date
if (entryRelations[k][‘observation’][‘effectiveTime’][‘high’][‘@value’].toString() != ”) {
var reactionEndDate = entryRelations[k][‘observation’][‘effectiveTime’][‘high’][‘@value’].toString();
//logger.debug(“reaction End Date: ” + reactionEndDate);
}
}
}
}
}
}
}

Leave a Comment