Skip to content
This repository has been archived by the owner on Dec 1, 2017. It is now read-only.

WIP: working to minimize (or at least enumerate) the ways that CCDA generation loses data fidelity #127

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 16 additions & 3 deletions lib/core/xml.js
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,16 @@ Core.XML = (function () {
var elsByTag = function (tag) {
return wrapElement(this.el.getElementsByTagName(tag));
};


var unescapeSpecialChars = function(s) {
if (!s) { return s; }
return s.replace(/&lt;/g, '<')
.replace(/&gt;/g, '>')
.replace(/&amp;/g, '&')
.replace(/&quot;/g, '"')
.replace(/&apos;/g, "'");
};


/*
Expand All @@ -158,7 +168,10 @@ Core.XML = (function () {
var attr = function (attrName) {
if (!this.el) { return null; }
var attrVal = this.el.getAttribute(attrName);
return attrVal || null;
if (attrVal) {
return unescapeSpecialChars(attrVal);
}
return null;
};

/*
Expand Down Expand Up @@ -207,7 +220,7 @@ Core.XML = (function () {
contentId = this.el.childNodes[1].getAttribute('value');

} else {
return textContent;
return unescapeSpecialChars(textContent);
}

if (contentId && contentId[0] === '#') {
Expand All @@ -218,7 +231,7 @@ Core.XML = (function () {
}
}

return textContent;
return unescapeSpecialChars(textContent);
};


Expand Down
83 changes: 64 additions & 19 deletions lib/generators/ccda_template.ejs
Original file line number Diff line number Diff line change
Expand Up @@ -95,9 +95,13 @@
<%} else { %>
<ethnicGroupCode nullFlavor="NI" />
<%} %>
<% if (codes.reverseRole(bb.demographics.guardian.relationship) && bb.demographics.guardian.name.family) { %>
<% if (bb.demographics.guardian.name.family) { %>
<guardian>
<code code="<%=: codes.reverseRole(bb.demographics.guardian.relationship) %>" displayName="<%= bb.demographics.guardian.relationship %>" codeSystem="2.16.840.1.113883.5.111" codeSystemName="HL7 Role code"/>
<% if (codes.role(bb.demographics.guardian.relationship_code)) { -%>
<code code="<%=: bb.demographics.guardian.relationship_code %>" displayName="<%= bb.demographics.guardian.relationship %>" codeSystem="2.16.840.1.113883.5.111" codeSystemName="HL7 Role code"/>
<% } else if (codes.reverseRole(bb.demographics.guardian.relationship)) { -%>
<code code="<%=: codes.reverseRole(bb.demographics.guardian.relationship) %>" displayName="<%= bb.demographics.guardian.relationship %>" codeSystem="2.16.840.1.113883.5.111" codeSystemName="HL7 Role code"/>
<% } -%>
<addr use="HP">
<!-- HP is "primary home" from codeSystem 2.16.840.1.113883.5.1119 -->
<%-: tagHelpers.addressTags(bb.demographics.guardian.address) %>
Expand Down Expand Up @@ -366,15 +370,17 @@
</playingEntity>
</participantRole>
</participant>
<entryRelationship typeCode="SUBJ" inversionInd="true">
<observation classCode="OBS" moodCode="EVN">
<templateId root="2.16.840.1.113883.10.20.22.4.28"/>
<!-- Alert status observation template -->
<code code="33999-4" codeSystem="2.16.840.1.113883.6.1" codeSystemName="LOINC" displayName="Status"/>
<statusCode code="completed"/>
<value xsi:type="CE" code="55561003" codeSystem="2.16.840.1.113883.6.96" displayName="<%= bb.allergies[i].status %>"/>
</observation>
</entryRelationship>
<% if (bb.allergies[i].status) { -%>
<entryRelationship typeCode="SUBJ" inversionInd="true">
<observation classCode="OBS" moodCode="EVN">
<templateId root="2.16.840.1.113883.10.20.22.4.28"/>
<!-- Alert status observation template -->
<code code="33999-4" codeSystem="2.16.840.1.113883.6.1" codeSystemName="LOINC" displayName="Status"/>
<statusCode code="completed"/>
<value xsi:type="CE" code="55561003" codeSystem="2.16.840.1.113883.6.96" displayName="<%= bb.allergies[i].status %>"/>
</observation>
</entryRelationship>
<%} -%>
<entryRelationship typeCode="MFST" inversionInd="true">
<observation classCode="OBS" moodCode="EVN">
<templateId root="2.16.840.1.113883.10.20.22.4.9"/>
Expand Down Expand Up @@ -757,7 +763,7 @@
</effectiveTime>
<routeCode <%-: bb.visit_medications[i].route | hl7Code %> />
<% if (bb.visit_medications[i].dose_quantity.value) { %>
<doseQuantity value="<%= bb.visit_medications[i].dose_quantity.value %>" unit="<%= bb.visit_medications[i].dose_quantity.unit %>"/>
<doseQuantity value="<%= bb.visit_medications[i].dose_quantity.value %>" <% if (bb.visit_medications[i].dose_quantity.unit) { %> unit="<%= bb.visit_medications[i].dose_quantity.unit %>" <% } %> />
<%} %>
<% if (bb.visit_medications[i].rate_quantity.value) { %>
<rateQuantity value="<%= bb.visit_medications[i].rate_quantity.value %>" unit="<%= bb.visit_medications[i].rate_quantity.unit %>"/>
Expand Down Expand Up @@ -856,7 +862,7 @@
<% } %>
<routeCode <%-: bb.medications[i].route | hl7Code %> />
<% if (bb.medications[i].dose_quantity.value) { %>
<doseQuantity value="<%= bb.medications[i].dose_quantity.value %>" unit="<%= bb.medications[i].dose_quantity.unit %>"/>
<doseQuantity value="<%= bb.medications[i].dose_quantity.value %>" <% if (bb.medications[i].dose_quantity.unit) { %> unit="<%= bb.medications[i].dose_quantity.unit %>" <% } %> />
<%} %>
<% if (bb.medications[i].rate_quantity.value) { %>
<rateQuantity value="<%= bb.medications[i].rate_quantity.value %>" unit="<%= bb.medications[i].rate_quantity.unit %>"/>
Expand All @@ -878,6 +884,18 @@
<manufacturerOrganization/>
</manufacturedProduct>
</consumable>
<% if (bb.medications[i].vehicle.name) { -%>
<participant typeCode="CSM">
<participantRole classCode="MANU">
<templateId root="2.16.840.1.113883.10.20.22.4.24"/>
<code code="412307009" displayName="drug vehicle" codeSystem="2.16.840.1.113883.6.96"/>
<playingEntity classCode="MMAT">
<code <%-: bb.medications[i].vehicle | hl7Code %> />
<name><%= bb.medications[i].vehicle.name %></name>
</playingEntity>
</participantRole>
</participant>
<% } %>
<entryRelationship typeCode="RSON">
<observation classCode="OBS" moodCode="EVN">
<templateId root="2.16.840.1.113883.10.20.22.4.19"/>
Expand Down Expand Up @@ -993,7 +1011,11 @@
<effectiveTime>
<low <%-: bb.problems[i].date_range.start | hl7Date %> />
</effectiveTime>
<value xsi:type="CD" <%-: bb.problems[i] | hl7Code %> />
<value xsi:type="CD" <%-: bb.problems[i] | hl7Code %> >
<% if (bb.problems[i].translation && bb.problems[i].translation.code) { -%>
<translation <%-: bb.problems[i].translation | hl7Code %> />
<% } -%>
</value>
<entryRelationship typeCode="REFR">
<observation classCode="OBS" moodCode="EVN">
<!-- Problem status observation template -->
Expand All @@ -1003,6 +1025,17 @@
<value xsi:type="CD" code="<%=: codes.reverseProblemStatus(bb.problems[i].status) %>" codeSystem="2.16.840.1.113883.6.96" displayName="<%= bb.problems[i].status %>" codeSystemName="SNOMED CT"/>
</observation>
</entryRelationship>
<% if (bb.problems[i].age) { -%>
<entryRelationship typeCode="SUBJ" inversionInd="true">
<observation classCode="OBS" moodCode="EVN">
<templateId root="2.16.840.1.113883.10.20.22.4.31"/>
<!-- Age observation template -->
<code code="445518008" codeSystem="2.16.840.1.113883.6.96" displayName="Age At Onset"/>
<statusCode code="completed"/>
<value xsi:type="PQ" value="<%= bb.problems[i].age %>" unit="a"/>
</observation>
</entryRelationship>
<% } %>
</observation>
</entryRelationship>
</act>
Expand Down Expand Up @@ -1173,7 +1206,7 @@
<!-- Result organizer template -->
<templateId root="2.16.840.1.113883.10.20.22.4.1"/>
<id root="7d5a02b0-67a4-11db-bd13-0800200c9a66"/>
<code code="<%=bb.results[i].code %>" displayName="<%=bb.results[i].name %>" codeSystem="2.16.840.1.113883.6.96" codeSystemName="SNOMED CT"/>
<code <%-: bb.results[i] | hl7Code %> />
<statusCode code="completed"/>

<% for (var j=0; j<bb.results[i].tests.length; j++) { %>
Expand Down Expand Up @@ -1201,7 +1234,17 @@
<targetSiteCode/>
<referenceRange>
<observationRange>
<text></text>
<% if (bb.results[i].tests[j].reference_range.text) { -%>
<text><%= bb.results[i].tests[j].reference_range.text %></text>
<% } else if (bb.results[i].tests[j].reference_range.low_value &&
bb.results[i].tests[j].reference_range.high_value) { -%>
<value xsi:type="IVL_PQ">
<low value="<%= bb.results[i].tests[j].reference_range.low_value %>"
unit="<%= bb.results[i].tests[j].reference_range.low_unit %>"/>
<high value="<%= bb.results[i].tests[j].reference_range.high_value %>"
unit="<%= bb.results[i].tests[j].reference_range.high_unit %>"/>
</value>
<% } -%>
</observationRange>
</referenceRange>
</observation>
Expand Down Expand Up @@ -1300,7 +1343,7 @@
<!-- Encounter Activities -->
<!-- ******** Encounter activity template ******** -->
<id root="2a620155-9d11-439e-92b3-5d9815ff4de8"/>
<code <%-: bb.encounters[i] | hl7Code %> >
<code <%-: bb.encounters[i] | hl7Code %> <% if (bb.encounters[i].code_system_version) { %>codeSystemVersion="<%= bb.encounters[i].code_system_version %>"<% } %> >
<% if (bb.encounters[i].translation) { -%>
<translation <%-: bb.encounters[i].translation | hl7Code %> />
<% } -%>
Expand Down Expand Up @@ -1413,7 +1456,9 @@
<templateId root="2.16.840.1.113883.10.20.22.4.20"/>
<!-- ** Instructions Template ** -->
<code <%-: bb.immunizations[i].education_type | hl7Code %> />
<text><%= bb.immunizations[i].instructions%></text>
<% if (bb.immunizations[i].instructions) { -%>
<text><%= bb.immunizations[i].instructions%></text>
<% } -%>
<statusCode code="completed"/>
</act>
</entryRelationship>
Expand Down Expand Up @@ -1499,7 +1544,7 @@
<templateId root="2.16.840.1.113883.10.20.22.4.26"/>
<!-- Vital signs organizer template -->
<id root="c6f88320-67ad-11db-bd13-0800200c9a66"/>
<code code="46680005" codeSystem="2.16.840.1.113883.6.96" codeSystemName="SNOMED -CT" displayName="Vital signs"/>
<code code="46680005" codeSystem="2.16.840.1.113883.6.96" codeSystemName="SNOMED CT" displayName="Vital signs"/>
<statusCode code="completed"/>
<effectiveTime <%-: bb.vitals[i].date | hl7Date %> />

Expand Down
2 changes: 2 additions & 0 deletions lib/parsers/c32/demographics.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ Parsers.C32.demographics = function (c32) {

el = patient.tag('guardian');
var guardian_relationship = el.tag('code').attr('displayName'),
guardian_relationship_code = el.tag('code').attr('code'),
guardian_home = el.tag('telecom').attr('value');

el = el.tag('guardianPerson').tag('name');
Expand Down Expand Up @@ -80,6 +81,7 @@ Parsers.C32.demographics = function (c32) {
family: guardian_name_dict.family
},
relationship: guardian_relationship,
relationship_code: guardian_relationship_code,
address: guardian_address_dict,
phone: {
home: guardian_home
Expand Down
13 changes: 9 additions & 4 deletions lib/parsers/c32/medications.js
Original file line number Diff line number Diff line change
Expand Up @@ -95,10 +95,15 @@ Parsers.C32.medications = function (c32) {
route_code_system = el.attr('codeSystem'),
route_code_system_name = el.attr('codeSystemName');

// participant => vehicle
el = entry.tag('participant').tag('code');
var vehicle_name = el.attr('displayName'),
vehicle_code = el.attr('code'),
// participant/playingEntity => vehicle
el = entry.tag('participant').tag('playingEntity');
var vehicle_name = el.tag('name').val();

el = el.tag('code');
// prefer the code vehicle_name but fall back to the non-coded one
// (which for C32s is in fact the primary field for this info)
vehicle_name = el.attr('displayName') || vehicle_name;
var vehicle_code = el.attr('code'),
vehicle_code_system = el.attr('codeSystem'),
vehicle_code_system_name = el.attr('codeSystemName');

Expand Down
2 changes: 2 additions & 0 deletions lib/parsers/ccda/demographics.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ Parsers.CCDA.demographics = function (ccda) {

el = patient.tag('guardian');
var guardian_relationship = el.tag('code').attr('displayName'),
guardian_relationship_code = el.tag('code').attr('code'),
guardian_home = el.tag('telecom').attr('value');

el = el.tag('guardianPerson').tag('name');
Expand Down Expand Up @@ -81,6 +82,7 @@ Parsers.CCDA.demographics = function (ccda) {
family: guardian_name_dict.family
},
relationship: guardian_relationship,
relationship_code: guardian_relationship_code,
address: guardian_address_dict,
phone: {
home: guardian_home
Expand Down
12 changes: 8 additions & 4 deletions lib/parsers/ccda/medications.js
Original file line number Diff line number Diff line change
Expand Up @@ -82,10 +82,14 @@ Parsers.CCDA.medications = function (ccda) {
route_code_system = el.attr('codeSystem'),
route_code_system_name = el.attr('codeSystemName');

// participant => vehicle
el = entry.tag('participant').tag('code');
var vehicle_name = el.attr('displayName'),
vehicle_code = el.attr('code'),
// participant/playingEntity => vehicle
el = entry.tag('participant').tag('playingEntity');
var vehicle_name = el.tag('name').val();

el = el.tag('code');
// prefer the code vehicle_name but fall back to the non-coded one
vehicle_name = el.attr('displayName') || vehicle_name;
var vehicle_code = el.attr('code'),
vehicle_code_system = el.attr('codeSystem'),
vehicle_code_system_name = el.attr('codeSystemName');

Expand Down
2 changes: 1 addition & 1 deletion lib/parsers/ccda/procedures.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ Parsers.CCDA.procedures = function (ccda) {
performer_dict.phone = phone;

// participant => device
el = entry.tag('participant').tag('code');
el = entry.template('2.16.840.1.113883.10.20.22.4.37').tag('code');
var device_name = el.attr('displayName'),
device_code = el.attr('code'),
device_code_system = el.attr('codeSystem');
Expand Down
Loading