CCDA and Other (#4382)
[openemr.git] / ccdaservice / oe-blue-button-generate / lib / sectionLevel2.js
bloba8bf47b6300f027fca14c1d45e2005c9d292f538
1 "use strict";
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) {
19     var result = {
20         key: "text",
21         existsWhen: condition.keyExists(topArrayKey),
23         content: [{
24             key: "table",
25             attributes: {
26                 border: "1",
27                 width: "100%"
28             },
29             content: [{
30                 key: "thead",
31                 content: [{
32                     key: "tr",
33                     content: []
34                 }]
35             }, {
36                 key: "tbody",
37                 content: [{
38                     key: "tr",
39                     content: [],
40                     dataKey: topArrayKey
41                 }]
42             }]
43         }]
44     };
45     var headerTarget = result.content[0].content[0].content[0].content;
46     headers.forEach(function (header) {
47         var element = {
48             key: "th",
49             text: header
50         };
51         headerTarget.push(element);
52     });
53     var valueTarget = result.content[0].content[1].content[0].content;
54     values.forEach(function (value) {
55         var data;
56         if (typeof value !== 'function') {
57             data = leafLevel.deepInputProperty(value, "");
58         } else {
59             data = value;
60         }
62         var element = {
63             key: "td",
64             text: data
65         };
66         valueTarget.push(element);
67     });
68     return result;
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", "")
78 ];*/
80 exports.allergiesSectionEntriesRequired = function (htmlHeader, na) {
81     return {
82         key: "component",
83         content: [{
84             key: "section",
85             content: [
86                 fieldLevel.templateIdExt("2.16.840.1.113883.10.20.22.2.6.1", "2015-08-01"),
87                 fieldLevel.templateId("2.16.840.1.113883.10.20.22.2.6.1"),
88                 fieldLevel.templateCode("AllergiesSection"),
89                 fieldLevel.templateTitle("AllergiesSection"), {
90                     key: "text",
91                     text: na,
92                     existsWhen: condition.keyDoesntExist("allergies")
94                 },
95                 htmlHeader, {
96                     key: "entry",
97                     attributes: {
98                         "typeCode": "DRIV"
99                     },
100                     content: [
101                         [entryLevel.allergyProblemAct, required]
102                     ],
103                     dataKey: "allergies",
104                     required: true
105                 }
106             ]
107         }]
108     };
111 /*var medicationsTextHeaders = ["Medication Class", "# fills", "Last fill date"];
112 var medicationsTextRow = [ // Name, did not find class in the medication blue-button-data
113     function (input) {
114         var value = bbuo.deepValue(input, 'product.product.name');
115         if (!bbuo.exists(value)) {
116             value = bbuo.deepValue(input, 'product.unencoded_name');
117         }
118         if (!bbuo.exists(value)) {
119             return "";
120         } else {
121             return value;
122         }
123     },
124     leafLevel.deepInputProperty("supply.repeatNumber", ""),
125     leafLevel.deepInputDate("supply.date_time.point", "")
126 ];*/
128 exports.medicationsSectionEntriesRequired = function (htmlHeader, na) {
129     return {
130         key: "component",
131         content: [{
132             key: "section",
133             content: [
134                 fieldLevel.templateIdExt("2.16.840.1.113883.10.20.22.2.1.1", "2014-06-09"),
135                 fieldLevel.templateId("2.16.840.1.113883.10.20.22.2.1.1"),
136                 fieldLevel.templateCode("MedicationsSection"),
137                 fieldLevel.templateTitle("MedicationsSection"), {
138                     key: "text",
139                     text: na,
140                     existsWhen: condition.keyDoesntExist("medications")
142                 },
143                 htmlHeader, {
144                     key: "entry",
145                     attributes: {
146                         "typeCode": "DRIV"
147                     },
148                     content: [
149                         [entryLevel.medicationActivity, required]
150                     ],
151                     dataKey: "medications",
152                     required: true
153                 }
154             ]
155         }]
156     };
159 exports.problemsSectionEntriesRequired = function (htmlHeader, na) {
160     return {
161         key: "component",
162         content: [{
163             key: "section",
164             content: [
165                 fieldLevel.templateIdExt("2.16.840.1.113883.10.20.22.2.5.1", "2015-08-01"),
166                 fieldLevel.templateId("2.16.840.1.113883.10.20.22.2.5.1"),
167                 fieldLevel.templateCode("ProblemSection"),
168                 fieldLevel.templateTitle("ProblemSection"), {
169                     key: "text",
170                     text: na,
171                     existsWhen: condition.keyDoesntExist("problems")
173                 },
174                 htmlHeader, {
175                     key: "entry",
176                     attributes: {
177                         "typeCode": "DRIV"
178                     },
179                     content: [
180                         [entryLevel.problemConcernAct, required]
181                     ],
182                     dataKey: "problems",
183                     required: true
184                 }, {
185                     key: "entry",
186                     existsWhen: condition.keyExists("problems_comment"),
187                     content: {
188                         key: "act",
189                         attributes: {
190                             classCode: "ACT",
191                             moodCode: "EVN"
192                         },
193                         content: [
194                             fieldLevel.templateId("2.16.840.1.113883.10.20.22.4.64"),
195                             fieldLevel.templateCode("CommentActivity"), {
196                                 key: "text",
197                                 text: leafLevel.deepInputProperty("problems_comment")
198                             },
199                         ]
201                     },
202                     dataKey: "demographics.meta"
203                 }
204             ]
205         }]
206     };
209 exports.proceduresSectionEntriesRequired = function (htmlHeader, na) {
210     return {
211         key: "component",
212         content: [{
213             key: "section",
214             content: [
215                 fieldLevel.templateId("2.16.840.1.113883.10.20.22.2.7"),
216                 fieldLevel.templateId("2.16.840.1.113883.10.20.22.2.7.1"),
217                 fieldLevel.templateCode("ProceduresSection"),
218                 fieldLevel.templateTitle("ProceduresSection"), {
219                     key: "text",
220                     text: na,
221                     existsWhen: condition.keyDoesntExist("procedures")
223                 },
224                 htmlHeader, {
225                     key: "entry",
226                     attributes: {
227                         "typeCode": function (input) {
228                             return input.procedure_type === "procedure" ? "DRIV" : null;
229                         }
230                     },
231                     content: [
232                         entryLevel.procedureActivityAct,
233                         entryLevel.procedureActivityProcedure,
234                         entryLevel.procedureActivityObservation
235                     ],
236                     dataKey: "procedures"
237                 }
238             ]
239         }],
240         notImplemented: [
241             "entry required"
242         ]
243     };
246 exports.resultsSectionEntriesRequired = function (htmlHeader, na) {
247     return {
248         key: "component",
249         content: [{
250             key: "section",
251             content: [
252                 fieldLevel.templateIdExt("2.16.840.1.113883.10.20.22.2.3.1", "2015-08-01"),
253                 fieldLevel.templateId("2.16.840.1.113883.10.20.22.2.3.1"),
254                 fieldLevel.templateCode("ResultsSection"),
255                 fieldLevel.templateTitle("ResultsSection"), {
256                     key: "text",
257                     text: na,
258                     existsWhen: condition.keyDoesntExist("results")
260                 },
261                 htmlHeader, {
262                     key: "entry",
263                     attributes: {
264                         typeCode: "DRIV"
265                     },
266                     content: [
267                         [entryLevel.resultOrganizer, required]
268                     ],
269                     dataKey: "results",
270                     required: true
271                 }
272             ]
273         }]
274     };
277 exports.encountersSectionEntriesOptional = function (htmlHeader, na) {
278     return {
279         key: "component",
280         content: [{
281             key: "section",
282             content: [
283                 fieldLevel.templateIdExt("2.16.840.1.113883.10.20.22.2.22.1", "2015-08-01"),
284                 fieldLevel.templateId("2.16.840.1.113883.10.20.22.2.22.1"),
285                 fieldLevel.templateCode("EncountersSection"),
286                 fieldLevel.templateTitle("EncountersSection"), {
287                     key: "text",
288                     text: na,
289                     existsWhen: condition.keyDoesntExist("encounters")
291                 },
292                 htmlHeader, {
293                     key: "entry",
294                     attributes: {
295                         "typeCode": "DRIV"
296                     },
297                     content: [
298                         [entryLevel.encounterActivities, required]
299                     ],
300                     dataKey: "encounters"
301                 }
302             ]
303         }]
304     };
307 exports.immunizationsSectionEntriesOptional = function (htmlHeader, na) {
308     return {
309         key: "component",
310         content: [{
311             key: "section",
312             content: [
313                 fieldLevel.templateId("2.16.840.1.113883.10.20.22.2.2"),
314                 fieldLevel.templateId("2.16.840.1.113883.10.20.22.2.2.1"),
315                 fieldLevel.templateCode("ImmunizationsSection"),
316                 fieldLevel.templateTitle("ImmunizationsSection"), {
317                     key: "text",
318                     text: na,
319                     existsWhen: condition.keyDoesntExist("immunizations")
321                 },
322                 htmlHeader, {
323                     key: "entry",
324                     attributes: {
325                         "typeCode": "DRIV"
326                     },
327                     content: [
328                         [entryLevel.immunizationActivity, required]
329                     ],
330                     dataKey: "immunizations"
331                 }
332             ]
333         }]
334     };
337 exports.payersSection = function (htmlHeader, na) {
338     return {
339         key: "component",
340         content: [{
341             key: "section",
342             content: [
343                 fieldLevel.templateId("2.16.840.1.113883.10.20.22.2.18"),
344                 fieldLevel.templateCode("PayersSection"),
345                 fieldLevel.templateTitle("PayersSection"), {
346                     key: "text",
347                     text: na,
348                     existsWhen: condition.keyDoesntExist("payers")
350                 },
351                 htmlHeader, {
352                     key: "entry",
353                     attributes: {
354                         typeCode: "DRIV"
355                     },
356                     content: [
357                         [entryLevel.coverageActivity, required]
358                     ],
359                     dataKey: "payers"
360                 }
361             ]
362         }]
363     };
366 exports.planOfCareSection = function (htmlHeader, na) {
367     return {
368         key: "component",
369         content: [{
370             key: "section",
371             content: [
372                 fieldLevel.templateId("2.16.840.1.113883.10.20.22.2.10"),
373                 fieldLevel.templateCode("PlanOfCareSection"),
374                 fieldLevel.templateTitle("PlanOfCareSection"), {
375                     key: "text",
376                     text: na,
377                     existsWhen: condition.keyDoesntExist("plan_of_care")
379                 },
380                 htmlHeader, {
381                     key: "entry",
382                     attributes: {
383                         "typeCode": function (input) {
384                             return input.type === "observation" ? "DRIV" : null;
385                         }
386                     },
387                     content: [
388                         entryLevel.planOfCareActivityAct,
389                         entryLevel.planOfCareActivityObservation,
390                         entryLevel.planOfCareActivityProcedure,
391                         entryLevel.planOfCareActivityEncounter,
392                         entryLevel.planOfCareActivitySubstanceAdministration,
393                         entryLevel.planOfCareActivitySupply,
394                         entryLevel.planOfCareActivityInstructions
395                     ],
396                     dataKey: "plan_of_care"
397                 }
398             ]
399         }]
400     };
403 exports.socialHistorySection = function (htmlHeader, na) {
404     return {
405         key: "component",
406         content: [{
407             key: "section",
408             content: [
409                 fieldLevel.templateIdExt("2.16.840.1.113883.10.20.22.2.17", "2015-08-01"),
410                 fieldLevel.templateId("2.16.840.1.113883.10.20.22.2.17"),
411                 fieldLevel.templateCode("SocialHistorySection"),
412                 fieldLevel.templateTitle("SocialHistorySection"), {
413                     key: "text",
414                     text: na,
415                     existsWhen: condition.keyDoesntExist("social_history")
417                 },
418                 htmlHeader, {
419                     key: "entry",
420                     attributes: {
421                         typeCode: "DRIV"
422                     },
423                     content: [entryLevel.smokingStatusObservation],
424                     dataKey: "social_history"
425                 }, {
426                     key: "entry",
427                     attributes: {
428                         typeCode: "DRIV"
429                     },
430                     content: [entryLevel.genderStatusObservation],
431                     dataKey: "social_history"
432                 }, {
433                     key: "entry",
434                     attributes: {
435                         typeCode: "DRIV"
436                     },
437                     content: [entryLevel.socialHistoryObservation],
438                     existsWhen: function (input) {
439                         return (!input.value) || input.value.indexOf("smoke") < 0;
440                     },
441                     dataKey: "social_history"
442                 }
443             ]
444         }],
445         notImplemented: [
446             "pregnancyObservation",
447             "tobaccoUse"
448         ]
449     };
452 exports.vitalSignsSectionEntriesOptional = function (htmlHeader, na) {
453     return {
454         key: "component",
455         content: [{
456             key: "section",
457             content: [
458                 fieldLevel.templateIdExt("2.16.840.1.113883.10.20.22.2.4.1", "2015-08-01"),
459                 fieldLevel.templateId("2.16.840.1.113883.10.20.22.2.4.1"),
460                 fieldLevel.templateCode("VitalSignsSection"),
461                 fieldLevel.templateTitle("VitalSignsSection"), {
462                     key: "text",
463                     text: na,
464                     existsWhen: condition.keyDoesntExist("vitals")
466                 },
467                 htmlHeader, {
468                     key: "entry",
469                     attributes: {
470                         "typeCode": "DRIV"
471                     },
472                     content: [
473                         [entryLevel.vitalSignsOrganizer, required]
474                     ],
475                     dataKey: "vitals"
476                 }
477             ]
478         }]
479     };
482 exports.medicalEquipmentSectionEntriesOptional = function (htmlHeader, na) {
483     return {
484         key: "component",
485         content: [{
486             key: "section",
487             content: [
488                 fieldLevel.templateIdExt("2.16.840.1.113883.10.20.22.2.23", "2014-06-09"),
489                 fieldLevel.templateId("2.16.840.1.113883.10.20.22.2.23"),
490                 fieldLevel.templateCode("MedicalEquipmentSection"),
491                 fieldLevel.templateTitle("MedicalEquipmentSection"), {
492                     key: "text",
493                     text: na,
494                     existsWhen: condition.keyDoesntExist("medical_devices")
496                 },
497                 htmlHeader, {
498                     key: "entry",
499                     content: [
500                         entryLevel.medicalDeviceActivityProcedure,
501                     ],
502                     dataKey: "medical_devices"
503                 }
504             ]
505         }],
506         notImplemented: [
507             "entry required"
508         ]
509     };