Search in sources :

Example 1 with RenderingContext

use of org.hl7.fhir.r5.renderers.utils.RenderingContext in project kindling by HL7.

the class Publisher method generateCodeSystemPart2.

private void generateCodeSystemPart2(CodeSystem cs) throws Exception {
    String n = cs.getUserString("filename");
    if (n == null)
        n = "codesystem-" + cs.getId();
    ImplementationGuideDefn ig = (ImplementationGuideDefn) cs.getUserData(ToolResourceUtilities.NAME_RES_IG);
    if (ig != null)
        n = ig.getCode() + File.separator + n;
    if (cs.getText().getDiv().allChildrenAreText() && (Utilities.noString(cs.getText().getDiv().allText()) || !cs.getText().getDiv().allText().matches(".*\\w.*"))) {
        RenderingContext lrc = page.getRc().copy().setLocalPrefix(ig != null ? "../" : "").setTooCostlyNoteEmpty(PageProcessor.TOO_MANY_CODES_TEXT_EMPTY).setTooCostlyNoteNotEmpty(PageProcessor.TOO_MANY_CODES_TEXT_NOT_EMPTY);
        RendererFactory.factory(cs, lrc).render(cs);
    }
    page.getVsValidator().validate(page.getValidationErrors(), n, cs, true, false);
    if (isGenerate) {
        // page.log(" ... "+n, LogMessageType.Process);
        addToResourceFeed(cs, valueSetsFeed, null);
        if (cs.getUserData("path") == null)
            cs.setUserData("path", n + ".html");
        page.setId(cs.getId());
        String sf;
        WorkGroup wg = wg(cs, "vocab");
        try {
            sf = page.processPageIncludes(n + ".html", TextFile.fileToString(page.getFolders().templateDir + "template-cs.html"), "codeSystem", null, n + ".html", cs, null, "Value Set", ig, null, wg);
        } catch (Exception e) {
            throw new Exception("Error processing " + n + ".html: " + e.getMessage(), e);
        }
        sf = addSectionNumbers(n + ".html", "template-codesystem", sf, csCounter(), ig == null ? 0 : 1, null, ig);
        TextFile.stringToFile(sf, page.getFolders().dstDir + n + ".html");
        try {
            String src = page.processPageIncludesForBook(n + ".html", TextFile.fileToString(page.getFolders().templateDir + "template-cs-book.html"), "codeSystem", cs, ig, null);
            cachePage(n + ".html", src, "Code System " + n, false);
            page.setId(null);
        } catch (Exception e) {
            throw new Exception("Error processing " + n + ".html: " + e.getMessage(), e);
        }
        IParser json = new JsonParser().setOutputStyle(OutputStyle.PRETTY);
        FileOutputStream s = new FileOutputStream(page.getFolders().dstDir + n + ".json");
        json.compose(s, cs);
        s.close();
        json = new JsonParser().setOutputStyle(OutputStyle.CANONICAL);
        s = new FileOutputStream(page.getFolders().dstDir + n + ".canonical.json");
        json.compose(s, cs);
        s.close();
        IParser xml = new XmlParser().setOutputStyle(OutputStyle.PRETTY);
        s = new FileOutputStream(page.getFolders().dstDir + n + ".xml");
        xml.compose(s, cs);
        s.close();
        xml = new XmlParser().setOutputStyle(OutputStyle.CANONICAL);
        s = new FileOutputStream(page.getFolders().dstDir + n + ".canonical.xml");
        xml.compose(s, cs);
        s.close();
        // System.out.println(vs.getUrl());
        cloneToXhtml(n, "Definition for Code System " + cs.getName(), false, "codesystem-instance", "Code System", null, wg);
        jsonToXhtml(n, "Definition for Code System " + cs.getName(), resource2Json(cs), "codesystem-instance", "Code System", null, wg);
        ttlToXhtml(n, "Definition for Code System " + cs.getName(), resource2Ttl(cs), "codesystem-instance", "Code System", null, wg);
    }
}
Also used : RenderingContext(org.hl7.fhir.r5.renderers.utils.RenderingContext) WorkGroup(org.hl7.fhir.definitions.model.WorkGroup) XmlParser(org.hl7.fhir.r5.formats.XmlParser) FileOutputStream(java.io.FileOutputStream) ImplementationGuideDefn(org.hl7.fhir.definitions.model.ImplementationGuideDefn) TransformerException(javax.xml.transform.TransformerException) IOException(java.io.IOException) FHIRException(org.hl7.fhir.exceptions.FHIRException) FileNotFoundException(java.io.FileNotFoundException) UnsupportedEncodingException(java.io.UnsupportedEncodingException) IParser(org.hl7.fhir.r5.formats.IParser) JsonParser(org.hl7.fhir.r5.formats.JsonParser)

Example 2 with RenderingContext

use of org.hl7.fhir.r5.renderers.utils.RenderingContext in project kindling by HL7.

the class Publisher method generateConceptMap.

private void generateConceptMap(ConceptMap cm) throws Exception {
    String filename = cm.getUserString("path");
    RenderingContext lrc = page.getRc().copy().setLocalPrefix("").setTooCostlyNoteEmpty(PageProcessor.TOO_MANY_CODES_TEXT_EMPTY).setTooCostlyNoteNotEmpty(PageProcessor.TOO_MANY_CODES_TEXT_NOT_EMPTY);
    RendererFactory.factory(cm, lrc).render(cm);
    IParser json = new JsonParser().setOutputStyle(OutputStyle.PRETTY);
    FileOutputStream s = new FileOutputStream(page.getFolders().dstDir + Utilities.changeFileExt(filename, ".json"));
    json.compose(s, cm);
    s.close();
    json = new JsonParser().setOutputStyle(OutputStyle.CANONICAL);
    s = new FileOutputStream(page.getFolders().dstDir + Utilities.changeFileExt(filename, ".canonical.json"));
    json.compose(s, cm);
    s.close();
    String n = Utilities.changeFileExt(filename, "");
    jsonToXhtml(n, cm.getName(), resource2Json(cm), "conceptmap-instance", "Concept Map", null, wg("vocab"));
    ttlToXhtml(n, cm.getName(), resource2Ttl(cm), "conceptmap-instance", "Concept Map", null, wg("vocab"));
    IParser xml = new XmlParser().setOutputStyle(OutputStyle.PRETTY);
    s = new FileOutputStream(page.getFolders().dstDir + Utilities.changeFileExt(filename, ".xml"));
    xml.compose(s, cm);
    s.close();
    xml = new XmlParser().setOutputStyle(OutputStyle.CANONICAL);
    s = new FileOutputStream(page.getFolders().dstDir + Utilities.changeFileExt(filename, ".canonical.xml"));
    xml.compose(s, cm);
    s.close();
    cloneToXhtml(n, cm.getName(), false, "conceptmap-instance", "Concept Map", null, wg("vocab"));
    // now, we create an html page from the narrative
    String narrative = new XhtmlComposer(XhtmlComposer.HTML).compose(cm.getText().getDiv());
    String html = TextFile.fileToString(page.getFolders().templateDir + "template-example.html").replace("<%example%>", narrative);
    html = page.processPageIncludes(Utilities.changeFileExt(filename, ".html"), html, "conceptmap-instance", null, null, null, "Concept Map", null, null, wg("vocab"));
    TextFile.stringToFile(html, page.getFolders().dstDir + Utilities.changeFileExt(filename, ".html"));
    conceptMapsFeed.getEntry().add(new BundleEntryComponent().setResource(cm).setFullUrl("http://hl7.org/fhir/" + cm.fhirType() + "/" + cm.getId()));
    page.getConceptMaps().see(cm, page.packageInfo());
    page.getHTMLChecker().registerFile(n + ".html", cm.getName(), HTMLLinkChecker.XHTML_TYPE, false);
}
Also used : RenderingContext(org.hl7.fhir.r5.renderers.utils.RenderingContext) XmlParser(org.hl7.fhir.r5.formats.XmlParser) BundleEntryComponent(org.hl7.fhir.r5.model.Bundle.BundleEntryComponent) FileOutputStream(java.io.FileOutputStream) XhtmlComposer(org.hl7.fhir.utilities.xhtml.XhtmlComposer) IParser(org.hl7.fhir.r5.formats.IParser) JsonParser(org.hl7.fhir.r5.formats.JsonParser)

Example 3 with RenderingContext

use of org.hl7.fhir.r5.renderers.utils.RenderingContext in project kindling by HL7.

the class Publisher method produceConceptMap.

private void produceConceptMap(ConceptMap cm, ResourceDefn rd, SectionTracker st) throws Exception {
    RenderingContext lrc = page.getRc().copy().setLocalPrefix("");
    RendererFactory.factory(cm, lrc).render(cm);
    String n = cm.getUserString("path");
    FileOutputStream s = new FileOutputStream(page.getFolders().dstDir + Utilities.changeFileExt(n, ".xml"));
    new XmlParser().setOutputStyle(OutputStyle.PRETTY).compose(s, cm);
    s.close();
    s = new FileOutputStream(page.getFolders().dstDir + Utilities.changeFileExt(n, ".canonical.xml"));
    new XmlParser().setOutputStyle(OutputStyle.CANONICAL).compose(s, cm);
    s.close();
    s = new FileOutputStream(page.getFolders().dstDir + Utilities.changeFileExt(n, ".json"));
    new JsonParser().setOutputStyle(OutputStyle.PRETTY).compose(s, cm);
    s.close();
    s = new FileOutputStream(page.getFolders().dstDir + Utilities.changeFileExt(n, ".canonical.json"));
    new JsonParser().setOutputStyle(OutputStyle.CANONICAL).compose(s, cm);
    s.close();
    Utilities.copyFile(new CSFile(page.getFolders().dstDir + Utilities.changeFileExt(n, ".xml")), new CSFile(page.getFolders().dstDir + "examples" + File.separator + Utilities.changeFileExt(n, ".xml")));
    // saveAsPureHtml(cm, new FileOutputStream(Utilities.path(page.getFolders().dstDir, "html", n)), true);
    String src = TextFile.fileToString(page.getFolders().templateDir + "template-status-map.html");
    Map<String, String> others = new HashMap<String, String>();
    others.put("status-map", new XhtmlComposer(XhtmlComposer.HTML).compose(cm.getText().getDiv()));
    TextFile.stringToFile(insertSectionNumbers(page.processPageIncludes(n, src, "conceptmap-instance", others, null, null, "Profile", null, rd, rd.getWg()), st, n, 0, null), page.getFolders().dstDir + n);
    page.getHTMLChecker().registerFile(n, cm.getTitle(), HTMLLinkChecker.XHTML_TYPE, true);
    cloneToXhtml(Utilities.changeFileExt(n, ""), cm.getTitle(), true, "conceptmap-instance", "Profile", null, ((ResourceDefn) cm.getUserData("resource-definition")).getWg());
    jsonToXhtml(Utilities.changeFileExt(n, ""), cm.getTitle(), resource2Json(cm), "conceptmap-instance", "Profile", null, ((ResourceDefn) cm.getUserData("resource-definition")).getWg());
    ttlToXhtml(Utilities.changeFileExt(n, ""), cm.getTitle(), resource2Ttl(cm), "conceptmap-instance", "Profile", null, ((ResourceDefn) cm.getUserData("resource-definition")).getWg());
}
Also used : RenderingContext(org.hl7.fhir.r5.renderers.utils.RenderingContext) XmlParser(org.hl7.fhir.r5.formats.XmlParser) LinkedHashMap(java.util.LinkedHashMap) HashMap(java.util.HashMap) FileOutputStream(java.io.FileOutputStream) XhtmlComposer(org.hl7.fhir.utilities.xhtml.XhtmlComposer) CSFile(org.hl7.fhir.utilities.CSFile) JsonParser(org.hl7.fhir.r5.formats.JsonParser)

Example 4 with RenderingContext

use of org.hl7.fhir.r5.renderers.utils.RenderingContext in project kindling by HL7.

the class PageProcessor method expandVS.

public String expandVS(ValueSet vs, String prefix, String base) {
    try {
        ValueSetExpansionOutcome result = workerContext.expandVS(vs, true, true);
        if (result.getError() != null)
            return "<hr/>\r\n" + VS_INC_START + "<!--3-->" + processExpansionError(result.getError()) + VS_INC_END;
        if (result.getValueset() == null)
            return "<hr/>\r\n" + VS_INC_START + "<!--4-->" + processExpansionError("(no error returned)") + VS_INC_END;
        ValueSet exp = result.getValueset();
        if (exp == vs)
            throw new Exception("Expansion cannot be the same instance");
        exp.setCompose(null);
        exp.setText(null);
        exp.setDescription("Value Set Contents (Expansion) for " + vs.present() + " at " + Config.DATE_FORMAT().format(new Date()));
        int i = countContains(exp.getExpansion().getContains());
        IniFile sini = new IniFile(Utilities.path(folders.rootDir, "temp", "stats.ini"));
        sini.setIntegerProperty("valuesets", vs.getId(), i, null);
        sini.save();
        RenderingContext lrc = rc.copy().setLocalPrefix(prefix).setTooCostlyNoteEmpty(TOO_MANY_CODES_TEXT_EMPTY).setTooCostlyNoteNotEmpty(TOO_MANY_CODES_TEXT_NOT_EMPTY);
        RendererFactory.factory(exp, lrc).render(exp);
        return "<hr/>\r\n" + VS_INC_START + "" + new XhtmlComposer(XhtmlComposer.HTML).compose(exp.getText().getDiv()) + VS_INC_END;
    } catch (Exception e) {
        e.printStackTrace();
        return "<hr/>\r\n" + VS_INC_START + "<!--5-->" + processExpansionError(e instanceof NullPointerException ? "NullPointerException" : e.getMessage()) + " " + Utilities.escapeXml(stack(e)) + VS_INC_END;
    }
}
Also used : RenderingContext(org.hl7.fhir.r5.renderers.utils.RenderingContext) IniFile(org.hl7.fhir.utilities.IniFile) XhtmlComposer(org.hl7.fhir.utilities.xhtml.XhtmlComposer) ValueSetExpansionOutcome(org.hl7.fhir.r5.terminologies.ValueSetExpander.ValueSetExpansionOutcome) ValueSet(org.hl7.fhir.r5.model.ValueSet) 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) Date(java.util.Date) ContactPoint(org.hl7.fhir.r5.model.ContactPoint)

Example 5 with RenderingContext

use of org.hl7.fhir.r5.renderers.utils.RenderingContext in project kindling by HL7.

the class PageProcessor method expandValueSetIG.

private String expandValueSetIG(ValueSet vs, boolean heirarchy) throws Exception {
    if (!hasDynamicContent(vs))
        return "";
    try {
        ValueSetExpansionOutcome result = workerContext.expandVS(vs, true, heirarchy);
        if (result.getError() != null)
            return "<hr/>\r\n" + VS_INC_START + "<!--1-->" + processExpansionError(result.getError()) + VS_INC_END;
        ValueSet exp = result.getValueset();
        if (exp == vs)
            throw new Exception("Expansion cannot be the same instance");
        exp.setCompose(null);
        exp.setText(null);
        exp.setDescription("Value Set Contents (Expansion) for " + vs.present() + " at " + Config.DATE_FORMAT().format(new Date()));
        RenderingContext lrc = rc.copy().setTooCostlyNoteEmpty(TOO_MANY_CODES_TEXT_EMPTY).setTooCostlyNoteNotEmpty(TOO_MANY_CODES_TEXT_NOT_EMPTY);
        RendererFactory.factory(exp, lrc).render(exp);
        return "<hr/>\r\n" + VS_INC_START + "" + new XhtmlComposer(XhtmlComposer.HTML).compose(exp.getText().getDiv()) + VS_INC_END;
    } catch (Exception e) {
        return "<hr/>\r\n" + VS_INC_START + "<!--2-->" + processExpansionError(e.getMessage()) + VS_INC_END;
    }
}
Also used : RenderingContext(org.hl7.fhir.r5.renderers.utils.RenderingContext) XhtmlComposer(org.hl7.fhir.utilities.xhtml.XhtmlComposer) ValueSetExpansionOutcome(org.hl7.fhir.r5.terminologies.ValueSetExpander.ValueSetExpansionOutcome) ValueSet(org.hl7.fhir.r5.model.ValueSet) 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) Date(java.util.Date)

Aggregations

RenderingContext (org.hl7.fhir.r5.renderers.utils.RenderingContext)22 FHIRException (org.hl7.fhir.exceptions.FHIRException)14 FileOutputStream (java.io.FileOutputStream)13 XmlParser (org.hl7.fhir.r5.formats.XmlParser)13 XhtmlComposer (org.hl7.fhir.utilities.xhtml.XhtmlComposer)11 IOException (java.io.IOException)10 ArrayList (java.util.ArrayList)10 FileNotFoundException (java.io.FileNotFoundException)9 JsonParser (org.hl7.fhir.r5.formats.JsonParser)8 Cell (org.hl7.fhir.utilities.xhtml.HierarchicalTableGenerator.Cell)8 TransformerException (javax.xml.transform.TransformerException)6 NotImplementedException (org.apache.commons.lang3.NotImplementedException)6 DefinitionException (org.hl7.fhir.exceptions.DefinitionException)6 PathEngineException (org.hl7.fhir.exceptions.PathEngineException)6 StructureDefinition (org.hl7.fhir.r5.model.StructureDefinition)6 Piece (org.hl7.fhir.utilities.xhtml.HierarchicalTableGenerator.Piece)6 StructureDefinition (org.hl7.fhir.r4b.model.StructureDefinition)5 ValueSet (org.hl7.fhir.r5.model.ValueSet)5 ParserConfigurationException (javax.xml.parsers.ParserConfigurationException)4 IParser (org.hl7.fhir.r5.formats.IParser)4