Search in sources :

Example 46 with Element

use of org.hl7.fhir.r4b.elementmodel.Element in project kindling by HL7.

the class XSDBaseGenerator method genInfrastructure.

private void genInfrastructure(ElementDefn elem) throws Exception {
    enums.clear();
    enumDefs.clear();
    String name = elem.getName();
    write("  <xs:complexType name=\"" + name + "\">\r\n");
    write("    <xs:annotation>\r\n");
    write("      <xs:documentation xml:lang=\"en\">" + Utilities.escapeXml(elem.getDefinition()) + "</xs:documentation>\r\n");
    write("      <xs:documentation xml:lang=\"en\">If the element is present, it must have a value for at least one of the defined elements, an @id referenced from the Narrative, or extensions</xs:documentation>\r\n");
    write("    </xs:annotation>\r\n");
    if (!elem.getName().equals("Base")) {
        write("    <xs:complexContent>\r\n");
        write("      <xs:extension base=\"" + getParentType(elem) + "\">\r\n");
    }
    write("        <xs:sequence>\r\n");
    for (ElementDefn e : elem.getElements()) {
        if (!e.isXmlAttribute()) {
            if (e.getName().equals("[type]"))
                generateAny(elem, e, null, null);
            else
                generateElement(elem, e, null, null);
        }
    }
    write("        </xs:sequence>\r\n");
    for (ElementDefn e : elem.getElements()) {
        if (e.isXmlAttribute()) {
            generateAttribute(elem, e, null);
        }
    }
    if (!elem.getName().equals("Base")) {
        write("      </xs:extension>\r\n");
        write("    </xs:complexContent>\r\n");
    }
    write("  </xs:complexType>\r\n");
    while (!structures.isEmpty()) {
        String s = structures.keySet().iterator().next();
        generateType(elem, s, structures.get(s));
        structures.remove(s);
    }
    for (BindingSpecification en : enums) {
        generateEnum(en);
    }
}
Also used : ElementDefn(org.hl7.fhir.definitions.model.ElementDefn) BindingSpecification(org.hl7.fhir.definitions.model.BindingSpecification)

Example 47 with Element

use of org.hl7.fhir.r4b.elementmodel.Element 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 48 with Element

use of org.hl7.fhir.r4b.elementmodel.Element in project kindling by HL7.

the class JsonSpecGenerator method generateCoreElemDetails.

private void generateCoreElemDetails(ElementDefn elem, int indent, String rootName, String pathName, boolean backbone, boolean last, int width, String en, TypeRef type, boolean doco) throws Exception {
    if (elem.getName().equals("extension")) {
        write("  (<a href=\"" + prefix + "extensibility.html\">Extensions</a> - see <a href=\"" + prefix + "json.html#extensions\">JSON page</a>)\r\n");
        return;
    }
    if (elem.getName().equals("modifierExtension")) {
        write("  (<a href=\"" + prefix + "extensibility.html#modifier\">Modifier Extensions</a> - see <a href=\"" + prefix + "json.html#modifier\">JSON page</a>)\r\n");
        return;
    }
    // 1. name
    for (int i = 0; i < indent; i++) {
        write("  ");
    }
    if (defPage == null) {
        if (elem.isModifier() || elem.isMustSupport())
            write("\"<span style=\"text-decoration: underline\" title=\"" + Utilities.escapeXml(elem.getEnhancedDefinition()) + "\">");
        else
            write("\"<span title=\"" + Utilities.escapeXml(elem.getDefinition()) + "\">");
    } else if (elem.isModifier() || elem.getMustSupport())
        write("\"<a href=\"" + (defPage + "#" + pathName + "." + en) + "\" title=\"" + Utilities.escapeXml(elem.getEnhancedDefinition()) + "\" class=\"dict\"><span style=\"text-decoration: underline\">");
    else
        write("\"<a href=\"" + (defPage + "#" + pathName + "." + en) + "\" title=\"" + Utilities.escapeXml(elem.getDefinition()) + "\" class=\"dict\">");
    if (defPage == null) {
        write(en + "</span>");
    } else if (elem.isModifier() || elem.getMustSupport())
        write(en + "</span></a>");
    else
        write(en + "</a>");
    write("\" : ");
    // 2. value
    boolean delayedCloseArray = false;
    boolean sharedDT = definitions.dataTypeIsSharedInfo(elem.typeCode());
    if (elem.getMaxCardinality() != null && elem.getMaxCardinality() > 1)
        write("[");
    if (elem.usesCompositeType()) {
        write("{ <span style=\"color: darkgreen\">");
        write("Content as for " + elem.typeCode().substring(1) + "</span> }");
    } else if (type == null) {
        // inline definition
        assert (elem.getElements().size() > 0);
        write("{");
        delayedCloseArray = true;
    } else if (type.isXhtml()) {
        // element contains xhtml
        write("\"(Escaped XHTML)\"");
    } else if (definitions.getPrimitives().containsKey(type.getName()) && !type.hasParams()) {
        if (!(type.getName().equals("integer") || type.getName().equals("boolean") || type.getName().equals("decimal")))
            write("\"");
        write("&lt;<span style=\"color: darkgreen\"><a href=\"" + prefix + (dtRoot + definitions.getSrcFile(type.getName()) + ".html#" + type.getName()) + "\">" + type.getName() + "</a></span>&gt;");
        if (!(type.getName().equals("integer") || type.getName().equals("boolean") || type.getName().equals("decimal")))
            write("\"");
    } else {
        write("{");
        width = writeTypeLinks(elem, indent, type);
        write(" }");
    }
    if (!delayedCloseArray && (elem.getMaxCardinality() != null && elem.getMaxCardinality() > 1))
        write("]");
    if (!last && !delayedCloseArray)
        write(",");
    if (!elem.hasFixed() && doco) {
        write(" <span style=\"color: Gray\">//</span>");
        // 3. optionality
        writeCardinality(elem);
        // 4. doco
        write(" ");
        if (elem.getName().equals("extension")) {
            write(" <a href=\"" + prefix + "extensibility.html\"><span style=\"color: navy; opacity: 0.8\">See Extensions</span></a>");
        } else if ("See Extensions".equals(elem.getShortDefn())) {
            write(" <a href=\"" + prefix + "extensibility.html\"><span style=\"color: navy; opacity: 0.8\">" + Utilities.escapeXml(elem.getShortDefn()) + "</span></a>");
        } else {
            String ref = getBindingLink(elem);
            write("<span style=\"color: navy; opacity: 0.8\"><a href=\"" + (Utilities.isAbsoluteUrl(ref) ? "" : prefix) + ref + "\" style=\"color: navy; opacity: 0.8\">" + Utilities.escapeXml(elem.getShortDefn()) + "</a></span>");
        }
    }
    if (elem.getMaxCardinality() != null && elem.getMaxCardinality() == 0)
        write("</span>");
    if (elem.getElements().size() > 0) {
        write("\r\n");
        int c = 0;
        for (ElementDefn child : elem.getElements()) {
            generateCoreElem(child, indent + 1, rootName, pathName + "." + en, backbone, ++c == elem.getElements().size());
        }
        for (int i = 0; i < indent; i++) {
            write("  ");
        }
    }
    if (elem.getElements().size() > 0) {
        write("}");
        if (delayedCloseArray && elem.getMaxCardinality() != null && elem.getMaxCardinality() > 1)
            write("]");
        if (!last && delayedCloseArray)
            write(",");
    }
    write("\r\n");
}
Also used : ElementDefn(org.hl7.fhir.definitions.model.ElementDefn)

Example 49 with Element

use of org.hl7.fhir.r4b.elementmodel.Element in project kindling by HL7.

the class ProfileGenerator method generateLogicalModel.

public StructureDefinition generateLogicalModel(ImplementationGuideDefn igd, ResourceDefn r) throws Exception {
    StructureDefinition p = new StructureDefinition();
    p.setId(r.getRoot().getName());
    p.setUrl("http://hl7.org/fhir/StructureDefinition/" + r.getRoot().getName());
    p.setKind(StructureDefinitionKind.LOGICAL);
    p.setAbstract(false);
    p.setUserData("filename", r.getName().toLowerCase());
    p.setUserData("path", igd.getPrefix() + r.getName().toLowerCase() + ".html");
    p.setTitle(r.getName());
    p.setFhirVersion(version);
    p.setVersion(version.toCode());
    p.setType(r.getRoot().getName());
    ToolingExtensions.setStandardsStatus(p, r.getStatus(), null);
    ToolResourceUtilities.updateUsage(p, igd.getCode());
    p.setName(r.getRoot().getName());
    p.setPublisher("Health Level Seven International" + (r.getWg() == null ? " " + igd.getCommittee() : " (" + r.getWg().getName() + ")"));
    p.addContact().getTelecom().add(Factory.newContactPoint(ContactPointSystem.URL, "http://hl7.org/fhir"));
    if (r.getWg() != null) {
        p.addContact().getTelecom().add(Factory.newContactPoint(ContactPointSystem.URL, r.getWg().getUrl()));
        ToolingExtensions.setCodeExtension(p, ToolingExtensions.EXT_WORKGROUP, r.getWg().getCode());
    }
    p.setDescription("Logical Model: " + r.getDefinition());
    p.setPurpose(r.getRoot().getRequirements());
    if (!p.hasPurpose())
        p.setPurpose(r.getRoot().getRequirements());
    p.setDate(genDate.getTime());
    // DSTU
    p.setStatus(PublicationStatus.fromCode("draft"));
    Set<String> containedSlices = new HashSet<String>();
    // first, the differential
    p.setSnapshot(new StructureDefinitionSnapshotComponent());
    defineElement(null, p, p.getSnapshot().getElement(), r.getRoot(), r.getRoot().getName(), containedSlices, new ArrayList<ProfileGenerator.SliceHandle>(), SnapShotMode.None, true, "Element", "Element", true);
    addElementConstraintToSnapshot(p);
    XhtmlNode div = new XhtmlNode(NodeType.Element, "div");
    div.addText("to do");
    p.setText(new Narrative());
    p.getText().setStatus(NarrativeStatus.GENERATED);
    p.getText().setDiv(div);
    return p;
}
Also used : StructureDefinition(org.hl7.fhir.r5.model.StructureDefinition) Narrative(org.hl7.fhir.r5.model.Narrative) StructureDefinitionSnapshotComponent(org.hl7.fhir.r5.model.StructureDefinition.StructureDefinitionSnapshotComponent) HashSet(java.util.HashSet) XhtmlNode(org.hl7.fhir.utilities.xhtml.XhtmlNode)

Example 50 with Element

use of org.hl7.fhir.r4b.elementmodel.Element in project kindling by HL7.

the class ProfileGenerator method convertElements.

public void convertElements(ElementDefn src, StructureDefinition ed, String path) throws Exception {
    ElementDefinition dst = new ElementDefinition();
    if (!ed.hasDifferential())
        ed.setDifferential(new StructureDefinitionDifferentialComponent());
    ed.getDifferential().getElement().add(dst);
    String thisPath = path == null ? "Extension" : path;
    dst.setId(thisPath);
    dst.setPath(thisPath);
    if (!Utilities.noString(src.getProfileName()))
        dst.setSliceName(src.getProfileName());
    dst.setShort(src.getShortDefn());
    dst.setDefinition(preProcessMarkdown(src.getDefinition(), "Element Definition"));
    dst.setComment(preProcessMarkdown(src.getComments(), "Element Comments"));
    if (src.getMaxCardinality() != null) {
        if (src.getMaxCardinality() == Integer.MAX_VALUE)
            dst.setMax("*");
        else
            dst.setMax(src.getMaxCardinality().toString());
    }
    if (src.getMinCardinality() != null)
        dst.setMin(src.getMinCardinality());
    if (src.getFixed() != null)
        dst.setFixed(src.getFixed());
    if (src.hasMustSupport())
        dst.setMustSupport(src.isMustSupport());
    if (src.hasModifier())
        dst.setIsModifier(src.isModifier());
    if (dst.getIsModifier())
        dst.setIsModifierReason(src.getModifierReason());
    if (src.hasSummaryItem() && dst.getPath().contains("."))
        dst.setIsSummaryElement(Factory.newBoolean(src.isSummary()));
    for (Invariant id : src.getStatedInvariants()) dst.addCondition(id.getId());
    // dDst.
    for (TypeRef t : src.getTypes()) {
        if (t.hasParams()) {
            for (String tp : t.getParams()) {
                if (definitions.hasLogicalModel(tp)) {
                    for (String tpn : definitions.getLogicalModel(tp).getImplementations()) {
                        ElementDefinition.TypeRefComponent type = dst.getType(t.getName());
                        String pr = "http://hl7.org/fhir/StructureDefinition/" + tpn;
                        type.addTargetProfile(pr);
                    }
                } else {
                    ElementDefinition.TypeRefComponent type = dst.getType(t.getName());
                    String pr = t.hasProfile() ? t.getProfile() : // this should only happen if t.getParams().size() == 1
                    "http://hl7.org/fhir/StructureDefinition/" + (tp.equals("Any") ? "Resource" : tp);
                    if (type.getWorkingCode().equals("Reference") || type.getWorkingCode().equals("canonical") || type.getWorkingCode().equals("CodeableReference"))
                        type.addTargetProfile(pr);
                    else
                        type.addProfile(pr);
                }
            }
        } else if (t.isWildcardType()) {
            for (String n : TypesUtilities.wildcardTypes(version.toString())) dst.getType(n);
        } else {
            if (definitions != null && definitions.getConstraints().containsKey(t.getName())) {
                ProfiledType ct = definitions.getConstraints().get(t.getName());
                ElementDefinition.TypeRefComponent type = dst.getType(ct.getBaseType());
                type.addProfile("http://hl7.org/fhir/StructureDefinition/" + ct.getName());
            } else if ("Extension.url".equals(path)) {
            // juat don't populate it
            // ElementDefinition.TypeRefComponent tt = dst.addType();
            // tt.setCodeElement(new UriType());
            // tt.getFormatCommentsPre().add("Note: special primitive values do not have an assigned type. e.g. this is compiler magic. XML, JSON and RDF types provided by extension");
            // ToolingExtensions.addStringExtension(tt.getCodeElement(), ToolingExtensions.EXT_JSON_TYPE, "string");
            // ToolingExtensions.addStringExtension(tt.getCodeElement(), ToolingExtensions.EXT_XML_TYPE, "xs:anyURI");
            // ToolingExtensions.addStringExtension(tt.getCodeElement(), ToolingExtensions.EXT_RDF_TYPE, "xs:anyURI");
            } else {
                ElementDefinition.TypeRefComponent type = dst.getType(t.getName());
                if (t.hasProfile())
                    if (type.getWorkingCode().equals("Reference") || type.getWorkingCode().equals("CodeableReference"))
                        type.addTargetProfile(t.getProfile());
                    else
                        type.addProfile(t.getProfile());
            }
        }
    }
    if (definitions != null) {
        // igtodo - catch this
        for (String mu : definitions.getMapTypes().keySet()) {
            if (src.hasMapping(mu)) {
                addMapping(ed, dst, mu, src.getMapping(mu), null);
            }
        }
    }
    for (String in : src.getInvariants().keySet()) {
        ElementDefinitionConstraintComponent con = new ElementDefinitionConstraintComponent();
        Invariant inv = src.getInvariants().get(in);
        con.setKey(inv.getId());
        if (!con.hasKey()) {
            extensionCounter++;
            con.setKey("exd-" + Integer.toString(extensionCounter));
        }
        con.setRequirements(inv.getRequirements());
        if (Utilities.noString(inv.getSeverity()))
            con.setSeverity(ConstraintSeverity.ERROR);
        else
            con.setSeverity(ConstraintSeverity.fromCode(inv.getSeverity()));
        con.setHuman(inv.getEnglish());
        con.setXpath(inv.getXpath());
        if (!"n/a".equals(inv.getExpression()))
            con.setExpression(inv.getExpression());
        dst.getConstraint().add(con);
    }
    if (src.hasBinding())
        dst.setBinding(generateBinding(src.getBinding()));
    if (src.getElements().isEmpty()) {
        if (path == null)
            throw new Exception("?error parsing extension");
    } else {
        ElementDefn url = src.getElements().get(0);
        if (!url.getName().equals("url"))
            throw new Exception("first child of extension should be 'url', not " + url.getName() + " for structure definition " + ed.getUrl());
        convertElements(url, ed, thisPath + ".url");
        // this pair might leave elements out of order, but we're going to sort them later
        if (!hasValue(src)) {
            ElementDefn value = new ElementDefn();
            value.setName("value[x]");
            value.setMinCardinality(0);
            value.setMaxCardinality(0);
            convertElements(value, ed, thisPath + ".value[x]");
        } else {
            ElementDefn ext = new ElementDefn();
            // can't have an extension if you have a value
            ext.setName("extension");
            ext.setMaxCardinality(0);
            convertElements(ext, ed, thisPath + ".extension");
        }
        if (src.getElements().size() == 2 && src.getElements().get(0).getName().equals("url") && src.getElements().get(1).getName().equals("value[x]")) {
            ElementDefn value = src.getElements().get(1);
            value.setMinCardinality(1);
            convertElements(value, ed, thisPath + ".value[x]");
        } else {
            for (ElementDefn child : src.getElements()) {
                if (child != url) {
                    if (child.getName().startsWith("value") && !child.getName().startsWith("valueSet"))
                        convertElements(child, ed, thisPath + "." + child.getName());
                    else {
                        if (child.getElements().size() == 0 || !child.getElements().get(0).getName().equals("url")) {
                            ElementDefn childUrl = new ElementDefn();
                            childUrl.setName("url");
                            childUrl.setXmlAttribute(true);
                            childUrl.getTypes().add(new TypeRef("uri"));
                            childUrl.setFixed(new UriType(child.getName()));
                            child.getElements().add(0, childUrl);
                        }
                        if (!hasValue(child)) {
                            ElementDefn value = new ElementDefn();
                            value.setName("value[x]");
                            value.setMinCardinality(0);
                            value.setMaxCardinality(0);
                            child.getElements().add(value);
                        }
                        convertElements(child, ed, thisPath + ".extension");
                    }
                }
            }
        }
    }
}
Also used : Invariant(org.hl7.fhir.definitions.model.Invariant) ProfiledType(org.hl7.fhir.definitions.model.ProfiledType) TypeRefComponent(org.hl7.fhir.r5.model.ElementDefinition.TypeRefComponent) TypeRef(org.hl7.fhir.definitions.model.TypeRef) StructureDefinitionDifferentialComponent(org.hl7.fhir.r5.model.StructureDefinition.StructureDefinitionDifferentialComponent) ElementDefn(org.hl7.fhir.definitions.model.ElementDefn) ElementDefinition(org.hl7.fhir.r5.model.ElementDefinition) TypeRefComponent(org.hl7.fhir.r5.model.ElementDefinition.TypeRefComponent) ElementDefinitionConstraintComponent(org.hl7.fhir.r5.model.ElementDefinition.ElementDefinitionConstraintComponent) FHIRException(org.hl7.fhir.exceptions.FHIRException) URISyntaxException(java.net.URISyntaxException) UriType(org.hl7.fhir.r5.model.UriType)

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