Search in sources :

Example 41 with NodeStack

use of org.hl7.fhir.validation.instance.utils.NodeStack in project org.hl7.fhir.core by hapifhir.

the class ValueSetValidator method validateValueSetCompose.

private void validateValueSetCompose(List<ValidationMessage> errors, Element compose, NodeStack stack, String vsid, boolean retired) {
    List<Element> includes = compose.getChildrenByName("include");
    int ci = 0;
    for (Element include : includes) {
        validateValueSetInclude(errors, include, stack.push(include, ci, null, null), vsid, retired);
        ci++;
    }
    List<Element> excludes = compose.getChildrenByName("exclude");
    int ce = 0;
    for (Element exclude : excludes) {
        validateValueSetInclude(errors, exclude, stack.push(exclude, ce, null, null), vsid, retired);
        ce++;
    }
}
Also used : Element(org.hl7.fhir.r5.elementmodel.Element)

Example 42 with NodeStack

use of org.hl7.fhir.validation.instance.utils.NodeStack in project org.hl7.fhir.core by hapifhir.

the class ValueSetValidator method validateValueSet.

public void validateValueSet(List<ValidationMessage> errors, Element vs, NodeStack stack) {
    if (!VersionUtilities.isR2Ver(context.getVersion())) {
        List<Element> composes = vs.getChildrenByName("compose");
        int cc = 0;
        for (Element compose : composes) {
            validateValueSetCompose(errors, compose, stack.push(compose, cc, null, null), vs.getNamedChildValue("url"), "retired".equals(vs.getNamedChildValue("url")));
            cc++;
        }
    }
}
Also used : Element(org.hl7.fhir.r5.elementmodel.Element)

Example 43 with NodeStack

use of org.hl7.fhir.validation.instance.utils.NodeStack in project org.hl7.fhir.core by hapifhir.

the class ValueSetValidator method validateValueSetIncludeConcept.

private boolean validateValueSetIncludeConcept(List<ValidationMessage> errors, Element concept, NodeStack stack, String system, String version) {
    String code = concept.getChildValue("code");
    if (version == null) {
        ValidationResult vv = context.validateCode(ValidationOptions.defaults(), new Coding(system, code, null), null);
        if (vv.getErrorClass() == TerminologyServiceErrorClass.CODESYSTEM_UNSUPPORTED) {
            return false;
        } else {
            boolean ok = vv.isOk();
            warning(errors, IssueType.BUSINESSRULE, stack.getLiteralPath(), ok, I18nConstants.VALUESET_INCLUDE_INVALID_CONCEPT_CODE, system, code);
        }
    } else {
        ValidationResult vv = context.validateCode(ValidationOptions.defaults(), new Coding(system, code, null).setVersion(version), null);
        if (vv.getErrorClass() == TerminologyServiceErrorClass.CODESYSTEM_UNSUPPORTED) {
            return false;
        } else {
            boolean ok = vv.isOk();
            warning(errors, IssueType.BUSINESSRULE, stack.getLiteralPath(), ok, I18nConstants.VALUESET_INCLUDE_INVALID_CONCEPT_CODE_VER, system, version, code);
        }
    }
    return true;
}
Also used : Coding(org.hl7.fhir.r5.model.Coding) ValidationResult(org.hl7.fhir.r5.context.IWorkerContext.ValidationResult)

Example 44 with NodeStack

use of org.hl7.fhir.validation.instance.utils.NodeStack in project org.hl7.fhir.core by hapifhir.

the class ValueSetValidator method validateValueSetInclude.

private void validateValueSetInclude(List<ValidationMessage> errors, Element include, NodeStack stack, String vsid, boolean retired) {
    String system = include.getChildValue("system");
    String version = include.getChildValue("version");
    List<Element> valuesets = include.getChildrenByName("valueSet");
    int i = 0;
    for (Element ve : valuesets) {
        String v = ve.getValue();
        ValueSet vs = context.fetchResource(ValueSet.class, v);
        if (vs == null) {
            NodeStack ns = stack.push(ve, i, ve.getProperty().getDefinition(), ve.getProperty().getDefinition());
            Resource rs = context.fetchResource(Resource.class, v);
            if (rs != null) {
                warning(errors, IssueType.BUSINESSRULE, ns.getLiteralPath(), false, I18nConstants.VALUESET_REFERENCE_INVALID_TYPE, v, rs.fhirType());
            } else {
                // todo: it's possible, at this point, that the txx server knows the value set, but it's not in scope
                // should we handle this case?
                warning(errors, IssueType.BUSINESSRULE, ns.getLiteralPath(), false, I18nConstants.VALUESET_REFERENCE_UNKNOWN, v);
            }
        }
        i++;
    }
    if (valuesets.size() > 1) {
        warning(errors, IssueType.INFORMATIONAL, stack.getLiteralPath(), false, I18nConstants.VALUESET_IMPORT_UNION_INTERSECTION);
    }
    List<Element> concepts = include.getChildrenByName("concept");
    List<Element> filters = include.getChildrenByName("filter");
    if (!Utilities.noString(system)) {
        boolean systemOk = true;
        int cc = 0;
        List<VSCodingValidationRequest> batch = new ArrayList<>();
        boolean first = true;
        for (Element concept : concepts) {
            // we treat the first differently because we want to know if tbe system is worth validating. if it is, then we batch the rest
            if (first) {
                systemOk = validateValueSetIncludeConcept(errors, concept, stack.push(concept, cc, null, null), system, version);
                first = false;
            } else if (systemOk) {
                batch.add(prepareValidateValueSetIncludeConcept(errors, concept, stack.push(concept, cc, null, null), system, version));
            }
            cc++;
        }
        if (parent.isValidateValueSetCodesOnTxServer() && batch.size() > 0) {
            long t = System.currentTimeMillis();
            if (parent.isDebug()) {
                System.out.println("  : Validate " + batch.size() + " codes from " + system + " for " + vsid);
            }
            context.validateCodeBatch(ValidationOptions.defaults(), batch, null);
            if (parent.isDebug()) {
                System.out.println("  :   .. " + (System.currentTimeMillis() - t) + "ms");
            }
            for (VSCodingValidationRequest cv : batch) {
                if (version == null) {
                    warningOrHint(errors, IssueType.BUSINESSRULE, cv.getStack().getLiteralPath(), cv.getResult().isOk(), !retired, I18nConstants.VALUESET_INCLUDE_INVALID_CONCEPT_CODE, system, cv.getCoding().getCode());
                } else {
                    warningOrHint(errors, IssueType.BUSINESSRULE, cv.getStack().getLiteralPath(), cv.getResult().isOk(), !retired, I18nConstants.VALUESET_INCLUDE_INVALID_CONCEPT_CODE_VER, system, version, cv.getCoding().getCode());
                }
            }
        }
        int cf = 0;
        for (Element filter : filters) {
            if (systemOk && !validateValueSetIncludeFilter(errors, include, stack.push(filter, cf, null, null), system, version)) {
                systemOk = false;
            }
            cf++;
        }
        warning(errors, IssueType.BUSINESSRULE, stack.getLiteralPath(), systemOk, version == null ? I18nConstants.VALUESET_UNC_SYSTEM_WARNING : I18nConstants.VALUESET_UNC_SYSTEM_WARNING_VER);
    } else {
        warning(errors, IssueType.BUSINESSRULE, stack.getLiteralPath(), filters.size() == 0 && concepts.size() == 0, I18nConstants.VALUESET_NO_SYSTEM_WARNING);
    }
}
Also used : Element(org.hl7.fhir.r5.elementmodel.Element) Resource(org.hl7.fhir.r5.model.Resource) ArrayList(java.util.ArrayList) NodeStack(org.hl7.fhir.validation.instance.utils.NodeStack) ValueSet(org.hl7.fhir.r5.model.ValueSet)

Example 45 with NodeStack

use of org.hl7.fhir.validation.instance.utils.NodeStack in project org.hl7.fhir.core by hapifhir.

the class MeasureValidator method validateMeasure.

public void validateMeasure(ValidatorHostContext hostContext, List<ValidationMessage> errors, Element element, NodeStack stack) throws FHIRException {
    MeasureContext mctxt = new MeasureContext();
    List<Element> libs = element.getChildrenByName("library");
    for (Element lib : libs) {
        String ref = lib.isPrimitive() ? lib.primitiveValue() : lib.getChildValue("reference");
        if (!Utilities.noString(ref)) {
            Library l = context.fetchResource(Library.class, ref);
            if (hint(errors, IssueType.NOTFOUND, lib.line(), lib.col(), stack.getLiteralPath(), l != null, I18nConstants.MEASURE_M_LIB_UNKNOWN, ref)) {
                mctxt.seeLibrary(l);
            }
        }
    }
    List<Element> groups = element.getChildrenByName("group");
    if (warning(errors, IssueType.REQUIRED, element.line(), element.col(), stack.getLiteralPath(), groups.size() > 0, I18nConstants.MEASURE_M_NO_GROUPS)) {
        int c = 0;
        for (Element group : groups) {
            NodeStack ns = stack.push(group, c, null, null);
            warning(errors, IssueType.REQUIRED, group.line(), group.col(), ns.getLiteralPath(), groups.size() == 1 || group.hasChild("code"), I18nConstants.MEASURE_M_GROUP_CODE);
            warning(errors, IssueType.REQUIRED, group.line(), group.col(), ns.getLiteralPath(), group.hasChildren("population"), I18nConstants.MEASURE_M_GROUP_POP);
            int c1 = 0;
            List<Element> pl = group.getChildrenByName("population");
            for (Element p : pl) {
                NodeStack ns2 = ns.push(p, c1, null, null);
                warning(errors, IssueType.REQUIRED, p.line(), p.col(), ns2.getLiteralPath(), pl.size() == 1 || p.hasChild("code"), I18nConstants.MEASURE_M_GROUP_POP_NO_CODE);
                c1++;
            }
            c1 = 0;
            List<Element> stl = group.getChildrenByName("stratifier");
            for (Element st : stl) {
                NodeStack ns2 = ns.push(st, c1, null, null);
                warning(errors, IssueType.REQUIRED, st.line(), st.col(), ns2.getLiteralPath(), stl.size() == 1 || st.hasChild("code"), I18nConstants.MEASURE_M_GROUP_STRATA_NO_CODE);
                if (st.hasChild("criteria")) {
                    Element crit = st.getNamedChild("criteria");
                    NodeStack nsc = ns2.push(crit, -1, null, null);
                    validateMeasureCriteria(hostContext, errors, mctxt, crit, nsc);
                }
                int c2 = 0;
                List<Element> cpl = group.getChildrenByName("component");
                for (Element cp : cpl) {
                    NodeStack ns3 = ns2.push(cp, c2, null, null);
                    warning(errors, IssueType.REQUIRED, cp.line(), cp.col(), ns3.getLiteralPath(), cpl.size() == 1 || cp.hasChild("code"), I18nConstants.MEASURE_M_GROUP_STRATA_COMP_NO_CODE);
                    if (cp.hasChild("criteria")) {
                        Element crit = cp.getNamedChild("criteria");
                        NodeStack nsc = ns3.push(crit, -1, null, null);
                        validateMeasureCriteria(hostContext, errors, mctxt, crit, nsc);
                    }
                    c2++;
                }
                c1++;
            }
            c++;
        }
    }
}
Also used : Element(org.hl7.fhir.r5.elementmodel.Element) NodeStack(org.hl7.fhir.validation.instance.utils.NodeStack) Library(org.hl7.fhir.r5.model.Library)

Aggregations

Element (org.hl7.fhir.r5.elementmodel.Element)50 ArrayList (java.util.ArrayList)35 NodeStack (org.hl7.fhir.validation.instance.utils.NodeStack)32 FHIRException (org.hl7.fhir.exceptions.FHIRException)22 IndexedElement (org.hl7.fhir.validation.instance.utils.IndexedElement)22 IOException (java.io.IOException)14 SpecialElement (org.hl7.fhir.r5.elementmodel.Element.SpecialElement)14 NamedElement (org.hl7.fhir.r5.elementmodel.ParserBase.NamedElement)13 DefinitionException (org.hl7.fhir.exceptions.DefinitionException)12 ContactPoint (org.hl7.fhir.r5.model.ContactPoint)12 StructureDefinition (org.hl7.fhir.r5.model.StructureDefinition)12 ValueSet (org.hl7.fhir.r5.model.ValueSet)12 FHIRLexerException (org.hl7.fhir.r5.utils.FHIRLexer.FHIRLexerException)11 NotImplementedException (org.apache.commons.lang3.NotImplementedException)10 PathEngineException (org.hl7.fhir.exceptions.PathEngineException)10 TerminologyServiceException (org.hl7.fhir.exceptions.TerminologyServiceException)10 ValidationResult (org.hl7.fhir.r5.context.IWorkerContext.ValidationResult)10 List (java.util.List)8 CodeSystem (org.hl7.fhir.r5.model.CodeSystem)8 Coding (org.hl7.fhir.r5.model.Coding)8