Search in sources :

Example 1 with PropertyRepresentation

use of org.hl7.fhir.r5.model.ElementDefinition.PropertyRepresentation in project kindling by HL7.

the class CDAGenerator method dumpPaths.

private void dumpPaths() {
    for (StructureDefinition sd : structures) {
        if (sd.hasBaseDefinition())
            System.out.println("Class " + sd.getId() + " : " + sd.getBaseDefinition().substring(40));
        else
            System.out.println("Class " + sd.getId());
        for (ElementDefinition ed : sd.getDifferential().getElement()) {
            CommaSeparatedStringBuilder b = new CommaSeparatedStringBuilder();
            for (TypeRefComponent t : ed.getType()) {
                b.append(t.getWorkingCode());
            }
            CommaSeparatedStringBuilder b2 = new CommaSeparatedStringBuilder();
            for (Enumeration<PropertyRepresentation> r : ed.getRepresentation()) if (!r.asStringValue().equals("typeAttr"))
                b2.append(r.asStringValue());
            String s = Utilities.noString(b2.toString()) ? "" : " <<" + b2.toString() + ">>";
            if (ed.hasContentReference())
                s = " <<see " + ed.getContentReference().substring(1) + ">>";
            System.out.println("  " + ed.getPath() + " [" + ed.getMin() + ".." + ed.getMax() + "] : " + b.toString() + s);
        }
    }
}
Also used : StructureDefinition(org.hl7.fhir.r5.model.StructureDefinition) PropertyRepresentation(org.hl7.fhir.r5.model.ElementDefinition.PropertyRepresentation) TypeRefComponent(org.hl7.fhir.r5.model.ElementDefinition.TypeRefComponent) CommaSeparatedStringBuilder(org.hl7.fhir.utilities.CommaSeparatedStringBuilder) ElementDefinition(org.hl7.fhir.r5.model.ElementDefinition)

Example 2 with PropertyRepresentation

use of org.hl7.fhir.r5.model.ElementDefinition.PropertyRepresentation in project kindling by HL7.

the class XmlSpecGenerator method generateCoreElem.

private void generateCoreElem(List<ElementDefinition> elements, ElementDefinition elem, int indent, String pathName, boolean asValue, boolean complex) throws Exception {
    // return;
    for (Enumeration<PropertyRepresentation> t : elem.getRepresentation()) if (t.getValue() == PropertyRepresentation.XMLATTR)
        return;
    if (elem.getPath().endsWith(".extension") && !complex)
        return;
    if (complex && elem.getMax().equals("0"))
        return;
    boolean listed = false;
    boolean doneType = false;
    int width = 0;
    List<ElementDefinition> children = getChildren(elements, elem);
    String name = tail(elem.getPath());
    String indentS = "";
    for (int i = 0; i < indent; i++) {
        indentS += " ";
    }
    write(indentS);
    String en = asValue ? "value[x]" : name;
    if (en.contains("[x]") && elem.getType().size() == 1)
        en = en.replace("[x]", upFirst(elem.getType().get(0).getWorkingCode()));
    String closeOut;
    if (elem.hasSlicing()) {
        write("<span style=\"color: navy\">&lt;-- " + en + describeSlicing(elem.getSlicing()) + "--&gt;</span>\r\n");
        closeOut = "";
        return;
    } else if (asValue) {
        closeOut = "";
        throw new Error("not done yet");
    } else if (elem.getIsModifier() || elem.getMustSupport()) {
        write("&lt;<a href=\"" + (defPage + "#" + pathName + "." + en) + "\" title=\"" + Utilities.escapeXml(getEnhancedDefinition(elem)) + "\" class=\"dict\"><span style=\"text-decoration: underline\">");
        closeOut = "</b></span></a>";
    } else {
        write("&lt;<a href=\"" + (defPage + "#" + pathName + "." + en) + "\" title=\"" + Utilities.escapeXml(elem.getDefinition()) + "\" class=\"dict\">");
        closeOut = "</b></a>";
    }
    write("<b>" + Utilities.escapeXml(en));
    write(closeOut);
    if (complex && elem.getPath().endsWith(".extension")) {
        write(" url=\"");
        write("<span style=\"color: navy\">" + getUrl(children) + "</span>");
        write("\"");
    }
    if (elem.getType().size() == 1 && (definitions.getPrimitives().containsKey(elem.getType().get(0).getWorkingCode()))) {
        doneType = true;
        write(" value=\"[<span style=\"color: darkgreen\"><a href=\"" + prefix + dtRoot + definitions.getSrcFile(elem.getType().get(0).getWorkingCode()) + ".html#" + elem.getType().get(0).getWorkingCode() + "\">" + elem.getType().get(0).getWorkingCode() + "</a></span>]\"/");
    }
    write("&gt;");
    // optionality etc. within a comment
    if (children.isEmpty())
        write("<span style=\"color: Gray\">&lt;!--</span>");
    // } else
    if (!elem.getType().isEmpty()) {
        writeCardinality(elem);
        listed = true;
        if (!doneType) {
            width = writeTypeLinks(elem, indent);
        }
    } else if (tail(elem.getPath()).equals("extension")) {
        write(" <a href=\"" + prefix + "extensibility.html\"><span style=\"color: navy\">See Extensions</span></a> ");
    } else if (elem.hasContentReference()) {
        write(" <a href=\"#" + elem.getContentReference() + "\"><span style=\"color: navy\">See " + elem.getContentReference() + "</span></a> ");
    } else {
        write(" <a href=\"" + prefix + "none.html\"><span style=\"color: navy\">No Types?</span></a> ");
    }
    write(" ");
    if (children.isEmpty()) {
        if (name.equals("extension") || name.equals("modifierExtension")) {
            write(" <a href=\"" + prefix + "extensibility.html\"><span style=\"color: navy\">" + Utilities.escapeXml(elem.getShort()) + "</span></a> ");
        } else {
            if (elem.hasMax() && elem.getMax().equals("0"))
                write("<span style=\"text-decoration: line-through\">");
            if (elem.hasBinding() && elem.getBinding().hasValueSet()) {
                ValueSet vs = resolveValueSet(elem.getBinding().getValueSet());
                if (vs != null)
                    write("<span style=\"color: navy\"><a href=\"" + (Utilities.isAbsoluteUrl(vs.getUserString("path")) ? "" : prefix) + vs.getUserData("path") + "\" style=\"color: navy\">" + Utilities.escapeXml(elem.getShort()) + "</a><!--A--></span>");
                else
                    write("<span style=\"color: navy\"><a href=\"" + elem.getBinding().getValueSet() + "\" style=\"color: navy\">" + Utilities.escapeXml(elem.getShort()) + "</a><!--B--></span>");
            } else
                write("<span style=\"color: navy\">" + docPrefix(width, indent, elem) + Utilities.escapeXml(elem.getShort()) + "</span>");
            if (elem.hasMax() && elem.getMax().equals("0"))
                write("</span>");
        }
        if (children.isEmpty())
            write("<span style=\"color: Gray\"> --&gt;</span>");
    } else {
        if ("*".equals(elem.getMax()) && !listed) {
            // isNolist()) {
            if (elem.hasShort()) {
                write(" <span style=\"color: Gray\">&lt;!--");
                writeCardinality(elem);
                if (elem.hasMax() && elem.getMax().equals("0"))
                    write("<span style=\"text-decoration: line-through\">");
                write(" " + Utilities.escapeXml(elem.getShort()));
                if (elem.hasMax() && elem.getMax().equals("0"))
                    write("</span>");
                write(" --&gt;</span>");
            } else {
                write(" <span style=\"color: Gray\">&lt;!--");
                writeCardinality(elem);
                write(" --&gt;</span>");
            }
        } else if (elem.hasShort()) {
            write(" <span style=\"color: Gray\">&lt;!--");
            writeCardinality(elem);
            if (elem.hasMax() && elem.getMax().equals("0"))
                write("<span style=\"text-decoration: line-through\">");
            write(" " + Utilities.escapeXml(elem.getShort()));
            if (elem.hasMax() && elem.getMax().equals("0"))
                write("</span>");
            write(" --&gt;</span>");
        }
        write("\r\n");
        if (elem.getMax() == null || !elem.getMax().equals("0")) {
            // }
            for (ElementDefinition child : children) {
                generateCoreElem(elements, child, indent + 1, pathName + "." + name, false, false);
            }
        }
        for (int i = 0; i < indent; i++) {
            write(" ");
        }
        if (children.isEmpty())
            write("<span style=\"color: Gray\"> --&gt;</span>");
    }
    if (!doneType) {
        write("&lt;/");
        write(en);
        write("&gt;");
    }
    write("\r\n");
}
Also used : PropertyRepresentation(org.hl7.fhir.r5.model.ElementDefinition.PropertyRepresentation) ElementDefinition(org.hl7.fhir.r5.model.ElementDefinition) ValueSet(org.hl7.fhir.r5.model.ValueSet)

Example 3 with PropertyRepresentation

use of org.hl7.fhir.r5.model.ElementDefinition.PropertyRepresentation in project org.hl7.fhir.core by hapifhir.

the class InstanceValidator method assignChildren.

public List<String> assignChildren(ValidatorHostContext hostContext, List<ValidationMessage> errors, StructureDefinition profile, Element resource, NodeStack stack, List<ElementDefinition> childDefinitions, List<ElementInfo> children) throws DefinitionException {
    // 2. assign children to a definition
    // for each definition, for each child, check whether it belongs in the slice
    ElementDefinition slicer = null;
    boolean unsupportedSlicing = false;
    List<String> problematicPaths = new ArrayList<String>();
    String slicingPath = null;
    int sliceOffset = 0;
    for (int i = 0; i < childDefinitions.size(); i++) {
        ElementDefinition ed = childDefinitions.get(i);
        boolean childUnsupportedSlicing = false;
        boolean process = true;
        if (ed.hasSlicing() && !ed.getSlicing().getOrdered()) {
            slicingPath = ed.getPath();
        } else if (slicingPath != null && ed.getPath().equals(slicingPath)) {
            // nothing
            ;
        } else if (slicingPath != null && !ed.getPath().startsWith(slicingPath)) {
            slicingPath = null;
        }
        // where are we with slicing
        if (ed.hasSlicing()) {
            if (slicer != null && slicer.getPath().equals(ed.getPath())) {
                String errorContext = "profile " + profile.getUrl();
                if (!resource.getChildValue(ID).isEmpty()) {
                    errorContext += "; instance " + resource.getChildValue("id");
                }
                throw new DefinitionException(context.formatMessage(I18nConstants.SLICE_ENCOUNTERED_MIDWAY_THROUGH_SET_PATH___ID___, slicer.getPath(), slicer.getId(), errorContext));
            }
            slicer = ed;
            process = false;
            sliceOffset = i;
        } else if (slicer != null && !slicer.getPath().equals(ed.getPath()))
            slicer = null;
        for (ElementInfo ei : children) {
            if (ei.sliceInfo == null) {
                ei.sliceInfo = new ArrayList<>();
            }
            unsupportedSlicing = matchSlice(hostContext, errors, ei.sliceInfo, profile, stack, slicer, unsupportedSlicing, problematicPaths, sliceOffset, i, ed, childUnsupportedSlicing, ei);
        }
    }
    int last = -1;
    ElementInfo lastei = null;
    int lastSlice = -1;
    for (ElementInfo ei : children) {
        String sliceInfo = "";
        if (slicer != null) {
            sliceInfo = " (slice: " + slicer.getPath() + ")";
        }
        if (!unsupportedSlicing) {
            if (ei.additionalSlice && ei.definition != null) {
                if (ei.definition.getSlicing().getRules().equals(ElementDefinition.SlicingRules.OPEN) || ei.definition.getSlicing().getRules().equals(ElementDefinition.SlicingRules.OPENATEND) && true) /* TODO: replace "true" with condition to check that this element is at "end" */
                {
                    slicingHint(errors, IssueType.INFORMATIONAL, ei.line(), ei.col(), ei.getPath(), false, isProfile(slicer) || isCritical(ei.sliceInfo), context.formatMessage(I18nConstants.THIS_ELEMENT_DOES_NOT_MATCH_ANY_KNOWN_SLICE_, profile == null ? "" : " defined in the profile " + profile.getUrl()), context.formatMessage(I18nConstants.THIS_ELEMENT_DOES_NOT_MATCH_ANY_KNOWN_SLICE_, profile == null ? "" : I18nConstants.DEFINED_IN_THE_PROFILE + profile.getUrl()) + errorSummaryForSlicingAsHtml(ei.sliceInfo), errorSummaryForSlicingAsText(ei.sliceInfo));
                } else if (ei.definition.getSlicing().getRules().equals(ElementDefinition.SlicingRules.CLOSED)) {
                    rule(errors, IssueType.INVALID, ei.line(), ei.col(), ei.getPath(), false, I18nConstants.VALIDATION_VAL_PROFILE_NOTSLICE, (profile == null ? "" : " defined in the profile " + profile.getUrl()), errorSummaryForSlicing(ei.sliceInfo));
                }
            } else {
                // Don't raise this if we're in an abstract profile, like Resource
                if (!profile.getAbstract()) {
                    rule(errors, IssueType.NOTSUPPORTED, ei.line(), ei.col(), ei.getPath(), (ei.definition != null), I18nConstants.VALIDATION_VAL_PROFILE_NOTALLOWED, profile.getUrl());
                }
            }
        }
        // TODO: Should get the order of elements correct when parsing elements that are XML attributes vs. elements
        boolean isXmlAttr = false;
        if (ei.definition != null) {
            for (Enumeration<PropertyRepresentation> r : ei.definition.getRepresentation()) {
                if (r.getValue() == PropertyRepresentation.XMLATTR) {
                    isXmlAttr = true;
                    break;
                }
            }
        }
        if (!ToolingExtensions.readBoolExtension(profile, "http://hl7.org/fhir/StructureDefinition/structuredefinition-xml-no-order")) {
            boolean ok = (ei.definition == null) || (ei.index >= last) || isXmlAttr;
            rule(errors, IssueType.INVALID, ei.line(), ei.col(), ei.getPath(), ok, I18nConstants.VALIDATION_VAL_PROFILE_OUTOFORDER, profile.getUrl(), ei.getName(), lastei == null ? "(null)" : lastei.getName());
        }
        if (ei.slice != null && ei.index == last && ei.slice.getSlicing().getOrdered()) {
            rule(errors, IssueType.INVALID, ei.line(), ei.col(), ei.getPath(), (ei.definition == null) || (ei.sliceindex >= lastSlice) || isXmlAttr, I18nConstants.VALIDATION_VAL_PROFILE_SLICEORDER, profile.getUrl(), ei.getName());
        }
        if (ei.definition == null || !isXmlAttr) {
            last = ei.index;
            lastei = ei;
        }
        if (ei.slice != null) {
            lastSlice = ei.sliceindex;
        } else {
            lastSlice = -1;
        }
    }
    return problematicPaths;
}
Also used : PropertyRepresentation(org.hl7.fhir.r5.model.ElementDefinition.PropertyRepresentation) ElementInfo(org.hl7.fhir.validation.instance.utils.ElementInfo) ArrayList(java.util.ArrayList) TypedElementDefinition(org.hl7.fhir.r5.utils.FHIRPathEngine.TypedElementDefinition) ElementDefinition(org.hl7.fhir.r5.model.ElementDefinition) DefinitionException(org.hl7.fhir.exceptions.DefinitionException) ContactPoint(org.hl7.fhir.r5.model.ContactPoint)

Aggregations

ElementDefinition (org.hl7.fhir.r5.model.ElementDefinition)3 PropertyRepresentation (org.hl7.fhir.r5.model.ElementDefinition.PropertyRepresentation)3 ArrayList (java.util.ArrayList)1 DefinitionException (org.hl7.fhir.exceptions.DefinitionException)1 ContactPoint (org.hl7.fhir.r5.model.ContactPoint)1 TypeRefComponent (org.hl7.fhir.r5.model.ElementDefinition.TypeRefComponent)1 StructureDefinition (org.hl7.fhir.r5.model.StructureDefinition)1 ValueSet (org.hl7.fhir.r5.model.ValueSet)1 TypedElementDefinition (org.hl7.fhir.r5.utils.FHIRPathEngine.TypedElementDefinition)1 CommaSeparatedStringBuilder (org.hl7.fhir.utilities.CommaSeparatedStringBuilder)1 ElementInfo (org.hl7.fhir.validation.instance.utils.ElementInfo)1