use of org.hl7.fhir.r4b.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);
}
}
use of org.hl7.fhir.r4b.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);
}
use of org.hl7.fhir.r4b.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());
}
use of org.hl7.fhir.r4b.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;
}
}
use of org.hl7.fhir.r4b.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;
}
}
Aggregations