Search in sources :

Example 26 with TerminologyServiceException

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

the class NarrativeGenerator method getConceptForCode.

private ConceptDefinitionComponent getConceptForCode(CodeSystem e, String code, ConceptSetComponent inc) {
    // first, look in the code systems
    if (e == null)
        e = context.fetchCodeSystem(inc.getSystem());
    if (e != null) {
        ConceptDefinitionComponent v = getConceptForCode(e.getConcept(), code);
        if (v != null)
            return v;
    }
    if (!context.hasCache()) {
        ValueSetExpansionComponent vse;
        try {
            ValueSetExpansionOutcome vso = context.expandVS(inc, false);
            ValueSet valueset = vso.getValueset();
            if (valueset == null)
                throw new TerminologyServiceException("Error Expanding ValueSet: " + vso.getError());
            vse = valueset.getExpansion();
        } catch (TerminologyServiceException e1) {
            return null;
        }
        if (vse != null) {
            ConceptDefinitionComponent v = getConceptForCodeFromExpansion(vse.getContains(), code);
            if (v != null)
                return v;
        }
    }
    return context.validateCode(terminologyServiceOptions, inc.getSystem(), code, null).asConceptDefinition();
}
Also used : ValueSetExpansionOutcome(org.hl7.fhir.r4.terminologies.ValueSetExpander.ValueSetExpansionOutcome) TerminologyServiceException(org.hl7.fhir.exceptions.TerminologyServiceException) ValueSet(org.hl7.fhir.r4.model.ValueSet)

Example 27 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, boolean noInactive) throws TerminologyServiceException {
    ValueSet vs = new ValueSet();
    vs.setStatus(PublicationStatus.ACTIVE);
    vs.setCompose(new ValueSetComposeComponent());
    vs.getCompose().setInactive(!noInactive);
    vs.getCompose().getInclude().add(inc);
    CacheToken cacheToken = txCache.generateExpandToken(vs, hierarchical);
    ValueSetExpansionOutcome res;
    res = txCache.getExpansion(cacheToken);
    if (res != null) {
        return res;
    }
    Parameters p = constructParameters(vs, hierarchical);
    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");
    txLog("$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.r5.model.ValueSet.ConceptSetComponent) Parameters(org.hl7.fhir.r5.model.Parameters) HashMap(java.util.HashMap) CacheToken(org.hl7.fhir.r5.context.TerminologyCache.CacheToken) ValueSetExpansionOutcome(org.hl7.fhir.r5.terminologies.ValueSetExpander.ValueSetExpansionOutcome) ValueSet(org.hl7.fhir.r5.model.ValueSet) ValueSetComposeComponent(org.hl7.fhir.r5.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