3 var bbu = require("../../oe-blue-button-util");
5 var fieldLevel = require("./fieldLevel");
6 var entryLevel = require("./entryLevel");
7 var leafLevel = require('./leafLevel');
8 var contentModifier = require("./contentModifier");
10 var required = contentModifier.required;
11 var bbud = bbu.datetime;
12 var bbuo = bbu.object;
14 var nda = "No Data Available";
16 var condition = require('./condition');
18 var getText = function (topArrayKey, headers, values) {
21 existsWhen: condition.keyExists(topArrayKey),
45 var headerTarget = result.content[0].content[0].content[0].content;
46 headers.forEach(function (header) {
51 headerTarget.push(element);
53 var valueTarget = result.content[0].content[1].content[0].content;
54 values.forEach(function (value) {
56 if (typeof value !== 'function') {
57 data = leafLevel.deepInputProperty(value, "");
66 valueTarget.push(element);
70 // Replace with static table
71 /*var alllergiesTextHeaders = ["Substance", "Overall Severity", "Reaction", "Reaction Severity", "Status"];
72 var allergiesTextRow = [
73 leafLevel.deepInputProperty("observation.allergen.name", ""),
74 leafLevel.deepInputProperty("observation.severity.code.name", ""),
75 leafLevel.deepInputProperty("observation.reactions.0.reaction.name", ""),
76 leafLevel.deepInputProperty("observation.reactions.0.severity.code.name", ""),
77 leafLevel.deepInputProperty("observation.status.name", "")
80 //exports.allergiesSectionEntriesRequiredHtmlHeader = getText('allergies', alllergiesTextHeaders, allergiesTextRow);
82 exports.allergiesSectionEntriesRequiredHtmlHeader = {
84 existsWhen: condition.keyExists("allergies"),
98 text: leafLevel.input,
99 dataTransform: function () {
100 return ["Substance", "Overall Severity", "Reaction", "Reaction Severity", "Status"];
110 text: leafLevel.deepInputProperty("observation.allergen.name", nda),
114 ID: leafLevel.nextTableReference("severity")
116 text: leafLevel.deepInputProperty("observation.severity.code.name", nda)
120 ID: leafLevel.nextTableReference("reaction")
122 text: leafLevel.deepInputProperty("observation.reactions.0.reaction.name", nda)
126 ID: leafLevel.nextTableReference("severity")
128 text: leafLevel.deepInputProperty("observation.reactions.0.severity.code.name", nda)
131 text: leafLevel.deepInputProperty("observation.status.name", nda)
139 exports.medicationsSectionEntriesRequiredHtmlHeader = {
141 existsWhen: condition.keyExists("medications"),
155 text: leafLevel.input,
156 dataTransform: function () {
157 return ["Medication Class", "# fills", "Last fill date"];
168 ID: leafLevel.nextTableReference("medinfo")
170 text: function (input) {
171 var value = bbuo.deepValue(input, 'product.product.name');
172 if (!bbuo.exists(value)) {
173 value = bbuo.deepValue(input, 'product.unencoded_name');
175 if (!bbuo.exists(value)) {
183 text: leafLevel.deepInputProperty("supply.repeatNumber", ""),
186 text: leafLevel.deepInputDate("supply.date_time.low", nda)
189 dataKey: 'medications'
194 exports.problemsSectionEntriesRequiredHtmlHeader = {
196 existsWhen: condition.keyExists("problems"),
215 text: leafLevel.input,
216 dataTransform: function () {
217 return ['Condition', 'Status'];
228 ID: leafLevel.nextTableReference("problem")
230 text: leafLevel.deepInputProperty("problem.code.name", nda)
234 ID: leafLevel.nextTableReference("healthStatus")
236 text: leafLevel.deepInputProperty("problem.severity.code.name", nda)
244 exports.proceduresSectionEntriesRequiredHtmlHeader = {
247 existsWhen: condition.keyExists("procedures"),
266 text: leafLevel.input,
267 dataTransform: function () {
268 return ['Service', 'Procedure code', 'Service date', 'Servicing provider', 'Phone#'];
279 ID: leafLevel.nextTableReference("procedure")
281 text: leafLevel.deepInputProperty("procedure.name", nda)
284 text: leafLevel.deepInputProperty("procedure.code", nda)
287 text: leafLevel.deepInputDate("date_time.point", nda)
290 text: leafLevel.deepInputProperty("performer.0.organization.0.name.0", nda)
293 text: leafLevel.deepInputProperty("performer.0.organization.0.phone.0.value.number", nda)
296 dataKey: 'procedures'
301 exports.resultsSectionEntriesRequiredHtmlHeader = {
303 existsWhen: condition.keyExists("results"),
316 text: "Laboratory Results"
322 text: leafLevel.input,
323 dataTransform: function () {
324 return ['Test', 'Result', 'Units', 'Reference Range', 'Date', 'Source'];
337 text: leafLevel.deepInputProperty('result_set.name', nda),
343 text: leafLevel.deepInputProperty("result.name", nda)
347 ID: leafLevel.nextTableReference("result")
349 text: leafLevel.deepInputProperty("value", nda)
352 text: leafLevel.deepInputProperty("unit", nda)
355 text: leafLevel.deepInputProperty("reference_range.range", nda)
358 text: leafLevel.deepInputDate("date_time.point", nda),
370 exports.encountersSectionEntriesOptionalHtmlHeader = {
372 existsWhen: condition.keyExists("encounters"),
385 text: leafLevel.input,
386 dataTransform: function () {
387 return ['Type', 'Facility', 'Date of Service', 'Diagnosis/Complaint'];
398 ID: leafLevel.nextTableReference("Encounter")
400 text: leafLevel.deepInputProperty("encounter.name", nda)
403 text: leafLevel.deepInputProperty("locations.0.name", nda)
406 text: function (input) {
407 var value = bbuo.deepValue(input, "date_time.point");
409 value = bbud.modelToDate({
411 precision: value.precision // workaround a bug in bbud. Changes precision.
414 var vps = value.split('-');
415 if (vps.length === 3) {
416 return [vps[1], vps[2], vps[0]].join('/');
424 text: leafLevel.deepInputProperty("findings.0.value.name", nda)
427 dataKey: 'encounters'
432 exports.immunizationsSectionEntriesOptionalHtmlHeader = {
434 existsWhen: condition.keyExists("immunizations"),
447 text: "Immunizations"
453 text: leafLevel.input,
454 dataTransform: function () {
455 return ['Vaccine', 'Date', 'Status'];
466 ID: leafLevel.nextTableReference("immunization")
468 text: leafLevel.deepInputProperty("product.product.name", nda)
471 text: leafLevel.deepInputDate("date_time.point", nda),
474 text: leafLevel.deepInputProperty("status", nda)
477 dataKey: 'immunizations'
482 exports.payersSectionHtmlHeader = {
484 existsWhen: condition.keyExists("payers"),
503 text: leafLevel.input,
504 dataTransform: function () {
505 return ['Payer Name', 'Group ID', 'Member ID', 'Elegibility Start Date', 'Elegibility End Date'];
515 text: leafLevel.deepInputProperty("policy.insurance.performer.organization.0.name.0", nda)
518 text: leafLevel.deepInputProperty("policy.identifiers.0.extension", nda)
521 text: leafLevel.deepInputProperty("participant.performer.identifiers.0.extension", nda)
524 text: leafLevel.deepInputProperty("participant.date_time.low.date", nda)
527 text: leafLevel.deepInputProperty("participant.date_time.high.date", nda)
535 exports.planOfCareSectionHtmlHeader = {
537 existsWhen: condition.keyExists("plan_of_care"),
555 text: leafLevel.input,
556 dataTransform: function () {
557 return ['Program', 'Start Date', 'Status', 'Goals'];
568 ID: leafLevel.nextTableReference("problem")
570 text: leafLevel.deepInputProperty("plan.name", nda)
573 text: leafLevel.deepInputDate("date_time.center", nda)
576 text: leafLevel.deepInputProperty("status.code", nda)
579 text: leafLevel.deepInputProperty("goal.name", nda)
582 dataKey: 'plan_of_care'
587 exports.goalSectionHtmlHeader = {
589 existsWhen: condition.keyExists("goals"),
607 text: leafLevel.input,
608 dataTransform: function () {
609 return ['Start Date','Goal', 'Status'];
619 text: leafLevel.deepInputDate("date_time.point", nda)
623 ID: leafLevel.nextTableReference("goal")
625 text: leafLevel.deepInputProperty("name", nda)
628 text: leafLevel.deepInputProperty("status.code", nda)
636 exports.socialHistorySectionHtmlHeader = {key: "text",
637 existsWhen: condition.keyExists("social_history"),
650 text: "Social History"
656 text: leafLevel.input,
657 dataTransform: function () {
658 return ['Social History Element', 'Description', 'Effective Dates'];
669 ID: leafLevel.nextTableReference("social")
671 text: leafLevel.deepInputProperty("code.name", nda)
674 text: leafLevel.deepInputProperty("value", nda)
677 text: leafLevel.deepInputDate("date_time.low", nda),
680 dataKey: 'social_history'
685 exports.vitalSignsSectionEntriesOptionalHtmlHeader = {
687 existsWhen: condition.keyExists("vitals"),
700 text: "Vital Sign Observations"
706 text: leafLevel.input,
707 dataTransform: function () {
708 return ['Date', 'Body Temperature', 'Systolic BP [90-140 mmHg]', 'Diastolic BP [60-90 mmHg]', 'Heart Rate', 'Height', 'Weight Measured', 'BMI (Body Mass Index)'];
718 text: leafLevel.deepInputDate("date_time.point", nda)
722 ID: leafLevel.nextTableReference("vital")
724 text: leafLevel.deepInputProperty("vital_list.7.value", nda, "vital_list.7.unit")
728 ID: leafLevel.nextTableReference("vital")
730 text: leafLevel.deepInputProperty("vital_list.0.value", nda, "vital_list.0.unit")
734 ID: leafLevel.nextTableReference("vital")
736 text: leafLevel.deepInputProperty("vital_list.1.value", nda, "vital_list.1.unit")
740 ID: leafLevel.nextTableReference("vital")
742 text: leafLevel.deepInputProperty("vital_list.5.value", nda, "vital_list.5.unit")
746 ID: leafLevel.nextTableReference("vital")
748 text: leafLevel.deepInputProperty("vital_list.2.value", nda, "vital_list.2.unit")
752 ID: leafLevel.nextTableReference("vital")
754 text: leafLevel.deepInputProperty("vital_list.3.value", nda, "vital_list.3.unit")
758 ID: leafLevel.nextTableReference("vital")
760 text: leafLevel.deepInputProperty("vital_list.4.value", nda, "vital_list.4.unit")
768 exports.medicalEquipmentSectionEntriesOptionalHtmlHeader = {
770 existsWhen: condition.keyExists("medical_devices"),
784 text: leafLevel.input,
785 dataTransform: function () {
786 return ["Implant", "UDI"];
797 ID: leafLevel.nextTableReference("device")
799 text: leafLevel.deepInputProperty("device.name", nda),
802 text: leafLevel.deepInputProperty("device.udi", "na"),
806 dataKey: 'medical_devices'
811 exports.functionalStatusSectionHtmlHeader = {
813 existsWhen: condition.keyExists("functional_status"),
827 text: leafLevel.input,
828 dataTransform: function () {
829 return ["Functional Category", "Effective Date"];
840 ID: leafLevel.nextTableReference("functional_status")
842 text: leafLevel.deepInputProperty("observation.value.name", nda),
845 text: leafLevel.deepInputDate("observation.date_time.point", nda),
849 dataKey: 'functional_status'
854 exports.functionalStatusSectionHtmlHeaderNA = "Not Available";
855 exports.allergiesSectionEntriesRequiredHtmlHeaderNA = "Not Available";
856 exports.medicationsSectionEntriesRequiredHtmlHeaderNA = "Not Available";
857 exports.problemsSectionEntriesRequiredHtmlHeaderNA = "Not Available";
858 exports.proceduresSectionEntriesRequiredHtmlHeaderNA = "Not Available";
859 exports.resultsSectionEntriesRequiredHtmlHeaderNA = "Not Available";
860 exports.encountersSectionEntriesOptionalHtmlHeaderNA = "Not Available";
861 exports.immunizationsSectionEntriesOptionalHtmlHeaderNA = "Not Available";
862 exports.payersSectionHtmlHeaderNA = "Not Available";
863 exports.planOfCareSectionHtmlHeaderNA = "Not Available";
864 exports.goalSectionHtmlHeaderNA = "Not Available";
865 exports.socialHistorySectionHtmlHeaderNA = "Not Available";
866 exports.vitalSignsSectionEntriesOptionalHtmlHeaderNA = "Not Available";
867 exports.medicalEquipmentSectionEntriesOptionalHtmlHeaderNA = "Not Available";