Search in sources :

Example 26 with NodeStack

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

the class InstanceValidator method findInParams.

private NodeStack findInParams(NodeStack params, String ref) {
    int i = 0;
    for (Element child : params.getElement().getChildren("parameter")) {
        NodeStack p = params.push(child, i, child.getProperty().getDefinition(), child.getProperty().getDefinition());
        if (child.hasChild("resource")) {
            Element res = child.getNamedChild("resource");
            if ((res.fhirType() + "/" + res.getIdBase()).equals(ref)) {
                return p.push(res, -1, res.getProperty().getDefinition(), res.getProperty().getDefinition());
            }
        }
        NodeStack pc = findInParamParts(p, child, ref);
        if (pc != null) {
            return pc;
        }
    }
    return null;
}
Also used : NamedElement(org.hl7.fhir.r5.elementmodel.ParserBase.NamedElement) IndexedElement(org.hl7.fhir.validation.instance.utils.IndexedElement) SpecialElement(org.hl7.fhir.r5.elementmodel.Element.SpecialElement) Element(org.hl7.fhir.r5.elementmodel.Element) NodeStack(org.hl7.fhir.validation.instance.utils.NodeStack) ContactPoint(org.hl7.fhir.r5.model.ContactPoint)

Example 27 with NodeStack

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

the class CodeSystemValidator method metaChecks.

private void metaChecks(List<ValidationMessage> errors, Element cs, NodeStack stack, String url, String content, String caseSensitive, String hierarchyMeaning, boolean isSupplement) {
    if (isSupplement) {
        if (!"supplement".equals(content)) {
            NodeStack s = stack.push(cs.getNamedChild("content"), -1, null, null);
            rule(errors, IssueType.BUSINESSRULE, s.getLiteralPath(), false, I18nConstants.CODESYSTEM_CS_HL7_PRESENT_ELEMENT_SUPPL_WRONG);
        }
        if (!Utilities.noString(caseSensitive)) {
            NodeStack s = stack.push(cs.getNamedChild("caseSensitive"), -1, null, null);
            rule(errors, IssueType.BUSINESSRULE, s.getLiteralPath(), false, I18nConstants.CODESYSTEM_CS_HL7_PRESENT_ELEMENT_SUPPL, "caseSensitive");
        }
        if (!Utilities.noString(hierarchyMeaning)) {
            NodeStack s = stack.push(cs.getNamedChild("hierarchyMeaning"), -1, null, null);
            rule(errors, IssueType.BUSINESSRULE, s.getLiteralPath(), false, I18nConstants.CODESYSTEM_CS_HL7_PRESENT_ELEMENT_SUPPL, "caseSensitive");
        }
    } else {
        boolean isHL7 = url != null && (url.contains("hl7.org") || url.contains("fhir.org"));
        if (Utilities.noString(content)) {
            NodeStack s = stack;
            Element c = cs.getNamedChild("content");
            if (c != null) {
                s = stack.push(c, -1, null, null);
            }
            if (isHL7) {
                rule(errors, IssueType.BUSINESSRULE, s.getLiteralPath(), false, I18nConstants.CODESYSTEM_CS_HL7_MISSING_ELEMENT_SHALL, "content");
            } else {
                warning(errors, IssueType.BUSINESSRULE, s.getLiteralPath(), false, I18nConstants.CODESYSTEM_CS_NONHL7_MISSING_ELEMENT, "content");
            }
        } else if ("supplement".equals(content)) {
            NodeStack s = stack.push(cs.getNamedChild("content"), -1, null, null);
            rule(errors, IssueType.BUSINESSRULE, s.getLiteralPath(), false, I18nConstants.CODESYSTEM_CS_HL7_PRESENT_ELEMENT_SUPPL_MISSING);
        }
        if (Utilities.noString(caseSensitive)) {
            NodeStack s = stack;
            Element c = cs.getNamedChild("caseSensitive");
            if (c != null) {
                s = stack.push(c, -1, null, null);
            }
            if (isHL7) {
                warning(errors, IssueType.BUSINESSRULE, s.getLiteralPath(), false, I18nConstants.CODESYSTEM_CS_HL7_MISSING_ELEMENT_SHOULD, "caseSensitive");
            } else {
                hint(errors, IssueType.BUSINESSRULE, s.getLiteralPath(), false, I18nConstants.CODESYSTEM_CS_NONHL7_MISSING_ELEMENT, "caseSensitive");
            }
        }
        if (Utilities.noString(hierarchyMeaning) && hasHeirarchy(cs)) {
            NodeStack s = stack;
            Element c = cs.getNamedChild("hierarchyMeaning");
            if (c != null) {
                s = stack.push(c, -1, null, null);
            }
            if (isHL7) {
                warning(errors, IssueType.BUSINESSRULE, s.getLiteralPath(), false, I18nConstants.CODESYSTEM_CS_HL7_MISSING_ELEMENT_SHOULD, "hierarchyMeaning");
            } else {
                hint(errors, IssueType.BUSINESSRULE, s.getLiteralPath(), false, I18nConstants.CODESYSTEM_CS_NONHL7_MISSING_ELEMENT, "hierarchyMeaning");
            }
        }
    }
}
Also used : Element(org.hl7.fhir.r5.elementmodel.Element) NodeStack(org.hl7.fhir.validation.instance.utils.NodeStack)

Example 28 with NodeStack

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

the class MeasureValidator method validateMeasureCriteria.

private void validateMeasureCriteria(ValidatorHostContext hostContext, List<ValidationMessage> errors, MeasureContext mctxt, Element crit, NodeStack nsc) {
    String mimeType = crit.getChildValue("language");
    if (!Utilities.noString(mimeType)) {
        // that would be an error elsewhere
        if ("text/cql".equals(mimeType) || "text/cql.identifier".equals(mimeType)) {
            String cqlRef = crit.getChildValue("expression");
            Library lib = null;
            if (rule(errors, IssueType.INVALID, crit.line(), crit.col(), nsc.getLiteralPath(), mctxt.libraries().size() > 0, I18nConstants.MEASURE_M_CRITERIA_CQL_NO_LIB)) {
                if (cqlRef.contains(".")) {
                    String name = cqlRef.substring(0, cqlRef.indexOf("."));
                    cqlRef = cqlRef.substring(cqlRef.indexOf(".") + 1);
                    for (Library l : mctxt.libraries()) {
                        if (name.equals(l.getName())) {
                            if (rule(errors, IssueType.INVALID, crit.line(), crit.col(), nsc.getLiteralPath(), lib == null, I18nConstants.MEASURE_M_CRITERIA_CQL_LIB_DUPL)) {
                                lib = l;
                            }
                        }
                    }
                    rule(errors, IssueType.INVALID, crit.line(), crit.col(), nsc.getLiteralPath(), lib != null, I18nConstants.MEASURE_M_CRITERIA_CQL_LIB_NOT_FOUND, name);
                } else {
                    if (rule(errors, IssueType.INVALID, crit.line(), crit.col(), nsc.getLiteralPath(), mctxt.libraries().size() == 1, I18nConstants.MEASURE_M_CRITERIA_CQL_ONLY_ONE_LIB)) {
                        lib = mctxt.libraries().get(0);
                    }
                }
            }
            if (lib != null) {
                if (rule(errors, IssueType.INVALID, crit.line(), crit.col(), nsc.getLiteralPath(), lib.hasUserData(MeasureContext.USER_DATA_ELM), I18nConstants.MEASURE_M_CRITERIA_CQL_NO_ELM, lib.getUrl())) {
                    if (lib.getUserData(MeasureContext.USER_DATA_ELM) instanceof String) {
                        rule(errors, IssueType.INVALID, crit.line(), crit.col(), nsc.getLiteralPath(), false, I18nConstants.MEASURE_M_CRITERIA_CQL_ERROR, lib.getUrl(), lib.getUserString(MeasureContext.USER_DATA_ELM));
                    } else if (lib.getUserData(MeasureContext.USER_DATA_ELM) instanceof Document) {
                        org.w3c.dom.Element elm = ((Document) lib.getUserData(MeasureContext.USER_DATA_ELM)).getDocumentElement();
                        if (rule(errors, IssueType.INVALID, crit.line(), crit.col(), nsc.getLiteralPath(), isValidElm(elm), I18nConstants.MEASURE_M_CRITERIA_CQL_ELM_NOT_VALID, lib.getUrl(), cqlRef)) {
                            rule(errors, IssueType.INVALID, crit.line(), crit.col(), nsc.getLiteralPath(), hasCqlTarget(elm, cqlRef), I18nConstants.MEASURE_M_CRITERIA_CQL_NOT_FOUND, lib.getUrl(), cqlRef);
                        }
                    }
                }
            }
        } else if ("text/fhirpath".equals(mimeType)) {
            warning(errors, IssueType.REQUIRED, crit.line(), crit.col(), nsc.getLiteralPath(), false, I18nConstants.MEASURE_M_CRITERIA_UNKNOWN, mimeType);
        } else if ("application/x-fhir-query".equals(mimeType)) {
            warning(errors, IssueType.REQUIRED, crit.line(), crit.col(), nsc.getLiteralPath(), false, I18nConstants.MEASURE_M_CRITERIA_UNKNOWN, mimeType);
        } else {
            warning(errors, IssueType.REQUIRED, crit.line(), crit.col(), nsc.getLiteralPath(), false, I18nConstants.MEASURE_M_CRITERIA_UNKNOWN, mimeType);
        }
    }
}
Also used : Element(org.hl7.fhir.r5.elementmodel.Element) Library(org.hl7.fhir.r5.model.Library) Document(org.w3c.dom.Document)

Example 29 with NodeStack

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

the class BundleValidator method checkSearchSet.

private void checkSearchSet(List<ValidationMessage> errors, Element bundle, List<Element> entries, NodeStack stack) {
    // warning: should have self link
    List<Element> links = new ArrayList<Element>();
    bundle.getNamedChildren(LINK, links);
    Element selfLink = getSelfLink(links);
    List<String> types = new ArrayList<>();
    if (selfLink == null) {
        warning(errors, IssueType.INVALID, bundle.line(), bundle.col(), stack.getLiteralPath(), false, I18nConstants.BUNDLE_SEARCH_NOSELF);
    } else {
        readSearchResourceTypes(selfLink.getNamedChildValue("url"), types);
        if (types.size() == 0) {
            hint(errors, IssueType.INVALID, bundle.line(), bundle.col(), stack.getLiteralPath(), false, I18nConstants.BUNDLE_SEARCH_SELF_NOT_UNDERSTOOD);
        }
    }
    Boolean searchMode = readHasSearchMode(entries);
    if (searchMode != null && searchMode == false) {
        // if no resources have search mode
        boolean typeProblem = false;
        String rtype = null;
        int count = 0;
        for (Element entry : entries) {
            NodeStack estack = stack.push(entry, count, null, null);
            count++;
            Element res = entry.getNamedChild("resource");
            if (rule(errors, IssueType.INVALID, bundle.line(), bundle.col(), estack.getLiteralPath(), res != null, I18nConstants.BUNDLE_SEARCH_ENTRY_NO_RESOURCE)) {
                NodeStack rstack = estack.push(res, -1, null, null);
                String rt = res.fhirType();
                Boolean ok = checkSearchType(types, rt);
                if (ok == null) {
                    typeProblem = true;
                    hint(errors, IssueType.INVALID, bundle.line(), bundle.col(), rstack.getLiteralPath(), selfLink == null, I18nConstants.BUNDLE_SEARCH_ENTRY_TYPE_NOT_SURE);
                    String id = res.getNamedChildValue("id");
                    warning(errors, IssueType.INVALID, bundle.line(), bundle.col(), rstack.getLiteralPath(), id != null || "OperationOutcome".equals(rt), I18nConstants.BUNDLE_SEARCH_ENTRY_NO_RESOURCE_ID);
                } else if (ok) {
                    if (!"OperationOutcome".equals(rt)) {
                        String id = res.getNamedChildValue("id");
                        warning(errors, IssueType.INVALID, bundle.line(), bundle.col(), rstack.getLiteralPath(), id != null, I18nConstants.BUNDLE_SEARCH_ENTRY_NO_RESOURCE_ID);
                        if (rtype != null && !rt.equals(rtype)) {
                            typeProblem = true;
                        } else if (rtype == null) {
                            rtype = rt;
                        }
                    }
                } else {
                    typeProblem = true;
                    warning(errors, IssueType.INVALID, bundle.line(), bundle.col(), estack.getLiteralPath(), false, I18nConstants.BUNDLE_SEARCH_ENTRY_WRONG_RESOURCE_TYPE_NO_MODE, rt, types);
                }
            }
        }
        if (typeProblem) {
            warning(errors, IssueType.INVALID, bundle.line(), bundle.col(), stack.getLiteralPath(), !typeProblem, I18nConstants.BUNDLE_SEARCH_NO_MODE);
        } else {
            hint(errors, IssueType.INVALID, bundle.line(), bundle.col(), stack.getLiteralPath(), !typeProblem, I18nConstants.BUNDLE_SEARCH_NO_MODE);
        }
    } else {
        int count = 0;
        for (Element entry : entries) {
            NodeStack estack = stack.push(entry, count, null, null);
            count++;
            Element res = entry.getNamedChild("resource");
            String sm = null;
            Element s = entry.getNamedChild("search");
            if (s != null) {
                sm = s.getNamedChildValue("mode");
            }
            warning(errors, IssueType.INVALID, bundle.line(), bundle.col(), estack.getLiteralPath(), sm != null, I18nConstants.BUNDLE_SEARCH_NO_MODE);
            if (rule(errors, IssueType.INVALID, bundle.line(), bundle.col(), estack.getLiteralPath(), res != null, I18nConstants.BUNDLE_SEARCH_ENTRY_NO_RESOURCE)) {
                NodeStack rstack = estack.push(res, -1, null, null);
                String rt = res.fhirType();
                String id = res.getNamedChildValue("id");
                if (sm != null) {
                    if ("match".equals(sm)) {
                        rule(errors, IssueType.INVALID, bundle.line(), bundle.col(), rstack.getLiteralPath(), id != null, I18nConstants.BUNDLE_SEARCH_ENTRY_NO_RESOURCE_ID);
                        rule(errors, IssueType.INVALID, bundle.line(), bundle.col(), rstack.getLiteralPath(), types.size() == 0 || checkSearchType(types, rt), I18nConstants.BUNDLE_SEARCH_ENTRY_WRONG_RESOURCE_TYPE_MODE, rt, types);
                    } else if ("include".equals(sm)) {
                        rule(errors, IssueType.INVALID, bundle.line(), bundle.col(), rstack.getLiteralPath(), id != null, I18nConstants.BUNDLE_SEARCH_ENTRY_NO_RESOURCE_ID);
                    } else {
                        // outcome
                        rule(errors, IssueType.INVALID, bundle.line(), bundle.col(), rstack.getLiteralPath(), "OperationOutcome".equals(rt), I18nConstants.BUNDLE_SEARCH_ENTRY_WRONG_RESOURCE_TYPE_OUTCOME, rt);
                    }
                }
            }
        }
    }
}
Also used : IndexedElement(org.hl7.fhir.validation.instance.utils.IndexedElement) Element(org.hl7.fhir.r5.elementmodel.Element) ArrayList(java.util.ArrayList) NodeStack(org.hl7.fhir.validation.instance.utils.NodeStack)

Example 30 with NodeStack

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

the class BundleValidator method validateBundleReference.

private void validateBundleReference(List<ValidationMessage> errors, List<Element> entries, Element ref, String name, NodeStack stack, String fullUrl, String type, String id) {
    String reference = null;
    try {
        reference = ref.getNamedChildValue("reference");
    } catch (Error e) {
    }
    if (ref != null && !Utilities.noString(reference) && !reference.startsWith("#")) {
        Element target = resolveInBundle(entries, reference, fullUrl, type, id);
        rule(errors, IssueType.INVALID, ref.line(), ref.col(), stack.addToLiteralPath("reference"), target != null, I18nConstants.BUNDLE_BUNDLE_ENTRY_NOTFOUND, reference, name);
    }
}
Also used : IndexedElement(org.hl7.fhir.validation.instance.utils.IndexedElement) Element(org.hl7.fhir.r5.elementmodel.Element)

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