Search in sources :

Example 31 with ElementDefn

use of org.hl7.fhir.definitions.model.ElementDefn in project kindling by HL7.

the class TerminologyNotesGenerator method scan.

private void scan(ElementDefn e, String path) throws Exception {
    if (e.hasBinding()) {
        BindingSpecification cd = e.getBinding();
        if (!txusages.containsKey(cd)) {
            txusages.put(cd, new ArrayList<CDUsage>());
            c++;
            txusages.get(cd).add(new CDUsage(String.valueOf(c), null));
        }
        txusages.get(cd).add(new CDUsage(path, e));
    }
    for (ElementDefn c : e.getElements()) {
        scan(c, path + "." + c.getName());
    }
}
Also used : BindingSpecification(org.hl7.fhir.definitions.model.BindingSpecification) ElementDefn(org.hl7.fhir.definitions.model.ElementDefn)

Example 32 with ElementDefn

use of org.hl7.fhir.definitions.model.ElementDefn 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 33 with ElementDefn

use of org.hl7.fhir.definitions.model.ElementDefn in project kindling by HL7.

the class TurtleSpecGenerator method generateCoreElem.

private void generateCoreElem(ElementDefn elem, int indent, String path, boolean backbone) throws Exception {
    String left = Utilities.padLeft("", ' ', indent * 2);
    if (isChoice(elem)) {
        write(left + "# ");
        String en = elem.getName();
        writeElementName(elem, path, en);
        write(": ");
        write(elem.describeCardinality());
        write(" <span style=\"color: navy\">");
        write(Utilities.escapeXml(elem.getShortDefn()));
        write("</span>");
        List<TypeRef> tl = getTypes(elem);
        write(". One of these ");
        write(Integer.toString(tl.size()));
        write("\r\n");
        for (TypeRef t : tl) {
            generateElementType(elem, path, left + "  ", t, elem.getName().replace("[x]", Utilities.capitalize(t.getName())));
            write("\r\n");
        }
    } else if (elem.getTypes().size() == 1) {
        TypeRef t = elem.getTypes().get(0);
        String en = elem.getName();
        generateElementType(elem, path, left, t, en);
        if (elem.getMaxCardinality() > 1)
            write(", ... ; # ");
        else
            write("; # ");
        write(elem.describeCardinality());
        write(" <span style=\"color: navy\">");
        write(Utilities.escapeXml(elem.getShortDefn()));
        write("</span>\r\n");
    } else {
        // children elements
        write(left + "fhir:");
        String en = elem.getName();
        writeElementName(elem, path, en);
        write("[ # ");
        write(elem.describeCardinality());
        write(" <span style=\"color: navy\">");
        write(Utilities.escapeXml(elem.getShortDefn()));
        write("</span>\r\n");
        for (ElementDefn child : elem.getElements()) {
            generateCoreElem(child, indent + 1, path + "." + en, backbone);
        }
        if (elem.getMaxCardinality() > 1)
            write(left + "], ...;\r\n");
        else
            write(left + "];\r\n");
    }
}
Also used : TypeRef(org.hl7.fhir.definitions.model.TypeRef) ElementDefn(org.hl7.fhir.definitions.model.ElementDefn)

Example 34 with ElementDefn

use of org.hl7.fhir.definitions.model.ElementDefn 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 35 with ElementDefn

use of org.hl7.fhir.definitions.model.ElementDefn in project kindling by HL7.

the class XmlSpecGenerator method getInvariants.

private String getInvariants(ElementDefn elem) {
    StringBuilder b = new StringBuilder();
    boolean first = true;
    for (Invariant i : elem.getStatedInvariants()) {
        if (!first)
            b.append("; ");
        first = false;
        b.append(i.getId() + ": " + i.getEnglish());
    }
    return b.toString();
}
Also used : Invariant(org.hl7.fhir.definitions.model.Invariant) CommaSeparatedStringBuilder(org.hl7.fhir.utilities.CommaSeparatedStringBuilder)

Aggregations

ElementDefn (org.hl7.fhir.definitions.model.ElementDefn)100 TypeRef (org.hl7.fhir.definitions.model.TypeRef)35 ArrayList (java.util.ArrayList)28 FHIRException (org.hl7.fhir.exceptions.FHIRException)28 CommaSeparatedStringBuilder (org.hl7.fhir.utilities.CommaSeparatedStringBuilder)21 ResourceDefn (org.hl7.fhir.definitions.model.ResourceDefn)19 Invariant (org.hl7.fhir.definitions.model.Invariant)16 IOException (java.io.IOException)14 BindingSpecification (org.hl7.fhir.definitions.model.BindingSpecification)11 FileNotFoundException (java.io.FileNotFoundException)10 URISyntaxException (java.net.URISyntaxException)10 StructureDefinition (org.hl7.fhir.r5.model.StructureDefinition)10 ProfiledType (org.hl7.fhir.definitions.model.ProfiledType)9 TransformerException (javax.xml.transform.TransformerException)8 ElementDefinition (org.hl7.fhir.r5.model.ElementDefinition)8 TransformerConfigurationException (javax.xml.transform.TransformerConfigurationException)7 NotImplementedException (org.apache.commons.lang3.NotImplementedException)7 UcumException (org.fhir.ucum.UcumException)7 TypeParser (org.hl7.fhir.definitions.parsers.TypeParser)7 DefinitionException (org.hl7.fhir.exceptions.DefinitionException)7