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.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);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue