Merge remote-tracking branch 'origin-real/bug_check_loop_variable' into bug_check_loop_variable

# Conflicts:
#	org.hl7.fhir.r4/src/test/java/org/hl7/fhir/r4/terminologies/ConceptMapEngineTest.java
This commit is contained in:
Paul Robson 2022-01-06 12:20:43 -03:00
commit db08eb4f0a
1 changed files with 44 additions and 12 deletions

View File

@ -1,17 +1,23 @@
package org.hl7.fhir.r4.terminologies; package org.hl7.fhir.r4.terminologies;
import org.hl7.fhir.exceptions.FHIRException;
import org.hl7.fhir.r4.context.SimpleWorkerContext; 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 javax.annotation.Nonnull;
import org.junit.jupiter.api.DisplayName; import org.junit.jupiter.api.DisplayName;
import org.junit.jupiter.api.Test; import org.junit.jupiter.api.Test;
import javax.annotation.Nonnull;
import java.io.IOException; import java.io.IOException;
import java.util.Arrays;
import java.util.Collection;
import java.util.Collections; import java.util.Collections;
import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertThrows;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;
class ConceptMapEngineTest { class ConceptMapEngineTest {
@ -20,9 +26,12 @@ class ConceptMapEngineTest {
public static final String TARGET_CODE_STRING = "vital-signs"; public static final String TARGET_CODE_STRING = "vital-signs";
@Test @Test
@DisplayName("Coding is converted according to ConceptMap") @DisplayName("Coding is translated according to ConceptMap")
void translate() throws IOException { void codingTranslate() throws IOException {
ConceptMapEngine conceptMapEngine = getConceptMapEngine();
final ConceptMap.SourceElementComponent sourceElementComponent = getSourceElementComponent();
final ConceptMapEngine conceptMapEngine = getConceptMapEngine(Arrays.asList(sourceElementComponent));
Coding coding = new Coding(null, SOURCE_CODE_STRING, "Body Weight"); Coding coding = new Coding(null, SOURCE_CODE_STRING, "Body Weight");
Coding actual = conceptMapEngine.translate(coding, CONCEPT_MAP_URL); Coding actual = conceptMapEngine.translate(coding, CONCEPT_MAP_URL);
@ -30,18 +39,34 @@ class ConceptMapEngineTest {
assertEquals(TARGET_CODE_STRING, actual.getCode()); assertEquals(TARGET_CODE_STRING, actual.getCode());
} }
@Nonnull @Test
private ConceptMapEngine getConceptMapEngine() throws IOException { @DisplayName("Coding fails to translate due to multiple candidate matches in ConceptMap")
ConceptMap conceptMap = getConceptMap(); void codingTranslateFailsForMultipleCandidateMatches() throws IOException {
SimpleWorkerContext simpleWorkerContext = new SimpleWorkerContext(); final ConceptMap.SourceElementComponent sourceElementComponent = getSourceElementComponent();
simpleWorkerContext.cacheResource(conceptMap);
final ConceptMapEngine conceptMapEngine = getConceptMapEngine(Arrays.asList(sourceElementComponent,
sourceElementComponent
));
Coding coding = new Coding(null, SOURCE_CODE_STRING, "Body Weight");
assertThrows(FHIRException.class, () -> {
conceptMapEngine.translate(coding, CONCEPT_MAP_URL);
});
}
@Nonnull
private ConceptMapEngine getConceptMapEngine(Collection<ConceptMap.SourceElementComponent> elements) throws IOException {
ConceptMap conceptMap = getConceptMap(elements);
SimpleWorkerContext simpleWorkerContext = mock(SimpleWorkerContext.class);
when(simpleWorkerContext.fetchResource(ConceptMap.class, CONCEPT_MAP_URL)).thenReturn(conceptMap);
return new ConceptMapEngine(simpleWorkerContext); return new ConceptMapEngine(simpleWorkerContext);
} }
@Nonnull @Nonnull
private ConceptMap getConceptMap() { private ConceptMap.SourceElementComponent getSourceElementComponent() {
ConceptMap.TargetElementComponent targetElementComponent = new ConceptMap.TargetElementComponent(); ConceptMap.TargetElementComponent targetElementComponent = new ConceptMap.TargetElementComponent();
targetElementComponent.setCode(TARGET_CODE_STRING); targetElementComponent.setCode(TARGET_CODE_STRING);
targetElementComponent.setEquivalence(Enumerations.ConceptMapEquivalence.EQUIVALENT); targetElementComponent.setEquivalence(Enumerations.ConceptMapEquivalence.EQUIVALENT);
@ -50,9 +75,16 @@ class ConceptMapEngineTest {
sourceElementComponent.setCode(SOURCE_CODE_STRING); sourceElementComponent.setCode(SOURCE_CODE_STRING);
sourceElementComponent.setTarget(Collections.singletonList(targetElementComponent)); sourceElementComponent.setTarget(Collections.singletonList(targetElementComponent));
ConceptMap.ConceptMapGroupComponent conceptMapGroupComponent = new ConceptMap.ConceptMapGroupComponent(); return sourceElementComponent;
conceptMapGroupComponent.addElement(sourceElementComponent); }
@Nonnull
private ConceptMap getConceptMap(Collection<ConceptMap.SourceElementComponent> elements) {
ConceptMap.ConceptMapGroupComponent conceptMapGroupComponent = new ConceptMap.ConceptMapGroupComponent();
for (ConceptMap.SourceElementComponent element : elements) {
conceptMapGroupComponent.addElement(element);
}
return new ConceptMap() return new ConceptMap()
.addGroup(conceptMapGroupComponent) .addGroup(conceptMapGroupComponent)
.setUrl(CONCEPT_MAP_URL); .setUrl(CONCEPT_MAP_URL);