Search in sources :

Example 11 with Narrative

use of org.hl7.fhir.dstu2016may.model.Narrative in project kindling by HL7.

the class SvgGenerator method drawElement.

private ClassItem drawElement(XMLWriter xml, String[] classNames) throws Exception {
    // classNames.length == 1 && classNames[0].equals("Base");
    boolean onlyElement = false;
    if (classNames != null) {
        for (String cn : classNames) {
            if (definitions.getPrimitives().containsKey(cn)) {
                DefinedCode cd = definitions.getPrimitives().get(cn);
                ElementDefn fake = fakes.get(cn);
                if (cd instanceof DefinedStringPattern) {
                    links.add(new Link(classes.get(fakes.get(((DefinedStringPattern) cd).getBase())), drawClass(xml, fake, false, null, true, null, cd, StandardsStatus.NORMATIVE), LinkType.SPECIALIZATION, null, null, PointKind.unknown, null, null));
                } else {
                    ClassItem parent = classes.get(definitions.getElementDefn(version.isR4B() ? "Element" : "PrimitiveType"));
                    if (parent == null) {
                        drawClass(xml, fake, false, null, true, null, cd, StandardsStatus.NORMATIVE);
                    } else {
                        links.add(new Link(parent, drawClass(xml, fake, false, null, true, null, cd, StandardsStatus.NORMATIVE), LinkType.SPECIALIZATION, null, null, PointKind.unknown, null, null));
                    }
                }
            } else if ("xhtml".equals(cn)) {
                DefinedCode cd = new DefinedCode("xhtml", "XHTML for resource narrative", null);
                ElementDefn fake = fakes.get(cn);
                ClassItem parent = classes.get(definitions.getElementDefn(version.isR4B() ? "Element" : "DataType"));
                if (parent == null) {
                    drawClass(xml, fake, false, null, true, null, cd, StandardsStatus.NORMATIVE);
                } else {
                    links.add(new Link(parent, drawClass(xml, fake, false, null, true, null, cd, StandardsStatus.NORMATIVE), LinkType.SPECIALIZATION, null, null, PointKind.unknown, null, null));
                }
            } else if (definitions.getConstraints().containsKey(cn)) {
                ProfiledType cd = definitions.getConstraints().get(cn);
                ElementDefn fake = fakes.get(cn);
                ClassItem parent = classes.get(definitions.getElementDefn(cd.getBaseType()));
                links.add(new Link(parent, drawClass(xml, fake, false, null, true, null, null, StandardsStatus.NORMATIVE), LinkType.CONSTRAINT, null, null, PointKind.unknown, null, null));
            } else if (definitions.getPrimitives().containsKey(cn)) {
                DefinedCode cd = new DefinedCode("xhtml", "XHTML for resource narrative", null);
                ElementDefn fake = fakes.get(cn);
                // links.add(new Link(item,
                // , LinkType.SPECIALIZATION, null, null, PointKind.unknown, null, null));
                drawClass(xml, fake, false, null, true, null, cd, StandardsStatus.NORMATIVE);
            } else if (!onlyElement) {
                ElementDefn e = definitions.getElementDefn(cn);
                ClassItem parent = Utilities.noString(e.typeCode()) ? null : classes.get(definitions.getElementDefn(e.typeCode()));
                if (parent == null) {
                    drawClass(xml, e, false, null, true, cn, null, e.getStandardsStatus());
                } else {
                    links.add(new Link(parent, drawClass(xml, e, false, null, true, cn, null, e.getStandardsStatus()), LinkType.SPECIALIZATION, null, null, PointKind.unknown, null, null));
                }
            }
        }
    }
    return null;
}
Also used : DefinedStringPattern(org.hl7.fhir.definitions.model.DefinedStringPattern) ProfiledType(org.hl7.fhir.definitions.model.ProfiledType) DefinedCode(org.hl7.fhir.definitions.model.DefinedCode) ElementDefn(org.hl7.fhir.definitions.model.ElementDefn)

Example 12 with Narrative

use of org.hl7.fhir.dstu2016may.model.Narrative in project kindling by HL7.

the class SvgGenerator method determineMetrics.

private Point determineMetrics(String[] classNames) throws Exception {
    double width = textWidth("Element") * 1.8;
    double height = HEADER_HEIGHT + GAP_HEIGHT * 2;
    // if ("true".equals(ini.getStringProperty("diagram", "element-attributes"))) {
    // height = height + LINE_HEIGHT + GAP_HEIGHT;
    // width = textWidth("extension : Extension 0..*");
    // }
    Point p = new Point(0, 0, PointKind.unknown);
    ClassItem item = new ClassItem(p.x, p.y, width, height, id);
    classes.put(null, item);
    double x = item.right() + MARGIN_X;
    double y = item.bottom() + MARGIN_Y;
    if (classNames != null) {
        for (String cn : classNames) {
            if (definitions.getPrimitives().containsKey(cn)) {
                DefinedCode cd = definitions.getPrimitives().get(cn);
                ElementDefn fake = new ElementDefn();
                fake.setName(cn);
                fakes.put(cn, fake);
                if (cd instanceof DefinedStringPattern)
                    p = determineMetrics(fake, classes.get(fakes.get(((DefinedStringPattern) cd).getBase())), cn, false, cd);
                else
                    p = determineMetrics(fake, item, cn, false, cd);
            } else if ("xhtml".equals(cn)) {
                ElementDefn fake = new ElementDefn();
                fake.setName("xhtml");
                fakes.put("xhtml", fake);
                DefinedCode cd = new DefinedCode("xhtml", "XHTML for resource narrative", null);
                p = determineMetrics(fake, item, cn, false, cd);
            } else if (definitions.getConstraints().containsKey(cn)) {
                ProfiledType cd = definitions.getConstraints().get(cn);
                ElementDefn ed = definitions.getElementDefn(cd.getBaseType());
                ClassItem parentClss = classes.get(ed);
                ElementDefn fake = new ElementDefn();
                fake.setName(cn);
                fakes.put(cn, fake);
                p = determineMetrics(fake, parentClss, cn, false, null);
            } else {
                ElementDefn c = definitions.getElementDefn(cn);
                p = determineMetrics(c, item, 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 : DefinedStringPattern(org.hl7.fhir.definitions.model.DefinedStringPattern) ProfiledType(org.hl7.fhir.definitions.model.ProfiledType) DefinedCode(org.hl7.fhir.definitions.model.DefinedCode) ElementDefn(org.hl7.fhir.definitions.model.ElementDefn)

Example 13 with Narrative

use of org.hl7.fhir.dstu2016may.model.Narrative 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: <http://hl7.org/fhir/> .");
    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 14 with Narrative

use of org.hl7.fhir.dstu2016may.model.Narrative in project kindling by HL7.

the class XSDBaseGenerator method genInfrastructure.

private void genInfrastructure(ElementDefn elem) throws Exception {
    enums.clear();
    enumDefs.clear();
    String name = elem.getName();
    write("  <xs:complexType name=\"" + name + "\">\r\n");
    write("    <xs:annotation>\r\n");
    write("      <xs:documentation xml:lang=\"en\">" + Utilities.escapeXml(elem.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");
    if (!elem.getName().equals("Base")) {
        write("    <xs:complexContent>\r\n");
        write("      <xs:extension base=\"" + getParentType(elem) + "\">\r\n");
    }
    write("        <xs:sequence>\r\n");
    for (ElementDefn e : elem.getElements()) {
        if (!e.isXmlAttribute()) {
            if (e.getName().equals("[type]"))
                generateAny(elem, e, null, null);
            else
                generateElement(elem, e, null, null);
        }
    }
    write("        </xs:sequence>\r\n");
    for (ElementDefn e : elem.getElements()) {
        if (e.isXmlAttribute()) {
            generateAttribute(elem, e, null);
        }
    }
    if (!elem.getName().equals("Base")) {
        write("      </xs:extension>\r\n");
        write("    </xs:complexContent>\r\n");
    }
    write("  </xs:complexType>\r\n");
    while (!structures.isEmpty()) {
        String s = structures.keySet().iterator().next();
        generateType(elem, s, structures.get(s));
        structures.remove(s);
    }
    for (BindingSpecification en : enums) {
        generateEnum(en);
    }
}
Also used : ElementDefn(org.hl7.fhir.definitions.model.ElementDefn) BindingSpecification(org.hl7.fhir.definitions.model.BindingSpecification)

Example 15 with Narrative

use of org.hl7.fhir.dstu2016may.model.Narrative in project kindling by HL7.

the class Publisher method buildLoincExample.

private String buildLoincExample(String filename) throws FileNotFoundException, Exception {
    LoincToDEConvertor conv = new LoincToDEConvertor();
    conv.setDefinitions(Utilities.path(page.getFolders().srcDir, "loinc", "loincS.xml"));
    conv.process();
    IParser xml = new XmlParser().setOutputStyle(OutputStyle.PRETTY);
    FileOutputStream s = new FileOutputStream(Utilities.path(page.getFolders().dstDir, filename + ".xml"));
    xml.compose(s, conv.getBundle());
    s.close();
    IParser json = new JsonParser().setOutputStyle(OutputStyle.PRETTY);
    s = new FileOutputStream(Utilities.path(page.getFolders().dstDir, filename + ".json"));
    json.compose(s, conv.getBundle());
    s.close();
    return "Loinc Narrative";
}
Also used : XmlParser(org.hl7.fhir.r5.formats.XmlParser) FileOutputStream(java.io.FileOutputStream) LoincToDEConvertor(org.hl7.fhir.r5.terminologies.LoincToDEConvertor) IParser(org.hl7.fhir.r5.formats.IParser) JsonParser(org.hl7.fhir.r5.formats.JsonParser)

Aggregations

XhtmlNode (org.hl7.fhir.utilities.xhtml.XhtmlNode)80 FHIRException (org.hl7.fhir.exceptions.FHIRException)40 IOException (java.io.IOException)34 NotImplementedException (org.apache.commons.lang3.NotImplementedException)30 UnsupportedEncodingException (java.io.UnsupportedEncodingException)27 DefinitionException (org.hl7.fhir.exceptions.DefinitionException)23 Test (org.junit.Test)22 MethodOutcome (ca.uhn.fhir.rest.api.MethodOutcome)19 ArrayList (java.util.ArrayList)19 XhtmlParser (org.hl7.fhir.utilities.xhtml.XhtmlParser)17 Narrative (org.hl7.fhir.r4.model.Narrative)15 Narrative (org.hl7.fhir.r5.model.Narrative)15 StructureDefinition (org.hl7.fhir.r5.model.StructureDefinition)14 XhtmlComposer (org.hl7.fhir.utilities.xhtml.XhtmlComposer)14 GET (javax.ws.rs.GET)12 Path (javax.ws.rs.Path)12 Produces (javax.ws.rs.Produces)12 IBaseOperationOutcome (org.hl7.fhir.instance.model.api.IBaseOperationOutcome)12 FileNotFoundException (java.io.FileNotFoundException)10 LinkedHashMap (java.util.LinkedHashMap)10