Skip to content

Commit

Permalink
immunization activity content from template
Browse files Browse the repository at this point in the history
  • Loading branch information
au2 committed Oct 9, 2014
1 parent 90969c8 commit a087a6b
Show file tree
Hide file tree
Showing 6 changed files with 206 additions and 45 deletions.
28 changes: 27 additions & 1 deletion lib/bbutil/translate.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {};
Expand Down Expand Up @@ -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];
Expand All @@ -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);
}
};
90 changes: 48 additions & 42 deletions lib/immunizations.js
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down Expand Up @@ -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
Expand Down
2 changes: 2 additions & 0 deletions lib/templates/attrLevel.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,4 +24,6 @@ exports.booleanData = function (key) {

exports.code = translate.code;

exports.codeName = translate.codeName;

exports.time = translate.time;
7 changes: 6 additions & 1 deletion lib/templates/common.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {
Expand Down
122 changes: 122 additions & 0 deletions lib/templates/entryLevel.js
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}
];
2 changes: 1 addition & 1 deletion lib/templates/js2xml.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
});
Expand Down

0 comments on commit a087a6b

Please sign in to comment.