Search in sources :

Example 31 with ElementDefinition

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

the class XmlSpecGenerator method generateExtensionInner.

private void generateExtensionInner(StructureDefinition ed) throws IOException, Exception {
    ElementDefinition root = ed.getSnapshot().getElement().get(0);
    write("<!-- " + Utilities.escapeXml(ed.getName()) + " -->");
    write("<span style=\"float: right\"><a title=\"Documentation for this format\" href=\"" + prefix + "xml.html\"><img src=\"" + prefix + "help.png\" alt=\"doco\"/></a></span>\r\n");
    String rn = ed.getSnapshot().getElement().get(0).getIsModifier() ? "modifierExtension" : "extension";
    write("\r\n&lt;");
    if (defPage == null)
        write("<span title=\"" + Utilities.escapeXml(root.getDefinition()) + "\"><b>");
    else
        write("<a href=\"" + (defPage + "#" + root.getSliceName()) + "\" title=\"" + Utilities.escapeXml(root.getDefinition()) + "\" class=\"dict\"><b>");
    write(rn);
    if ((defPage == null))
        write("</b></span>");
    else
        write("</b></a>");
    write(" xmlns=\"http://hl7.org/fhir\"\r\n    ");
    generateExtensionAttribute(ed);
    write(" &gt;\r\n");
    List<ElementDefinition> children = getChildren(ed.getSnapshot().getElement(), ed.getSnapshot().getElement().get(0));
    boolean complex = isComplex(children);
    if (!complex)
        write("  &lt;!-- from Element: <a href=\"" + prefix + "extensibility.html\">extension</a> -->\r\n");
    for (ElementDefinition child : children) generateCoreElem(ed.getSnapshot().getElement(), child, 1, rn, false, complex);
    write("&lt;/");
    write(rn);
    write("&gt;\r\n");
}
Also used : ElementDefinition(org.hl7.fhir.r5.model.ElementDefinition)

Example 32 with ElementDefinition

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

the class XmlSpecGenerator method generateInner.

private void generateInner(StructureDefinition sd) throws IOException, Exception {
    ElementDefinition root = sd.getSnapshot().getElement().get(0);
    write("&lt;!-- " + Utilities.escapeXml(sd.getName()) + " -->");
    write("<span style=\"float: right\"><a title=\"Documentation for this format\" href=\"" + prefix + "xml.html\"><img src=\"" + prefix + "help.png\" alt=\"doco\"/></a></span>\r\n");
    String rn = sd.getSnapshot().getElement().get(0).getPath();
    write("\r\n&lt;");
    if (defPage == null)
        write("<span title=\"" + Utilities.escapeXml(root.getDefinition()) + "\"><b>");
    else
        write("<a href=\"" + (defPage + "#" + root.getSliceName()) + "\" title=\"" + Utilities.escapeXml(root.getDefinition()) + "\" class=\"dict\"><b>");
    write(rn);
    if ((defPage == null))
        write("</b></span>");
    else
        write("</b></a>");
    write(" xmlns=\"http://hl7.org/fhir\"\r\n&gt;\r\n");
    List<ElementDefinition> children = getChildren(sd.getSnapshot().getElement(), sd.getSnapshot().getElement().get(0));
    boolean complex = isComplex(children);
    if (!complex)
        write("  &lt;!-- from Element: <a href=\"" + prefix + "extensibility.html\">extension</a> -->\r\n");
    for (ElementDefinition child : children) generateCoreElem(sd.getSnapshot().getElement(), child, 1, rn, false, complex);
    write("&lt;/");
    write(rn);
    write("&gt;\r\n");
}
Also used : ElementDefinition(org.hl7.fhir.r5.model.ElementDefinition)

Example 33 with ElementDefinition

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

the class JsonSpecGenerator method generateCoreElem.

@SuppressWarnings("rawtypes")
private void generateCoreElem(List<ElementDefinition> elements, ElementDefinition elem, int indent, String pathName, boolean asValue, TypeRefComponent type, boolean last, boolean complex) throws Exception {
    if (elem.getPath().endsWith(".id"))
        return;
    if (!complex && elem.getPath().endsWith(".extension"))
        return;
    if (elem.getMax().equals("0"))
        return;
    String indentS = "";
    for (int i = 0; i < indent; i++) {
        indentS += "  ";
    }
    write(indentS);
    List<ElementDefinition> children = getChildren(elements, elem);
    String name = tail(elem.getPath());
    String en = asValue ? "value[x]" : name;
    String tc = type.getWorkingCode();
    if (en.contains("[x]"))
        en = en.replace("[x]", upFirst(tc));
    boolean unbounded = elem.hasMax() && elem.getMax().equals("*");
    // 1. name
    write("\"<a href=\"" + (defPage + "#" + pathName + "." + en) + "\" title=\"" + Utilities.escapeXml(getEnhancedDefinition(elem)) + "\" class=\"dict\"><span style=\"text-decoration: underline\">" + en + "</span></a>\" : ");
    // 2. value
    boolean delayedCloseArray = false;
    if (unbounded)
        write("[");
    if (type == null) {
        // inline definition
        assert (children.size() > 0);
        write("{");
        delayedCloseArray = true;
    } else if (definitions.getPrimitives().containsKey(tc)) {
        if (!(tc.equals("integer") || tc.equals("boolean") || tc.equals("decimal")))
            write("\"");
        if (elem.hasFixed())
            write(Utilities.escapeJson(((PrimitiveType) elem.getFixed()).asStringValue()));
        else
            write("&lt;<span style=\"color: darkgreen\"><a href=\"" + prefix + (dtRoot + definitions.getSrcFile(tc) + ".html#" + tc) + "\">" + tc + "</a></span>&gt;");
        if (!(tc.equals("integer") || tc.equals("boolean") || tc.equals("decimal")))
            write("\"");
    } else {
        write("{ ");
        write("<span style=\"color: darkgreen\"><a href=\"" + prefix + (dtRoot + definitions.getSrcFile(tc) + ".html#" + tc) + "\">" + tc + "</a></span>");
        if (type.hasProfile()) {
            if (type.getProfile().get(0).getValue().startsWith("http://hl7.org/fhir/StructureDefinition/")) {
                String t = type.getProfile().get(0).getValue().substring(40);
                if (definitions.hasType(t))
                    write("(<span style=\"color: darkgreen\"><a href=\"" + prefix + (dtRoot + definitions.getSrcFile(t) + ".html#" + t) + "\">" + t + "</a></span>)");
                else if (definitions.hasResource(t))
                    write("(<span style=\"color: darkgreen\"><a href=\"" + prefix + dtRoot + t.toLowerCase() + ".html\">" + t + "</a></span>)");
                else
                    write("(" + t + ")");
            } else
                write("(" + type.getProfile() + ")");
        }
        if (type.hasTargetProfile()) {
            if (type.getTargetProfile().get(0).getValue().startsWith("http://hl7.org/fhir/StructureDefinition/")) {
                String t = type.getTargetProfile().get(0).getValue().substring(40);
                if (definitions.hasType(t))
                    write("(<span style=\"color: darkgreen\"><a href=\"" + prefix + (dtRoot + definitions.getSrcFile(t) + ".html#" + t) + "\">" + t + "</a></span>)");
                else if (definitions.hasResource(t))
                    write("(<span style=\"color: darkgreen\"><a href=\"" + prefix + dtRoot + t.toLowerCase() + ".html\">" + t + "</a></span>)");
                else
                    write("(" + t + ")");
            } else
                write("(" + type.getTargetProfile() + ")");
        }
        write(" }");
    }
    if (!delayedCloseArray) {
        if (unbounded)
            write("]");
        if (!last)
            write(",");
    }
    write(" <span style=\"color: Gray\">//</span>");
    // 3. optionality
    writeCardinality(elem);
    // 4. doco
    if (!elem.hasFixed()) {
        if (elem.hasBinding() && elem.getBinding().hasValueSet()) {
            ValueSet vs = resolveValueSet(elem.getBinding().getValueSet());
            if (vs != null)
                write("<span style=\"color: navy; opacity: 0.8\"><a href=\"" + (Utilities.isAbsoluteUrl(vs.getUserString("path")) ? "" : prefix) + vs.getUserData("path") + "\" style=\"color: navy\">" + Utilities.escapeXml(elem.getShort()) + "</a></span>");
            else
                write("<span style=\"color: navy; opacity: 0.8\"><a href=\"" + elem.getBinding().getValueSet() + ".html\" style=\"color: navy\">" + Utilities.escapeXml(elem.getShort()) + "</a></span>");
        } else
            write("<span style=\"color: navy; opacity: 0.8\">" + Utilities.escapeXml(elem.getShort()) + "</span>");
    }
    write("\r\n");
    if (delayedCloseArray) {
        int c = 0;
        for (ElementDefinition child : children) {
            if (child.getType().size() == 1)
                generateCoreElem(elements, child, indent + 1, pathName + "." + name, false, child.getType().get(0), ++c == children.size(), false);
            else {
                write("<span style=\"color: Gray\">// value[x]: <span style=\"color: navy; opacity: 0.8\">" + Utilities.escapeXml(child.getShort()) + "</span>. One of these " + Integer.toString(child.getType().size()) + ":</span>\r\n");
                for (TypeRefComponent t : child.getType()) generateCoreElem(elements, child, indent + 1, pathName + "." + name, false, t, ++c == children.size(), false);
            }
        }
        write("}]");
        if (!last)
            write(",");
    }
}
Also used : TypeRefComponent(org.hl7.fhir.r5.model.ElementDefinition.TypeRefComponent) PrimitiveType(org.hl7.fhir.r5.model.PrimitiveType) ElementDefinition(org.hl7.fhir.r5.model.ElementDefinition) ValueSet(org.hl7.fhir.r5.model.ValueSet)

Example 34 with ElementDefinition

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

the class JsonSpecGenerator method generateCoreElemSliced.

private void generateCoreElemSliced(List<ElementDefinition> elements, ElementDefinition elem, List<ElementDefinition> children, int indent, String pathName, boolean asValue, TypeRefComponent type, boolean last, boolean complex) throws Exception {
    String name = tail(elem.getPath());
    String en = asValue ? "value[x]" : name;
    if (en.contains("[x]"))
        en = en.replace("[x]", upFirst(type.getWorkingCode()));
    boolean unbounded = elem.hasMax() && elem.getMax().equals("*");
    String indentS = "";
    for (int i = 0; i < indent; i++) {
        indentS += "  ";
    }
    write(indentS);
    List<ElementDefinition> slices = getSlices(elem, children);
    boolean hasContent = slices.size() > 0;
    write("\"<a href=\"" + (defPage + "#" + pathName + "." + en) + "\" title=\"" + Utilities.escapeXml(getEnhancedDefinition(elem)) + "\" class=\"dict\"><span style=\"text-decoration: underline\">" + en + "</span></a>\" : ");
    write("[ // <span style=\"color: navy\">" + describeSlicing(elem.getSlicing()) + "</span> " + (hasContent ? "" : "]"));
    // write(" <span style=\"color: Gray\">//</span>");
    // writeCardinality(elem);
    write("\r\n");
    int c = 0;
    for (ElementDefinition slice : slices) {
        write(indentS + "  ");
        write("{ // <span style=\"color: navy; opacity: 0.8\">" + Utilities.escapeXml(slice.getShort()) + "</span>");
        write(" <span style=\"color: Gray\">//</span>");
        writeCardinality(slice);
        write("\r\n");
        List<ElementDefinition> extchildren = getChildren(elements, slice);
        boolean extcomplex = isComplex(extchildren) && complex;
        if (!extcomplex) {
            write(indentS + "  ");
            write("  // from Element: <a href=\"" + prefix + "extensibility.html\">extension</a>\r\n");
        }
        int cc = 0;
        int l = lastChild(extchildren);
        for (ElementDefinition child : extchildren) if (child.hasSlicing())
            generateCoreElemSliced(elements, child, children, indent + 2, pathName + "." + en, false, child.getType().get(0), ++cc == l, extcomplex);
        else if (wasSliced(child, children))
            // nothing
            ;
        else if (child.getType().size() == 1)
            generateCoreElem(elements, child, indent + 2, pathName + "." + en, false, child.getType().get(0), ++cc == l, extcomplex);
        else {
            write("<span style=\"color: Gray\">// value[x]: <span style=\"color: navy; opacity: 0.8\">" + Utilities.escapeXml(child.getShort()) + "</span>. One of these " + Integer.toString(child.getType().size()) + ":</span>\r\n");
            for (TypeRefComponent t : child.getType()) generateCoreElem(elements, child, indent + 2, pathName + "." + en, false, t, ++cc == l, false);
        }
        c++;
        write(indentS);
        if (c == slices.size())
            write("  }\r\n");
        else
            write("  },\r\n");
    }
    if (hasContent) {
        write(indentS);
        if (last)
            write("]\r\n");
        else
            write("],\r\n");
    }
}
Also used : TypeRefComponent(org.hl7.fhir.r5.model.ElementDefinition.TypeRefComponent) ElementDefinition(org.hl7.fhir.r5.model.ElementDefinition)

Example 35 with ElementDefinition

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

the class MappingsGenerator method generate.

public void generate(StructureDefinition profile) throws IOException {
    if (profile.getMapping().isEmpty())
        mappings = "<p>No Mappings</p>";
    else {
        StringBuilder s = new StringBuilder();
        for (StructureDefinitionMappingComponent map : profile.getMapping()) {
            s.append("<a name=\"" + map.getIdentity() + "\"> </a><h3>" + map.getName() + " (" + map.getUri() + ")</h3>");
            if (map.hasComment())
                s.append("<p>" + Utilities.escapeXml(map.getComment()) + "</p>");
            else if (definitions.getMapTypes().containsKey(map.getUri())) {
                XhtmlNode pre = definitions.getMapTypes().get(map.getUri()).getPreamble();
                if (pre != null)
                    s.append(new XhtmlComposer(XhtmlComposer.HTML).compose(pre));
            }
            s.append("<table class=\"grid\">\r\n");
            s.append(" <tr><td colspan=\"3\"><b>" + Utilities.escapeXml(profile.getName()) + "</b></td></tr>\r\n");
            String path = null;
            for (ElementDefinition e : profile.getSnapshot().getElement()) {
                if (path == null || !e.getPath().startsWith(path)) {
                    path = null;
                    if (e.hasMax() && e.getMax().equals("0")) {
                        path = e.getPath() + ".";
                    } else
                        genElement(s, e, map.getIdentity());
                }
            }
            s.append("</table>\r\n");
        }
        mappings = s.toString();
    }
}
Also used : StructureDefinitionMappingComponent(org.hl7.fhir.r5.model.StructureDefinition.StructureDefinitionMappingComponent) XhtmlComposer(org.hl7.fhir.utilities.xhtml.XhtmlComposer) ElementDefinition(org.hl7.fhir.r5.model.ElementDefinition) XhtmlNode(org.hl7.fhir.utilities.xhtml.XhtmlNode)

Aggregations

ArrayList (java.util.ArrayList)226 ElementDefinition (org.hl7.fhir.r5.model.ElementDefinition)199 DefinitionException (org.hl7.fhir.exceptions.DefinitionException)120 FHIRException (org.hl7.fhir.exceptions.FHIRException)116 StructureDefinition (org.hl7.fhir.r5.model.StructureDefinition)92 ElementDefinition (org.hl7.fhir.r4b.model.ElementDefinition)91 ValidationMessage (org.hl7.fhir.utilities.validation.ValidationMessage)85 ElementDefinition (org.hl7.fhir.dstu3.model.ElementDefinition)82 ElementDefinition (org.hl7.fhir.r4.model.ElementDefinition)68 TypeRefComponent (org.hl7.fhir.r5.model.ElementDefinition.TypeRefComponent)60 CommaSeparatedStringBuilder (org.hl7.fhir.utilities.CommaSeparatedStringBuilder)57 Cell (org.hl7.fhir.utilities.xhtml.HierarchicalTableGenerator.Cell)51 StructureDefinition (org.hl7.fhir.r4b.model.StructureDefinition)50 StructureDefinition (org.hl7.fhir.dstu3.model.StructureDefinition)46 Piece (org.hl7.fhir.utilities.xhtml.HierarchicalTableGenerator.Piece)44 ElementDefinition (org.hl7.fhir.dstu2016may.model.ElementDefinition)42 ElementDefinition (org.hl7.fhir.dstu2.model.ElementDefinition)41 FHIRFormatError (org.hl7.fhir.exceptions.FHIRFormatError)41 XhtmlNode (org.hl7.fhir.utilities.xhtml.XhtmlNode)38 List (java.util.List)37