Search in sources :

Example 76 with ValueSetExpansionOutcome

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

the class NarrativeGenerator method countMembership.

private Integer countMembership(ValueSet vs) {
    int count = 0;
    if (vs.hasExpansion())
        count = count + conceptCount(vs.getExpansion().getContains());
    else {
        if (vs.hasCompose()) {
            if (vs.getCompose().hasExclude()) {
                try {
                    ValueSetExpansionOutcome vse = context.expandVS(vs, true, false);
                    count = 0;
                    count += conceptCount(vse.getValueset().getExpansion().getContains());
                    return count;
                } catch (Exception e) {
                    return null;
                }
            }
            for (ConceptSetComponent inc : vs.getCompose().getInclude()) {
                if (inc.hasFilter())
                    return null;
                if (!inc.hasConcept())
                    return null;
                count = count + inc.getConcept().size();
            }
        }
    }
    return count;
}
Also used : ConceptSetComponent(org.hl7.fhir.dstu3.model.ValueSet.ConceptSetComponent) ValueSetExpansionOutcome(org.hl7.fhir.dstu3.terminologies.ValueSetExpander.ValueSetExpansionOutcome) ContactPoint(org.hl7.fhir.dstu3.model.ContactPoint) TerminologyServiceException(org.hl7.fhir.exceptions.TerminologyServiceException) DefinitionException(org.hl7.fhir.exceptions.DefinitionException) IOException(java.io.IOException) FHIRException(org.hl7.fhir.exceptions.FHIRException) ParseException(java.text.ParseException) UnsupportedEncodingException(java.io.UnsupportedEncodingException) NotImplementedException(org.apache.commons.lang3.NotImplementedException)

Example 77 with ValueSetExpansionOutcome

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

the class ValueSetExpansionCache method loadCache.

private void loadCache() throws FHIRFormatError, IOException {
    File[] files = new File(cacheFolder).listFiles();
    for (File f : files) {
        if (f.getName().endsWith(".xml")) {
            final FileInputStream is = new FileInputStream(f);
            try {
                Resource r = context.newXmlParser().setOutputStyle(OutputStyle.PRETTY).parse(is);
                if (r instanceof OperationOutcome) {
                    OperationOutcome oo = (OperationOutcome) r;
                    expansions.put(ToolingExtensions.getExtension(oo, VS_ID_EXT).getValue().toString(), new ValueSetExpansionOutcome(new XhtmlComposer(XhtmlComposer.XML).composePlainText(oo.getText().getDiv()), TerminologyServiceErrorClass.UNKNOWN));
                } else {
                    ValueSet vs = (ValueSet) r;
                    expansions.put(vs.getUrl(), new ValueSetExpansionOutcome(vs));
                }
            } finally {
                IOUtils.closeQuietly(is);
            }
        }
    }
}
Also used : OperationOutcome(org.hl7.fhir.dstu3.model.OperationOutcome) Resource(org.hl7.fhir.dstu3.model.Resource) XhtmlComposer(org.hl7.fhir.utilities.xhtml.XhtmlComposer) ValueSetExpansionOutcome(org.hl7.fhir.dstu3.terminologies.ValueSetExpander.ValueSetExpansionOutcome) File(java.io.File) ValueSet(org.hl7.fhir.dstu3.model.ValueSet) FileInputStream(java.io.FileInputStream)

Example 78 with ValueSetExpansionOutcome

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

the class ValueSetExpanderSimple method importValueSet.

private ValueSet importValueSet(String value, List<ValueSetExpansionParameterComponent> params, ExpansionProfile profile) 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 = factory.getExpander().expand(vs, profile);
    if (vso.getError() != null)
        throw new TerminologyServiceException("Unable to expand imported value set: " + vso.getError());
    if (vso.getService() != null)
        throw new TerminologyServiceException("Unable to expand imported value set " + value);
    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 : NoTerminologyServiceException(org.hl7.fhir.exceptions.NoTerminologyServiceException) TerminologyServiceException(org.hl7.fhir.exceptions.TerminologyServiceException) ValueSet(org.hl7.fhir.dstu3.model.ValueSet)

Example 79 with ValueSetExpansionOutcome

use of org.hl7.fhir.dstu3.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;
    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();
                display = t.getDisplay();
                break;
            }
            if (code.equalsIgnoreCase(t.getDisplay()) && t.hasSystem()) {
                system = t.getSystem();
                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, system, 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.r4.model.ValueSet.ValueSetExpansionContainsComponent) Coding(org.hl7.fhir.r4.model.Coding) ValueSetExpansionOutcome(org.hl7.fhir.r4.terminologies.ValueSetExpander.ValueSetExpansionOutcome) CommaSeparatedStringBuilder(org.hl7.fhir.utilities.CommaSeparatedStringBuilder) ValidationResult(org.hl7.fhir.r4.context.IWorkerContext.ValidationResult) ValueSet(org.hl7.fhir.r4.model.ValueSet) FHIRException(org.hl7.fhir.exceptions.FHIRException)

Example 80 with ValueSetExpansionOutcome

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

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