Search in sources :

Example 41 with Element

use of org.hl7.fhir.dstu2016may.model.Element 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 42 with Element

use of org.hl7.fhir.dstu2016may.model.Element 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 43 with Element

use of org.hl7.fhir.dstu2016may.model.Element in project kindling by HL7.

the class XSDBaseGenerator method generateElement.

private void generateElement(ElementDefn root, ElementDefn e, String paramType, Map<String, String> rules) throws Exception {
    List<TypeRef> types = e.getTypes();
    if (types.size() > 1 || (types.size() == 1 && types.get(0).isWildcardType())) {
        if (!e.getName().contains("[x]"))
            throw new Exception("Element has multiple types as a choice doesn't have a [x] in the element name '" + e.getName() + "' in resource " + root.getName());
        if ((types.size() == 1 && types.get(0).isWildcardType())) {
            generateAny(root, e, e.getName().replace("[x]", ""), null);
        } else {
            String close = " minOccurs=\"0\">";
            ;
            if (!forCodeGeneration) {
                write("          <xs:choice minOccurs=\"" + checkRule(e.getMinCardinality().toString(), e.getName() + ".min", rules) + "\" maxOccurs=\"1\">\r\n");
                if (e.hasDefinition()) {
                    write("            <xs:annotation>\r\n");
                    write("              <xs:documentation xml:lang=\"en\">" + Utilities.escapeXml(checkRule(e.getDefinition(), e.getName() + ".defn", rules)) + "</xs:documentation>\r\n");
                    write("            </xs:annotation>\r\n");
                }
                close = "/>";
            }
            for (TypeRef t : types) {
                String type = encodeType(e, t, true);
                String name = e.getName().substring(0, e.getName().length() - 3) + nameForType(type);
                write("           <xs:element name=\"" + name + "\" type=\"" + type + "\" ");
                if (e.unbounded())
                    write(" maxOccurs=\"" + checkRule("unbounded", e.getName() + ".max", rules) + "\"" + close + "\r\n");
                else
                    write(" maxOccurs=\"" + checkRule("1", e.getName() + ".max", rules) + "\"" + close + "\r\n");
                if (forCodeGeneration) {
                    write("              <xs:annotation>\r\n");
                    if (e.hasDefinition()) {
                        write("                <xs:documentation xml:lang=\"en\">" + Utilities.escapeXml(checkRule(e.getDefinition(), e.getName() + ".defn", rules)) + " (choose any one of " + e.getName().replace("[x]", "") + "*, but only one)</xs:documentation>\r\n");
                    } else {
                        write("                <xs:documentation xml:lang=\"en\">(choose any one of " + e.getName().replace("[x]", "") + "*, but only one)</xs:documentation>\r\n");
                    }
                    write("              </xs:annotation>\r\n");
                    write("             </xs:element>\r\n");
                }
            }
            if (!forCodeGeneration)
                write("          </xs:choice>\r\n");
        }
    } else {
        write("          ");
        if ("extension".equals(e.getName()))
            write("<xs:element name=\"" + e.getName() + "\" type=\"Extension\" ");
        else if ("div".equals(e.getName()) && e.typeCode().equals("xhtml"))
            write("<xs:element ref=\"xhtml:div\" ");
        else if (e.usesCompositeType()) {
            ElementDefn ref = root.getElementByName(definitions, e.typeCode().substring(1), true, false, null);
            String rtn = this.types.get(ref);
            if (rtn == null)
                throw new Exception("logic error in schema generator (null composite reference in " + types.toString() + ")");
            write("<xs:element name=\"" + e.getName() + "\" type=\"" + rtn + "\" ");
        } else if (types.size() == 0 && e.getElements().size() > 0) {
            String tn = root.getName() + "." + Utilities.capitalize(e.getName());
            int i = 0;
            while (typenames.contains(tn)) {
                i++;
                tn = root.getName() + "." + Utilities.capitalize(e.getName()) + Integer.toString(i);
            }
            write("<xs:element name=\"" + e.getName() + "\" type=\"" + tn + "\" ");
            structures.put(tn, e);
            this.types.put(e, tn);
            typenames.add(tn);
        } else if (types.size() == 1) {
            if (types.get(0).isUnboundGenericParam() && paramType != null)
                write("<xs:element name=\"" + e.getName() + "\" type=\"" + paramType + "\" ");
            else if (!Utilities.noString(e.getRegex())) {
                String tn = root.getName() + Utilities.capitalize(e.getName()) + "Type";
                regexQueue.put(tn, e.getRegex());
                write("<xs:element name=\"" + e.getName() + "\" type=\"" + tn + "\" ");
            } else
                write("<xs:element name=\"" + e.getName() + "\" type=\"" + encodeType(e, types.get(0), true) + "\" ");
        } else
            throw new Exception("how do we get here? " + e.getName() + " in " + root.getName() + " " + Integer.toString(types.size()));
        write("minOccurs=\"" + checkRule(e.getMinCardinality().toString(), e.getName() + ".min", rules) + "\"");
        if (e.unbounded())
            write(" maxOccurs=\"" + checkRule("unbounded", e.getName() + ".max", rules) + "\"");
        else
            write(" maxOccurs=\"" + checkRule("1", e.getName() + ".max", rules) + "\"");
        if (e.hasDefinition()) {
            write(">\r\n");
            write("            <xs:annotation>\r\n");
            write("              <xs:documentation xml:lang=\"en\">" + Utilities.escapeXml(checkRule(e.getDefinition(), e.getName() + ".defn", rules)) + "</xs:documentation>\r\n");
            write("            </xs:annotation>\r\n");
            write("          </xs:element>\r\n");
        } else {
            write("/>\r\n");
        }
    }
}
Also used : TypeRef(org.hl7.fhir.definitions.model.TypeRef) ElementDefn(org.hl7.fhir.definitions.model.ElementDefn) IOException(java.io.IOException) UnsupportedEncodingException(java.io.UnsupportedEncodingException)

Example 44 with Element

use of org.hl7.fhir.dstu2016may.model.Element in project kindling by HL7.

the class XSDGenerator method generateType.

private void generateType(ElementDefn root, String name, ElementDefn struc, boolean isResource) throws IOException, Exception {
    write("  <xs:complexType name=\"" + name + "\">\r\n");
    write("    <xs:annotation>\r\n");
    write("      <xs:documentation xml:lang=\"en\">" + Utilities.escapeXml(root.getDefinition()) + "</xs:documentation>\r\n");
    if (isResource)
        write("      <xs:documentation xml:lang=\"en\">If the element is present, it must have either a @value, an @id, or extensions</xs:documentation>\r\n");
    write("    </xs:annotation>\r\n");
    write("    <xs:complexContent>\r\n");
    if (isResource)
        write("      <xs:extension base=\"" + root.typeCode() + "\">\r\n");
    else
        write("      <xs:extension base=\"BackboneElement\">\r\n");
    write("        <xs:sequence>\r\n");
    for (ElementDefn e : struc.getElements()) {
        if (e.getName().equals("[type]"))
            generateAny(root, e);
        else
            generateElement(root, e);
    }
    write("        </xs:sequence>\r\n");
    write("      </xs:extension>\r\n");
    write("    </xs:complexContent>\r\n");
    write("  </xs:complexType>\r\n");
}
Also used : ElementDefn(org.hl7.fhir.definitions.model.ElementDefn)

Example 45 with Element

use of org.hl7.fhir.dstu2016may.model.Element in project kindling by HL7.

the class XSDGenerator method generateEnum.

private void generateEnum(String en) throws IOException {
    if (allenums.contains(en))
        return;
    allenums.add(en);
    write("  <xs:simpleType name=\"" + en + "-list\">\r\n");
    write("    <xs:restriction base=\"code-primitive\">\r\n");
    ValueSet vs = enums.get(en);
    vs.setUserData(ToolResourceUtilities.NAME_VS_USE_MARKER, true);
    ValueSet ex = workerContext.expandVS(vs, true, false).getValueset();
    for (ValueSetExpansionContainsComponent cc : ex.getExpansion().getContains()) {
        genIncludedCode(cc);
    }
    write("    </xs:restriction>\r\n");
    write("  </xs:simpleType>\r\n");
    write("  <xs:complexType name=\"" + en + "\">\r\n");
    write("    <xs:annotation>\r\n");
    write("      <xs:documentation xml:lang=\"en\">" + Utilities.escapeXml(enumDefs.get(en)) + "</xs:documentation>\r\n");
    write("      <xs:documentation xml:lang=\"en\">If the element is present, it must have either a @value, an @id, or extensions</xs:documentation>\r\n");
    write("    </xs:annotation>\r\n");
    write("    <xs:complexContent>\r\n");
    write("      <xs:extension base=\"Element\">\r\n");
    write("        <xs:attribute name=\"value\" type=\"" + en + "-list\" use=\"optional\"/>\r\n");
    write("      </xs:extension>\r\n");
    write("    </xs:complexContent>\r\n");
    write("  </xs:complexType>\r\n");
}
Also used : ValueSetExpansionContainsComponent(org.hl7.fhir.r5.model.ValueSet.ValueSetExpansionContainsComponent) ValueSet(org.hl7.fhir.r5.model.ValueSet)

Aggregations

Complex (org.hl7.fhir.r4.utils.formats.Turtle.Complex)659 Complex (org.hl7.fhir.dstu2016may.formats.RdfGenerator.Complex)488 Complex (org.hl7.fhir.dstu3.utils.formats.Turtle.Complex)486 ArrayList (java.util.ArrayList)240 FHIRException (org.hl7.fhir.exceptions.FHIRException)162 Element (org.hl7.fhir.r5.elementmodel.Element)98 IOException (java.io.IOException)97 DefinitionException (org.hl7.fhir.exceptions.DefinitionException)91 ElementDefinition (org.hl7.fhir.r5.model.ElementDefinition)84 StructureDefinition (org.hl7.fhir.r5.model.StructureDefinition)84 Element (org.w3c.dom.Element)74 JsonElement (com.google.gson.JsonElement)62 FHIRFormatError (org.hl7.fhir.exceptions.FHIRFormatError)61 XhtmlNode (org.hl7.fhir.utilities.xhtml.XhtmlNode)60 HashSet (java.util.HashSet)53 SpecialElement (org.hl7.fhir.r5.elementmodel.Element.SpecialElement)49 NamedElement (org.hl7.fhir.r5.elementmodel.ParserBase.NamedElement)48 Cell (org.hl7.fhir.utilities.xhtml.HierarchicalTableGenerator.Cell)47 CommaSeparatedStringBuilder (org.hl7.fhir.utilities.CommaSeparatedStringBuilder)46 IndexedElement (org.hl7.fhir.validation.instance.utils.IndexedElement)43