Search in sources :

Example 71 with ElementDefn

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

the class XSDBaseGenerator method generateType.

private void generateType(ElementDefn root, String name, ElementDefn struc) 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");
    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");
    write("    <xs:complexContent>\r\n");
    write("      <xs:extension base=\"" + getParentType(root) + "\">\r\n");
    write("        <xs:sequence>\r\n");
    for (ElementDefn e : struc.getElements()) {
        if (e.getName().equals("[type]"))
            generateAny(root, e, null, null);
        else
            generateElement(root, e, null, null);
    }
    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 72 with ElementDefn

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

the class ResourceDependencyGenerator method genElement.

protected Row genElement(ElementDefn e, HierarchicalTableGenerator gen, boolean resource, String path, boolean isProfile, String prefix, RenderMode mode, boolean isRoot) throws Exception {
    Row row = gen.new Row();
    row.setAnchor(path);
    // 1. Name
    Cell gc = gen.new Cell(null, dictLinks() ? pageName + "#" + path.replace("[", "_").replace("]", "_") : null, e.getName(), path + " : " + e.getDefinition(), null);
    row.getCells().add(gc);
    if (e.getStandardsStatus() != null) {
        gc.addPiece(gen.new Piece(null, " ", null));
        gc.addStyledText("Publication Status = " + e.getStandardsStatus().toDisplay(), e.getStandardsStatus().getAbbrev(), "black", e.getStandardsStatus().getColor(), prefix + "versions.html#std-process", true);
    }
    Cell dc;
    if (resource) {
        // card.
        row.getCells().add(gen.new Cell());
        row.setIcon("icon_resource.png", HierarchicalTableGenerator.TEXT_ICON_RESOURCE);
        if (Utilities.noString(e.typeCode())) {
            row.getCells().add(gen.new Cell(null, null, "n/a", null, null));
            // analysis
            row.getCells().add(dc = gen.new Cell());
        } else {
            // type
            row.getCells().add(gen.new Cell(null, prefix + definitions.getSrcFile(e.typeCode()) + ".html#" + e.typeCode(), e.typeCode(), null, null));
            // analysis
            row.getCells().add(dc = gen.new Cell(null, null, path.contains(".") ? e.describeCardinality() : "", null, null));
        }
    } else {
        if (!e.getElements().isEmpty()) {
            // card.
            row.getCells().add(gen.new Cell(null, null, path.contains(".") ? e.describeCardinality() : "", null, null));
            row.setIcon("icon_element.gif", HierarchicalTableGenerator.TEXT_ICON_ELEMENT);
            if (mode == RenderMode.RESOURCE)
                row.getCells().add(gen.new Cell(null, prefix + definitions.getBackboneLink(), "BackboneElement", null, null));
            else if (e.getName().equals("Element"))
                row.getCells().add(gen.new Cell(null, null, "n/a", null, null));
            else
                row.getCells().add(gen.new Cell(null, prefix + definitions.getBackboneLink(), "Element", null, null));
            // analysis
            row.getCells().add(dc = gen.new Cell());
        } else if (e.getTypes().size() == 1) {
            // card.
            row.getCells().add(gen.new Cell(null, null, path.contains(".") ? e.describeCardinality() : "", null, null));
            String t = e.getTypes().get(0).getName();
            Cell c;
            if (t.startsWith("@")) {
                row.setIcon("icon_reuse.png", HierarchicalTableGenerator.TEXT_ICON_REUSE);
                row.getCells().add(c = gen.new Cell("see ", "#" + t.substring(1), t.substring(t.lastIndexOf(".") + 1), t.substring(1), null));
                // analysis
                row.getCells().add(dc = gen.new Cell());
            } else if (t.equals("Reference") || t.equals("canonical")) {
                row.setIcon("icon_reference.png", HierarchicalTableGenerator.TEXT_ICON_REFERENCE);
                row.getCells().add(c = gen.new Cell());
                c.getPieces().add(gen.new Piece(prefix + "references.html", t, null));
                c.getPieces().add(gen.new Piece(null, "(", null));
                boolean first = true;
                for (String rt : e.getTypes().get(0).getParams()) {
                    if (definitions.hasLogicalModel(rt)) {
                        for (String rtn : definitions.getLogicalModel(rt).getImplementations()) {
                            if (!first)
                                c.getPieces().add(gen.new Piece(null, " | ", null));
                            c.getPieces().add(gen.new Piece(prefix + findPage(rtn) + ".html", rtn, null));
                            first = false;
                        }
                    } else {
                        if (!first)
                            c.getPieces().add(gen.new Piece(null, " | ", null));
                        if (first && isProfile && e.getTypes().get(0).getProfile() != null)
                            c.getPieces().add(gen.new Piece(null, e.getTypes().get(0).getProfile(), null));
                        else
                            c.getPieces().add(gen.new Piece(prefix + findPage(rt) + ".html", rt, null));
                        first = false;
                    }
                }
                c.getPieces().add(gen.new Piece(null, ")", null));
                // analysis
                row.getCells().add(dc = gen.new Cell());
                for (String rt : e.getTypes().get(0).getParams()) if (definitions.hasLogicalModel(rt)) {
                    for (String rtn : definitions.getLogicalModel(rt).getImplementations()) {
                        addTypeToAnalysis(gen, row, dc, true, e.getStandardsStatus(), rtn);
                    }
                } else
                    addTypeToAnalysis(gen, row, dc, true, e.getStandardsStatus(), rt);
            } else if (definitions.getPrimitives().containsKey(t)) {
                row.setIcon("icon_primitive.png", HierarchicalTableGenerator.TEXT_ICON_PRIMITIVE);
                row.getCells().add(c = gen.new Cell(null, prefix + "datatypes.html#" + t, t, null, null));
                // analysis
                row.getCells().add(dc = gen.new Cell());
                addTypeToAnalysis(gen, row, dc, false, e.getStandardsStatus(), e.typeCode());
            } else {
                if (t.equals("Extension"))
                    row.setIcon("icon_extension_simple.png", HierarchicalTableGenerator.TEXT_ICON_EXTENSION);
                else
                    row.setIcon("icon_datatype.gif", HierarchicalTableGenerator.TEXT_ICON_DATATYPE);
                row.getCells().add(c = gen.new Cell(null, prefix + definitions.getSrcFile(t) + ".html#" + t.replace("*", "open"), t, null, null));
                // analysis
                row.getCells().add(dc = gen.new Cell());
                addTypeToAnalysis(gen, row, dc, false, e.getStandardsStatus(), t);
            }
        } else {
            row.getCells().add(gen.new Cell(null, null, e.describeCardinality(), null, null));
            row.setIcon("icon_choice.gif", HierarchicalTableGenerator.TEXT_ICON_CHOICE);
            row.getCells().add(gen.new Cell(null, null, "", null, null));
            // analysis
            row.getCells().add(dc = gen.new Cell());
        }
    }
    if (e.hasBinding() && e.getBinding() != null && e.getBinding().getBinding() != BindingMethod.Unbound && (e.getBinding().getStrength() == BindingStrength.REQUIRED || e.getBinding().getStrength() == BindingStrength.EXTENSIBLE)) {
        addBindingToAnalysis(gen, row, dc, e.getBinding().getStrength() == BindingStrength.REQUIRED, e.getStandardsStatus(), e.getBinding());
    // if (cc.getPieces().size() == 1)
    // cc.addPiece(gen.new Piece("br"));
    // cc.getPieces().add(gen.new Piece(getBindingLink(prefix, e), e.getBinding().getValueSet() != null ? e.getBinding().getValueSet().getName() : e.getBinding().getName(),
    // e.getBinding().getDefinition()));
    // cc.getPieces().add(gen.new Piece(null, " (", null));
    // BindingSpecification b = e.getBinding();
    // if (b.hasMax() ) {
    // cc.getPieces().add(gen.new Piece(prefix+"terminologies.html#"+b.getStrength().toCode(), b.getStrength().getDisplay(),  b.getStrength().getDefinition()));
    // cc.getPieces().add(gen.new Piece(null, " but limited to ", null));
    // ValueSet vs = b.getMaxValueSet();
    // cc.getPieces().add(gen.new Piece(vs.getUserString("path"), vs.getName(), null));
    // }  else
    // cc.getPieces().add(gen.new Piece(prefix+"terminologies.html#"+b.getStrength().toCode(), b.getStrength().getDisplay(),  b.getStrength().getDefinition()));
    // cc.getPieces().add(gen.new Piece(null, ")", null));
    }
    if (e.getTypes().size() > 1) {
        // create a child for each choice
        for (TypeRef tr : e.getTypes()) {
            Row choicerow = gen.new Row();
            String t = tr.getName();
            if (t.equals("Reference")) {
                choicerow.getCells().add(gen.new Cell(null, null, e.getName().replace("[x]", "Reference"), null, null));
                choicerow.getCells().add(gen.new Cell(null, null, "", null, null));
                choicerow.setIcon("icon_reference.png", HierarchicalTableGenerator.TEXT_ICON_REFERENCE);
                Cell c = gen.new Cell();
                choicerow.getCells().add(c);
                c.getPieces().add(gen.new Piece(prefix + "references.html", "Reference", null));
                c.getPieces().add(gen.new Piece(null, "(", null));
                boolean first = true;
                List<String> tt = new ArrayList<>();
                for (String rt : tr.getParams()) {
                    if (definitions.hasLogicalModel(rt))
                        tt.addAll(definitions.getLogicalModel(rt).getImplementations());
                    else
                        tt.add(rt);
                }
                Collections.sort(tt);
                for (String rt : tt) {
                    if (!first)
                        c.getPieces().add(gen.new Piece(null, " | ", null));
                    c.getPieces().add(gen.new Piece(prefix + findPage(rt) + ".html", rt, null));
                    first = false;
                }
                // analysis
                choicerow.getCells().add(dc = gen.new Cell());
                for (String rt : tt) addTypeToAnalysis(gen, choicerow, dc, true, e.getStandardsStatus(), rt);
            } else if (definitions.getPrimitives().containsKey(t)) {
                choicerow.getCells().add(gen.new Cell(null, null, e.getName().replace("[x]", Utilities.capitalize(t)), definitions.getPrimitives().get(t).getDefinition(), null));
                choicerow.getCells().add(gen.new Cell(null, null, "", null, null));
                choicerow.setIcon("icon_primitive.png", HierarchicalTableGenerator.TEXT_ICON_PRIMITIVE);
                choicerow.getCells().add(gen.new Cell(null, prefix + "datatypes.html#" + t, t, null, null));
                // analysis
                choicerow.getCells().add(dc = gen.new Cell());
                addTypeToAnalysis(gen, choicerow, dc, false, e.getStandardsStatus(), t);
            } else if (definitions.getConstraints().containsKey(t)) {
                ProfiledType pt = definitions.getConstraints().get(t);
                choicerow.getCells().add(gen.new Cell(null, null, e.getName().replace("[x]", Utilities.capitalize(pt.getBaseType())), definitions.getTypes().containsKey(t) ? definitions.getTypes().get(t).getDefinition() : null, null));
                choicerow.getCells().add(gen.new Cell(null, null, "", null, null));
                choicerow.setIcon("icon_datatype.gif", HierarchicalTableGenerator.TEXT_ICON_DATATYPE);
                choicerow.getCells().add(gen.new Cell(null, definitions.getSrcFile(t) + ".html#" + t.replace("*", "open"), t, null, null));
                // analysis
                choicerow.getCells().add(dc = gen.new Cell());
                addTypeToAnalysis(gen, choicerow, dc, false, e.getStandardsStatus(), t);
            } else {
                choicerow.getCells().add(gen.new Cell(null, null, e.getName().replace("[x]", Utilities.capitalize(t)), definitions.getTypes().containsKey(t) ? definitions.getTypes().get(t).getDefinition() : null, null));
                choicerow.getCells().add(gen.new Cell(null, null, "", null, null));
                choicerow.setIcon("icon_datatype.gif", HierarchicalTableGenerator.TEXT_ICON_DATATYPE);
                choicerow.getCells().add(gen.new Cell(null, definitions.getSrcFile(t) + ".html#" + t.replace("*", "open"), t, null, null));
                // analysis
                choicerow.getCells().add(dc = gen.new Cell());
                addTypeToAnalysis(gen, choicerow, dc, false, e.getStandardsStatus(), t);
            }
            row.getSubRows().add(choicerow);
        }
    } else
        for (ElementDefn c : e.getElements()) row.getSubRows().add(genElement(c, gen, false, path + '.' + c.getName(), isProfile, prefix, mode, false));
    return row;
}
Also used : ProfiledType(org.hl7.fhir.definitions.model.ProfiledType) TypeRef(org.hl7.fhir.definitions.model.TypeRef) ArrayList(java.util.ArrayList) ElementDefn(org.hl7.fhir.definitions.model.ElementDefn) Row(org.hl7.fhir.utilities.xhtml.HierarchicalTableGenerator.Row) Cell(org.hl7.fhir.utilities.xhtml.HierarchicalTableGenerator.Cell)

Example 73 with ElementDefn

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

the class SchematronGenerator method generateInvariants.

private void generateInvariants(Section section, String path, ElementDefn ed, Definitions definitions, List<String> parents, String name) throws Exception {
    if (definitions.getBaseResources().containsKey(ed.typeCode()))
        generateInvariants(section, path, definitions.getBaseResources().get(ed.typeCode()).getRoot(), definitions, parents, name);
    // logger.log("generate: "+path+" ("+parents.toString()+")");
    if (name.contains("("))
        name = name.substring(0, name.indexOf("("));
    if (ed.getElements().size() > 0) {
        path = path == null ? "f:" + name : path + (recursesToSelf(ed) ? "/" : "") + "/f:" + name;
        genInvs(section, path, ed);
        genChildren(section, path, null, ed, definitions, parents);
    } else {
        for (TypeRef tr : ed.typeCode().equals("*") ? allTypes() : ed.getTypes()) {
            String en = name;
            if (en.endsWith("[x]")) {
                if (definitions.getConstraints().containsKey(tr.getName()))
                    en = en.replace("[x]", definitions.getConstraints().get(tr.getName()).getBaseType());
                else
                    en = en.replace("[x]", Utilities.capitalize(tr.summary()));
            }
            if (en.contains("("))
                en = en.substring(0, en.indexOf("("));
            if (en.equals("div"))
                en = "h:" + en;
            else
                en = "f:" + en;
            String sPath = path == null ? en : path + "/" + en;
            genInvs(section, sPath, ed);
            ElementDefn td = getType(tr, definitions);
            if (td != null) {
                genInvs(section, sPath, td);
                genChildren(section, sPath, tr.summary(), td, definitions, parents);
            }
        }
    }
}
Also used : TypeRef(org.hl7.fhir.definitions.model.TypeRef) ElementDefn(org.hl7.fhir.definitions.model.ElementDefn)

Example 74 with ElementDefn

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

the class SvgGenerator method determineMetrics.

private Point determineMetrics(ElementDefn e, ClassItem source, String path, boolean isRoot, DefinedCode primitive) throws Exception {
    String t = e.getName();
    if (isRoot) {
        t = t + " {" + e.typeCodeNoParams() + ")";
    }
    if (definitions.getBaseResources().containsKey(e.getName()) && definitions.getBaseResources().get(e.getName()).isInterface()) {
        t = t + " «Interface»";
    }
    double width = textWidth(t) * 1.8;
    // double width = textWidth(e.getName()) * 1.8 + (isRoot ? textWidth(" (Resource)") : 0);
    double height;
    if (attributes) {
        if (primitive != null) {
            if (primitive instanceof PrimitiveType) {
                height = HEADER_HEIGHT + GAP_HEIGHT * 2 + LINE_HEIGHT + GAP_HEIGHT * 2;
                width = textWidth("value : " + getXsi(primitive) + " 0..1");
            } else
                height = HEADER_HEIGHT + GAP_HEIGHT * 2;
        } else {
            int i = 0;
            for (ElementDefn c : e.getElements()) if (isAttribute(c)) {
                String[] texts = textForAttribute(c);
                i = i + texts.length;
                double w = textWidth(texts[0]);
                for (int j = 1; j < texts.length; j++) w = Math.max(w, textWidth(texts[j]));
                if (w > width)
                    width = w;
            }
            height = HEADER_HEIGHT + GAP_HEIGHT * 2 + LINE_HEIGHT * i + GAP_HEIGHT * 2;
        }
    } else
        height = HEADER_HEIGHT + GAP_HEIGHT * 2;
    if (ini != null) {
        String uml = ini.getStringProperty("directions", path);
        if (!Utilities.noString(uml) && uml.contains(";")) {
            String[] svg = uml.split("\\;");
            e.setSvgLeft(Integer.parseInt(svg[0]));
            e.setSvgTop(Integer.parseInt(svg[1]));
        } else if (!Utilities.noString(uml) && uml.contains(",")) {
            String[] svg = uml.split("\\,");
            e.setSvgLeft(Integer.parseInt(svg[0]));
            e.setSvgTop(Integer.parseInt(svg[1]));
        } else {
            e.setUmlDir(uml);
        }
    }
    Point p = new Point(e.getSvgLeft(), e.getSvgTop(), PointKind.unknown);
    if (p.y == ElementDefn.MAX_NEG || p.x == ElementDefn.MAX_NEG) {
        if ("left".equals(e.getUmlDir())) {
            p.x = source.left - 120 - width;
            p.y = source.centerV() - height / 2;
            p = findEmptyPlace(p, width, height, 0, 80);
        } else if ("right".equals(e.getUmlDir())) {
            p.x = source.right() + 120;
            p.y = source.centerV() - height / 2;
            p = findEmptyPlace(p, width, height, 0, 80);
        } else if ("up".equals(e.getUmlDir())) {
            p.x = source.centerH() - width / 2;
            p.y = source.top - height - 80;
            p = findEmptyPlace(p, width, height, 80, 0);
        } else if ("down".equals(e.getUmlDir())) {
            p.x = source.centerH() - width / 2;
            p.y = source.bottom() + 80;
            p = findEmptyPlace(p, width, height, +80, 0);
        } else {
            p.y = 0;
            p.x = 0;
            p = findEmptyPlace(p, width, height, 80, 0);
        }
    }
    miny = Math.min(miny, p.y);
    minx = Math.min(minx, p.x);
    ClassItem item = new ClassItem(p.x, p.y, width, height, e.getPath());
    classes.put(e, item);
    double x = item.right() + MARGIN_X;
    double y = item.bottom() + MARGIN_Y;
    if (attributes) {
        for (ElementDefn c : e.getElements()) {
            if (!isAttribute(c) && (Utilities.noString(c.typeCode()) || !c.typeCode().startsWith("@"))) {
                p = determineMetrics(c, item, path + "." + c.getName(), false, null);
                x = Math.max(x, p.x + MARGIN_X);
                y = Math.max(y, p.y + MARGIN_Y);
            }
        }
    }
    return new Point(x, y, PointKind.unknown);
}
Also used : ElementDefn(org.hl7.fhir.definitions.model.ElementDefn) PrimitiveType(org.hl7.fhir.definitions.model.PrimitiveType)

Example 75 with ElementDefn

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

the class XPathQueryGenerator method generateXpath.

public String generateXpath(List<String> list, String rn) throws Exception {
    StringBuilder b = new StringBuilder();
    for (String ppath : list) {
        String[] path = splitPath(rn != null ? ppath.replace("{{name}}", rn) : ppath);
        if (path[path.length - 1].endsWith("[x]")) {
            ElementDefn defn = definitions.getElementDefn(path[0]);
            ElementDefn ed = defn.getElementForPath(ppath, definitions, "Search parameter xpath generation", true, false);
            for (TypeRef tr : ed.getTypes()) {
                buildPath(b, path, ed.getName().substring(0, ed.getName().length() - 3) + Utilities.capitalize(tr.getName()));
            }
        } else
            buildPath(b, path, path[path.length - 1]);
    }
    return b.toString();
}
Also used : TypeRef(org.hl7.fhir.definitions.model.TypeRef) ElementDefn(org.hl7.fhir.definitions.model.ElementDefn)

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