3 const { fetchPreviousAddresses
} = require('./previous-addresses');
4 const { fDate
} = require('../date/date');
9 } = require('../constants');
11 function getGuardianNames(display_name
) {
12 const parts
= display_name
.split(' ');
13 return parts
.length
=== 3
14 ? [{ first
: parts
[0], last
: parts
[2] }]
16 ? [{ first
: parts
[0], last
: parts
[1] }]
17 : [{ first
: NOT_INFORMED
, last
: NOT_INFORMED
}];
20 function getGuardianInfo(guardian
) {
23 relation
: guardian
.relation
,
26 street_lines
: [guardian
.address
],
28 state
: guardian
.state
,
29 zip
: guardian
.postalCode
,
30 country
: guardian
.country
|| 'US',
34 names
: getGuardianNames(guardian
.display_name
),
37 number
: guardian
.telecom
,
45 function setNullFlavorIfUnspecifiedOrEmpty(patient
, property
) {
46 if (patient
[property
] === DECLINED_TO_SPECIFY
|| patient
[property
] === '') {
47 patient
[property
] = NULL_FLAVOR
;
51 function getLanguageCode(patient
) {
52 return patient
.language
=== 'English'
54 : patient
.language
=== 'Spanish'
59 function getNpiFacility(documentData
, useFallback
) {
61 ? documentData
.encounter_provider
.facility_npi
|| NOT_INFORMED
62 : documentData
.encounter_provider
.facility_npi
;
65 function populateDemographics(documentData
, npiFacility
) {
66 const patient
= documentData
.patient
;
67 const guardian
= documentData
.guardian
;
69 documentData
.encounter_provider
.facility_oid
||
70 '2.16.840.1.113883.19.5.99999.1';
72 setNullFlavorIfUnspecifiedOrEmpty(patient
, 'race');
73 setNullFlavorIfUnspecifiedOrEmpty(patient
, 'race_group');
74 setNullFlavorIfUnspecifiedOrEmpty(patient
, 'ethnicity');
78 prefix
: patient
.prefix
,
79 suffix
: patient
.suffix
,
80 middle
: [patient
.mname
],
85 middle
: patient
.birth_mname
|| '',
86 last
: patient
.birth_lname
|| '',
87 first
: patient
.birth_fname
|| '',
91 date
: fDate(patient
.dob
),
95 gender
: patient
.gender
.toUpperCase() || NULL_FLAVOR
,
98 identifier
: oidFacility
|| npiFacility
,
99 extension
: patient
.uuid
,
102 marital_status
: patient
.status
.toUpperCase(),
103 addresses
: fetchPreviousAddresses(patient
),
106 number
: patient
.phone_home
,
107 type
: 'primary home',
110 number
: patient
.phone_mobile
,
111 type
: 'primary mobile',
114 number
: patient
.phone_work
,
118 number
: patient
.phone_emergency
,
119 type
: 'emergency contact',
122 email
: patient
.email
,
123 type
: 'contact_email',
126 ethnicity
: patient
.ethnicity
|| '',
127 race
: patient
.race
|| NULL_FLAVOR
,
128 race_additional
: patient
.race_group
|| NULL_FLAVOR
,
131 language
: getLanguageCode(patient
),
133 mode
: 'Expressed spoken',
137 attributed_provider
: {
140 root
: '2.16.840.1.113883.4.6',
141 extension
: npiFacility
|| '',
147 documentData
.encounter_provider
.facility_phone
|| '',
152 full
: documentData
.encounter_provider
.facility_name
|| '',
158 documentData
.encounter_provider
.facility_street
,
160 city
: documentData
.encounter_provider
.facility_city
,
161 state
: documentData
.encounter_provider
.facility_state
,
162 zip
: documentData
.encounter_provider
.facility_postal_code
,
164 documentData
.encounter_provider
.facility_country_code
||
171 guardians
: guardian
.display_name
? getGuardianInfo(guardian
) : '',
175 exports
.populateDemographics
= populateDemographics
;
176 exports
.getNpiFacility
= getNpiFacility
;