use of org.hl7.fhir.r5.terminologies.TerminologyClient in project org.hl7.fhir.core by hapifhir.
the class SimpleWorkerContextTests method testExpandValueSetWithClient.
@Test
public void testExpandValueSetWithClient() throws IOException {
ValueSet.ConceptSetComponent inc = new ValueSet.ConceptSetComponent();
ValueSet vs = new ValueSet();
vs.setStatus(Enumerations.PublicationStatus.ACTIVE);
vs.setCompose(new ValueSet.ValueSetComposeComponent());
vs.getCompose().setInactive(true);
vs.getCompose().getInclude().add(inc);
Mockito.doReturn(cacheToken).when(terminologyCache).generateExpandToken(argThat(new ValueSetMatcher(vs)), eq(true));
Mockito.doReturn(expParameters).when(context).constructParameters(argThat(new ValueSetMatcher(vs)), eq(true));
ValueSet expectedValueSet = new ValueSet();
Mockito.doReturn(expectedValueSet).when(terminologyClient).expandValueset(argThat(new ValueSetMatcher(vs)), argThat(new ParametersMatcher(pInWithDependentResources)), eq(params));
ValueSetExpander.ValueSetExpansionOutcome actualExpansionResult = context.expandVS(inc, true, false);
assertEquals(expectedValueSet, actualExpansionResult.getValueset());
Mockito.verify(terminologyCache).getExpansion(cacheToken);
Mockito.verify(terminologyCache).cacheExpansion(cacheToken, actualExpansionResult, true);
}
use of org.hl7.fhir.r5.terminologies.TerminologyClient in project org.hl7.fhir.core by hapifhir.
the class SimpleWorkerContextTests method testExpandValueSet4ArgsWithValueSetExpanderSimple.
@Test
public void testExpandValueSet4ArgsWithValueSetExpanderSimple() throws IOException {
ValueSet vs = new ValueSet();
vs.setUrl(DUMMY_URL);
Mockito.doReturn(cacheToken).when(terminologyCache).generateExpandToken(vs, true);
Parameters pIn = new Parameters();
Mockito.doReturn(vs).when(expectedExpansionResult).getValueset();
Mockito.doReturn(expectedExpansionResult).when(valueSetExpanderSimple).expand(eq(vs), argThat(new ParametersMatcher(pInWithDependentResources)));
Mockito.doReturn(valueSetExpanderSimple).when(context).constructValueSetExpanderSimple();
ValueSetExpander.ValueSetExpansionOutcome actualExpansionResult = context.expandVS(vs, true, true, true, pIn);
assertEquals(expectedExpansionResult, actualExpansionResult);
Mockito.verify(terminologyCache).getExpansion(cacheToken);
Mockito.verify(terminologyCache).cacheExpansion(cacheToken, actualExpansionResult, false);
Mockito.verify(terminologyClient, times(0)).expandValueset(any(), any(), any());
}
use of org.hl7.fhir.r5.terminologies.TerminologyClient in project pathling by aehrc.
the class DefaultTerminologyServiceTest method testIntersectFiltersIllegalAndUnknownCodings.
@SuppressWarnings("ConstantConditions")
@Test
void testIntersectFiltersIllegalAndUnknownCodings() {
final ValueSet responseExpansion = new ValueSet();
responseExpansion.getExpansion().getContains().addAll(Arrays.asList(fromSimpleCoding(CODING1_VERSION1), fromSimpleCoding(CODING2_VERSION1)));
when(terminologyClient.expand(any(), any())).thenReturn(responseExpansion);
// setup SYSTEM1 as known system
when(terminologyClient.searchCodeSystems(refEq(new UriParam(SYSTEM1)), any())).thenReturn(Collections.singletonList(new CodeSystem()));
final Set<SimpleCoding> actualExpansion = terminologyService.intersect("uuid:value-set", Arrays.asList(CODING1_VERSION1, CODING2_VERSION1, CODING3_VERSION1, new SimpleCoding(SYSTEM1, null), new SimpleCoding(null, "code1"), new SimpleCoding(null, null), null));
final Set<SimpleCoding> expectedExpansion = ImmutableSet.of(CODING1_VERSION1, CODING2_VERSION1);
assertEquals(expectedExpansion, actualExpansion);
// verify behaviour
verify(terminologyClient).searchCodeSystems(refEq(new UriParam(SYSTEM1)), any());
verify(terminologyClient).searchCodeSystems(refEq(new UriParam(SYSTEM2)), any());
final ValueSet requestValueSet = new ValueSet();
final List<ConceptSetComponent> includes = requestValueSet.getCompose().getInclude();
includes.add(new ConceptSetComponent().addValueSet("uuid:value-set").setSystem(SYSTEM1).setVersion("version1").addConcept(new ConceptReferenceComponent().setCode("code1")).addConcept(new ConceptReferenceComponent().setCode("code2")));
verify(terminologyClient).expand(deepEq(requestValueSet), deepEq(new IntegerType(2)));
verifyNoMoreInteractions(terminologyClient);
}
use of org.hl7.fhir.r5.terminologies.TerminologyClient in project pathling by aehrc.
the class DefaultTerminologyServiceTest method testSubsumesFiltersIllegalAndUnknownCodings.
@Test
@SuppressWarnings("ConstantConditions")
void testSubsumesFiltersIllegalAndUnknownCodings() {
// CODING1 subsumes CODING2
final ConceptMap responseMap = ConceptMapBuilder.empty().withSubsumes(CODING2_VERSION1.toCoding(), CODING1_VERSION1.toCoding()).build();
when(terminologyClient.closure(any(), any())).thenReturn(responseMap);
// setup SYSTEM1 as known system
when(terminologyClient.searchCodeSystems(refEq(new UriParam(SYSTEM1)), any())).thenReturn(Collections.singletonList(new CodeSystem()));
final Relation actualRelation = terminologyService.getSubsumesRelation(Arrays.asList(CODING1_VERSION1, CODING1_UNVERSIONED, CODING2_VERSION1, CODING3_VERSION1, new SimpleCoding(SYSTEM1, null), new SimpleCoding(null, "code1"), new SimpleCoding(null, null), null));
final Relation expectedRelation = RelationBuilder.empty().add(CODING1_VERSION1.toCoding(), CODING2_VERSION1.toCoding()).build();
assertEquals(expectedRelation, actualRelation);
// verify behaviour
verify(terminologyClient).searchCodeSystems(refEq(new UriParam(SYSTEM1)), any());
verify(terminologyClient).searchCodeSystems(refEq(new UriParam(SYSTEM2)), any());
verify(terminologyClient).initialiseClosure(deepEq(new StringType(TEST_UUID_AS_STRING)));
verify(terminologyClient).closure(deepEq(new StringType(TEST_UUID_AS_STRING)), argThat(new CodingSetMatcher(Arrays.asList(CODING1_VERSION1, CODING1_UNVERSIONED, CODING2_VERSION1))));
verifyNoMoreInteractions(terminologyClient);
}
use of org.hl7.fhir.r5.terminologies.TerminologyClient in project pathling by aehrc.
the class DefaultTerminologyServiceTest method testTranslateForValidAndInvalidCodings.
@Test
void testTranslateForValidAndInvalidCodings() {
// Response bundle:
// [1] CODING1_VERSION1 -> None
// [2] CODING2_VERSION1 -> { equivalent: CODING3_VERSION1, wider: CODING1_VERSION1}
final Bundle responseBundle = new Bundle().setType(BundleType.BATCHRESPONSE);
// entry with no mapping
final Parameters noTranslation = new Parameters().addParameter("result", false);
responseBundle.addEntry().setResource(noTranslation).getResponse().setStatus("200");
// entry with two mappings
final Parameters withTranslation = new Parameters().addParameter("result", true);
final ParametersParameterComponent equivalentMatch = withTranslation.addParameter().setName("match");
equivalentMatch.addPart().setName("equivalence").setValue(new CodeType("equivalent"));
equivalentMatch.addPart().setName("concept").setValue(CODING3_VERSION1.toCoding());
final ParametersParameterComponent widerMatch = withTranslation.addParameter().setName("match");
widerMatch.addPart().setName("equivalence").setValue(new CodeType("wider"));
widerMatch.addPart().setName("concept").setValue(CODING1_VERSION1.toCoding());
responseBundle.addEntry().setResource(withTranslation).getResponse().setStatus("200");
when(terminologyClient.batch(any())).thenReturn(responseBundle);
final ConceptTranslator actualTranslator = terminologyService.translate(Arrays.asList(CODING1_VERSION1, CODING2_VERSION1, new SimpleCoding(SYSTEM1, null), new SimpleCoding(null, "code1"), new SimpleCoding(null, null), null), "uuid:concept-map", false, Collections.singletonList(ConceptMapEquivalence.EQUIVALENT));
assertEquals(ConceptTranslatorBuilder.empty().put(CODING2_VERSION1, CODING3_VERSION1.toCoding()).build(), actualTranslator);
// expected request bundle
final Bundle requestBundle = new Bundle().setType(BundleType.BATCH);
requestBundle.addEntry().setResource(new Parameters().addParameter("url", new UriType("uuid:concept-map")).addParameter("reverse", false).addParameter("coding", CODING1_VERSION1.toCoding())).getRequest().setMethod(HTTPVerb.POST).setUrl("ConceptMap/$translate");
requestBundle.addEntry().setResource(new Parameters().addParameter("url", new UriType("uuid:concept-map")).addParameter("reverse", false).addParameter("coding", CODING2_VERSION1.toCoding())).getRequest().setMethod(HTTPVerb.POST).setUrl("ConceptMap/$translate");
verify(terminologyClient).batch(deepEq(requestBundle));
verifyNoMoreInteractions(terminologyClient);
}
Aggregations