Search in sources :

Example 6 with ValueSetExpansionOutcome

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

the class ValueSetExpanderSimple method expand.

@Override
public ValueSetExpansionOutcome expand(ValueSet source) {
    try {
        focus = source.copy();
        focus.setExpansion(new ValueSet.ValueSetExpansionComponent());
        focus.getExpansion().setTimestampElement(DateTimeType.now());
        focus.getExpansion().setIdentifier(Factory.createUUID());
        handleDefine(source, focus.getExpansion().getParameter());
        if (source.hasCompose())
            handleCompose(source.getCompose(), focus.getExpansion().getParameter());
        for (ValueSetExpansionContainsComponent c : codes) {
            if (map.containsKey(key(c))) {
                focus.getExpansion().getContains().add(c);
            }
        }
        return new ValueSetExpansionOutcome(focus, null);
    } catch (Exception e) {
        // that might fail too, but it might not, later.
        return new ValueSetExpansionOutcome(new ValueSetCheckerSimple(source, factory, context), e.getMessage());
    }
}
Also used : ValueSetExpansionContainsComponent(org.hl7.fhir.dstu2.model.ValueSet.ValueSetExpansionContainsComponent) ValueSetExpansionComponent(org.hl7.fhir.dstu2.model.ValueSet.ValueSetExpansionComponent) ValueSet(org.hl7.fhir.dstu2.model.ValueSet) NotImplementedException(org.apache.commons.lang3.NotImplementedException) IOException(java.io.IOException) TerminologyServiceException(org.hl7.fhir.exceptions.TerminologyServiceException) FileNotFoundException(java.io.FileNotFoundException)

Example 7 with ValueSetExpansionOutcome

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

the class ValueSetExpanderSimple method importValueSet.

private void importValueSet(String value, List<ValueSetExpansionParameterComponent> params) throws ETooCostly, TerminologyServiceException, FileNotFoundException, IOException {
    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);
    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() + "?version=" + vs.getVersion())))
            params.add(new ValueSetExpansionParameterComponent().setName("version").setValue(new UriType(vs.getUrl() + "?version=" + vs.getVersion())));
    for (ValueSetExpansionParameterComponent p : vso.getValueset().getExpansion().getParameter()) {
        if (!existsInParams(params, p.getName(), p.getValue()))
            params.add(p);
    }
    for (ValueSetExpansionContainsComponent c : vso.getValueset().getExpansion().getContains()) {
        addCode(c.getSystem(), c.getCode(), c.getDisplay());
    }
}
Also used : ValueSetExpansionContainsComponent(org.hl7.fhir.dstu2.model.ValueSet.ValueSetExpansionContainsComponent) ValueSetExpansionParameterComponent(org.hl7.fhir.dstu2.model.ValueSet.ValueSetExpansionParameterComponent) TerminologyServiceException(org.hl7.fhir.exceptions.TerminologyServiceException) ValueSet(org.hl7.fhir.dstu2.model.ValueSet) UriType(org.hl7.fhir.dstu2.model.UriType)

Example 8 with ValueSetExpansionOutcome

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

the class BaseWorkerContext method handleByCache.

private ValidationResult handleByCache(ValueSet vs, CodeableConcept concept, boolean tryCache) {
    String cacheId = cacheId(concept);
    Map<String, ValidationResult> cache = validationCache.get(vs.getUrl());
    if (cache == null) {
        cache = new HashMap<String, IWorkerContext.ValidationResult>();
        validationCache.put(vs.getUrl(), cache);
    }
    if (cache.containsKey(cacheId))
        return cache.get(cacheId);
    if (validationCache.containsKey(vs.getUrl()) && validationCache.get(vs.getUrl()).containsKey(cacheId))
        return validationCache.get(vs.getUrl()).get(cacheId);
    if (!tryCache)
        return null;
    if (!cacheValidation)
        return null;
    if (failed.contains(vs.getUrl()))
        return null;
    ValueSetExpansionOutcome vse = expandVS(vs, true);
    if (vse.getValueset() == null || notcomplete(vse.getValueset())) {
        failed.add(vs.getUrl());
        return null;
    }
    ValidationResult res = validateCode(concept, vse.getValueset());
    cache.put(cacheId, res);
    return res;
}
Also used : ValueSetExpansionOutcome(org.hl7.fhir.dstu2.terminologies.ValueSetExpander.ValueSetExpansionOutcome)

Example 9 with ValueSetExpansionOutcome

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

the class ValueSetExpanderSimple method importValueSet.

private void importValueSet(String value, List<ValueSetExpansionParameterComponent> params) throws ETooCostly, TerminologyServiceException, FileNotFoundException, IOException {
    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);
    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() + "?version=" + vs.getVersion())))
            params.add(new ValueSetExpansionParameterComponent().setName("version").setValue(new UriType(vs.getUrl() + "?version=" + vs.getVersion())));
    for (ValueSetExpansionParameterComponent p : vso.getValueset().getExpansion().getParameter()) {
        if (!existsInParams(params, p.getName(), p.getValue()))
            params.add(p);
    }
    for (ValueSetExpansionContainsComponent c : vso.getValueset().getExpansion().getContains()) {
        addCode(c.getSystem(), c.getCode(), c.getDisplay());
    }
}
Also used : ValueSetExpansionContainsComponent(org.hl7.fhir.dstu2016may.model.ValueSet.ValueSetExpansionContainsComponent) ValueSetExpansionParameterComponent(org.hl7.fhir.dstu2016may.model.ValueSet.ValueSetExpansionParameterComponent) TerminologyServiceException(org.hl7.fhir.exceptions.TerminologyServiceException) ValueSet(org.hl7.fhir.dstu2016may.model.ValueSet) UriType(org.hl7.fhir.dstu2016may.model.UriType)

Example 10 with ValueSetExpansionOutcome

use of org.hl7.fhir.r5.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(true, false).composePlainText(oo.getText().getDiv())));
                } else {
                    ValueSet vs = (ValueSet) r;
                    expansions.put(vs.getUrl(), new ValueSetExpansionOutcome(vs, null));
                }
            } finally {
                IOUtils.closeQuietly(is);
            }
        }
    }
}
Also used : OperationOutcome(org.hl7.fhir.dstu2016may.model.OperationOutcome) Resource(org.hl7.fhir.dstu2016may.model.Resource) XhtmlComposer(org.hl7.fhir.utilities.xhtml.XhtmlComposer) ValueSetExpansionOutcome(org.hl7.fhir.dstu2016may.terminologies.ValueSetExpander.ValueSetExpansionOutcome) File(java.io.File) ValueSet(org.hl7.fhir.dstu2016may.model.ValueSet) FileInputStream(java.io.FileInputStream)

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