Search in sources :

Example 11 with ValueSetExpansionOutcome

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

Example 12 with ValueSetExpansionOutcome

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

the class BaseWorkerContext method handleByCache.

private ValidationResult handleByCache(ValueSet vs, Coding coding, boolean tryCache) {
    String cacheId = cacheId(coding);
    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 (!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(coding, vse.getValueset());
    cache.put(cacheId, res);
    return res;
}
Also used : ValueSetExpansionOutcome(org.hl7.fhir.dstu2016may.terminologies.ValueSetExpander.ValueSetExpansionOutcome)

Example 13 with ValueSetExpansionOutcome

use of org.hl7.fhir.r4b.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());
        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 (RuntimeException e) {
        // it swallows bugs.. what would be expected to be caught there?
        throw e;
    } 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.dstu2016may.model.ValueSet.ValueSetExpansionContainsComponent) ValueSetExpansionComponent(org.hl7.fhir.dstu2016may.model.ValueSet.ValueSetExpansionComponent) ValueSet(org.hl7.fhir.dstu2016may.model.ValueSet) NotImplementedException(org.apache.commons.lang3.NotImplementedException) IOException(java.io.IOException) TerminologyServiceException(org.hl7.fhir.exceptions.TerminologyServiceException) FileNotFoundException(java.io.FileNotFoundException)

Example 14 with ValueSetExpansionOutcome

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

Example 15 with ValueSetExpansionOutcome

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

the class BaseWorkerContext method expandVS.

@Override
public ValueSetExpansionOutcome expandVS(ValueSet vs, boolean cacheOk, boolean heirarchical) {
    try {
        if (vs.hasExpansion()) {
            return new ValueSetExpansionOutcome(vs.copy());
        }
        String cacheFn = null;
        if (cache != null) {
            cacheFn = Utilities.path(cache, determineCacheId(vs, heirarchical) + ".json");
            if (new File(cacheFn).exists()) {
                return loadFromCache(vs.copy(), cacheFn);
            }
        }
        if (cacheOk && vs.hasUrl()) {
            if (expProfile == null) {
                throw new Exception("No ExpansionProfile provided");
            }
            ValueSetExpansionOutcome vse = expansionCache.getExpander().expand(vs, expProfile.setExcludeNested(!heirarchical));
            if (vse.getValueset() != null) {
                if (cache != null) {
                    FileOutputStream s = new FileOutputStream(cacheFn);
                    newJsonParser().compose(new FileOutputStream(cacheFn), vse.getValueset());
                    s.close();
                }
            }
            return vse;
        } else {
            ValueSetExpansionOutcome res = expandOnServer(vs, cacheFn);
            if (cacheFn != null) {
                if (res.getValueset() != null) {
                    saveToCache(res.getValueset(), cacheFn);
                } else {
                    OperationOutcome oo = new OperationOutcome();
                    oo.addIssue().getDetails().setText(res.getError());
                    saveToCache(oo, cacheFn);
                }
            }
            return res;
        }
    } catch (NoTerminologyServiceException e) {
        return new ValueSetExpansionOutcome(e.getMessage() == null ? e.getClass().getName() : e.getMessage(), TerminologyServiceErrorClass.NOSERVICE);
    } catch (Exception e) {
        return new ValueSetExpansionOutcome(e.getMessage() == null ? e.getClass().getName() : e.getMessage(), TerminologyServiceErrorClass.UNKNOWN);
    }
}
Also used : NoTerminologyServiceException(org.hl7.fhir.exceptions.NoTerminologyServiceException) OperationOutcome(org.hl7.fhir.dstu3.model.OperationOutcome) FileOutputStream(java.io.FileOutputStream) ValueSetExpansionOutcome(org.hl7.fhir.dstu3.terminologies.ValueSetExpander.ValueSetExpansionOutcome) File(java.io.File) TextFile(org.hl7.fhir.utilities.TextFile) 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)

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