diff --git a/service/src/main/java/uk/nhs/adaptors/gp2gp/ehr/mapper/CodeableConceptCdMapper.java b/service/src/main/java/uk/nhs/adaptors/gp2gp/ehr/mapper/CodeableConceptCdMapper.java index b648ad624..7f4522f3c 100644 --- a/service/src/main/java/uk/nhs/adaptors/gp2gp/ehr/mapper/CodeableConceptCdMapper.java +++ b/service/src/main/java/uk/nhs/adaptors/gp2gp/ehr/mapper/CodeableConceptCdMapper.java @@ -1,5 +1,6 @@ package uk.nhs.adaptors.gp2gp.ehr.mapper; +import java.util.ArrayList; import java.util.Collections; import java.util.List; import java.util.Optional; @@ -316,12 +317,16 @@ private List getNonSnomedCodeCodings(CodeableConcept codeableConcept) { .filter(coding -> !isSnomed(coding)) .toList(); + List nonSnomedCodings = new ArrayList<>(); + for (Coding coding : nonSnomedCodeCodings) { var hl7CodeSystem = CodeSystemsUtil.getHl7code(coding.getSystem()); - coding.setSystem(hl7CodeSystem); + if (!hl7CodeSystem.isEmpty()) { + nonSnomedCodings.add(new Coding(hl7CodeSystem, coding.getCode(), coding.getDisplay())); + } } - return nonSnomedCodeCodings; + return nonSnomedCodings; } private Optional findOriginalText(CodeableConcept codeableConcept, Optional coding) { diff --git a/service/src/main/java/uk/nhs/adaptors/gp2gp/ehr/utils/CodeSystemsUtil.java b/service/src/main/java/uk/nhs/adaptors/gp2gp/ehr/utils/CodeSystemsUtil.java index 11d2bc668..9af6c8ec7 100644 --- a/service/src/main/java/uk/nhs/adaptors/gp2gp/ehr/utils/CodeSystemsUtil.java +++ b/service/src/main/java/uk/nhs/adaptors/gp2gp/ehr/utils/CodeSystemsUtil.java @@ -12,10 +12,11 @@ public final class CodeSystemsUtil { "http://snomed.info/sct", "2.16.840.1.113883.2.1.3.2.4.15", "https://fhir.hl7.org.uk/Id/egton-codes", "2.16.840.1.113883.2.1.6.3", "http://read.info/readv2", "2.16.840.1.113883.2.1.6.2", - "http://read.info/ctv3", "2.16.840.1.113883.2.1.3.2.4.14" + "http://read.info/ctv3", "2.16.840.1.113883.2.1.3.2.4.14", + "https://fhir.hl7.org.uk/Id/emis-drug-codes", "2.16.840.1.113883.2.1.6.9" ); public static String getHl7code(String fhirCodeSystem) { - return SYSTEM_CODES.getOrDefault(fhirCodeSystem, fhirCodeSystem); + return SYSTEM_CODES.getOrDefault(fhirCodeSystem, ""); } } diff --git a/service/src/main/resources/templates/codeable_concept_cd_template.mustache b/service/src/main/resources/templates/codeable_concept_cd_template.mustache index b9126a3c4..4c2a18087 100644 --- a/service/src/main/resources/templates/codeable_concept_cd_template.mustache +++ b/service/src/main/resources/templates/codeable_concept_cd_template.mustache @@ -1,8 +1,8 @@ + {{#mainOriginalText}} + {{mainOriginalText}} + {{/mainOriginalText}} {{#translations}} {{/translations}} - {{#mainOriginalText}} - {{mainOriginalText}} - {{/mainOriginalText}} \ No newline at end of file diff --git a/service/src/test/java/uk/nhs/adaptors/gp2gp/ehr/mapper/CodeableConceptCdMapperTest.java b/service/src/test/java/uk/nhs/adaptors/gp2gp/ehr/mapper/CodeableConceptCdMapperTest.java index 22d2921a1..a6dfc9042 100644 --- a/service/src/test/java/uk/nhs/adaptors/gp2gp/ehr/mapper/CodeableConceptCdMapperTest.java +++ b/service/src/test/java/uk/nhs/adaptors/gp2gp/ehr/mapper/CodeableConceptCdMapperTest.java @@ -123,6 +123,36 @@ void When_MappingCodeableConceptWithNonSnomedCodeSystems_Expect_ManifestedXmlCon assertThat(outputMessageXml).isEqualToIgnoringWhitespace(expectedOutputXml); } + @Test + void When_MappingCodeableConceptWithUnknownNonSnomedCodeSystem_Expect_ManifestedXmlDoesNotContainTranslations() { + var inputJson = """ + { + "resourceType" : "Observation", + "code": { + "coding": [ + { + "system": "http://snomed.info/sct", + "code": "123456", + "display": "Endometriosis of uterus" + }, + { + "system": "http://unknown.code/systen", + "code": "UNKNOWN01", + "display": "Unknown Code System Display" + } + ] + } + }"""; + var expectedOutputXml = """ + + """; + var codeableConcept = fhirParseService.parseResource(inputJson, Observation.class).getCode(); + + var outputMessageXml = codeableConceptCdMapper.mapCodeableConceptToCd(codeableConcept); + + assertThat(outputMessageXml).isEqualToIgnoringWhitespace(expectedOutputXml); + } + @Test void When_MapToNullFlavorCodeableConceptForAllergyWithoutSnomedCode_Expect_OriginalTextIsNotPresent() { var inputJson = """ @@ -351,9 +381,9 @@ void When_WithSnomedCodingAndLegacyCodings_Expect_SnomedCdXmlWithTranslations() }"""; var expectedOutput = """ + Prothrombin time - Prothrombin time """; var codeableConcept = fhirParseService.parseResource(inputJson, Observation.class).getCode(); diff --git a/service/src/test/java/uk/nhs/adaptors/gp2gp/utils/CodeSystemUtilTest.java b/service/src/test/java/uk/nhs/adaptors/gp2gp/utils/CodeSystemUtilTest.java index 91775b20f..df95bd2db 100644 --- a/service/src/test/java/uk/nhs/adaptors/gp2gp/utils/CodeSystemUtilTest.java +++ b/service/src/test/java/uk/nhs/adaptors/gp2gp/utils/CodeSystemUtilTest.java @@ -10,14 +10,14 @@ import java.util.stream.Stream; -public class CodeSystemUtilTest { - +class CodeSystemUtilTest { private static Stream knownCodeSystems() { return Stream.of( Arguments.of("http://snomed.info/sct", "2.16.840.1.113883.2.1.3.2.4.15"), Arguments.of("https://fhir.hl7.org.uk/Id/egton-codes", "2.16.840.1.113883.2.1.6.3"), Arguments.of("http://read.info/readv2", "2.16.840.1.113883.2.1.6.2"), - Arguments.of("http://read.info/ctv3", "2.16.840.1.113883.2.1.3.2.4.14") + Arguments.of("http://read.info/ctv3", "2.16.840.1.113883.2.1.3.2.4.14"), + Arguments.of("https://fhir.hl7.org.uk/Id/emis-drug-codes", "2.16.840.1.113883.2.1.6.9") ); } @@ -30,9 +30,9 @@ void When_FhirCodeSystemIsKnown_Expect_CorrectHl7Code(String fhirCodeSystem, Str } @Test - void When_FhirCodeSystemIsUnknown_Expect_FhirCodeSystemIsProvided() { + void When_FhirCodeSystemIsUnknown_Expect_EmptyString() { var hl7Code = CodeSystemsUtil.getHl7code("https://unknown.code/system"); - assertThat(hl7Code).isEqualTo("https://unknown.code/system"); + assertThat(hl7Code).isEmpty(); } } diff --git a/service/src/test/resources/ehr/mapper/blood_pressure/blood-pressure-with-codeable-concepts.xml b/service/src/test/resources/ehr/mapper/blood_pressure/blood-pressure-with-codeable-concepts.xml index 6665dd77b..39ff8eec4 100644 --- a/service/src/test/resources/ehr/mapper/blood_pressure/blood-pressure-with-codeable-concepts.xml +++ b/service/src/test/resources/ehr/mapper/blood_pressure/blood-pressure-with-codeable-concepts.xml @@ -2,8 +2,8 @@ - Prothrombin time + @@ -14,8 +14,8 @@ - Systolic arterial pressure + @@ -36,8 +36,8 @@ - Diastolic arterial pressure + diff --git a/service/src/test/resources/ehr/mapper/codeableconcept/allergyActive/allergy_with_snomed_and_non_snomed_codes_in_coding_with_text.xml b/service/src/test/resources/ehr/mapper/codeableconcept/allergyActive/allergy_with_snomed_and_non_snomed_codes_in_coding_with_text.xml index 2c9a4065e..7d2d1c8a8 100644 --- a/service/src/test/resources/ehr/mapper/codeableconcept/allergyActive/allergy_with_snomed_and_non_snomed_codes_in_coding_with_text.xml +++ b/service/src/test/resources/ehr/mapper/codeableconcept/allergyActive/allergy_with_snomed_and_non_snomed_codes_in_coding_with_text.xml @@ -1,5 +1,5 @@ + Pivampicillin adverse reaction (rt) - Pivampicillin adverse reaction (rt) \ No newline at end of file diff --git a/wiremock/stubs/__files/EMISPatientStructurede2eResponsePWTP3.json b/wiremock/stubs/__files/EMISPatientStructurede2eResponsePWTP3.json index 594791de9..907f5f660 100644 --- a/wiremock/stubs/__files/EMISPatientStructurede2eResponsePWTP3.json +++ b/wiremock/stubs/__files/EMISPatientStructurede2eResponsePWTP3.json @@ -8817,7 +8817,7 @@ "coding": [ { "system": "https://fhir.hl7.org.uk/Id/emis-drug-codes", - "code": "CO2 27587NEMIS", + "code": "CO227587NEMIS", "display": "Coloplast Micro-bag two piece ostomy system urostomy bag 14204 40mm (Coloplast Ltd)", "userSelected": true },