Search in sources :

Example 1 with TerminologyClient

use of org.hl7.fhir.r5.terminologies.TerminologyClient in project kindling by HL7.

the class PageProcessor method setDefinitions.

public void setDefinitions(Definitions definitions) throws Exception {
    this.definitions = definitions;
    breadCrumbManager.setDefinitions(definitions);
    TerminologyClient client;
    try {
        client = new TerminologyClientR5(tsServer);
        client.setTimeout(60000);
    } catch (Exception e) {
        System.out.println("Warning @ PageProcessor client initialize: " + e.getLocalizedMessage());
        client = null;
    }
    workerContext = new BuildWorkerContext(definitions, client, definitions.getCodeSystems(), definitions.getValuesets(), conceptMaps, profiles, guides, folders.rootDir);
    workerContext.setDefinitions(definitions);
    workerContext.setLogger(this);
    workerContext.setAllowLoadingDuplicates(true);
    log("Load UTG Terminology", LogMessageType.Process);
    NpmPackage utg = new FilesystemPackageCacheManager(true, ToolsVersion.TOOLS_VERSION).loadPackage("hl7.terminology");
    workerContext.loadFromPackage(utg, new R4ToR5Loader(BuildWorkerContext.defaultTypesToLoad(), new UTGLoader(utg.version())));
    log("Load Terminology Cache from " + Utilities.path(folders.rootDir, "vscache"), LogMessageType.Process);
    workerContext.initTS(Utilities.path(folders.rootDir, "vscache"));
    log("  .. loaded", LogMessageType.Process);
    vsValidator = new ValueSetValidator(workerContext, definitions.getVsFixups(), definitions.getStyleExemptions());
    breadCrumbManager.setContext(workerContext);
}
Also used : TerminologyClientR5(org.hl7.fhir.convertors.txClient.TerminologyClientR5) FilesystemPackageCacheManager(org.hl7.fhir.utilities.npm.FilesystemPackageCacheManager) NpmPackage(org.hl7.fhir.utilities.npm.NpmPackage) R4ToR5Loader(org.hl7.fhir.convertors.loaders.R4ToR5Loader) TerminologyClient(org.hl7.fhir.r5.terminologies.TerminologyClient) ValueSetValidator(org.hl7.fhir.definitions.validation.ValueSetValidator) UcumException(org.fhir.ucum.UcumException) TransformerException(javax.xml.transform.TransformerException) TransformerConfigurationException(javax.xml.transform.TransformerConfigurationException) IOException(java.io.IOException) FHIRException(org.hl7.fhir.exceptions.FHIRException) URISyntaxException(java.net.URISyntaxException) PathEngineException(org.hl7.fhir.exceptions.PathEngineException) DefinitionException(org.hl7.fhir.exceptions.DefinitionException) FileNotFoundException(java.io.FileNotFoundException) NotImplementedException(org.apache.commons.lang3.NotImplementedException)

Example 2 with TerminologyClient

use of org.hl7.fhir.r5.terminologies.TerminologyClient in project quality-measure-and-cohort-service by Alvearie.

the class CohortEngineRestHandler method createMeasureEvaluator.

private MeasureEvaluator createMeasureEvaluator(InputStream inputStream, FhirServerConfig dataServerConfig, FhirServerConfig terminologyServerConfig, Boolean expandValueSets, Integer searchPageSize, RetrieveCacheContext retrieveCacheContext, FhirContext fhirContext) throws IOException {
    FhirClientBuilder clientBuilder = FhirClientBuilderFactory.newInstance().newFhirClientBuilder(fhirContext);
    IGenericClient dataClient = clientBuilder.createFhirClient(dataServerConfig);
    IGenericClient terminologyClient = dataClient;
    if (terminologyServerConfig != null) {
        terminologyClient = clientBuilder.createFhirClient(terminologyServerConfig);
    }
    IParser parser = dataClient.getFhirContext().newJsonParser();
    String[] searchPaths = new String[] { "fhirResources", "fhirResources/libraries" };
    R4QualityMeasureResolverFactory resolverFactory = new R4QualityMeasureResolverFactory(parser);
    R4QualityMeasureResolvers resolvers = resolverFactory.fromZipStream(new ZipInputStream(inputStream), searchPaths);
    FhirResourceResolver<Library> libraryResolver = resolvers.getLibraryResolver();
    FhirResourceResolver<Measure> measureResolver = resolvers.getMeasureResolver();
    R4LibraryDependencyGatherer libraryDependencyGatherer = new R4LibraryDependencyGatherer(libraryResolver);
    CqlTerminologyProvider terminologyProvider = new R4RestFhirTerminologyProvider(terminologyClient);
    if (expandValueSets == null) {
        expandValueSets = R4DataProviderFactory.DEFAULT_IS_EXPAND_VALUE_SETS;
    }
    if (searchPageSize == null) {
        searchPageSize = R4DataProviderFactory.DEFAULT_PAGE_SIZE;
    }
    Map<String, CqlDataProvider> dataProviders = R4DataProviderFactory.createDataProviderMap(dataClient, terminologyProvider, retrieveCacheContext, R4FhirModelResolverFactory.createCachingResolver(), expandValueSets, searchPageSize);
    return new MeasureEvaluator(measureResolver, libraryResolver, libraryDependencyGatherer, terminologyProvider, dataProviders);
}
Also used : FhirClientBuilder(com.ibm.cohort.fhir.client.config.FhirClientBuilder) IGenericClient(ca.uhn.fhir.rest.client.api.IGenericClient) R4QualityMeasureResolverFactory(com.ibm.cohort.cql.hapi.resolver.R4QualityMeasureResolverFactory) R4RestFhirTerminologyProvider(com.ibm.cohort.engine.terminology.R4RestFhirTerminologyProvider) MeasureEvaluator(com.ibm.cohort.engine.measure.MeasureEvaluator) ZipInputStream(java.util.zip.ZipInputStream) Measure(org.hl7.fhir.r4.model.Measure) R4QualityMeasureResolvers(com.ibm.cohort.cql.hapi.resolver.R4QualityMeasureResolvers) R4LibraryDependencyGatherer(com.ibm.cohort.cql.hapi.R4LibraryDependencyGatherer) Library(org.hl7.fhir.r4.model.Library) CqlTerminologyProvider(com.ibm.cohort.cql.terminology.CqlTerminologyProvider) CqlDataProvider(com.ibm.cohort.cql.data.CqlDataProvider) IParser(ca.uhn.fhir.parser.IParser)

Example 3 with TerminologyClient

use of org.hl7.fhir.r5.terminologies.TerminologyClient in project org.hl7.fhir.core by hapifhir.

the class SimpleWorkerContext method connectToTSServer.

public String connectToTSServer(TerminologyClient client, String log) {
    try {
        tlog("Connect to " + client.getAddress());
        txClient = client;
        if (log != null && log.endsWith(".txt")) {
            txLog = new TextClientLogger(log);
        } else {
            txLog = new HTMLClientLogger(log);
        }
        txClient.setLogger(txLog);
        txClient.setUserAgent(userAgent);
        CapabilityStatement cps = txClient.getCapabilitiesStatementQuick();
        setTxCaps(txClient.getTerminologyCapabilities());
        return cps.getSoftware().getVersion();
    } catch (Exception e) {
        throw new FHIRException(formatMessage(canNoTS ? I18nConstants.UNABLE_TO_CONNECT_TO_TERMINOLOGY_SERVER_USE_PARAMETER_TX_NA_TUN_RUN_WITHOUT_USING_TERMINOLOGY_SERVICES_TO_VALIDATE_LOINC_SNOMED_ICDX_ETC_ERROR__ : I18nConstants.UNABLE_TO_CONNECT_TO_TERMINOLOGY_SERVER, e.getMessage()), e);
    }
}
Also used : CapabilityStatement(org.hl7.fhir.r4b.model.CapabilityStatement) FHIRException(org.hl7.fhir.exceptions.FHIRException) FileNotFoundException(java.io.FileNotFoundException) DataFormatException(ca.uhn.fhir.parser.DataFormatException) DefinitionException(org.hl7.fhir.exceptions.DefinitionException) IOException(java.io.IOException) FHIRException(org.hl7.fhir.exceptions.FHIRException)

Example 4 with TerminologyClient

use of org.hl7.fhir.r5.terminologies.TerminologyClient in project org.hl7.fhir.core by hapifhir.

the class SimpleWorkerContextTests method testExpandValueSetWithCache.

@Test
public void testExpandValueSetWithCache() 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(expectedExpansionResult).when(terminologyCache).getExpansion(cacheToken);
    ValueSetExpander.ValueSetExpansionOutcome actualExpansionResult = context.expandVS(inc, true, false);
    assertEquals(expectedExpansionResult, actualExpansionResult);
    Mockito.verify(terminologyCache).getExpansion(cacheToken);
    Mockito.verify(terminologyCache, times(0)).cacheExpansion(any(), any(), anyBoolean());
    Mockito.verify(terminologyClient, times(0)).expandValueset(any(), any(), any());
}
Also used : ValueSet(org.hl7.fhir.r5.model.ValueSet) ValueSetExpander(org.hl7.fhir.r5.terminologies.ValueSetExpander) Test(org.junit.jupiter.api.Test)

Example 5 with TerminologyClient

use of org.hl7.fhir.r5.terminologies.TerminologyClient in project org.hl7.fhir.core by hapifhir.

the class SimpleWorkerContextTests method testExpandValueSet4ArgsWithClient.

@Test
public void testExpandValueSet4ArgsWithClient() throws IOException {
    ValueSet vs = new ValueSet();
    vs.setUrl(DUMMY_URL);
    Mockito.doReturn(cacheToken).when(terminologyCache).generateExpandToken(vs, true);
    Parameters pIn = new Parameters();
    ValueSet expectedValueSet = new ValueSet();
    expectedValueSet.setUrl("dummyUrl2");
    Mockito.doReturn(expectedExpansionResult).when(valueSetExpanderSimple).expand(eq(vs), argThat(new ParametersMatcher(pInWithDependentResources)));
    Mockito.doReturn(valueSetExpanderSimple).when(context).constructValueSetExpanderSimple();
    Mockito.doReturn(expectedValueSet).when(terminologyClient).expandValueset(eq(vs), argThat(new ParametersMatcher(pInWithDependentResources)), eq(params));
    ValueSetExpander.ValueSetExpansionOutcome actualExpansionResult = context.expandVS(vs, true, true, true, pIn);
    assertEquals(expectedValueSet, actualExpansionResult.getValueset());
    Mockito.verify(terminologyCache).getExpansion(cacheToken);
    Mockito.verify(terminologyCache).cacheExpansion(cacheToken, actualExpansionResult, true);
}
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)

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