Search in sources :

Example 16 with ImplementationGuideDefn

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

the class Publisher method cloneToXhtml.

private void cloneToXhtml(String n, String description, boolean adorn, String pageType, String crumbTitle, ImplementationGuideDefn igd, ResourceDefn rd, WorkGroup wg) throws Exception {
    DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
    factory.setNamespaceAware(true);
    DocumentBuilder builder = factory.newDocumentBuilder();
    Document xdoc = builder.parse(new CSFileInputStream(new CSFile(page.getFolders().dstDir + n + ".xml")));
    XhtmlGenerator xhtml = new XhtmlGenerator(new ExampleAdorner(page.getDefinitions(), page.genlevel(Utilities.charCount(n, File.separatorChar))));
    ByteArrayOutputStream b = new ByteArrayOutputStream();
    xhtml.generate(xdoc, b, n.toUpperCase().substring(0, 1) + n.substring(1), description, 0, adorn, n + ".xml.html");
    String html = TextFile.fileToString(page.getFolders().templateDir + "template-example-xml.html").replace("<%example%>", b.toString());
    html = page.processPageIncludes(n + ".xml.html", html, pageType, null, n + ".xml.html", null, null, crumbTitle, (adorn && hasNarrative(xdoc)) ? new Boolean(true) : null, igd, rd, wg);
    TextFile.stringToFile(html, page.getFolders().dstDir + n + ".xml.html");
    // page.getEpub().registerFile(n + ".xml.html", description, EPubManager.XHTML_TYPE);
    page.getHTMLChecker().registerExternal(n + ".xml.html");
}
Also used : DocumentBuilderFactory(javax.xml.parsers.DocumentBuilderFactory) DocumentBuilder(javax.xml.parsers.DocumentBuilder) CSFile(org.hl7.fhir.utilities.CSFile) ByteArrayOutputStream(java.io.ByteArrayOutputStream) Document(org.w3c.dom.Document) XhtmlDocument(org.hl7.fhir.utilities.xhtml.XhtmlDocument) CSFileInputStream(org.hl7.fhir.utilities.CSFileInputStream) XhtmlGenerator(org.hl7.fhir.utilities.xml.XhtmlGenerator)

Example 17 with ImplementationGuideDefn

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

the class Publisher method copyStaticContent.

private void copyStaticContent() throws IOException, Exception {
    if (page.getIni().getPropertyNames("support") != null)
        for (String n : page.getIni().getPropertyNames("support")) {
            Utilities.copyFile(new CSFile(page.getFolders().srcDir + n), new CSFile(page.getFolders().dstDir + n));
            page.getHTMLChecker().registerFile(n, "Support File", HTMLLinkChecker.determineType(n), true);
        }
    for (String n : page.getIni().getPropertyNames("images")) {
        copyImage(page.getFolders().imgDir, n);
    }
    for (ImplementationGuideDefn ig : page.getDefinitions().getSortedIgs()) {
        for (String n : ig.getImageList()) {
            copyIgImage(ig, n);
        }
    }
    for (String n : page.getIni().getPropertyNames("files")) {
        Utilities.copyFile(new CSFile(page.getFolders().rootDir + n), new CSFile(page.getFolders().dstDir + page.getIni().getStringProperty("files", n)));
        page.getHTMLChecker().registerFile(page.getIni().getStringProperty("files", n), "Support File", HTMLLinkChecker.determineType(page.getIni().getStringProperty("files", n)), true);
    }
    page.log("Copy HTML templates", LogMessageType.Process);
    Utilities.copyDirectory(page.getFolders().rootDir + page.getIni().getStringProperty("html", "source"), page.getFolders().dstDir, page.getHTMLChecker());
    TextFile.stringToFile("\r\n[FHIR]\r\nFhirVersion=" + page.getVersion() + "-" + page.getBuildId() + "\r\nversion=" + page.getVersion().toCode() + "\r\nbuildId=" + page.getBuildId() + "\r\ndate=" + new SimpleDateFormat("yyyyMMddHHmmss").format(page.getGenDate().getTime()), Utilities.path(page.getFolders().dstDir, "version.info"), false);
    for (String n : page.getDefinitions().getDiagrams().keySet()) {
        page.log(" ...diagram " + n, LogMessageType.Process);
        page.getSvgs().put(n, TextFile.fileToString(page.getFolders().srcDir + page.getDefinitions().getDiagrams().get(n)));
    }
}
Also used : CSFile(org.hl7.fhir.utilities.CSFile) ImplementationGuideDefn(org.hl7.fhir.definitions.model.ImplementationGuideDefn) SimpleDateFormat(java.text.SimpleDateFormat)

Example 18 with ImplementationGuideDefn

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

the class PageProcessor method produceDataTypeExtras.

private String produceDataTypeExtras(String tn, boolean profiles) {
    int count = 0;
    Map<String, StructureDefinition> map = new HashMap<String, StructureDefinition>();
    for (StructureDefinition sd : workerContext.getExtensionDefinitions()) {
        boolean inc = false;
        for (StructureDefinitionContextComponent ec : sd.getContext()) {
            if (ec.getType() == ExtensionContextType.ELEMENT) {
                inc = inc || matchesType(tn, ec.getExpression());
            }
        }
        if (inc)
            map.put(sd.getId(), sd);
    }
    StringBuilder b = new StringBuilder();
    b.append("  <tr><td colspan=\"3\"><b>Extensions</b> (+ see <a href=\"" + definitions.getElementExtrasLink() + "\">extensions on all Elements</a>)</td></tr>\r\n");
    for (String s : sorted(map.keySet())) {
        StructureDefinition cs = map.get(s);
        count++;
        b.append("  <tr>\r\n");
        String ref = cs.getUserString("path");
        b.append("    <td><a href=\"").append(ref).append("\">").append(Utilities.escapeXml(cs.getId())).append("</a></td>\r\n");
        b.append("    <td>").append(Utilities.escapeXml(cs.getName())).append("</td>\r\n");
        Profile ap = (Profile) cs.getUserData("profile");
        if (ap == null)
            b.append("    <td></td>\r\n");
        else {
            ImplementationGuideDefn ig = definitions.getIgs().get(ap.getCategory());
            b.append("    <td>for <a href=\"" + ig.getPrefix() + ap.getId().toLowerCase() + ".html\">" + Utilities.escapeXml(ap.getTitle()) + "</a></td>\r\n");
        }
        b.append(" </tr>\r\n");
    }
    if (count == 0)
        b.append("<tr><td>No Extensions defined for " + (tn.equals("primitives") ? "primitive types" : "this type") + " (though see <a href=\"element-extensions.html\">extensions on all Elements</a>)</td></tr>");
    if (profiles) {
        count = 0;
        Map<String, CSPair> pmap = new HashMap<String, CSPair>();
        for (Profile ap : definitions.getPackList()) {
            for (ConstraintStructure cs : ap.getProfiles()) {
                if (coversType(cs, tn))
                    pmap.put(cs.getTitle(), new CSPair(ap, cs));
            }
        }
        b.append("  <tr><td colspan=\"3\"><b>Profiles</b></td></tr>\r\n");
        for (String s : sorted(pmap.keySet())) {
            CSPair cs = pmap.get(s);
            ImplementationGuideDefn ig = definitions.getIgs().get(cs.p.getCategory());
            count++;
            b.append("  <tr>\r\n");
            String ref = (ig.isCore() ? "" : ig.getCode() + File.separator) + cs.cs.getId() + ".html";
            b.append("    <td><a href=\"").append(ref).append("\">").append(Utilities.escapeXml(cs.cs.getTitle())).append("</a></td>\r\n");
            b.append("    <td>").append(Utilities.escapeXml(cs.p.getDescription())).append("</td>\r\n");
            ref = (ig.isCore() ? "" : ig.getCode() + File.separator) + cs.p.getId().toLowerCase() + ".html";
            b.append("    <td>for <a href=\"").append(ref).append("\">").append(Utilities.escapeXml(cs.p.getTitle())).append("</a></td>\r\n");
            b.append(" </tr>\r\n");
        }
        if (count == 0)
            b.append("<tr><td>No Profiles defined for for " + (tn.equals("primitives") ? "primitive types" : "this type") + "</td></tr>");
    }
    return b.toString();
}
Also used : StructureDefinitionContextComponent(org.hl7.fhir.r5.model.StructureDefinition.StructureDefinitionContextComponent) CommaSeparatedStringBuilder(org.hl7.fhir.utilities.CommaSeparatedStringBuilder) HashMap(java.util.HashMap) ImplementationGuideDefn(org.hl7.fhir.definitions.model.ImplementationGuideDefn) ContactPoint(org.hl7.fhir.r5.model.ContactPoint) Profile(org.hl7.fhir.definitions.model.Profile) StructureDefinition(org.hl7.fhir.r5.model.StructureDefinition) ConstraintStructure(org.hl7.fhir.definitions.model.ConstraintStructure)

Example 19 with ImplementationGuideDefn

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

the class PageProcessor method buildIgRegistry.

private String buildIgRegistry(ImplementationGuideDefn ig, String types) throws Exception {
    StringBuilder b = new StringBuilder();
    b.append("<table class=\"codes\">\r\n");
    b.append("<tr><td><b>Id</b></td><td><b>Name</b></td><td><b>Description</b></td></tr>\r\n");
    // examples second:
    boolean example = false;
    while (true) {
        boolean usedPurpose = false;
        for (String type : types.split("\\,")) {
            List<String> ids = new ArrayList<String>();
            Map<String, ImplementationGuideDefinitionResourceComponent> map = new HashMap<String, ImplementationGuideDefinitionResourceComponent>();
            for (ImplementationGuideDefinitionResourceComponent r : ig.getIg().getDefinition().getResource()) {
                Resource ar = (Resource) r.getUserData(ToolResourceUtilities.RES_ACTUAL_RESOURCE);
                if (ar != null && ar.getResourceType().toString().equals(type) && r.hasExample() == example) {
                    String id = ar.getId();
                    ids.add(id);
                    map.put(id, r);
                }
                Example ex = (Example) r.getUserData(ToolResourceUtilities.NAME_RES_EXAMPLE);
                if (ex != null && ex.getResourceName().equals(type) && r.hasExample() == example) {
                    String id = ex.getId();
                    ids.add(id);
                    map.put(id, r);
                }
            }
            if (ids.size() > 0) {
                if (!usedPurpose) {
                    b.append("<tr><td colspan=\"3\" style=\"background: #DFDFDF\"><b>" + (example ? "Specification" : "Example") + "</b> </td></tr>\r\n");
                    usedPurpose = true;
                }
                Collections.sort(ids);
                b.append("<tr><td colspan=\"3\" style=\"background: #EFEFEF\">" + getTypePluralDesc(type) + "</td></tr>\r\n");
                for (String id : ids) {
                    ImplementationGuideDefinitionResourceComponent r = map.get(id);
                    b.append("<tr><td><a href=\"" + Utilities.changeFileExt(r.getReference().getReference(), ".html") + "\">" + id + "</a></td><td>" + Utilities.escapeXml(r.getName()) + "</td><td>" + Utilities.escapeXml(r.getDescription()) + "</td></tr>\r\n");
                }
            }
        }
        if (example)
            break;
        else
            example = true;
    }
    b.append("</table>\r\n");
    return b.toString();
}
Also used : CommaSeparatedStringBuilder(org.hl7.fhir.utilities.CommaSeparatedStringBuilder) HashMap(java.util.HashMap) Example(org.hl7.fhir.definitions.model.Example) OperationExample(org.hl7.fhir.definitions.model.Operation.OperationExample) ArrayList(java.util.ArrayList) Resource(org.hl7.fhir.r5.model.Resource) DomainResource(org.hl7.fhir.r5.model.DomainResource) CanonicalResource(org.hl7.fhir.r5.model.CanonicalResource) ImplementationGuideDefinitionResourceComponent(org.hl7.fhir.r5.model.ImplementationGuide.ImplementationGuideDefinitionResourceComponent)

Example 20 with ImplementationGuideDefn

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

the class PageProcessor method genExtensionsTable.

private String genExtensionsTable() throws Exception {
    StringBuilder s = new StringBuilder();
    s.append("<table class=\"list\">\r\n");
    s.append("<tr>");
    s.append("<td><b>Identity</b></td>");
    s.append("<td><b><a href=\"defining-extensions.html#cardinality\">Conf.</a></b></td>");
    s.append("<td><b>Type</b></td>");
    s.append("<td><b><a href=\"defining-extensions.html#context\">Context</a></b></td>");
    s.append("<td><b><a href=\"versions.html#maturity\">FMM</a></b></td>");
    s.append("</tr>");
    List<String> names = new ArrayList<String>();
    for (StructureDefinition sd : workerContext.getExtensionDefinitions()) names.add(sd.getUrl());
    Collections.sort(names);
    Set<StructureDefinition> processed = new HashSet<StructureDefinition>();
    for (ImplementationGuideDefn ig : definitions.getSortedIgs()) {
        // if (ig.isCore()) {
        for (String n : names) {
            StructureDefinition ed = workerContext.fetchResource(StructureDefinition.class, n);
            if (!processed.contains(ed)) {
                processed.add(ed);
                // if (ig.getCode().equals(ToolResourceUtilities.getUsage(ed))) {
                genExtensionRow(ig, s, ed);
            // }
            }
        }
    // }
    }
    s.append("</table>\r\n");
    return s.toString();
}
Also used : StructureDefinition(org.hl7.fhir.r5.model.StructureDefinition) CommaSeparatedStringBuilder(org.hl7.fhir.utilities.CommaSeparatedStringBuilder) ArrayList(java.util.ArrayList) ImplementationGuideDefn(org.hl7.fhir.definitions.model.ImplementationGuideDefn) HashSet(java.util.HashSet)

Aggregations

ImplementationGuideDefn (org.hl7.fhir.definitions.model.ImplementationGuideDefn)34 FHIRException (org.hl7.fhir.exceptions.FHIRException)25 FileNotFoundException (java.io.FileNotFoundException)22 IOException (java.io.IOException)22 TransformerException (javax.xml.transform.TransformerException)21 CSFile (org.hl7.fhir.utilities.CSFile)21 StructureDefinition (org.hl7.fhir.r5.model.StructureDefinition)19 CommaSeparatedStringBuilder (org.hl7.fhir.utilities.CommaSeparatedStringBuilder)18 ContactPoint (org.hl7.fhir.r5.model.ContactPoint)17 File (java.io.File)16 ArrayList (java.util.ArrayList)16 Profile (org.hl7.fhir.definitions.model.Profile)16 ValueSet (org.hl7.fhir.r5.model.ValueSet)15 IniFile (org.hl7.fhir.utilities.IniFile)15 TextFile (org.hl7.fhir.utilities.TextFile)15 Example (org.hl7.fhir.definitions.model.Example)14 UnsupportedEncodingException (java.io.UnsupportedEncodingException)11 URISyntaxException (java.net.URISyntaxException)11 HashMap (java.util.HashMap)10 TransformerConfigurationException (javax.xml.transform.TransformerConfigurationException)10