Skip to content

Commit 74c048e

Browse files
NIAD-3304: Ensure correct ordering of originalText when mapping CodeableConcept to CD (#1168)
* NIAD-3304: Fix issue with ordering of `originalText` when mapping to CD XML * Update CD template to ensure that `originalText` is always populated first. * Update tests to reflect the ordering change * NIAD-3304: Fix issue with ordering of `originalText` when mapping to CD XML * Update `CodeableConceptCdMapper` to only add code translations when it is possible to map from URL to OID as anything other than an OID is not supported in the schema. * Update CodesSystemsUtil to return empty string if a mapping to known code system cannot be found. * Update test accordingly. * NIAD-3304: Fix issue with ordering of `originalText` when mapping to CD XML * Update `CodeableConceptCdMapper` to create a new coding element for legacy codes, to avoid modifying an element whilst iterating a list. * NIAD-3304: Fix issue with ordering of `originalText` when mapping to CD XML * Add test for an unknown code system. * SonarCube fix to remove public modifier on test class. * Fix error in "Medications" test file, where a legacy code contains a space, which is not valid according to the schema.
1 parent 571acd5 commit 74c048e

File tree

8 files changed

+54
-18
lines changed

8 files changed

+54
-18
lines changed

service/src/main/java/uk/nhs/adaptors/gp2gp/ehr/mapper/CodeableConceptCdMapper.java

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package uk.nhs.adaptors.gp2gp.ehr.mapper;
22

3+
import java.util.ArrayList;
34
import java.util.Collections;
45
import java.util.List;
56
import java.util.Optional;
@@ -316,12 +317,16 @@ private List<Coding> getNonSnomedCodeCodings(CodeableConcept codeableConcept) {
316317
.filter(coding -> !isSnomed(coding))
317318
.toList();
318319

320+
List<Coding> nonSnomedCodings = new ArrayList<>();
321+
319322
for (Coding coding : nonSnomedCodeCodings) {
320323
var hl7CodeSystem = CodeSystemsUtil.getHl7code(coding.getSystem());
321-
coding.setSystem(hl7CodeSystem);
324+
if (!hl7CodeSystem.isEmpty()) {
325+
nonSnomedCodings.add(new Coding(hl7CodeSystem, coding.getCode(), coding.getDisplay()));
326+
}
322327
}
323328

324-
return nonSnomedCodeCodings;
329+
return nonSnomedCodings;
325330
}
326331

327332
private Optional<String> findOriginalText(CodeableConcept codeableConcept, Optional<Coding> coding) {

service/src/main/java/uk/nhs/adaptors/gp2gp/ehr/utils/CodeSystemsUtil.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,11 @@ public final class CodeSystemsUtil {
1212
"http://snomed.info/sct", "2.16.840.1.113883.2.1.3.2.4.15",
1313
"https://fhir.hl7.org.uk/Id/egton-codes", "2.16.840.1.113883.2.1.6.3",
1414
"http://read.info/readv2", "2.16.840.1.113883.2.1.6.2",
15-
"http://read.info/ctv3", "2.16.840.1.113883.2.1.3.2.4.14"
15+
"http://read.info/ctv3", "2.16.840.1.113883.2.1.3.2.4.14",
16+
"https://fhir.hl7.org.uk/Id/emis-drug-codes", "2.16.840.1.113883.2.1.6.9"
1617
);
1718

1819
public static String getHl7code(String fhirCodeSystem) {
19-
return SYSTEM_CODES.getOrDefault(fhirCodeSystem, fhirCodeSystem);
20+
return SYSTEM_CODES.getOrDefault(fhirCodeSystem, "");
2021
}
2122
}
Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
<code{{#nullFlavor}} nullFlavor="UNK"{{/nullFlavor}}{{^nullFlavor}} code="{{mainCode}}" codeSystem="{{mainCodeSystem}}" displayName="{{mainDisplayName}}"{{/nullFlavor}}>
2+
{{#mainOriginalText}}
3+
<originalText>{{mainOriginalText}}</originalText>
4+
{{/mainOriginalText}}
25
{{#translations}}
36
<translation code="{{code}}" codeSystem="{{system}}" displayName="{{display}}" />
47
{{/translations}}
5-
{{#mainOriginalText}}
6-
<originalText>{{mainOriginalText}}</originalText>
7-
{{/mainOriginalText}}
88
</code>

service/src/test/java/uk/nhs/adaptors/gp2gp/ehr/mapper/CodeableConceptCdMapperTest.java

Lines changed: 31 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,36 @@ void When_MappingCodeableConceptWithNonSnomedCodeSystems_Expect_ManifestedXmlCon
123123
assertThat(outputMessageXml).isEqualToIgnoringWhitespace(expectedOutputXml);
124124
}
125125

126+
@Test
127+
void When_MappingCodeableConceptWithUnknownNonSnomedCodeSystem_Expect_ManifestedXmlDoesNotContainTranslations() {
128+
var inputJson = """
129+
{
130+
"resourceType" : "Observation",
131+
"code": {
132+
"coding": [
133+
{
134+
"system": "http://snomed.info/sct",
135+
"code": "123456",
136+
"display": "Endometriosis of uterus"
137+
},
138+
{
139+
"system": "http://unknown.code/systen",
140+
"code": "UNKNOWN01",
141+
"display": "Unknown Code System Display"
142+
}
143+
]
144+
}
145+
}""";
146+
var expectedOutputXml = """
147+
<code code="123456" codeSystem="2.16.840.1.113883.2.1.3.2.4.15" displayName="Endometriosis of uterus">
148+
</code>""";
149+
var codeableConcept = fhirParseService.parseResource(inputJson, Observation.class).getCode();
150+
151+
var outputMessageXml = codeableConceptCdMapper.mapCodeableConceptToCd(codeableConcept);
152+
153+
assertThat(outputMessageXml).isEqualToIgnoringWhitespace(expectedOutputXml);
154+
}
155+
126156
@Test
127157
void When_MapToNullFlavorCodeableConceptForAllergyWithoutSnomedCode_Expect_OriginalTextIsNotPresent() {
128158
var inputJson = """
@@ -351,9 +381,9 @@ void When_WithSnomedCodingAndLegacyCodings_Expect_SnomedCdXmlWithTranslations()
351381
}""";
352382
var expectedOutput = """
353383
<code code="852471000000107" codeSystem="2.16.840.1.113883.2.1.3.2.4.15" displayName="Prothrombin time">
384+
<originalText>Prothrombin time</originalText>
354385
<translation code="42Q5.00" codeSystem="2.16.840.1.113883.2.1.6.2" displayName="Observed Prothrombin time" />
355386
<translation code="123456" codeSystem="2.16.840.1.113883.2.1.3.2.4.14" displayName="Prothrombin time (observed)" />
356-
<originalText>Prothrombin time</originalText>
357387
</code>""";
358388
var codeableConcept = fhirParseService.parseResource(inputJson, Observation.class).getCode();
359389

service/src/test/java/uk/nhs/adaptors/gp2gp/utils/CodeSystemUtilTest.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,14 +10,14 @@
1010

1111
import java.util.stream.Stream;
1212

13-
public class CodeSystemUtilTest {
14-
13+
class CodeSystemUtilTest {
1514
private static Stream<Arguments> knownCodeSystems() {
1615
return Stream.of(
1716
Arguments.of("http://snomed.info/sct", "2.16.840.1.113883.2.1.3.2.4.15"),
1817
Arguments.of("https://fhir.hl7.org.uk/Id/egton-codes", "2.16.840.1.113883.2.1.6.3"),
1918
Arguments.of("http://read.info/readv2", "2.16.840.1.113883.2.1.6.2"),
20-
Arguments.of("http://read.info/ctv3", "2.16.840.1.113883.2.1.3.2.4.14")
19+
Arguments.of("http://read.info/ctv3", "2.16.840.1.113883.2.1.3.2.4.14"),
20+
Arguments.of("https://fhir.hl7.org.uk/Id/emis-drug-codes", "2.16.840.1.113883.2.1.6.9")
2121
);
2222
}
2323

@@ -30,9 +30,9 @@ void When_FhirCodeSystemIsKnown_Expect_CorrectHl7Code(String fhirCodeSystem, Str
3030
}
3131

3232
@Test
33-
void When_FhirCodeSystemIsUnknown_Expect_FhirCodeSystemIsProvided() {
33+
void When_FhirCodeSystemIsUnknown_Expect_EmptyString() {
3434
var hl7Code = CodeSystemsUtil.getHl7code("https://unknown.code/system");
3535

36-
assertThat(hl7Code).isEqualTo("https://unknown.code/system");
36+
assertThat(hl7Code).isEmpty();
3737
}
3838
}

service/src/test/resources/ehr/mapper/blood_pressure/blood-pressure-with-codeable-concepts.xml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@
22
<CompoundStatement classCode="BATTERY" moodCode="EVN">
33
<id root="5E496953-065B-41F2-9577-BE8F2FBD0757"/>
44
<code code="852471000000107" codeSystem="2.16.840.1.113883.2.1.3.2.4.15" displayName="Prothrombin time">
5-
<translation code="42Q5.00" codeSystem="2.16.840.1.113883.2.1.6.2" displayName="Prothrombin time" />
65
<originalText>Prothrombin time</originalText>
6+
<translation code="42Q5.00" codeSystem="2.16.840.1.113883.2.1.6.2" displayName="Prothrombin time" />
77
</code>
88
<statusCode code="COMPLETE"/>
99
<effectiveTime>
@@ -14,8 +14,8 @@
1414
<ObservationStatement classCode="OBS" moodCode="EVN">
1515
<id root="5E496953-065B-41F2-9577-BE8F2FBD0757"/>
1616
<code code="72313002" codeSystem="2.16.840.1.113883.2.1.3.2.4.15" displayName="Systolic arterial pressure">
17-
<translation code="2469" codeSystem="2.16.840.1.113883.2.1.6.3" displayName="Systolic arterial pressure" />
1817
<originalText>Systolic arterial pressure</originalText>
18+
<translation code="2469" codeSystem="2.16.840.1.113883.2.1.6.3" displayName="Systolic arterial pressure" />
1919
</code>
2020
<statusCode code="COMPLETE"/>
2121
<effectiveTime>
@@ -36,8 +36,8 @@
3636
<ObservationStatement classCode="OBS" moodCode="EVN">
3737
<id root="5E496953-065B-41F2-9577-BE8F2FBD0757"/>
3838
<code code="1091811000000102" codeSystem="2.16.840.1.113883.2.1.3.2.4.15" displayName="Diastolic arterial pressure">
39-
<translation code="246A" codeSystem="2.16.840.1.113883.2.1.6.3" displayName="Diastolic arterial pressure" />
4039
<originalText>Diastolic arterial pressure</originalText>
40+
<translation code="246A" codeSystem="2.16.840.1.113883.2.1.6.3" displayName="Diastolic arterial pressure" />
4141
</code>
4242
<statusCode code="COMPLETE"/>
4343
<effectiveTime>
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<code code="292971006" codeSystem="2.16.840.1.113883.2.1.3.2.4.15" displayName="Pivampicillin adverse reaction pt">
2+
<originalText>Pivampicillin adverse reaction (rt)</originalText>
23
<translation code="TJ00800" codeSystem="2.16.840.1.113883.2.1.6.2" displayName="Adverse reaction to pivampicillin pt" />
34
<translation code="TJ00800-1" codeSystem="2.16.840.1.113883.2.1.3.2.4.14" displayName="Adverse reaction to pivampicillin" />
4-
<originalText>Pivampicillin adverse reaction (rt)</originalText>
55
</code>

wiremock/stubs/__files/EMISPatientStructurede2eResponsePWTP3.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8817,7 +8817,7 @@
88178817
"coding": [
88188818
{
88198819
"system": "https://fhir.hl7.org.uk/Id/emis-drug-codes",
8820-
"code": "CO2 27587NEMIS",
8820+
"code": "CO227587NEMIS",
88218821
"display": "Coloplast Micro-bag two piece ostomy system urostomy bag 14204 40mm (Coloplast Ltd)",
88228822
"userSelected": true
88238823
},

0 commit comments

Comments
 (0)