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);
}
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);
}
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);
}
}
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());
}
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);
}
Aggregations