Search in sources :

Example 6 with TerminologyServiceException

use of org.hl7.fhir.exceptions.TerminologyServiceException in project org.hl7.fhir.core by hapifhir.

the class BaseWorkerContext method supportsSystem.

@Override
public boolean supportsSystem(String system) throws TerminologyServiceException {
    if (codeSystems.containsKey(system)) {
        return true;
    } else if (nonSupportedCodeSystems.contains(system)) {
        return false;
    } else if (system.startsWith("http://example.org") || system.startsWith("http://acme.com") || system.startsWith("http://hl7.org/fhir/valueset-") || system.startsWith("urn:oid:")) {
        return false;
    } else {
        if (noTerminologyServer) {
            return false;
        }
        if (bndCodeSystems == null) {
            try {
                tlog("Terminology server: Check for supported code systems for " + system);
                bndCodeSystems = txServer.fetchFeed(txServer.getAddress() + "/CodeSystem?content-mode=not-present&_summary=true&_count=1000");
            } catch (Exception e) {
                if (canRunWithoutTerminology) {
                    noTerminologyServer = true;
                    log("==============!! Running without terminology server !!============== (" + e.getMessage() + ")");
                    return false;
                } else {
                    throw new TerminologyServiceException(e);
                }
            }
        }
        if (bndCodeSystems != null) {
            for (BundleEntryComponent be : bndCodeSystems.getEntry()) {
                CodeSystem cs = (CodeSystem) be.getResource();
                if (!codeSystems.containsKey(cs.getUrl())) {
                    codeSystems.put(cs.getUrl(), null);
                }
            }
        }
        if (codeSystems.containsKey(system)) {
            return true;
        }
    }
    nonSupportedCodeSystems.add(system);
    return false;
}
Also used : BundleEntryComponent(org.hl7.fhir.dstu3.model.Bundle.BundleEntryComponent) TerminologyServiceException(org.hl7.fhir.exceptions.TerminologyServiceException) NoTerminologyServiceException(org.hl7.fhir.exceptions.NoTerminologyServiceException) CodeSystem(org.hl7.fhir.dstu3.model.CodeSystem) TerminologyServiceException(org.hl7.fhir.exceptions.TerminologyServiceException) FileNotFoundException(java.io.FileNotFoundException) NoTerminologyServiceException(org.hl7.fhir.exceptions.NoTerminologyServiceException) JsonSyntaxException(com.google.gson.JsonSyntaxException) IOException(java.io.IOException) FHIRException(org.hl7.fhir.exceptions.FHIRException)

Example 7 with TerminologyServiceException

use of org.hl7.fhir.exceptions.TerminologyServiceException in project org.hl7.fhir.core by hapifhir.

the class ValueSetExpanderSimple method importValueSet.

private ValueSet importValueSet(String value, List<ValueSetExpansionParameterComponent> params, Parameters expParams) throws ETooCostly, TerminologyServiceException, FileNotFoundException, IOException, FHIRFormatError {
    if (value == null)
        throw new TerminologyServiceException("unable to find value set with no identity");
    ValueSet vs = context.fetchResource(ValueSet.class, value);
    if (vs == null)
        throw new TerminologyServiceException("Unable to find imported value set " + value);
    ValueSetExpansionOutcome vso = new ValueSetExpanderSimple(context).expand(vs, expParams);
    if (vso.getError() != null)
        throw new TerminologyServiceException("Unable to expand imported value set: " + vso.getError());
    if (vs.hasVersion())
        if (!existsInParams(params, "version", new UriType(vs.getUrl() + "|" + vs.getVersion())))
            params.add(new ValueSetExpansionParameterComponent().setName("version").setValue(new UriType(vs.getUrl() + "|" + vs.getVersion())));
    for (ValueSetExpansionParameterComponent p : vso.getValueset().getExpansion().getParameter()) {
        if (!existsInParams(params, p.getName(), p.getValue()))
            params.add(p);
    }
    // if we're importing a value set, we have to be combining, so we won't try for a heirarchy
    canBeHeirarchy = false;
    return vso.getValueset();
}
Also used : ValueSetExpansionParameterComponent(org.hl7.fhir.r4.model.ValueSet.ValueSetExpansionParameterComponent) NoTerminologyServiceException(org.hl7.fhir.exceptions.NoTerminologyServiceException) TerminologyServiceException(org.hl7.fhir.exceptions.TerminologyServiceException) ValueSet(org.hl7.fhir.r4.model.ValueSet) UriType(org.hl7.fhir.r4.model.UriType)

Example 8 with TerminologyServiceException

use of org.hl7.fhir.exceptions.TerminologyServiceException in project org.hl7.fhir.core by hapifhir.

the class ValueSetExpanderSimple method doServerIncludeCodes.

private void doServerIncludeCodes(ConceptSetComponent inc, boolean heirarchical, List<ValueSetExpansionParameterComponent> params, List<ValueSet> imports, Parameters expParams) throws FHIRException {
    ValueSetExpansionOutcome vso = context.expandVS(inc, heirarchical);
    if (vso.getError() != null)
        throw new TerminologyServiceException("Unable to expand imported value set: " + vso.getError());
    ValueSet vs = vso.getValueset();
    if (vs.hasVersion())
        if (!existsInParams(params, "version", new UriType(vs.getUrl() + "|" + vs.getVersion())))
            params.add(new ValueSetExpansionParameterComponent().setName("version").setValue(new UriType(vs.getUrl() + "|" + vs.getVersion())));
    for (ValueSetExpansionParameterComponent p : vso.getValueset().getExpansion().getParameter()) {
        if (!existsInParams(params, p.getName(), p.getValue()))
            params.add(p);
    }
    for (ValueSetExpansionContainsComponent cc : vs.getExpansion().getContains()) {
        addCodeAndDescendents(cc, null, expParams, imports);
    }
}
Also used : ValueSetExpansionContainsComponent(org.hl7.fhir.r4.model.ValueSet.ValueSetExpansionContainsComponent) ValueSetExpansionParameterComponent(org.hl7.fhir.r4.model.ValueSet.ValueSetExpansionParameterComponent) NoTerminologyServiceException(org.hl7.fhir.exceptions.NoTerminologyServiceException) TerminologyServiceException(org.hl7.fhir.exceptions.TerminologyServiceException) ValueSet(org.hl7.fhir.r4.model.ValueSet) UriType(org.hl7.fhir.r4.model.UriType)

Example 9 with TerminologyServiceException

use of org.hl7.fhir.exceptions.TerminologyServiceException in project org.hl7.fhir.core by hapifhir.

the class ValueSetExpanderSimple method excludeCodes.

private void excludeCodes(ConceptSetComponent exc, List<ValueSetExpansionParameterComponent> params, String ctxt) throws FHIRException {
    exc.checkNoModifiers("Compose.exclude", "expanding");
    if (exc.hasSystem() && exc.getConcept().size() == 0 && exc.getFilter().size() == 0) {
        excludeSystems.add(exc.getSystem());
    }
    if (exc.hasValueSet())
        throw new Error("Processing Value set references in exclude is not yet done in " + ctxt);
    // importValueSet(imp.getValue(), params, expParams);
    CodeSystem cs = context.fetchCodeSystem(exc.getSystem());
    if ((cs == null || cs.getContent() != CodeSystemContentMode.COMPLETE) && context.supportsSystem(exc.getSystem())) {
        ValueSetExpansionOutcome vse = context.expandVS(exc, false);
        ValueSet valueset = vse.getValueset();
        if (valueset == null)
            throw new TerminologyServiceException("Error Expanding ValueSet: " + vse.getError());
        excludeCodes(valueset.getExpansion(), params);
        return;
    }
    for (ConceptReferenceComponent c : exc.getConcept()) {
        excludeCode(exc.getSystem(), c.getCode());
    }
    if (exc.getFilter().size() > 0)
        throw new NotImplementedException("not done yet");
}
Also used : NotImplementedException(org.apache.commons.lang3.NotImplementedException) FHIRFormatError(org.hl7.fhir.exceptions.FHIRFormatError) NoTerminologyServiceException(org.hl7.fhir.exceptions.NoTerminologyServiceException) TerminologyServiceException(org.hl7.fhir.exceptions.TerminologyServiceException) CodeSystem(org.hl7.fhir.r4.model.CodeSystem) ValueSet(org.hl7.fhir.r4.model.ValueSet) ConceptReferenceComponent(org.hl7.fhir.r4.model.ValueSet.ConceptReferenceComponent)

Example 10 with TerminologyServiceException

use of org.hl7.fhir.exceptions.TerminologyServiceException in project org.hl7.fhir.core by hapifhir.

the class BaseWorkerContext method expandVS.

@Override
public ValueSetExpansionOutcome expandVS(ConceptSetComponent inc, boolean hierarchical) throws TerminologyServiceException {
    ValueSet vs = new ValueSet();
    vs.setStatus(PublicationStatus.ACTIVE);
    vs.setCompose(new ValueSetComposeComponent());
    vs.getCompose().getInclude().add(inc);
    CacheToken cacheToken = txCache.generateExpandToken(vs, hierarchical);
    ValueSetExpansionOutcome res;
    res = txCache.getExpansion(cacheToken);
    if (res != null) {
        return res;
    }
    Parameters p = expParameters.copy();
    p.setParameter("includeDefinition", false);
    p.setParameter("excludeNested", !hierarchical);
    boolean cached = addDependentResources(p, vs);
    if (cached) {
        p.addParameter().setName("cache-id").setValue(new StringType(cacheId));
    }
    for (ConceptSetComponent incl : vs.getCompose().getInclude()) {
        codeSystemsUsed.add(incl.getSystem());
    }
    for (ConceptSetComponent incl : vs.getCompose().getExclude()) {
        codeSystemsUsed.add(incl.getSystem());
    }
    if (noTerminologyServer) {
        return new ValueSetExpansionOutcome(formatMessage(I18nConstants.ERROR_EXPANDING_VALUESET_RUNNING_WITHOUT_TERMINOLOGY_SERVICES), TerminologyServiceErrorClass.NOSERVICE);
    }
    Map<String, String> params = new HashMap<String, String>();
    params.put("_limit", Integer.toString(expandCodesLimit));
    params.put("_incomplete", "true");
    tlog("$expand on " + txCache.summary(vs));
    try {
        ValueSet result = txClient.expandValueset(vs, p, params);
        res = new ValueSetExpansionOutcome(result).setTxLink(txLog.getLastId());
    } catch (Exception e) {
        res = new ValueSetExpansionOutcome(e.getMessage() == null ? e.getClass().getName() : e.getMessage(), TerminologyServiceErrorClass.UNKNOWN);
        if (txLog != null) {
            res.setTxLink(txLog.getLastId());
        }
    }
    txCache.cacheExpansion(cacheToken, res, TerminologyCache.PERMANENT);
    return res;
}
Also used : ConceptSetComponent(org.hl7.fhir.r4b.model.ValueSet.ConceptSetComponent) Parameters(org.hl7.fhir.r4b.model.Parameters) StringType(org.hl7.fhir.r4b.model.StringType) HashMap(java.util.HashMap) CacheToken(org.hl7.fhir.r4b.context.TerminologyCache.CacheToken) ValueSetExpansionOutcome(org.hl7.fhir.r4b.terminologies.ValueSetExpander.ValueSetExpansionOutcome) ValueSet(org.hl7.fhir.r4b.model.ValueSet) ValueSetComposeComponent(org.hl7.fhir.r4b.model.ValueSet.ValueSetComposeComponent) TerminologyServiceException(org.hl7.fhir.exceptions.TerminologyServiceException) FileNotFoundException(java.io.FileNotFoundException) NoTerminologyServiceException(org.hl7.fhir.exceptions.NoTerminologyServiceException) DefinitionException(org.hl7.fhir.exceptions.DefinitionException) IOException(java.io.IOException) FHIRException(org.hl7.fhir.exceptions.FHIRException)

Aggregations

TerminologyServiceException (org.hl7.fhir.exceptions.TerminologyServiceException)22 NoTerminologyServiceException (org.hl7.fhir.exceptions.NoTerminologyServiceException)12 IOException (java.io.IOException)9 FileNotFoundException (java.io.FileNotFoundException)8 FHIRException (org.hl7.fhir.exceptions.FHIRException)8 DefinitionException (org.hl7.fhir.exceptions.DefinitionException)7 NotImplementedException (org.apache.commons.lang3.NotImplementedException)6 HashMap (java.util.HashMap)5 ArrayList (java.util.ArrayList)4 UriType (org.hl7.fhir.r4.model.UriType)4 ValueSet (org.hl7.fhir.r4.model.ValueSet)4 ValueSet (org.hl7.fhir.r5.model.ValueSet)4 ValueSet (org.hl7.fhir.dstu3.model.ValueSet)3 ValueSetExpansionParameterComponent (org.hl7.fhir.r4.model.ValueSet.ValueSetExpansionParameterComponent)3 List (java.util.List)2 UriType (org.hl7.fhir.dstu2.model.UriType)2 ValueSet (org.hl7.fhir.dstu2.model.ValueSet)2 ValueSetExpansionParameterComponent (org.hl7.fhir.dstu2.model.ValueSet.ValueSetExpansionParameterComponent)2 UriType (org.hl7.fhir.dstu2016may.model.UriType)2 ValueSetExpansionParameterComponent (org.hl7.fhir.dstu2016may.model.ValueSet.ValueSetExpansionParameterComponent)2