Skip to content

Commit 7802306

Browse files
fix: Validation for Encounter and Location resources (#82)
* remove location ext from encounter, add meta profile url to location * update fhir converter api snapshot tests * update fhir converter snapshot tests * update location templates with correct profile, add data absent reason extensions for required fields, update validation numErrors * update fhir converter snapshot tests * update fhir converter api snapshot tests * add unit tests for Encounter and Location templates * update location templates, flawed address logic * update snapshot and unit tests * update name and type null flavors for location * update snapshot tess, fhir converter api snapshot tests, unit tests * fix: Add planned encounters back (#68) * planned encounter converts to own encounter * remove default values for nonrequired fields * update test * update snapshot * encompassing encounter status * update snapshots * remove spaces * do not convert cdc local sustem to url * fix tests * add actcode name back * merge main, resolve conflicts * merge conflicts, update unit test for Encounter * fix unit test again --------- Co-authored-by: Josh Nygaard <141273852+JNygaard-Skylight@users.noreply.github.com>
1 parent 3bd64e8 commit 7802306

File tree

13 files changed

+569
-148
lines changed

13 files changed

+569
-148
lines changed

data/Templates/eCR/Reference/Encounter/_Location_Location.liquid

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,6 @@
2020
},
2121
{% assign codes = LOC.code | to_array -%}
2222
{% if codes.first -%}
23-
"extension": [{
24-
"url": "http://build.fhir.org/ig/HL7/case-reporting/StructureDefinition-us-ph-location-definitions.html#Location.type",
25-
"valueCodeableConcept": { {% include 'DataType/CodeableConcept' CodeableConcept: codes.first, minCardinality: 1 -%} },
26-
},],
2723
{% endif -%}
2824
},
2925
],

data/Templates/eCR/Resource/_Location.liquid

Lines changed: 45 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,18 +3,56 @@
33
"resource":{
44
"resourceType": "Location",
55
"id":"{{ ID }}",
6+
"meta": {
7+
"profile": [
8+
"http://hl7.org/fhir/us/ecr/StructureDefinition/us-ph-location"
9+
]
10+
},
611
"identifier":
712
[
813
{% assign ids = location.id | to_array -%}
9-
{% for id in ids -%}
10-
{% include 'DataType/Identifier' Identifier: id -%}
11-
{% endfor -%}
14+
{% if ids != empty -%}
15+
{% for id in ids -%}
16+
{% include 'DataType/Identifier' Identifier: id -%}
17+
{% endfor -%}
18+
{% else %}
19+
{
20+
"system": "urn:ietf:rfc:3986",
21+
"value": "urn:uuid:{{ ID }}"
22+
}
23+
{% endif %}
1224
],
13-
"name":"{{ location.playingEntity.name._ }}",
14-
"address":
15-
{
25+
26+
{% if location.playingEntity.name._ %}
27+
"name":"{{ location.playingEntity.name._ }}",
28+
{% else %}
29+
"_name": {
30+
"extension": [
31+
{%- include 'Extension/DataAbsentReason' nullFlavor: location.playingEntity.name.nullFlavor | default: "unknown" | get_property: 'ValueSet/NullFlavor' -%}
32+
],
33+
},
34+
{% endif %}
35+
36+
"address": {
1637
{% include 'DataType/Address' Address: location.addr -%}
38+
{% if location.addr.city._ == null %}
39+
"_city": {
40+
"extension": [
41+
{% assign nfCity = location.addr.city.nullFlavor | default: location.addr.nullFlavor | default: "unknown" %}
42+
{%- include 'Extension/DataAbsentReason' nullFlavor: nfCity | get_property: 'ValueSet/NullFlavor' -%}
43+
]
44+
},
45+
{% endif %}
46+
{% if location.addr.state._ == null %}
47+
"_state": {
48+
"extension": [
49+
{% assign nfState = location.addr.state.nullFlavor | default: location.addr.nullFlavor | default: "unknown" %}
50+
{%- include 'Extension/DataAbsentReason' nullFlavor: nfState | get_property: 'ValueSet/NullFlavor' -%}
51+
]
52+
},
53+
{% endif %}
1754
},
55+
1856
"telecom":
1957
[
2058
{% assign telecoms = location.telecom | to_array -%}
@@ -26,7 +64,7 @@
2664
[
2765
{% assign codes = location.code | to_array -%}
2866
{% for code in codes -%}
29-
{ {% include 'DataType/CodeableConcept' CodeableConcept: code, minCardinality: 0 -%} },
67+
{ {% include 'DataType/CodeableConcept' CodeableConcept: code, minCardinality: 1, nullFlavor: code.nullFlavor -%} },
3068
{% endfor -%}
3169
],
3270
},

data/Templates/eCR/Resource/_LocationHealthCareFacility.liquid

Lines changed: 58 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -2,30 +2,69 @@
22
"fullUrl":"urn:uuid:{{ ID }}",
33
"resource":{
44
"resourceType": "Location",
5+
"meta": {
6+
"profile": [
7+
"http://hl7.org/fhir/us/ecr/StructureDefinition/us-ph-location"
8+
]
9+
},
510
"id":"{{ ID }}",
611
"identifier":
712
[
813
{% assign ids = location.id | to_array -%}
9-
{% for id in ids -%}
10-
{% include 'DataType/Identifier' Identifier: id -%}
11-
{% endfor -%}
14+
{% if ids != empty -%}
15+
{% for id in ids -%}
16+
{% include 'DataType/Identifier' Identifier: id -%}
17+
{% endfor -%}
18+
{% else %}
19+
{
20+
"system": "urn:ietf:rfc:3986",
21+
"value": "urn:uuid:{{ ID }}"
22+
}
23+
{% endif %}
1224
],
1325

1426
{% if location.location.name and location.location.name._ -%}
1527
"name":"{{ location.location.name._ }}",
1628
{% elsif location.serviceProviderOrganization and location.serviceProviderOrganization.name and location.serviceProviderOrganization.name._ -%}
1729
"name":"{{ location.serviceProviderOrganization.name._ }}",
18-
{% endif -%}
19-
30+
{% else %}
31+
"_name": {
32+
"extension": [
33+
{% assign nfName = location.location.name.nullFlavor | default: location.serviceProviderOrganization.name.nullFlavor | default: "unknown" %}
34+
{%- include 'Extension/DataAbsentReason' nullFlavor: nfName | get_property: 'ValueSet/NullFlavor' -%}
35+
],
36+
},
37+
{% endif %}
2038

21-
"address":
22-
{
23-
{% if location.location.addr and location.location.addr.state._ -%}
24-
{% include 'DataType/Address' Address: location.location.addr -%}
25-
{% elsif location.serviceProviderOrganization.addr and location.serviceProviderOrganization.addr.state._ -%}
26-
{% include 'DataType/Address' Address: location.serviceProviderOrganization.addr -%}
27-
{% endif -%}
39+
"address": {
40+
{% if location.location %}
41+
{% assign addressLocation = location.location %}
42+
{% elsif location.serviceProviderOrganization %}
43+
{% assign addressLocation = location.serviceProviderOrganization %}
44+
{% else %}
45+
{% assign addressLocation = null %}
46+
{% endif %}
47+
{% if addressLocation.addr -%}
48+
{% include 'DataType/Address' Address: addressLocation.addr -%}
49+
{% endif %}
50+
{% if addressLocation.addr.city._ == null %}
51+
"_city": {
52+
"extension": [
53+
{%- assign nfCity = addressLocation.addr.city.nullFlavor | default: addressLocation.addr.nullFlavor | default: "unknown" -%}
54+
{%- include 'Extension/DataAbsentReason' nullFlavor: nfCity | get_property: 'ValueSet/NullFlavor' -%}
55+
]
56+
},
57+
{% endif %}
58+
{% if addressLocation.addr.state._ == null %}
59+
"_state": {
60+
"extension": [
61+
{%- assign nfState = addressLocation.addr.state.nullFlavor | default: addressLocation.addr.nullFlavor | default: "unknown" -%}
62+
{%- include 'Extension/DataAbsentReason' nullFlavor: nfState | get_property: 'ValueSet/NullFlavor' -%}
63+
]
64+
},
65+
{% endif %}
2866
},
67+
2968
"telecom":
3069
[
3170
{% assign telecoms = location.location.telecom | to_array -%}
@@ -37,12 +76,13 @@
3776
{ {% include 'DataType/ContactPoint' ContactPoint: telecom -%} },
3877
{% endfor -%}
3978
],
79+
4080
"type":
41-
[
42-
{% assign codes = location.code | to_array -%}
43-
{% for code in codes -%}
44-
{ {% include 'DataType/CodeableConcept' CodeableConcept: code, minCardinality: 0 -%} },
45-
{% endfor -%}
46-
],
81+
[
82+
{% assign codes = location.code | to_array -%}
83+
{% for code in codes -%}
84+
{ {% include 'DataType/CodeableConcept' CodeableConcept: code, minCardinality: 1, nullFlavor: code.nullFlavor -%} },
85+
{% endfor -%}
86+
],
4787
},
4888
},

src/Dibbs.FhirConverterApi.FunctionalTests/__snapshots__/FhirConverterApiFunctionalTests.ConvertToFhir_ReturnsSuccess_WhenValidEicrWithRrProvided.snap

Lines changed: 43 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -351,20 +351,7 @@
351351
"id": "2.16.840.1.113883.4.6",
352352
"location": {
353353
"reference": "Location/bea8eaff-b016-f74b-10ab-9d0440257223"
354-
},
355-
"extension": [
356-
{
357-
"url": "http://build.fhir.org/ig/HL7/case-reporting/StructureDefinition-us-ph-location-definitions.html#Location.type",
358-
"valueCodeableConcept": {
359-
"coding": [
360-
{
361-
"code": "unknown",
362-
"system": "http://terminology.hl7.org/CodeSystem/data-absent-reason"
363-
}
364-
]
365-
}
366-
}
367-
]
354+
}
368355
}
369356
],
370357
"serviceProvider": {
@@ -396,6 +383,12 @@
396383
"fullUrl": "urn:uuid:bea8eaff-b016-f74b-10ab-9d0440257223",
397384
"resource": {
398385
"resourceType": "Location",
386+
"meta": {
387+
"profile": [
388+
"http://hl7.org/fhir/us/ecr/StructureDefinition/us-ph-location"
389+
],
390+
"source": "ecr"
391+
},
399392
"id": "bea8eaff-b016-f74b-10ab-9d0440257223",
400393
"identifier": [
401394
{
@@ -410,9 +403,42 @@
410403
}
411404
}
412405
],
413-
"meta": {
414-
"source": "ecr"
415-
}
406+
"_name": {
407+
"extension": [
408+
{
409+
"url": "http://hl7.org/fhir/StructureDefinition/data-absent-reason",
410+
"valueCode": "not-applicable"
411+
}
412+
]
413+
},
414+
"address": {
415+
"_city": {
416+
"extension": [
417+
{
418+
"url": "http://hl7.org/fhir/StructureDefinition/data-absent-reason",
419+
"valueCode": "not-applicable"
420+
}
421+
]
422+
},
423+
"_state": {
424+
"extension": [
425+
{
426+
"url": "http://hl7.org/fhir/StructureDefinition/data-absent-reason",
427+
"valueCode": "not-applicable"
428+
}
429+
]
430+
}
431+
},
432+
"type": [
433+
{
434+
"coding": [
435+
{
436+
"code": "not-applicable",
437+
"system": "http://terminology.hl7.org/CodeSystem/data-absent-reason"
438+
}
439+
]
440+
}
441+
]
416442
}
417443
},
418444
{

src/Dibbs.FhirConverterApi.FunctionalTests/__snapshots__/FhirConverterApiFunctionalTests.ConvertToFhir_ReturnsSuccess_WhenValidEicrWithoutRrProvided.snap

Lines changed: 43 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -301,20 +301,7 @@
301301
"id": "2.16.840.1.113883.4.6",
302302
"location": {
303303
"reference": "Location/bea8eaff-b016-f74b-10ab-9d0440257223"
304-
},
305-
"extension": [
306-
{
307-
"url": "http://build.fhir.org/ig/HL7/case-reporting/StructureDefinition-us-ph-location-definitions.html#Location.type",
308-
"valueCodeableConcept": {
309-
"coding": [
310-
{
311-
"code": "unknown",
312-
"system": "http://terminology.hl7.org/CodeSystem/data-absent-reason"
313-
}
314-
]
315-
}
316-
}
317-
]
304+
}
318305
}
319306
],
320307
"serviceProvider": {
@@ -346,6 +333,12 @@
346333
"fullUrl": "urn:uuid:bea8eaff-b016-f74b-10ab-9d0440257223",
347334
"resource": {
348335
"resourceType": "Location",
336+
"meta": {
337+
"profile": [
338+
"http://hl7.org/fhir/us/ecr/StructureDefinition/us-ph-location"
339+
],
340+
"source": "ecr"
341+
},
349342
"id": "bea8eaff-b016-f74b-10ab-9d0440257223",
350343
"identifier": [
351344
{
@@ -360,9 +353,42 @@
360353
}
361354
}
362355
],
363-
"meta": {
364-
"source": "ecr"
365-
}
356+
"_name": {
357+
"extension": [
358+
{
359+
"url": "http://hl7.org/fhir/StructureDefinition/data-absent-reason",
360+
"valueCode": "not-applicable"
361+
}
362+
]
363+
},
364+
"address": {
365+
"_city": {
366+
"extension": [
367+
{
368+
"url": "http://hl7.org/fhir/StructureDefinition/data-absent-reason",
369+
"valueCode": "not-applicable"
370+
}
371+
]
372+
},
373+
"_state": {
374+
"extension": [
375+
{
376+
"url": "http://hl7.org/fhir/StructureDefinition/data-absent-reason",
377+
"valueCode": "not-applicable"
378+
}
379+
]
380+
}
381+
},
382+
"type": [
383+
{
384+
"coding": [
385+
{
386+
"code": "not-applicable",
387+
"system": "http://terminology.hl7.org/CodeSystem/data-absent-reason"
388+
}
389+
]
390+
}
391+
]
366392
}
367393
},
368394
{

src/Microsoft.Health.Fhir.Liquid.Converter.FunctionalTests/BaseConvertDataFunctionalTests.cs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -239,11 +239,11 @@ public static IEnumerable<object[]> GetDataForEcr()
239239
// 4. whether the file should fail at parsing or validation when testing if valid (if it is fully valid, "validation" is what should be there)
240240
// 5. The number of expected failures at the step in (4)
241241
// ]
242-
new[] { @"EICR", @"eCR_full.xml", @"eCR_full-expected.json", "validation", "13" },
243-
new[] { @"EICR", @"eCR_RR_combined_3_1.xml", @"eCR_RR_combined_3_1-expected.json", "validation", "26" },
244-
new[] { @"EICR", @"eCR_EveEverywoman.xml", @"eCR_EveEverywoman-expected.json", "validation", "58" },
245-
new[] { @"EICR", @"eicr04152020.xml", @"eicr04152020-expected.json", "validation", "22" },
246-
new[] { @"EICR", @"CDAR2_IG_PHCASERPT_R2_D2_SAMPLE.xml", @"CDAR2_IG_PHCASERPT_R2_D2_SAMPLE-expected.json", "validation", "32" },
242+
new[] { @"EICR", @"eCR_full.xml", @"eCR_full-expected.json", "validation", "12" },
243+
new[] { @"EICR", @"eCR_RR_combined_3_1.xml", @"eCR_RR_combined_3_1-expected.json", "validation", "25" },
244+
new[] { @"EICR", @"eCR_EveEverywoman.xml", @"eCR_EveEverywoman-expected.json", "validation", "57" },
245+
new[] { @"EICR", @"eicr04152020.xml", @"eicr04152020-expected.json", "validation", "21" },
246+
new[] { @"EICR", @"CDAR2_IG_PHCASERPT_R2_D2_SAMPLE.xml", @"CDAR2_IG_PHCASERPT_R2_D2_SAMPLE-expected.json", "validation", "31" },
247247
};
248248
return data.Select(item => new[]
249249
{

src/Microsoft.Health.Fhir.Liquid.Converter.FunctionalTests/TestData/Expected/eCR/EICR/CDAR2_IG_PHCASERPT_R2_D2_SAMPLE-expected.json

Lines changed: 6 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -416,21 +416,7 @@
416416
"location": {
417417
"reference": "Location/14383c1c-7f95-3974-3e55-9d730de06b9e",
418418
"display": "Good Health Hospital"
419-
},
420-
"extension": [
421-
{
422-
"url": "http://build.fhir.org/ig/HL7/case-reporting/StructureDefinition-us-ph-location-definitions.html#Location.type",
423-
"valueCodeableConcept": {
424-
"coding": [
425-
{
426-
"code": "OF",
427-
"system": "urn:oid:2.16.840.1.113883.5.111",
428-
"display": "Outpatient facility"
429-
}
430-
]
431-
}
432-
}
433-
]
419+
}
434420
}
435421
],
436422
"serviceProvider": {
@@ -459,6 +445,11 @@
459445
"fullUrl": "urn:uuid:14383c1c-7f95-3974-3e55-9d730de06b9e",
460446
"resource": {
461447
"resourceType": "Location",
448+
"meta": {
449+
"profile": [
450+
"http://hl7.org/fhir/us/ecr/StructureDefinition/us-ph-location"
451+
]
452+
},
462453
"id": "14383c1c-7f95-3974-3e55-9d730de06b9e",
463454
"identifier": [
464455
{

0 commit comments

Comments
 (0)