Skip to content

Commit c2a8fe5

Browse files
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.
1 parent ebd4f0e commit c2a8fe5

File tree

3 files changed

+15
-7
lines changed

3 files changed

+15
-7
lines changed

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

Lines changed: 8 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,17 @@ 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+
coding.setSystem(hl7CodeSystem);
326+
nonSnomedCodings.add(coding);
327+
}
322328
}
323329

324-
return nonSnomedCodeCodings;
330+
return nonSnomedCodings;
325331
}
326332

327333
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
}

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

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,8 @@ private static Stream<Arguments> knownCodeSystems() {
1717
Arguments.of("http://snomed.info/sct", "2.16.840.1.113883.2.1.3.2.4.15"),
1818
Arguments.of("https://fhir.hl7.org.uk/Id/egton-codes", "2.16.840.1.113883.2.1.6.3"),
1919
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")
20+
Arguments.of("http://read.info/ctv3", "2.16.840.1.113883.2.1.3.2.4.14"),
21+
Arguments.of("https://fhir.hl7.org.uk/Id/emis-drug-codes", "2.16.840.1.113883.2.1.6.9")
2122
);
2223
}
2324

@@ -30,9 +31,9 @@ void When_FhirCodeSystemIsKnown_Expect_CorrectHl7Code(String fhirCodeSystem, Str
3031
}
3132

3233
@Test
33-
void When_FhirCodeSystemIsUnknown_Expect_FhirCodeSystemIsProvided() {
34+
void When_FhirCodeSystemIsUnknown_Expect_EmptyString() {
3435
var hl7Code = CodeSystemsUtil.getHl7code("https://unknown.code/system");
3536

36-
assertThat(hl7Code).isEqualTo("https://unknown.code/system");
37+
assertThat(hl7Code).isEmpty();
3738
}
3839
}

0 commit comments

Comments
 (0)