use of org.hl7.fhir.definitions.model.ResourceDefn in project kindling by HL7.
the class Publisher method produceSpecMap.
private void produceSpecMap() throws IOException {
SpecMapManager spm = new SpecMapManager("hl7.fhir.core", page.getVersion().toCode(), page.getVersion().toCode(), page.getBuildId(), page.getGenDate(), CANONICAL_BASE);
for (StructureDefinition sd : page.getWorkerContext().allStructures()) {
if (sd.hasUserData("path")) {
spm.path(sd.getUrl(), sd.getUserString("path").replace("\\", "/"));
spm.target(sd.getUserString("path").replace("\\", "/"));
}
}
for (StructureDefinition sd : page.getWorkerContext().getExtensionDefinitions()) {
if (sd.hasUserData("path")) {
spm.path(sd.getUrl(), sd.getUserString("path").replace("\\", "/"));
spm.target(sd.getUserString("path").replace("\\", "/"));
}
}
for (String s : page.getCodeSystems().keys()) {
CodeSystem cs = page.getCodeSystems().get(s);
if (cs == null && !Utilities.existsInList(s, "http://unitsofmeasure.org", "http://loinc.org", "http://fdasis.nlm.nih.gov", "http://www.nlm.nih.gov/research/umls/rxnorm", "urn:oid:1.2.36.1.2001.1005.17") && !SIDUtilities.isknownCodeSystem(s))
System.out.println("No code system resource found for " + s);
}
for (CodeSystem cs : page.getCodeSystems().getList()) {
if (cs != null && cs.hasUserData("path")) {
spm.path(cs.getUrl(), cs.getUserString("path").replace("\\", "/"));
spm.target(cs.getUserString("path").replace("\\", "/"));
}
}
for (ValueSet vs : page.getValueSets().getList()) {
if (vs.hasUserData("path")) {
spm.path(vs.getUrl(), vs.getUserString("path").replace("\\", "/"));
spm.target(vs.getUserString("path").replace("\\", "/"));
}
}
for (ConceptMap cm : page.getConceptMaps().getList()) {
if (cm.hasUserData("path")) {
spm.path(cm.getUrl(), cm.getUserString("path").replace("\\", "/"));
spm.target(cm.getUserString("path").replace("\\", "/"));
}
}
for (String s : page.getDefinitions().getPageTitles().keySet()) {
spm.page(s, page.getDefinitions().getPageTitles().get(s));
}
for (String n : page.getIni().getPropertyNames("pages")) {
spm.target(n);
}
for (ResourceDefn rd : page.getDefinitions().getResources().values()) {
spm.target(rd.getName().toLowerCase() + ".html");
spm.target(rd.getName().toLowerCase() + "-definitions.html");
spm.target(rd.getName().toLowerCase() + "-mappings.html");
spm.target(rd.getName().toLowerCase() + "-examples.html");
spm.target(rd.getName().toLowerCase() + "-profiles.html");
if (!rd.getOperations().isEmpty())
spm.target(rd.getName().toLowerCase() + "-operations.html");
for (Example ex : rd.getExamples()) {
ImplementationGuideDefn ig = ex.getIg() == null ? null : page.getDefinitions().getIgs().get(ex.getIg());
String prefix = (ig == null || ig.isCore()) ? "" : ig.getCode() + "/";
spm.target(prefix + ex.getTitle() + ".html");
}
}
for (Profile p : page.getDefinitions().getPackList()) {
spm.target(p.getId() + ".html");
}
// for (String url : page.getDefinitions().getMapTypes().keySet()) {
// spm.map(url, page.getDefinitions().getMapTypes().get(url).getPreamble());
// }
scanForImages(spm, page.getFolders().dstDir, page.getFolders().dstDir);
scanForPages(spm, page.getFolders().dstDir, page.getFolders().dstDir);
for (String url : page.getDefinitions().getRedirectList().keySet()) {
// http://hl7.org/fhir/ = 20 chars
spm.target(url.substring(20));
}
spm.save(page.getFolders().dstDir + "spec.internals");
}
use of org.hl7.fhir.definitions.model.ResourceDefn in project kindling by HL7.
the class Publisher method generateProfile.
private StructureDefinition generateProfile(ResourceDefn root, String n, String xmlSpec, String jsonSpec, String ttlSpec, boolean gen) throws Exception, FileNotFoundException {
StructureDefinition rp = root.getProfile();
page.getProfiles().see(rp, page.packageInfo());
FileOutputStream s = new FileOutputStream(page.getFolders().dstDir + n + ".profile.xml");
new XmlParser().setOutputStyle(OutputStyle.PRETTY).compose(s, rp);
s.close();
s = new FileOutputStream(page.getFolders().dstDir + n + ".profile.canonical.xml");
new XmlParser().setOutputStyle(OutputStyle.CANONICAL).compose(s, rp);
s.close();
s = new FileOutputStream(page.getFolders().dstDir + n + ".profile.json");
new JsonParser().setOutputStyle(OutputStyle.PRETTY).compose(s, rp);
s.close();
s = new FileOutputStream(page.getFolders().dstDir + n + ".profile.canonical.json");
new JsonParser().setOutputStyle(OutputStyle.CANONICAL).compose(s, rp);
s.close();
Utilities.copyFile(new CSFile(page.getFolders().dstDir + n + ".profile.xml"), new CSFile(page.getFolders().dstDir + "examples" + File.separator + n + ".profile.xml"));
if (buildFlags.get("all")) {
addToResourceFeed(rp, page.getResourceBundle(), null);
}
if (gen) {
saveAsPureHtml(rp, new FileOutputStream(page.getFolders().dstDir + "html" + File.separator + n + ".html"));
cloneToXhtml(n + ".profile", "StructureDefinition for " + n, true, "profile-instance:resource:" + root.getName(), "Profile", root, root.getWg());
jsonToXhtml(n + ".profile", "StructureDefinition for " + n, resource2Json(rp), "profile-instance:resource:" + root.getName(), "Profile", root, root.getWg());
ttlToXhtml(n + ".profile", "StructureDefinition for " + n, resource2Ttl(rp), "profile-instance:resource:" + root.getName(), "Profile", root, root.getWg());
String shex = new ShExGenerator(page.getWorkerContext()).generate(HTMLLinkPolicy.NONE, rp);
TextFile.stringToFile(shex, page.getFolders().dstDir + n + ".shex");
shexToXhtml(n, "ShEx statement for " + n, shex, "profile-instance:type:" + root.getName(), "Type", root, root.getWg());
}
return rp;
}
use of org.hl7.fhir.definitions.model.ResourceDefn in project kindling by HL7.
the class Publisher method listLinks.
private void listLinks(Element xml, List<ExampleReference> refs) throws Exception {
if (xml.getLocalName().equals("feed")) {
Element n = XMLUtil.getFirstChild(xml);
while (n != null) {
if (n.getLocalName().equals("entry")) {
Element c = XMLUtil.getNamedChild(n, "content");
listLinks(XMLUtil.getFirstChild(c), refs);
}
n = XMLUtil.getNextSibling(n);
}
} else {
String n = xml.getLocalName();
if (!n.equals("Binary")) {
ResourceDefn r = page.getDefinitions().getResourceByName(n);
if (r == null)
throw new Exception("Unable to find resource definition for " + n);
List<Element> nodes = new ArrayList<Element>();
nodes.add(xml);
listLinks("/f:" + n, r.getRoot(), nodes, refs);
Element e = XMLUtil.getFirstChild(xml);
while (e != null) {
if (e.getNodeName().equals("contained")) {
listLinks(XMLUtil.getFirstChild(e), refs);
}
e = XMLUtil.getNextSibling(e);
}
}
}
}
use of org.hl7.fhir.definitions.model.ResourceDefn 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.definitions.model.ResourceDefn 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());
}
Aggregations