Skip to content

Commit b6ca021

Browse files
fix: update patient birth sex and language code conversion (#95)
1 parent e5e1548 commit b6ca021

File tree

11 files changed

+90
-123
lines changed

11 files changed

+90
-123
lines changed
Lines changed: 17 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,17 @@
1-
{% if birthSObs -%}
2-
"url" : "http://hl7.org/fhir/us/core/StructureDefinition/us-core-birthsex",
3-
"extension" : [
4-
{
5-
"url" : "value",
6-
{% include 'Utils/ValueHelper' value: birthSobs.value, origText: SOCIALTEXT -%}
7-
},
8-
],
9-
{% endif -%}
1+
{%- assign birthSexRawValue = '' -%}
2+
{%- assign birthSexNullFlavor = '' -%}
3+
{%- if birthSObs and birthSObs.value -%}
4+
{%- assign birthSexRawValue = birthSObs.value.code | default: birthSObs.value.displayName | default: birthSObs.value.originalText._ | default: '' | strip -%}
5+
{%- assign birthSexNullFlavor = birthSObs.value.nullFlavor | default: birthSObs.nullFlavor | default: '' | upcase | strip -%}
6+
{%- endif -%}
7+
{%- assign normalizedBirthSex = birthSexRawValue | downcase | strip -%}
8+
9+
{%- assign normalizedBirthSex = normalizedBirthSex | get_property: 'ValueSet/BirthSex', 'code' -%}
10+
11+
{%- assign dataAbsentNullFlavor = birthSexNullFlavor | default: 'UNK' -%}
12+
"url": "http://hl7.org/fhir/us/core/StructureDefinition/us-core-birthsex",
13+
{%- if normalizedBirthSex != '' -%}
14+
"valueCode": "{{ normalizedBirthSex }}"
15+
{%- else -%}
16+
"valueCode": "UNK"
17+
{%- endif -%}

data/Templates/eCR/Resource/_Patient.liquid

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -37,17 +37,18 @@
3737
{ {% include 'Extension/Race' Race: patientRole.patient -%} },
3838
{ {% include 'Extension/Ethnicity' Ethnicity: patientRole.patient -%} },
3939
{ {% include 'Extension/Religion' patient: patientRole.patient -%}},
40+
{%- assign birthSexObs = '' -%}
4041
{% for entry in SOCIALOBS -%}
4142
{% assign firstTemplate = entry.observation.templateId | to_array | first -%}
4243
{% if firstTemplate.root == '2.16.840.1.113883.10.20.34.3.45' or entry.observation.code.code == '76691-5' -%}
4344
{ {% include 'Extension/GenderIdentity' gendIdOb: entry.observation -%} },
4445
{% elsif firstTemplate.root == '2.16.840.1.113883.10.20.15.2.3.48' -%}
4546
{ {% include 'Extension/TribalAffiliation' tribeAOb: entry.observation -%} },
46-
{% elsif firstTemplate.root == '2.16.840.1.113883.10.20.22.4.200' -%}
47-
{ {% include 'Extension/BirthSex' birthSObs: entry.observation -%} },
47+
{% elsif entry.observation.code.code == '76689-9' and birthSexObs == '' -%}
48+
{% assign birthSexObs = entry.observation -%}
4849
{% endif -%}
4950
{% endfor -%}
50-
51+
{ {% include 'Extension/BirthSex' birthSObs: birthSexObs -%} },
5152
],
5253
"address":
5354
[
@@ -92,17 +93,20 @@
9293
[
9394
{% assign languageCommunications = patientRole.patient.languageCommunication | to_array -%}
9495
{% for languageCommunication in languageCommunications -%}
96+
{%- assign langCode = languageCommunication.languageCode.code | downcase | strip | default: '' -%}
97+
{%- assign mappedCode = langCode | get_property: 'ValueSet/Language', 'code' -%}
98+
{%- assign mappedDisplay = langCode | get_property: 'ValueSet/Language', 'display' -%}
99+
{%- assign cdaNullFlavor = languageCommunication.languageCode.nullFlavor | upcase | strip | default: '' -%}
100+
{%- assign nullFlavorToUse = cdaNullFlavor | default: 'OTH' -%}
95101
{
96102
"language":
97103
{
98-
"coding":
99-
[
100-
{
101-
"system":"urn:ietf:bcp:47",
102-
"code":"{{ languageCommunication.languageCode.code | downcase | get_property: 'ValueSet/Language', , 'code' }}",
103-
"display":"{{ languageCommunication.languageCode.code | downcase | get_property: 'ValueSet/Language', , 'display' }}",
104-
},
105-
],
104+
{%- if mappedCode != '' -%}
105+
"coding": [ { "system":"urn:ietf:bcp:47", "code":"{{ mappedCode }}", "display":"{{ mappedDisplay }}" } ]
106+
{%- else -%}
107+
"extension": [ {% include 'Extension/DataAbsentReason' nullFlavor: nullFlavorToUse -%} ],
108+
"text": "{{ languageCommunication.languageCode.displayName | default: languageCommunication.languageCode.code }}"
109+
{%- endif -%}
106110
},
107111
{% if languageCommunication.preferenceInd.value -%}
108112
"preferred": {{ languageCommunication.preferenceInd.value }},

data/Templates/eCR/ValueSet/ValueSet.json

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -364,6 +364,32 @@
364364
"code": ""
365365
}
366366
},
367+
"ValueSet/BirthSex": {
368+
"m": {
369+
"code": "M"
370+
},
371+
"male": {
372+
"code": "M"
373+
},
374+
"f": {
375+
"code": "F"
376+
},
377+
"female": {
378+
"code": "F"
379+
},
380+
"u": {
381+
"code": "UNK"
382+
},
383+
"unk": {
384+
"code": "UNK"
385+
},
386+
"unknown": {
387+
"code": "UNK"
388+
},
389+
"__default__": {
390+
"code": ""
391+
}
392+
},
367393
"ValueSet/ImmunizationStatus": {
368394
"cancelled": {
369395
"code": "not-done"

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

Lines changed: 1 addition & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -961,20 +961,7 @@
961961
},
962962
{
963963
"url": "http://hl7.org/fhir/us/core/StructureDefinition/us-core-birthsex",
964-
"extension": [
965-
{
966-
"url": "value",
967-
"valueCodeableConcept": {
968-
"coding": [
969-
{
970-
"code": "M",
971-
"system": "urn:oid:2.16.840.1.113883.5.1",
972-
"display": "Male"
973-
}
974-
]
975-
}
976-
}
977-
]
964+
"valueCode": "M"
978965
}
979966
],
980967
"address": [

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

Lines changed: 1 addition & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -640,20 +640,7 @@
640640
},
641641
{
642642
"url": "http://hl7.org/fhir/us/core/StructureDefinition/us-core-birthsex",
643-
"extension": [
644-
{
645-
"url": "value",
646-
"valueCodeableConcept": {
647-
"coding": [
648-
{
649-
"code": "M",
650-
"system": "urn:oid:2.16.840.1.113883.5.1",
651-
"display": "Male"
652-
}
653-
]
654-
}
655-
}
656-
]
643+
"valueCode": "M"
657644
}
658645
],
659646
"address": [

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

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -237,13 +237,13 @@ public static IEnumerable<object[]> GetDataForEcr()
237237
// 2. ecr file,
238238
// 3. expected fhir file,
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)
240-
// 5. The number of expected failures at the step in (4)
240+
// 5. The number of expected failures at the step in (4) for the numFailures parameter
241241
// ]
242-
new[] { @"EICR", @"eCR_full.xml", @"eCR_full-expected.json", "validation", "8" },
243-
new[] { @"EICR", @"eCR_RR_combined_3_1.xml", @"eCR_RR_combined_3_1-expected.json", "validation", "12" },
244-
new[] { @"EICR", @"eCR_EveEverywoman.xml", @"eCR_EveEverywoman-expected.json", "validation", "36" },
245-
new[] { @"EICR", @"eicr04152020.xml", @"eicr04152020-expected.json", "validation", "17" },
246-
new[] { @"EICR", @"CDAR2_IG_PHCASERPT_R2_D2_SAMPLE.xml", @"CDAR2_IG_PHCASERPT_R2_D2_SAMPLE-expected.json", "validation", "20" },
242+
new[] { @"EICR", @"eCR_full.xml", @"eCR_full-expected.json", "validation", "6" },
243+
new[] { @"EICR", @"eCR_RR_combined_3_1.xml", @"eCR_RR_combined_3_1-expected.json", "validation", "10" },
244+
new[] { @"EICR", @"eCR_EveEverywoman.xml", @"eCR_EveEverywoman-expected.json", "validation", "34" },
245+
new[] { @"EICR", @"eicr04152020.xml", @"eicr04152020-expected.json", "validation", "16" },
246+
new[] { @"EICR", @"CDAR2_IG_PHCASERPT_R2_D2_SAMPLE.xml", @"CDAR2_IG_PHCASERPT_R2_D2_SAMPLE-expected.json", "validation", "18" },
247247
};
248248
return data.Select(item => new[]
249249
{
@@ -369,8 +369,8 @@ protected void ConvertCCDAMessageAndValidateExpectedResponse(ITemplateProvider t
369369
var inputContent = File.ReadAllText(inputFile);
370370
var actualContent = ccdaProcessor.Convert(inputContent, rootTemplate, templateProvider);
371371

372-
var updateSnaphot = Environment.GetEnvironmentVariable("UPDATE_SNAPSHOT") ?? "false";
373-
if (updateSnaphot.Trim() == "true")
372+
var updateSnapshot = Environment.GetEnvironmentVariable("UPDATE_SNAPSHOT") ?? "false";
373+
if (updateSnapshot.Trim() == "true")
374374
{
375375
File.WriteAllText(expectedFile, actualContent);
376376
}

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

Lines changed: 4 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -745,23 +745,6 @@
745745
}
746746
]
747747
},
748-
{
749-
"url": "http://hl7.org/fhir/us/core/StructureDefinition/us-core-birthsex",
750-
"extension": [
751-
{
752-
"url": "value",
753-
"valueCodeableConcept": {
754-
"coding": [
755-
{
756-
"code": "F",
757-
"system": "urn:oid:2.16.840.1.113883.5.1",
758-
"display": "Female"
759-
}
760-
]
761-
}
762-
}
763-
]
764-
},
765748
{
766749
"url": "http://hl7.org/fhir/us/ecr/StructureDefinition/us-ph-genderidentity-extension",
767750
"extension": [
@@ -778,6 +761,10 @@
778761
}
779762
}
780763
]
764+
},
765+
{
766+
"url": "http://hl7.org/fhir/us/core/StructureDefinition/us-core-birthsex",
767+
"valueCode": "F"
781768
}
782769
],
783770
"address": [

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

Lines changed: 4 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1361,23 +1361,6 @@
13611361
}
13621362
]
13631363
},
1364-
{
1365-
"url": "http://hl7.org/fhir/us/core/StructureDefinition/us-core-birthsex",
1366-
"extension": [
1367-
{
1368-
"url": "value",
1369-
"valueCodeableConcept": {
1370-
"coding": [
1371-
{
1372-
"code": "F",
1373-
"system": "urn:oid:2.16.840.1.113883.5.1",
1374-
"display": "Female"
1375-
}
1376-
]
1377-
}
1378-
}
1379-
]
1380-
},
13811364
{
13821365
"url": "http://hl7.org/fhir/us/ecr/StructureDefinition/us-ph-genderidentity-extension",
13831366
"extension": [
@@ -1411,6 +1394,10 @@
14111394
"valueBoolean": true
14121395
}
14131396
]
1397+
},
1398+
{
1399+
"url": "http://hl7.org/fhir/us/core/StructureDefinition/us-core-birthsex",
1400+
"valueCode": "F"
14141401
}
14151402
],
14161403
"address": [

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

Lines changed: 4 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1137,22 +1137,6 @@
11371137
}
11381138
]
11391139
},
1140-
{
1141-
"url": "http://hl7.org/fhir/us/core/StructureDefinition/us-core-birthsex",
1142-
"extension": [
1143-
{
1144-
"url": "value",
1145-
"valueCodeableConcept": {
1146-
"coding": [
1147-
{
1148-
"code": "M",
1149-
"system": "urn:oid:2.16.840.1.113883.5.1"
1150-
}
1151-
]
1152-
}
1153-
}
1154-
]
1155-
},
11561140
{
11571141
"url": "http://hl7.org/fhir/us/ecr/StructureDefinition/us-ph-genderidentity-extension",
11581142
"extension": [
@@ -1161,6 +1145,10 @@
11611145
"valueString": "Not on file"
11621146
}
11631147
]
1148+
},
1149+
{
1150+
"url": "http://hl7.org/fhir/us/core/StructureDefinition/us-core-birthsex",
1151+
"valueCode": "M"
11641152
}
11651153
],
11661154
"address": [

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

Lines changed: 1 addition & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -611,20 +611,7 @@
611611
},
612612
{
613613
"url": "http://hl7.org/fhir/us/core/StructureDefinition/us-core-birthsex",
614-
"extension": [
615-
{
616-
"url": "value",
617-
"valueCodeableConcept": {
618-
"coding": [
619-
{
620-
"code": "M",
621-
"system": "urn:oid:2.16.840.1.113883.5.1",
622-
"display": "Male"
623-
}
624-
]
625-
}
626-
}
627-
]
614+
"valueCode": "M"
628615
}
629616
],
630617
"address": [

0 commit comments

Comments
 (0)