use of org.hl7.fhir.r5.formats.IParser 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.r5.formats.IParser 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.r5.formats.IParser in project kindling by HL7.
the class Publisher method resource2Ttl.
private String resource2Ttl(Resource r) throws Exception {
ByteArrayOutputStream bytes = new ByteArrayOutputStream();
IParser rdf = new RdfParser().setOutputStyle(OutputStyle.PRETTY);
rdf.setSuppressXhtml("Snipped for Brevity");
rdf.compose(bytes, r);
bytes.close();
return new String(bytes.toByteArray());
}
use of org.hl7.fhir.r5.formats.IParser in project kindling by HL7.
the class PageProcessor method r2Json.
private String r2Json(ValueSet vs) throws Exception {
ByteArrayOutputStream bytes = new ByteArrayOutputStream();
IParser json = new JsonParser().setOutputStyle(OutputStyle.PRETTY);
json.setSuppressXhtml("Snipped for Brevity");
json.compose(bytes, vs);
return new String(bytes.toByteArray());
}
use of org.hl7.fhir.r5.formats.IParser in project kindling by HL7.
the class BindingsParser method loadValueSet.
private ValueSet loadValueSet(String ref, String committee) throws Exception {
String folder = new File(filename).getParent();
String srcName;
IParser p;
if (new File(Utilities.path(folder, ref + ".xml")).exists()) {
p = new XmlParser();
srcName = Utilities.path(folder, ref + ".xml");
} else if (new File(Utilities.path(folder, ref + ".json")).exists()) {
p = new JsonParser();
srcName = Utilities.path(folder, ref + ".json");
} else
throw new Exception("Unable to find source for " + ref + " in " + filename + " (" + Utilities.path(folder, ref + ".xml/json)"));
FileInputStream input = new FileInputStream(srcName);
try {
ValueSet result = ValueSetUtilities.makeShareable((ValueSet) p.parse(input));
result.setId(ref.substring(9));
if (!result.hasExperimental())
result.setExperimental(false);
// if (!result.hasUrl())
result.setUrl("http://hl7.org/fhir/ValueSet/" + ref.substring(9));
if (!result.hasVersion() || result.getUrl().startsWith("http://hl7.org/fhir"))
result.setVersion(version);
if (!Utilities.noString(committee)) {
if (!result.hasExtension(ToolingExtensions.EXT_WORKGROUP)) {
result.addExtension().setUrl(ToolingExtensions.EXT_WORKGROUP).setValue(new CodeType(committee));
} else {
String ec = ToolingExtensions.readStringExtension(result, ToolingExtensions.EXT_WORKGROUP);
if (!ec.equals(committee))
System.out.println("ValueSet " + result.getUrl() + " WG mismatch 1: is " + ec + ", want to set to " + committee);
}
}
result.setUserData("filename", "valueset-" + ref.substring(9));
result.setUserData("path", "valueset-" + ref.substring(9) + ".html");
new CodeSystemConvertor(codeSystems).convert(p, result, srcName, packageInfo);
return result;
} finally {
IOUtils.closeQuietly(input);
}
}
Aggregations