@onivoro/isomorphic-fhir 24.28.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +189 -0
- package/package.json +23 -0
- package/src/index.d.ts +3 -0
- package/src/index.js +6 -0
- package/src/index.js.map +1 -0
- package/src/lib/functions/fhir-test-config.d.ts +127 -0
- package/src/lib/functions/fhir-test-config.js +276 -0
- package/src/lib/functions/fhir-test-config.js.map +1 -0
- package/src/lib/functions/normalize-fhir-bundle.function.d.ts +3 -0
- package/src/lib/functions/normalize-fhir-bundle.function.js +1487 -0
- package/src/lib/functions/normalize-fhir-bundle.function.js.map +1 -0
- package/src/lib/functions/test-setup.d.ts +13 -0
- package/src/lib/functions/test-setup.js +81 -0
- package/src/lib/functions/test-setup.js.map +1 -0
- package/src/lib/interfaces/fhir-normalized-tables.interface.d.ts +594 -0
- package/src/lib/interfaces/fhir-normalized-tables.interface.js +3 -0
- package/src/lib/interfaces/fhir-normalized-tables.interface.js.map +1 -0
- package/src/lib/interfaces/fhir-resources.interface.d.ts +715 -0
- package/src/lib/interfaces/fhir-resources.interface.js +4 -0
- package/src/lib/interfaces/fhir-resources.interface.js.map +1 -0
|
@@ -0,0 +1,1487 @@
|
|
|
1
|
+
import { v4 as uuidv4 } from 'uuid';
|
|
2
|
+
export function normalizeFhirBundle(bundle) {
|
|
3
|
+
const result = {
|
|
4
|
+
bundles: [],
|
|
5
|
+
bundleEntries: [],
|
|
6
|
+
patients: [],
|
|
7
|
+
patientIdentifiers: [],
|
|
8
|
+
patientNames: [],
|
|
9
|
+
patientContacts: [],
|
|
10
|
+
practitioners: [],
|
|
11
|
+
practitionerQualifications: [],
|
|
12
|
+
organizations: [],
|
|
13
|
+
organizationTypes: [],
|
|
14
|
+
locations: [],
|
|
15
|
+
encounters: [],
|
|
16
|
+
encounterParticipants: [],
|
|
17
|
+
conditions: [],
|
|
18
|
+
observations: [],
|
|
19
|
+
observationComponents: [],
|
|
20
|
+
medicationRequests: [],
|
|
21
|
+
medicationDosages: [],
|
|
22
|
+
procedures: [],
|
|
23
|
+
procedurePerformers: [],
|
|
24
|
+
immunizations: [],
|
|
25
|
+
allergyIntolerances: [],
|
|
26
|
+
allergyReactions: [],
|
|
27
|
+
allergyManifestations: [],
|
|
28
|
+
diagnosticReports: [],
|
|
29
|
+
diagnosticReportResults: [],
|
|
30
|
+
appointments: [],
|
|
31
|
+
appointmentParticipants: [],
|
|
32
|
+
careTeams: [],
|
|
33
|
+
careTeamParticipants: [],
|
|
34
|
+
carePlans: [],
|
|
35
|
+
carePlanActivities: [],
|
|
36
|
+
addresses: [],
|
|
37
|
+
telecoms: [],
|
|
38
|
+
codeableConcepts: [],
|
|
39
|
+
codings: [],
|
|
40
|
+
notes: [],
|
|
41
|
+
attachments: [],
|
|
42
|
+
references: [],
|
|
43
|
+
};
|
|
44
|
+
// Normalize bundle
|
|
45
|
+
const bundleId = uuidv4();
|
|
46
|
+
const bundleRecord = {
|
|
47
|
+
id: bundleId,
|
|
48
|
+
resourceId: bundle.id,
|
|
49
|
+
type: bundle.type,
|
|
50
|
+
timestamp: bundle.timestamp,
|
|
51
|
+
total: bundle.total,
|
|
52
|
+
createdAt: new Date(),
|
|
53
|
+
};
|
|
54
|
+
result.bundles.push(bundleRecord);
|
|
55
|
+
// Process bundle entries
|
|
56
|
+
if (bundle.entry) {
|
|
57
|
+
bundle.entry.forEach((entry, index) => {
|
|
58
|
+
var _a, _b;
|
|
59
|
+
const entryId = uuidv4();
|
|
60
|
+
const entryRecord = {
|
|
61
|
+
id: entryId,
|
|
62
|
+
bundleId: bundleId,
|
|
63
|
+
fullUrl: entry.fullUrl,
|
|
64
|
+
searchMode: (_a = entry.search) === null || _a === void 0 ? void 0 : _a.mode,
|
|
65
|
+
searchScore: (_b = entry.search) === null || _b === void 0 ? void 0 : _b.score,
|
|
66
|
+
createdAt: new Date(),
|
|
67
|
+
};
|
|
68
|
+
if (entry.resource) {
|
|
69
|
+
entryRecord.resourceType = entry.resource.resourceType;
|
|
70
|
+
entryRecord.resourceId = entry.resource.id;
|
|
71
|
+
// Process the resource based on its type
|
|
72
|
+
processResource(entry.resource, result);
|
|
73
|
+
}
|
|
74
|
+
result.bundleEntries.push(entryRecord);
|
|
75
|
+
});
|
|
76
|
+
}
|
|
77
|
+
return result;
|
|
78
|
+
}
|
|
79
|
+
function processResource(resource, result) {
|
|
80
|
+
switch (resource.resourceType) {
|
|
81
|
+
case 'Patient':
|
|
82
|
+
processPatient(resource, result);
|
|
83
|
+
break;
|
|
84
|
+
case 'Practitioner':
|
|
85
|
+
processPractitioner(resource, result);
|
|
86
|
+
break;
|
|
87
|
+
case 'Organization':
|
|
88
|
+
processOrganization(resource, result);
|
|
89
|
+
break;
|
|
90
|
+
case 'Encounter':
|
|
91
|
+
processEncounter(resource, result);
|
|
92
|
+
break;
|
|
93
|
+
case 'Condition':
|
|
94
|
+
processCondition(resource, result);
|
|
95
|
+
break;
|
|
96
|
+
case 'Observation':
|
|
97
|
+
processObservation(resource, result);
|
|
98
|
+
break;
|
|
99
|
+
case 'MedicationRequest':
|
|
100
|
+
processMedicationRequest(resource, result);
|
|
101
|
+
break;
|
|
102
|
+
case 'Procedure':
|
|
103
|
+
processProcedure(resource, result);
|
|
104
|
+
break;
|
|
105
|
+
case 'Immunization':
|
|
106
|
+
processImmunization(resource, result);
|
|
107
|
+
break;
|
|
108
|
+
case 'AllergyIntolerance':
|
|
109
|
+
processAllergyIntolerance(resource, result);
|
|
110
|
+
break;
|
|
111
|
+
case 'DiagnosticReport':
|
|
112
|
+
processDiagnosticReport(resource, result);
|
|
113
|
+
break;
|
|
114
|
+
case 'Location':
|
|
115
|
+
processLocation(resource, result);
|
|
116
|
+
break;
|
|
117
|
+
case 'Appointment':
|
|
118
|
+
processAppointment(resource, result);
|
|
119
|
+
break;
|
|
120
|
+
case 'CareTeam':
|
|
121
|
+
processCareTeam(resource, result);
|
|
122
|
+
break;
|
|
123
|
+
case 'CarePlan':
|
|
124
|
+
processCarePlan(resource, result);
|
|
125
|
+
break;
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
function processPatient(patient, result) {
|
|
129
|
+
var _a, _b, _c, _d, _e;
|
|
130
|
+
const patientId = uuidv4();
|
|
131
|
+
// Main patient record
|
|
132
|
+
const patientRecord = {
|
|
133
|
+
id: patientId,
|
|
134
|
+
resourceId: patient.id,
|
|
135
|
+
active: patient.active,
|
|
136
|
+
gender: patient.gender,
|
|
137
|
+
birthDate: patient.birthDate,
|
|
138
|
+
deceased: typeof patient.deceased === 'boolean' ? patient.deceased : undefined,
|
|
139
|
+
deceasedDateTime: typeof patient.deceased === 'string' ? patient.deceased : undefined,
|
|
140
|
+
maritalStatus: ((_a = patient.maritalStatus) === null || _a === void 0 ? void 0 : _a.text) || ((_d = (_c = (_b = patient.maritalStatus) === null || _b === void 0 ? void 0 : _b.coding) === null || _c === void 0 ? void 0 : _c[0]) === null || _d === void 0 ? void 0 : _d.display),
|
|
141
|
+
multipleBirth: typeof patient.multipleBirth === 'boolean' ? patient.multipleBirth : undefined,
|
|
142
|
+
multipleBirthInteger: typeof patient.multipleBirth === 'number' ? patient.multipleBirth : undefined,
|
|
143
|
+
managingOrganizationId: (_e = patient.managingOrganization) === null || _e === void 0 ? void 0 : _e.reference,
|
|
144
|
+
createdAt: new Date(),
|
|
145
|
+
updatedAt: new Date(),
|
|
146
|
+
};
|
|
147
|
+
result.patients.push(patientRecord);
|
|
148
|
+
// Process identifiers
|
|
149
|
+
if (patient.identifier) {
|
|
150
|
+
patient.identifier.forEach(identifier => {
|
|
151
|
+
var _a, _b, _c;
|
|
152
|
+
result.patientIdentifiers.push({
|
|
153
|
+
id: uuidv4(),
|
|
154
|
+
patientId: patientId,
|
|
155
|
+
use: identifier.use,
|
|
156
|
+
system: identifier.system,
|
|
157
|
+
value: identifier.value,
|
|
158
|
+
periodStart: (_a = identifier.period) === null || _a === void 0 ? void 0 : _a.start,
|
|
159
|
+
periodEnd: (_b = identifier.period) === null || _b === void 0 ? void 0 : _b.end,
|
|
160
|
+
assignerReference: (_c = identifier.assigner) === null || _c === void 0 ? void 0 : _c.reference,
|
|
161
|
+
createdAt: new Date(),
|
|
162
|
+
});
|
|
163
|
+
});
|
|
164
|
+
}
|
|
165
|
+
// Process names
|
|
166
|
+
if (patient.name) {
|
|
167
|
+
patient.name.forEach(name => {
|
|
168
|
+
var _a, _b, _c, _d, _e;
|
|
169
|
+
result.patientNames.push({
|
|
170
|
+
id: uuidv4(),
|
|
171
|
+
patientId: patientId,
|
|
172
|
+
use: name.use,
|
|
173
|
+
text: name.text,
|
|
174
|
+
family: name.family,
|
|
175
|
+
given: (_a = name.given) === null || _a === void 0 ? void 0 : _a.join(' '),
|
|
176
|
+
prefix: (_b = name.prefix) === null || _b === void 0 ? void 0 : _b.join(' '),
|
|
177
|
+
suffix: (_c = name.suffix) === null || _c === void 0 ? void 0 : _c.join(' '),
|
|
178
|
+
periodStart: (_d = name.period) === null || _d === void 0 ? void 0 : _d.start,
|
|
179
|
+
periodEnd: (_e = name.period) === null || _e === void 0 ? void 0 : _e.end,
|
|
180
|
+
createdAt: new Date(),
|
|
181
|
+
});
|
|
182
|
+
});
|
|
183
|
+
}
|
|
184
|
+
// Process addresses
|
|
185
|
+
if (patient.address) {
|
|
186
|
+
patient.address.forEach(address => {
|
|
187
|
+
processAddress('Patient', patientId, address, result);
|
|
188
|
+
});
|
|
189
|
+
}
|
|
190
|
+
// Process telecom
|
|
191
|
+
if (patient.telecom) {
|
|
192
|
+
patient.telecom.forEach(telecom => {
|
|
193
|
+
processTelecom('Patient', patientId, telecom, result);
|
|
194
|
+
});
|
|
195
|
+
}
|
|
196
|
+
// Process contacts
|
|
197
|
+
if (patient.contact) {
|
|
198
|
+
patient.contact.forEach(contact => {
|
|
199
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o;
|
|
200
|
+
const contactId = uuidv4();
|
|
201
|
+
result.patientContacts.push({
|
|
202
|
+
id: contactId,
|
|
203
|
+
patientId: patientId,
|
|
204
|
+
relationshipCode: (_d = (_c = (_b = (_a = contact.relationship) === null || _a === void 0 ? void 0 : _a[0]) === null || _b === void 0 ? void 0 : _b.coding) === null || _c === void 0 ? void 0 : _c[0]) === null || _d === void 0 ? void 0 : _d.code,
|
|
205
|
+
relationshipText: (_f = (_e = contact.relationship) === null || _e === void 0 ? void 0 : _e[0]) === null || _f === void 0 ? void 0 : _f.text,
|
|
206
|
+
name: ((_g = contact.name) === null || _g === void 0 ? void 0 : _g.text) || `${(_j = (_h = contact.name) === null || _h === void 0 ? void 0 : _h.given) === null || _j === void 0 ? void 0 : _j.join(' ')} ${(_k = contact.name) === null || _k === void 0 ? void 0 : _k.family}`.trim(),
|
|
207
|
+
gender: contact.gender,
|
|
208
|
+
organizationReference: (_l = contact.organization) === null || _l === void 0 ? void 0 : _l.reference,
|
|
209
|
+
periodStart: (_m = contact.period) === null || _m === void 0 ? void 0 : _m.start,
|
|
210
|
+
periodEnd: (_o = contact.period) === null || _o === void 0 ? void 0 : _o.end,
|
|
211
|
+
createdAt: new Date(),
|
|
212
|
+
});
|
|
213
|
+
// Process contact's telecom and address
|
|
214
|
+
if (contact.telecom) {
|
|
215
|
+
contact.telecom.forEach(telecom => {
|
|
216
|
+
processTelecom('PatientContact', contactId, telecom, result);
|
|
217
|
+
});
|
|
218
|
+
}
|
|
219
|
+
if (contact.address) {
|
|
220
|
+
processAddress('PatientContact', contactId, contact.address, result);
|
|
221
|
+
}
|
|
222
|
+
});
|
|
223
|
+
}
|
|
224
|
+
// Process general practitioner references
|
|
225
|
+
if (patient.generalPractitioner) {
|
|
226
|
+
patient.generalPractitioner.forEach(gp => {
|
|
227
|
+
processReference('Patient', patientId, 'generalPractitioner', gp, result);
|
|
228
|
+
});
|
|
229
|
+
}
|
|
230
|
+
// Process photo attachments
|
|
231
|
+
if (patient.photo) {
|
|
232
|
+
patient.photo.forEach(photo => {
|
|
233
|
+
processAttachment('Patient', patientId, 'photo', photo, result);
|
|
234
|
+
});
|
|
235
|
+
}
|
|
236
|
+
// Process marital status
|
|
237
|
+
if (patient.maritalStatus) {
|
|
238
|
+
processCodeableConcept('Patient', patientId, 'maritalStatus', patient.maritalStatus, result);
|
|
239
|
+
}
|
|
240
|
+
}
|
|
241
|
+
function processPractitioner(practitioner, result) {
|
|
242
|
+
const practitionerId = uuidv4();
|
|
243
|
+
const practitionerRecord = {
|
|
244
|
+
id: practitionerId,
|
|
245
|
+
resourceId: practitioner.id,
|
|
246
|
+
active: practitioner.active,
|
|
247
|
+
gender: practitioner.gender,
|
|
248
|
+
birthDate: practitioner.birthDate,
|
|
249
|
+
createdAt: new Date(),
|
|
250
|
+
updatedAt: new Date(),
|
|
251
|
+
};
|
|
252
|
+
result.practitioners.push(practitionerRecord);
|
|
253
|
+
// Process qualifications
|
|
254
|
+
if (practitioner.qualification) {
|
|
255
|
+
practitioner.qualification.forEach(qual => {
|
|
256
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _j;
|
|
257
|
+
result.practitionerQualifications.push({
|
|
258
|
+
id: uuidv4(),
|
|
259
|
+
practitionerId: practitionerId,
|
|
260
|
+
code: (_b = (_a = qual.code.coding) === null || _a === void 0 ? void 0 : _a[0]) === null || _b === void 0 ? void 0 : _b.code,
|
|
261
|
+
codeSystem: (_d = (_c = qual.code.coding) === null || _c === void 0 ? void 0 : _c[0]) === null || _d === void 0 ? void 0 : _d.system,
|
|
262
|
+
codeDisplay: ((_f = (_e = qual.code.coding) === null || _e === void 0 ? void 0 : _e[0]) === null || _f === void 0 ? void 0 : _f.display) || qual.code.text,
|
|
263
|
+
periodStart: (_g = qual.period) === null || _g === void 0 ? void 0 : _g.start,
|
|
264
|
+
periodEnd: (_h = qual.period) === null || _h === void 0 ? void 0 : _h.end,
|
|
265
|
+
issuerReference: (_j = qual.issuer) === null || _j === void 0 ? void 0 : _j.reference,
|
|
266
|
+
createdAt: new Date(),
|
|
267
|
+
});
|
|
268
|
+
});
|
|
269
|
+
}
|
|
270
|
+
// Process other fields similar to patient
|
|
271
|
+
if (practitioner.identifier) {
|
|
272
|
+
practitioner.identifier.forEach(identifier => {
|
|
273
|
+
processIdentifier('Practitioner', practitionerId, identifier, result);
|
|
274
|
+
});
|
|
275
|
+
}
|
|
276
|
+
if (practitioner.name) {
|
|
277
|
+
practitioner.name.forEach(name => {
|
|
278
|
+
processHumanName('Practitioner', practitionerId, name, result);
|
|
279
|
+
});
|
|
280
|
+
}
|
|
281
|
+
if (practitioner.telecom) {
|
|
282
|
+
practitioner.telecom.forEach(telecom => {
|
|
283
|
+
processTelecom('Practitioner', practitionerId, telecom, result);
|
|
284
|
+
});
|
|
285
|
+
}
|
|
286
|
+
if (practitioner.address) {
|
|
287
|
+
practitioner.address.forEach(address => {
|
|
288
|
+
processAddress('Practitioner', practitionerId, address, result);
|
|
289
|
+
});
|
|
290
|
+
}
|
|
291
|
+
if (practitioner.photo) {
|
|
292
|
+
practitioner.photo.forEach(photo => {
|
|
293
|
+
processAttachment('Practitioner', practitionerId, 'photo', photo, result);
|
|
294
|
+
});
|
|
295
|
+
}
|
|
296
|
+
if (practitioner.communication) {
|
|
297
|
+
practitioner.communication.forEach(comm => {
|
|
298
|
+
processCodeableConcept('Practitioner', practitionerId, 'communication', comm, result);
|
|
299
|
+
});
|
|
300
|
+
}
|
|
301
|
+
}
|
|
302
|
+
function processOrganization(organization, result) {
|
|
303
|
+
var _a;
|
|
304
|
+
const organizationId = uuidv4();
|
|
305
|
+
const organizationRecord = {
|
|
306
|
+
id: organizationId,
|
|
307
|
+
resourceId: organization.id,
|
|
308
|
+
active: organization.active,
|
|
309
|
+
name: organization.name,
|
|
310
|
+
partOfReference: (_a = organization.partOf) === null || _a === void 0 ? void 0 : _a.reference,
|
|
311
|
+
createdAt: new Date(),
|
|
312
|
+
updatedAt: new Date(),
|
|
313
|
+
};
|
|
314
|
+
result.organizations.push(organizationRecord);
|
|
315
|
+
// Process organization types
|
|
316
|
+
if (organization.type) {
|
|
317
|
+
organization.type.forEach(type => {
|
|
318
|
+
var _a;
|
|
319
|
+
const coding = (_a = type.coding) === null || _a === void 0 ? void 0 : _a[0];
|
|
320
|
+
if (coding) {
|
|
321
|
+
result.organizationTypes.push({
|
|
322
|
+
id: uuidv4(),
|
|
323
|
+
organizationId: organizationId,
|
|
324
|
+
system: coding.system,
|
|
325
|
+
code: coding.code,
|
|
326
|
+
display: coding.display || type.text,
|
|
327
|
+
createdAt: new Date(),
|
|
328
|
+
});
|
|
329
|
+
}
|
|
330
|
+
});
|
|
331
|
+
}
|
|
332
|
+
// Process other fields
|
|
333
|
+
if (organization.identifier) {
|
|
334
|
+
organization.identifier.forEach(identifier => {
|
|
335
|
+
processIdentifier('Organization', organizationId, identifier, result);
|
|
336
|
+
});
|
|
337
|
+
}
|
|
338
|
+
if (organization.telecom) {
|
|
339
|
+
organization.telecom.forEach(telecom => {
|
|
340
|
+
processTelecom('Organization', organizationId, telecom, result);
|
|
341
|
+
});
|
|
342
|
+
}
|
|
343
|
+
if (organization.address) {
|
|
344
|
+
organization.address.forEach(address => {
|
|
345
|
+
processAddress('Organization', organizationId, address, result);
|
|
346
|
+
});
|
|
347
|
+
}
|
|
348
|
+
if (organization.endpoint) {
|
|
349
|
+
organization.endpoint.forEach(endpoint => {
|
|
350
|
+
processReference('Organization', organizationId, 'endpoint', endpoint, result);
|
|
351
|
+
});
|
|
352
|
+
}
|
|
353
|
+
}
|
|
354
|
+
function processEncounter(encounter, result) {
|
|
355
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r;
|
|
356
|
+
const encounterId = uuidv4();
|
|
357
|
+
const encounterRecord = {
|
|
358
|
+
id: encounterId,
|
|
359
|
+
resourceId: encounter.id,
|
|
360
|
+
status: encounter.status,
|
|
361
|
+
class: encounter.class.code || '',
|
|
362
|
+
classSystem: encounter.class.system,
|
|
363
|
+
classDisplay: encounter.class.display,
|
|
364
|
+
serviceType: ((_c = (_b = (_a = encounter.serviceType) === null || _a === void 0 ? void 0 : _a.coding) === null || _b === void 0 ? void 0 : _b[0]) === null || _c === void 0 ? void 0 : _c.display) || ((_d = encounter.serviceType) === null || _d === void 0 ? void 0 : _d.text),
|
|
365
|
+
priority: (_g = (_f = (_e = encounter.priority) === null || _e === void 0 ? void 0 : _e.coding) === null || _f === void 0 ? void 0 : _f[0]) === null || _g === void 0 ? void 0 : _g.code,
|
|
366
|
+
subjectReference: (_h = encounter.subject) === null || _h === void 0 ? void 0 : _h.reference,
|
|
367
|
+
episodeOfCareReference: (_k = (_j = encounter.episodeOfCare) === null || _j === void 0 ? void 0 : _j[0]) === null || _k === void 0 ? void 0 : _k.reference,
|
|
368
|
+
serviceProviderReference: (_l = encounter.serviceProvider) === null || _l === void 0 ? void 0 : _l.reference,
|
|
369
|
+
partOfReference: (_m = encounter.partOf) === null || _m === void 0 ? void 0 : _m.reference,
|
|
370
|
+
periodStart: (_o = encounter.period) === null || _o === void 0 ? void 0 : _o.start,
|
|
371
|
+
periodEnd: (_p = encounter.period) === null || _p === void 0 ? void 0 : _p.end,
|
|
372
|
+
lengthValue: (_q = encounter.length) === null || _q === void 0 ? void 0 : _q.value,
|
|
373
|
+
lengthUnit: (_r = encounter.length) === null || _r === void 0 ? void 0 : _r.unit,
|
|
374
|
+
createdAt: new Date(),
|
|
375
|
+
updatedAt: new Date(),
|
|
376
|
+
};
|
|
377
|
+
result.encounters.push(encounterRecord);
|
|
378
|
+
// Process participants
|
|
379
|
+
if (encounter.participant) {
|
|
380
|
+
encounter.participant.forEach(participant => {
|
|
381
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o;
|
|
382
|
+
result.encounterParticipants.push({
|
|
383
|
+
id: uuidv4(),
|
|
384
|
+
encounterId: encounterId,
|
|
385
|
+
typeCode: (_d = (_c = (_b = (_a = participant.type) === null || _a === void 0 ? void 0 : _a[0]) === null || _b === void 0 ? void 0 : _b.coding) === null || _c === void 0 ? void 0 : _c[0]) === null || _d === void 0 ? void 0 : _d.code,
|
|
386
|
+
typeDisplay: ((_h = (_g = (_f = (_e = participant.type) === null || _e === void 0 ? void 0 : _e[0]) === null || _f === void 0 ? void 0 : _f.coding) === null || _g === void 0 ? void 0 : _g[0]) === null || _h === void 0 ? void 0 : _h.display) || ((_k = (_j = participant.type) === null || _j === void 0 ? void 0 : _j[0]) === null || _k === void 0 ? void 0 : _k.text),
|
|
387
|
+
individualReference: (_l = participant.individual) === null || _l === void 0 ? void 0 : _l.reference,
|
|
388
|
+
periodStart: (_m = participant.period) === null || _m === void 0 ? void 0 : _m.start,
|
|
389
|
+
periodEnd: (_o = participant.period) === null || _o === void 0 ? void 0 : _o.end,
|
|
390
|
+
createdAt: new Date(),
|
|
391
|
+
});
|
|
392
|
+
});
|
|
393
|
+
}
|
|
394
|
+
// Process subject reference
|
|
395
|
+
if (encounter.subject) {
|
|
396
|
+
processReference('Encounter', encounterId, 'subject', encounter.subject, result);
|
|
397
|
+
}
|
|
398
|
+
// Process other references
|
|
399
|
+
if (encounter.identifier) {
|
|
400
|
+
encounter.identifier.forEach(identifier => {
|
|
401
|
+
processIdentifier('Encounter', encounterId, identifier, result);
|
|
402
|
+
});
|
|
403
|
+
}
|
|
404
|
+
if (encounter.basedOn) {
|
|
405
|
+
encounter.basedOn.forEach(ref => {
|
|
406
|
+
processReference('Encounter', encounterId, 'basedOn', ref, result);
|
|
407
|
+
});
|
|
408
|
+
}
|
|
409
|
+
if (encounter.appointment) {
|
|
410
|
+
encounter.appointment.forEach(ref => {
|
|
411
|
+
processReference('Encounter', encounterId, 'appointment', ref, result);
|
|
412
|
+
});
|
|
413
|
+
}
|
|
414
|
+
if (encounter.reasonCode) {
|
|
415
|
+
encounter.reasonCode.forEach(reason => {
|
|
416
|
+
processCodeableConcept('Encounter', encounterId, 'reasonCode', reason, result);
|
|
417
|
+
});
|
|
418
|
+
}
|
|
419
|
+
if (encounter.reasonReference) {
|
|
420
|
+
encounter.reasonReference.forEach(ref => {
|
|
421
|
+
processReference('Encounter', encounterId, 'reasonReference', ref, result);
|
|
422
|
+
});
|
|
423
|
+
}
|
|
424
|
+
}
|
|
425
|
+
function processCondition(condition, result) {
|
|
426
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r, _s, _t, _u, _v, _w, _x;
|
|
427
|
+
const conditionId = uuidv4();
|
|
428
|
+
const conditionRecord = {
|
|
429
|
+
id: conditionId,
|
|
430
|
+
resourceId: condition.id,
|
|
431
|
+
clinicalStatus: (_c = (_b = (_a = condition.clinicalStatus) === null || _a === void 0 ? void 0 : _a.coding) === null || _b === void 0 ? void 0 : _b[0]) === null || _c === void 0 ? void 0 : _c.code,
|
|
432
|
+
verificationStatus: (_f = (_e = (_d = condition.verificationStatus) === null || _d === void 0 ? void 0 : _d.coding) === null || _e === void 0 ? void 0 : _e[0]) === null || _f === void 0 ? void 0 : _f.code,
|
|
433
|
+
severity: (_j = (_h = (_g = condition.severity) === null || _g === void 0 ? void 0 : _g.coding) === null || _h === void 0 ? void 0 : _h[0]) === null || _j === void 0 ? void 0 : _j.code,
|
|
434
|
+
code: (_m = (_l = (_k = condition.code) === null || _k === void 0 ? void 0 : _k.coding) === null || _l === void 0 ? void 0 : _l[0]) === null || _m === void 0 ? void 0 : _m.code,
|
|
435
|
+
codeSystem: (_q = (_p = (_o = condition.code) === null || _o === void 0 ? void 0 : _o.coding) === null || _p === void 0 ? void 0 : _p[0]) === null || _q === void 0 ? void 0 : _q.system,
|
|
436
|
+
codeDisplay: ((_t = (_s = (_r = condition.code) === null || _r === void 0 ? void 0 : _r.coding) === null || _s === void 0 ? void 0 : _s[0]) === null || _t === void 0 ? void 0 : _t.display) || ((_u = condition.code) === null || _u === void 0 ? void 0 : _u.text),
|
|
437
|
+
subjectReference: condition.subject.reference || '',
|
|
438
|
+
encounterReference: (_v = condition.encounter) === null || _v === void 0 ? void 0 : _v.reference,
|
|
439
|
+
onsetDateTime: typeof condition.onset === 'string' ? condition.onset : undefined,
|
|
440
|
+
abatementDateTime: typeof condition.abatement === 'string' ? condition.abatement : undefined,
|
|
441
|
+
recordedDate: condition.recordedDate,
|
|
442
|
+
recorderReference: (_w = condition.recorder) === null || _w === void 0 ? void 0 : _w.reference,
|
|
443
|
+
asserterReference: (_x = condition.asserter) === null || _x === void 0 ? void 0 : _x.reference,
|
|
444
|
+
createdAt: new Date(),
|
|
445
|
+
updatedAt: new Date(),
|
|
446
|
+
};
|
|
447
|
+
result.conditions.push(conditionRecord);
|
|
448
|
+
// Process other fields
|
|
449
|
+
if (condition.identifier) {
|
|
450
|
+
condition.identifier.forEach(identifier => {
|
|
451
|
+
processIdentifier('Condition', conditionId, identifier, result);
|
|
452
|
+
});
|
|
453
|
+
}
|
|
454
|
+
if (condition.category) {
|
|
455
|
+
condition.category.forEach(cat => {
|
|
456
|
+
processCodeableConcept('Condition', conditionId, 'category', cat, result);
|
|
457
|
+
});
|
|
458
|
+
}
|
|
459
|
+
if (condition.bodySite) {
|
|
460
|
+
condition.bodySite.forEach(site => {
|
|
461
|
+
processCodeableConcept('Condition', conditionId, 'bodySite', site, result);
|
|
462
|
+
});
|
|
463
|
+
}
|
|
464
|
+
if (condition.note) {
|
|
465
|
+
condition.note.forEach(note => {
|
|
466
|
+
processNote('Condition', conditionId, note, result);
|
|
467
|
+
});
|
|
468
|
+
}
|
|
469
|
+
}
|
|
470
|
+
function processObservation(observation, result) {
|
|
471
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r, _s, _t, _u, _v, _w;
|
|
472
|
+
const observationId = uuidv4();
|
|
473
|
+
const observationRecord = {
|
|
474
|
+
id: observationId,
|
|
475
|
+
resourceId: observation.id,
|
|
476
|
+
status: observation.status,
|
|
477
|
+
code: ((_b = (_a = observation.code.coding) === null || _a === void 0 ? void 0 : _a[0]) === null || _b === void 0 ? void 0 : _b.code) || '',
|
|
478
|
+
codeSystem: (_d = (_c = observation.code.coding) === null || _c === void 0 ? void 0 : _c[0]) === null || _d === void 0 ? void 0 : _d.system,
|
|
479
|
+
codeDisplay: ((_f = (_e = observation.code.coding) === null || _e === void 0 ? void 0 : _e[0]) === null || _f === void 0 ? void 0 : _f.display) || observation.code.text,
|
|
480
|
+
subjectReference: (_g = observation.subject) === null || _g === void 0 ? void 0 : _g.reference,
|
|
481
|
+
encounterReference: (_h = observation.encounter) === null || _h === void 0 ? void 0 : _h.reference,
|
|
482
|
+
effectiveDateTime: typeof observation.effective === 'string' ? observation.effective : undefined,
|
|
483
|
+
effectivePeriodStart: typeof observation.effective === 'object' && observation.effective && 'start' in observation.effective ? observation.effective.start : undefined,
|
|
484
|
+
effectivePeriodEnd: typeof observation.effective === 'object' && observation.effective && 'end' in observation.effective ? observation.effective.end : undefined,
|
|
485
|
+
issued: observation.issued,
|
|
486
|
+
dataAbsentReason: (_l = (_k = (_j = observation.dataAbsentReason) === null || _j === void 0 ? void 0 : _j.coding) === null || _k === void 0 ? void 0 : _k[0]) === null || _l === void 0 ? void 0 : _l.code,
|
|
487
|
+
bodySite: ((_p = (_o = (_m = observation.bodySite) === null || _m === void 0 ? void 0 : _m.coding) === null || _o === void 0 ? void 0 : _o[0]) === null || _p === void 0 ? void 0 : _p.display) || ((_q = observation.bodySite) === null || _q === void 0 ? void 0 : _q.text),
|
|
488
|
+
method: ((_t = (_s = (_r = observation.method) === null || _r === void 0 ? void 0 : _r.coding) === null || _s === void 0 ? void 0 : _s[0]) === null || _t === void 0 ? void 0 : _t.display) || ((_u = observation.method) === null || _u === void 0 ? void 0 : _u.text),
|
|
489
|
+
specimenReference: (_v = observation.specimen) === null || _v === void 0 ? void 0 : _v.reference,
|
|
490
|
+
deviceReference: (_w = observation.device) === null || _w === void 0 ? void 0 : _w.reference,
|
|
491
|
+
createdAt: new Date(),
|
|
492
|
+
updatedAt: new Date(),
|
|
493
|
+
};
|
|
494
|
+
// Process value based on type
|
|
495
|
+
if (observation.value) {
|
|
496
|
+
if (typeof observation.value === 'string') {
|
|
497
|
+
observationRecord.valueType = 'string';
|
|
498
|
+
observationRecord.valueString = observation.value;
|
|
499
|
+
}
|
|
500
|
+
else if (typeof observation.value === 'number') {
|
|
501
|
+
observationRecord.valueType = 'number';
|
|
502
|
+
observationRecord.valueNumber = observation.value;
|
|
503
|
+
}
|
|
504
|
+
else if (typeof observation.value === 'boolean') {
|
|
505
|
+
observationRecord.valueType = 'boolean';
|
|
506
|
+
observationRecord.valueBoolean = observation.value;
|
|
507
|
+
}
|
|
508
|
+
else if (observation.value.value !== undefined) {
|
|
509
|
+
observationRecord.valueType = 'Quantity';
|
|
510
|
+
observationRecord.valueNumber = observation.value.value;
|
|
511
|
+
observationRecord.valueString = observation.value.unit;
|
|
512
|
+
}
|
|
513
|
+
}
|
|
514
|
+
result.observations.push(observationRecord);
|
|
515
|
+
// Process components
|
|
516
|
+
if (observation.component) {
|
|
517
|
+
observation.component.forEach(component => {
|
|
518
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _j;
|
|
519
|
+
const componentRecord = {
|
|
520
|
+
id: uuidv4(),
|
|
521
|
+
observationId: observationId,
|
|
522
|
+
code: ((_b = (_a = component.code.coding) === null || _a === void 0 ? void 0 : _a[0]) === null || _b === void 0 ? void 0 : _b.code) || '',
|
|
523
|
+
codeSystem: (_d = (_c = component.code.coding) === null || _c === void 0 ? void 0 : _c[0]) === null || _d === void 0 ? void 0 : _d.system,
|
|
524
|
+
codeDisplay: ((_f = (_e = component.code.coding) === null || _e === void 0 ? void 0 : _e[0]) === null || _f === void 0 ? void 0 : _f.display) || component.code.text,
|
|
525
|
+
dataAbsentReason: (_j = (_h = (_g = component.dataAbsentReason) === null || _g === void 0 ? void 0 : _g.coding) === null || _h === void 0 ? void 0 : _h[0]) === null || _j === void 0 ? void 0 : _j.code,
|
|
526
|
+
createdAt: new Date(),
|
|
527
|
+
};
|
|
528
|
+
// Process component value
|
|
529
|
+
if (component.value) {
|
|
530
|
+
if (typeof component.value === 'string') {
|
|
531
|
+
componentRecord.valueType = 'string';
|
|
532
|
+
componentRecord.valueString = component.value;
|
|
533
|
+
}
|
|
534
|
+
else if (typeof component.value === 'number') {
|
|
535
|
+
componentRecord.valueType = 'number';
|
|
536
|
+
componentRecord.valueNumber = component.value;
|
|
537
|
+
}
|
|
538
|
+
else if (typeof component.value === 'boolean') {
|
|
539
|
+
componentRecord.valueType = 'boolean';
|
|
540
|
+
componentRecord.valueBoolean = component.value;
|
|
541
|
+
}
|
|
542
|
+
else if (component.value.value !== undefined) {
|
|
543
|
+
componentRecord.valueType = 'Quantity';
|
|
544
|
+
componentRecord.valueNumber = component.value.value;
|
|
545
|
+
}
|
|
546
|
+
}
|
|
547
|
+
result.observationComponents.push(componentRecord);
|
|
548
|
+
});
|
|
549
|
+
}
|
|
550
|
+
// Process other fields
|
|
551
|
+
if (observation.identifier) {
|
|
552
|
+
observation.identifier.forEach(identifier => {
|
|
553
|
+
processIdentifier('Observation', observationId, identifier, result);
|
|
554
|
+
});
|
|
555
|
+
}
|
|
556
|
+
if (observation.basedOn) {
|
|
557
|
+
observation.basedOn.forEach(ref => {
|
|
558
|
+
processReference('Observation', observationId, 'basedOn', ref, result);
|
|
559
|
+
});
|
|
560
|
+
}
|
|
561
|
+
if (observation.partOf) {
|
|
562
|
+
observation.partOf.forEach(ref => {
|
|
563
|
+
processReference('Observation', observationId, 'partOf', ref, result);
|
|
564
|
+
});
|
|
565
|
+
}
|
|
566
|
+
if (observation.category) {
|
|
567
|
+
observation.category.forEach(cat => {
|
|
568
|
+
processCodeableConcept('Observation', observationId, 'category', cat, result);
|
|
569
|
+
});
|
|
570
|
+
}
|
|
571
|
+
if (observation.interpretation) {
|
|
572
|
+
observation.interpretation.forEach(interp => {
|
|
573
|
+
processCodeableConcept('Observation', observationId, 'interpretation', interp, result);
|
|
574
|
+
});
|
|
575
|
+
}
|
|
576
|
+
if (observation.note) {
|
|
577
|
+
observation.note.forEach(note => {
|
|
578
|
+
processNote('Observation', observationId, note, result);
|
|
579
|
+
});
|
|
580
|
+
}
|
|
581
|
+
if (observation.performer) {
|
|
582
|
+
observation.performer.forEach(ref => {
|
|
583
|
+
processReference('Observation', observationId, 'performer', ref, result);
|
|
584
|
+
});
|
|
585
|
+
}
|
|
586
|
+
if (observation.hasMember) {
|
|
587
|
+
observation.hasMember.forEach(ref => {
|
|
588
|
+
processReference('Observation', observationId, 'hasMember', ref, result);
|
|
589
|
+
});
|
|
590
|
+
}
|
|
591
|
+
if (observation.derivedFrom) {
|
|
592
|
+
observation.derivedFrom.forEach(ref => {
|
|
593
|
+
processReference('Observation', observationId, 'derivedFrom', ref, result);
|
|
594
|
+
});
|
|
595
|
+
}
|
|
596
|
+
}
|
|
597
|
+
function processMedicationRequest(medRequest, result) {
|
|
598
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r, _s;
|
|
599
|
+
const medRequestId = uuidv4();
|
|
600
|
+
const medRequestRecord = {
|
|
601
|
+
id: medRequestId,
|
|
602
|
+
resourceId: medRequest.id,
|
|
603
|
+
status: medRequest.status,
|
|
604
|
+
statusReason: (_c = (_b = (_a = medRequest.statusReason) === null || _a === void 0 ? void 0 : _a.coding) === null || _b === void 0 ? void 0 : _b[0]) === null || _c === void 0 ? void 0 : _c.code,
|
|
605
|
+
intent: medRequest.intent,
|
|
606
|
+
priority: medRequest.priority,
|
|
607
|
+
doNotPerform: medRequest.doNotPerform,
|
|
608
|
+
medicationCodeableConcept: typeof medRequest.medication === 'object' && 'coding' in medRequest.medication
|
|
609
|
+
? ((_e = (_d = medRequest.medication.coding) === null || _d === void 0 ? void 0 : _d[0]) === null || _e === void 0 ? void 0 : _e.display) || medRequest.medication.text
|
|
610
|
+
: undefined,
|
|
611
|
+
medicationReference: typeof medRequest.medication === 'object' && 'reference' in medRequest.medication
|
|
612
|
+
? medRequest.medication.reference
|
|
613
|
+
: undefined,
|
|
614
|
+
subjectReference: medRequest.subject.reference || '',
|
|
615
|
+
encounterReference: (_f = medRequest.encounter) === null || _f === void 0 ? void 0 : _f.reference,
|
|
616
|
+
authoredOn: medRequest.authoredOn,
|
|
617
|
+
requesterReference: (_g = medRequest.requester) === null || _g === void 0 ? void 0 : _g.reference,
|
|
618
|
+
performerReference: (_h = medRequest.performer) === null || _h === void 0 ? void 0 : _h.reference,
|
|
619
|
+
performerType: (_l = (_k = (_j = medRequest.performerType) === null || _j === void 0 ? void 0 : _j.coding) === null || _k === void 0 ? void 0 : _k[0]) === null || _l === void 0 ? void 0 : _l.code,
|
|
620
|
+
recorderReference: (_m = medRequest.recorder) === null || _m === void 0 ? void 0 : _m.reference,
|
|
621
|
+
groupIdentifierValue: (_o = medRequest.groupIdentifier) === null || _o === void 0 ? void 0 : _o.value,
|
|
622
|
+
courseOfTherapyType: (_r = (_q = (_p = medRequest.courseOfTherapyType) === null || _p === void 0 ? void 0 : _p.coding) === null || _q === void 0 ? void 0 : _q[0]) === null || _r === void 0 ? void 0 : _r.code,
|
|
623
|
+
priorPrescriptionReference: (_s = medRequest.priorPrescription) === null || _s === void 0 ? void 0 : _s.reference,
|
|
624
|
+
createdAt: new Date(),
|
|
625
|
+
updatedAt: new Date(),
|
|
626
|
+
};
|
|
627
|
+
result.medicationRequests.push(medRequestRecord);
|
|
628
|
+
// Process dosage instructions
|
|
629
|
+
if (medRequest.dosageInstruction) {
|
|
630
|
+
medRequest.dosageInstruction.forEach(dosage => {
|
|
631
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q;
|
|
632
|
+
const dosageRecord = {
|
|
633
|
+
id: uuidv4(),
|
|
634
|
+
medicationRequestId: medRequestId,
|
|
635
|
+
sequence: dosage.sequence,
|
|
636
|
+
text: dosage.text,
|
|
637
|
+
patientInstruction: dosage.patientInstruction,
|
|
638
|
+
asNeeded: typeof dosage.asNeeded === 'boolean' ? dosage.asNeeded : undefined,
|
|
639
|
+
asNeededCode: typeof dosage.asNeeded === 'object' ? (_b = (_a = dosage.asNeeded.coding) === null || _a === void 0 ? void 0 : _a[0]) === null || _b === void 0 ? void 0 : _b.code : undefined,
|
|
640
|
+
site: ((_e = (_d = (_c = dosage.site) === null || _c === void 0 ? void 0 : _c.coding) === null || _d === void 0 ? void 0 : _d[0]) === null || _e === void 0 ? void 0 : _e.display) || ((_f = dosage.site) === null || _f === void 0 ? void 0 : _f.text),
|
|
641
|
+
route: ((_j = (_h = (_g = dosage.route) === null || _g === void 0 ? void 0 : _g.coding) === null || _h === void 0 ? void 0 : _h[0]) === null || _j === void 0 ? void 0 : _j.display) || ((_k = dosage.route) === null || _k === void 0 ? void 0 : _k.text),
|
|
642
|
+
method: ((_o = (_m = (_l = dosage.method) === null || _l === void 0 ? void 0 : _l.coding) === null || _m === void 0 ? void 0 : _m[0]) === null || _o === void 0 ? void 0 : _o.display) || ((_p = dosage.method) === null || _p === void 0 ? void 0 : _p.text),
|
|
643
|
+
createdAt: new Date(),
|
|
644
|
+
};
|
|
645
|
+
// Process dose and rate
|
|
646
|
+
if ((_q = dosage.doseAndRate) === null || _q === void 0 ? void 0 : _q[0]) {
|
|
647
|
+
const doseAndRate = dosage.doseAndRate[0];
|
|
648
|
+
if (doseAndRate.dose && 'value' in doseAndRate.dose) {
|
|
649
|
+
dosageRecord.doseValue = doseAndRate.dose.value;
|
|
650
|
+
dosageRecord.doseUnit = doseAndRate.dose.unit;
|
|
651
|
+
dosageRecord.doseCode = doseAndRate.dose.code;
|
|
652
|
+
}
|
|
653
|
+
if (doseAndRate.rate && 'value' in doseAndRate.rate) {
|
|
654
|
+
dosageRecord.rateValue = doseAndRate.rate.value;
|
|
655
|
+
dosageRecord.rateUnit = doseAndRate.rate.unit;
|
|
656
|
+
}
|
|
657
|
+
}
|
|
658
|
+
result.medicationDosages.push(dosageRecord);
|
|
659
|
+
});
|
|
660
|
+
}
|
|
661
|
+
// Process other fields
|
|
662
|
+
if (medRequest.identifier) {
|
|
663
|
+
medRequest.identifier.forEach(identifier => {
|
|
664
|
+
processIdentifier('MedicationRequest', medRequestId, identifier, result);
|
|
665
|
+
});
|
|
666
|
+
}
|
|
667
|
+
if (medRequest.category) {
|
|
668
|
+
medRequest.category.forEach(cat => {
|
|
669
|
+
processCodeableConcept('MedicationRequest', medRequestId, 'category', cat, result);
|
|
670
|
+
});
|
|
671
|
+
}
|
|
672
|
+
if (medRequest.reasonCode) {
|
|
673
|
+
medRequest.reasonCode.forEach(reason => {
|
|
674
|
+
processCodeableConcept('MedicationRequest', medRequestId, 'reasonCode', reason, result);
|
|
675
|
+
});
|
|
676
|
+
}
|
|
677
|
+
if (medRequest.reasonReference) {
|
|
678
|
+
medRequest.reasonReference.forEach(ref => {
|
|
679
|
+
processReference('MedicationRequest', medRequestId, 'reasonReference', ref, result);
|
|
680
|
+
});
|
|
681
|
+
}
|
|
682
|
+
if (medRequest.supportingInformation) {
|
|
683
|
+
medRequest.supportingInformation.forEach(ref => {
|
|
684
|
+
processReference('MedicationRequest', medRequestId, 'supportingInformation', ref, result);
|
|
685
|
+
});
|
|
686
|
+
}
|
|
687
|
+
if (medRequest.basedOn) {
|
|
688
|
+
medRequest.basedOn.forEach(ref => {
|
|
689
|
+
processReference('MedicationRequest', medRequestId, 'basedOn', ref, result);
|
|
690
|
+
});
|
|
691
|
+
}
|
|
692
|
+
if (medRequest.insurance) {
|
|
693
|
+
medRequest.insurance.forEach(ref => {
|
|
694
|
+
processReference('MedicationRequest', medRequestId, 'insurance', ref, result);
|
|
695
|
+
});
|
|
696
|
+
}
|
|
697
|
+
if (medRequest.note) {
|
|
698
|
+
medRequest.note.forEach(note => {
|
|
699
|
+
processNote('MedicationRequest', medRequestId, note, result);
|
|
700
|
+
});
|
|
701
|
+
}
|
|
702
|
+
if (medRequest.detectedIssue) {
|
|
703
|
+
medRequest.detectedIssue.forEach(ref => {
|
|
704
|
+
processReference('MedicationRequest', medRequestId, 'detectedIssue', ref, result);
|
|
705
|
+
});
|
|
706
|
+
}
|
|
707
|
+
if (medRequest.eventHistory) {
|
|
708
|
+
medRequest.eventHistory.forEach(ref => {
|
|
709
|
+
processReference('MedicationRequest', medRequestId, 'eventHistory', ref, result);
|
|
710
|
+
});
|
|
711
|
+
}
|
|
712
|
+
}
|
|
713
|
+
function processProcedure(procedure, result) {
|
|
714
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r, _s, _t, _u, _v, _w, _x, _y;
|
|
715
|
+
const procedureId = uuidv4();
|
|
716
|
+
const procedureRecord = {
|
|
717
|
+
id: procedureId,
|
|
718
|
+
resourceId: procedure.id,
|
|
719
|
+
status: procedure.status,
|
|
720
|
+
statusReason: (_c = (_b = (_a = procedure.statusReason) === null || _a === void 0 ? void 0 : _a.coding) === null || _b === void 0 ? void 0 : _b[0]) === null || _c === void 0 ? void 0 : _c.code,
|
|
721
|
+
category: (_f = (_e = (_d = procedure.category) === null || _d === void 0 ? void 0 : _d.coding) === null || _e === void 0 ? void 0 : _e[0]) === null || _f === void 0 ? void 0 : _f.code,
|
|
722
|
+
code: (_j = (_h = (_g = procedure.code) === null || _g === void 0 ? void 0 : _g.coding) === null || _h === void 0 ? void 0 : _h[0]) === null || _j === void 0 ? void 0 : _j.code,
|
|
723
|
+
codeSystem: (_m = (_l = (_k = procedure.code) === null || _k === void 0 ? void 0 : _k.coding) === null || _l === void 0 ? void 0 : _l[0]) === null || _m === void 0 ? void 0 : _m.system,
|
|
724
|
+
codeDisplay: ((_q = (_p = (_o = procedure.code) === null || _o === void 0 ? void 0 : _o.coding) === null || _p === void 0 ? void 0 : _p[0]) === null || _q === void 0 ? void 0 : _q.display) || ((_r = procedure.code) === null || _r === void 0 ? void 0 : _r.text),
|
|
725
|
+
subjectReference: procedure.subject.reference || '',
|
|
726
|
+
encounterReference: (_s = procedure.encounter) === null || _s === void 0 ? void 0 : _s.reference,
|
|
727
|
+
performedDateTime: typeof procedure.performed === 'string' ? procedure.performed : undefined,
|
|
728
|
+
performedPeriodStart: typeof procedure.performed === 'object' && 'start' in procedure.performed ? procedure.performed.start : undefined,
|
|
729
|
+
performedPeriodEnd: typeof procedure.performed === 'object' && 'end' in procedure.performed ? procedure.performed.end : undefined,
|
|
730
|
+
recorderReference: (_t = procedure.recorder) === null || _t === void 0 ? void 0 : _t.reference,
|
|
731
|
+
asserterReference: (_u = procedure.asserter) === null || _u === void 0 ? void 0 : _u.reference,
|
|
732
|
+
locationReference: (_v = procedure.location) === null || _v === void 0 ? void 0 : _v.reference,
|
|
733
|
+
outcome: (_y = (_x = (_w = procedure.outcome) === null || _w === void 0 ? void 0 : _w.coding) === null || _x === void 0 ? void 0 : _x[0]) === null || _y === void 0 ? void 0 : _y.code,
|
|
734
|
+
createdAt: new Date(),
|
|
735
|
+
updatedAt: new Date(),
|
|
736
|
+
};
|
|
737
|
+
result.procedures.push(procedureRecord);
|
|
738
|
+
// Process performers
|
|
739
|
+
if (procedure.performer) {
|
|
740
|
+
procedure.performer.forEach(performer => {
|
|
741
|
+
var _a, _b, _c, _d;
|
|
742
|
+
result.procedurePerformers.push({
|
|
743
|
+
id: uuidv4(),
|
|
744
|
+
procedureId: procedureId,
|
|
745
|
+
function: (_c = (_b = (_a = performer.function) === null || _a === void 0 ? void 0 : _a.coding) === null || _b === void 0 ? void 0 : _b[0]) === null || _c === void 0 ? void 0 : _c.code,
|
|
746
|
+
actorReference: performer.actor.reference || '',
|
|
747
|
+
onBehalfOfReference: (_d = performer.onBehalfOf) === null || _d === void 0 ? void 0 : _d.reference,
|
|
748
|
+
createdAt: new Date(),
|
|
749
|
+
});
|
|
750
|
+
});
|
|
751
|
+
}
|
|
752
|
+
// Process other fields
|
|
753
|
+
if (procedure.identifier) {
|
|
754
|
+
procedure.identifier.forEach(identifier => {
|
|
755
|
+
processIdentifier('Procedure', procedureId, identifier, result);
|
|
756
|
+
});
|
|
757
|
+
}
|
|
758
|
+
if (procedure.basedOn) {
|
|
759
|
+
procedure.basedOn.forEach(ref => {
|
|
760
|
+
processReference('Procedure', procedureId, 'basedOn', ref, result);
|
|
761
|
+
});
|
|
762
|
+
}
|
|
763
|
+
if (procedure.partOf) {
|
|
764
|
+
procedure.partOf.forEach(ref => {
|
|
765
|
+
processReference('Procedure', procedureId, 'partOf', ref, result);
|
|
766
|
+
});
|
|
767
|
+
}
|
|
768
|
+
if (procedure.reasonCode) {
|
|
769
|
+
procedure.reasonCode.forEach(reason => {
|
|
770
|
+
processCodeableConcept('Procedure', procedureId, 'reasonCode', reason, result);
|
|
771
|
+
});
|
|
772
|
+
}
|
|
773
|
+
if (procedure.reasonReference) {
|
|
774
|
+
procedure.reasonReference.forEach(ref => {
|
|
775
|
+
processReference('Procedure', procedureId, 'reasonReference', ref, result);
|
|
776
|
+
});
|
|
777
|
+
}
|
|
778
|
+
if (procedure.bodySite) {
|
|
779
|
+
procedure.bodySite.forEach(site => {
|
|
780
|
+
processCodeableConcept('Procedure', procedureId, 'bodySite', site, result);
|
|
781
|
+
});
|
|
782
|
+
}
|
|
783
|
+
if (procedure.report) {
|
|
784
|
+
procedure.report.forEach(ref => {
|
|
785
|
+
processReference('Procedure', procedureId, 'report', ref, result);
|
|
786
|
+
});
|
|
787
|
+
}
|
|
788
|
+
if (procedure.complication) {
|
|
789
|
+
procedure.complication.forEach(comp => {
|
|
790
|
+
processCodeableConcept('Procedure', procedureId, 'complication', comp, result);
|
|
791
|
+
});
|
|
792
|
+
}
|
|
793
|
+
if (procedure.complicationDetail) {
|
|
794
|
+
procedure.complicationDetail.forEach(ref => {
|
|
795
|
+
processReference('Procedure', procedureId, 'complicationDetail', ref, result);
|
|
796
|
+
});
|
|
797
|
+
}
|
|
798
|
+
if (procedure.followUp) {
|
|
799
|
+
procedure.followUp.forEach(followUp => {
|
|
800
|
+
processCodeableConcept('Procedure', procedureId, 'followUp', followUp, result);
|
|
801
|
+
});
|
|
802
|
+
}
|
|
803
|
+
if (procedure.note) {
|
|
804
|
+
procedure.note.forEach(note => {
|
|
805
|
+
processNote('Procedure', procedureId, note, result);
|
|
806
|
+
});
|
|
807
|
+
}
|
|
808
|
+
if (procedure.usedReference) {
|
|
809
|
+
procedure.usedReference.forEach(ref => {
|
|
810
|
+
processReference('Procedure', procedureId, 'usedReference', ref, result);
|
|
811
|
+
});
|
|
812
|
+
}
|
|
813
|
+
if (procedure.usedCode) {
|
|
814
|
+
procedure.usedCode.forEach(code => {
|
|
815
|
+
processCodeableConcept('Procedure', procedureId, 'usedCode', code, result);
|
|
816
|
+
});
|
|
817
|
+
}
|
|
818
|
+
}
|
|
819
|
+
function processImmunization(immunization, result) {
|
|
820
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r, _s, _t, _u, _v, _w, _x, _y, _z, _0, _1, _2, _3;
|
|
821
|
+
const immunizationId = uuidv4();
|
|
822
|
+
const immunizationRecord = {
|
|
823
|
+
id: immunizationId,
|
|
824
|
+
resourceId: immunization.id,
|
|
825
|
+
status: immunization.status,
|
|
826
|
+
statusReason: (_c = (_b = (_a = immunization.statusReason) === null || _a === void 0 ? void 0 : _a.coding) === null || _b === void 0 ? void 0 : _b[0]) === null || _c === void 0 ? void 0 : _c.code,
|
|
827
|
+
vaccineCode: ((_e = (_d = immunization.vaccineCode.coding) === null || _d === void 0 ? void 0 : _d[0]) === null || _e === void 0 ? void 0 : _e.code) || '',
|
|
828
|
+
vaccineCodeSystem: (_g = (_f = immunization.vaccineCode.coding) === null || _f === void 0 ? void 0 : _f[0]) === null || _g === void 0 ? void 0 : _g.system,
|
|
829
|
+
vaccineCodeDisplay: ((_j = (_h = immunization.vaccineCode.coding) === null || _h === void 0 ? void 0 : _h[0]) === null || _j === void 0 ? void 0 : _j.display) || immunization.vaccineCode.text,
|
|
830
|
+
patientReference: immunization.patient.reference || '',
|
|
831
|
+
encounterReference: (_k = immunization.encounter) === null || _k === void 0 ? void 0 : _k.reference,
|
|
832
|
+
occurrenceDateTime: typeof immunization.occurrence === 'string' ? immunization.occurrence : undefined,
|
|
833
|
+
recorded: immunization.recorded,
|
|
834
|
+
primarySource: immunization.primarySource,
|
|
835
|
+
reportOrigin: (_o = (_m = (_l = immunization.reportOrigin) === null || _l === void 0 ? void 0 : _l.coding) === null || _m === void 0 ? void 0 : _m[0]) === null || _o === void 0 ? void 0 : _o.code,
|
|
836
|
+
locationReference: (_p = immunization.location) === null || _p === void 0 ? void 0 : _p.reference,
|
|
837
|
+
manufacturerReference: (_q = immunization.manufacturer) === null || _q === void 0 ? void 0 : _q.reference,
|
|
838
|
+
lotNumber: immunization.lotNumber,
|
|
839
|
+
expirationDate: immunization.expirationDate,
|
|
840
|
+
site: ((_t = (_s = (_r = immunization.site) === null || _r === void 0 ? void 0 : _r.coding) === null || _s === void 0 ? void 0 : _s[0]) === null || _t === void 0 ? void 0 : _t.display) || ((_u = immunization.site) === null || _u === void 0 ? void 0 : _u.text),
|
|
841
|
+
route: ((_x = (_w = (_v = immunization.route) === null || _v === void 0 ? void 0 : _v.coding) === null || _w === void 0 ? void 0 : _w[0]) === null || _x === void 0 ? void 0 : _x.display) || ((_y = immunization.route) === null || _y === void 0 ? void 0 : _y.text),
|
|
842
|
+
doseQuantityValue: (_z = immunization.doseQuantity) === null || _z === void 0 ? void 0 : _z.value,
|
|
843
|
+
doseQuantityUnit: (_0 = immunization.doseQuantity) === null || _0 === void 0 ? void 0 : _0.unit,
|
|
844
|
+
isSubpotent: immunization.isSubpotent,
|
|
845
|
+
fundingSource: (_3 = (_2 = (_1 = immunization.fundingSource) === null || _1 === void 0 ? void 0 : _1.coding) === null || _2 === void 0 ? void 0 : _2[0]) === null || _3 === void 0 ? void 0 : _3.code,
|
|
846
|
+
createdAt: new Date(),
|
|
847
|
+
updatedAt: new Date(),
|
|
848
|
+
};
|
|
849
|
+
result.immunizations.push(immunizationRecord);
|
|
850
|
+
// Process other fields
|
|
851
|
+
if (immunization.identifier) {
|
|
852
|
+
immunization.identifier.forEach(identifier => {
|
|
853
|
+
processIdentifier('Immunization', immunizationId, identifier, result);
|
|
854
|
+
});
|
|
855
|
+
}
|
|
856
|
+
if (immunization.reasonCode) {
|
|
857
|
+
immunization.reasonCode.forEach(reason => {
|
|
858
|
+
processCodeableConcept('Immunization', immunizationId, 'reasonCode', reason, result);
|
|
859
|
+
});
|
|
860
|
+
}
|
|
861
|
+
if (immunization.reasonReference) {
|
|
862
|
+
immunization.reasonReference.forEach(ref => {
|
|
863
|
+
processReference('Immunization', immunizationId, 'reasonReference', ref, result);
|
|
864
|
+
});
|
|
865
|
+
}
|
|
866
|
+
if (immunization.subpotentReason) {
|
|
867
|
+
immunization.subpotentReason.forEach(reason => {
|
|
868
|
+
processCodeableConcept('Immunization', immunizationId, 'subpotentReason', reason, result);
|
|
869
|
+
});
|
|
870
|
+
}
|
|
871
|
+
if (immunization.programEligibility) {
|
|
872
|
+
immunization.programEligibility.forEach(prog => {
|
|
873
|
+
processCodeableConcept('Immunization', immunizationId, 'programEligibility', prog, result);
|
|
874
|
+
});
|
|
875
|
+
}
|
|
876
|
+
if (immunization.note) {
|
|
877
|
+
immunization.note.forEach(note => {
|
|
878
|
+
processNote('Immunization', immunizationId, note, result);
|
|
879
|
+
});
|
|
880
|
+
}
|
|
881
|
+
}
|
|
882
|
+
function processAllergyIntolerance(allergy, result) {
|
|
883
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r, _s, _t, _u;
|
|
884
|
+
const allergyId = uuidv4();
|
|
885
|
+
const allergyRecord = {
|
|
886
|
+
id: allergyId,
|
|
887
|
+
resourceId: allergy.id,
|
|
888
|
+
clinicalStatus: (_c = (_b = (_a = allergy.clinicalStatus) === null || _a === void 0 ? void 0 : _a.coding) === null || _b === void 0 ? void 0 : _b[0]) === null || _c === void 0 ? void 0 : _c.code,
|
|
889
|
+
verificationStatus: (_f = (_e = (_d = allergy.verificationStatus) === null || _d === void 0 ? void 0 : _d.coding) === null || _e === void 0 ? void 0 : _e[0]) === null || _f === void 0 ? void 0 : _f.code,
|
|
890
|
+
type: allergy.type,
|
|
891
|
+
criticality: allergy.criticality,
|
|
892
|
+
code: (_j = (_h = (_g = allergy.code) === null || _g === void 0 ? void 0 : _g.coding) === null || _h === void 0 ? void 0 : _h[0]) === null || _j === void 0 ? void 0 : _j.code,
|
|
893
|
+
codeSystem: (_m = (_l = (_k = allergy.code) === null || _k === void 0 ? void 0 : _k.coding) === null || _l === void 0 ? void 0 : _l[0]) === null || _m === void 0 ? void 0 : _m.system,
|
|
894
|
+
codeDisplay: ((_q = (_p = (_o = allergy.code) === null || _o === void 0 ? void 0 : _o.coding) === null || _p === void 0 ? void 0 : _p[0]) === null || _q === void 0 ? void 0 : _q.display) || ((_r = allergy.code) === null || _r === void 0 ? void 0 : _r.text),
|
|
895
|
+
patientReference: allergy.patient.reference || '',
|
|
896
|
+
encounterReference: (_s = allergy.encounter) === null || _s === void 0 ? void 0 : _s.reference,
|
|
897
|
+
onsetDateTime: typeof allergy.onset === 'string' ? allergy.onset : undefined,
|
|
898
|
+
recordedDate: allergy.recordedDate,
|
|
899
|
+
recorderReference: (_t = allergy.recorder) === null || _t === void 0 ? void 0 : _t.reference,
|
|
900
|
+
asserterReference: (_u = allergy.asserter) === null || _u === void 0 ? void 0 : _u.reference,
|
|
901
|
+
lastOccurrence: allergy.lastOccurrence,
|
|
902
|
+
createdAt: new Date(),
|
|
903
|
+
updatedAt: new Date(),
|
|
904
|
+
};
|
|
905
|
+
result.allergyIntolerances.push(allergyRecord);
|
|
906
|
+
// Process reactions
|
|
907
|
+
if (allergy.reaction) {
|
|
908
|
+
allergy.reaction.forEach(reaction => {
|
|
909
|
+
var _a, _b, _c, _d, _e, _f, _g, _h;
|
|
910
|
+
const reactionId = uuidv4();
|
|
911
|
+
const reactionRecord = {
|
|
912
|
+
id: reactionId,
|
|
913
|
+
allergyIntoleranceId: allergyId,
|
|
914
|
+
substance: ((_c = (_b = (_a = reaction.substance) === null || _a === void 0 ? void 0 : _a.coding) === null || _b === void 0 ? void 0 : _b[0]) === null || _c === void 0 ? void 0 : _c.display) || ((_d = reaction.substance) === null || _d === void 0 ? void 0 : _d.text),
|
|
915
|
+
description: reaction.description,
|
|
916
|
+
onset: reaction.onset,
|
|
917
|
+
severity: reaction.severity,
|
|
918
|
+
exposureRoute: ((_g = (_f = (_e = reaction.exposureRoute) === null || _e === void 0 ? void 0 : _e.coding) === null || _f === void 0 ? void 0 : _f[0]) === null || _g === void 0 ? void 0 : _g.display) || ((_h = reaction.exposureRoute) === null || _h === void 0 ? void 0 : _h.text),
|
|
919
|
+
createdAt: new Date(),
|
|
920
|
+
};
|
|
921
|
+
result.allergyReactions.push(reactionRecord);
|
|
922
|
+
// Process manifestations
|
|
923
|
+
if (reaction.manifestation) {
|
|
924
|
+
reaction.manifestation.forEach(manifestation => {
|
|
925
|
+
var _a, _b, _c, _d, _e, _f;
|
|
926
|
+
result.allergyManifestations.push({
|
|
927
|
+
id: uuidv4(),
|
|
928
|
+
allergyReactionId: reactionId,
|
|
929
|
+
code: (_b = (_a = manifestation.coding) === null || _a === void 0 ? void 0 : _a[0]) === null || _b === void 0 ? void 0 : _b.code,
|
|
930
|
+
codeSystem: (_d = (_c = manifestation.coding) === null || _c === void 0 ? void 0 : _c[0]) === null || _d === void 0 ? void 0 : _d.system,
|
|
931
|
+
codeDisplay: ((_f = (_e = manifestation.coding) === null || _e === void 0 ? void 0 : _e[0]) === null || _f === void 0 ? void 0 : _f.display) || manifestation.text,
|
|
932
|
+
createdAt: new Date(),
|
|
933
|
+
});
|
|
934
|
+
});
|
|
935
|
+
}
|
|
936
|
+
// Process reaction notes
|
|
937
|
+
if (reaction.note) {
|
|
938
|
+
reaction.note.forEach(note => {
|
|
939
|
+
processNote('AllergyReaction', reactionId, note, result);
|
|
940
|
+
});
|
|
941
|
+
}
|
|
942
|
+
});
|
|
943
|
+
}
|
|
944
|
+
// Process other fields
|
|
945
|
+
if (allergy.identifier) {
|
|
946
|
+
allergy.identifier.forEach(identifier => {
|
|
947
|
+
processIdentifier('AllergyIntolerance', allergyId, identifier, result);
|
|
948
|
+
});
|
|
949
|
+
}
|
|
950
|
+
if (allergy.category) {
|
|
951
|
+
allergy.category.forEach(cat => {
|
|
952
|
+
processCodeableConcept('AllergyIntolerance', allergyId, 'category', { text: cat }, result);
|
|
953
|
+
});
|
|
954
|
+
}
|
|
955
|
+
if (allergy.note) {
|
|
956
|
+
allergy.note.forEach(note => {
|
|
957
|
+
processNote('AllergyIntolerance', allergyId, note, result);
|
|
958
|
+
});
|
|
959
|
+
}
|
|
960
|
+
}
|
|
961
|
+
function processDiagnosticReport(report, result) {
|
|
962
|
+
var _a, _b, _c, _d, _e, _f, _g, _h;
|
|
963
|
+
const reportId = uuidv4();
|
|
964
|
+
const reportRecord = {
|
|
965
|
+
id: reportId,
|
|
966
|
+
resourceId: report.id,
|
|
967
|
+
status: report.status,
|
|
968
|
+
code: ((_b = (_a = report.code.coding) === null || _a === void 0 ? void 0 : _a[0]) === null || _b === void 0 ? void 0 : _b.code) || '',
|
|
969
|
+
codeSystem: (_d = (_c = report.code.coding) === null || _c === void 0 ? void 0 : _c[0]) === null || _d === void 0 ? void 0 : _d.system,
|
|
970
|
+
codeDisplay: ((_f = (_e = report.code.coding) === null || _e === void 0 ? void 0 : _e[0]) === null || _f === void 0 ? void 0 : _f.display) || report.code.text,
|
|
971
|
+
subjectReference: (_g = report.subject) === null || _g === void 0 ? void 0 : _g.reference,
|
|
972
|
+
encounterReference: (_h = report.encounter) === null || _h === void 0 ? void 0 : _h.reference,
|
|
973
|
+
effectiveDateTime: typeof report.effective === 'string' ? report.effective : undefined,
|
|
974
|
+
effectivePeriodStart: typeof report.effective === 'object' ? report.effective.start : undefined,
|
|
975
|
+
effectivePeriodEnd: typeof report.effective === 'object' ? report.effective.end : undefined,
|
|
976
|
+
issued: report.issued,
|
|
977
|
+
conclusion: report.conclusion,
|
|
978
|
+
createdAt: new Date(),
|
|
979
|
+
updatedAt: new Date(),
|
|
980
|
+
};
|
|
981
|
+
result.diagnosticReports.push(reportRecord);
|
|
982
|
+
// Process results
|
|
983
|
+
if (report.result) {
|
|
984
|
+
report.result.forEach(resultRef => {
|
|
985
|
+
result.diagnosticReportResults.push({
|
|
986
|
+
id: uuidv4(),
|
|
987
|
+
diagnosticReportId: reportId,
|
|
988
|
+
resultReference: resultRef.reference || '',
|
|
989
|
+
createdAt: new Date(),
|
|
990
|
+
});
|
|
991
|
+
});
|
|
992
|
+
}
|
|
993
|
+
// Process other fields
|
|
994
|
+
if (report.identifier) {
|
|
995
|
+
report.identifier.forEach(identifier => {
|
|
996
|
+
processIdentifier('DiagnosticReport', reportId, identifier, result);
|
|
997
|
+
});
|
|
998
|
+
}
|
|
999
|
+
if (report.basedOn) {
|
|
1000
|
+
report.basedOn.forEach(ref => {
|
|
1001
|
+
processReference('DiagnosticReport', reportId, 'basedOn', ref, result);
|
|
1002
|
+
});
|
|
1003
|
+
}
|
|
1004
|
+
if (report.category) {
|
|
1005
|
+
report.category.forEach(cat => {
|
|
1006
|
+
processCodeableConcept('DiagnosticReport', reportId, 'category', cat, result);
|
|
1007
|
+
});
|
|
1008
|
+
}
|
|
1009
|
+
if (report.performer) {
|
|
1010
|
+
report.performer.forEach(ref => {
|
|
1011
|
+
processReference('DiagnosticReport', reportId, 'performer', ref, result);
|
|
1012
|
+
});
|
|
1013
|
+
}
|
|
1014
|
+
if (report.resultsInterpreter) {
|
|
1015
|
+
report.resultsInterpreter.forEach(ref => {
|
|
1016
|
+
processReference('DiagnosticReport', reportId, 'resultsInterpreter', ref, result);
|
|
1017
|
+
});
|
|
1018
|
+
}
|
|
1019
|
+
if (report.specimen) {
|
|
1020
|
+
report.specimen.forEach(ref => {
|
|
1021
|
+
processReference('DiagnosticReport', reportId, 'specimen', ref, result);
|
|
1022
|
+
});
|
|
1023
|
+
}
|
|
1024
|
+
if (report.imagingStudy) {
|
|
1025
|
+
report.imagingStudy.forEach(ref => {
|
|
1026
|
+
processReference('DiagnosticReport', reportId, 'imagingStudy', ref, result);
|
|
1027
|
+
});
|
|
1028
|
+
}
|
|
1029
|
+
if (report.conclusionCode) {
|
|
1030
|
+
report.conclusionCode.forEach(code => {
|
|
1031
|
+
processCodeableConcept('DiagnosticReport', reportId, 'conclusionCode', code, result);
|
|
1032
|
+
});
|
|
1033
|
+
}
|
|
1034
|
+
if (report.presentedForm) {
|
|
1035
|
+
report.presentedForm.forEach(form => {
|
|
1036
|
+
processAttachment('DiagnosticReport', reportId, 'presentedForm', form, result);
|
|
1037
|
+
});
|
|
1038
|
+
}
|
|
1039
|
+
}
|
|
1040
|
+
function processLocation(location, result) {
|
|
1041
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k;
|
|
1042
|
+
const locationId = uuidv4();
|
|
1043
|
+
const locationRecord = {
|
|
1044
|
+
id: locationId,
|
|
1045
|
+
resourceId: location.id,
|
|
1046
|
+
status: location.status,
|
|
1047
|
+
operationalStatus: (_a = location.operationalStatus) === null || _a === void 0 ? void 0 : _a.code,
|
|
1048
|
+
name: location.name,
|
|
1049
|
+
description: location.description,
|
|
1050
|
+
mode: location.mode,
|
|
1051
|
+
physicalType: ((_d = (_c = (_b = location.physicalType) === null || _b === void 0 ? void 0 : _b.coding) === null || _c === void 0 ? void 0 : _c[0]) === null || _d === void 0 ? void 0 : _d.display) || ((_e = location.physicalType) === null || _e === void 0 ? void 0 : _e.text),
|
|
1052
|
+
latitude: (_f = location.position) === null || _f === void 0 ? void 0 : _f.latitude,
|
|
1053
|
+
longitude: (_g = location.position) === null || _g === void 0 ? void 0 : _g.longitude,
|
|
1054
|
+
altitude: (_h = location.position) === null || _h === void 0 ? void 0 : _h.altitude,
|
|
1055
|
+
managingOrganizationReference: (_j = location.managingOrganization) === null || _j === void 0 ? void 0 : _j.reference,
|
|
1056
|
+
partOfReference: (_k = location.partOf) === null || _k === void 0 ? void 0 : _k.reference,
|
|
1057
|
+
availabilityExceptions: location.availabilityExceptions,
|
|
1058
|
+
createdAt: new Date(),
|
|
1059
|
+
updatedAt: new Date(),
|
|
1060
|
+
};
|
|
1061
|
+
result.locations.push(locationRecord);
|
|
1062
|
+
// Process other fields
|
|
1063
|
+
if (location.identifier) {
|
|
1064
|
+
location.identifier.forEach(identifier => {
|
|
1065
|
+
processIdentifier('Location', locationId, identifier, result);
|
|
1066
|
+
});
|
|
1067
|
+
}
|
|
1068
|
+
if (location.alias) {
|
|
1069
|
+
location.alias.forEach((alias, index) => {
|
|
1070
|
+
processCodeableConcept('Location', locationId, `alias[${index}]`, { text: alias }, result);
|
|
1071
|
+
});
|
|
1072
|
+
}
|
|
1073
|
+
if (location.type) {
|
|
1074
|
+
location.type.forEach(type => {
|
|
1075
|
+
processCodeableConcept('Location', locationId, 'type', type, result);
|
|
1076
|
+
});
|
|
1077
|
+
}
|
|
1078
|
+
if (location.telecom) {
|
|
1079
|
+
location.telecom.forEach(telecom => {
|
|
1080
|
+
processTelecom('Location', locationId, telecom, result);
|
|
1081
|
+
});
|
|
1082
|
+
}
|
|
1083
|
+
if (location.address) {
|
|
1084
|
+
processAddress('Location', locationId, location.address, result);
|
|
1085
|
+
}
|
|
1086
|
+
if (location.endpoint) {
|
|
1087
|
+
location.endpoint.forEach(ref => {
|
|
1088
|
+
processReference('Location', locationId, 'endpoint', ref, result);
|
|
1089
|
+
});
|
|
1090
|
+
}
|
|
1091
|
+
}
|
|
1092
|
+
function processAppointment(appointment, result) {
|
|
1093
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r, _s, _t, _u, _v, _w, _x, _y, _z, _0;
|
|
1094
|
+
const appointmentId = uuidv4();
|
|
1095
|
+
const appointmentRecord = {
|
|
1096
|
+
id: appointmentId,
|
|
1097
|
+
resourceId: appointment.id,
|
|
1098
|
+
status: appointment.status,
|
|
1099
|
+
cancelationReason: (_c = (_b = (_a = appointment.cancelationReason) === null || _a === void 0 ? void 0 : _a.coding) === null || _b === void 0 ? void 0 : _b[0]) === null || _c === void 0 ? void 0 : _c.code,
|
|
1100
|
+
serviceCategory: ((_g = (_f = (_e = (_d = appointment.serviceCategory) === null || _d === void 0 ? void 0 : _d[0]) === null || _e === void 0 ? void 0 : _e.coding) === null || _f === void 0 ? void 0 : _f[0]) === null || _g === void 0 ? void 0 : _g.display) || ((_j = (_h = appointment.serviceCategory) === null || _h === void 0 ? void 0 : _h[0]) === null || _j === void 0 ? void 0 : _j.text),
|
|
1101
|
+
serviceType: ((_o = (_m = (_l = (_k = appointment.serviceType) === null || _k === void 0 ? void 0 : _k[0]) === null || _l === void 0 ? void 0 : _l.coding) === null || _m === void 0 ? void 0 : _m[0]) === null || _o === void 0 ? void 0 : _o.display) || ((_q = (_p = appointment.serviceType) === null || _p === void 0 ? void 0 : _p[0]) === null || _q === void 0 ? void 0 : _q.text),
|
|
1102
|
+
specialty: ((_u = (_t = (_s = (_r = appointment.specialty) === null || _r === void 0 ? void 0 : _r[0]) === null || _s === void 0 ? void 0 : _s.coding) === null || _t === void 0 ? void 0 : _t[0]) === null || _u === void 0 ? void 0 : _u.display) || ((_w = (_v = appointment.specialty) === null || _v === void 0 ? void 0 : _v[0]) === null || _w === void 0 ? void 0 : _w.text),
|
|
1103
|
+
appointmentType: ((_z = (_y = (_x = appointment.appointmentType) === null || _x === void 0 ? void 0 : _x.coding) === null || _y === void 0 ? void 0 : _y[0]) === null || _z === void 0 ? void 0 : _z.display) || ((_0 = appointment.appointmentType) === null || _0 === void 0 ? void 0 : _0.text),
|
|
1104
|
+
priority: appointment.priority,
|
|
1105
|
+
description: appointment.description,
|
|
1106
|
+
start: appointment.start,
|
|
1107
|
+
end: appointment.end,
|
|
1108
|
+
minutesDuration: appointment.minutesDuration,
|
|
1109
|
+
created: appointment.created,
|
|
1110
|
+
comment: appointment.comment,
|
|
1111
|
+
patientInstruction: appointment.patientInstruction,
|
|
1112
|
+
createdAt: new Date(),
|
|
1113
|
+
updatedAt: new Date(),
|
|
1114
|
+
};
|
|
1115
|
+
result.appointments.push(appointmentRecord);
|
|
1116
|
+
// Process participants
|
|
1117
|
+
if (appointment.participant) {
|
|
1118
|
+
appointment.participant.forEach(participant => {
|
|
1119
|
+
var _a, _b, _c, _d, _e, _f, _g;
|
|
1120
|
+
result.appointmentParticipants.push({
|
|
1121
|
+
id: uuidv4(),
|
|
1122
|
+
appointmentId: appointmentId,
|
|
1123
|
+
type: (_d = (_c = (_b = (_a = participant.type) === null || _a === void 0 ? void 0 : _a[0]) === null || _b === void 0 ? void 0 : _b.coding) === null || _c === void 0 ? void 0 : _c[0]) === null || _d === void 0 ? void 0 : _d.code,
|
|
1124
|
+
actorReference: (_e = participant.actor) === null || _e === void 0 ? void 0 : _e.reference,
|
|
1125
|
+
required: participant.required,
|
|
1126
|
+
status: participant.status,
|
|
1127
|
+
periodStart: (_f = participant.period) === null || _f === void 0 ? void 0 : _f.start,
|
|
1128
|
+
periodEnd: (_g = participant.period) === null || _g === void 0 ? void 0 : _g.end,
|
|
1129
|
+
createdAt: new Date(),
|
|
1130
|
+
});
|
|
1131
|
+
});
|
|
1132
|
+
}
|
|
1133
|
+
// Process other fields
|
|
1134
|
+
if (appointment.identifier) {
|
|
1135
|
+
appointment.identifier.forEach(identifier => {
|
|
1136
|
+
processIdentifier('Appointment', appointmentId, identifier, result);
|
|
1137
|
+
});
|
|
1138
|
+
}
|
|
1139
|
+
if (appointment.reasonCode) {
|
|
1140
|
+
appointment.reasonCode.forEach(reason => {
|
|
1141
|
+
processCodeableConcept('Appointment', appointmentId, 'reasonCode', reason, result);
|
|
1142
|
+
});
|
|
1143
|
+
}
|
|
1144
|
+
if (appointment.reasonReference) {
|
|
1145
|
+
appointment.reasonReference.forEach(ref => {
|
|
1146
|
+
processReference('Appointment', appointmentId, 'reasonReference', ref, result);
|
|
1147
|
+
});
|
|
1148
|
+
}
|
|
1149
|
+
if (appointment.supportingInformation) {
|
|
1150
|
+
appointment.supportingInformation.forEach(ref => {
|
|
1151
|
+
processReference('Appointment', appointmentId, 'supportingInformation', ref, result);
|
|
1152
|
+
});
|
|
1153
|
+
}
|
|
1154
|
+
if (appointment.slot) {
|
|
1155
|
+
appointment.slot.forEach(ref => {
|
|
1156
|
+
processReference('Appointment', appointmentId, 'slot', ref, result);
|
|
1157
|
+
});
|
|
1158
|
+
}
|
|
1159
|
+
if (appointment.basedOn) {
|
|
1160
|
+
appointment.basedOn.forEach(ref => {
|
|
1161
|
+
processReference('Appointment', appointmentId, 'basedOn', ref, result);
|
|
1162
|
+
});
|
|
1163
|
+
}
|
|
1164
|
+
}
|
|
1165
|
+
function processCareTeam(careTeam, result) {
|
|
1166
|
+
var _a, _b, _c, _d;
|
|
1167
|
+
const careTeamId = uuidv4();
|
|
1168
|
+
const careTeamRecord = {
|
|
1169
|
+
id: careTeamId,
|
|
1170
|
+
resourceId: careTeam.id,
|
|
1171
|
+
status: careTeam.status,
|
|
1172
|
+
name: careTeam.name,
|
|
1173
|
+
subjectReference: (_a = careTeam.subject) === null || _a === void 0 ? void 0 : _a.reference,
|
|
1174
|
+
encounterReference: (_b = careTeam.encounter) === null || _b === void 0 ? void 0 : _b.reference,
|
|
1175
|
+
periodStart: (_c = careTeam.period) === null || _c === void 0 ? void 0 : _c.start,
|
|
1176
|
+
periodEnd: (_d = careTeam.period) === null || _d === void 0 ? void 0 : _d.end,
|
|
1177
|
+
createdAt: new Date(),
|
|
1178
|
+
updatedAt: new Date(),
|
|
1179
|
+
};
|
|
1180
|
+
result.careTeams.push(careTeamRecord);
|
|
1181
|
+
// Process participants
|
|
1182
|
+
if (careTeam.participant) {
|
|
1183
|
+
careTeam.participant.forEach(participant => {
|
|
1184
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k;
|
|
1185
|
+
result.careTeamParticipants.push({
|
|
1186
|
+
id: uuidv4(),
|
|
1187
|
+
careTeamId: careTeamId,
|
|
1188
|
+
role: ((_d = (_c = (_b = (_a = participant.role) === null || _a === void 0 ? void 0 : _a[0]) === null || _b === void 0 ? void 0 : _b.coding) === null || _c === void 0 ? void 0 : _c[0]) === null || _d === void 0 ? void 0 : _d.display) || ((_f = (_e = participant.role) === null || _e === void 0 ? void 0 : _e[0]) === null || _f === void 0 ? void 0 : _f.text),
|
|
1189
|
+
memberReference: (_g = participant.member) === null || _g === void 0 ? void 0 : _g.reference,
|
|
1190
|
+
onBehalfOfReference: (_h = participant.onBehalfOf) === null || _h === void 0 ? void 0 : _h.reference,
|
|
1191
|
+
periodStart: (_j = participant.period) === null || _j === void 0 ? void 0 : _j.start,
|
|
1192
|
+
periodEnd: (_k = participant.period) === null || _k === void 0 ? void 0 : _k.end,
|
|
1193
|
+
createdAt: new Date(),
|
|
1194
|
+
});
|
|
1195
|
+
});
|
|
1196
|
+
}
|
|
1197
|
+
// Process other fields
|
|
1198
|
+
if (careTeam.identifier) {
|
|
1199
|
+
careTeam.identifier.forEach(identifier => {
|
|
1200
|
+
processIdentifier('CareTeam', careTeamId, identifier, result);
|
|
1201
|
+
});
|
|
1202
|
+
}
|
|
1203
|
+
if (careTeam.category) {
|
|
1204
|
+
careTeam.category.forEach(cat => {
|
|
1205
|
+
processCodeableConcept('CareTeam', careTeamId, 'category', cat, result);
|
|
1206
|
+
});
|
|
1207
|
+
}
|
|
1208
|
+
if (careTeam.reasonCode) {
|
|
1209
|
+
careTeam.reasonCode.forEach(reason => {
|
|
1210
|
+
processCodeableConcept('CareTeam', careTeamId, 'reasonCode', reason, result);
|
|
1211
|
+
});
|
|
1212
|
+
}
|
|
1213
|
+
if (careTeam.reasonReference) {
|
|
1214
|
+
careTeam.reasonReference.forEach(ref => {
|
|
1215
|
+
processReference('CareTeam', careTeamId, 'reasonReference', ref, result);
|
|
1216
|
+
});
|
|
1217
|
+
}
|
|
1218
|
+
if (careTeam.managingOrganization) {
|
|
1219
|
+
careTeam.managingOrganization.forEach(ref => {
|
|
1220
|
+
processReference('CareTeam', careTeamId, 'managingOrganization', ref, result);
|
|
1221
|
+
});
|
|
1222
|
+
}
|
|
1223
|
+
if (careTeam.telecom) {
|
|
1224
|
+
careTeam.telecom.forEach(telecom => {
|
|
1225
|
+
processTelecom('CareTeam', careTeamId, telecom, result);
|
|
1226
|
+
});
|
|
1227
|
+
}
|
|
1228
|
+
if (careTeam.note) {
|
|
1229
|
+
careTeam.note.forEach(note => {
|
|
1230
|
+
processNote('CareTeam', careTeamId, note, result);
|
|
1231
|
+
});
|
|
1232
|
+
}
|
|
1233
|
+
}
|
|
1234
|
+
function processCarePlan(carePlan, result) {
|
|
1235
|
+
var _a, _b, _c, _d;
|
|
1236
|
+
const carePlanId = uuidv4();
|
|
1237
|
+
const carePlanRecord = {
|
|
1238
|
+
id: carePlanId,
|
|
1239
|
+
resourceId: carePlan.id,
|
|
1240
|
+
status: carePlan.status,
|
|
1241
|
+
intent: carePlan.intent,
|
|
1242
|
+
title: carePlan.title,
|
|
1243
|
+
description: carePlan.description,
|
|
1244
|
+
subjectReference: carePlan.subject.reference || '',
|
|
1245
|
+
encounterReference: (_a = carePlan.encounter) === null || _a === void 0 ? void 0 : _a.reference,
|
|
1246
|
+
periodStart: (_b = carePlan.period) === null || _b === void 0 ? void 0 : _b.start,
|
|
1247
|
+
periodEnd: (_c = carePlan.period) === null || _c === void 0 ? void 0 : _c.end,
|
|
1248
|
+
created: carePlan.created,
|
|
1249
|
+
authorReference: (_d = carePlan.author) === null || _d === void 0 ? void 0 : _d.reference,
|
|
1250
|
+
createdAt: new Date(),
|
|
1251
|
+
updatedAt: new Date(),
|
|
1252
|
+
};
|
|
1253
|
+
result.carePlans.push(carePlanRecord);
|
|
1254
|
+
// Process activities
|
|
1255
|
+
if (carePlan.activity) {
|
|
1256
|
+
carePlan.activity.forEach(activity => {
|
|
1257
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r, _s, _t, _u, _v, _w, _x, _y, _z, _0, _1, _2, _3, _4, _5, _6, _7, _8, _9, _10, _11, _12, _13, _14;
|
|
1258
|
+
const activityRecord = {
|
|
1259
|
+
id: uuidv4(),
|
|
1260
|
+
carePlanId: carePlanId,
|
|
1261
|
+
outcomeCodeableConcept: (_b = (_a = activity.outcomeCodeableConcept) === null || _a === void 0 ? void 0 : _a[0]) === null || _b === void 0 ? void 0 : _b.text,
|
|
1262
|
+
outcomeReference: (_d = (_c = activity.outcomeReference) === null || _c === void 0 ? void 0 : _c[0]) === null || _d === void 0 ? void 0 : _d.reference,
|
|
1263
|
+
progress: (_f = (_e = activity.progress) === null || _e === void 0 ? void 0 : _e[0]) === null || _f === void 0 ? void 0 : _f.text,
|
|
1264
|
+
reference: (_g = activity.reference) === null || _g === void 0 ? void 0 : _g.reference,
|
|
1265
|
+
kind: (_h = activity.detail) === null || _h === void 0 ? void 0 : _h.kind,
|
|
1266
|
+
code: ((_m = (_l = (_k = (_j = activity.detail) === null || _j === void 0 ? void 0 : _j.code) === null || _k === void 0 ? void 0 : _k.coding) === null || _l === void 0 ? void 0 : _l[0]) === null || _m === void 0 ? void 0 : _m.display) || ((_p = (_o = activity.detail) === null || _o === void 0 ? void 0 : _o.code) === null || _p === void 0 ? void 0 : _p.text),
|
|
1267
|
+
status: ((_q = activity.detail) === null || _q === void 0 ? void 0 : _q.status) || 'unknown',
|
|
1268
|
+
statusReason: (_u = (_t = (_s = (_r = activity.detail) === null || _r === void 0 ? void 0 : _r.statusReason) === null || _s === void 0 ? void 0 : _s.coding) === null || _t === void 0 ? void 0 : _t[0]) === null || _u === void 0 ? void 0 : _u.code,
|
|
1269
|
+
doNotPerform: (_v = activity.detail) === null || _v === void 0 ? void 0 : _v.doNotPerform,
|
|
1270
|
+
scheduledDateTime: typeof ((_w = activity.detail) === null || _w === void 0 ? void 0 : _w.scheduled) === 'string' ? activity.detail.scheduled : undefined,
|
|
1271
|
+
scheduledPeriodStart: typeof ((_x = activity.detail) === null || _x === void 0 ? void 0 : _x.scheduled) === 'object' && 'start' in activity.detail.scheduled ? activity.detail.scheduled.start : undefined,
|
|
1272
|
+
scheduledPeriodEnd: typeof ((_y = activity.detail) === null || _y === void 0 ? void 0 : _y.scheduled) === 'object' && 'end' in activity.detail.scheduled ? activity.detail.scheduled.end : undefined,
|
|
1273
|
+
locationReference: (_0 = (_z = activity.detail) === null || _z === void 0 ? void 0 : _z.location) === null || _0 === void 0 ? void 0 : _0.reference,
|
|
1274
|
+
performerReference: (_3 = (_2 = (_1 = activity.detail) === null || _1 === void 0 ? void 0 : _1.performer) === null || _2 === void 0 ? void 0 : _2[0]) === null || _3 === void 0 ? void 0 : _3.reference,
|
|
1275
|
+
productCodeableConcept: typeof ((_4 = activity.detail) === null || _4 === void 0 ? void 0 : _4.product) === 'object' && 'coding' in activity.detail.product ? activity.detail.product.text : undefined,
|
|
1276
|
+
productReference: typeof ((_5 = activity.detail) === null || _5 === void 0 ? void 0 : _5.product) === 'object' && 'reference' in activity.detail.product ? activity.detail.product.reference : undefined,
|
|
1277
|
+
dailyAmountValue: (_7 = (_6 = activity.detail) === null || _6 === void 0 ? void 0 : _6.dailyAmount) === null || _7 === void 0 ? void 0 : _7.value,
|
|
1278
|
+
dailyAmountUnit: (_9 = (_8 = activity.detail) === null || _8 === void 0 ? void 0 : _8.dailyAmount) === null || _9 === void 0 ? void 0 : _9.unit,
|
|
1279
|
+
quantityValue: (_11 = (_10 = activity.detail) === null || _10 === void 0 ? void 0 : _10.quantity) === null || _11 === void 0 ? void 0 : _11.value,
|
|
1280
|
+
quantityUnit: (_13 = (_12 = activity.detail) === null || _12 === void 0 ? void 0 : _12.quantity) === null || _13 === void 0 ? void 0 : _13.unit,
|
|
1281
|
+
description: (_14 = activity.detail) === null || _14 === void 0 ? void 0 : _14.description,
|
|
1282
|
+
createdAt: new Date(),
|
|
1283
|
+
};
|
|
1284
|
+
result.carePlanActivities.push(activityRecord);
|
|
1285
|
+
});
|
|
1286
|
+
}
|
|
1287
|
+
// Process other fields
|
|
1288
|
+
if (carePlan.identifier) {
|
|
1289
|
+
carePlan.identifier.forEach(identifier => {
|
|
1290
|
+
processIdentifier('CarePlan', carePlanId, identifier, result);
|
|
1291
|
+
});
|
|
1292
|
+
}
|
|
1293
|
+
if (carePlan.basedOn) {
|
|
1294
|
+
carePlan.basedOn.forEach(ref => {
|
|
1295
|
+
processReference('CarePlan', carePlanId, 'basedOn', ref, result);
|
|
1296
|
+
});
|
|
1297
|
+
}
|
|
1298
|
+
if (carePlan.replaces) {
|
|
1299
|
+
carePlan.replaces.forEach(ref => {
|
|
1300
|
+
processReference('CarePlan', carePlanId, 'replaces', ref, result);
|
|
1301
|
+
});
|
|
1302
|
+
}
|
|
1303
|
+
if (carePlan.partOf) {
|
|
1304
|
+
carePlan.partOf.forEach(ref => {
|
|
1305
|
+
processReference('CarePlan', carePlanId, 'partOf', ref, result);
|
|
1306
|
+
});
|
|
1307
|
+
}
|
|
1308
|
+
if (carePlan.category) {
|
|
1309
|
+
carePlan.category.forEach(cat => {
|
|
1310
|
+
processCodeableConcept('CarePlan', carePlanId, 'category', cat, result);
|
|
1311
|
+
});
|
|
1312
|
+
}
|
|
1313
|
+
if (carePlan.contributor) {
|
|
1314
|
+
carePlan.contributor.forEach(ref => {
|
|
1315
|
+
processReference('CarePlan', carePlanId, 'contributor', ref, result);
|
|
1316
|
+
});
|
|
1317
|
+
}
|
|
1318
|
+
if (carePlan.careTeam) {
|
|
1319
|
+
carePlan.careTeam.forEach(ref => {
|
|
1320
|
+
processReference('CarePlan', carePlanId, 'careTeam', ref, result);
|
|
1321
|
+
});
|
|
1322
|
+
}
|
|
1323
|
+
if (carePlan.addresses) {
|
|
1324
|
+
carePlan.addresses.forEach(ref => {
|
|
1325
|
+
processReference('CarePlan', carePlanId, 'addresses', ref, result);
|
|
1326
|
+
});
|
|
1327
|
+
}
|
|
1328
|
+
if (carePlan.supportingInfo) {
|
|
1329
|
+
carePlan.supportingInfo.forEach(ref => {
|
|
1330
|
+
processReference('CarePlan', carePlanId, 'supportingInfo', ref, result);
|
|
1331
|
+
});
|
|
1332
|
+
}
|
|
1333
|
+
if (carePlan.goal) {
|
|
1334
|
+
carePlan.goal.forEach(ref => {
|
|
1335
|
+
processReference('CarePlan', carePlanId, 'goal', ref, result);
|
|
1336
|
+
});
|
|
1337
|
+
}
|
|
1338
|
+
if (carePlan.note) {
|
|
1339
|
+
carePlan.note.forEach(note => {
|
|
1340
|
+
processNote('CarePlan', carePlanId, note, result);
|
|
1341
|
+
});
|
|
1342
|
+
}
|
|
1343
|
+
}
|
|
1344
|
+
// Helper functions for common data types
|
|
1345
|
+
function processAddress(resourceType, resourceId, address, result) {
|
|
1346
|
+
var _a, _b, _c;
|
|
1347
|
+
const addressRecord = {
|
|
1348
|
+
id: uuidv4(),
|
|
1349
|
+
resourceType: resourceType,
|
|
1350
|
+
resourceId: resourceId,
|
|
1351
|
+
use: address.use,
|
|
1352
|
+
type: address.type,
|
|
1353
|
+
text: address.text,
|
|
1354
|
+
line: (_a = address.line) === null || _a === void 0 ? void 0 : _a.join('\n'),
|
|
1355
|
+
city: address.city,
|
|
1356
|
+
district: address.district,
|
|
1357
|
+
state: address.state,
|
|
1358
|
+
postalCode: address.postalCode,
|
|
1359
|
+
country: address.country,
|
|
1360
|
+
periodStart: (_b = address.period) === null || _b === void 0 ? void 0 : _b.start,
|
|
1361
|
+
periodEnd: (_c = address.period) === null || _c === void 0 ? void 0 : _c.end,
|
|
1362
|
+
createdAt: new Date(),
|
|
1363
|
+
updatedAt: new Date(),
|
|
1364
|
+
};
|
|
1365
|
+
result.addresses.push(addressRecord);
|
|
1366
|
+
}
|
|
1367
|
+
function processTelecom(resourceType, resourceId, telecom, result) {
|
|
1368
|
+
var _a, _b;
|
|
1369
|
+
const telecomRecord = {
|
|
1370
|
+
id: uuidv4(),
|
|
1371
|
+
resourceType: resourceType,
|
|
1372
|
+
resourceId: resourceId,
|
|
1373
|
+
system: telecom.system,
|
|
1374
|
+
value: telecom.value,
|
|
1375
|
+
use: telecom.use,
|
|
1376
|
+
rank: telecom.rank,
|
|
1377
|
+
periodStart: (_a = telecom.period) === null || _a === void 0 ? void 0 : _a.start,
|
|
1378
|
+
periodEnd: (_b = telecom.period) === null || _b === void 0 ? void 0 : _b.end,
|
|
1379
|
+
createdAt: new Date(),
|
|
1380
|
+
};
|
|
1381
|
+
result.telecoms.push(telecomRecord);
|
|
1382
|
+
}
|
|
1383
|
+
function processCodeableConcept(resourceType, resourceId, fieldName, concept, result) {
|
|
1384
|
+
const conceptId = uuidv4();
|
|
1385
|
+
const conceptRecord = {
|
|
1386
|
+
id: conceptId,
|
|
1387
|
+
resourceType: resourceType,
|
|
1388
|
+
resourceId: resourceId,
|
|
1389
|
+
fieldName: fieldName,
|
|
1390
|
+
text: concept.text,
|
|
1391
|
+
createdAt: new Date(),
|
|
1392
|
+
};
|
|
1393
|
+
result.codeableConcepts.push(conceptRecord);
|
|
1394
|
+
// Process codings
|
|
1395
|
+
if (concept.coding) {
|
|
1396
|
+
concept.coding.forEach(coding => {
|
|
1397
|
+
const codingRecord = {
|
|
1398
|
+
id: uuidv4(),
|
|
1399
|
+
codeableConceptId: conceptId,
|
|
1400
|
+
system: coding.system,
|
|
1401
|
+
version: coding.version,
|
|
1402
|
+
code: coding.code,
|
|
1403
|
+
display: coding.display,
|
|
1404
|
+
userSelected: coding.userSelected,
|
|
1405
|
+
createdAt: new Date(),
|
|
1406
|
+
};
|
|
1407
|
+
result.codings.push(codingRecord);
|
|
1408
|
+
});
|
|
1409
|
+
}
|
|
1410
|
+
}
|
|
1411
|
+
function processReference(resourceType, resourceId, fieldName, reference, result) {
|
|
1412
|
+
const referenceRecord = {
|
|
1413
|
+
id: uuidv4(),
|
|
1414
|
+
resourceType: resourceType,
|
|
1415
|
+
resourceId: resourceId,
|
|
1416
|
+
fieldName: fieldName,
|
|
1417
|
+
reference: reference.reference,
|
|
1418
|
+
type: reference.type,
|
|
1419
|
+
identifier: reference.identifier ? JSON.stringify(reference.identifier) : undefined,
|
|
1420
|
+
display: reference.display,
|
|
1421
|
+
createdAt: new Date(),
|
|
1422
|
+
};
|
|
1423
|
+
result.references.push(referenceRecord);
|
|
1424
|
+
}
|
|
1425
|
+
function processIdentifier(resourceType, resourceId, identifier, result) {
|
|
1426
|
+
// We'll store identifiers in a generic way using the CodeableConcept table
|
|
1427
|
+
if (identifier.type) {
|
|
1428
|
+
processCodeableConcept(resourceType, resourceId, 'identifier.type', identifier.type, result);
|
|
1429
|
+
}
|
|
1430
|
+
// Store the identifier value in the references table as a special case
|
|
1431
|
+
const identifierRecord = {
|
|
1432
|
+
id: uuidv4(),
|
|
1433
|
+
resourceType: resourceType,
|
|
1434
|
+
resourceId: resourceId,
|
|
1435
|
+
fieldName: 'identifier',
|
|
1436
|
+
reference: identifier.value,
|
|
1437
|
+
type: identifier.use,
|
|
1438
|
+
identifier: JSON.stringify({
|
|
1439
|
+
system: identifier.system,
|
|
1440
|
+
value: identifier.value,
|
|
1441
|
+
period: identifier.period,
|
|
1442
|
+
assigner: identifier.assigner,
|
|
1443
|
+
}),
|
|
1444
|
+
display: `${identifier.system}|${identifier.value}`,
|
|
1445
|
+
createdAt: new Date(),
|
|
1446
|
+
};
|
|
1447
|
+
result.references.push(identifierRecord);
|
|
1448
|
+
}
|
|
1449
|
+
function processNote(resourceType, resourceId, note, result) {
|
|
1450
|
+
var _a;
|
|
1451
|
+
const noteRecord = {
|
|
1452
|
+
id: uuidv4(),
|
|
1453
|
+
resourceType: resourceType,
|
|
1454
|
+
resourceId: resourceId,
|
|
1455
|
+
authorReference: (_a = note.authorReference) === null || _a === void 0 ? void 0 : _a.reference,
|
|
1456
|
+
authorString: note.authorString,
|
|
1457
|
+
time: note.time,
|
|
1458
|
+
text: note.text,
|
|
1459
|
+
createdAt: new Date(),
|
|
1460
|
+
};
|
|
1461
|
+
result.notes.push(noteRecord);
|
|
1462
|
+
}
|
|
1463
|
+
function processAttachment(resourceType, resourceId, fieldName, attachment, result) {
|
|
1464
|
+
const attachmentRecord = {
|
|
1465
|
+
id: uuidv4(),
|
|
1466
|
+
resourceType: resourceType,
|
|
1467
|
+
resourceId: resourceId,
|
|
1468
|
+
fieldName: fieldName,
|
|
1469
|
+
contentType: attachment.contentType,
|
|
1470
|
+
language: attachment.language,
|
|
1471
|
+
data: attachment.data,
|
|
1472
|
+
url: attachment.url,
|
|
1473
|
+
size: attachment.size,
|
|
1474
|
+
hash: attachment.hash,
|
|
1475
|
+
title: attachment.title,
|
|
1476
|
+
creation: attachment.creation,
|
|
1477
|
+
createdAt: new Date(),
|
|
1478
|
+
};
|
|
1479
|
+
result.attachments.push(attachmentRecord);
|
|
1480
|
+
}
|
|
1481
|
+
function processHumanName(resourceType, resourceId, name, result) {
|
|
1482
|
+
var _a, _b, _c;
|
|
1483
|
+
// Store human names in a generic way using the CodeableConcept table
|
|
1484
|
+
const nameText = name.text || `${(_a = name.prefix) === null || _a === void 0 ? void 0 : _a.join(' ')} ${(_b = name.given) === null || _b === void 0 ? void 0 : _b.join(' ')} ${name.family} ${(_c = name.suffix) === null || _c === void 0 ? void 0 : _c.join(' ')}`.trim();
|
|
1485
|
+
processCodeableConcept(resourceType, resourceId, 'name', { text: nameText }, result);
|
|
1486
|
+
}
|
|
1487
|
+
//# sourceMappingURL=normalize-fhir-bundle.function.js.map
|