refactor: extract private helper methods
This commit is contained in:
parent
f941329fcc
commit
9171c39d59
|
@ -4,6 +4,7 @@ import org.hl7.fhir.r4.context.SimpleWorkerContext;
|
||||||
import org.hl7.fhir.r4.model.Coding;
|
import org.hl7.fhir.r4.model.Coding;
|
||||||
import org.hl7.fhir.r4.model.ConceptMap;
|
import org.hl7.fhir.r4.model.ConceptMap;
|
||||||
import org.hl7.fhir.r4.model.Enumerations;
|
import org.hl7.fhir.r4.model.Enumerations;
|
||||||
|
import org.jetbrains.annotations.NotNull;
|
||||||
import org.junit.jupiter.api.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
@ -14,33 +15,43 @@ import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||||
class ConceptMapEngineTest {
|
class ConceptMapEngineTest {
|
||||||
|
|
||||||
private static final String CONCEPT_MAP_URL = "https://test-fhir.com/ConceptMap/fake";
|
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
|
@Test
|
||||||
void translate() throws IOException {
|
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();
|
ConceptMap.TargetElementComponent targetElementComponent = new ConceptMap.TargetElementComponent();
|
||||||
targetElementComponent.setCode("vital-signs");
|
targetElementComponent.setCode(TARGET_CODE_STRING);
|
||||||
targetElementComponent.setEquivalence(Enumerations.ConceptMapEquivalence.EQUIVALENT);
|
targetElementComponent.setEquivalence(Enumerations.ConceptMapEquivalence.EQUIVALENT);
|
||||||
|
|
||||||
ConceptMap.SourceElementComponent sourceElementComponent = new ConceptMap.SourceElementComponent();
|
ConceptMap.SourceElementComponent sourceElementComponent = new ConceptMap.SourceElementComponent();
|
||||||
sourceElementComponent.setCode("body-weight");
|
sourceElementComponent.setCode(SOURCE_CODE_STRING);
|
||||||
sourceElementComponent.setTarget(Collections.singletonList(targetElementComponent));
|
sourceElementComponent.setTarget(Collections.singletonList(targetElementComponent));
|
||||||
|
|
||||||
ConceptMap.ConceptMapGroupComponent conceptMapGroupComponent = new ConceptMap.ConceptMapGroupComponent();
|
ConceptMap.ConceptMapGroupComponent conceptMapGroupComponent = new ConceptMap.ConceptMapGroupComponent();
|
||||||
conceptMapGroupComponent.addElement(sourceElementComponent);
|
conceptMapGroupComponent.addElement(sourceElementComponent);
|
||||||
|
|
||||||
ConceptMap conceptMap = new ConceptMap();
|
return new ConceptMap()
|
||||||
conceptMap.addGroup(conceptMapGroupComponent);
|
.addGroup(conceptMapGroupComponent)
|
||||||
conceptMap.setUrl(CONCEPT_MAP_URL);
|
.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());
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue