chore(eslint): ESLint setup (#6708)
[openemr.git] / ccdaservice / oe-blue-button-generate / lib / headerLevel.js
blob0a7347f812aa63bdfecf63b3ac5ef1836948b8b6
1 "use strict";
3 var fieldLevel = require('./fieldLevel');
4 var leafLevel = require('./leafLevel');
5 var condition = require('./condition');
6 var contentModifier = require("./contentModifier");
7 var translate = require("./translate");
8 var key = contentModifier.key;
9 var required = contentModifier.required;
10 var dataKey = contentModifier.dataKey;
12 var patientName = Object.create(fieldLevel.usRealmName);
13 patientName.attributes = {
14     use: "L"
17 var patient = exports.patient = {
18     key: "patient",
19     content: [
20         patientName,
21         {
22             key: "name",
23             content: [{
24                 key: "given",
25                 attributes: {
26                     qualifier: "BR"
27                 },
28                 text: leafLevel.inputProperty("first")
29             }, {
30                 key: "given",
31                 text: leafLevel.inputProperty("middle"),
32                 existsWhen: condition.propertyNotEmpty("middle")
33             }, {
34                 key: "family",
35                 attributes: {
36                     qualifier: "BR"
37                 },
38                 text: leafLevel.inputProperty("last")
39             }],
40             dataKey: "birth_name",
41             existsWhen: condition.propertyNotEmpty("last")
42         }, {
43             key: "administrativeGenderCode",
44             attributes: {
45                 code: function (input) {
46                     if (Object.prototype.toString.call(input) === "[object String]")
47                         return input.substring(0, 1);
48                     else return input.code.substring(0, 1);
49                 },
50                 codeSystem: "2.16.840.1.113883.5.1",
51                 codeSystemName: "HL7 AdministrativeGender",
52                 displayName: leafLevel.input
53             },
54             dataKey: "gender"
55         },
56         [fieldLevel.effectiveTime, key("birthTime"), dataKey("dob")], {
57             key: "maritalStatusCode",
58             attributes: {
59                 code: function (input) {
60                     if (Object.prototype.toString.call(input) === "[object String]") {
61                         return input.substring(0, 1);
62                     } else {
63                         return input.code.substring(0, 1);
64                     }
65                 },
66                 displayName: leafLevel.input,
67                 codeSystem: "2.16.840.1.113883.5.2",
68                 codeSystemName: "HL7 Marital Status"
69             },
70             dataKey: "marital_status",
71         }, {
72             key: "religiousAffiliationCode",
73             attributes: leafLevel.codeFromName("2.16.840.1.113883.5.1076"),
74             dataKey: "religion"
75         }, {
76             key: "raceCode",
77             attributes: leafLevel.codeFromName("2.16.840.1.113883.6.238"),
78             dataKey: "race"
79         }, {
80             key: "sdtc:raceCode",
81             attributes: leafLevel.codeFromName("2.16.840.1.113883.6.238"),
82             dataKey: "race_additional"
83         }, {
84             key: "ethnicGroupCode",
85             attributes: leafLevel.codeFromName("2.16.840.1.113883.6.238"),
86             dataKey: "ethnicity"
87         }, {
88             key: "guardian",
89             content: [{
90                 key: "code",
91                 attributes: leafLevel.codeFromName("2.16.840.1.113883.5.111"),
92                 dataKey: "relation"
93             },
94                 [fieldLevel.usRealmAddress, dataKey("addresses")],
95                 fieldLevel.telecom, {
96                     key: "guardianPerson",
97                     content: {
98                         key: "name",
99                         content: [{
100                             key: "given",
101                             text: leafLevel.inputProperty("first")
102                         }, {
103                             key: "family",
104                             text: leafLevel.inputProperty("last")
105                         }],
106                         dataKey: "names"
107                     }
108                 }
109             ],
110             dataKey: "guardians"
111         }, {
112             key: "birthplace",
113             content: {
114                 key: "place",
115                 content: [
116                     [fieldLevel.usRealmAddress, dataKey("birthplace")]
117                 ]
118             },
119             existsWhen: condition.keyExists("birthplace")
120         }, {
121             key: "languageCommunication",
122             content: [{
123                 key: "languageCode",
124                 attributes: {
125                     code: leafLevel.input
126                 },
127                 dataKey: "language"
128             }, {
129                 key: "modeCode",
130                 attributes: leafLevel.codeFromName("2.16.840.1.113883.5.60"),
131                 dataKey: "mode"
132             }, {
133                 key: "proficiencyLevelCode",
134                 attributes: {
135                     code: function (input) {
136                         if (Object.prototype.toString.call(input) === "[object String]")
137                             return input.substring(0, 1);
138                         else return input.code.substring(0, 1);
139                     },
140                     displayName: leafLevel.input,
141                     codeSystem: "2.16.840.1.113883.5.61",
142                     codeSystemName: "LanguageAbilityProficiency"
143                 },
144                 dataKey: "proficiency"
145             }, {
146                 key: "preferenceInd",
147                 attributes: {
148                     value: function (input) {
149                         return input.toString();
150                     }
151                 },
152                 dataKey: "preferred"
153             }],
154             dataKey: "languages"
155         }
156     ]
159 var provider = exports.provider = [{
160     key: "performer",
161     attributes: {
162         typeCode: "PRF"
163     },
164     content: [
165         {
166             key: "functionCode",
167             attributes: {
168                 "code": "PP",
169                 "displayName": "Primary Performer",
170                 "codeSystem": "2.16.840.1.113883.12.443",
171                 "codeSystemName": "Provider Role"
172             },
173             existsWhen: condition.propertyNotEmpty('function_code'),
174             content: [{key: "originalText", text: "Primary Care Provider"}]
175         },
176         {
177             key: "assignedEntity",
178             content: [{
179                 key: "id",
180                 attributes: {
181                     root: leafLevel.inputProperty("root"),
182                     extension: leafLevel.inputProperty("extension")
183                 },
184                 dataKey: "identity"
185             }, {
186                 key: "code",
187                 attributes: leafLevel.code,
188                 content: [{key: "originalText", text: "Care Team Member"}],
189                 dataKey: "type"
190             },
191                 fieldLevel.usRealmAddress,
192                 fieldLevel.telecom,
193                 {
194                     key: "assignedPerson",
195                     content: fieldLevel.usRealmName
196                 }
197             ]
198         }
199     ],
200     dataKey: "providers.provider"
203 var providers = exports.providers = {
204     key: "documentationOf",
205     attributes: {
206         typeCode: "DOC"
207     },
208     content: {
209         key: "serviceEvent",
210         attributes: {
211             classCode: "PCPR"
212         },
213         content: [
214             {
215                 key: "code",
216                 attributes: leafLevel.code,
217                 existsWhen: condition.propertyNotEmpty('code'),
218                 dataKey: "providers.code"
219             },
220             [fieldLevel.effectiveTime, key("effectiveTime"), dataKey("providers.date_time"), required],
221             provider
222         ]
223     },
224     dataKey: "data.demographics"
227 var participants = (exports.participant = [
228     {
229         key: "participant",
230         attributes: {
231             typeCode: leafLevel.inputProperty("typeCode"),
232         },
233         // TODO: check if this middle element can be removed
234         /* eslint-disable-next-line no-sparse-arrays */
235         content: [
236             [fieldLevel.effectiveTime, required, key("time")],
237             ,
238             // associatedEntity
239             fieldLevel.associatedEntity,
240         ],
241         dataKey: "meta.ccda_header.participants",
242     },
245 var attributed_provider = exports.attributed_provider = {
246     key: "providerOrganization",
247     content: [{
248         key: "id",
249         attributes: {
250             root: leafLevel.inputProperty("root"),
251             extension: leafLevel.inputProperty("extension")
252         },
253         dataKey: "identity"
254     }, {
255         key: "name",
256         text: leafLevel.inputProperty("full"),
257         dataKey: "name"
258     }, {
259         key: "telecom",
260         attributes: [{
261             use: "WP",
262             value: function (input) {
263                 return input.number;
264             }
265         }],
266         dataKey: "phone"
267     }, {
268         key: "addr",
269         attributes: {
270             use: leafLevel.use("use")
271         },
272         content: [{
273             key: "country",
274             text: leafLevel.inputProperty("country")
275         }, {
276             key: "state",
277             text: leafLevel.inputProperty("state")
278         }, {
279             key: "city",
280             text: leafLevel.inputProperty("city")
281         }, {
282             key: "postalCode",
283             text: leafLevel.inputProperty("zip")
284         }, {
285             key: "streetAddressLine",
286             text: leafLevel.input,
287             dataKey: "street_lines"
288         }],
289         dataKey: "address"
290     }],
291     dataKey: "attributed_provider"
294 var recordTarget = exports.recordTarget = {
295     key: "recordTarget",
296     content: {
297         key: "patientRole",
298         content: [
299             fieldLevel.id, [fieldLevel.usRealmAddress, dataKey("addresses")],
300             fieldLevel.telecom,
301             patient,
302             attributed_provider
303         ]
304     },
305     dataKey: "data.demographics"
308 var headerAuthor = exports.headerAuthor = {
309     key: "author",
310     content: [
311         [fieldLevel.effectiveTime, required, key("time")],
312         {
313             key: "assignedAuthor",
314             content: [{
315                 key: "id",
316                 attributes: {
317                     root: leafLevel.inputProperty("identifier"),
318                     extension: leafLevel.inputProperty("extension")
319                 },
320                 dataKey: 'identifiers',
321             }, {
322                 key: "code",
323                 attributes: leafLevel.code,
324                 existsWhen: condition.propertyNotEmpty('code'),
325                 dataKey: "code"
326             }, {
327                 key: "addr",
328                 attributes: {
329                     use: leafLevel.use("use")
330                 },
331                 content: [{
332                     key: "country",
333                     text: leafLevel.inputProperty("country")
334                 }, {
335                     key: "state",
336                     text: leafLevel.inputProperty("state")
337                 }, {
338                     key: "city",
339                     text: leafLevel.inputProperty("city")
340                 }, {
341                     key: "postalCode",
342                     text: leafLevel.inputProperty("zip")
343                 }, {
344                     key: "streetAddressLine",
345                     text: leafLevel.input,
346                     dataKey: "street_lines"
347                 }],
348                 dataKey: "address"
349             }, {
350                 key: "telecom",
351                 attributes: {
352                     value: leafLevel.inputProperty("value"),
353                     use: leafLevel.inputProperty("use")
354                 },
355                 dataTransform: translate.telecom
356             }, {
357                 key: "assignedPerson",
358                 content: {
359                     key: "name",
360                     content: [
361                         {
362                             key: "family",
363                             text: leafLevel.inputProperty("family")
364                         }, {
365                             key: "given",
366                             text: leafLevel.input,
367                             dataKey: "given"
368                         }, {
369                             key: "prefix",
370                             text: leafLevel.inputProperty("prefix")
371                         }, {
372                             key: "suffix",
373                             text: leafLevel.inputProperty("suffix")
374                         }],
375                     dataKey: "name",
376                     dataTransform: translate.name
377                 } // content
378             }, {
379                 key: "representedOrganization",
380                 content: [
381                     {
382                         key: "id",
383                         attributes: {
384                             root: leafLevel.inputProperty("root")
385                         },
386                         dataKey: "identity"
387                     }, {
388                         key: "name",
389                         text: leafLevel.input,
390                         dataKey: "name"
391                     }, {
392                         key: "telecom",
393                         attributes: {
394                             value: leafLevel.inputProperty("value"),
395                             use: leafLevel.inputProperty("use")
396                         },
397                         dataTransform: translate.telecom,
398                         datakey: "phone"
399                     },
400                     {
401                         key: "addr",
402                         attributes: {
403                             use: leafLevel.use("use")
404                         },
405                         content: [{
406                             key: "country",
407                             text: leafLevel.inputProperty("country")
408                         }, {
409                             key: "state",
410                             text: leafLevel.inputProperty("state")
411                         }, {
412                             key: "city",
413                             text: leafLevel.inputProperty("city")
414                         }, {
415                             key: "postalCode",
416                             text: leafLevel.inputProperty("zip")
417                         }, {
418                             key: "streetAddressLine",
419                             text: leafLevel.input,
420                             dataKey: "street_lines"
421                         }],
422                         dataKey: "address"
423                     }
424                 ],
425                 dataKey: "organization"
426             }
427             ] // content
428         }
429     ],
430     dataKey: "meta.ccda_header.author"
432 var headerInformant = exports.headerInformant = {
433     key: "informant",
434     content: {
435         key: "assignedEntity",
436         //attributes: {id:}
437         content: [{
438             key: "id",
439             attributes: {
440                 root: leafLevel.inputProperty("identifier")
441             },
442             dataKey: "identifiers"
444         }, {
445             key: "representedOrganization",
446             content: [{
447                 key: "id",
448                 attributes: {
449                     root: leafLevel.inputProperty("identifier")
450                 },
451                 dataKey: "identifiers"
452             }, {
453                 key: "name",
454                 text: leafLevel.inputProperty("name"),
455                 dataKey: "name"
456             }]
457         }]
458     },
459     dataKey: "meta.ccda_header.informant"
461 var headerCustodian = exports.headerCustodian = {
462     key: "custodian",
463     content: {
464         key: "assignedCustodian",
465         //attributes: {id:}
466         content: [{
467             key: "representedCustodianOrganization",
468             content: [
469                 {
470                     key: "id",
471                     attributes: {
472                         root: leafLevel.inputProperty("root"),
473                         extension: leafLevel.inputProperty("extension")
474                     },
475                     dataKey: "identity"
476                 }, {
477                     key: "name",
478                     text: leafLevel.input,
479                     dataKey: "name"
480                 },
481                 {
482                     key: "telecom",
483                     attributes: {
484                         value: leafLevel.inputProperty("value"),
485                         use: leafLevel.inputProperty("use")
486                     },
487                     dataTransform: translate.telecom,
488                     datakey: "phone"
489                 },
490                 {
491                     key: "addr",
492                     attributes: {
493                         use: leafLevel.use("use")
494                     },
495                     content: [{
496                         key: "country",
497                         text: leafLevel.inputProperty("country")
498                     }, {
499                         key: "state",
500                         text: leafLevel.inputProperty("state")
501                     }, {
502                         key: "city",
503                         text: leafLevel.inputProperty("city")
504                     }, {
505                         key: "postalCode",
506                         text: leafLevel.inputProperty("zip")
507                     }, {
508                         key: "streetAddressLine",
509                         text: leafLevel.input,
510                         dataKey: "street_lines"
511                     }],
512                     dataKey: "address"
513                 }
514             ],
515         }]
516     },
517     dataKey: "meta.ccda_header.custodian"
519 var headerInformationRecipient = exports.headerInformationRecipient = {
520     key: "informationRecipient",
521     content: {
522         key: "intendedRecipient",
523         content: [{
524             key: "informationRecipient",
525             content: {
526                 key: "name",
527                 content: [
528                     {
529                         key: "family",
530                         text: leafLevel.inputProperty("family")
531                     }, {
532                         key: "given",
533                         text: leafLevel.input,
534                         dataKey: "given"
535                     }, {
536                         key: "prefix",
537                         text: leafLevel.inputProperty("prefix")
538                     }, {
539                         key: "suffix",
540                         text: leafLevel.inputProperty("suffix")
541                     }],
542                 dataKey: "name",
543                 dataTransform: translate.name,
544             },
545         },
546             {
547                 key: "receivedOrganization",
548                 content: [{
549                     key: "name",
550                     text: leafLevel.inputProperty("name"),
551                     dataKey: "organization"
552                 }],
553             }]
554     },
555     dataKey: "meta.ccda_header.information_recipient"
558 /* {
559     key: "receivedOrganization",
560     content: [{
561         key: "name",
562         text: leafLevel.inputProperty("name"),
563         dataKey: "organization"
564     }],
567 var headerComponentOf = exports.headerComponentOf = {
568     key: "componentOf",
569     content: {
570         key: "encompassingEncounter",
571         content: [
572             fieldLevel.id,
573             {
574                 key: "code",
575                 attributes: leafLevel.code,
576                 existsWhen: condition.propertyNotEmpty('code'),
577                 dataKey: "code"
578             },
579             [fieldLevel.effectiveTime, key("effectiveTime"), dataKey("date_time"), required],
580             fieldLevel.responsibleParty,
581             {
582                 key: "encounterParticipant",
583                 attributes: {
584                     "typeCode": "ATND"
585                 },
586                 content: [{
587                     key: "assignedEntity",
588                     content: [{
589                         key: "id",
590                         attributes: {
591                             root: leafLevel.inputProperty("root")
592                         }
593                     }
594                         , fieldLevel.usRealmAddress
595                         , fieldLevel.telecom
596                         , {
597                             key: "assignedPerson",
598                             content: fieldLevel.usRealmName
599                         }]
600                 }],
601                 dataKey: "encounter_participant",
602                 existsWhen: condition.propertyValueNotEmpty("name.last")
603             }
604         ]
605     },
606     dataKey: "meta.ccda_header.component_of"