diff --git a/org.hl7.fhir.r4/src/test/java/org/hl7/fhir/r4/terminologies/ConceptMapEngineTest.java b/org.hl7.fhir.r4/src/test/java/org/hl7/fhir/r4/terminologies/ConceptMapEngineTest.java index c428d3b0b..bea524f3a 100644 --- a/org.hl7.fhir.r4/src/test/java/org/hl7/fhir/r4/terminologies/ConceptMapEngineTest.java +++ b/org.hl7.fhir.r4/src/test/java/org/hl7/fhir/r4/terminologies/ConceptMapEngineTest.java @@ -4,6 +4,7 @@ import org.hl7.fhir.r4.context.SimpleWorkerContext; import org.hl7.fhir.r4.model.Coding; import org.hl7.fhir.r4.model.ConceptMap; import org.hl7.fhir.r4.model.Enumerations; +import org.jetbrains.annotations.NotNull; import org.junit.jupiter.api.Test; import java.io.IOException; @@ -14,33 +15,43 @@ import static org.junit.jupiter.api.Assertions.assertEquals; class ConceptMapEngineTest { private static final String CONCEPT_MAP_URL = "https://test-fhir.com/ConceptMap/fake"; + public static final String SOURCE_CODE_STRING = "body-weight"; + public static final String TARGET_CODE_STRING = "vital-signs"; @Test void translate() throws IOException { + ConceptMap conceptMap = getConceptMap(); + ConceptMapEngine conceptMapEngine = getConceptMapEngine(conceptMap); + Coding coding = new Coding(null, SOURCE_CODE_STRING, "Body Weight"); + + Coding actual = conceptMapEngine.translate(coding, CONCEPT_MAP_URL); + + assertEquals(TARGET_CODE_STRING, actual.getCode()); + } + + @NotNull + private ConceptMapEngine getConceptMapEngine(ConceptMap conceptMap) throws IOException { + SimpleWorkerContext simpleWorkerContext = new SimpleWorkerContext(); + simpleWorkerContext.cacheResource(conceptMap); + + return new ConceptMapEngine(simpleWorkerContext); + } + + @NotNull + private ConceptMap getConceptMap() { ConceptMap.TargetElementComponent targetElementComponent = new ConceptMap.TargetElementComponent(); - targetElementComponent.setCode("vital-signs"); + targetElementComponent.setCode(TARGET_CODE_STRING); targetElementComponent.setEquivalence(Enumerations.ConceptMapEquivalence.EQUIVALENT); ConceptMap.SourceElementComponent sourceElementComponent = new ConceptMap.SourceElementComponent(); - sourceElementComponent.setCode("body-weight"); + sourceElementComponent.setCode(SOURCE_CODE_STRING); sourceElementComponent.setTarget(Collections.singletonList(targetElementComponent)); ConceptMap.ConceptMapGroupComponent conceptMapGroupComponent = new ConceptMap.ConceptMapGroupComponent(); conceptMapGroupComponent.addElement(sourceElementComponent); - ConceptMap conceptMap = new ConceptMap(); - conceptMap.addGroup(conceptMapGroupComponent); - conceptMap.setUrl(CONCEPT_MAP_URL); - - SimpleWorkerContext simpleWorkerContext = new SimpleWorkerContext(); - simpleWorkerContext.cacheResource(conceptMap); - - ConceptMapEngine conceptMapEngine = new ConceptMapEngine(simpleWorkerContext); - - Coding coding = new Coding(null, "body-weight", "Body Weight"); - - Coding actual = conceptMapEngine.translate(coding, CONCEPT_MAP_URL); - - assertEquals("vital-signs", actual.getCode()); + return new ConceptMap() + .addGroup(conceptMapGroupComponent) + .setUrl(CONCEPT_MAP_URL); } }