Search in sources :

Example 96 with ElementDefn

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

the class SvgGenerator method textForAttribute.

private String[] textForAttribute(ElementDefn e) throws Exception {
    LineStatus ls = new LineStatus();
    // this is a dummary
    XMLWriter xml = new XMLWriter(new ByteArrayOutputStream(), "UTF-8");
    xml.start();
    addAttribute(xml, 0, 0, e, "Element.id", ls, 0, 0);
    ls.close();
    return ls.list.toArray(new String[] {});
}
Also used : ByteArrayOutputStream(java.io.ByteArrayOutputStream) XMLWriter(org.hl7.fhir.utilities.xml.XMLWriter)

Example 97 with ElementDefn

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

the class SvgGenerator method addAttribute.

private void addAttribute(XMLWriter xml, double left, double top, ElementDefn e, String path, LineStatus ls, double height, double width) throws Exception {
    if (e.getStandardsStatus() != null) {
        xml.attribute("x", Double.toString(left + 1));
        xml.attribute("y", Double.toString(top - height + GAP_HEIGHT));
        xml.attribute("id", "n" + (++nc));
        xml.attribute("width", Double.toString(width - 2));
        xml.attribute("height", Double.toString(height));
        xml.attribute("style", "fill:" + e.getStandardsStatus().getColorSvg() + ";stroke:black;stroke-width:0");
        xml.element("rect", null);
    }
    xml.attribute("x", Double.toString(left + LEFT_MARGIN + (ls.line == 0 ? 0 : WRAP_INDENT)));
    xml.attribute("y", Double.toString(top + LINE_HEIGHT * ls.line));
    xml.attribute("fill", "black");
    xml.attribute("class", "diagram-class-detail");
    xml.attribute("id", "n" + (++nc));
    xml.enter("text");
    xml.attribute("xlink:href", baseUrl(path) + path + "." + e.getName().replace("[", "_").replace("]", "_"));
    xml.attribute("id", "n" + (++nc));
    xml.enter("a");
    xml.element("title", e.getEnhancedDefinition());
    xml.text(ls.see(e.getName()));
    xml.exit("a");
    xml.text(ls.see(" : "));
    encodeType(xml, ls, getTypeCodeForElement(e.getTypes()));
    xml.text(ls.see(" [" + e.describeCardinality() + "]"));
    // now, the stereotypes
    boolean hasTS = !((e.getTypes().isEmpty()) || (e.getTypes().size() == 1 && !isReference(e.getTypes().get(0).getName())));
    boolean hasBinding = (e.hasBinding() && e.getBinding().getBinding() != BindingMethod.Unbound);
    if (hasTS || hasBinding) {
        xml.text(ls.see(" \u00AB "));
        if (hasTS) {
            if (isReference(e.getTypes().get(0).getName()) && e.getTypes().size() == 1) {
                boolean first = true;
                for (String p : e.getTypes().get(0).getParams()) {
                    if (first)
                        first = false;
                    else
                        xml.text(ls.see("|"));
                    ls.check(xml, left, top, p.length(), null);
                    encodeType(xml, ls, p);
                }
            } else {
                boolean firstOuter = true;
                for (TypeRef t : e.getTypes()) {
                    if (firstOuter)
                        firstOuter = false;
                    else
                        xml.text(ls.see("|"));
                    ls.check(xml, left, top, t.getName().length(), null);
                    encodeType(xml, ls, t.getName());
                    if (t.getParams().size() > 0) {
                        xml.text(ls.see("("));
                        boolean first = true;
                        for (String p : t.getParams()) {
                            if (first)
                                first = false;
                            else
                                xml.text(ls.see("|"));
                            ls.check(xml, left, top, p.length(), null);
                            encodeType(xml, ls, p);
                        }
                        xml.text(ls.see(")"));
                    }
                }
            }
        }
        if (hasTS && hasBinding) {
            xml.text(ls.see("; "));
        }
        if (hasBinding) {
            BindingSpecification b = e.getBinding();
            String name = e.getBinding().getValueSet() != null ? e.getBinding().getValueSet().getName() : e.getBinding().getName();
            if (name.toLowerCase().endsWith(" codes"))
                name = name.substring(0, name.length() - 5);
            if (name.length() > 30)
                name = name.substring(0, 29) + "...";
            String link = getBindingLink(prefix, e);
            if (b.getStrength() == BindingStrength.EXAMPLE) {
                if (link != null) {
                    xml.attribute("xlink:href", link);
                    xml.attribute("id", "n" + (++nc));
                    xml.enter("a");
                    xml.attribute("id", "n" + (++nc));
                }
                xml.element("title", b.getDefinition() + " (Strength=Example)");
                for (String p : parts(name)) {
                    ls.check(xml, left, top, p.length(), link);
                    xml.text(ls.see(p));
                }
                if (link != null) {
                    xml.exit("a");
                }
                xml.text("??");
            } else if (b.getStrength() == BindingStrength.PREFERRED) {
                xml.attribute("xlink:href", link);
                xml.attribute("id", "n" + (++nc));
                xml.enter("a");
                xml.element("title", b.getDefinition() + " (Strength=Preferred)");
                for (String p : parts(name)) {
                    ls.check(xml, left, top, p.length(), link);
                    xml.text(ls.see(p));
                }
                xml.exit("a");
                xml.text("?");
            } else if (b.getStrength() == BindingStrength.EXTENSIBLE) {
                // if (b.hasMax())
                // what do in this case...
                xml.attribute("xlink:href", link);
                xml.attribute("id", "n" + (++nc));
                xml.enter("a");
                xml.attribute("id", "n" + (++nc));
                xml.element("title", b.getDefinition() + " (Strength=Extensible)");
                for (String p : parts(name)) {
                    ls.check(xml, left, top, p.length(), link);
                    xml.text(ls.see(p));
                }
                xml.exit("a");
                xml.text("+");
            } else if (b.getStrength() == BindingStrength.REQUIRED) {
                xml.attribute("xlink:href", link);
                xml.attribute("id", "n" + (++nc));
                xml.enter("a");
                xml.attribute("id", "n" + (++nc));
                xml.element("title", b.getDefinition() + " (Strength=Required)");
                // xml.open("b");
                for (String p : parts(name)) {
                    ls.check(xml, left, top, p.length(), link);
                    xml.text(ls.see(p));
                }
                // xml.close("b");
                xml.exit("a");
                xml.text("!");
            } else {
                xml.attribute("id", "n" + (++nc));
                xml.attribute("xlink:href", link);
                xml.enter("a");
                xml.attribute("id", "n" + (++nc));
                xml.element("title", b.getDefinition() + " (??)");
                for (String p : parts(name)) {
                    ls.check(xml, left, top, p.length(), link);
                    xml.text(ls.see(p));
                }
                xml.exit("a");
            }
        }
        xml.text(ls.see(" \u00BB"));
    }
    xml.exit("text");
}
Also used : TypeRef(org.hl7.fhir.definitions.model.TypeRef) BindingSpecification(org.hl7.fhir.definitions.model.BindingSpecification)

Example 98 with ElementDefn

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

the class PageProcessor method populateLogicalMappingColumn.

private void populateLogicalMappingColumn(StringBuilder b, String n, String page, ElementDefn e, StructureDefinition sd, String rn, String code, String url, StringBuilder b2, IniFile ini, String iniPath) throws FHIRException {
    LogicalModelSupportInformation info = new LogicalModelSupportInformation();
    for (ElementDefinition ed : sd.getSnapshot().getElement()) {
        for (ElementDefinitionMappingComponent m : ed.getMapping()) {
            if (m.getIdentity().equals(code)) {
                String s = m.getMap();
                for (String p : s.split("\\,")) {
                    String f = p.contains("{") ? p.substring(0, p.indexOf("{")).trim() : p;
                    String cm = p.contains("{") ? p.substring(p.indexOf("{")) : null;
                    if (cm != null) {
                        cm = cm.trim();
                    }
                    if (f.equals(e.getPath())) {
                        checkMapping(info, e, ed, b2 == null, cm);
                    }
                }
            }
        }
    }
    for (StructureDefinition ext : workerContext.getExtensionDefinitions()) {
        boolean ok = false;
        for (StructureDefinitionContextComponent ec : ext.getContext()) {
            if (ec.getType() == ExtensionContextType.ELEMENT) {
                if (rn.equals(ec.getExpression()))
                    ok = true;
            }
            if (ok) {
                String map = getWorkflowMapping(ext, url);
                if (map != null) {
                    for (String p : map.split("\\,")) {
                        String f = p.contains("{") ? p.substring(0, p.indexOf("{")) : p;
                        if (f.equals(e.getPath())) {
                            checkExtMapping(info, e, ext);
                        }
                    }
                }
            }
        }
    }
    // color:
    // one color when supported and aligned
    // one color when not aligned
    // one coor when color extension
    // blank for no mapping
    String color;
    if (info.typeMismatch == TypeMappingStatus.ERROR || info.cardinalityProblem)
        color = LOGICAL_MAPPING_MISMATCH_COLOR;
    else if (info.nameChanged || info.typeMismatch == TypeMappingStatus.NEEDS_MAPPING)
        color = LOGICAL_MAPPING_NAMECHANGE_COLOR;
    else if (info.extension)
        color = LOGICAL_MAPPING_EXTENSION_COLOR;
    else if (info.elementcount > 0)
        color = LOGICAL_MAPPING_MAPPED_COLOR;
    else
        color = LOGICAL_MAPPING_NOTMAPPED_COLOR;
    if (b != null) {
        StringBuilder ns = new StringBuilder();
        for (String s : info.notes) {
            if (ns.length() > 0)
                ns.append("; ");
            ns.append(s);
        }
        b.append("  <td style=\"background-color: " + color + "\" title=\"" + ns.toString() + "\">");
        if (info.elementcount > 0)
            b.append(info.elementcount);
        else if (info.extension)
            b.append("E");
        b.append(" ");
        if (info.nameChanged)
            b.append("N");
        if (info.typeMismatch == TypeMappingStatus.ERROR)
            b.append("T");
        if (info.cardinalityProblem)
            b.append("C");
        b.append("</td>\r\n");
    }
    StringBuilder ns = new StringBuilder();
    for (String s : info.notes) {
        ns.append(s);
    }
    String tasks = ini == null ? null : ini.getStringProperty(iniPath, sd.getName() + ".tasks");
    String status = ini == null ? null : ini.getStringProperty(iniPath, sd.getName() + ".status");
    String notes = ini == null ? null : ini.getStringProperty(iniPath, sd.getName() + ".notes");
    if (b2 != null && !(Utilities.noString(ns.toString()) && Utilities.noString(tasks))) {
        b2.append("<tr style=\"background-color: " + color + "\"><td><b><a href=\"" + sd.getName().toLowerCase() + ".html\">" + sd.getName() + "</a></b></td><td><ul>" + ns.toString() + "</ul>");
        if (info.extension)
            b2.append(" (as an extension)");
        b2.append("</td><td>");
        if (info.nameChanged || info.typeMismatch != TypeMappingStatus.OK || info.cardinalityProblem) {
            boolean first = true;
            if (info.nameChanged) {
                b2.append("Names are different. ");
                first = false;
            }
            if (info.typeMismatch != TypeMappingStatus.OK) {
                if (!first)
                    b2.append("<br/>");
                b2.append("Type Mismatch. ");
                first = false;
            }
            if (info.cardinalityProblem) {
                if (!first)
                    b2.append("<br/>");
                b2.append("Cardinality Problem. ");
            }
        }
        b2.append("</td><td>");
        boolean first = true;
        if (!Utilities.noString(tasks)) {
            for (String id : tasks.split("\\;")) {
                if (!first)
                    b2.append(" | ");
                b2.append("<a href=\"https://gforge.hl7.org/gf/project/fhir/tracker/?action=TrackerItemEdit&amp;tracker_item_id=" + id.trim() + "\">GF#" + id.trim() + "</a>");
                first = false;
            }
            b2.append("</td><td>");
        }
        if (!Utilities.noString(status))
            b2.append(Utilities.escapeXml(status));
        b2.append("</td><td>");
        if (!Utilities.noString(notes))
            b2.append(Utilities.escapeXml(notes));
        b2.append("</td></tr>\r\n");
    }
}
Also used : StructureDefinition(org.hl7.fhir.r5.model.StructureDefinition) StructureDefinitionContextComponent(org.hl7.fhir.r5.model.StructureDefinition.StructureDefinitionContextComponent) CommaSeparatedStringBuilder(org.hl7.fhir.utilities.CommaSeparatedStringBuilder) ElementDefinition(org.hl7.fhir.r5.model.ElementDefinition) ElementDefinitionMappingComponent(org.hl7.fhir.r5.model.ElementDefinition.ElementDefinitionMappingComponent)

Example 99 with ElementDefn

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

the class PageProcessor method checkExtMapping.

private void checkExtMapping(LogicalModelSupportInformation info, ElementDefn logical, StructureDefinition extension) throws FHIRException {
    info.extension = true;
    ElementDefinition e = extension.getSnapshot().getElementFirstRep();
    ElementDefinition v = null;
    for (ElementDefinition ed : extension.getSnapshot().getElement()) {
        if ("Extension.value[x]".equals(ed.getBase().getPath()))
            v = ed;
    }
    String s = logical.getPath() + " : " + logical.typeCode() + " [" + logical.describeCardinality() + "] =&gt; Extension " + tail(extension.getUrl()) + " : " + v.typeSummary() + " [" + e.getMin() + ".." + e.getMax() + "]";
    String cardinalityError = checkCardinality(logical, e);
    if (!Utilities.noString(cardinalityError)) {
        info.cardinalityProblem = true;
        s = s + " " + cardinalityError;
    }
    String typeError = checkType(logical, v, null);
    if (!Utilities.noString(typeError)) {
        info.typeMismatch = TypeMappingStatus.ERROR;
        s = s + " " + typeError;
    }
    info.notes.add(s);
}
Also used : ElementDefinition(org.hl7.fhir.r5.model.ElementDefinition)

Example 100 with ElementDefn

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

the class PageProcessor method dictForDt.

// private boolean notime;
private String dictForDt(String dt) throws Exception {
    File tmp = Utilities.createTempFile("tmp", ".tmp");
    DictHTMLGenerator gen = new DictHTMLGenerator(new FileOutputStream(tmp), this, "");
    TypeParser tp = new TypeParser(version.toCode());
    TypeRef t = tp.parse(dt, false, null, workerContext, true).get(0);
    ElementDefn e;
    if (t.getName().equals("Resource"))
        e = definitions.getBaseResources().get("DomainResource").getRoot();
    else
        e = definitions.getElementDefn(t.getName());
    if (e == null) {
        gen.close();
        throw new Exception("unable to find definition for " + dt);
    } else {
        gen.generate(e);
        gen.close();
    }
    String val = TextFile.fileToString(tmp.getAbsolutePath()) + "\r\n";
    tmp.delete();
    return val;
}
Also used : ITypeParser(org.hl7.fhir.r5.renderers.utils.RenderingContext.ITypeParser) TypeParser(org.hl7.fhir.definitions.parsers.TypeParser) DictHTMLGenerator(org.hl7.fhir.definitions.generators.specification.DictHTMLGenerator) TypeRef(org.hl7.fhir.definitions.model.TypeRef) FileOutputStream(java.io.FileOutputStream) ElementDefn(org.hl7.fhir.definitions.model.ElementDefn) IniFile(org.hl7.fhir.utilities.IniFile) File(java.io.File) CSFile(org.hl7.fhir.utilities.CSFile) TextFile(org.hl7.fhir.utilities.TextFile) UcumException(org.fhir.ucum.UcumException) TransformerException(javax.xml.transform.TransformerException) TransformerConfigurationException(javax.xml.transform.TransformerConfigurationException) IOException(java.io.IOException) FHIRException(org.hl7.fhir.exceptions.FHIRException) URISyntaxException(java.net.URISyntaxException) PathEngineException(org.hl7.fhir.exceptions.PathEngineException) DefinitionException(org.hl7.fhir.exceptions.DefinitionException) FileNotFoundException(java.io.FileNotFoundException) NotImplementedException(org.apache.commons.lang3.NotImplementedException)

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