forked from lantanagroup/FHIR.js
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathparseConformance.js
394 lines (394 loc) · 32.2 KB
/
parseConformance.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
"use strict";
exports.__esModule = true;
var _ = require("underscore");
var fhir_1 = require("./fhir");
var ParseConformance = (function () {
function ParseConformance(loadCached, version) {
this.structureDefinitions = [];
this.parsedStructureDefinitions = loadCached ? require('./profiles/types.json') : {};
this.parsedValueSets = loadCached ? require('./profiles/valuesets.json') : {};
this.version = version || fhir_1.Versions.R4;
this.codeSystems = [];
}
ParseConformance.prototype.isBaseProfile = function (url) {
var urls;
switch (this.version) {
case fhir_1.Versions.STU3:
urls = ['http://hl7.org/fhir/StructureDefinition/Account', 'http://hl7.org/fhir/StructureDefinition/ActivityDefinition', 'http://hl7.org/fhir/StructureDefinition/AllergyIntolerance', 'http://hl7.org/fhir/StructureDefinition/AdverseEvent', 'http://hl7.org/fhir/StructureDefinition/Appointment', 'http://hl7.org/fhir/StructureDefinition/AppointmentResponse', 'http://hl7.org/fhir/StructureDefinition/AuditEvent', 'http://hl7.org/fhir/StructureDefinition/Basic', 'http://hl7.org/fhir/StructureDefinition/Binary', 'http://hl7.org/fhir/StructureDefinition/BodySite', 'http://hl7.org/fhir/StructureDefinition/Bundle', 'http://hl7.org/fhir/StructureDefinition/CapabilityStatement', 'http://hl7.org/fhir/StructureDefinition/CarePlan', 'http://hl7.org/fhir/StructureDefinition/CareTeam', 'http://hl7.org/fhir/StructureDefinition/ChargeItem', 'http://hl7.org/fhir/StructureDefinition/Claim', 'http://hl7.org/fhir/StructureDefinition/ClaimResponse', 'http://hl7.org/fhir/StructureDefinition/ClinicalImpression', 'http://hl7.org/fhir/StructureDefinition/CodeSystem', 'http://hl7.org/fhir/StructureDefinition/Communication', 'http://hl7.org/fhir/StructureDefinition/CommunicationRequest', 'http://hl7.org/fhir/StructureDefinition/CompartmentDefinition', 'http://hl7.org/fhir/StructureDefinition/Composition', 'http://hl7.org/fhir/StructureDefinition/ConceptMap', 'http://hl7.org/fhir/StructureDefinition/Condition (aka Problem)', 'http://hl7.org/fhir/StructureDefinition/Consent', 'http://hl7.org/fhir/StructureDefinition/Contract', 'http://hl7.org/fhir/StructureDefinition/Coverage', 'http://hl7.org/fhir/StructureDefinition/DataElement', 'http://hl7.org/fhir/StructureDefinition/DetectedIssue', 'http://hl7.org/fhir/StructureDefinition/Device', 'http://hl7.org/fhir/StructureDefinition/DeviceComponent', 'http://hl7.org/fhir/StructureDefinition/DeviceMetric', 'http://hl7.org/fhir/StructureDefinition/DeviceRequest', 'http://hl7.org/fhir/StructureDefinition/DeviceUseStatement', 'http://hl7.org/fhir/StructureDefinition/DiagnosticReport', 'http://hl7.org/fhir/StructureDefinition/DocumentManifest', 'http://hl7.org/fhir/StructureDefinition/DocumentReference', 'http://hl7.org/fhir/StructureDefinition/EligibilityRequest', 'http://hl7.org/fhir/StructureDefinition/EligibilityResponse', 'http://hl7.org/fhir/StructureDefinition/Encounter', 'http://hl7.org/fhir/StructureDefinition/Endpoint', 'http://hl7.org/fhir/StructureDefinition/EnrollmentRequest', 'http://hl7.org/fhir/StructureDefinition/EnrollmentResponse', 'http://hl7.org/fhir/StructureDefinition/EpisodeOfCare', 'http://hl7.org/fhir/StructureDefinition/ExpansionProfile', 'http://hl7.org/fhir/StructureDefinition/ExplanationOfBenefit', 'http://hl7.org/fhir/StructureDefinition/FamilyMemberHistory', 'http://hl7.org/fhir/StructureDefinition/Flag', 'http://hl7.org/fhir/StructureDefinition/Goal', 'http://hl7.org/fhir/StructureDefinition/GraphDefinition', 'http://hl7.org/fhir/StructureDefinition/Group', 'http://hl7.org/fhir/StructureDefinition/GuidanceResponse', 'http://hl7.org/fhir/StructureDefinition/HealthcareService', 'http://hl7.org/fhir/StructureDefinition/ImagingManifest', 'http://hl7.org/fhir/StructureDefinition/ImagingStudy', 'http://hl7.org/fhir/StructureDefinition/Immunization', 'http://hl7.org/fhir/StructureDefinition/ImmunizationRecommendation', 'http://hl7.org/fhir/StructureDefinition/ImplementationGuide', 'http://hl7.org/fhir/StructureDefinition/Library', 'http://hl7.org/fhir/StructureDefinition/Linkage', 'http://hl7.org/fhir/StructureDefinition/List', 'http://hl7.org/fhir/StructureDefinition/Location', 'http://hl7.org/fhir/StructureDefinition/Measure', 'http://hl7.org/fhir/StructureDefinition/MeasureReport', 'http://hl7.org/fhir/StructureDefinition/Media', 'http://hl7.org/fhir/StructureDefinition/Medication', 'http://hl7.org/fhir/StructureDefinition/MedicationAdministration', 'http://hl7.org/fhir/StructureDefinition/MedicationDispense', 'http://hl7.org/fhir/StructureDefinition/MedicationRequest', 'http://hl7.org/fhir/StructureDefinition/MedicationStatement', 'http://hl7.org/fhir/StructureDefinition/MessageDefinition', 'http://hl7.org/fhir/StructureDefinition/MessageHeader', 'http://hl7.org/fhir/StructureDefinition/NamingSystem', 'http://hl7.org/fhir/StructureDefinition/NutritionOrder', 'http://hl7.org/fhir/StructureDefinition/Observation', 'http://hl7.org/fhir/StructureDefinition/OperationDefinition', 'http://hl7.org/fhir/StructureDefinition/OperationOutcome', 'http://hl7.org/fhir/StructureDefinition/Organization', 'http://hl7.org/fhir/StructureDefinition/Parameters', 'http://hl7.org/fhir/StructureDefinition/Patient', 'http://hl7.org/fhir/StructureDefinition/PaymentNotice', 'http://hl7.org/fhir/StructureDefinition/PaymentReconciliation', 'http://hl7.org/fhir/StructureDefinition/Person', 'http://hl7.org/fhir/StructureDefinition/PlanDefinition', 'http://hl7.org/fhir/StructureDefinition/Practitioner', 'http://hl7.org/fhir/StructureDefinition/PractitionerRole', 'http://hl7.org/fhir/StructureDefinition/Procedure', 'http://hl7.org/fhir/StructureDefinition/ProcedureRequest', 'http://hl7.org/fhir/StructureDefinition/ProcessRequest', 'http://hl7.org/fhir/StructureDefinition/ProcessResponse', 'http://hl7.org/fhir/StructureDefinition/Provenance', 'http://hl7.org/fhir/StructureDefinition/Questionnaire', 'http://hl7.org/fhir/StructureDefinition/QuestionnaireResponse', 'http://hl7.org/fhir/StructureDefinition/ReferralRequest', 'http://hl7.org/fhir/StructureDefinition/RelatedPerson', 'http://hl7.org/fhir/StructureDefinition/RequestGroup', 'http://hl7.org/fhir/StructureDefinition/ResearchStudy', 'http://hl7.org/fhir/StructureDefinition/ResearchSubject', 'http://hl7.org/fhir/StructureDefinition/RiskAssessment', 'http://hl7.org/fhir/StructureDefinition/Schedule', 'http://hl7.org/fhir/StructureDefinition/SearchParameter', 'http://hl7.org/fhir/StructureDefinition/Sequence', 'http://hl7.org/fhir/StructureDefinition/ServiceDefinition', 'http://hl7.org/fhir/StructureDefinition/Slot', 'http://hl7.org/fhir/StructureDefinition/Specimen', 'http://hl7.org/fhir/StructureDefinition/StructureDefinition', 'http://hl7.org/fhir/StructureDefinition/StructureMap', 'http://hl7.org/fhir/StructureDefinition/Subscription', 'http://hl7.org/fhir/StructureDefinition/Substance', 'http://hl7.org/fhir/StructureDefinition/SupplyDelivery', 'http://hl7.org/fhir/StructureDefinition/SupplyRequest', 'http://hl7.org/fhir/StructureDefinition/Task', 'http://hl7.org/fhir/StructureDefinition/TestScript', 'http://hl7.org/fhir/StructureDefinition/TestReport', 'http://hl7.org/fhir/StructureDefinition/ValueSet', 'http://hl7.org/fhir/StructureDefinition/VisionPrescription'];
break;
case fhir_1.Versions.R4:
urls = ['http://hl7.org/fhir/StructureDefinition/Account', 'http://hl7.org/fhir/StructureDefinition/ActivityDefinition', 'http://hl7.org/fhir/StructureDefinition/AdverseEvent', 'http://hl7.org/fhir/StructureDefinition/AllergyIntolerance', 'http://hl7.org/fhir/StructureDefinition/Appointment', 'http://hl7.org/fhir/StructureDefinition/AppointmentResponse', 'http://hl7.org/fhir/StructureDefinition/AuditEvent', 'http://hl7.org/fhir/StructureDefinition/Basic', 'http://hl7.org/fhir/StructureDefinition/Binary', 'http://hl7.org/fhir/StructureDefinition/BiologicallyDerivedProduct', 'http://hl7.org/fhir/StructureDefinition/BodyStructure', 'http://hl7.org/fhir/StructureDefinition/Bundle', 'http://hl7.org/fhir/StructureDefinition/CapabilityStatement', 'http://hl7.org/fhir/StructureDefinition/CarePlan', 'http://hl7.org/fhir/StructureDefinition/CareTeam', 'http://hl7.org/fhir/StructureDefinition/CatalogEntry', 'http://hl7.org/fhir/StructureDefinition/ChargeItem', 'http://hl7.org/fhir/StructureDefinition/ChargeItemDefinition', 'http://hl7.org/fhir/StructureDefinition/Claim', 'http://hl7.org/fhir/StructureDefinition/ClaimResponse', 'http://hl7.org/fhir/StructureDefinition/ClinicalImpression', 'http://hl7.org/fhir/StructureDefinition/CodeSystem', 'http://hl7.org/fhir/StructureDefinition/Communication', 'http://hl7.org/fhir/StructureDefinition/CommunicationRequest', 'http://hl7.org/fhir/StructureDefinition/CompartmentDefinition', 'http://hl7.org/fhir/StructureDefinition/Composition', 'http://hl7.org/fhir/StructureDefinition/ConceptMap', 'http://hl7.org/fhir/StructureDefinition/Condition (aka Problem)', 'http://hl7.org/fhir/StructureDefinition/Consent', 'http://hl7.org/fhir/StructureDefinition/Contract', 'http://hl7.org/fhir/StructureDefinition/Coverage', 'http://hl7.org/fhir/StructureDefinition/CoverageEligibilityRequest', 'http://hl7.org/fhir/StructureDefinition/CoverageEligibilityResponse', 'http://hl7.org/fhir/StructureDefinition/DetectedIssue', 'http://hl7.org/fhir/StructureDefinition/Device', 'http://hl7.org/fhir/StructureDefinition/DeviceDefinition', 'http://hl7.org/fhir/StructureDefinition/DeviceMetric', 'http://hl7.org/fhir/StructureDefinition/DeviceRequest', 'http://hl7.org/fhir/StructureDefinition/DeviceUseStatement', 'http://hl7.org/fhir/StructureDefinition/DiagnosticReport', 'http://hl7.org/fhir/StructureDefinition/DocumentManifest', 'http://hl7.org/fhir/StructureDefinition/DocumentReference', 'http://hl7.org/fhir/StructureDefinition/EffectEvidenceSynthesis', 'http://hl7.org/fhir/StructureDefinition/Encounter', 'http://hl7.org/fhir/StructureDefinition/Endpoint', 'http://hl7.org/fhir/StructureDefinition/EnrollmentRequest', 'http://hl7.org/fhir/StructureDefinition/EnrollmentResponse', 'http://hl7.org/fhir/StructureDefinition/EpisodeOfCare', 'http://hl7.org/fhir/StructureDefinition/EventDefinition', 'http://hl7.org/fhir/StructureDefinition/Evidence', 'http://hl7.org/fhir/StructureDefinition/EvidenceVariable', 'http://hl7.org/fhir/StructureDefinition/ExampleScenario', 'http://hl7.org/fhir/StructureDefinition/ExplanationOfBenefit', 'http://hl7.org/fhir/StructureDefinition/FamilyMemberHistory', 'http://hl7.org/fhir/StructureDefinition/Flag', 'http://hl7.org/fhir/StructureDefinition/Goal', 'http://hl7.org/fhir/StructureDefinition/GraphDefinition', 'http://hl7.org/fhir/StructureDefinition/Group', 'http://hl7.org/fhir/StructureDefinition/GuidanceResponse', 'http://hl7.org/fhir/StructureDefinition/HealthcareService', 'http://hl7.org/fhir/StructureDefinition/ImagingStudy', 'http://hl7.org/fhir/StructureDefinition/Immunization', 'http://hl7.org/fhir/StructureDefinition/ImmunizationEvaluation', 'http://hl7.org/fhir/StructureDefinition/ImmunizationRecommendation', 'http://hl7.org/fhir/StructureDefinition/ImplementationGuide', 'http://hl7.org/fhir/StructureDefinition/InsurancePlan', 'http://hl7.org/fhir/StructureDefinition/Invoice', 'http://hl7.org/fhir/StructureDefinition/Library', 'http://hl7.org/fhir/StructureDefinition/Linkage', 'http://hl7.org/fhir/StructureDefinition/List', 'http://hl7.org/fhir/StructureDefinition/Location', 'http://hl7.org/fhir/StructureDefinition/Measure', 'http://hl7.org/fhir/StructureDefinition/MeasureReport', 'http://hl7.org/fhir/StructureDefinition/Media', 'http://hl7.org/fhir/StructureDefinition/Medication', 'http://hl7.org/fhir/StructureDefinition/MedicationAdministration', 'http://hl7.org/fhir/StructureDefinition/MedicationDispense', 'http://hl7.org/fhir/StructureDefinition/MedicationKnowledge', 'http://hl7.org/fhir/StructureDefinition/MedicationRequest', 'http://hl7.org/fhir/StructureDefinition/MedicationStatement', 'http://hl7.org/fhir/StructureDefinition/MedicinalProduct', 'http://hl7.org/fhir/StructureDefinition/MedicinalProductAuthorization', 'http://hl7.org/fhir/StructureDefinition/MedicinalProductContraindication', 'http://hl7.org/fhir/StructureDefinition/MedicinalProductIndication', 'http://hl7.org/fhir/StructureDefinition/MedicinalProductIngredient', 'http://hl7.org/fhir/StructureDefinition/MedicinalProductInteraction', 'http://hl7.org/fhir/StructureDefinition/MedicinalProductManufactured', 'http://hl7.org/fhir/StructureDefinition/MedicinalProductPackaged', 'http://hl7.org/fhir/StructureDefinition/MedicinalProductPharmaceutical', 'http://hl7.org/fhir/StructureDefinition/MedicinalProductUndesirableEffect', 'http://hl7.org/fhir/StructureDefinition/MessageDefinition', 'http://hl7.org/fhir/StructureDefinition/MessageHeader', 'http://hl7.org/fhir/StructureDefinition/MolecularSequence', 'http://hl7.org/fhir/StructureDefinition/amingSystem', 'http://hl7.org/fhir/StructureDefinition/utritionOrder', 'http://hl7.org/fhir/StructureDefinition/Observation', 'http://hl7.org/fhir/StructureDefinition/ObservationDefinition', 'http://hl7.org/fhir/StructureDefinition/OperationDefinition', 'http://hl7.org/fhir/StructureDefinition/OperationOutcome', 'http://hl7.org/fhir/StructureDefinition/Organization', 'http://hl7.org/fhir/StructureDefinition/OrganizationAffiliation', 'http://hl7.org/fhir/StructureDefinition/Parameters', 'http://hl7.org/fhir/StructureDefinition/Patient', 'http://hl7.org/fhir/StructureDefinition/PaymentNotice', 'http://hl7.org/fhir/StructureDefinition/PaymentReconciliation', 'http://hl7.org/fhir/StructureDefinition/Person', 'http://hl7.org/fhir/StructureDefinition/PlanDefinition', 'http://hl7.org/fhir/StructureDefinition/Practitioner', 'http://hl7.org/fhir/StructureDefinition/PractitionerRole', 'http://hl7.org/fhir/StructureDefinition/Procedure', 'http://hl7.org/fhir/StructureDefinition/Provenance', 'http://hl7.org/fhir/StructureDefinition/Questionnaire', 'http://hl7.org/fhir/StructureDefinition/QuestionnaireResponse', 'http://hl7.org/fhir/StructureDefinition/RelatedPerson', 'http://hl7.org/fhir/StructureDefinition/RequestGroup', 'http://hl7.org/fhir/StructureDefinition/ResearchDefinition', 'http://hl7.org/fhir/StructureDefinition/ResearchElementDefinition', 'http://hl7.org/fhir/StructureDefinition/ResearchStudy', 'http://hl7.org/fhir/StructureDefinition/ResearchSubject', 'http://hl7.org/fhir/StructureDefinition/RiskAssessment', 'http://hl7.org/fhir/StructureDefinition/RiskEvidenceSynthesis', 'http://hl7.org/fhir/StructureDefinition/Schedule', 'http://hl7.org/fhir/StructureDefinition/SearchParameter', 'http://hl7.org/fhir/StructureDefinition/ServiceRequest', 'http://hl7.org/fhir/StructureDefinition/Slot', 'http://hl7.org/fhir/StructureDefinition/Specimen', 'http://hl7.org/fhir/StructureDefinition/SpecimenDefinition', 'http://hl7.org/fhir/StructureDefinition/StructureDefinition', 'http://hl7.org/fhir/StructureDefinition/StructureMap', 'http://hl7.org/fhir/StructureDefinition/Subscription', 'http://hl7.org/fhir/StructureDefinition/Substance', 'http://hl7.org/fhir/StructureDefinition/SubstancePolymer', 'http://hl7.org/fhir/StructureDefinition/SubstanceReferenceInformation', 'http://hl7.org/fhir/StructureDefinition/SubstanceSpecification', 'http://hl7.org/fhir/StructureDefinition/SupplyDelivery', 'http://hl7.org/fhir/StructureDefinition/SupplyRequest', 'http://hl7.org/fhir/StructureDefinition/Task', 'http://hl7.org/fhir/StructureDefinition/TerminologyCapabilities', 'http://hl7.org/fhir/StructureDefinition/TestReport', 'http://hl7.org/fhir/StructureDefinition/TestScript', 'http://hl7.org/fhir/StructureDefinition/ValueSet', 'http://hl7.org/fhir/StructureDefinition/VerificationResult', 'http://hl7.org/fhir/StructureDefinition/VisionPrescription'];
break;
}
return urls.indexOf(url) >= 0;
};
ParseConformance.prototype.sortValueSetDependencies = function (valueSets) {
var ret = [];
function addValueSet(valueSetUrl) {
var foundValueSet = _.find(valueSets, function (nextValueSet) {
return nextValueSet.url === valueSetUrl;
});
if (!foundValueSet) {
return;
}
if (foundValueSet.compose) {
_.each(foundValueSet.compose.include, function (include) {
addValueSet(include.valueSet);
});
}
if (ret.indexOf(foundValueSet) < 0) {
ret.push(foundValueSet);
}
}
_.each(valueSets, function (valueSet) {
addValueSet(valueSet.url);
});
return ret;
};
ParseConformance.prototype.loadCodeSystem = function (codeSystem) {
if (!codeSystem) {
return;
}
var foundCodeSystem = _.find(this.codeSystems, function (nextCodeSystem) {
return nextCodeSystem.url === codeSystem.url || nextCodeSystem.id === codeSystem.id;
});
if (!foundCodeSystem) {
this.codeSystems.push(codeSystem);
}
};
;
ParseConformance.prototype.parseBundle = function (bundle) {
var _this = this;
if (!bundle || !bundle.entry) {
return;
}
_.chain(bundle.entry)
.filter(function (entry) {
return entry.resource.resourceType === 'CodeSystem';
})
.each(function (entry) {
_this.loadCodeSystem(entry.resource);
});
var valueSets = _.chain(bundle.entry)
.filter(function (entry) {
return entry.resource.resourceType === 'ValueSet';
})
.map(function (entry) {
return entry.resource;
})
.value();
valueSets = this.sortValueSetDependencies(valueSets);
_.each(valueSets, function (valueSet) {
_this.parseValueSet(valueSet);
});
_.chain(bundle.entry)
.filter(function (entry) {
if (entry.resource.resourceType !== 'StructureDefinition') {
return false;
}
var resource = entry.resource;
return !(resource.kind != 'resource' && resource.kind != 'complex-type' && resource.kind != 'primitive-type');
})
.each(function (entry) {
_this.parseStructureDefinition(entry.resource);
});
};
ParseConformance.prototype.parseStructureDefinition = function (structureDefinition) {
var uid = ("0000" + ((Math.random() * Math.pow(36, 4)) | 0).toString(36)).slice(-4);
var parsedStructureDefinition = {
_url: structureDefinition.url,
_type: 'Resource',
_kind: structureDefinition.kind,
_properties: []
};
this.parsedStructureDefinitions[structureDefinition.id || uid] = parsedStructureDefinition;
var loadedStructureDefinition = _.find(this.structureDefinitions, function (sd) { return sd.url === structureDefinition.url; });
if (!loadedStructureDefinition) {
this.structureDefinitions.push(structureDefinition);
}
if (structureDefinition.snapshot && structureDefinition.snapshot.element) {
for (var x in structureDefinition.snapshot.element) {
var element = structureDefinition.snapshot.element[x];
var elementId = structureDefinition.snapshot.element[x].id;
elementId = elementId.substring(structureDefinition.id.length + 1);
if (!element.max) {
throw 'Expected all base resource elements to have a max value';
}
if (!elementId || elementId.indexOf('.') > 0 || !element.type) {
continue;
}
if (element.type.length === 1) {
var newProperty = {
_name: elementId,
_type: element.type[0].code || 'string',
_multiple: element.max !== '1',
_required: element.min === 1
};
parsedStructureDefinition._properties.push(newProperty);
this.populateValueSet(element, newProperty);
if (element.type[0].code == 'BackboneElement' || element.type[0].code == 'Element') {
newProperty._properties = [];
this.populateBackboneElement(parsedStructureDefinition, structureDefinition.snapshot.element[x].id, structureDefinition);
}
}
else if (elementId.endsWith('[x]')) {
elementId = elementId.substring(0, elementId.length - 3);
for (var y in element.type) {
var choiceType = element.type[y].code;
choiceType = choiceType.substring(0, 1).toUpperCase() + choiceType.substring(1);
var choiceElementId = elementId + choiceType;
var newProperty = {
_name: choiceElementId,
_choice: elementId,
_type: element.type[y].code,
_multiple: element.max !== '1',
_required: element.min === 1
};
this.populateValueSet(element, newProperty);
parsedStructureDefinition._properties.push(newProperty);
}
}
else {
var isReference = true;
for (var y in element.type) {
if (element.type[y].code !== 'Reference') {
isReference = false;
break;
}
}
if (isReference) {
parsedStructureDefinition._properties.push({
_name: elementId,
_type: 'Reference',
_multiple: element.max !== '1'
});
}
else {
console.log(elementId);
}
}
}
}
return parsedStructureDefinition;
};
ParseConformance.prototype.parseValueSet = function (valueSet) {
var newValueSet = {
systems: []
};
if (valueSet.expansion && valueSet.expansion.contains) {
var _loop_1 = function (i) {
var contains = valueSet.expansion.contains[i];
if (contains.inactive || contains.abstract) {
return "continue";
}
var foundSystem = _.find(newValueSet.systems, function (system) {
return system.uri === contains.system;
});
if (!foundSystem) {
foundSystem = {
uri: contains.system,
codes: []
};
newValueSet.systems.push(foundSystem);
}
foundSystem.codes.push({
code: contains.code,
display: contains.display
});
};
for (var i = 0; i < valueSet.expansion.contains.length; i++) {
_loop_1(i);
}
}
else if (valueSet.compose) {
var _loop_2 = function (i) {
var include = valueSet.compose.include[i];
if (include.system) {
var foundSystem = _.find(newValueSet.systems, function (system) {
return system.uri === include.system;
});
if (!foundSystem) {
foundSystem = {
uri: include.system,
codes: []
};
newValueSet.systems.push(foundSystem);
}
var foundCodeSystem = _.find(this_1.codeSystems, function (codeSystem) {
return codeSystem.url === include.system;
});
if (foundCodeSystem) {
var codes = _.map(foundCodeSystem.concept, function (concept) {
return {
code: concept.code,
display: concept.display
};
});
foundSystem.codes = foundSystem.codes.concat(codes);
}
}
if (include.valueSet) {
var includeValueSet = this_1.parsedValueSets[include.valueSet];
if (includeValueSet) {
_.each(includeValueSet.systems, function (includeSystem) {
var foundSystem = _.find(newValueSet.systems, function (nextSystem) {
return nextSystem.uri === includeSystem.uri;
});
if (!foundSystem) {
newValueSet.systems.push({
uri: includeSystem.uri,
codes: [].concat(includeSystem.codes)
});
}
else {
foundSystem.codes = foundSystem.codes.concat(includeSystem.codes);
}
});
}
}
if (include.concept) {
var systemUri_1 = include.system || '';
var foundSystem = _.find(newValueSet.systems, function (nextSystem) {
return nextSystem.uri === systemUri_1;
});
if (!foundSystem) {
foundSystem = {
uri: systemUri_1,
codes: []
};
newValueSet.systems.push(foundSystem);
}
var codes = _.map(include.concept, function (concept) {
return {
code: concept.code,
display: concept.display
};
});
foundSystem.codes = foundSystem.codes.concat(codes);
}
};
var this_1 = this;
for (var i = 0; i < valueSet.compose.include.length; i++) {
_loop_2(i);
}
}
var systemsWithCodes = _.filter(newValueSet.systems, function (system) {
return system.codes && system.codes.length > 0;
});
if (systemsWithCodes.length > 0) {
this.parsedValueSets[valueSet.url] = newValueSet;
return newValueSet;
}
};
ParseConformance.prototype.populateValueSet = function (element, property) {
if (element.binding) {
var binding = element.binding;
if (binding.strength) {
property._valueSetStrength = binding.strength;
}
if (this.version === fhir_1.Versions.R4 && binding.valueSet) {
property._valueSet = binding.valueSet;
}
else if (this.version === fhir_1.Versions.STU3 && binding.valueSetReference && binding.valueSetReference.reference) {
property._valueSet = binding.valueSetReference.reference;
}
}
};
ParseConformance.prototype.populateBackboneElement = function (resourceType, parentElementId, profile) {
var _loop_3 = function (y) {
var backboneElement = profile.snapshot.element[y];
var backboneElementId = backboneElement.id;
if (!backboneElementId.startsWith(parentElementId + '.') || backboneElementId.split('.').length !== parentElementId.split('.').length + 1) {
return "continue";
}
backboneElementId = backboneElementId.substring(profile.id.length + 1);
var parentElementIdSplit = parentElementId.substring(profile.id.length + 1).split('.');
var parentBackboneElement = null;
var _loop_4 = function (j) {
parentBackboneElement = _.find(!parentBackboneElement ? resourceType._properties : parentBackboneElement._properties, function (property) {
return property._name == parentElementIdSplit[j];
});
if (!parentBackboneElement) {
throw 'Parent backbone element not found';
}
};
for (var j = 0; j < parentElementIdSplit.length; j++) {
_loop_4(j);
}
if (parentBackboneElement) {
if (!backboneElement.type) {
var type = 'string';
if (backboneElement.contentReference) {
type = backboneElement.contentReference;
}
parentBackboneElement._properties.push({
_name: backboneElementId.substring(backboneElementId.lastIndexOf('.') + 1),
_type: type,
_multiple: backboneElement.max !== '1',
_required: backboneElement.min === 1
});
}
else if (backboneElement.type.length == 1) {
var newProperty = {
_name: backboneElementId.substring(backboneElementId.lastIndexOf('.') + 1),
_type: backboneElement.type[0].code,
_multiple: backboneElement.max !== '1',
_required: backboneElement.min === 1,
_properties: []
};
parentBackboneElement._properties.push(newProperty);
this_2.populateValueSet(backboneElement, newProperty);
if (backboneElement.type[0].code === 'BackboneElement' || backboneElement.type[0].code == 'Element') {
this_2.populateBackboneElement(resourceType, profile.snapshot.element[y].id, profile);
}
}
else if (backboneElement.id.endsWith('[x]')) {
for (var y_1 in backboneElement.type) {
var choiceType = backboneElement.type[y_1].code;
choiceType = choiceType.substring(0, 1).toUpperCase() + choiceType.substring(1);
var choiceElementId = backboneElement.id.substring(backboneElement.id.lastIndexOf('.') + 1, backboneElement.id.length - 3) + choiceType;
var newProperty = {
_name: choiceElementId,
_choice: backboneElement.id.substring(backboneElement.id.lastIndexOf('.') + 1),
_type: backboneElement.type[y_1].code,
_multiple: backboneElement.max !== '1',
_required: backboneElement.min === 1
};
parentBackboneElement._properties.push(newProperty);
this_2.populateValueSet(backboneElement, newProperty);
}
}
else {
var isReference = true;
for (var z in backboneElement.type) {
if (backboneElement.type[z].code !== 'Reference') {
isReference = false;
break;
}
}
if (!isReference) {
throw 'Did not find a reference... not sure what to do';
}
var newProperty = {
_name: backboneElementId.substring(backboneElementId.lastIndexOf('.') + 1),
_type: 'Reference',
_multiple: backboneElement.max !== '1',
_required: backboneElement.min === 1
};
parentBackboneElement._properties.push(newProperty);
this_2.populateValueSet(backboneElement, newProperty);
}
}
else {
throw 'Unexpected backbone parent element id';
}
};
var this_2 = this;
for (var y in profile.snapshot.element) {
_loop_3(y);
}
};
return ParseConformance;
}());
exports.ParseConformance = ParseConformance;
//# sourceMappingURL=parseConformance.js.map