diff --git a/lib/bbutil/translate.js b/lib/bbutil/translate.js index fafe1f1..ecf3ebc 100644 --- a/lib/bbutil/translate.js +++ b/lib/bbutil/translate.js @@ -3,6 +3,22 @@ var bbm = require("blue-button-meta"); var codeSystems = bbm.CCDA.codeSystems; +var OIDs = require("../../node_modules/blue-button/lib/parser/ccda/oids.js"); + +exports.codeName = function (OID) { + return function (input) { + var obj = OIDs[OID]; + for (var key in obj.table) { + obj.table[obj.table[key]] = key; + } + return { + "displayName": input, + "code": obj.table[input], + "codeSystem": OID, + "codeSystemName": obj.name + }; + }; +}; exports.code = function (input) { var result = {}; @@ -109,7 +125,7 @@ exports.telecom = function (input) { return result.length === 0 ? null : result; }; -exports.name = function (input) { +var nameSingle = function (input) { var given = null; if (input.first) { given = [input.first]; @@ -124,3 +140,13 @@ exports.name = function (input) { suffix: input.suffix }; }; + +exports.name = function (input) { + if (Array.isArray(input)) { + return input.map(function (e) { + return nameSingle(e); + }); + } else { + return nameSingle(input); + } +}; diff --git a/lib/immunizations.js b/lib/immunizations.js index b0ed129..e180c3d 100644 --- a/lib/immunizations.js +++ b/lib/immunizations.js @@ -5,6 +5,9 @@ var libCCDAGen = require("../lib/templating_functions.js"); var bbm = require("blue-button-meta"); var sec_entries_codes = bbm.CCDA.sections_entries_codes["codes"]; +var js2xml = require('./templates/js2xml'); +var entryLevel = require('./templates/entryLevel'); + module.exports = function (data, codeSystems, isCCD, CCDxml) { var doc = new libxmljs.Document(); var xmlDoc = libCCDAGen.header_v2(!isCCD ? doc : CCDxml, "2.16.840.1.113883.10.20.22.2.2", @@ -39,50 +42,53 @@ module.exports = function (data, codeSystems, isCCD, CCDxml) { }); } } - sa.node('templateId').attr({ - root: "2.16.840.1.113883.10.20.22.4.52" - }); - libCCDAGen.id(sa, data[i]["identifiers"]); + //sa.node('templateId').attr({ + // root: "2.16.840.1.113883.10.20.22.4.52" + //}); + //libCCDAGen.id(sa, data[i]["identifiers"]); - sa.node('text').node('reference').attr({ - value: "#immun" + (i + 1) - }); - sa.node('statusCode').attr({ - code: 'completed' - }); - if (data[i].date_time) { - libCCDAGen.effectiveTime(sa, data[i].date_time, undefined, 'IVL_TS'); - } - if (data[i].sequence_number || (data[i].sequence_number === "")) { // allow empty string for now, workaround for c32 parser - sa.node('repeatNumber').attr({ - value: data[i].sequence_number - }); - } + //sa.node('text').node('reference').attr({ + // value: "#immun" + (i + 1) + //}); + //sa.node('statusCode').attr({ + // code: 'completed' + //}); + //if (data[i].date_time) { + // libCCDAGen.effectiveTime(sa, data[i].date_time, undefined, 'IVL_TS'); + //} + //if (data[i].sequence_number || (data[i].sequence_number === "")) { // allow empty string for now, workaround for c32 parser + // sa.node('repeatNumber').attr({ + // value: data[i].sequence_number + // }); + //} - libCCDAGen.routeCode(sa, data[i].administration, true); - if (data[i].administration && data[i].administration.body_site) { - libCCDAGen.code(sa, data[i].administration.body_site, 'approachSiteCode'); - } - libCCDAGen.doseQuantity(sa, data[i].administration); - libCCDAGen.consumable(sa, data[i].product, "#immi" + (i + 1)); - libCCDAGen.performerRevised(sa, data[i].performer, {}); - if (data[i].instructions) { - var instERSetting = { - templateId: "2.16.840.1.113883.10.20.22.4.20", - inversionInd: "true" - }; - libCCDAGen.entryRelationship(sa, data[i].instructions, 'act', 'SUBJ', '#immunSect', instERSetting); - } - if (data[i].refusal_reason) { - var rrData = { - code: libCCDAGen.reverseTable("2.16.840.1.113883.5.8", data[i].refusal_reason) - }; - var instRRSetting = { - templateId: "2.16.840.1.113883.10.20.22.4.53", - id: true - }; - libCCDAGen.entryRelationship(sa, rrData, 'observation', 'RSON', undefined, instRRSetting); - } + //libCCDAGen.routeCode(sa, data[i].administration, true); + //if (data[i].administration && data[i].administration.body_site) { + // libCCDAGen.code(sa, data[i].administration.body_site, 'approachSiteCode'); + //} + //libCCDAGen.doseQuantity(sa, data[i].administration); + + js2xml.update(sa, data[i], entryLevel.immunizationActivity); + + //libCCDAGen.performerRevised(sa, data[i].performer, {}); + + //if (data[i].instructions) { + // var instERSetting = { + // templateId: "2.16.840.1.113883.10.20.22.4.20", + // inversionInd: "true" + // }; + // libCCDAGen.entryRelationship(sa, data[i].instructions, 'act', 'SUBJ', '#immunSect', instERSetting); + //} + //if (data[i].refusal_reason) { + // var rrData = { + // code: libCCDAGen.reverseTable("2.16.840.1.113883.5.8", data[i].refusal_reason) + // }; + // var instRRSetting = { + // templateId: "2.16.840.1.113883.10.20.22.4.53", + // id: true + // }; + // libCCDAGen.entryRelationship(sa, rrData, 'observation', 'RSON', undefined, instRRSetting); + //} } xmlDoc = xmlDoc.parent() // end section .parent(); // end clinicalDocument diff --git a/lib/templates/attrLevel.js b/lib/templates/attrLevel.js index 8c2727d..6afc738 100644 --- a/lib/templates/attrLevel.js +++ b/lib/templates/attrLevel.js @@ -24,4 +24,6 @@ exports.booleanData = function (key) { exports.code = translate.code; +exports.codeName = translate.codeName; + exports.time = translate.time; diff --git a/lib/templates/common.js b/lib/templates/common.js index b8035d5..4491c56 100644 --- a/lib/templates/common.js +++ b/lib/templates/common.js @@ -139,10 +139,15 @@ var assignedEntity = exports.assignedEntity = { content: [ fieldLevel.id, usRealmAddress("addr"), + telecom, { + key: "assignedPerson", + content: usRealmName, + existsWhen: condition.keyExists("name") + }, representedOrganization ], dataKey: "performer", - existsWhen: condition.eitherKeyExists("address", "id", "organization") + existsWhen: condition.eitherKeyExists("address", "identifiers", "organization") }; exports.performer = { diff --git a/lib/templates/entryLevel.js b/lib/templates/entryLevel.js index 97c61b4..1b86b4a 100644 --- a/lib/templates/entryLevel.js +++ b/lib/templates/entryLevel.js @@ -534,3 +534,125 @@ var medicationActivity = exports.medicationActivity = { } ] }; + +var immunizationMedicationInformation = exports.immunizationMedicationInformation = { + key: "manufacturedProduct", + attributes: { + classCode: "MANU" + }, + content: [ + common.templateId("2.16.840.1.113883.10.20.22.4.54"), + fieldLevel.id, { + key: "manufacturedMaterial", + content: [{ + key: "code", + attributes: [ + attrLevel.code + ], + content: [{ + key: "originalText", + text: attrLevel.data("unencoded_name"), + content: [{ + key: "reference", + attributes: [ + attrLevel.code + ] + }] + }, { + key: "translation", + attributes: [ + attrLevel.code + ], + dataKey: "translations" + }] + }, { + key: "lotNumberText", + text: attrLevel.input, + dataKey: "lot_number" + }], + dataKey: "product" + }, { + key: "manufacturerOrganization", + content: { + key: "name", + text: attrLevel.input, + }, + dataKey: "manufacturer" + } + ], + dataTransform: function (input) { + if (input.product) { + input.product.lot_number = input.lot_number; + } + return input; + } +}; + +var immunizationRefusalReason = { + key: "observation", + attributes: { + classCode: "OBS", + moodCode: "EVN" + }, + content: [ + common.templateId("2.16.840.1.113883.10.20.22.4.53"), + fieldLevel.id, { + key: "code", + attributes: attrLevel.codeName("2.16.840.1.113883.5.8") + }, + common.completed + ] +}; + +exports.immunizationActivity = [ + common.templateId("2.16.840.1.113883.10.20.22.4.52"), + fieldLevel.id, + common.completed, + fieldLevel.effectiveTime(), { + key: "repeatNumber", + attributes: { + value: attrLevel.data("sequence_number") + }, + existsWhen: function (input) { + return input.sequence_number || (input.sequence_number === ""); + } + }, { + key: "routeCode", + attributes: attrLevel.code, + dataKey: "administration.route" + }, { + key: "approachSiteCode", + attributes: attrLevel.code, + dataKey: "administration.body_site" + }, { + key: "doseQuantity", + attributes: { + value: attrLevel.data("value"), + unit: attrLevel.data("unit") + }, + dataKey: "administration.dose" + }, { + key: "consumable", + content: immunizationMedicationInformation, + dataKey: "product" + }, { + key: "performer", + content: common.assignedEntity, + existsWhen: condition.keyExists("performer") + }, { + key: "entryRelationship", + attributes: { + typeCode: "SUBJ", + inversionInd: "true" + }, + content: instructions, + dataKey: "instructions" + }, { + key: "entryRelationship", + attributes: { + typeCode: "RSON" + }, + content: immunizationRefusalReason, + dataKey: "refusal_reason" + } +]; diff --git a/lib/templates/js2xml.js b/lib/templates/js2xml.js index 87e6eb6..a5ea7e4 100644 --- a/lib/templates/js2xml.js +++ b/lib/templates/js2xml.js @@ -37,7 +37,7 @@ var expandAttributes = function expandAttributes(input, attrObj, attrs) { if (typeof attrVal === 'function') { attrVal = attrVal(input); } - if (attrVal) { + if ((attrVal !== null) && (attrVal !== undefined)) { attrs[attrKey] = attrVal; } });