Search in sources :

Example 1 with ValidationResult

use of org.hl7.fhir.r4.context.IWorkerContext.ValidationResult in project org.hl7.fhir.core by hapifhir.

the class BaseWorkerContext method validateCode.

@Override
public ValidationResult validateCode(String system, String code, String display, ConceptSetComponent vsi) {
    try {
        ValueSet vs = new ValueSet().setUrl(Utilities.makeUuidUrn());
        vs.getCompose().addInclude(vsi);
        return verifyCodeExternal(vs, new Coding().setSystem(system).setCode(code).setDisplay(display), true);
    } catch (Exception e) {
        return new ValidationResult(IssueSeverity.FATAL, "Error validating code \"" + code + "\" in system \"" + system + "\": " + e.getMessage());
    }
}
Also used : Coding(org.hl7.fhir.dstu2.model.Coding) ValueSet(org.hl7.fhir.dstu2.model.ValueSet) IOException(java.io.IOException) FileNotFoundException(java.io.FileNotFoundException)

Example 2 with ValidationResult

use of org.hl7.fhir.r4.context.IWorkerContext.ValidationResult in project org.hl7.fhir.core by hapifhir.

the class BaseWorkerContext method verifyCodeExternal.

private ValidationResult verifyCodeExternal(ValueSet vs, CodeableConcept cc, boolean tryCache) {
    ValidationResult res = handleByCache(vs, cc, tryCache);
    if (res != null)
        return res;
    Parameters pin = new Parameters();
    pin.addParameter().setName("codeableConcept").setValue(cc);
    pin.addParameter().setName("valueSet").setResource(vs);
    res = serverValidateCode(pin);
    Map<String, ValidationResult> cache = validationCache.get(vs.getUrl());
    cache.put(cacheId(cc), res);
    return res;
}
Also used : Parameters(org.hl7.fhir.dstu2.model.Parameters)

Example 3 with ValidationResult

use of org.hl7.fhir.r4.context.IWorkerContext.ValidationResult in project org.hl7.fhir.core by hapifhir.

the class BaseWorkerContext method verifyCodeExternal.

private ValidationResult verifyCodeExternal(ValueSet vs, Coding coding, boolean tryCache) {
    ValidationResult res = handleByCache(vs, coding, tryCache);
    if (res != null)
        return res;
    Parameters pin = new Parameters();
    pin.addParameter().setName("coding").setValue(coding);
    pin.addParameter().setName("valueSet").setResource(vs);
    res = serverValidateCode(pin);
    Map<String, ValidationResult> cache = validationCache.get(vs.getUrl());
    cache.put(cacheId(coding), res);
    return res;
}
Also used : Parameters(org.hl7.fhir.dstu2.model.Parameters)

Example 4 with ValidationResult

use of org.hl7.fhir.r4.context.IWorkerContext.ValidationResult 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 5 with ValidationResult

use of org.hl7.fhir.r4.context.IWorkerContext.ValidationResult in project org.hl7.fhir.core by hapifhir.

the class BaseWorkerContext method validateCode.

@Override
public ValidationResult validateCode(String system, String code, String display, ConceptSetComponent vsi) {
    try {
        ValueSet vs = new ValueSet().setUrl(Utilities.makeUuidUrn());
        vs.getCompose().addInclude(vsi);
        return verifyCodeExternal(vs, new Coding().setSystem(system).setCode(code).setDisplay(display), true);
    } catch (Exception e) {
        return new ValidationResult(IssueSeverity.FATAL, "Error validating code \"" + code + "\" in system \"" + system + "\": " + e.getMessage());
    }
}
Also used : Coding(org.hl7.fhir.dstu2016may.model.Coding) ValueSet(org.hl7.fhir.dstu2016may.model.ValueSet) IOException(java.io.IOException) FileNotFoundException(java.io.FileNotFoundException)

Aggregations

FHIRException (org.hl7.fhir.exceptions.FHIRException)32 IOException (java.io.IOException)22 ValidationResult (org.hl7.fhir.r5.context.IWorkerContext.ValidationResult)20 TerminologyServiceException (org.hl7.fhir.exceptions.TerminologyServiceException)17 DefinitionException (org.hl7.fhir.exceptions.DefinitionException)15 FileNotFoundException (java.io.FileNotFoundException)14 ValidationResult (ca.uhn.fhir.validation.ValidationResult)12 CodeSystem (org.hl7.fhir.r5.model.CodeSystem)12 ConceptDefinitionComponent (org.hl7.fhir.r5.model.CodeSystem.ConceptDefinitionComponent)11 ValueSet (org.hl7.fhir.r5.model.ValueSet)11 CommaSeparatedStringBuilder (org.hl7.fhir.utilities.CommaSeparatedStringBuilder)11 NoTerminologyServiceException (org.hl7.fhir.exceptions.NoTerminologyServiceException)10 ValidationResult (org.hl7.fhir.r4b.context.IWorkerContext.ValidationResult)10 ArrayList (java.util.ArrayList)9 Coding (org.hl7.fhir.r5.model.Coding)9 NotImplementedException (org.apache.commons.lang3.NotImplementedException)7 PathEngineException (org.hl7.fhir.exceptions.PathEngineException)7 ValidationResult (org.hl7.fhir.r4.context.IWorkerContext.ValidationResult)7 ConceptDefinitionComponent (org.hl7.fhir.r4b.model.CodeSystem.ConceptDefinitionComponent)7 FHIRLexerException (org.hl7.fhir.r5.utils.FHIRLexer.FHIRLexerException)7