Search in sources :

Example 16 with TypeRef

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

the class ElementDefn method typeCodeBase.

public String typeCodeBase() {
    List<String> ts = new ArrayList<>();
    for (TypeRef t : types) {
        ts.add(t.getName());
    }
    Collections.sort(ts);
    CommaSeparatedStringBuilder b = new CommaSeparatedStringBuilder();
    for (String t : ts) b.append(t);
    return b.toString();
}
Also used : TypeRef(org.hl7.fhir.definitions.model.TypeRef) ArrayList(java.util.ArrayList) CommaSeparatedStringBuilder(org.hl7.fhir.utilities.CommaSeparatedStringBuilder)

Example 17 with TypeRef

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

the class ElementDefn method typeCode.

public String typeCode() {
    StringBuilder tn = new StringBuilder();
    boolean first = true;
    for (TypeRef t : types) {
        if (!first)
            tn.append("|");
        first = false;
        tn.append(t.getName());
        if (t.hasParams()) {
            tn.append("(");
            boolean f = true;
            for (String s : t.getParams()) {
                if (!f)
                    tn.append("|");
                f = false;
                tn.append(s);
            }
            tn.append(")");
        }
    }
    return tn.toString();
}
Also used : CommaSeparatedStringBuilder(org.hl7.fhir.utilities.CommaSeparatedStringBuilder) TypeRef(org.hl7.fhir.definitions.model.TypeRef)

Example 18 with TypeRef

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

the class XVerPathsGenerator method process.

private void process(ElementDefn ed, String path) {
    ElementInfo ei = new ElementInfo();
    ei.path = path;
    r5List.add(ei);
    ElementInfo r4 = r4List.get(path);
    if (ed.getTypes().size() > 0) {
        // leaf
        for (TypeRef tr : ed.getTypes()) {
            if (r4 == null || !r4.types.contains(tr.summary())) {
                ei.types.add(tr.summary());
            }
        }
    } else {
        for (ElementDefn child : ed.getElements()) {
            if (r4 == null || !r4.elements.contains(child.getName())) {
                ei.elements.add(child.getName());
            }
            process(child, path + "." + child.getName());
        }
    }
}
Also used : TypeRef(org.hl7.fhir.definitions.model.TypeRef) ElementDefn(org.hl7.fhir.definitions.model.ElementDefn)

Example 19 with TypeRef

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

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

the class ProfileGenerator method genUml.

private void genUml(TypeDefn t) {
    if (!uml.hasClass(t.getName())) {
        UMLClass c = new UMLClass(t.getName(), UMLClassType.Class);
        uml.getTypes().put(t.getName(), c);
    }
    UMLClass c = uml.getClassByName(t.getName());
    c.setDocumentation(t.getDefinition());
    if (!t.getTypes().isEmpty()) {
        c.setSpecialises(uml.getClassByName(t.typeCodeNoParams()));
    }
    if (!c.hasAttributes()) {
        for (ElementDefn e : t.getElements()) {
            UMLAttribute a = null;
            if (t.getTypes().isEmpty()) {
                a = new UMLAttribute(e.getName(), Integer.toString(e.getMinCardinality()), Integer.toString(e.getMaxCardinality()), uml.getClassByNameCreate("Base"));
            } else if (t.getTypes().size() == 1 && !isReference(t.getTypes().get(0).getName())) {
                a = new UMLAttribute(e.getName(), Integer.toString(e.getMinCardinality()), Integer.toString(e.getMaxCardinality()), uml.getClassByNameCreate(e.typeCode()));
            } else {
                String tn = t.getTypes().get(0).getName();
                boolean allSame = true;
                for (int i = 1; i < t.getTypes().size(); i++) {
                    allSame = tn.equals(t.getTypes().get(i).getName());
                }
                if (allSame && isReference(tn)) {
                    a = new UMLAttribute(e.getName(), Integer.toString(e.getMinCardinality()), Integer.toString(e.getMaxCardinality()), uml.getClassByNameCreate(tn));
                    for (TypeRef tr : t.getTypes()) {
                        for (String p : tr.getParams()) {
                            a.getTargets().add(p);
                        }
                    }
                } else {
                    boolean allPrimitive = true;
                    for (TypeRef tr : t.getTypes()) {
                        if (!definitions.hasPrimitiveType(tr.getName())) {
                            allPrimitive = false;
                        }
                    }
                    if (allPrimitive) {
                        a = new UMLAttribute(e.getName(), Integer.toString(e.getMinCardinality()), Integer.toString(e.getMaxCardinality()), uml.getClassByNameCreate("PrimitiveType"));
                    } else {
                        a = new UMLAttribute(e.getName(), Integer.toString(e.getMinCardinality()), Integer.toString(e.getMaxCardinality()), uml.getClassByNameCreate("DataType"));
                    }
                    for (TypeRef tr : t.getTypes()) {
                        a.getTypes().add(tr.getName());
                        for (String p : tr.getParams()) {
                            a.getTargets().add(p);
                        }
                    }
                }
            }
            c.getAttributes().add(a);
        }
    }
}
Also used : UMLClass(org.hl7.fhir.definitions.uml.UMLClass) UMLAttribute(org.hl7.fhir.definitions.uml.UMLAttribute) TypeRef(org.hl7.fhir.definitions.model.TypeRef) ElementDefn(org.hl7.fhir.definitions.model.ElementDefn)

Aggregations

TypeRef (org.hl7.fhir.definitions.model.TypeRef)51 ElementDefn (org.hl7.fhir.definitions.model.ElementDefn)26 ArrayList (java.util.ArrayList)18 FHIRException (org.hl7.fhir.exceptions.FHIRException)13 IOException (java.io.IOException)10 ProfiledType (org.hl7.fhir.definitions.model.ProfiledType)9 URISyntaxException (java.net.URISyntaxException)8 TypeParser (org.hl7.fhir.definitions.parsers.TypeParser)8 CommaSeparatedStringBuilder (org.hl7.fhir.utilities.CommaSeparatedStringBuilder)7 File (java.io.File)6 FileNotFoundException (java.io.FileNotFoundException)6 Invariant (org.hl7.fhir.definitions.model.Invariant)6 CSFile (org.hl7.fhir.utilities.CSFile)6 IniFile (org.hl7.fhir.utilities.IniFile)6 TextFile (org.hl7.fhir.utilities.TextFile)6 TransformerConfigurationException (javax.xml.transform.TransformerConfigurationException)5 TransformerException (javax.xml.transform.TransformerException)5 NotImplementedException (org.apache.commons.lang3.NotImplementedException)5 UcumException (org.fhir.ucum.UcumException)5 DefinitionException (org.hl7.fhir.exceptions.DefinitionException)5