Skip to content

Commit

Permalink
Vitera_CCDA_SMART_Sample medications now match
Browse files Browse the repository at this point in the history
  • Loading branch information
au2 committed Aug 29, 2014
1 parent 5d5f80d commit 242d3e9
Show file tree
Hide file tree
Showing 4 changed files with 88 additions and 61 deletions.
14 changes: 11 additions & 3 deletions lib/generator/ccda/lib/templating_functions.js
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,9 @@ var name = function (xmlDoc, name, use) {
xmlDoc = xmlDoc.node('given', name[0]["middle"][0]).parent();
if (name[0]["last"])
xmlDoc = xmlDoc.node('family', name[0]["last"]).parent();
if (name[0].suffix) {
xmlDoc = xmlDoc.node('suffix', name[0].suffix).parent();
}
xmlDoc = xmlDoc.parent();
return xmlDoc;
} else {
Expand All @@ -200,6 +203,9 @@ var name = function (xmlDoc, name, use) {
xmlDoc = xmlDoc.node('given', name["middle"][0]).parent();
if (name["last"])
xmlDoc = xmlDoc.node('family', name["last"]).parent();
if (name.suffix) {
xmlDoc = xmlDoc.node('suffix', name.suffix).parent();
}
xmlDoc = xmlDoc.parent();
return xmlDoc;
}
Expand Down Expand Up @@ -416,9 +422,11 @@ var manufacturedProduct = function (xmlDoc, product, ref, sec) {
xmlDoc = xmlDoc.node('lotNumberText', product["lot_number"]).parent();
}
xmlDoc = xmlDoc.parent() // end manufacturedMaterial
xmlDoc = xmlDoc.node('manufacturerOrganization')
.node('name', product["manufacturer"]).parent()
.parent();
if (product.manufacturer) {
xmlDoc = xmlDoc.node('manufacturerOrganization')
.node('name', product.manufacturer).parent()
.parent();
}
} else {
xmlDoc = xmlDoc.node('id')
.attr({nullFlavor: "UNK"}).parent()
Expand Down
130 changes: 75 additions & 55 deletions lib/generator/ccda/templates/medications.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,33 @@
var libxmljs = require("libxmljs");
var libCCDAGen = require("../lib/templating_functions.js");

var updateIndication = function(xmlDoc, indication) {
if (indication) {
xmlDoc = xmlDoc.node('entryRelationship') // Indication
.attr({typeCode: "RSON"})
.node('observation').attr({classCode: "OBS"})
.attr({moodCode: "EVN"})
.node('templateId')
.attr({root: "2.16.840.1.113883.10.20.22.4.19"}).parent();
xmlDoc = libCCDAGen.id(xmlDoc, indication.identifiers);
xmlDoc = libCCDAGen.code(xmlDoc, indication.code).parent();
xmlDoc = xmlDoc.node('statusCode').attr({code: "completed"}).parent();
xmlDoc = libCCDAGen.effectiveTime(xmlDoc, libCCDAGen.getTimes(indication.date_time));
xmlDoc = libCCDAGen.value(xmlDoc, indication.value, "CD");
}
}

var administrationAttrs = function(entry) {
var attrs = {classCode: "SBADM"};
var status = entry.status;
if (status === 'Prescribed') {
attrs.moodCode = 'INT'
} else if (status === 'Completed') {
attrs.moodCode = 'EVN';
}
return attrs;
}

module.exports = function (data, codeSystems, isCCD, CCDxml) {

var doc = new libxmljs.Document();
Expand All @@ -11,27 +38,30 @@ module.exports = function (data, codeSystems, isCCD, CCDxml) {
for (var i = 0; i < data.length; i++) {
var time = libCCDAGen.getTimes(data[i]["date_time"]);
xmlDoc = xmlDoc.node('entry').attr({typeCode: "DRIV"})
.node('substanceAdministration').attr({classCode: "SBADM"}).attr({moodCode: "EVN"})
.node('substanceAdministration').attr(administrationAttrs(data[i]))
.node('templateId').attr({root: "2.16.840.1.113883.10.20.22.4.16"}).parent(); // medication activity
xmlDoc = libCCDAGen.id(xmlDoc, data[0]["identifiers"]);
xmlDoc = xmlDoc.node('text', data[i]["product"] ? data[i]["product"]["unencoded_name"] : undefined)
xmlDoc = libCCDAGen.id(xmlDoc, data[i]["identifiers"]);
xmlDoc = xmlDoc.node('text', data[i].sig)
.node('reference').attr({value: "#MedSec_1"}).parent()
.parent()
.node('statusCode').attr({code: 'completed'}).parent();
xmlDoc = libCCDAGen.effectiveTime(xmlDoc, time);
xmlDoc = xmlDoc.node('effectiveTime')
.attr({"xsi:type": "PIVL_TS"})
.attr({institutionSpecified: "true"})
.attr({operator: "A"});
var period;
if (period = data[i]["administration"] ? data[i]["administration"]["interval"] ? data[i]["administration"]["interval"]["period"] : undefined : undefined) {
xmlDoc = xmlDoc.node('period').attr({value: period["value"]})
.attr({unit: period["unit"]}).parent()
}
xmlDoc = xmlDoc.parent()

if (data[i].administration && data[i].administration.interval) {
xmlDoc = xmlDoc.node('effectiveTime')
.attr({"xsi:type": "PIVL_TS"})
.attr({institutionSpecified: "true"})
.attr({operator: "A"});
var period;
if (period = data[i]["administration"] ? data[i]["administration"]["interval"] ? data[i]["administration"]["interval"]["period"] : undefined : undefined) {
xmlDoc = xmlDoc.node('period').attr({value: period["value"]})
.attr({unit: period["unit"]}).parent()
}
xmlDoc = xmlDoc.parent()
}
xmlDoc = libCCDAGen.medication_administration(xmlDoc, data[i]["administration"]);
xmlDoc = libCCDAGen.consumable(xmlDoc, data[i].product, data[i].product.unencoded_name);
xmlDoc = libCCDAGen.performerRevised(xmlDoc, data[i]["performer"], {});
xmlDoc = libCCDAGen.performerRevised(xmlDoc, data[i].performer, {});

xmlDoc = xmlDoc.node('participant').attr({typeCode: "CSM"})
.node('participantRole').attr({classCode: "MANU"}) // drug vehicle
Expand All @@ -45,37 +75,28 @@ module.exports = function (data, codeSystems, isCCD, CCDxml) {
xmlDoc = xmlDoc.node('name', data[i]["drug_vehicle"] ? data[i]["drug_vehicle"]["name"] : "").parent()
.parent()
.parent()
.parent()
.node('entryRelationship') // Indication
.attr({typeCode: "RSON"})
.node('observation').attr({classCode: "OBS"})
.attr({moodCode: "EVN"})
.node('templateId')
.attr({root: "2.16.840.1.113883.10.20.22.4.19"}).parent();
xmlDoc = libCCDAGen.id(xmlDoc, data[i]["indication"] ? data[i]["indication"]["identifiers"] : undefined);
xmlDoc = xmlDoc.node('code')
.attr({code: "404684003"})
.attr({displayName: "Finding"})
.attr({codeSystem: codeSystems["SNOMED CT"][0]})
.attr({codeSystemName: "SNOMED CT"}).parent()
.node('statusCode')
.attr({code: "completed"}).parent();
xmlDoc = libCCDAGen.effectiveTime(xmlDoc, libCCDAGen.getTimes(data[i]["indication"] ? data[i]["indication"]["date_time"] : time));
xmlDoc = libCCDAGen.value(xmlDoc, data[i]["indication"] ? data[i]["indication"]["value"] : undefined, "CD");
xmlDoc = xmlDoc.parent()
.parent()
.parent();

updateIndication(xmlDoc, data[i].indication);

.node('entryRelationship').attr({typeCode: "REFR"}) // Supply
xmlDoc = xmlDoc.node('entryRelationship').attr({typeCode: "REFR"}) // Supply
.node('supply').attr({classCode: "SPLY"}).attr({moodCode: "INT"})
.node('templateId').attr({root: "2.16.840.1.113883.10.20.22.4.17"}).parent()
.node('id').attr({nullFlavor: "NI"}).parent()
.node('statusCode').attr({code: "completed"}).parent();
if (data[i].supply && data[i].supply.date_time) {
xmlDoc = libCCDAGen.effectiveTime(xmlDoc, libCCDAGen.getTimes(data[i].supply.date_time), undefined, "IVL_TS");
}
xmlDoc = xmlDoc.node('repeatNumber').attr({value: "1"}).parent()
.node('quantity').attr({value: "75"}).parent()
.node('product');
if (data[i].supply) {
if (data[i].supply.repeatNumber) {
xmlDoc = xmlDoc.node('repeatNumber').attr({value: data[i].supply.repeatNumber}).parent();
}
if (data[i].supply.quantity) {
xmlDoc = xmlDoc.node('quantity').attr({value: data[i].supply.quantity}).parent();
}
}

xmlDoc = xmlDoc.node('product');
xmlDoc = libCCDAGen.manufacturedProduct(xmlDoc, data[i]["product"], '#MedSec_1', 'MSO');
xmlDoc = xmlDoc.parent();
xmlDoc = libCCDAGen.performerRevised(xmlDoc, undefined, {
Expand All @@ -88,18 +109,23 @@ module.exports = function (data, codeSystems, isCCD, CCDxml) {
"templateId_in": undefined
});
xmlDoc = xmlDoc.node('author')
.node('time').attr({nullFlavor: "UNK"}).parent()
.node('assignedAuthor');

if (data[i].supply && data[i].supply.author && data[i].supply.author.date_time) {
xmlDoc = libCCDAGen.effectiveTime(xmlDoc, libCCDAGen.getTimes(data[i].supply.author.date_time), 'time');
} else {
xmlDoc = xmlDoc.node('time').attr({nullFlavor: "UNK"}).parent()
}

xmlDoc = xmlDoc.node('assignedAuthor');
xmlDoc = libCCDAGen.id(xmlDoc, data[i].supply && data[i].supply.author ? data[i].supply.author.identifiers : undefined);
xmlDoc = xmlDoc.node('addr').attr({nullFlavor: "UNK"}).parent()
.node('telecom').attr({nullFlavor: "UNK"}).parent()
.node('assignedPerson')
.node('name')
.node('prefix', "Dr.").parent()
.node('given', "Henry").parent()
.node('family', 'Seven').parent()
.parent()
.parent()
.node('assignedPerson');

if (data[i].supply.author && data[i].supply.author.name) {
xmlDoc = libCCDAGen.name(xmlDoc, data[i].supply.author.name);
}
xmlDoc = xmlDoc.parent()
.parent()
.parent()
xmlDoc = libCCDAGen.entryRelationship(xmlDoc, data[i]["instructions"], 'act', 'SUBJ'); // Instructions
Expand All @@ -118,15 +144,9 @@ module.exports = function (data, codeSystems, isCCD, CCDxml) {
.node('product');
xmlDoc = libCCDAGen.manufacturedProduct(xmlDoc, data[i]["product"], '#MedSec_1', "MD");
xmlDoc = xmlDoc.parent();
xmlDoc = libCCDAGen.performerRevised(xmlDoc, undefined, {
"id": "2.16.840.1.113883.19.5.9999.456",
"extension": "2981823",
"addr": "generic",
"tel": undefined,
"repOrg": "generic",
"assignedP": "generic",
"templateId_in": undefined
});
if (data[i].dispense && data[i].dispense.performer) {
xmlDoc = libCCDAGen.performerRevised(xmlDoc, data[i].dispense.performer);
}
xmlDoc = xmlDoc.parent()
.parent()
xmlDoc = libCCDAGen.precondition(xmlDoc, data[i]["precondition"]);
Expand Down
3 changes: 1 addition & 2 deletions lib/parser/ccda/sections/medications.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,14 +31,13 @@ var exportMedicationsSection = function (version) {
*/
var MedicationInterval = component.define("MedicationInterval")
.fields([
["xsiType", "0..1", "./@xsi:type"],
["phase", "0..1", "./h:phase", shared.EffectiveTime],
["period", "0..1", "./h:period", shared.PhysicalQuantity],
["alignment", "0..1", "./@alignment"],
["frequency", "0..1", "./@institutionSpecified", Processor.asBoolean],
["event", "0..1", "./h:event/@code", shared.SimpleCode("2.16.840.1.113883.5.139")],
["event_offset", "0..1", "./h:offset", shared.EventOffset]
]).cleanupStep(cleanup.removeField('xsiType'))
]);

var MedicationAdministration = component.define("MedicationAdministration")
.fields([
Expand Down
2 changes: 1 addition & 1 deletion test/generator-ccda/test-generator-ccda.js
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,6 @@ describe('parse generate parse generate', function () {
delete result.errors;
delete result2.errors;

assert.deepEqual(result2.data.results, result.data.results);
assert.deepEqual(result2.data.medications, result.data.medications);
});
});

0 comments on commit 242d3e9

Please sign in to comment.