Search in sources :

Example 31 with ValueSetExpansionOutcome

use of org.hl7.fhir.r5.terminologies.ValueSetExpander.ValueSetExpansionOutcome 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)

Example 32 with ValueSetExpansionOutcome

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

the class BaseWorkerContext method expandVS.

@Override
public ValueSetExpansionOutcome expandVS(ElementDefinitionBindingComponent binding, boolean cacheOk, boolean heirarchical) throws FHIRException {
    ValueSet vs = null;
    vs = fetchResource(ValueSet.class, binding.getValueSet());
    if (vs == null) {
        throw new FHIRException(formatMessage(I18nConstants.UNABLE_TO_RESOLVE_VALUE_SET_, binding.getValueSet()));
    }
    return expandVS(vs, cacheOk, heirarchical);
}
Also used : ValueSet(org.hl7.fhir.r4b.model.ValueSet) FHIRException(org.hl7.fhir.exceptions.FHIRException)

Example 33 with ValueSetExpansionOutcome

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

the class StructureMapUtilities method buildCoding.

private Coding buildCoding(String uri, String code) throws FHIRException {
    // if we can get this as a valueSet, we will
    String system = null;
    String display = null;
    String version = null;
    ValueSet vs = Utilities.noString(uri) ? null : worker.fetchResourceWithException(ValueSet.class, uri);
    if (vs != null) {
        ValueSetExpansionOutcome vse = worker.expandVS(vs, true, false);
        if (vse.getError() != null)
            throw new FHIRException(vse.getError());
        CommaSeparatedStringBuilder b = new CommaSeparatedStringBuilder();
        for (ValueSetExpansionContainsComponent t : vse.getValueset().getExpansion().getContains()) {
            if (t.hasCode())
                b.append(t.getCode());
            if (code.equals(t.getCode()) && t.hasSystem()) {
                system = t.getSystem();
                version = t.getVersion();
                display = t.getDisplay();
                break;
            }
            if (code.equalsIgnoreCase(t.getDisplay()) && t.hasSystem()) {
                system = t.getSystem();
                version = t.getVersion();
                display = t.getDisplay();
                break;
            }
        }
        if (system == null)
            throw new FHIRException("The code '" + code + "' is not in the value set '" + uri + "' (valid codes: " + b.toString() + "; also checked displays)");
    } else {
        system = uri;
    }
    ValidationResult vr = worker.validateCode(terminologyServiceOptions.setVersionFlexible(true), system, version, code, null);
    if (vr != null && vr.getDisplay() != null)
        display = vr.getDisplay();
    return new Coding().setSystem(system).setCode(code).setDisplay(display);
}
Also used : ValueSetExpansionContainsComponent(org.hl7.fhir.r4b.model.ValueSet.ValueSetExpansionContainsComponent) ValueSetExpansionOutcome(org.hl7.fhir.r4b.terminologies.ValueSetExpander.ValueSetExpansionOutcome) CommaSeparatedStringBuilder(org.hl7.fhir.utilities.CommaSeparatedStringBuilder) ValidationResult(org.hl7.fhir.r4b.context.IWorkerContext.ValidationResult) FHIRException(org.hl7.fhir.exceptions.FHIRException)

Example 34 with ValueSetExpansionOutcome

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

the class BaseWorkerContext method expandVS.

@Override
public ValueSetExpansionOutcome expandVS(ElementDefinitionBindingComponent binding, boolean cacheOk, boolean heirarchical) throws FHIRException {
    ValueSet vs = null;
    vs = fetchResource(ValueSet.class, binding.getValueSet());
    if (vs == null) {
        throw new FHIRException(formatMessage(I18nConstants.UNABLE_TO_RESOLVE_VALUE_SET_, binding.getValueSet()));
    }
    return expandVS(vs, cacheOk, heirarchical);
}
Also used : ValueSet(org.hl7.fhir.r5.model.ValueSet) FHIRException(org.hl7.fhir.exceptions.FHIRException)

Example 35 with ValueSetExpansionOutcome

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

the class TerminologyCache method getCacheEntry.

private CacheEntry getCacheEntry(String request, String resultString) throws IOException {
    CacheEntry ce = new CacheEntry();
    ce.persistent = true;
    ce.request = request;
    boolean e = resultString.charAt(0) == 'e';
    resultString = resultString.substring(3);
    JsonObject o = (JsonObject) new com.google.gson.JsonParser().parse(resultString);
    String error = loadJS(o.get("error"));
    if (e) {
        if (o.has("valueSet"))
            ce.e = new ValueSetExpansionOutcome((ValueSet) new JsonParser().parse(o.getAsJsonObject("valueSet")), error, TerminologyServiceErrorClass.UNKNOWN);
        else
            ce.e = new ValueSetExpansionOutcome(error, TerminologyServiceErrorClass.UNKNOWN);
    } else {
        String t = loadJS(o.get("severity"));
        IssueSeverity severity = t == null ? null : IssueSeverity.fromCode(t);
        String display = loadJS(o.get("display"));
        String code = loadJS(o.get("code"));
        String system = loadJS(o.get("system"));
        String definition = loadJS(o.get("definition"));
        t = loadJS(o.get("class"));
        TerminologyServiceErrorClass errorClass = t == null ? null : TerminologyServiceErrorClass.valueOf(t);
        ce.v = new ValidationResult(severity, error, system, new ConceptDefinitionComponent().setDisplay(display).setDefinition(definition).setCode(code)).setErrorClass(errorClass);
    }
    return ce;
}
Also used : TerminologyServiceErrorClass(org.hl7.fhir.r5.terminologies.ValueSetExpander.TerminologyServiceErrorClass) ConceptDefinitionComponent(org.hl7.fhir.r5.model.CodeSystem.ConceptDefinitionComponent) IssueSeverity(org.hl7.fhir.utilities.validation.ValidationMessage.IssueSeverity) JsonObject(com.google.gson.JsonObject) ValueSetExpansionOutcome(org.hl7.fhir.r5.terminologies.ValueSetExpander.ValueSetExpansionOutcome) ValidationResult(org.hl7.fhir.r5.context.IWorkerContext.ValidationResult) JsonParser(org.hl7.fhir.r5.formats.JsonParser)

Aggregations

IOException (java.io.IOException)26 FHIRException (org.hl7.fhir.exceptions.FHIRException)25 TerminologyServiceException (org.hl7.fhir.exceptions.TerminologyServiceException)24 DefinitionException (org.hl7.fhir.exceptions.DefinitionException)22 FileNotFoundException (java.io.FileNotFoundException)16 ValueSet (org.hl7.fhir.r5.model.ValueSet)16 ValueSetExpansionOutcome (org.hl7.fhir.r5.terminologies.ValueSetExpander.ValueSetExpansionOutcome)16 HashMap (java.util.HashMap)11 ValueSetExpansionOutcome (org.hl7.fhir.dstu3.terminologies.ValueSetExpander.ValueSetExpansionOutcome)11 NoTerminologyServiceException (org.hl7.fhir.exceptions.NoTerminologyServiceException)11 ValueSet (org.hl7.fhir.r4b.model.ValueSet)11 ValidationMessage (org.hl7.fhir.utilities.validation.ValidationMessage)11 File (java.io.File)10 ValueSetExpansionOutcome (org.hl7.fhir.r4.terminologies.ValueSetExpander.ValueSetExpansionOutcome)10 ValueSetExpansionOutcome (org.hl7.fhir.r4b.terminologies.ValueSetExpander.ValueSetExpansionOutcome)10 NotImplementedException (org.apache.commons.lang3.NotImplementedException)9 ValueSet (org.hl7.fhir.r4.model.ValueSet)9 FileInputStream (java.io.FileInputStream)8 ValueSetExpansionOutcome (org.hl7.fhir.dstu2.terminologies.ValueSetExpander.ValueSetExpansionOutcome)8 ValueSetExpansionOutcome (org.hl7.fhir.dstu2016may.terminologies.ValueSetExpander.ValueSetExpansionOutcome)8