Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -316,12 +317,16 @@ private List<Coding> getNonSnomedCodeCodings(CodeableConcept codeableConcept) {
.filter(coding -> !isSnomed(coding))
.toList();

List<Coding> 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<String> findOriginalText(CodeableConcept codeableConcept, Optional<Coding> coding) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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, "");
}
}
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
<code{{#nullFlavor}} nullFlavor="UNK"{{/nullFlavor}}{{^nullFlavor}} code="{{mainCode}}" codeSystem="{{mainCodeSystem}}" displayName="{{mainDisplayName}}"{{/nullFlavor}}>
{{#mainOriginalText}}
<originalText>{{mainOriginalText}}</originalText>
{{/mainOriginalText}}
{{#translations}}
<translation code="{{code}}" codeSystem="{{system}}" displayName="{{display}}" />
{{/translations}}
{{#mainOriginalText}}
<originalText>{{mainOriginalText}}</originalText>
{{/mainOriginalText}}
</code>
Original file line number Diff line number Diff line change
Expand Up @@ -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 = """
<code code="123456" codeSystem="2.16.840.1.113883.2.1.3.2.4.15" displayName="Endometriosis of uterus">
</code>""";
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 = """
Expand Down Expand Up @@ -351,9 +381,9 @@ void When_WithSnomedCodingAndLegacyCodings_Expect_SnomedCdXmlWithTranslations()
}""";
var expectedOutput = """
<code code="852471000000107" codeSystem="2.16.840.1.113883.2.1.3.2.4.15" displayName="Prothrombin time">
<originalText>Prothrombin time</originalText>
<translation code="42Q5.00" codeSystem="2.16.840.1.113883.2.1.6.2" displayName="Observed Prothrombin time" />
<translation code="123456" codeSystem="2.16.840.1.113883.2.1.3.2.4.14" displayName="Prothrombin time (observed)" />
<originalText>Prothrombin time</originalText>
</code>""";
var codeableConcept = fhirParseService.parseResource(inputJson, Observation.class).getCode();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,14 @@

import java.util.stream.Stream;

public class CodeSystemUtilTest {

class CodeSystemUtilTest {
private static Stream<Arguments> 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")
);
}

Expand All @@ -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();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
<CompoundStatement classCode="BATTERY" moodCode="EVN">
<id root="5E496953-065B-41F2-9577-BE8F2FBD0757"/>
<code code="852471000000107" codeSystem="2.16.840.1.113883.2.1.3.2.4.15" displayName="Prothrombin time">
<translation code="42Q5.00" codeSystem="2.16.840.1.113883.2.1.6.2" displayName="Prothrombin time" />
<originalText>Prothrombin time</originalText>
<translation code="42Q5.00" codeSystem="2.16.840.1.113883.2.1.6.2" displayName="Prothrombin time" />
</code>
<statusCode code="COMPLETE"/>
<effectiveTime>
Expand All @@ -14,8 +14,8 @@
<ObservationStatement classCode="OBS" moodCode="EVN">
<id root="5E496953-065B-41F2-9577-BE8F2FBD0757"/>
<code code="72313002" codeSystem="2.16.840.1.113883.2.1.3.2.4.15" displayName="Systolic arterial pressure">
<translation code="2469" codeSystem="2.16.840.1.113883.2.1.6.3" displayName="Systolic arterial pressure" />
<originalText>Systolic arterial pressure</originalText>
<translation code="2469" codeSystem="2.16.840.1.113883.2.1.6.3" displayName="Systolic arterial pressure" />
</code>
<statusCode code="COMPLETE"/>
<effectiveTime>
Expand All @@ -36,8 +36,8 @@
<ObservationStatement classCode="OBS" moodCode="EVN">
<id root="5E496953-065B-41F2-9577-BE8F2FBD0757"/>
<code code="1091811000000102" codeSystem="2.16.840.1.113883.2.1.3.2.4.15" displayName="Diastolic arterial pressure">
<translation code="246A" codeSystem="2.16.840.1.113883.2.1.6.3" displayName="Diastolic arterial pressure" />
<originalText>Diastolic arterial pressure</originalText>
<translation code="246A" codeSystem="2.16.840.1.113883.2.1.6.3" displayName="Diastolic arterial pressure" />
</code>
<statusCode code="COMPLETE"/>
<effectiveTime>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<code code="292971006" codeSystem="2.16.840.1.113883.2.1.3.2.4.15" displayName="Pivampicillin adverse reaction pt">
<originalText>Pivampicillin adverse reaction (rt)</originalText>
<translation code="TJ00800" codeSystem="2.16.840.1.113883.2.1.6.2" displayName="Adverse reaction to pivampicillin pt" />
<translation code="TJ00800-1" codeSystem="2.16.840.1.113883.2.1.3.2.4.14" displayName="Adverse reaction to pivampicillin" />
<originalText>Pivampicillin adverse reaction (rt)</originalText>
</code>
Original file line number Diff line number Diff line change
Expand Up @@ -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
},
Expand Down