use of org.hl7.fhir.definitions.generators.specification.DictHTMLGenerator in project kindling by HL7.
the class PageProcessor method dictForDt.
// private boolean notime;
private String dictForDt(String dt) throws Exception {
File tmp = Utilities.createTempFile("tmp", ".tmp");
DictHTMLGenerator gen = new DictHTMLGenerator(new FileOutputStream(tmp), this, "");
TypeParser tp = new TypeParser(version.toCode());
TypeRef t = tp.parse(dt, false, null, workerContext, true).get(0);
ElementDefn e;
if (t.getName().equals("Resource"))
e = definitions.getBaseResources().get("DomainResource").getRoot();
else
e = definitions.getElementDefn(t.getName());
if (e == null) {
gen.close();
throw new Exception("unable to find definition for " + dt);
} else {
gen.generate(e);
gen.close();
}
String val = TextFile.fileToString(tmp.getAbsolutePath()) + "\r\n";
tmp.delete();
return val;
}
use of org.hl7.fhir.definitions.generators.specification.DictHTMLGenerator in project kindling by HL7.
the class PageProcessor method definitionsProfile.
private String definitionsProfile(StructureDefinition source, String prefix) throws Exception {
ByteArrayOutputStream b = new ByteArrayOutputStream();
DictHTMLGenerator d = new DictHTMLGenerator(b, this, prefix);
d.generate(source);
d.close();
return b.toString();
}
use of org.hl7.fhir.definitions.generators.specification.DictHTMLGenerator in project kindling by HL7.
the class Publisher method produceResource2.
private void produceResource2(ResourceDefn resource, boolean isAbstract, String extraTypeForDefn, boolean logicalOnly) throws Exception {
File tmp = Utilities.createTempFile("tmp", ".tmp");
String n = resource.getName().toLowerCase();
String xml = xmls.get(n);
String json = jsons.get(n);
String ttl = ttls.get(n);
TerminologyNotesGenerator tgen = new TerminologyNotesGenerator(new FileOutputStream(tmp), page);
tgen.generate("", resource.getRoot());
tgen.close();
String tx = TextFile.fileToString(tmp.getAbsolutePath());
DictHTMLGenerator dgen = new DictHTMLGenerator(new FileOutputStream(tmp), page, "");
dgen.generate(resource.getRoot());
dgen.close();
String dict = TextFile.fileToString(tmp.getAbsolutePath());
if (extraTypeForDefn != null) {
dgen = new DictHTMLGenerator(new FileOutputStream(tmp), page, "");
dgen.generate(page.getDefinitions().getElementDefn(extraTypeForDefn));
dgen.close();
dict = dict + "\r\n" + TextFile.fileToString(tmp.getAbsolutePath());
}
Map<String, String> values = new HashMap<String, String>();
MappingsGenerator mgen = new MappingsGenerator(page.getDefinitions());
mgen.generate(resource);
String mappings = mgen.getMappings();
String mappingsList = mgen.getMappingsList();
if (!logicalOnly) {
SvgGenerator svg = new SvgGenerator(page, "", resource.getLayout(), true, false, page.getVersion());
svg.generate(resource, page.getFolders().dstDir + n + ".svg", "1");
svg.generate(resource, Utilities.path(page.getFolders().srcDir, n, n + ".gen.svg"), "1");
String prefix = page.getBreadCrumbManager().getIndexPrefixForReference(resource.getName());
SectionTracker st = new SectionTracker(prefix, false);
st.start("");
page.getSectionTrackerCache().put(n, st);
String template = isAbstract ? "template-abstract" : "template";
String src = TextFile.fileToString(page.getFolders().templateDir + template + ".html");
src = insertSectionNumbers(page.processResourceIncludes(n, resource, xml, json, ttl, tx, dict, src, mappings, mappingsList, "resource", n + ".html", null, values, resource.getWg(), null), st, n + ".html", 0, null);
TextFile.stringToFile(src, page.getFolders().dstDir + n + ".html");
scanForFragments(n + ".html", new XhtmlParser().parseFragment(src));
page.getHTMLChecker().registerFile(n + ".html", "Base Page for " + resource.getName(), HTMLLinkChecker.XHTML_TYPE, true);
StructureDefinition profile = (StructureDefinition) ResourceUtilities.getById(page.getResourceBundle(), ResourceType.StructureDefinition, resource.getName());
String pages = page.getIni().getStringProperty("resource-pages", n);
if (!Utilities.noString(pages)) {
for (String p : pages.split(",")) {
producePage(p, n);
}
}
try {
if (!isAbstract)
processQuestionnaire(resource, profile, st, true, "", null);
} catch (Exception e) {
// e.printStackTrace();
page.log("Questionnaire Generation Failed: " + e.getMessage(), LogMessageType.Error);
}
if (!isAbstract || !resource.getExamples().isEmpty()) {
src = TextFile.fileToString(page.getFolders().templateDir + template + "-examples.html");
TextFile.stringToFile(insertSectionNumbers(page.processResourceIncludes(n, resource, xml, json, ttl, tx, dict, src, mappings, mappingsList, "res-Examples", n + "-examples.html", null, values, resource.getWg(), null), st, n + "-examples.html", 0, null), page.getFolders().dstDir + n + "-examples.html");
page.getHTMLChecker().registerFile(n + "-examples.html", "Examples for " + resource.getName(), HTMLLinkChecker.XHTML_TYPE, true);
for (Example e : resource.getExamples()) {
try {
processExample(e, resource, profile, null, e.getIg() == null ? null : page.getDefinitions().getIgs().get(e.getIg()));
} catch (Exception ex) {
throw new Exception("processing " + e.getTitle(), ex);
// throw new Exception(ex.getMessage()+" processing "+e.getFileTitle());
}
}
}
src = TextFile.fileToString(page.getFolders().templateDir + template + "-definitions.html");
TextFile.stringToFile(insertSectionNumbers(page.processResourceIncludes(n, resource, xml, json, ttl, tx, dict, src, mappings, mappingsList, "res-Detailed Descriptions", n + "-definitions.html", null, values, resource.getWg(), null), st, n + "-definitions.html", 0, null), page.getFolders().dstDir + n + "-definitions.html");
page.getHTMLChecker().registerFile(n + "-definitions.html", "Detailed Descriptions for " + resource.getName(), HTMLLinkChecker.XHTML_TYPE, true);
if (!isAbstract) {
src = TextFile.fileToString(page.getFolders().templateDir + "template-mappings.html");
TextFile.stringToFile(insertSectionNumbers(page.processResourceIncludes(n, resource, xml, json, ttl, tx, dict, src, mappings, mappingsList, "res-Mappings", n + "-mappings.html", null, values, resource.getWg(), null), st, n + "-mappings.html", 0, null), page.getFolders().dstDir + n + "-mappings.html");
page.getHTMLChecker().registerFile(n + "-mappings.html", "Formal Mappings for " + resource.getName(), HTMLLinkChecker.XHTML_TYPE, true);
src = TextFile.fileToString(page.getFolders().templateDir + "template-profiles.html");
TextFile.stringToFile(insertSectionNumbers(page.processResourceIncludes(n, resource, xml, json, ttl, tx, dict, src, mappings, mappingsList, "res-Profiles", n + "-profiles.html", null, values, resource.getWg(), null), st, n + "-profiles.html", 0, null), page.getFolders().dstDir + n + "-profiles.html");
page.getHTMLChecker().registerFile(n + "-profiles.html", "Profiles for " + resource.getName(), HTMLLinkChecker.XHTML_TYPE, true);
}
if (!resource.getOperations().isEmpty()) {
src = TextFile.fileToString(page.getFolders().templateDir + "template-operations.html");
TextFile.stringToFile(insertSectionNumbers(page.processResourceIncludes(n, resource, xml, json, ttl, tx, dict, src, mappings, mappingsList, "res-Operations", n + "-operations.html", null, values, resource.getWg(), null), st, n + "-operations.html", 0, null), page.getFolders().dstDir + n + "-operations.html");
page.getHTMLChecker().registerFile(n + "-operations.html", "Operations for " + resource.getName(), HTMLLinkChecker.XHTML_TYPE, true);
for (Operation t : resource.getOperations()) {
produceOperation(null, resource.getName().toLowerCase() + "-" + t.getName(), resource.getName() + "-" + t.getName(), resource, t, st);
}
}
produceMap(resource.getName(), st, resource);
for (Profile ap : resource.getConformancePackages()) produceConformancePackage(resource, ap, st);
src = TextFile.fileToString(page.getFolders().templateDir + "template-json-schema.html");
TextFile.stringToFile(insertSectionNumbers(page.processResourceIncludes(n, resource, xml, json, ttl, tx, dict, src, mappings, mappingsList, "res-schema", n + ".schema.json.html", null, values, resource.getWg(), null), st, n + ".schema.json.html", 0, null), page.getFolders().dstDir + n + ".schema.json.html");
page.getHTMLChecker().registerFile(n + ".schema.json.html", "Json Schema for " + resource.getName(), HTMLLinkChecker.XHTML_TYPE, true);
src = TextFile.fileToString(page.getFolders().templateDir + "template-dependencies.html");
TextFile.stringToFile(insertSectionNumbers(page.processResourceIncludes(n, resource, xml, json, ttl, tx, dict, src, mappings, mappingsList, "res-Dependencies", n + "-dependencies.html", null, values, resource.getWg(), null), st, n + "-dependencies.html", 0, null), page.getFolders().dstDir + n + "-dependencies.html");
page.getHTMLChecker().registerFile(n + "-dependencies.html", "Dependency graph for " + resource.getName(), HTMLLinkChecker.XHTML_TYPE, true);
for (ConceptMap cm : statusCodeConceptMaps) if (cm.getUserData("resource-definition") == resource)
produceConceptMap(cm, resource, st);
// xml to json
// todo - fix this up
// JsonGenerator jsongen = new JsonGenerator();
// jsongen.generate(new CSFile(page.getFolders().dstDir+n+".xml"), new
// File(page.getFolders().dstDir+n+".json"));
}
tmp.delete();
new ProfileUtilities(page.getWorkerContext(), page.getValidationErrors(), page).generateXlsx(new FileOutputStream(Utilities.path(page.getFolders().dstDir, n + ".xlsx")), resource.getProfile(), false, false);
// because we'll pick up a little more information as we process the
// resource
StructureDefinition p = generateProfile(resource, n, xml, json, ttl, !logicalOnly);
com.google.gson.JsonObject diff = new com.google.gson.JsonObject();
page.getDiffEngine().getDiffAsJson(diff, p);
Gson gson = new GsonBuilder().setPrettyPrinting().create();
json = gson.toJson(diff);
TextFile.stringToFile(json, Utilities.path(page.getFolders().dstDir, resource.getName().toLowerCase() + ".diff.json"));
DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
DocumentBuilder builder = dbf.newDocumentBuilder();
Document doc = builder.newDocument();
Element element = doc.createElement("difference");
doc.appendChild(element);
page.getDiffEngine().getDiffAsXml(doc, element, p);
prettyPrint(doc, Utilities.path(page.getFolders().dstDir, resource.getName().toLowerCase() + ".diff.xml"));
}
use of org.hl7.fhir.definitions.generators.specification.DictHTMLGenerator in project kindling by HL7.
the class PageProcessor method definitionsExtension.
private String definitionsExtension(StructureDefinition ed, String prefix) throws Exception {
ByteArrayOutputStream b = new ByteArrayOutputStream();
DictHTMLGenerator d = new DictHTMLGenerator(b, this, prefix);
d.generate(ed);
d.close();
return b.toString();
}
use of org.hl7.fhir.definitions.generators.specification.DictHTMLGenerator in project kindling by HL7.
the class Publisher method produceLogicalModel.
private void produceLogicalModel(LogicalModel lm, ImplementationGuideDefn ig) throws Exception {
String n = lm.getId();
Map<String, String> examples = new HashMap<String, String>();
File tmp = Utilities.createTempFile("tmp", ".tmp");
TerminologyNotesGenerator tgen = new TerminologyNotesGenerator(new FileOutputStream(tmp), page);
if (lm.hasResource())
tgen.generate("", lm.getResource().getRoot());
else
tgen.generate("", lm.getDefinition());
tgen.close();
String tx = TextFile.fileToString(tmp.getAbsolutePath());
DictHTMLGenerator dgen = new DictHTMLGenerator(new FileOutputStream(tmp), page, "");
if (lm.hasResource())
dgen.generate(lm.getResource().getRoot());
else
dgen.generate(lm.getDefinition());
dgen.close();
String dict = TextFile.fileToString(tmp.getAbsolutePath());
MappingsGenerator mgen = new MappingsGenerator(page.getDefinitions());
if (lm.hasResource())
mgen.generate(lm.getResource());
else
mgen.generate(lm.getDefinition());
String mappings = mgen.getMappings();
String mappingsList = mgen.getMappingsList();
SvgGenerator svg = new SvgGenerator(page, "", lm.getLayout(), true, false, page.getVersion());
String fn = ig.getPrefix() + n;
if (lm.hasResource())
svg.generate(lm.getResource(), page.getFolders().dstDir + fn + ".svg", "2");
else
svg.generate(lm.getDefinition(), page.getFolders().dstDir + fn + ".svg", "2");
String prefix = page.getBreadCrumbManager().getIndexPrefixForReference(lm.getId() + ".html");
SectionTracker st = new SectionTracker(prefix, true);
st.start("");
page.getSectionTrackerCache().put(fn, st);
if (lm.getDefinition() != null) {
new XmlParser().setOutputStyle(OutputStyle.PRETTY).compose(new FileOutputStream(Utilities.path(page.getFolders().dstDir, ig.getPrefix(), n + ".xml")), lm.getDefinition());
cloneToXhtml(ig.getPrefix() + n, "Logical Model " + lm.getDefinition().getName(), true, "logical-model", lm.getDefinition().getName(), null, lm.getWg());
new JsonParser().setOutputStyle(OutputStyle.PRETTY).compose(new FileOutputStream(Utilities.path(page.getFolders().dstDir, ig.getPrefix(), n + ".json")), lm.getDefinition());
jsonToXhtml(ig.getPrefix() + n, "Logical Model " + lm.getDefinition().getName(), new JsonParser().setOutputStyle(OutputStyle.PRETTY).composeString(lm.getDefinition()), "logical-model", lm.getDefinition().getName(), null, lm.getWg());
ttlToXhtml(ig.getPrefix() + n, "Logical Model " + lm.getDefinition().getName(), new RdfParser().setOutputStyle(OutputStyle.PRETTY).composeString(lm.getDefinition()), "logical-model", lm.getDefinition().getName(), null, lm.getWg());
}
if (lm.getWg() != null && lm.getResource().getWg() == null)
lm.getResource().setWg(lm.getWg());
String template = "template-logical";
String src = TextFile.fileToString(page.getFolders().templateDir + template + ".html");
Map<String, String> values = new HashMap<String, String>();
if (lm.hasResource())
src = insertSectionNumbers(page.processResourceIncludes(n, lm.getResource(), "", "", "", tx, dict, src, mappings, mappingsList, "resource", n + ".html", ig, values, lm.getWg(), examples), st, n + ".html", ig.getLevel(), null);
else
src = insertSectionNumbers(new LogicalModelProcessor(n, page, ig, lm.getDefinition().getId(), "logical-model", n + ".html", lm.getDefinition(), tx, dict, examples, ig.getLogicalModels(), page.getDefinitions(), page.getVersion()).process(src), st, n + ".html", ig.getLevel(), null);
TextFile.stringToFile(src, page.getFolders().dstDir + fn + ".html");
page.getHTMLChecker().registerFile(fn + ".html", "Base Page for " + n, HTMLLinkChecker.XHTML_TYPE, true);
src = TextFile.fileToString(page.getFolders().templateDir + "template-logical-definitions.html");
if (lm.hasResource())
TextFile.stringToFile(insertSectionNumbers(page.processResourceIncludes(n, lm.getResource(), "", "", "", tx, dict, src, mappings, mappingsList, "res-Detailed Descriptions", n + "-definitions.html", ig, values, lm.getWg(), examples), st, n + "-definitions.html", ig.getLevel(), null), page.getFolders().dstDir + fn + "-definitions.html");
else
TextFile.stringToFile(insertSectionNumbers(new LogicalModelProcessor(n, page, ig, lm.getDefinition().getId(), "logical-model", n + ".html", lm.getDefinition(), tx, dict, examples, ig.getLogicalModels(), page.getDefinitions(), page.getVersion()).process(src), st, n + "-definitions.html", ig.getLevel(), null), page.getFolders().dstDir + fn + "-definitions.html");
page.getHTMLChecker().registerFile(fn + "-definitions.html", "Detailed Descriptions for " + (lm.hasResource() ? lm.getResource().getName() : lm.getDefinition().getName()), HTMLLinkChecker.XHTML_TYPE, true);
src = TextFile.fileToString(page.getFolders().templateDir + "template-logical-examples.html");
if (lm.hasResource())
TextFile.stringToFile(insertSectionNumbers(page.processResourceIncludes(n, lm.getResource(), "", "", "", tx, dict, src, mappings, mappingsList, "resource", n + ".html", ig, values, lm.getWg(), examples), st, n + ".html", ig.getLevel(), null), page.getFolders().dstDir + fn + "-implementations.html");
else
TextFile.stringToFile(insertSectionNumbers(new LogicalModelProcessor(n, page, ig, lm.getDefinition().getId(), "logical-model", n + ".html", lm.getDefinition(), tx, dict, examples, ig.getLogicalModels(), page.getDefinitions(), page.getVersion()).process(src), st, n + "-implementations.html", ig.getLevel(), null), page.getFolders().dstDir + fn + "-implementations.html");
page.getHTMLChecker().registerFile(fn + "-implementations.html", "Implementations for " + (lm.hasResource() ? lm.getResource().getName() : lm.getDefinition().getName()), HTMLLinkChecker.XHTML_TYPE, true);
src = TextFile.fileToString(page.getFolders().templateDir + "template-logical-mappings.html");
if (lm.hasResource())
TextFile.stringToFile(insertSectionNumbers(page.processResourceIncludes(n, lm.getResource(), "", "", "", tx, dict, src, mappings, mappingsList, "res-Mappings", n + "-mappings.html", ig, values, lm.getWg(), examples), st, n + "-mappings.html", ig.getLevel(), null), page.getFolders().dstDir + fn + "-mappings.html");
else
TextFile.stringToFile(insertSectionNumbers(new LogicalModelProcessor(n, page, ig, lm.getDefinition().getId(), "logical-model", n + ".html", lm.getDefinition(), tx, dict, examples, ig.getLogicalModels(), page.getDefinitions(), page.getVersion()).process(src), st, n + "-mappings.html", ig.getLevel(), null), page.getFolders().dstDir + fn + "-mappings.html");
page.getHTMLChecker().registerFile(fn + "-mappings.html", "Formal Mappings for " + n, HTMLLinkChecker.XHTML_TYPE, true);
src = TextFile.fileToString(page.getFolders().templateDir + "template-logical-analysis.html");
if (lm.hasResource())
TextFile.stringToFile(insertSectionNumbers(page.processResourceIncludes(n, lm.getResource(), "", "", "", tx, dict, src, mappings, mappingsList, "res-Analysis", n + "-analysis.html", ig, values, lm.getWg(), examples), st, n + "-analysis.html", ig.getLevel(), null), page.getFolders().dstDir + fn + "-analysis.html");
else
TextFile.stringToFile(insertSectionNumbers(new LogicalModelProcessor(n, page, ig, lm.getDefinition().getId(), "logical-model", n + ".html", lm.getDefinition(), tx, dict, examples, ig.getLogicalModels(), page.getDefinitions(), page.getVersion()).process(src), st, n + "-analysis.html", ig.getLevel(), null), page.getFolders().dstDir + fn + "-analysis.html");
page.getHTMLChecker().registerFile(fn + "-analysis.html", "Analysis for " + n, HTMLLinkChecker.XHTML_TYPE, true);
tmp.delete();
}
Aggregations