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 2868090a5..4b93e96c1 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 @@ -17,6 +17,7 @@ import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; import uk.nhs.adaptors.gp2gp.ehr.mapper.parameters.CodeableConceptCdTemplateParameters; +import uk.nhs.adaptors.gp2gp.ehr.utils.CodeSystemsUtil; import uk.nhs.adaptors.gp2gp.ehr.utils.CodeableConceptMappingUtils; import uk.nhs.adaptors.gp2gp.ehr.utils.TemplateUtils; @@ -63,17 +64,14 @@ public String mapCodeableConceptToCd(CodeableConcept codeableConcept) { builder.mainCodeSystem(SNOMED_SYSTEM_CODE); - if (descriptionExtensions.isPresent()) { - var mainCode = getMainCode(descriptionExtensions.get(), snomedCodeCoding.get()); - mainCode.ifPresent(builder::mainCode); + var mainCode = getMainCode(descriptionExtensions, snomedCodeCoding.get()); + mainCode.ifPresent(builder::mainCode); - var mainDisplayName = getMainDisplayName(descriptionExtensions.get(), snomedCodeCoding.get()); - mainDisplayName.ifPresent(builder::mainDisplayName); + var mainDisplayName = getMainDisplayName(descriptionExtensions, snomedCodeCoding.get()); + mainDisplayName.ifPresent(builder::mainDisplayName); - if (codeableConcept.hasText()) { - builder.mainOriginalText(codeableConcept.getText()); - } - } + builder.mainOriginalText(codeableConcept.getText()); + builder.translations(getNonSnomedCodeCodings(codeableConcept)); return TemplateUtils.fillTemplate(CODEABLE_CONCEPT_CD_TEMPLATE, builder.build()); } @@ -329,6 +327,20 @@ private Optional getSnomedCodeCoding(CodeableConcept codeableConcept) { .findFirst(); } + private List getNonSnomedCodeCodings(CodeableConcept codeableConcept) { + var nonSnomedCodeCodings = codeableConcept.getCoding() + .stream() + .filter(coding -> !isSnomed(coding)) + .toList(); + + for (Coding coding : nonSnomedCodeCodings) { + var hl7CodeSystem = CodeSystemsUtil.getHl7code(coding.getSystem()); + coding.setSystem(hl7CodeSystem); + } + + return nonSnomedCodeCodings; + } + private Optional findOriginalText(CodeableConcept codeableConcept, Optional coding) { if (coding.isPresent()) { if (codeableConcept.hasText()) { @@ -457,30 +469,33 @@ private String buildNullFlavourCodeableConceptCd(CodeableConcept codeableConcept return TemplateUtils.fillTemplate(CODEABLE_CONCEPT_CD_TEMPLATE, builder.build()); } - private Optional getMainCode(List descriptionExtensions, Coding snomedCodeCoding) { - var descriptionCode = descriptionExtensions.stream() - .filter(descriptionExt -> DESCRIPTION_ID.equals(descriptionExt.getUrl())) - .map(description -> description.getValue().toString()) - .findFirst(); + private Optional getMainCode(Optional> descriptionExtensions, Coding snomedCodeCoding) { + if (descriptionExtensions.isPresent()) { + var descriptionCode = descriptionExtensions.get().stream() + .filter(descriptionExt -> DESCRIPTION_ID.equals(descriptionExt.getUrl())) + .map(description -> description.getValue().toString()) + .findFirst(); - if (descriptionCode.isPresent()) { - return descriptionCode; + if (descriptionCode.isPresent()) { + return descriptionCode; + } } return Optional.ofNullable(snomedCodeCoding.getCode()); } - private Optional getMainDisplayName(List descriptionExtensions, Coding snomedCodeCoding) { - var descriptionDisplayName = descriptionExtensions.stream() - .filter(descriptionExt -> DESCRIPTION_DISPLAY.equals(descriptionExt.getUrl())) - .map(description -> description.getValue().toString()) - .findFirst(); + private Optional getMainDisplayName(Optional> descriptionExtensions, Coding snomedCodeCoding) { + if (descriptionExtensions.isPresent()) { + var descriptionDisplayName = descriptionExtensions.get().stream() + .filter(descriptionExt -> DESCRIPTION_DISPLAY.equals(descriptionExt.getUrl())) + .map(description -> description.getValue().toString()) + .findFirst(); - if (descriptionDisplayName.isPresent()) { - return descriptionDisplayName; + if (descriptionDisplayName.isPresent()) { + return descriptionDisplayName; + } } return Optional.ofNullable(snomedCodeCoding.getDisplay()); } - } diff --git a/service/src/main/java/uk/nhs/adaptors/gp2gp/ehr/mapper/parameters/CodeableConceptCdTemplateParameters.java b/service/src/main/java/uk/nhs/adaptors/gp2gp/ehr/mapper/parameters/CodeableConceptCdTemplateParameters.java index 6ef08cd3a..32d893799 100644 --- a/service/src/main/java/uk/nhs/adaptors/gp2gp/ehr/mapper/parameters/CodeableConceptCdTemplateParameters.java +++ b/service/src/main/java/uk/nhs/adaptors/gp2gp/ehr/mapper/parameters/CodeableConceptCdTemplateParameters.java @@ -3,6 +3,9 @@ import lombok.Builder; import lombok.Getter; import lombok.Setter; +import org.hl7.fhir.dstu3.model.Coding; + +import java.util.List; @Getter @Setter @@ -12,5 +15,6 @@ public class CodeableConceptCdTemplateParameters { private String mainCodeSystem; private String mainDisplayName; private String mainOriginalText; + private List translations; private boolean nullFlavor; } 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 f9e71ef4c..b9126a3c4 100644 --- a/service/src/main/resources/templates/codeable_concept_cd_template.mustache +++ b/service/src/main/resources/templates/codeable_concept_cd_template.mustache @@ -1,4 +1,7 @@ + {{#translations}} + + {{/translations}} {{#mainOriginalText}} {{mainOriginalText}} {{/mainOriginalText}} 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 28e320ee8..c6ab124d7 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 @@ -85,6 +85,43 @@ public void When_MappingStubbedCodeableConcept_Expect_HL7CdObjectXml(String inpu .isEqualToIgnoringWhitespace(expectedOutput); } + @Test + void When_MappingCodeableConceptWithNonSnomedCodeSystems_Expect_ManifestedXmlContainsTranslationsForThoseCodes() { + var inputJson = """ + { + "resourceType" : "Observation", + "code": { + "coding": [ + { + "system": "http://snomed.info/sct", + "code": "123456", + "display": "Endometriosis of uterus" + }, + { + "system": "http://read.info/readv2", + "code": "READ0", + "display": "Read V2 Code Display" + }, + { + "system": "http://read.info/ctv3", + "code": "READ1", + "display": "Read CTV3 Code Display" + } + ] + } + }"""; + var expectedOutputXml = """ + + + + """; + var codeableConcept = fhirParseService.parseResource(inputJson, Observation.class).getCode(); + + var outputMessageXml = codeableConceptCdMapper.mapCodeableConceptToCd(codeableConcept); + + assertThat(outputMessageXml).isEqualToIgnoringWhitespace(expectedOutputXml); + } + @ParameterizedTest @MethodSource("getTestArgumentsActualProblem") public void When_MappingStubbedCodeableConceptForActualProblemHeader_Expect_HL7CdObjectXml(String inputJson, String outputXml) diff --git a/service/src/test/resources/ehr/mapper/codeableconcept/codeable_concept_snomed_with_description.json b/service/src/test/resources/ehr/mapper/codeableconcept/codeable_concept_snomed_with_description.json index 8d78244de..60d00c47f 100644 --- a/service/src/test/resources/ehr/mapper/codeableconcept/codeable_concept_snomed_with_description.json +++ b/service/src/test/resources/ehr/mapper/codeableconcept/codeable_concept_snomed_with_description.json @@ -2,12 +2,6 @@ "resourceType" : "Observation", "code": { "coding": [ - { - "system": "http://blah.info/blahsomecodesystem", - "code": "X%^^%", - "display": "Display for invalid code/system", - "userSelected": true - }, { "extension": [ { diff --git a/service/src/test/resources/ehr/mapper/codeableconcept/codeable_concept_snomed_with_no_description.json b/service/src/test/resources/ehr/mapper/codeableconcept/codeable_concept_snomed_with_no_description.json index 90cfb7a73..b16069cfe 100644 --- a/service/src/test/resources/ehr/mapper/codeableconcept/codeable_concept_snomed_with_no_description.json +++ b/service/src/test/resources/ehr/mapper/codeableconcept/codeable_concept_snomed_with_no_description.json @@ -2,12 +2,6 @@ "resourceType" : "Observation", "code": { "coding": [ - { - "system": "http://blah.info/blahsomecodesystem", - "code": "X%^^%", - "display": "Display for invalid code/system", - "userSelected": true - }, { "extension": [ { diff --git a/service/src/test/resources/ehr/mapper/codeableconcept/codeable_concept_with_text.json b/service/src/test/resources/ehr/mapper/codeableconcept/codeable_concept_with_text.json index 14f5a4a0b..0fd642e05 100644 --- a/service/src/test/resources/ehr/mapper/codeableconcept/codeable_concept_with_text.json +++ b/service/src/test/resources/ehr/mapper/codeableconcept/codeable_concept_with_text.json @@ -2,12 +2,6 @@ "resourceType" : "Observation", "code": { "coding": [ - { - "system": "http://blah.info/blahsomecodesystem", - "code": "X%^^%", - "display": "Display for invalid code/system", - "userSelected": true - }, { "extension": [ { diff --git a/service/src/test/resources/ehr/mapper/codeableconcept/codeable_concept_without_text.json b/service/src/test/resources/ehr/mapper/codeableconcept/codeable_concept_without_text.json index 0ca4935f3..1ba22e9a2 100644 --- a/service/src/test/resources/ehr/mapper/codeableconcept/codeable_concept_without_text.json +++ b/service/src/test/resources/ehr/mapper/codeableconcept/codeable_concept_without_text.json @@ -2,12 +2,7 @@ "resourceType" : "Observation", "code": { "coding": [ - { - "system": "http://blah.info/blahsomecodesystem", - "code": "F%^^%", - "display": "Happy puppet syndrome", - "userSelected": true - }, { + { "extension": [ { "url": "https://fhir.nhs.uk/STU3/StructureDefinition/Extension-coding-sctdescid", diff --git a/service/src/test/resources/ehr/mapper/diagnosticreport/observation/observation_compound_statement_1.xml b/service/src/test/resources/ehr/mapper/diagnosticreport/observation/observation_compound_statement_1.xml index 543788ccd..9ec212e15 100644 --- a/service/src/test/resources/ehr/mapper/diagnosticreport/observation/observation_compound_statement_1.xml +++ b/service/src/test/resources/ehr/mapper/diagnosticreport/observation/observation_compound_statement_1.xml @@ -2,7 +2,8 @@ - + +
@@ -12,7 +13,8 @@ - + +
diff --git a/service/src/test/resources/ehr/mapper/diagnosticreport/observation/observation_compound_statement_1_with_related_comment.xml b/service/src/test/resources/ehr/mapper/diagnosticreport/observation/observation_compound_statement_1_with_related_comment.xml index 71d98d118..955e03ddd 100644 --- a/service/src/test/resources/ehr/mapper/diagnosticreport/observation/observation_compound_statement_1_with_related_comment.xml +++ b/service/src/test/resources/ehr/mapper/diagnosticreport/observation/observation_compound_statement_1_with_related_comment.xml @@ -2,7 +2,8 @@ - + +
@@ -12,7 +13,8 @@ - + +
diff --git a/service/src/test/resources/ehr/mapper/diagnosticreport/observation/observation_compound_statement_2.xml b/service/src/test/resources/ehr/mapper/diagnosticreport/observation/observation_compound_statement_2.xml index 31b33f458..89030d96d 100644 --- a/service/src/test/resources/ehr/mapper/diagnosticreport/observation/observation_compound_statement_2.xml +++ b/service/src/test/resources/ehr/mapper/diagnosticreport/observation/observation_compound_statement_2.xml @@ -2,7 +2,8 @@ - + +
@@ -12,7 +13,8 @@ - + +
diff --git a/service/src/test/resources/ehr/mapper/diagnosticreport/observation/observation_compound_statement_3.xml b/service/src/test/resources/ehr/mapper/diagnosticreport/observation/observation_compound_statement_3.xml index 7582c0bcf..5ca86562f 100644 --- a/service/src/test/resources/ehr/mapper/diagnosticreport/observation/observation_compound_statement_3.xml +++ b/service/src/test/resources/ehr/mapper/diagnosticreport/observation/observation_compound_statement_3.xml @@ -2,7 +2,8 @@ - + +
@@ -12,7 +13,8 @@ - + +
diff --git a/service/src/test/resources/ehr/mapper/diagnosticreport/observation/observation_compound_statement_clustered_by_diagnosticreport_reference.xml b/service/src/test/resources/ehr/mapper/diagnosticreport/observation/observation_compound_statement_clustered_by_diagnosticreport_reference.xml index cdd5cfaf1..44d2ae2e4 100644 --- a/service/src/test/resources/ehr/mapper/diagnosticreport/observation/observation_compound_statement_clustered_by_diagnosticreport_reference.xml +++ b/service/src/test/resources/ehr/mapper/diagnosticreport/observation/observation_compound_statement_clustered_by_diagnosticreport_reference.xml @@ -2,7 +2,8 @@ - + +
@@ -12,7 +13,8 @@ - + +
diff --git a/service/src/test/resources/ehr/mapper/diagnosticreport/observation/observation_compound_statement_with_availabilitytime_and_low_effectivetime.xml b/service/src/test/resources/ehr/mapper/diagnosticreport/observation/observation_compound_statement_with_availabilitytime_and_low_effectivetime.xml index ea54612c4..0ca476560 100644 --- a/service/src/test/resources/ehr/mapper/diagnosticreport/observation/observation_compound_statement_with_availabilitytime_and_low_effectivetime.xml +++ b/service/src/test/resources/ehr/mapper/diagnosticreport/observation/observation_compound_statement_with_availabilitytime_and_low_effectivetime.xml @@ -2,7 +2,8 @@ - + + @@ -12,7 +13,8 @@ - + + diff --git a/service/src/test/resources/ehr/mapper/diagnosticreport/observation/observation_compound_statement_with_battery_test_result.xml b/service/src/test/resources/ehr/mapper/diagnosticreport/observation/observation_compound_statement_with_battery_test_result.xml index 4deed4ebc..e3801255e 100644 --- a/service/src/test/resources/ehr/mapper/diagnosticreport/observation/observation_compound_statement_with_battery_test_result.xml +++ b/service/src/test/resources/ehr/mapper/diagnosticreport/observation/observation_compound_statement_with_battery_test_result.xml @@ -2,6 +2,7 @@ + @@ -12,6 +13,7 @@ + @@ -22,6 +24,7 @@ + diff --git a/service/src/test/resources/ehr/mapper/diagnosticreport/observation/observation_compound_statement_with_data_absent_reason_and_interpretation_and_body_site_and_method.xml b/service/src/test/resources/ehr/mapper/diagnosticreport/observation/observation_compound_statement_with_data_absent_reason_and_interpretation_and_body_site_and_method.xml index c65269cb5..fa7eeabb3 100644 --- a/service/src/test/resources/ehr/mapper/diagnosticreport/observation/observation_compound_statement_with_data_absent_reason_and_interpretation_and_body_site_and_method.xml +++ b/service/src/test/resources/ehr/mapper/diagnosticreport/observation/observation_compound_statement_with_data_absent_reason_and_interpretation_and_body_site_and_method.xml @@ -2,7 +2,8 @@ - + +
@@ -12,7 +13,8 @@ - + +
diff --git a/service/src/test/resources/ehr/mapper/diagnosticreport/observation/observation_compound_statement_with_no_effective_properly_handled.xml b/service/src/test/resources/ehr/mapper/diagnosticreport/observation/observation_compound_statement_with_no_effective_properly_handled.xml index 992f20b3b..2cf87b6ee 100644 --- a/service/src/test/resources/ehr/mapper/diagnosticreport/observation/observation_compound_statement_with_no_effective_properly_handled.xml +++ b/service/src/test/resources/ehr/mapper/diagnosticreport/observation/observation_compound_statement_with_no_effective_properly_handled.xml @@ -2,7 +2,8 @@ - + +
@@ -12,7 +13,8 @@ - + +
diff --git a/service/src/test/resources/ehr/mapper/diagnosticreport/observation/observation_compound_statement_with_reference_range_and_interpretation.xml b/service/src/test/resources/ehr/mapper/diagnosticreport/observation/observation_compound_statement_with_reference_range_and_interpretation.xml index 22da863c8..3d28a1643 100644 --- a/service/src/test/resources/ehr/mapper/diagnosticreport/observation/observation_compound_statement_with_reference_range_and_interpretation.xml +++ b/service/src/test/resources/ehr/mapper/diagnosticreport/observation/observation_compound_statement_with_reference_range_and_interpretation.xml @@ -2,7 +2,8 @@ - + +
diff --git a/service/src/test/resources/ehr/mapper/diagnosticreport/observation/observation_compound_statement_with_value_string.xml b/service/src/test/resources/ehr/mapper/diagnosticreport/observation/observation_compound_statement_with_value_string.xml index 0392b8dd2..c51bc2c36 100644 --- a/service/src/test/resources/ehr/mapper/diagnosticreport/observation/observation_compound_statement_with_value_string.xml +++ b/service/src/test/resources/ehr/mapper/diagnosticreport/observation/observation_compound_statement_with_value_string.xml @@ -2,7 +2,8 @@ - + +