use of org.hl7.fhir.utilities.CSFileInputStream in project kindling by HL7.
the class Publisher method generateCodeSystemRegistry.
private void generateCodeSystemRegistry() throws FileNotFoundException, IOException, Exception {
XmlParser xml = new XmlParser();
xml.setOutputStyle(OutputStyle.PRETTY);
Bundle bnd = (Bundle) xml.parse(new CSFileInputStream(Utilities.path(page.getFolders().srcDir, "namingsystem", "namingsystem-terminologies.xml")));
for (BundleEntryComponent entry : bnd.getEntry()) {
NamingSystem ns = (NamingSystem) entry.getResource();
entry.setFullUrl("http://hl7.org/fhir/NamingSystem/" + ns.getId());
String url = null;
for (NamingSystemUniqueIdComponent t : ns.getUniqueId()) {
if (t.getType() == NamingSystemIdentifierType.URI)
url = t.getValue();
}
if (url != null) {
if (url.startsWith("http://hl7.org/fhir"))
page.getDefinitions().addNs(url, "System " + ns.getName(), "terminologies-systems.html#" + url);
page.getDefinitions().addNs(entry.getFullUrl(), ns.getId(), "terminologies-systems.html#" + url);
}
}
List<String> names = new ArrayList<String>();
Set<String> urls = new HashSet<>();
names.addAll(page.getCodeSystems().keys());
Collections.sort(names);
for (String n : names) {
CodeSystem cs = page.getCodeSystems().get(n);
if (cs != null && !urls.contains(cs.getUrl()) && cs.hasUrl() && !cs.getUrl().startsWith("http://terminology.hl7.org")) {
urls.add(cs.getUrl());
if (cs.hasName()) {
NamingSystem ns = new NamingSystem();
ns.setId(cs.getId());
ns.setName(cs.getName());
ns.setStatus(cs.getStatus());
if (!ns.hasStatus())
ns.setStatus(PublicationStatus.DRAFT);
ns.setKind(NamingSystemType.CODESYSTEM);
ns.setPublisher(cs.getPublisher());
for (ContactDetail c : cs.getContact()) {
ContactDetail nc = ns.addContact();
nc.setName(c.getName());
for (ContactPoint cc : c.getTelecom()) {
nc.getTelecom().add(cc);
}
}
ns.setDate(cs.getDate());
if (!ns.hasDate())
ns.setDate(page.getGenDate().getTime());
ns.setDescription(cs.getDescription());
ns.addUniqueId().setType(NamingSystemIdentifierType.URI).setValue(cs.getUrl()).setPreferred(true);
String oid = CodeSystemUtilities.getOID(cs);
if (oid != null) {
if (oid.startsWith("urn:oid:"))
oid = oid.substring(8);
ns.addUniqueId().setType(NamingSystemIdentifierType.OID).setValue(oid).setPreferred(false);
}
ns.setUserData("path", cs.getUserData("path"));
bnd.addEntry().setResource(ns).setFullUrl("http://hl7.org/fhir/" + ns.fhirType() + "/" + ns.getId());
}
}
}
xml.compose(new FileOutputStream(Utilities.path(page.getFolders().dstDir, "namingsystem-terminologies.xml")), bnd);
cloneToXhtml("namingsystem-terminologies", "Terminology Registry", false, "resource-instance:NamingSystem", "Terminology Registry", null, wg("vocab"));
xml.setOutputStyle(OutputStyle.CANONICAL);
xml.compose(new FileOutputStream(Utilities.path(page.getFolders().dstDir, "namingsystem-terminologies.canonical.xml")), bnd);
JsonParser json = new JsonParser();
json.setOutputStyle(OutputStyle.PRETTY);
json.compose(new FileOutputStream(Utilities.path(page.getFolders().dstDir, "namingsystem-terminologies.json")), bnd);
jsonToXhtml("namingsystem-terminologies", "Terminology Registry", TextFile.fileToString(Utilities.path(page.getFolders().dstDir, "namingsystem-terminologies.json")), "resource-instance:NamingSystem", "Terminology Registry", null, wg("vocab"));
json.setOutputStyle(OutputStyle.CANONICAL);
json.compose(new FileOutputStream(Utilities.path(page.getFolders().dstDir, "namingsystem-terminologies.canonical.json")), bnd);
RdfParser rdf = new RdfParser();
rdf.setOutputStyle(OutputStyle.PRETTY);
rdf.compose(new FileOutputStream(Utilities.path(page.getFolders().dstDir, "namingsystem-terminologies.ttl")), bnd);
ttlToXhtml("namingsystem-terminologies", "Terminology Registry", TextFile.fileToString(Utilities.path(page.getFolders().dstDir, "namingsystem-terminologies.ttl")), "resource-instance:NamingSystem", "Terminology Registry", null, wg("vocab"));
StringBuilder b = new StringBuilder();
b.append("<table class=\"grid\">\r\n");
b.append(" <tr>");
b.append("<td><b>Name</b></td>");
b.append("<td><b>Uri</b></td>");
b.append("<td><b>OID</b></td>");
b.append("</tr>\r\n");
for (BundleEntryComponent entry : bnd.getEntry()) {
NamingSystem ns = (NamingSystem) entry.getResource();
String uri = "";
String oid = "";
for (NamingSystemUniqueIdComponent id : ns.getUniqueId()) {
if (id.getType() == NamingSystemIdentifierType.URI)
uri = id.getValue();
if (id.getType() == NamingSystemIdentifierType.OID)
oid = id.getValue();
}
String link = "terminologies-systems.html#" + uri;
if (ns.getUserData("path") != null)
link = ns.getUserString("path");
b.append(" <tr>");
b.append("<td><a href=\"" + link + "\">" + Utilities.escapeXml(ns.getName()) + "</a></td>");
b.append("<td>" + Utilities.escapeXml(uri) + "</td>");
b.append("<td>" + Utilities.escapeXml(oid) + "</td>");
b.append("</tr>\r\n");
}
b.append("</table>\r\n");
String html = TextFile.fileToString(page.getFolders().templateDir + "template-example.html").replace("<%example%>", b.toString()).replace("<%example-usage%>", "");
html = page.processPageIncludes("namingsystem-terminologies.html", html, "resource-instance:NamingSystem", null, bnd, null, "Example", null, null, page.getDefinitions().getWorkgroups().get("fhir"));
TextFile.stringToFile(html, page.getFolders().dstDir + "namingsystem-terminologies.html");
cachePage("namingsystem-terminologies.html", html, "Registered Code Systems", false);
}
use of org.hl7.fhir.utilities.CSFileInputStream in project kindling by HL7.
the class Publisher method produceProfile.
private void produceProfile(ResourceDefn resource, Profile pack, ConstraintStructure profile, SectionTracker st, String intro, String notes, String prefix, ImplementationGuideDefn ig) throws Exception {
File tmp = Utilities.createTempFile("tmp", ".tmp");
String title = profile.getId();
int level = (ig == null || ig.isCore()) ? 0 : 1;
// you have to validate a profile, because it has to be merged with it's
// base resource to fill out all the missing bits
// validateProfile(profile);
ByteArrayOutputStream bs = new ByteArrayOutputStream();
XmlSpecGenerator gen = new XmlSpecGenerator(bs, title + "-definitions.html", "", page, ig.isCore() ? "" : "../");
gen.generate(profile.getResource());
gen.close();
String xml = new String(bs.toByteArray());
bs = new ByteArrayOutputStream();
JsonSpecGenerator genJ = new JsonSpecGenerator(bs, title + "-definitions.html", "", page, ig.isCore() ? "" : "../", page.getVersion().toCode());
genJ.generate(profile.getResource());
genJ.close();
String json = new String(bs.toByteArray());
XmlParser comp = new XmlParser();
FileOutputStream s = new FileOutputStream(page.getFolders().dstDir + prefix + title + ".profile.xml");
comp.setOutputStyle(OutputStyle.PRETTY).compose(s, profile.getResource());
s.close();
Utilities.copyFile(new CSFile(page.getFolders().dstDir + prefix + title + ".profile.xml"), new CSFile(page.getFolders().dstDir + "examples" + File.separator + title + ".profile.xml"));
JsonParser jcomp = new JsonParser();
s = new FileOutputStream(page.getFolders().dstDir + prefix + title + ".profile.json");
jcomp.setOutputStyle(OutputStyle.PRETTY).compose(s, profile.getResource());
s.close();
// String shex = new ShExGenerator(page.getWorkerContext()).generate(HTMLLinkPolicy.NONE, profile.getResource());
// TextFile.stringToFile(shex, Utilities.changeFileExt(page.getFolders().dstDir + prefix +title + ".profile.shex", ".shex"));
// shexToXhtml(prefix +title + ".profile", "ShEx statement for " + prefix +title, shex, "profile-instance:type:" + title, "Type");
TerminologyNotesGenerator tgen = new TerminologyNotesGenerator(new FileOutputStream(tmp), page);
tgen.generate(level == 0 ? "" : "../", profile);
tgen.close();
String tx = TextFile.fileToString(tmp.getAbsolutePath());
String src = TextFile.fileToString(page.getFolders().templateDir + "template-profile.html");
src = page.processProfileIncludes(profile.getId(), profile.getId(), pack, profile, xml, json, tx, src, title + ".html", (resource == null ? profile.getResource().getType() : resource.getName()) + "/" + pack.getId() + "/" + profile.getId(), intro, notes, ig, false, false);
if (st != null)
src = insertSectionNumbers(src, st, title + ".html", level, null);
else if (ig != null && !ig.isCore()) {
src = addSectionNumbers(title + ".html", title, src, null, 1, null, ig);
st = page.getSectionTrackerCache().get(ig.getCode() + "::" + title);
}
page.getHTMLChecker().registerFile(prefix + title + ".html", "StructureDefinition " + profile.getResource().getName(), HTMLLinkChecker.XHTML_TYPE, false);
TextFile.stringToFile(src, page.getFolders().dstDir + prefix + title + ".html");
new ProfileUtilities(page.getWorkerContext(), page.getValidationErrors(), page).generateSchematrons(new FileOutputStream(page.getFolders().dstDir + prefix + title + ".sch"), profile.getResource());
if (pack.getExamples().size() > 0) {
src = TextFile.fileToString(page.getFolders().templateDir + "template-profile-examples.html");
src = page.processProfileIncludes(profile.getId(), profile.getId(), pack, profile, xml, json, tx, src, title + ".html", (resource == null ? profile.getResource().getType() : resource.getName()) + "/" + pack.getId() + "/" + profile.getId(), intro, notes, ig, false, false);
page.getHTMLChecker().registerFile(prefix + title + "-examples.html", "Examples for StructureDefinition " + profile.getResource().getName(), HTMLLinkChecker.XHTML_TYPE, true);
TextFile.stringToFile(src, page.getFolders().dstDir + prefix + title + "-examples.html");
}
src = TextFile.fileToString(page.getFolders().templateDir + "template-profile-definitions.html");
src = page.processProfileIncludes(profile.getId(), profile.getId(), pack, profile, xml, json, tx, src, title + ".html", (resource == null ? profile.getResource().getType() : resource.getName()) + "/" + pack.getId() + "/" + profile.getId(), intro, notes, ig, false, false);
if (st != null)
src = insertSectionNumbers(src, st, title + "-definitions.html", level, null);
page.getHTMLChecker().registerFile(prefix + title + "-definitions.html", "Definitions for StructureDefinition " + profile.getResource().getName(), HTMLLinkChecker.XHTML_TYPE, true);
TextFile.stringToFile(src, page.getFolders().dstDir + prefix + title + "-definitions.html");
src = TextFile.fileToString(page.getFolders().templateDir + "template-profile-mappings.html");
src = page.processProfileIncludes(profile.getId(), profile.getId(), pack, profile, xml, json, tx, src, title + ".html", (resource == null ? profile.getResource().getType() : resource.getName()) + "/" + pack.getId() + "/" + profile.getId(), intro, notes, ig, false, false);
if (st != null)
src = insertSectionNumbers(src, st, title + "-mappings.html", level, null);
page.getHTMLChecker().registerFile(prefix + title + "-mappings.html", "Mappings for StructureDefinition " + profile.getResource().getName(), HTMLLinkChecker.XHTML_TYPE, true);
TextFile.stringToFile(src, page.getFolders().dstDir + prefix + title + "-mappings.html");
try {
processQuestionnaire(resource, profile.getResource(), st, false, prefix, ig);
} catch (Exception e) {
e.printStackTrace();
page.log("Questionnaire Generation Failed: " + e.getMessage(), LogMessageType.Error);
}
new ReviewSpreadsheetGenerator().generate(page.getFolders().dstDir + prefix + Utilities.changeFileExt((String) profile.getResource().getUserData("filename"), "-review.xls"), "Health Level Seven International", page.getGenDate(), profile.getResource(), page);
// xml to xhtml of xml
// first pass is to strip the xsi: stuff. seems to need double
// processing in order to delete namespace crap
DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
factory.setNamespaceAware(true);
DocumentBuilder builder = factory.newDocumentBuilder();
Document xdoc = builder.parse(new CSFileInputStream(page.getFolders().dstDir + prefix + title + ".profile.xml"));
XmlGenerator xmlgen = new XmlGenerator();
xmlgen.generate(xdoc.getDocumentElement(), tmp, "http://hl7.org/fhir", xdoc.getDocumentElement().getLocalName());
// reload it now
builder = factory.newDocumentBuilder();
xdoc = builder.parse(new CSFileInputStream(tmp.getAbsolutePath()));
XhtmlGenerator xhtml = new XhtmlGenerator(new ExampleAdorner(page.getDefinitions(), page.genlevel(level)));
ByteArrayOutputStream b = new ByteArrayOutputStream();
xhtml.generate(xdoc, b, "StructureDefinition", profile.getTitle(), 0, true, title + ".profile.xml.html");
String html = TextFile.fileToString(page.getFolders().templateDir + "template-profile-example-xml.html").replace("<%example%>", b.toString());
html = page.processProfileIncludes(title + ".profile.xml.html", profile.getId(), pack, profile, "", "", "", html, title + ".html", (resource == null ? profile.getResource().getType() : resource.getName()) + "/" + pack.getId() + "/" + profile.getId(), intro, notes, ig, false, hasNarrative(xdoc));
TextFile.stringToFile(html, page.getFolders().dstDir + prefix + title + ".profile.xml.html");
page.getHTMLChecker().registerFile(prefix + title + ".profile.xml.html", "StructureDefinition", HTMLLinkChecker.XHTML_TYPE, false);
String n = prefix + title + ".profile";
json = resource2Json(profile.getResource());
json = "<div class=\"example\">\r\n<p>" + Utilities.escapeXml("StructureDefinition for " + profile.getResource().getDescription()) + "</p>\r\n<p><a href=\"" + title + ".profile.json\">Raw JSON</a></p>\r\n<pre class=\"json\">\r\n" + Utilities.escapeXml(json) + "\r\n</pre>\r\n</div>\r\n";
html = TextFile.fileToString(page.getFolders().templateDir + "template-profile-example-json.html").replace("<%example%>", json);
html = page.processProfileIncludes(title + ".profile.json.html", profile.getId(), pack, profile, "", "", "", html, title + ".html", (resource == null ? profile.getResource().getType() : resource.getName()) + "/" + pack.getId() + "/" + profile.getId(), intro, notes, ig, false, false);
TextFile.stringToFile(html, page.getFolders().dstDir + prefix + title + ".profile.json.html");
// page.getEpub().registerFile(n + ".json.html", description, EPubManager.XHTML_TYPE);
page.getHTMLChecker().registerExternal(n + ".json.html");
tmp.delete();
}
use of org.hl7.fhir.utilities.CSFileInputStream 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");
}
use of org.hl7.fhir.utilities.CSFileInputStream in project kindling by HL7.
the class PageProcessor method cloneToXhtml.
private void cloneToXhtml(String src, String dst, String name, String description, int level, boolean adorn, String pageType, String crumbTitle, ImplementationGuideDefn ig, 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(src)));
// XhtmlGenerator xhtml = new XhtmlGenerator(null);
// xhtml.generate(xdoc, new CSFile(dst), name, description, level, adorn);
String n = new File(dst).getName();
n = n.substring(0, n.length() - 9);
XhtmlGenerator xhtml = new XhtmlGenerator(new ExampleAdorner(definitions, genlevel(level)));
ByteArrayOutputStream b = new ByteArrayOutputStream();
xhtml.generate(xdoc, b, name, description, level, adorn, n + ".xml.html");
String html = ("<%setlevel " + Integer.toString(level) + "%>" + TextFile.fileToString(folders.srcDir + "template-example-xml.html")).replace("<%example%>", b.toString());
html = processPageIncludes(n + ".xml.html", html, pageType, null, n + ".xml.html", null, null, crumbTitle, (adorn && hasNarrative(xdoc)) ? new Boolean(true) : null, ig, rd, wg);
TextFile.stringToFile(html, dst);
htmlchecker.registerExternal(dst);
}
use of org.hl7.fhir.utilities.CSFileInputStream in project kindling by HL7.
the class BuildWorkerContext method loadLoinc.
public void loadLoinc(String filename) throws Exception {
DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
DocumentBuilder builder = factory.newDocumentBuilder();
Document xdoc = builder.parse(new CSFileInputStream(filename));
Element code = XMLUtil.getFirstChild(xdoc.getDocumentElement());
while (code != null) {
Concept c = new Concept();
c.display = code.getAttribute("long");
c.shortN = code.getAttribute("short");
if (!code.getAttribute("long").equalsIgnoreCase(code.getAttribute("short")))
c.displays.add(code.getAttribute("short"));
loincCodes.put(code.getAttribute("id"), c);
code = XMLUtil.getNextSibling(code);
}
}
Aggregations