Search in sources :

Example 16 with ElementDefinitionBindingComponent

use of org.hl7.fhir.r4b.model.ElementDefinition.ElementDefinitionBindingComponent in project org.hl7.fhir.core by hapifhir.

the class ProfileUtilities method makeUnifiedBinding.

private ElementDefinitionBindingComponent makeUnifiedBinding(ElementDefinitionBindingComponent binding, ElementDefinition element) {
    if (!element.hasUserData(DERIVATION_POINTER)) {
        return binding;
    }
    ElementDefinition base = (ElementDefinition) element.getUserData(DERIVATION_POINTER);
    if (!base.hasBinding()) {
        return binding;
    }
    ElementDefinitionBindingComponent o = base.getBinding();
    ElementDefinitionBindingComponent b = new ElementDefinitionBindingComponent();
    b.setUserData(DERIVATION_POINTER, o);
    if (binding.hasValueSet()) {
        b.setValueSet(binding.getValueSet());
    } else if (o.hasValueSet()) {
        b.setValueSet(o.getValueSet());
        b.getValueSetElement().setUserData(DERIVATION_EQUALS, o.getValueSetElement());
    }
    if (binding.hasStrength()) {
        b.setStrength(binding.getStrength());
    } else if (o.hasStrength()) {
        b.setStrength(o.getStrength());
        b.getStrengthElement().setUserData(DERIVATION_EQUALS, o.getStrengthElement());
    }
    if (binding.hasDescription()) {
        b.setDescription(binding.getDescription());
    } else if (o.hasDescription()) {
        b.setDescription(o.getDescription());
        b.getDescriptionElement().setUserData(DERIVATION_EQUALS, o.getDescriptionElement());
    }
    return b;
}
Also used : ElementDefinition(org.hl7.fhir.r4b.model.ElementDefinition) ElementDefinitionBindingComponent(org.hl7.fhir.r4b.model.ElementDefinition.ElementDefinitionBindingComponent)

Example 17 with ElementDefinitionBindingComponent

use of org.hl7.fhir.r4b.model.ElementDefinition.ElementDefinitionBindingComponent in project org.hl7.fhir.core by hapifhir.

the class BaseWorkerContext method expandVS.

@Override
public ValueSetExpansionOutcome expandVS(ElementDefinitionBindingComponent binding, boolean cacheOk, boolean heirarchical) throws FHIRException {
    ValueSet vs = null;
    vs = fetchResource(ValueSet.class, binding.getValueSet());
    if (vs == null) {
        throw new FHIRException(formatMessage(I18nConstants.UNABLE_TO_RESOLVE_VALUE_SET_, binding.getValueSet()));
    }
    return expandVS(vs, cacheOk, heirarchical);
}
Also used : ValueSet(org.hl7.fhir.r4b.model.ValueSet) FHIRException(org.hl7.fhir.exceptions.FHIRException)

Example 18 with ElementDefinitionBindingComponent

use of org.hl7.fhir.r4b.model.ElementDefinition.ElementDefinitionBindingComponent in project org.hl7.fhir.core by hapifhir.

the class BaseWorkerContext method expandVS.

@Override
public ValueSetExpansionOutcome expandVS(ElementDefinitionBindingComponent binding, boolean cacheOk, boolean heirarchical) throws FHIRException {
    ValueSet vs = null;
    vs = fetchResource(ValueSet.class, binding.getValueSet());
    if (vs == null) {
        throw new FHIRException(formatMessage(I18nConstants.UNABLE_TO_RESOLVE_VALUE_SET_, binding.getValueSet()));
    }
    return expandVS(vs, cacheOk, heirarchical);
}
Also used : ValueSet(org.hl7.fhir.r5.model.ValueSet) FHIRException(org.hl7.fhir.exceptions.FHIRException)

Example 19 with ElementDefinitionBindingComponent

use of org.hl7.fhir.r4b.model.ElementDefinition.ElementDefinitionBindingComponent in project org.hl7.fhir.core by hapifhir.

the class ProfileUtilities method generateDescription.

private Cell generateDescription(HierarchicalTableGenerator gen, Row row, ElementDefinition definition, ElementDefinition fallback, boolean used, String baseURL, String url, StructureDefinition profile, String corePath, String imagePath, boolean root, boolean logicalModel, boolean allInvariants, ElementDefinition valueDefn, boolean snapshot, boolean mustSupportOnly, boolean allowSubRows, RenderingContext rc) throws IOException, FHIRException {
    Cell c = gen.new Cell();
    row.getCells().add(c);
    if (used) {
        if (logicalModel && ToolingExtensions.hasExtension(profile, "http://hl7.org/fhir/StructureDefinition/elementdefinition-namespace")) {
            if (root) {
                c.getPieces().add(gen.new Piece(null, translate("sd.table", "XML Namespace") + ": ", null).addStyle("font-weight:bold"));
                c.getPieces().add(gen.new Piece(null, ToolingExtensions.readStringExtension(profile, "http://hl7.org/fhir/StructureDefinition/elementdefinition-namespace"), null));
            } else if (!root && ToolingExtensions.hasExtension(definition, "http://hl7.org/fhir/StructureDefinition/elementdefinition-namespace") && !ToolingExtensions.readStringExtension(definition, "http://hl7.org/fhir/StructureDefinition/elementdefinition-namespace").equals(ToolingExtensions.readStringExtension(profile, "http://hl7.org/fhir/StructureDefinition/elementdefinition-namespace"))) {
                c.getPieces().add(gen.new Piece(null, translate("sd.table", "XML Namespace") + ": ", null).addStyle("font-weight:bold"));
                c.getPieces().add(gen.new Piece(null, ToolingExtensions.readStringExtension(definition, "http://hl7.org/fhir/StructureDefinition/elementdefinition-namespace"), null));
            }
        }
        if (root) {
            if (profile != null && profile.getAbstract()) {
                if (!c.getPieces().isEmpty()) {
                    c.addPiece(gen.new Piece("br"));
                }
                c.addPiece(gen.new Piece(null, "This is an abstract profile", null));
            }
        }
        if (definition.getPath().endsWith("url") && definition.hasFixed()) {
            c.getPieces().add(checkForNoChange(definition.getFixed(), gen.new Piece(null, "\"" + buildJson(definition.getFixed()) + "\"", null).addStyle("color: darkgreen")));
        } else {
            if (definition != null && definition.hasShort()) {
                if (!c.getPieces().isEmpty()) {
                    c.addPiece(gen.new Piece("br"));
                }
                c.addPiece(checkForNoChange(definition.getShortElement(), gen.new Piece(null, gt(definition.getShortElement()), null)));
            } else if (fallback != null && fallback.hasShort()) {
                if (!c.getPieces().isEmpty()) {
                    c.addPiece(gen.new Piece("br"));
                }
                c.addPiece(gen.new Piece(null, gt(fallback.getShortElement()), null).addStyle("opacity: 0.5"));
            }
            if (url != null) {
                if (!c.getPieces().isEmpty())
                    c.addPiece(gen.new Piece("br"));
                String fullUrl = url.startsWith("#") ? baseURL + url : url;
                StructureDefinition ed = context.fetchResource(StructureDefinition.class, url);
                String ref = null;
                String ref2 = null;
                String fixedUrl = null;
                if (ed != null) {
                    String p = ed.getUserString("path");
                    if (p != null) {
                        ref = p.startsWith("http:") || igmode ? p : Utilities.pathURL(corePath, p);
                    }
                    fixedUrl = getFixedUrl(ed);
                    if (fixedUrl != null) {
                        // if its null, we guess that it's not a profiled extension?
                        if (fixedUrl.equals(url))
                            fixedUrl = null;
                        else {
                            StructureDefinition ed2 = context.fetchResource(StructureDefinition.class, fixedUrl);
                            if (ed2 != null) {
                                String p2 = ed2.getUserString("path");
                                if (p2 != null) {
                                    ref2 = p2.startsWith("http:") || igmode ? p2 : Utilities.pathURL(corePath, p2);
                                }
                            }
                        }
                    }
                }
                if (fixedUrl == null) {
                    c.getPieces().add(gen.new Piece(null, translate("sd.table", "URL") + ": ", null).addStyle("font-weight:bold"));
                    c.getPieces().add(gen.new Piece(ref, fullUrl, null));
                } else {
                    // reference to a profile take on the extension show the base URL
                    c.getPieces().add(gen.new Piece(null, translate("sd.table", "URL") + ": ", null).addStyle("font-weight:bold"));
                    c.getPieces().add(gen.new Piece(ref2, fixedUrl, null));
                    c.getPieces().add(gen.new Piece(null, translate("sd.table", " profiled by ") + " ", null).addStyle("font-weight:bold"));
                    c.getPieces().add(gen.new Piece(ref, fullUrl, null));
                }
            }
            if (definition.hasSlicing()) {
                if (!c.getPieces().isEmpty()) {
                    c.addPiece(gen.new Piece("br"));
                }
                c.getPieces().add(gen.new Piece(null, translate("sd.table", "Slice") + ": ", null).addStyle("font-weight:bold"));
                c.getPieces().add(gen.new Piece(null, describeSlice(definition.getSlicing()), null));
            }
            if (!definition.getPath().contains(".") && ToolingExtensions.hasExtension(profile, ToolingExtensions.EXT_BINDING_STYLE)) {
                if (!c.getPieces().isEmpty()) {
                    c.addPiece(gen.new Piece("br"));
                }
                c.getPieces().add(gen.new Piece(null, translate("sd.table", "Binding") + ": ", null).addStyle("font-weight:bold"));
                c.getPieces().add(gen.new Piece(null, "This type can be bound to a value set using the ", null));
                c.getPieces().add(gen.new Piece(null, ToolingExtensions.readStringExtension(profile, ToolingExtensions.EXT_BINDING_STYLE), null));
                c.getPieces().add(gen.new Piece(null, " binding style", null));
            }
            if (definition.hasExtension(ToolingExtensions.EXT_XML_NAME)) {
                if (!c.getPieces().isEmpty()) {
                    c.addPiece(gen.new Piece("br"));
                }
                if (definition.hasExtension(ToolingExtensions.EXT_XML_NAMESPACE)) {
                    c.getPieces().add(gen.new Piece(null, translate("sd.table", "XML") + ": ", null).addStyle("font-weight:bold"));
                    c.getPieces().add(gen.new Piece(null, definition.getExtensionString(ToolingExtensions.EXT_XML_NAME), null));
                    c.getPieces().add(gen.new Piece(null, " (", null));
                    c.getPieces().add(gen.new Piece(null, definition.getExtensionString(ToolingExtensions.EXT_XML_NAMESPACE), null));
                    c.getPieces().add(gen.new Piece(null, ")", null));
                } else {
                    c.getPieces().add(gen.new Piece(null, translate("sd.table", "XML Element Name") + ": ", null).addStyle("font-weight:bold"));
                    c.getPieces().add(gen.new Piece(null, definition.getExtensionString(ToolingExtensions.EXT_XML_NAME), null));
                }
            } else if (definition.hasExtension(ToolingExtensions.EXT_XML_NAMESPACE)) {
                if (!c.getPieces().isEmpty()) {
                    c.addPiece(gen.new Piece("br"));
                }
                c.getPieces().add(gen.new Piece(null, translate("sd.table", "XML Namespace") + ": ", null).addStyle("font-weight:bold"));
                c.getPieces().add(gen.new Piece(null, definition.getExtensionString(ToolingExtensions.EXT_XML_NAMESPACE), null));
            }
            if (definition != null) {
                ElementDefinitionBindingComponent binding = null;
                if (valueDefn != null && valueDefn.hasBinding() && !valueDefn.getBinding().isEmpty())
                    binding = makeUnifiedBinding(valueDefn.getBinding(), valueDefn);
                else if (definition.hasBinding())
                    binding = makeUnifiedBinding(definition.getBinding(), definition);
                if (binding != null && !binding.isEmpty()) {
                    if (!c.getPieces().isEmpty())
                        c.addPiece(gen.new Piece("br"));
                    BindingResolution br = pkp == null ? makeNullBr(binding) : pkp.resolveBinding(profile, binding, definition.getPath());
                    c.getPieces().add(checkForNoChange(binding, gen.new Piece(null, translate("sd.table", "Binding") + ": ", null).addStyle("font-weight:bold")));
                    c.getPieces().add(checkForNoChange(binding.getValueSetElement(), gen.new Piece(br.url == null ? null : Utilities.isAbsoluteUrl(br.url) || !pkp.prependLinks() ? br.url : corePath + br.url, br.display, null)));
                    if (binding.hasStrength()) {
                        c.getPieces().add(checkForNoChange(binding.getStrengthElement(), gen.new Piece(null, " (", null)));
                        c.getPieces().add(checkForNoChange(binding.getStrengthElement(), gen.new Piece(corePath + "terminologies.html#" + binding.getStrength().toCode(), egt(binding.getStrengthElement()), binding.getStrength().getDefinition())));
                        c.getPieces().add(checkForNoChange(binding.getStrengthElement(), gen.new Piece(null, ")", null)));
                    }
                    if (binding.hasDescription() && MarkDownProcessor.isSimpleMarkdown(binding.getDescription())) {
                        c.getPieces().add(gen.new Piece(null, ": ", null));
                        c.addMarkdownNoPara(PublicationHacker.fixBindingDescriptions(context, binding.getDescriptionElement()).asStringValue(), checkForNoChange(PublicationHacker.fixBindingDescriptions(context, binding.getDescriptionElement())));
                    }
                    AdditionalBindingsRenderer abr = new AdditionalBindingsRenderer(pkp, corePath, profile, definition.getPath(), rc, null);
                    if (binding.hasExtension(ToolingExtensions.EXT_MAX_VALUESET)) {
                        abr.seeMaxBinding(ToolingExtensions.getExtension(binding, ToolingExtensions.EXT_MAX_VALUESET));
                    }
                    if (binding.hasExtension(ToolingExtensions.EXT_MIN_VALUESET)) {
                        abr.seeMinBinding(ToolingExtensions.getExtension(binding, ToolingExtensions.EXT_MIN_VALUESET));
                    }
                    if (binding.hasExtension(ToolingExtensions.EXT_BINDING_ADDITIONAL)) {
                        abr.seeAdditionalBindings(binding.getExtensionsByUrl(ToolingExtensions.EXT_BINDING_ADDITIONAL));
                    }
                    abr.render(gen, c);
                }
                for (ElementDefinitionConstraintComponent inv : definition.getConstraint()) {
                    if (!inv.hasSource() || profile == null || inv.getSource().equals(profile.getUrl()) || allInvariants) {
                        if (!c.getPieces().isEmpty())
                            c.addPiece(gen.new Piece("br"));
                        c.getPieces().add(checkForNoChange(inv, gen.new Piece(null, inv.getKey() + ": ", null).addStyle("font-weight:bold")));
                        c.getPieces().add(checkForNoChange(inv, gen.new Piece(null, gt(inv.getHumanElement()), null)));
                    }
                }
                if ((definition.hasBase() && "*".equals(definition.getBase().getMax())) || (definition.hasMax() && "*".equals(definition.getMax()))) {
                    if (c.getPieces().size() > 0)
                        c.addPiece(gen.new Piece("br"));
                    if (definition.hasOrderMeaning()) {
                        c.getPieces().add(gen.new Piece(null, "This repeating element order: " + definition.getOrderMeaning(), null));
                    } else {
                    // don't show this, this it's important: c.getPieces().add(gen.new Piece(null, "This repeating element has no defined order", null));
                    }
                }
                if (definition.hasFixed()) {
                    if (!c.getPieces().isEmpty()) {
                        c.addPiece(gen.new Piece("br"));
                    }
                    c.getPieces().add(checkForNoChange(definition.getFixed(), gen.new Piece(null, translate("sd.table", "Fixed Value") + ": ", null).addStyle("font-weight:bold")));
                    if (!useTableForFixedValues || !allowSubRows || definition.getFixed().isPrimitive()) {
                        String s = buildJson(definition.getFixed());
                        String link = null;
                        if (Utilities.isAbsoluteUrl(s))
                            link = pkp.getLinkForUrl(corePath, s);
                        c.getPieces().add(checkForNoChange(definition.getFixed(), gen.new Piece(link, s, null).addStyle("color: darkgreen")));
                    } else {
                        c.getPieces().add(checkForNoChange(definition.getFixed(), gen.new Piece(null, "As shown", null).addStyle("color: darkgreen")));
                        genFixedValue(gen, row, definition.getFixed(), snapshot, false, corePath, false);
                    }
                    if (isCoded(definition.getFixed()) && !hasDescription(definition.getFixed())) {
                        Piece p = describeCoded(gen, definition.getFixed());
                        if (p != null)
                            c.getPieces().add(p);
                    }
                } else if (definition.hasPattern()) {
                    if (!c.getPieces().isEmpty()) {
                        c.addPiece(gen.new Piece("br"));
                    }
                    c.getPieces().add(checkForNoChange(definition.getPattern(), gen.new Piece(null, translate("sd.table", "Required Pattern") + ": ", null).addStyle("font-weight:bold")));
                    if (!useTableForFixedValues || !allowSubRows || definition.getPattern().isPrimitive())
                        c.getPieces().add(checkForNoChange(definition.getPattern(), gen.new Piece(null, buildJson(definition.getPattern()), null).addStyle("color: darkgreen")));
                    else {
                        c.getPieces().add(checkForNoChange(definition.getPattern(), gen.new Piece(null, "At least the following", null).addStyle("color: darkgreen")));
                        genFixedValue(gen, row, definition.getPattern(), snapshot, true, corePath, mustSupportOnly);
                    }
                } else if (definition.hasExample()) {
                    for (ElementDefinitionExampleComponent ex : definition.getExample()) {
                        if (!c.getPieces().isEmpty()) {
                            c.addPiece(gen.new Piece("br"));
                        }
                        c.getPieces().add(checkForNoChange(ex, gen.new Piece(null, translate("sd.table", "Example") + ("".equals("General") ? "" : " " + ex.getLabel()) + ": ", null).addStyle("font-weight:bold")));
                        c.getPieces().add(checkForNoChange(ex, gen.new Piece(null, buildJson(ex.getValue()), null).addStyle("color: darkgreen")));
                    }
                }
                if (definition.hasMaxLength() && definition.getMaxLength() != 0) {
                    if (!c.getPieces().isEmpty()) {
                        c.addPiece(gen.new Piece("br"));
                    }
                    c.getPieces().add(checkForNoChange(definition.getMaxLengthElement(), gen.new Piece(null, "Max Length: ", null).addStyle("font-weight:bold")));
                    c.getPieces().add(checkForNoChange(definition.getMaxLengthElement(), gen.new Piece(null, Integer.toString(definition.getMaxLength()), null).addStyle("color: darkgreen")));
                }
                if (profile != null) {
                    for (StructureDefinitionMappingComponent md : profile.getMapping()) {
                        if (md.hasExtension(ToolingExtensions.EXT_TABLE_NAME)) {
                            ElementDefinitionMappingComponent map = null;
                            for (ElementDefinitionMappingComponent m : definition.getMapping()) if (m.getIdentity().equals(md.getIdentity()))
                                map = m;
                            if (map != null) {
                                for (int i = 0; i < definition.getMapping().size(); i++) {
                                    c.addPiece(gen.new Piece("br"));
                                    c.getPieces().add(gen.new Piece(null, ToolingExtensions.readStringExtension(md, ToolingExtensions.EXT_TABLE_NAME) + ": " + map.getMap(), null));
                                }
                            }
                        }
                    }
                }
            }
        }
    }
    return c;
}
Also used : ElementDefinitionExampleComponent(org.hl7.fhir.r5.model.ElementDefinition.ElementDefinitionExampleComponent) StructureDefinition(org.hl7.fhir.r5.model.StructureDefinition) BindingResolution(org.hl7.fhir.r5.conformance.ProfileUtilities.ProfileKnowledgeProvider.BindingResolution) StructureDefinitionMappingComponent(org.hl7.fhir.r5.model.StructureDefinition.StructureDefinitionMappingComponent) Piece(org.hl7.fhir.utilities.xhtml.HierarchicalTableGenerator.Piece) Cell(org.hl7.fhir.utilities.xhtml.HierarchicalTableGenerator.Cell) ElementDefinitionBindingComponent(org.hl7.fhir.r5.model.ElementDefinition.ElementDefinitionBindingComponent) ElementDefinitionConstraintComponent(org.hl7.fhir.r5.model.ElementDefinition.ElementDefinitionConstraintComponent) ElementDefinitionMappingComponent(org.hl7.fhir.r5.model.ElementDefinition.ElementDefinitionMappingComponent)

Example 20 with ElementDefinitionBindingComponent

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

Aggregations

ElementDefinitionBindingComponent (org.hl7.fhir.r5.model.ElementDefinition.ElementDefinitionBindingComponent)18 ValueSet (org.hl7.fhir.r5.model.ValueSet)12 Cell (org.hl7.fhir.utilities.xhtml.HierarchicalTableGenerator.Cell)8 Piece (org.hl7.fhir.utilities.xhtml.HierarchicalTableGenerator.Piece)8 IOException (java.io.IOException)7 DefinitionException (org.hl7.fhir.exceptions.DefinitionException)7 FHIRException (org.hl7.fhir.exceptions.FHIRException)7 ElementDefinitionBindingComponent (org.hl7.fhir.r4b.model.ElementDefinition.ElementDefinitionBindingComponent)6 ElementDefinition (org.hl7.fhir.r5.model.ElementDefinition)6 ValidationMessage (org.hl7.fhir.utilities.validation.ValidationMessage)6 ElementDefinitionBindingComponent (org.hl7.fhir.dstu3.model.ElementDefinition.ElementDefinitionBindingComponent)4 ElementDefinitionBindingComponent (org.hl7.fhir.r4.model.ElementDefinition.ElementDefinitionBindingComponent)4 ValidationResult (org.hl7.fhir.r5.context.IWorkerContext.ValidationResult)4 CodeSystem (org.hl7.fhir.r5.model.CodeSystem)4 ArrayList (java.util.ArrayList)3 NotImplementedException (org.apache.commons.lang3.NotImplementedException)3 ValueSet (org.hl7.fhir.r4b.model.ValueSet)3 StringType (org.hl7.fhir.r5.model.StringType)3 ElementDefinitionBindingComponent (org.hl7.fhir.dstu2.model.ElementDefinition.ElementDefinitionBindingComponent)2 Reference (org.hl7.fhir.dstu2.model.Reference)2