Search in sources :

Example 1 with NodeStack

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

the class InstanceValidator method validateResourceRules.

private void validateResourceRules(List<ValidationMessage> errors, Element element, NodeStack stack) {
    String lang = element.getNamedChildValue("language");
    Element text = element.getNamedChild("text");
    if (text != null) {
        Element div = text.getNamedChild("div");
        if (lang != null && div != null) {
            XhtmlNode xhtml = div.getXhtml();
            String l = xhtml.getAttribute("lang");
            String xl = xhtml.getAttribute("xml:lang");
            if (l == null && xl == null) {
                warning(errors, IssueType.BUSINESSRULE, div.line(), div.col(), stack.getLiteralPath(), false, I18nConstants.LANGUAGE_XHTML_LANG_MISSING1);
            } else {
                if (l == null) {
                    warning(errors, IssueType.BUSINESSRULE, div.line(), div.col(), stack.getLiteralPath(), false, I18nConstants.LANGUAGE_XHTML_LANG_MISSING2);
                } else if (!l.equals(lang)) {
                    warning(errors, IssueType.BUSINESSRULE, div.line(), div.col(), stack.getLiteralPath(), false, I18nConstants.LANGUAGE_XHTML_LANG_DIFFERENT1, lang, l);
                }
                if (xl == null) {
                    warning(errors, IssueType.BUSINESSRULE, div.line(), div.col(), stack.getLiteralPath(), false, I18nConstants.LANGUAGE_XHTML_LANG_MISSING3);
                } else if (!xl.equals(lang)) {
                    warning(errors, IssueType.BUSINESSRULE, div.line(), div.col(), stack.getLiteralPath(), false, I18nConstants.LANGUAGE_XHTML_LANG_DIFFERENT2, lang, xl);
                }
            }
        }
    }
    // security tags are a set (system|code)
    Element meta = element.getNamedChild(META);
    if (meta != null) {
        Set<String> tags = new HashSet<>();
        List<Element> list = new ArrayList<>();
        meta.getNamedChildren("security", list);
        int i = 0;
        for (Element e : list) {
            String s = e.getNamedChildValue("system") + "#" + e.getNamedChildValue("code");
            rule(errors, IssueType.BUSINESSRULE, e.line(), e.col(), stack.getLiteralPath() + ".meta.profile[" + Integer.toString(i) + "]", !tags.contains(s), I18nConstants.META_RES_SECURITY_DUPLICATE, s);
            tags.add(s);
            i++;
        }
    }
}
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) ArrayList(java.util.ArrayList) ContactPoint(org.hl7.fhir.r5.model.ContactPoint) XhtmlNode(org.hl7.fhir.utilities.xhtml.XhtmlNode) HashSet(java.util.HashSet)

Example 2 with NodeStack

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

the class InstanceValidator method checkCodeableConcept.

private boolean checkCodeableConcept(List<ValidationMessage> errors, String path, Element element, StructureDefinition profile, ElementDefinition theElementCntext, NodeStack stack) {
    boolean res = true;
    if (!noTerminologyChecks && theElementCntext != null && theElementCntext.hasBinding()) {
        ElementDefinitionBindingComponent binding = theElementCntext.getBinding();
        if (warning(errors, IssueType.CODEINVALID, element.line(), element.col(), path, binding != null, I18nConstants.TERMINOLOGY_TX_BINDING_MISSING, path)) {
            if (binding.hasValueSet()) {
                ValueSet valueset = resolveBindingReference(profile, binding.getValueSet(), profile.getUrl());
                if (valueset == null) {
                    CodeSystem cs = context.fetchCodeSystem(binding.getValueSet());
                    if (rule(errors, IssueType.CODEINVALID, element.line(), element.col(), path, cs == null, I18nConstants.TERMINOLOGY_TX_VALUESET_NOTFOUND_CS, describeReference(binding.getValueSet()))) {
                        warning(errors, IssueType.CODEINVALID, element.line(), element.col(), path, valueset != null, I18nConstants.TERMINOLOGY_TX_VALUESET_NOTFOUND, describeReference(binding.getValueSet()));
                    }
                } else {
                    try {
                        CodeableConcept cc = ObjectConverter.readAsCodeableConcept(element);
                        if (!cc.hasCoding()) {
                            if (binding.getStrength() == BindingStrength.REQUIRED)
                                rule(errors, IssueType.CODEINVALID, element.line(), element.col(), path, false, I18nConstants.TERMINOLOGY_TX_CODE_VALUESET, describeValueSet(binding.getValueSet()));
                            else if (binding.getStrength() == BindingStrength.EXTENSIBLE) {
                                if (binding.hasExtension("http://hl7.org/fhir/StructureDefinition/elementdefinition-maxValueSet"))
                                    rule(errors, IssueType.CODEINVALID, element.line(), element.col(), path, false, I18nConstants.TERMINOLOGY_TX_CODE_VALUESETMAX, describeReference(ToolingExtensions.readStringExtension(binding, "http://hl7.org/fhir/StructureDefinition/elementdefinition-maxValueSet")), valueset.getUrl());
                                else
                                    warning(errors, IssueType.CODEINVALID, element.line(), element.col(), path, false, I18nConstants.TERMINOLOGY_TX_CODE_VALUESET_EXT, describeValueSet(binding.getValueSet()));
                            }
                        } else {
                            long t = System.nanoTime();
                            // Check whether the codes are appropriate for the type of binding we have
                            boolean bindingsOk = true;
                            if (binding.getStrength() != BindingStrength.EXAMPLE) {
                                if (binding.getStrength() == BindingStrength.REQUIRED) {
                                    removeTrackedMessagesForLocation(errors, element, path);
                                }
                                boolean atLeastOneSystemIsSupported = false;
                                for (Coding nextCoding : cc.getCoding()) {
                                    String nextSystem = nextCoding.getSystem();
                                    if (isNotBlank(nextSystem) && context.supportsSystem(nextSystem)) {
                                        atLeastOneSystemIsSupported = true;
                                        break;
                                    }
                                }
                                if (!atLeastOneSystemIsSupported && binding.getStrength() == BindingStrength.EXAMPLE) {
                                // ignore this since we can't validate but it doesn't matter..
                                } else {
                                    // we're going to validate the codings directly, so only check the valueset
                                    ValidationResult vr = checkCodeOnServer(stack, valueset, cc, true);
                                    if (!vr.isOk()) {
                                        bindingsOk = false;
                                        if (vr.getErrorClass() != null && vr.getErrorClass() == TerminologyServiceErrorClass.NOSERVICE) {
                                            if (binding.getStrength() == BindingStrength.REQUIRED || (binding.getStrength() == BindingStrength.EXTENSIBLE && binding.hasExtension("http://hl7.org/fhir/StructureDefinition/elementdefinition-maxValueSet"))) {
                                                hint(errors, IssueType.CODEINVALID, element.line(), element.col(), path, false, I18nConstants.TERMINOLOGY_TX_NOSVC_BOUND_REQ, describeReference(binding.getValueSet()));
                                            } else if (binding.getStrength() == BindingStrength.EXTENSIBLE) {
                                                hint(errors, IssueType.CODEINVALID, element.line(), element.col(), path, false, I18nConstants.TERMINOLOGY_TX_NOSVC_BOUND_EXT, describeReference(binding.getValueSet()));
                                            }
                                        } else if (vr.getErrorClass() != null && vr.getErrorClass().isInfrastructure()) {
                                            if (binding.getStrength() == BindingStrength.REQUIRED)
                                                txWarning(errors, vr.getTxLink(), IssueType.CODEINVALID, element.line(), element.col(), path, false, I18nConstants.TERMINOLOGY_TX_CONFIRM_1_CC, describeReference(binding.getValueSet()), vr.getErrorClass().toString());
                                            else if (binding.getStrength() == BindingStrength.EXTENSIBLE) {
                                                if (binding.hasExtension("http://hl7.org/fhir/StructureDefinition/elementdefinition-maxValueSet"))
                                                    checkMaxValueSet(errors, path, element, profile, ToolingExtensions.readStringExtension(binding, "http://hl7.org/fhir/StructureDefinition/elementdefinition-maxValueSet"), cc, stack);
                                                else if (!noExtensibleWarnings)
                                                    txWarningForLaterRemoval(element, errors, vr.getTxLink(), IssueType.CODEINVALID, element.line(), element.col(), path, false, I18nConstants.TERMINOLOGY_TX_CONFIRM_2_CC, describeReference(binding.getValueSet()), vr.getErrorClass().toString());
                                            } else if (binding.getStrength() == BindingStrength.PREFERRED) {
                                                if (baseOnly) {
                                                    txHint(errors, vr.getTxLink(), IssueType.CODEINVALID, element.line(), element.col(), path, false, I18nConstants.TERMINOLOGY_TX_CONFIRM_3_CC, describeReference(binding.getValueSet()), vr.getErrorClass().toString());
                                                }
                                            }
                                        } else {
                                            if (binding.getStrength() == BindingStrength.REQUIRED) {
                                                txRule(errors, vr.getTxLink(), IssueType.CODEINVALID, element.line(), element.col(), path, false, I18nConstants.TERMINOLOGY_TX_NOVALID_1_CC, describeValueSet(binding.getValueSet()), ccSummary(cc));
                                            } else if (binding.getStrength() == BindingStrength.EXTENSIBLE) {
                                                if (binding.hasExtension("http://hl7.org/fhir/StructureDefinition/elementdefinition-maxValueSet"))
                                                    checkMaxValueSet(errors, path, element, profile, ToolingExtensions.readStringExtension(binding, "http://hl7.org/fhir/StructureDefinition/elementdefinition-maxValueSet"), cc, stack);
                                                if (!noExtensibleWarnings)
                                                    txWarningForLaterRemoval(element, errors, vr.getTxLink(), IssueType.CODEINVALID, element.line(), element.col(), path, false, I18nConstants.TERMINOLOGY_TX_NOVALID_2_CC, describeValueSet(binding.getValueSet()), ccSummary(cc));
                                            } else if (binding.getStrength() == BindingStrength.PREFERRED) {
                                                if (baseOnly) {
                                                    txHint(errors, vr.getTxLink(), IssueType.CODEINVALID, element.line(), element.col(), path, false, I18nConstants.TERMINOLOGY_TX_NOVALID_3_CC, describeValueSet(binding.getValueSet()), ccSummary(cc));
                                                }
                                            }
                                        }
                                    } else if (vr.getMessage() != null) {
                                        res = false;
                                        txWarning(errors, vr.getTxLink(), IssueType.CODEINVALID, element.line(), element.col(), path, false, vr.getMessage());
                                    } else {
                                        if (binding.getStrength() == BindingStrength.EXTENSIBLE) {
                                            removeTrackedMessagesForLocation(errors, element, path);
                                        }
                                        res = false;
                                    }
                                }
                                // to validate, we'll validate that the codes actually exist
                                if (bindingsOk) {
                                    for (Coding nextCoding : cc.getCoding()) {
                                        checkBindings(errors, path, element, stack, valueset, nextCoding);
                                    }
                                }
                                timeTracker.tx(t, "vc " + DataRenderer.display(context, cc));
                            }
                        }
                    } catch (Exception e) {
                        if (STACK_TRACE)
                            e.printStackTrace();
                        warning(errors, IssueType.CODEINVALID, element.line(), element.col(), path, false, I18nConstants.TERMINOLOGY_TX_ERROR_CODEABLECONCEPT, e.getMessage());
                    }
                }
            } else if (binding.hasValueSet()) {
                hint(errors, IssueType.CODEINVALID, element.line(), element.col(), path, false, I18nConstants.TERMINOLOGY_TX_BINDING_CANTCHECK);
            } else if (!noBindingMsgSuppressed) {
                hint(errors, IssueType.CODEINVALID, element.line(), element.col(), path, false, I18nConstants.TERMINOLOGY_TX_BINDING_NOSOURCE, path);
            }
        }
    }
    return res;
}
Also used : Coding(org.hl7.fhir.r5.model.Coding) ValidationResult(org.hl7.fhir.r5.context.IWorkerContext.ValidationResult) ElementDefinitionBindingComponent(org.hl7.fhir.r5.model.ElementDefinition.ElementDefinitionBindingComponent) ValueSet(org.hl7.fhir.r5.model.ValueSet) CodeSystem(org.hl7.fhir.r5.model.CodeSystem) TerminologyServiceException(org.hl7.fhir.exceptions.TerminologyServiceException) DefinitionException(org.hl7.fhir.exceptions.DefinitionException) IOException(java.io.IOException) FHIRException(org.hl7.fhir.exceptions.FHIRException) NotImplementedException(org.apache.commons.lang3.NotImplementedException) PathEngineException(org.hl7.fhir.exceptions.PathEngineException) FHIRLexerException(org.hl7.fhir.r5.utils.FHIRLexer.FHIRLexerException) CodeableConcept(org.hl7.fhir.r5.model.CodeableConcept)

Example 3 with NodeStack

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

the class InstanceValidator method findInParamParts.

private NodeStack findInParamParts(NodeStack pp, Element param, String ref) {
    int i = 0;
    for (Element child : param.getChildren("part")) {
        NodeStack p = pp.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 4 with NodeStack

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

the class InstanceValidator method getValueForDiscriminator.

private Element getValueForDiscriminator(Object appContext, List<ValidationMessage> errors, Element element, String discriminator, ElementDefinition criteria, NodeStack stack) throws FHIRException, IOException {
    String p = stack.getLiteralPath() + "." + element.getName();
    Element focus = element;
    String[] dlist = discriminator.split("\\.");
    for (String d : dlist) {
        if (focus.fhirType().equals("Reference") && d.equals("reference")) {
            String url = focus.getChildValue("reference");
            if (Utilities.noString(url))
                throw new FHIRException(context.formatMessage(I18nConstants.NO_REFERENCE_RESOLVING_DISCRIMINATOR__FROM_, discriminator, element.getProperty().getName()));
            // Note that we use the passed in stack here. This might be a problem if the discriminator is deep enough?
            Element target = resolve(appContext, url, stack, errors, p);
            if (target == null)
                throw new FHIRException(context.formatMessage(I18nConstants.UNABLE_TO_FIND_RESOURCE__AT__RESOLVING_DISCRIMINATOR__FROM_, url, d, discriminator, element.getProperty().getName()));
            focus = target;
        } else if (d.equals("value") && focus.isPrimitive()) {
            return focus;
        } else {
            List<Element> children = focus.getChildren(d);
            if (children.isEmpty())
                throw new FHIRException(context.formatMessage(I18nConstants.UNABLE_TO_FIND__RESOLVING_DISCRIMINATOR__FROM_, d, discriminator, element.getProperty().getName()));
            if (children.size() > 1)
                throw new FHIRException(context.formatMessage(I18nConstants.FOUND__ITEMS_FOR__RESOLVING_DISCRIMINATOR__FROM_, Integer.toString(children.size()), d, discriminator, element.getProperty().getName()));
            focus = children.get(0);
            p = p + "." + d;
        }
    }
    return focus;
}
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) ArrayList(java.util.ArrayList) List(java.util.List) FHIRException(org.hl7.fhir.exceptions.FHIRException)

Example 5 with NodeStack

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

the class InstanceValidator method sliceMatches.

/**
 * @param element - the candidate that might be in the slice
 * @param path    - for reporting any errors. the XPath for the element
 * @param slicer  - the definition of how slicing is determined
 * @param ed      - the slice for which to test membership
 * @param errors
 * @param stack
 * @param srcProfile
 * @return
 * @throws DefinitionException
 * @throws DefinitionException
 * @throws IOException
 * @throws FHIRException
 */
private boolean sliceMatches(ValidatorHostContext hostContext, Element element, String path, ElementDefinition slicer, ElementDefinition ed, StructureDefinition profile, List<ValidationMessage> errors, List<ValidationMessage> sliceInfo, NodeStack stack, StructureDefinition srcProfile) throws DefinitionException, FHIRException {
    if (!slicer.getSlicing().hasDiscriminator())
        // cannot validate in this case
        return false;
    ExpressionNode n = (ExpressionNode) ed.getUserData("slice.expression.cache");
    if (n == null) {
        long t = System.nanoTime();
        // GG: this approach is flawed because it treats discriminators individually rather than collectively
        StringBuilder expression = new StringBuilder("true");
        boolean anyFound = false;
        Set<String> discriminators = new HashSet<>();
        for (ElementDefinitionSlicingDiscriminatorComponent s : slicer.getSlicing().getDiscriminator()) {
            String discriminator = s.getPath();
            discriminators.add(discriminator);
            List<ElementDefinition> criteriaElements = getCriteriaForDiscriminator(path, ed, discriminator, profile, s.getType() == DiscriminatorType.PROFILE, srcProfile);
            boolean found = false;
            for (ElementDefinition criteriaElement : criteriaElements) {
                found = true;
                if (s.getType() == DiscriminatorType.TYPE) {
                    String type = null;
                    if (!criteriaElement.getPath().contains("[") && discriminator.contains("[")) {
                        discriminator = discriminator.substring(0, discriminator.indexOf('['));
                        String lastNode = tail(discriminator);
                        type = tail(criteriaElement.getPath()).substring(lastNode.length());
                        type = type.substring(0, 1).toLowerCase() + type.substring(1);
                    } else if (!criteriaElement.hasType() || criteriaElement.getType().size() == 1) {
                        if (discriminator.contains("["))
                            discriminator = discriminator.substring(0, discriminator.indexOf('['));
                        if (criteriaElement.hasType()) {
                            type = criteriaElement.getType().get(0).getWorkingCode();
                        } else if (!criteriaElement.getPath().contains(".")) {
                            type = criteriaElement.getPath();
                        } else {
                            throw new DefinitionException(context.formatMessage(I18nConstants.DISCRIMINATOR__IS_BASED_ON_TYPE_BUT_SLICE__IN__HAS_NO_TYPES, discriminator, ed.getId(), profile.getUrl()));
                        }
                    } else if (criteriaElement.getType().size() > 1) {
                        throw new DefinitionException(context.formatMessage(I18nConstants.DISCRIMINATOR__IS_BASED_ON_TYPE_BUT_SLICE__IN__HAS_MULTIPLE_TYPES_, discriminator, ed.getId(), profile.getUrl(), criteriaElement.typeSummary()));
                    } else
                        throw new DefinitionException(context.formatMessage(I18nConstants.DISCRIMINATOR__IS_BASED_ON_TYPE_BUT_SLICE__IN__HAS_NO_TYPES, discriminator, ed.getId(), profile.getUrl()));
                    if (discriminator.isEmpty())
                        expression.append(" and $this is " + type);
                    else
                        expression.append(" and " + discriminator + " is " + type);
                } else if (s.getType() == DiscriminatorType.PROFILE) {
                    if (criteriaElement.getType().size() == 0) {
                        throw new DefinitionException(context.formatMessage(I18nConstants.PROFILE_BASED_DISCRIMINATORS_MUST_HAVE_A_TYPE__IN_PROFILE_, criteriaElement.getId(), profile.getUrl()));
                    }
                    if (criteriaElement.getType().size() != 1) {
                        throw new DefinitionException(context.formatMessage(I18nConstants.PROFILE_BASED_DISCRIMINATORS_MUST_HAVE_ONLY_ONE_TYPE__IN_PROFILE_, criteriaElement.getId(), profile.getUrl()));
                    }
                    List<CanonicalType> list = discriminator.endsWith(".resolve()") || discriminator.equals("resolve()") ? criteriaElement.getType().get(0).getTargetProfile() : criteriaElement.getType().get(0).getProfile();
                    if (list.size() == 0) {
                        throw new DefinitionException(context.formatMessage(I18nConstants.PROFILE_BASED_DISCRIMINATORS_MUST_HAVE_A_TYPE_WITH_A_PROFILE__IN_PROFILE_, criteriaElement.getId(), profile.getUrl()));
                    } else if (list.size() > 1) {
                        CommaSeparatedStringBuilder b = new CommaSeparatedStringBuilder(" or ");
                        for (CanonicalType c : list) {
                            b.append(discriminator + ".conformsTo('" + c.getValue() + "')");
                        }
                        expression.append(" and (" + b + ")");
                    } else {
                        expression.append(" and " + discriminator + ".conformsTo('" + list.get(0).getValue() + "')");
                    }
                } else if (s.getType() == DiscriminatorType.EXISTS) {
                    if (criteriaElement.hasMin() && criteriaElement.getMin() >= 1)
                        expression.append(" and (" + discriminator + ".exists())");
                    else if (criteriaElement.hasMax() && criteriaElement.getMax().equals("0"))
                        expression.append(" and (" + discriminator + ".exists().not())");
                    else
                        throw new FHIRException(context.formatMessage(I18nConstants.DISCRIMINATOR__IS_BASED_ON_ELEMENT_EXISTENCE_BUT_SLICE__NEITHER_SETS_MIN1_OR_MAX0, discriminator, ed.getId()));
                } else if (criteriaElement.hasFixed()) {
                    buildFixedExpression(ed, expression, discriminator, criteriaElement);
                } else if (criteriaElement.hasPattern()) {
                    buildPattternExpression(ed, expression, discriminator, criteriaElement);
                } else if (criteriaElement.hasBinding() && criteriaElement.getBinding().hasStrength() && criteriaElement.getBinding().getStrength().equals(BindingStrength.REQUIRED) && criteriaElement.getBinding().hasValueSet()) {
                    expression.append(" and (" + discriminator + " memberOf '" + criteriaElement.getBinding().getValueSet() + "')");
                } else {
                    found = false;
                }
                if (found)
                    break;
            }
            if (found)
                anyFound = true;
        }
        if (!anyFound) {
            if (slicer.getSlicing().getDiscriminator().size() > 1)
                throw new DefinitionException(context.formatMessage(I18nConstants.COULD_NOT_MATCH_ANY_DISCRIMINATORS__FOR_SLICE__IN_PROFILE___NONE_OF_THE_DISCRIMINATOR__HAVE_FIXED_VALUE_BINDING_OR_EXISTENCE_ASSERTIONS, discriminators, ed.getId(), profile.getUrl(), discriminators));
            else
                throw new DefinitionException(context.formatMessage(I18nConstants.COULD_NOT_MATCH_DISCRIMINATOR__FOR_SLICE__IN_PROFILE___THE_DISCRIMINATOR__DOES_NOT_HAVE_FIXED_VALUE_BINDING_OR_EXISTENCE_ASSERTIONS, discriminators, ed.getId(), profile.getUrl(), discriminators));
        }
        try {
            n = fpe.parse(fixExpr(expression.toString(), null));
        } catch (FHIRLexerException e) {
            if (STACK_TRACE)
                e.printStackTrace();
            throw new FHIRException(context.formatMessage(I18nConstants.PROBLEM_PROCESSING_EXPRESSION__IN_PROFILE__PATH__, expression, profile.getUrl(), path, e.getMessage()));
        }
        timeTracker.fpe(t);
        ed.setUserData("slice.expression.cache", n);
    }
    ValidatorHostContext shc = hostContext.forSlicing();
    boolean pass = evaluateSlicingExpression(shc, element, path, profile, n);
    if (!pass) {
        slicingHint(sliceInfo, IssueType.STRUCTURE, element.line(), element.col(), path, false, isProfile(slicer), (context.formatMessage(I18nConstants.DOES_NOT_MATCH_SLICE_, ed.getSliceName())), "discriminator = " + Utilities.escapeXml(n.toString()), null);
        for (String url : shc.getSliceRecords().keySet()) {
            slicingHint(sliceInfo, IssueType.STRUCTURE, element.line(), element.col(), path, false, isProfile(slicer), context.formatMessage(I18nConstants.DETAILS_FOR__MATCHING_AGAINST_PROFILE_, stack.getLiteralPath(), url), context.formatMessage(I18nConstants.PROFILE__DOES_NOT_MATCH_FOR__BECAUSE_OF_THE_FOLLOWING_PROFILE_ISSUES__, url, stack.getLiteralPath(), errorSummaryForSlicingAsHtml(shc.getSliceRecords().get(url))), errorSummaryForSlicingAsText(shc.getSliceRecords().get(url)));
        }
    }
    return pass;
}
Also used : CommaSeparatedStringBuilder(org.hl7.fhir.utilities.CommaSeparatedStringBuilder) FHIRLexerException(org.hl7.fhir.r5.utils.FHIRLexer.FHIRLexerException) CommaSeparatedStringBuilder(org.hl7.fhir.utilities.CommaSeparatedStringBuilder) CanonicalType(org.hl7.fhir.r5.model.CanonicalType) FHIRException(org.hl7.fhir.exceptions.FHIRException) ElementDefinitionSlicingDiscriminatorComponent(org.hl7.fhir.r5.model.ElementDefinition.ElementDefinitionSlicingDiscriminatorComponent) ExpressionNode(org.hl7.fhir.r5.model.ExpressionNode) ValidatorHostContext(org.hl7.fhir.validation.instance.utils.ValidatorHostContext) ArrayList(java.util.ArrayList) List(java.util.List) TypedElementDefinition(org.hl7.fhir.r5.utils.FHIRPathEngine.TypedElementDefinition) ElementDefinition(org.hl7.fhir.r5.model.ElementDefinition) DefinitionException(org.hl7.fhir.exceptions.DefinitionException) HashSet(java.util.HashSet)

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