Search in sources :

Example 1 with TerminologyClientR5

use of org.hl7.fhir.convertors.txClient.TerminologyClientR5 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 TerminologyClientR5

use of org.hl7.fhir.convertors.txClient.TerminologyClientR5 in project org.hl7.fhir.core by hapifhir.

the class TestingUtilities method context.

public static IWorkerContext context(String version) {
    if ("4.5.0".equals(version)) {
        // temporary work around
        version = "4.4.0";
    }
    String v = VersionUtilities.getMajMin(version);
    if (fcontexts == null) {
        fcontexts = new HashMap<>();
    }
    if (!fcontexts.containsKey(v)) {
        FilesystemPackageCacheManager pcm;
        try {
            pcm = new FilesystemPackageCacheManager(true, ToolsVersion.TOOLS_VERSION);
            IWorkerContext fcontext = SimpleWorkerContext.fromPackage(pcm.loadPackage(VersionUtilities.packageForVersion(version), version));
            fcontext.setUcumService(new UcumEssenceService(TestingUtilities.loadTestResourceStream("ucum", "ucum-essence.xml")));
            fcontext.setExpansionProfile(new Parameters());
            // ((SimpleWorkerContext) fcontext).connectToTSServer(new TerminologyClientR5("http://tx.fhir.org/r4"), null);
            fcontexts.put(v, fcontext);
        } catch (Exception e) {
            e.printStackTrace();
            throw new Error(e);
        }
    }
    return fcontexts.get(v);
}
Also used : UcumEssenceService(org.fhir.ucum.UcumEssenceService) FilesystemPackageCacheManager(org.hl7.fhir.utilities.npm.FilesystemPackageCacheManager) IWorkerContext(org.hl7.fhir.r4b.context.IWorkerContext) Parameters(org.hl7.fhir.r4b.model.Parameters) JsonSyntaxException(com.google.gson.JsonSyntaxException) IOException(java.io.IOException) FileNotFoundException(java.io.FileNotFoundException)

Example 3 with TerminologyClientR5

use of org.hl7.fhir.convertors.txClient.TerminologyClientR5 in project kindling by HL7.

the class BuildWorkerContext method lookupLoinc.

private String lookupLoinc(String code) throws Exception {
    if (true) {
        // (!triedServer || serverOk) {
        try {
            triedServer = true;
            // for this, we use the FHIR client
            if (txClient == null) {
                txClient = new TerminologyClientR5(tsServer);
                this.txLog = new HTMLClientLogger(null);
            }
            Map<String, String> params = new HashMap<String, String>();
            params.put("code", code);
            params.put("system", "http://loinc.org");
            Parameters result = txClient.lookupCode(params);
            for (ParametersParameterComponent p : result.getParameter()) {
                if (p.getName().equals("display"))
                    return ((StringType) p.getValue()).asStringValue();
            }
            throw new Exception("Did not find LOINC code in return values");
        } catch (EFhirClientException e) {
            serverOk = true;
            throw e;
        } catch (Exception e) {
            serverOk = false;
            throw e;
        }
    } else
        throw new Exception("Server is not available");
}
Also used : TerminologyClientR5(org.hl7.fhir.convertors.txClient.TerminologyClientR5) Parameters(org.hl7.fhir.r5.model.Parameters) HashMap(java.util.HashMap) HTMLClientLogger(org.hl7.fhir.r5.context.HTMLClientLogger) UcumException(org.fhir.ucum.UcumException) TerminologyServiceException(org.hl7.fhir.exceptions.TerminologyServiceException) FileNotFoundException(java.io.FileNotFoundException) SAXException(org.xml.sax.SAXException) DefinitionException(org.hl7.fhir.exceptions.DefinitionException) EFhirClientException(org.hl7.fhir.r5.utils.client.EFhirClientException) IOException(java.io.IOException) ParserConfigurationException(javax.xml.parsers.ParserConfigurationException) FHIRException(org.hl7.fhir.exceptions.FHIRException) EFhirClientException(org.hl7.fhir.r5.utils.client.EFhirClientException) ParametersParameterComponent(org.hl7.fhir.r5.model.Parameters.ParametersParameterComponent)

Aggregations

FileNotFoundException (java.io.FileNotFoundException)3 IOException (java.io.IOException)3 UcumException (org.fhir.ucum.UcumException)2 TerminologyClientR5 (org.hl7.fhir.convertors.txClient.TerminologyClientR5)2 DefinitionException (org.hl7.fhir.exceptions.DefinitionException)2 FHIRException (org.hl7.fhir.exceptions.FHIRException)2 FilesystemPackageCacheManager (org.hl7.fhir.utilities.npm.FilesystemPackageCacheManager)2 JsonSyntaxException (com.google.gson.JsonSyntaxException)1 URISyntaxException (java.net.URISyntaxException)1 HashMap (java.util.HashMap)1 ParserConfigurationException (javax.xml.parsers.ParserConfigurationException)1 TransformerConfigurationException (javax.xml.transform.TransformerConfigurationException)1 TransformerException (javax.xml.transform.TransformerException)1 NotImplementedException (org.apache.commons.lang3.NotImplementedException)1 UcumEssenceService (org.fhir.ucum.UcumEssenceService)1 R4ToR5Loader (org.hl7.fhir.convertors.loaders.R4ToR5Loader)1 ValueSetValidator (org.hl7.fhir.definitions.validation.ValueSetValidator)1 PathEngineException (org.hl7.fhir.exceptions.PathEngineException)1 TerminologyServiceException (org.hl7.fhir.exceptions.TerminologyServiceException)1 IWorkerContext (org.hl7.fhir.r4b.context.IWorkerContext)1