Search in sources :

Example 76 with ValidationResult

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

the class FHIRPathEngine method opMemberOf.

private List<Base> opMemberOf(ExecutionContext context, List<Base> left, List<Base> right, ExpressionNode expr) throws FHIRException {
    boolean ans = false;
    String url = right.get(0).primitiveValue();
    ValueSet vs = hostServices != null ? hostServices.resolveValueSet(context.appInfo, url) : worker.fetchResource(ValueSet.class, url);
    if (vs != null) {
        for (Base l : left) {
            if (Utilities.existsInList(l.fhirType(), "code", "string", "uri")) {
                if (worker.validateCode(terminologyServiceOptions.guessSystem(), TypeConvertor.castToCoding(l), vs).isOk()) {
                    ans = true;
                }
            } else if (l.fhirType().equals("Coding")) {
                if (worker.validateCode(terminologyServiceOptions, TypeConvertor.castToCoding(l), vs).isOk()) {
                    ans = true;
                }
            } else if (l.fhirType().equals("CodeableConcept")) {
                CodeableConcept cc = TypeConvertor.castToCodeableConcept(l);
                ValidationResult vr = worker.validateCode(terminologyServiceOptions, cc, vs);
                // System.out.println("~~~ "+DataRenderer.display(worker, cc)+ " memberOf "+url+": "+vr.toString());
                if (vr.isOk()) {
                    ans = true;
                }
            } else {
            // System.out.println("unknown type in opMemberOf: "+l.fhirType());
            }
        }
    }
    return makeBoolean(ans);
}
Also used : ValidationResult(org.hl7.fhir.r5.context.IWorkerContext.ValidationResult) ValueSet(org.hl7.fhir.r5.model.ValueSet) Base(org.hl7.fhir.r5.model.Base) CodeableConcept(org.hl7.fhir.r5.model.CodeableConcept)

Example 77 with ValidationResult

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

the class ValueSetCheckerSimple method findCodeInExpansion.

private ValidationResult findCodeInExpansion(Coding code, List<ValueSetExpansionContainsComponent> contains) {
    for (ValueSetExpansionContainsComponent containsComponent : contains) {
        if (containsComponent.getSystem().equals(code.getSystem()) && containsComponent.getCode().equals(code.getCode())) {
            ConceptDefinitionComponent ccd = new ConceptDefinitionComponent();
            ccd.setCode(containsComponent.getCode());
            ccd.setDisplay(containsComponent.getDisplay());
            ValidationResult res = new ValidationResult(code.getSystem(), ccd);
            return res;
        }
        if (containsComponent.hasContains()) {
            ValidationResult res = findCodeInExpansion(code, containsComponent.getContains());
            if (res != null) {
                return res;
            }
        }
    }
    return null;
}
Also used : ValueSetExpansionContainsComponent(org.hl7.fhir.r5.model.ValueSet.ValueSetExpansionContainsComponent) ConceptDefinitionComponent(org.hl7.fhir.r5.model.CodeSystem.ConceptDefinitionComponent) ValidationResult(org.hl7.fhir.r5.context.IWorkerContext.ValidationResult)

Example 78 with ValidationResult

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

the class ValueSetCheckerSimple method inComponent.

private Boolean inComponent(ConceptSetComponent vsi, int vsiIndex, String system, String code, boolean only, List<String> warnings) throws FHIRException {
    if (isValueSetUnionImports()) {
        for (UriType uri : vsi.getValueSet()) {
            if (inImport(uri.getValue(), system, code)) {
                return true;
            }
        }
    } else {
        for (UriType uri : vsi.getValueSet()) {
            if (!inImport(uri.getValue(), system, code)) {
                return false;
            }
        }
    }
    if (!vsi.hasSystem()) {
        return false;
    }
    if (only && system == null) {
        // whether we know the system or not, we'll accept the stated codes at face value
        for (ConceptReferenceComponent cc : vsi.getConcept()) {
            if (cc.getCode().equals(code)) {
                return true;
            }
        }
    }
    if (!system.equals(vsi.getSystem()))
        return false;
    // ok, we need the code system
    CodeSystem cs = resolveCodeSystem(system);
    if (cs == null || (cs.getContent() != CodeSystemContentMode.COMPLETE && cs.getContent() != CodeSystemContentMode.FRAGMENT)) {
        // make up a transient value set with
        ValueSet vs = new ValueSet();
        vs.setStatus(PublicationStatus.ACTIVE);
        vs.setUrl(valueset.getUrl() + "--" + vsiIndex);
        vs.setVersion(valueset.getVersion());
        vs.getCompose().addInclude(vsi);
        ValidationResult res = context.validateCode(options.noClient(), new Coding(system, code, null), vs);
        if (res.getErrorClass() == TerminologyServiceErrorClass.UNKNOWN || res.getErrorClass() == TerminologyServiceErrorClass.CODESYSTEM_UNSUPPORTED || res.getErrorClass() == TerminologyServiceErrorClass.VALUESET_UNSUPPORTED) {
            if (warnings != null && res.getErrorClass() == TerminologyServiceErrorClass.CODESYSTEM_UNSUPPORTED) {
                warnings.add(context.formatMessage(I18nConstants.TERMINOLOGY_TX_SYSTEM_NOTKNOWN, system));
            }
            return null;
        }
        if (res.getErrorClass() == TerminologyServiceErrorClass.NOSERVICE) {
            throw new NoTerminologyServiceException();
        }
        return res.isOk();
    } else {
        if (vsi.hasFilter()) {
            boolean ok = true;
            for (ConceptSetFilterComponent f : vsi.getFilter()) {
                if (!codeInFilter(cs, system, f, code)) {
                    ok = false;
                    break;
                }
            }
            return ok;
        }
        List<ConceptDefinitionComponent> list = cs.getConcept();
        boolean ok = validateCodeInConceptList(code, cs, list);
        if (ok && vsi.hasConcept()) {
            for (ConceptReferenceComponent cc : vsi.getConcept()) {
                if (cc.getCode().equals(code)) {
                    return true;
                }
            }
            return false;
        } else {
            return ok;
        }
    }
}
Also used : NoTerminologyServiceException(org.hl7.fhir.exceptions.NoTerminologyServiceException) ConceptSetFilterComponent(org.hl7.fhir.r5.model.ValueSet.ConceptSetFilterComponent) ConceptDefinitionComponent(org.hl7.fhir.r5.model.CodeSystem.ConceptDefinitionComponent) Coding(org.hl7.fhir.r5.model.Coding) ValidationResult(org.hl7.fhir.r5.context.IWorkerContext.ValidationResult) ConceptReferenceComponent(org.hl7.fhir.r5.model.ValueSet.ConceptReferenceComponent) CodeSystem(org.hl7.fhir.r5.model.CodeSystem) ValueSet(org.hl7.fhir.r5.model.ValueSet) UriType(org.hl7.fhir.r5.model.UriType)

Example 79 with ValidationResult

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

the class BaseWorkerContext method serverValidateCode.

private ValidationResult serverValidateCode(Parameters pin) {
    Parameters pout = txServer.operateType(ValueSet.class, "validate-code", pin);
    boolean ok = false;
    String message = "No Message returned";
    String display = null;
    for (ParametersParameterComponent p : pout.getParameter()) {
        if (p.getName().equals("result"))
            ok = ((BooleanType) p.getValue()).getValue().booleanValue();
        else if (p.getName().equals("message"))
            message = ((StringType) p.getValue()).getValue();
        else if (p.getName().equals("display"))
            display = ((StringType) p.getValue()).getValue();
    }
    if (!ok)
        return new ValidationResult(IssueSeverity.ERROR, message);
    else if (display != null)
        return new ValidationResult(new ConceptDefinitionComponent().setDisplay(display));
    else
        return new ValidationResult(null);
}
Also used : Parameters(org.hl7.fhir.dstu2016may.model.Parameters) ConceptDefinitionComponent(org.hl7.fhir.dstu2016may.model.CodeSystem.ConceptDefinitionComponent) StringType(org.hl7.fhir.dstu2016may.model.StringType) ParametersParameterComponent(org.hl7.fhir.dstu2016may.model.Parameters.ParametersParameterComponent)

Example 80 with ValidationResult

use of org.hl7.fhir.r4b.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.dstu2016may.model.Parameters)

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