Search in sources :

Example 76 with StructureDefinition

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

the class ImplementationGuideDefn method findLogicalPage.

private boolean findLogicalPage(String n, String type, List<LinkTriple> res, List<ImplementationGuideDefinitionPageComponent> page) throws Exception {
    // see if we can find it as an example of an existing profile
    String src = Utilities.fileTitle(n) + ".html";
    for (ImplementationGuideDefinitionResourceComponent r : ig.getDefinition().getResource()) {
        if (src.equals(r.getReference().getReference())) {
            if (r.hasExampleCanonicalType()) {
                String psrc = r.getExampleCanonicalType().getValueAsString().substring(r.getExampleCanonicalType().getValueAsString().lastIndexOf("/") + 1) + ".html";
                if (findPage(psrc, res, page)) {
                    res.add(new LinkTriple(null, r.getName(), null));
                    return true;
                }
            }
        }
    }
    // now, see if we can find a registry to make it a child of
    String id = Utilities.fileTitle(n);
    for (Example e : examples) {
        if (e.getId().equals(id))
            if (findRegistryPage(e.getResourceName(), res, page)) {
                res.add(new LinkTriple(null, e.getName(), null));
                return true;
            }
    }
    if (type.startsWith("profile:"))
        if (findRegistryPage("StructureDefinition", res, page)) {
            res.add(new LinkTriple(null, "Profile", null));
            return true;
        }
    if (findModified(n, "-operations.html", "Operations", res, page))
        return true;
    if (findModified(n, "-questionnaire.html", "Questionnaire", res, page))
        return true;
    if (findModified(n, ".profile.html", "StructureDefinition", res, page))
        return true;
    return false;
}
Also used : ImplementationGuideDefinitionResourceComponent(org.hl7.fhir.r5.model.ImplementationGuide.ImplementationGuideDefinitionResourceComponent)

Example 77 with StructureDefinition

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

the class Publisher method genTypeProfile.

private void genTypeProfile(TypeDefn t) throws Exception {
    StructureDefinition profile;
    try {
        profile = new ProfileGenerator(page.getDefinitions(), page.getWorkerContext(), page, page.getGenDate(), page.getVersion(), dataElements, fpUsages, page.getFolders().rootDir, page.getUml(), page.getRc()).generate(t);
        page.getProfiles().see(profile, page.packageInfo());
        t.setProfile(profile);
        DataTypeTableGenerator dtg = new DataTypeTableGenerator(page.getFolders().dstDir, page, t.getName(), true, page.getVersion());
        t.getProfile().getText().setDiv(new XhtmlNode(NodeType.Element, "div"));
        t.getProfile().getText().getDiv().getChildNodes().add(dtg.generate(t, null, false));
    } catch (Exception e) {
        throw new Exception("Error generating profile for '" + t.getName() + "': " + e.getMessage(), e);
    }
}
Also used : StructureDefinition(org.hl7.fhir.r5.model.StructureDefinition) ProfileGenerator(org.hl7.fhir.definitions.generators.specification.ProfileGenerator) DataTypeTableGenerator(org.hl7.fhir.definitions.generators.specification.DataTypeTableGenerator) TransformerException(javax.xml.transform.TransformerException) IOException(java.io.IOException) FHIRException(org.hl7.fhir.exceptions.FHIRException) FileNotFoundException(java.io.FileNotFoundException) UnsupportedEncodingException(java.io.UnsupportedEncodingException) XhtmlNode(org.hl7.fhir.utilities.xhtml.XhtmlNode)

Example 78 with StructureDefinition

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

the class Publisher method produceTypeProfile.

private void produceTypeProfile(TypeDefn type) throws Exception {
    // ProfileDefn p = new ProfileDefn();
    // p.putMetadata("id", type.getName());
    // p.putMetadata("name", "Basic StructureDefinition for " + type.getName());
    // p.putMetadata("author.name", "FHIR Specification");
    // p.putMetadata("author.ref", "http://hl7.org/fhir");
    // p.putMetadata("description", "Basic StructureDefinition for " + type.getName() + " for validation support");
    // p.putMetadata("status", "draft");
    // p.putMetadata("date", new SimpleDateFormat("yyyy-MM-dd", new Locale("en", "US")).format(new Date()));
    // p.getElements().add(type);
    // ProfileGenerator pgen = new ProfileGenerator(page.getDefinitions());
    // String fn = "type-" + type.getName() + ".profile.xml";
    // StructureDefinition rp = pgen.generate(p, "type-" + type.getName() + ".profile", "<div>Type definition for " + type.getName() + " from <a href=\"http://hl7.org/fhir/datatypes.html#" + type.getName()
    // + "\">FHIR Specification</a></div>");
    String fn = type.getName().toLowerCase() + ".profile.xml";
    StructureDefinition rp = type.getProfile();
    FileOutputStream s = new FileOutputStream(page.getFolders().dstDir + fn);
    new XmlParser().setOutputStyle(OutputStyle.PRETTY).compose(s, rp);
    s.close();
    s = new FileOutputStream(page.getFolders().dstDir + Utilities.changeFileExt(fn, ".canonical.xml"));
    new XmlParser().setOutputStyle(OutputStyle.CANONICAL).compose(s, rp);
    s.close();
    s = new FileOutputStream(page.getFolders().dstDir + Utilities.changeFileExt(fn, ".json"));
    new JsonParser().setOutputStyle(OutputStyle.PRETTY).compose(s, rp);
    s.close();
    s = new FileOutputStream(page.getFolders().dstDir + Utilities.changeFileExt(fn, ".canonical.json"));
    new JsonParser().setOutputStyle(OutputStyle.CANONICAL).compose(s, rp);
    s.close();
    Utilities.copyFile(new CSFile(page.getFolders().dstDir + fn), new CSFile(Utilities.path(page.getFolders().dstDir, "examples", fn)));
    addToResourceFeed(rp, page.getTypeBundle(), fn);
    // saveAsPureHtml(rp, new FileOutputStream(page.getFolders().dstDir+ "html"
    // + File.separator + "datatypes.html"));
    cloneToXhtml(type.getName().toLowerCase() + ".profile", "StructureDefinition for " + type.getName(), false, "profile-instance:type:" + type.getName(), "Type", null, wg("mnm"));
    jsonToXhtml(type.getName().toLowerCase() + ".profile", "StructureDefinition for " + type.getName(), resource2Json(rp), "profile-instance:type:" + type.getName(), "Type", null, wg("mnm"));
    ttlToXhtml(type.getName().toLowerCase() + ".profile", "StructureDefinition for " + type.getName(), resource2Ttl(rp), "profile-instance:type:" + type.getName(), "Type", null, wg("mnm"));
    String shex = new ShExGenerator(page.getWorkerContext()).generate(HTMLLinkPolicy.NONE, rp);
    TextFile.stringToFile(shex, Utilities.changeFileExt(page.getFolders().dstDir + fn, ".shex"));
    shexToXhtml(type.getName().toLowerCase(), "ShEx statement for " + type.getName(), shex, "profile-instance:type:" + type.getName(), "Type", null, wg("mnm"));
}
Also used : XmlParser(org.hl7.fhir.r5.formats.XmlParser) StructureDefinition(org.hl7.fhir.r5.model.StructureDefinition) FileOutputStream(java.io.FileOutputStream) CSFile(org.hl7.fhir.utilities.CSFile) JsonParser(org.hl7.fhir.r5.formats.JsonParser) ShExGenerator(org.hl7.fhir.r5.conformance.ShExGenerator)

Example 79 with StructureDefinition

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

the class JsonSpecGenerator method generateCoreElem.

@SuppressWarnings("rawtypes")
private void generateCoreElem(List<ElementDefinition> elements, ElementDefinition elem, int indent, String pathName, boolean asValue, TypeRefComponent type, boolean last, boolean complex) throws Exception {
    if (elem.getPath().endsWith(".id"))
        return;
    if (!complex && elem.getPath().endsWith(".extension"))
        return;
    if (elem.getMax().equals("0"))
        return;
    String indentS = "";
    for (int i = 0; i < indent; i++) {
        indentS += "  ";
    }
    write(indentS);
    List<ElementDefinition> children = getChildren(elements, elem);
    String name = tail(elem.getPath());
    String en = asValue ? "value[x]" : name;
    String tc = type.getWorkingCode();
    if (en.contains("[x]"))
        en = en.replace("[x]", upFirst(tc));
    boolean unbounded = elem.hasMax() && elem.getMax().equals("*");
    // 1. name
    write("\"<a href=\"" + (defPage + "#" + pathName + "." + en) + "\" title=\"" + Utilities.escapeXml(getEnhancedDefinition(elem)) + "\" class=\"dict\"><span style=\"text-decoration: underline\">" + en + "</span></a>\" : ");
    // 2. value
    boolean delayedCloseArray = false;
    if (unbounded)
        write("[");
    if (type == null) {
        // inline definition
        assert (children.size() > 0);
        write("{");
        delayedCloseArray = true;
    } else if (definitions.getPrimitives().containsKey(tc)) {
        if (!(tc.equals("integer") || tc.equals("boolean") || tc.equals("decimal")))
            write("\"");
        if (elem.hasFixed())
            write(Utilities.escapeJson(((PrimitiveType) elem.getFixed()).asStringValue()));
        else
            write("&lt;<span style=\"color: darkgreen\"><a href=\"" + prefix + (dtRoot + definitions.getSrcFile(tc) + ".html#" + tc) + "\">" + tc + "</a></span>&gt;");
        if (!(tc.equals("integer") || tc.equals("boolean") || tc.equals("decimal")))
            write("\"");
    } else {
        write("{ ");
        write("<span style=\"color: darkgreen\"><a href=\"" + prefix + (dtRoot + definitions.getSrcFile(tc) + ".html#" + tc) + "\">" + tc + "</a></span>");
        if (type.hasProfile()) {
            if (type.getProfile().get(0).getValue().startsWith("http://hl7.org/fhir/StructureDefinition/")) {
                String t = type.getProfile().get(0).getValue().substring(40);
                if (definitions.hasType(t))
                    write("(<span style=\"color: darkgreen\"><a href=\"" + prefix + (dtRoot + definitions.getSrcFile(t) + ".html#" + t) + "\">" + t + "</a></span>)");
                else if (definitions.hasResource(t))
                    write("(<span style=\"color: darkgreen\"><a href=\"" + prefix + dtRoot + t.toLowerCase() + ".html\">" + t + "</a></span>)");
                else
                    write("(" + t + ")");
            } else
                write("(" + type.getProfile() + ")");
        }
        if (type.hasTargetProfile()) {
            if (type.getTargetProfile().get(0).getValue().startsWith("http://hl7.org/fhir/StructureDefinition/")) {
                String t = type.getTargetProfile().get(0).getValue().substring(40);
                if (definitions.hasType(t))
                    write("(<span style=\"color: darkgreen\"><a href=\"" + prefix + (dtRoot + definitions.getSrcFile(t) + ".html#" + t) + "\">" + t + "</a></span>)");
                else if (definitions.hasResource(t))
                    write("(<span style=\"color: darkgreen\"><a href=\"" + prefix + dtRoot + t.toLowerCase() + ".html\">" + t + "</a></span>)");
                else
                    write("(" + t + ")");
            } else
                write("(" + type.getTargetProfile() + ")");
        }
        write(" }");
    }
    if (!delayedCloseArray) {
        if (unbounded)
            write("]");
        if (!last)
            write(",");
    }
    write(" <span style=\"color: Gray\">//</span>");
    // 3. optionality
    writeCardinality(elem);
    // 4. doco
    if (!elem.hasFixed()) {
        if (elem.hasBinding() && elem.getBinding().hasValueSet()) {
            ValueSet vs = resolveValueSet(elem.getBinding().getValueSet());
            if (vs != null)
                write("<span style=\"color: navy; opacity: 0.8\"><a href=\"" + (Utilities.isAbsoluteUrl(vs.getUserString("path")) ? "" : prefix) + vs.getUserData("path") + "\" style=\"color: navy\">" + Utilities.escapeXml(elem.getShort()) + "</a></span>");
            else
                write("<span style=\"color: navy; opacity: 0.8\"><a href=\"" + elem.getBinding().getValueSet() + ".html\" style=\"color: navy\">" + Utilities.escapeXml(elem.getShort()) + "</a></span>");
        } else
            write("<span style=\"color: navy; opacity: 0.8\">" + Utilities.escapeXml(elem.getShort()) + "</span>");
    }
    write("\r\n");
    if (delayedCloseArray) {
        int c = 0;
        for (ElementDefinition child : children) {
            if (child.getType().size() == 1)
                generateCoreElem(elements, child, indent + 1, pathName + "." + name, false, child.getType().get(0), ++c == children.size(), false);
            else {
                write("<span style=\"color: Gray\">// value[x]: <span style=\"color: navy; opacity: 0.8\">" + Utilities.escapeXml(child.getShort()) + "</span>. One of these " + Integer.toString(child.getType().size()) + ":</span>\r\n");
                for (TypeRefComponent t : child.getType()) generateCoreElem(elements, child, indent + 1, pathName + "." + name, false, t, ++c == children.size(), false);
            }
        }
        write("}]");
        if (!last)
            write(",");
    }
}
Also used : TypeRefComponent(org.hl7.fhir.r5.model.ElementDefinition.TypeRefComponent) PrimitiveType(org.hl7.fhir.r5.model.PrimitiveType) ElementDefinition(org.hl7.fhir.r5.model.ElementDefinition) ValueSet(org.hl7.fhir.r5.model.ValueSet)

Example 80 with StructureDefinition

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

the class MappingsGenerator method generate.

public void generate(StructureDefinition profile) throws IOException {
    if (profile.getMapping().isEmpty())
        mappings = "<p>No Mappings</p>";
    else {
        StringBuilder s = new StringBuilder();
        for (StructureDefinitionMappingComponent map : profile.getMapping()) {
            s.append("<a name=\"" + map.getIdentity() + "\"> </a><h3>" + map.getName() + " (" + map.getUri() + ")</h3>");
            if (map.hasComment())
                s.append("<p>" + Utilities.escapeXml(map.getComment()) + "</p>");
            else if (definitions.getMapTypes().containsKey(map.getUri())) {
                XhtmlNode pre = definitions.getMapTypes().get(map.getUri()).getPreamble();
                if (pre != null)
                    s.append(new XhtmlComposer(XhtmlComposer.HTML).compose(pre));
            }
            s.append("<table class=\"grid\">\r\n");
            s.append(" <tr><td colspan=\"3\"><b>" + Utilities.escapeXml(profile.getName()) + "</b></td></tr>\r\n");
            String path = null;
            for (ElementDefinition e : profile.getSnapshot().getElement()) {
                if (path == null || !e.getPath().startsWith(path)) {
                    path = null;
                    if (e.hasMax() && e.getMax().equals("0")) {
                        path = e.getPath() + ".";
                    } else
                        genElement(s, e, map.getIdentity());
                }
            }
            s.append("</table>\r\n");
        }
        mappings = s.toString();
    }
}
Also used : StructureDefinitionMappingComponent(org.hl7.fhir.r5.model.StructureDefinition.StructureDefinitionMappingComponent) XhtmlComposer(org.hl7.fhir.utilities.xhtml.XhtmlComposer) ElementDefinition(org.hl7.fhir.r5.model.ElementDefinition) XhtmlNode(org.hl7.fhir.utilities.xhtml.XhtmlNode)

Aggregations

ArrayList (java.util.ArrayList)307 StructureDefinition (org.hl7.fhir.r5.model.StructureDefinition)241 FHIRException (org.hl7.fhir.exceptions.FHIRException)226 DefinitionException (org.hl7.fhir.exceptions.DefinitionException)158 ElementDefinition (org.hl7.fhir.r5.model.ElementDefinition)144 StructureDefinition (org.hl7.fhir.r4b.model.StructureDefinition)105 ValidationMessage (org.hl7.fhir.utilities.validation.ValidationMessage)98 IOException (java.io.IOException)91 StructureDefinition (org.hl7.fhir.dstu3.model.StructureDefinition)91 XhtmlNode (org.hl7.fhir.utilities.xhtml.XhtmlNode)87 StructureDefinition (org.hl7.fhir.r4.model.StructureDefinition)83 ElementDefinition (org.hl7.fhir.dstu3.model.ElementDefinition)70 CommaSeparatedStringBuilder (org.hl7.fhir.utilities.CommaSeparatedStringBuilder)69 ElementDefinition (org.hl7.fhir.r4b.model.ElementDefinition)67 FHIRFormatError (org.hl7.fhir.exceptions.FHIRFormatError)58 ElementDefinition (org.hl7.fhir.r4.model.ElementDefinition)56 TypeRefComponent (org.hl7.fhir.r5.model.ElementDefinition.TypeRefComponent)50 Piece (org.hl7.fhir.utilities.xhtml.HierarchicalTableGenerator.Piece)49 ProfileUtilities (org.hl7.fhir.r5.conformance.ProfileUtilities)46 Cell (org.hl7.fhir.utilities.xhtml.HierarchicalTableGenerator.Cell)46