Skip to content

Commit 3c7d44e

Browse files
NIAD-3304: Add CodeSystemUtil for mapping between code systems (#1126)
* NIAD-3304: Add CodeSystemUtil for mapping between code systems * Add CodeSystemUtil to map from JSON FHIR codes (urls) to HL7 XML codes (OIDs). * Add functionality to ensure that the JSON FHIR Code is preserved when the JSON FHIR Code is not a known code system. * Add unit tests for the above functionality. * NIAD-3304: Add CodeSystemUtil for mapping between code systems Refactor test string to align with use case.
1 parent 96feeb4 commit 3c7d44e

File tree

2 files changed

+59
-0
lines changed

2 files changed

+59
-0
lines changed
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
package uk.nhs.adaptors.gp2gp.ehr.utils;
2+
3+
import lombok.AccessLevel;
4+
import lombok.NoArgsConstructor;
5+
6+
import java.util.Map;
7+
8+
@NoArgsConstructor(access = AccessLevel.PRIVATE)
9+
public final class CodeSystemsUtil {
10+
11+
private static final Map<String, String> SYSTEM_CODES = Map.of(
12+
"http://snomed.info/sct", "2.16.840.1.113883.2.1.3.2.4.15",
13+
"https://fhir.hl7.org.uk/Id/egton-codes", "2.16.840.1.113883.2.1.6.3",
14+
"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"
16+
);
17+
18+
public static String getHl7code(String fhirCodeSystem) {
19+
return SYSTEM_CODES.getOrDefault(fhirCodeSystem, fhirCodeSystem);
20+
}
21+
}
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
package uk.nhs.adaptors.gp2gp.utils;
2+
3+
import static org.assertj.core.api.Assertions.assertThat;
4+
5+
import org.junit.jupiter.api.Test;
6+
import org.junit.jupiter.params.ParameterizedTest;
7+
import org.junit.jupiter.params.provider.Arguments;
8+
import org.junit.jupiter.params.provider.MethodSource;
9+
import uk.nhs.adaptors.gp2gp.ehr.utils.CodeSystemsUtil;
10+
11+
import java.util.stream.Stream;
12+
13+
public class CodeSystemUtilTest {
14+
15+
private static Stream<Arguments> knownCodeSystems() {
16+
return Stream.of(
17+
Arguments.of("http://snomed.info/sct", "2.16.840.1.113883.2.1.3.2.4.15"),
18+
Arguments.of("https://fhir.hl7.org.uk/Id/egton-codes", "2.16.840.1.113883.2.1.6.3"),
19+
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")
21+
);
22+
}
23+
24+
@ParameterizedTest
25+
@MethodSource("knownCodeSystems")
26+
void When_FhirCodeSystemIsKnown_Expect_CorrectHl7Code(String fhirCodeSystem, String expectedHl7Code) {
27+
var hl7Code = CodeSystemsUtil.getHl7code(fhirCodeSystem);
28+
29+
assertThat(hl7Code).isEqualTo(expectedHl7Code);
30+
}
31+
32+
@Test
33+
void When_FhirCodeSystemIsUnknown_Expect_FhirCodeSystemIsProvided() {
34+
var hl7Code = CodeSystemsUtil.getHl7code("https://unknown.code/system");
35+
36+
assertThat(hl7Code).isEqualTo("https://unknown.code/system");
37+
}
38+
}

0 commit comments

Comments
 (0)