Search in sources :

Example 41 with TypeRef

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

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

Example 43 with TypeRef

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

the class PageProcessor method tsForDt.

private String tsForDt(String dt) throws Exception {
    File tmp = Utilities.createTempFile("tmp", ".tmp");
    tmp.deleteOnExit();
    TerminologyNotesGenerator gen = new TerminologyNotesGenerator(new FileOutputStream(tmp), this);
    TypeParser tp = new TypeParser(version.toCode());
    TypeRef t = tp.parse(dt, false, null, workerContext, true).get(0);
    ElementDefn 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) TerminologyNotesGenerator(org.hl7.fhir.definitions.generators.specification.TerminologyNotesGenerator) 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)

Example 44 with TypeRef

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

the class PageProcessor method buildChoiceElementList.

private void buildChoiceElementList(StringBuilder b, String s, ElementDefn t) throws Exception {
    if (t.getName().contains("[x]")) {
        if (b.length() > 0)
            b.append(",\r\n");
        b.append("    ");
        b.append("\"" + t.getPath() + "\": [");
        boolean first = true;
        for (TypeRef tt : t.getTypes()) {
            if (first)
                first = false;
            else
                b.append(", ");
            b.append("\"");
            b.append(tt.getName());
            b.append("\"");
        }
        b.append("]");
    }
    for (ElementDefn e : t.getElements()) buildChoiceElementList(b, s, e);
}
Also used : TypeRef(org.hl7.fhir.definitions.model.TypeRef) ElementDefn(org.hl7.fhir.definitions.model.ElementDefn)

Example 45 with TypeRef

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

the class PageProcessor method xmlForDt.

private String xmlForDt(String dt, String pn) throws Exception {
    File tmp = Utilities.createTempFile("tmp", ".tmp");
    XmlSpecGenerator gen = new XmlSpecGenerator(new FileOutputStream(tmp), pn == null ? null : pn.substring(0, pn.indexOf(".")) + "-definitions.html", null, this, "");
    TypeParser tp = new TypeParser(version.toCode());
    TypeRef t = tp.parse(dt, false, null, workerContext, true).get(0);
    ElementDefn e = definitions.getElementDefn(t.getName());
    if (e == null) {
        gen.close();
        throw new Exception("unable to find definition for " + dt);
    } else {
        gen.generate(e, e.getName().equals("Element") || e.getName().equals("BackboneElement"), false);
        gen.close();
    }
    String val = TextFile.fileToString(tmp.getAbsolutePath()) + "\r\n";
    tmp.delete();
    return val;
}
Also used : XmlSpecGenerator(org.hl7.fhir.definitions.generators.specification.XmlSpecGenerator) ITypeParser(org.hl7.fhir.r5.renderers.utils.RenderingContext.ITypeParser) TypeParser(org.hl7.fhir.definitions.parsers.TypeParser) 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

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