Search in sources :

Example 6 with TerminologyClient

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);
}
Also used : ValueSet(org.hl7.fhir.r5.model.ValueSet) ValueSetExpander(org.hl7.fhir.r5.terminologies.ValueSetExpander) Test(org.junit.jupiter.api.Test)

Example 7 with TerminologyClient

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());
}
Also used : Parameters(org.hl7.fhir.r5.model.Parameters) ValueSet(org.hl7.fhir.r5.model.ValueSet) ValueSetExpander(org.hl7.fhir.r5.terminologies.ValueSetExpander) Test(org.junit.jupiter.api.Test)

Example 8 with TerminologyClient

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);
}
Also used : IntegerType(org.hl7.fhir.r4.model.IntegerType) ConceptSetComponent(org.hl7.fhir.r4.model.ValueSet.ConceptSetComponent) SimpleCoding(au.csiro.pathling.fhirpath.encoding.SimpleCoding) ValueSet(org.hl7.fhir.r4.model.ValueSet) UriParam(ca.uhn.fhir.rest.param.UriParam) CodeSystem(org.hl7.fhir.r4.model.CodeSystem) ConceptReferenceComponent(org.hl7.fhir.r4.model.ValueSet.ConceptReferenceComponent) Test(org.junit.jupiter.api.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Example 9 with 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);
}
Also used : SimpleCoding(au.csiro.pathling.fhirpath.encoding.SimpleCoding) StringType(org.hl7.fhir.r4.model.StringType) ConceptMap(org.hl7.fhir.r4.model.ConceptMap) UriParam(ca.uhn.fhir.rest.param.UriParam) CodeSystem(org.hl7.fhir.r4.model.CodeSystem) Test(org.junit.jupiter.api.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Example 10 with 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);
}
Also used : Parameters(org.hl7.fhir.r4.model.Parameters) SimpleCoding(au.csiro.pathling.fhirpath.encoding.SimpleCoding) Bundle(org.hl7.fhir.r4.model.Bundle) CodeType(org.hl7.fhir.r4.model.CodeType) ParametersParameterComponent(org.hl7.fhir.r4.model.Parameters.ParametersParameterComponent) UriType(org.hl7.fhir.r4.model.UriType) Test(org.junit.jupiter.api.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Aggregations

Test (org.junit.jupiter.api.Test)8 ValueSet (org.hl7.fhir.r5.model.ValueSet)5 ValueSetExpander (org.hl7.fhir.r5.terminologies.ValueSetExpander)5 FHIRException (org.hl7.fhir.exceptions.FHIRException)4 SimpleCoding (au.csiro.pathling.fhirpath.encoding.SimpleCoding)3 FileNotFoundException (java.io.FileNotFoundException)3 IOException (java.io.IOException)3 DefinitionException (org.hl7.fhir.exceptions.DefinitionException)3 Parameters (org.hl7.fhir.r5.model.Parameters)3 SpringBootTest (org.springframework.boot.test.context.SpringBootTest)3 DataFormatException (ca.uhn.fhir.parser.DataFormatException)2 UriParam (ca.uhn.fhir.rest.param.UriParam)2 CodeSystem (org.hl7.fhir.r4.model.CodeSystem)2 IParser (ca.uhn.fhir.parser.IParser)1 IGenericClient (ca.uhn.fhir.rest.client.api.IGenericClient)1 CqlDataProvider (com.ibm.cohort.cql.data.CqlDataProvider)1 R4LibraryDependencyGatherer (com.ibm.cohort.cql.hapi.R4LibraryDependencyGatherer)1 R4QualityMeasureResolverFactory (com.ibm.cohort.cql.hapi.resolver.R4QualityMeasureResolverFactory)1 R4QualityMeasureResolvers (com.ibm.cohort.cql.hapi.resolver.R4QualityMeasureResolvers)1 CqlTerminologyProvider (com.ibm.cohort.cql.terminology.CqlTerminologyProvider)1