Search in sources :

Example 56 with Extension

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

the class TurtleSpecGenerator method renderType.

private int renderType(int indent, int w, TypeRef t) throws IOException {
    if (t.isXhtml())
        write("fhir:value \"[escaped xhtml]\"^^xsd:string");
    else if (t.getName().startsWith("@"))
        write("<a href=\"#ttl-" + t.getName().substring(1) + "\"><span style=\"color: DarkViolet\">See " + t.getName().substring(1) + "</span></a>");
    else if (definitions.getConstraints().containsKey(t.getName())) {
        ProfiledType pt = definitions.getConstraints().get(t.getName());
        write("<a href=\"" + (dtRoot + definitions.getSrcFile(pt.getBaseType()) + ".html#" + pt.getBaseType() + "\">" + pt.getBaseType()) + "</a>");
        w = w + pt.getBaseType().length() + 2;
        write("(<a style=\"color:navy\" href=\"" + (dtRoot + definitions.getSrcFile(t.getName()) + ".html#" + t.getName() + "\">" + t.getName()) + "</a>)");
    } else
        write("<a href=\"" + (dtRoot + definitions.getSrcFile(t.getName()) + ".html#" + t.getName() + "\">" + t.getName()) + "</a>");
    if (t.hasParams()) {
        write("(");
        boolean firstp = true;
        List<String> ap = new ArrayList<>();
        for (String p : t.getParams()) {
            if (definitions.hasLogicalModel(p))
                ap.addAll(definitions.getLogicalModel(p).getImplementations());
            else
                ap.add(p);
        }
        Collections.sort(ap);
        for (String p : ap) {
            if (!firstp) {
                write("|");
                w++;
            }
            // again, p.length() could be wrong if this is an extension, but then it won't wrap
            if (w + p.length() > 80) {
                write("\r\n  ");
                for (int j = 0; j < indent; j++) write(" ");
                w = indent + 2;
            }
            w = w + p.length();
            // TODO: Display action and/or profile information
            if (p.equals("Any")) {
                write("<a href=\"" + prefix + "resourcelist.html" + "\">" + p + "</a>");
            } else if (t.getName().equals("Reference") && t.getParams().size() == 1 && !Utilities.noString(t.getProfile()))
                write("<a href=\"" + prefix + t.getProfile() + "\"><span style=\"color: DarkViolet\">@" + t.getProfile().substring(1) + "</span></a>");
            else
                write("<a href=\"" + (dtRoot + definitions.getSrcFile(p) + ".html#" + p) + "\">" + p + "</a>");
            firstp = false;
        }
        write(")");
        w++;
    }
    return w;
}
Also used : ProfiledType(org.hl7.fhir.definitions.model.ProfiledType) ArrayList(java.util.ArrayList)

Example 57 with Extension

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

the class TurtleSpecGenerator method generateInner.

private void generateInner(ElementDefn root, boolean resource, boolean isAbstract) throws IOException, Exception {
    String rn;
    if (root.getName().equals("Extension"))
        rn = "extension|modifierExtension";
    else if (root.getName().equals("Meta"))
        rn = "meta";
    else if (root.getTypes().size() > 0 && (root.getTypes().get(0).getName().equals("Type") || (root.getTypes().get(0).getName().equals("Structure"))) || isAbstract)
        rn = "[name]";
    else
        rn = root.getName();
    write("@prefix fhir: &lt;http://hl7.org/fhir/&gt; .");
    if (resource)
        write("<span style=\"float: right\"><a title=\"Documentation for this format\" href=\"" + prefix + "rdf.html\"><img src=\"" + prefix + "help.png\" alt=\"doco\"/></a></span>\r\n");
    write("\r\n");
    write("\r\n");
    if (resource) {
        write("[ a fhir:");
        if (defPage == null)
            write("<span title=\"" + Utilities.escapeXml(root.getDefinition()) + "\"><b>");
        else
            write("<a href=\"" + (defPage + "#" + root.getName()) + "\" title=\"" + Utilities.escapeXml(root.getDefinition()) + "\" class=\"dict\"><b>");
        write(rn);
        if ((defPage == null))
            write("</b></span>;");
        else
            write("</b></a>;");
        write("\r\n  fhir:nodeRole fhir:treeRoot; # if this is the parser root\r\n");
    } else
        write("[");
    write("\r\n");
    if (rn.equals(root.getName()) && resource) {
        if (!Utilities.noString(root.typeCode())) {
            write("  # from <a href=\"" + prefix + "resource.html\">Resource</a>: <a href=\"" + prefix + "resource.html#id\">.id</a>, <a href=\"" + prefix + "resource.html#meta\">.meta</a>, <a href=\"" + prefix + "resource.html#implicitRules\">.implicitRules</a>, and <a href=\"" + prefix + "resource.html#language\">.language</a>\r\n");
            if (root.typeCode().equals("DomainResource"))
                write("  # from <a href=\"" + prefix + "domainresource.html\">DomainResource</a>: <a href=\"" + prefix + "narrative.html#Narrative\">.text</a>, <a href=\"" + prefix + "references.html#contained\">.contained</a>, <a href=\"" + prefix + "extensibility.html\">.extension</a>, and <a href=\"" + prefix + "extensibility.html#modifierExtension\">.modifierExtension</a>\r\n");
        }
    } else {
        if (root.typeCode().equals("BackboneElement"))
            write(" # from BackboneElement: <a href=\"" + prefix + "extensibility.html\">Element.extension</a>, <a href=\"" + prefix + "extensibility.html\">BackboneElement.modifierextension</a>\r\n");
        else
            write(" # from Element: <a href=\"" + prefix + "extensibility.html\">Element.extension</a>\r\n");
    }
    for (ElementDefn elem : root.getElements()) {
        generateCoreElem(elem, 1, root.getName(), rn.equals(root.getName()) && resource);
    }
    write("]\r\n");
}
Also used : ElementDefn(org.hl7.fhir.definitions.model.ElementDefn)

Example 58 with Extension

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

the class Regenerator method generateOperation.

private void generateOperation(String root, ResourceDefn r, Operation op) throws IOException {
    OperationDefinition opd = op.getResource().copy();
    opd.setId(r.getName() + "-" + op.getName());
    opd.setUrl("http://hl7.org/fhir/build/OperationDefinition/" + opd.getId());
    if (!Utilities.noString(op.getFooter())) {
        opd.addExtension(BuildExtensions.EXT_FOOTER, new MarkdownType(op.getFooter()));
    }
    if (!Utilities.noString(op.getFooter2())) {
        opd.addExtension(BuildExtensions.EXT_FOOTER2, new MarkdownType(op.getFooter2()));
    }
    for (OperationExample opex : op.getExamples()) {
        Extension ex = new Extension(BuildExtensions.EXT_OP_EXAMPLE);
        if (!Utilities.noString(opex.getContent())) {
            ex.addExtension(BuildExtensions.EXT_OP_EXAMPLE_CONTENT, new StringType(opex.getContent()));
        }
        if (!Utilities.noString(opex.getComment())) {
            ex.addExtension(BuildExtensions.EXT_OP_EXAMPLE_COMMENT, new StringType(opex.getComment()));
        }
        ex.addExtension(BuildExtensions.EXT_OP_EXAMPLE_RESPONSE, new BooleanType(opex.isResponse()));
        ex.addExtension(BuildExtensions.EXT_OP_EXAMPLE_LIST, new IntegerType(1));
        opd.addExtension(ex);
    }
    for (OperationExample opex : op.getExamples2()) {
        Extension ex = new Extension(BuildExtensions.EXT_OP_EXAMPLE);
        if (!Utilities.noString(opex.getContent())) {
            ex.addExtension(BuildExtensions.EXT_OP_EXAMPLE_CONTENT, new StringType(opex.getContent()));
        }
        if (!Utilities.noString(opex.getComment())) {
            ex.addExtension(BuildExtensions.EXT_OP_EXAMPLE_COMMENT, new StringType(opex.getComment()));
        }
        ex.addExtension(BuildExtensions.EXT_OP_EXAMPLE_RESPONSE, new BooleanType(opex.isResponse()));
        ex.addExtension(BuildExtensions.EXT_OP_EXAMPLE_LIST, new IntegerType(2));
        opd.addExtension(ex);
    }
    File fn = new File(Utilities.path(root, opd.fhirType().toLowerCase() + "-" + opd.getId() + ".gen.xml"));
    new XmlParser().setOutputStyle(OutputStyle.PRETTY).compose(new FileOutputStream(fn), opd);
    fn.setLastModified(r.getTimestamp());
}
Also used : Extension(org.hl7.fhir.r5.model.Extension) IntegerType(org.hl7.fhir.r5.model.IntegerType) XmlParser(org.hl7.fhir.r5.formats.XmlParser) OperationExample(org.hl7.fhir.definitions.model.Operation.OperationExample) StringType(org.hl7.fhir.r5.model.StringType) FileOutputStream(java.io.FileOutputStream) BooleanType(org.hl7.fhir.r5.model.BooleanType) MarkdownType(org.hl7.fhir.r5.model.MarkdownType) OperationDefinition(org.hl7.fhir.r5.model.OperationDefinition) File(java.io.File)

Example 59 with Extension

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

the class XmlSpecGenerator method writeTypeLinks.

private int writeTypeLinks(ElementDefn elem, int indent) throws Exception {
    write(" <span style=\"color: darkgreen\">");
    int i = 0;
    // this is wrong if the type is an attribute, but the wrapping concern shouldn't apply in this case, so this is ok
    int w = indent + 12 + elem.getName().length();
    for (TypeRef t : elem.getTypes()) {
        if (i > 0) {
            write("|");
            w++;
        }
        if (w + t.getName().length() > 80) {
            write("\r\n  ");
            for (int j = 0; j < indent; j++) write(" ");
            w = indent + 2;
        }
        // again, could be wrong if this is an extension, but then it won't wrap
        w = w + t.getName().length();
        if (t.isXhtml() || t.getName().equals("list"))
            write(t.getName());
        else if (t.getName().equals("Extension") && t.getParams().size() == 0 && !Utilities.noString(t.getProfile()))
            write("<a href=\"" + prefix + t.getProfile() + "\"><span style=\"color: DarkViolet\">@" + t.getProfile().substring(1) + "</span></a>");
        else if (definitions.getConstraints().containsKey(t.getName())) {
            ProfiledType pt = definitions.getConstraints().get(t.getName());
            write("<a href=\"" + (dtRoot + definitions.getSrcFile(pt.getBaseType()) + ".html#" + pt.getBaseType() + "\">" + pt.getBaseType()) + "</a>");
            w = w + pt.getBaseType().length() + 2;
            write("(<a style=\"color:navy\" href=\"" + (dtRoot + definitions.getSrcFile(t.getName()) + ".html#" + t.getName() + "\">" + t.getName()) + "</a>)");
        } else
            write("<a href=\"" + (dtRoot + definitions.getSrcFile(t.getName()) + ".html#" + t.getName() + "\">" + t.getName()) + "</a>");
        if (t.hasParams()) {
            write("(");
            boolean firstp = true;
            List<String> ap = new ArrayList<>();
            for (String p : t.getParams()) {
                if (definitions.hasLogicalModel(p))
                    ap.addAll(definitions.getLogicalModel(p).getImplementations());
                else
                    ap.add(p);
            }
            Collections.sort(ap);
            for (String p : ap) {
                if (!firstp) {
                    write("|");
                    w++;
                }
                // again, p.length() could be wrong if this is an extension, but then it won't wrap
                if (w + p.length() > 80) {
                    write("\r\n  ");
                    for (int j = 0; j < indent; j++) write(" ");
                    w = indent + 2;
                }
                w = w + p.length();
                // TODO: Display action and/or profile information
                if (p.equals("Any")) {
                    write("<a href=\"" + prefix + "resourcelist.html" + "\">" + p + "</a>");
                } else if (t.getName().equals("Reference") && t.getParams().size() == 1 && !Utilities.noString(t.getProfile()))
                    write("<a href=\"" + prefix + t.getProfile() + "\"><span style=\"color: DarkViolet\">@" + t.getProfile().substring(1) + "</span></a>");
                else
                    write("<a href=\"" + (dtRoot + definitions.getSrcFile(p) + ".html#" + p) + "\">" + p + "</a>");
                firstp = false;
            }
            write(")");
            w++;
        }
        i++;
    }
    write("</span>");
    return w;
}
Also used : ProfiledType(org.hl7.fhir.definitions.model.ProfiledType) TypeRef(org.hl7.fhir.definitions.model.TypeRef) ArrayList(java.util.ArrayList)

Example 60 with Extension

use of org.hl7.fhir.r4.model.Extension 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("&lt;!-- " + 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)

Aggregations

Extension (org.hl7.fhir.r4.model.Extension)154 ArrayList (java.util.ArrayList)104 Coding (org.hl7.fhir.r4.model.Coding)69 Test (org.junit.jupiter.api.Test)69 Extension (org.hl7.fhir.dstu3.model.Extension)67 FHIRException (org.hl7.fhir.exceptions.FHIRException)55 StructureDefinition (org.hl7.fhir.r5.model.StructureDefinition)46 ElementDefinition (org.hl7.fhir.r5.model.ElementDefinition)42 Extension (org.hl7.fhir.r5.model.Extension)41 XhtmlNode (org.hl7.fhir.utilities.xhtml.XhtmlNode)39 Test (org.junit.Test)36 Cell (org.hl7.fhir.utilities.xhtml.HierarchicalTableGenerator.Cell)35 List (java.util.List)34 CodeableConcept (org.hl7.fhir.r4.model.CodeableConcept)34 Date (java.util.Date)30 Coding (org.hl7.fhir.dstu3.model.Coding)29 Piece (org.hl7.fhir.utilities.xhtml.HierarchicalTableGenerator.Piece)27 Row (org.hl7.fhir.utilities.xhtml.HierarchicalTableGenerator.Row)27 Reference (org.hl7.fhir.dstu3.model.Reference)26 Patient (org.hl7.fhir.r4.model.Patient)26