use of org.hl7.fhir.definitions.model.ImplementationGuideDefn in project kindling by HL7.
the class Publisher method determineLink.
private String determineLink(String path, String rn, String id) throws Exception {
ResourceDefn r = page.getDefinitions().getResourceByName(rn);
Example e = r.getExampleById(id);
if (e == null)
for (ImplementationGuideDefn ig : page.getDefinitions().getIgs().values()) {
e = ig.getExample(rn, id);
if (e != null)
break;
}
if (e == null) {
page.getValidationErrors().add(new ValidationMessage(Source.Publisher, IssueType.NOTFOUND, path, "The reference to " + rn + "/" + id + " could not be resolved", IssueSeverity.WARNING));
return "#null";
} else
return e.getTitle() + ".html";
}
use of org.hl7.fhir.definitions.model.ImplementationGuideDefn in project kindling by HL7.
the class PageProcessor method processPageIncludesForPrinting.
String processPageIncludesForPrinting(String file, String src, Resource resource, ImplementationGuideDefn ig) throws Exception {
boolean even = false;
List<String> tabs = new ArrayList<String>();
while (src.contains("<%") || src.contains("[%")) {
int i1 = src.indexOf("<%");
int i2 = src.indexOf("%>");
if (i1 == -1) {
i1 = src.indexOf("[%");
i2 = src.indexOf("%]");
}
String s1 = src.substring(0, i1);
String s2 = src.substring(i1 + 2, i2).trim();
String s3 = src.substring(i2 + 2);
String name = file.substring(0, file.indexOf("."));
String[] com = s2.split(" ");
if (com.length == 3 && com[0].equals("edt")) {
if (tabs != null)
tabs.add("tabs-" + com[1]);
src = s1 + orgDT(com[1], xmlForDt(com[1], com[2]), treeForDt(com[1]), umlForDt(com[1], com[2]), umlForDt(com[1], com[2] + "b"), profileRef(com[1]), tsForDt(com[1]), jsonForDt(com[1], com[2]), ttlForDt(com[1], com[2]), diffForDt(com[1], com[2])) + s3;
} else if (com.length == 2 && com[0].equals("dt")) {
if (tabs != null)
tabs.add("tabs-" + com[1]);
src = s1 + xmlForDt(com[1], null) + tsForDt(com[1]) + s3;
} else if (com.length == 2 && com[0].equals("adt")) {
if (tabs != null)
tabs.add("tabs-" + com[1]);
src = s1 + xmlForDt(com[1], null) + tsForDt(com[1]) + s3;
} else if (com.length == 2 && com[0].equals("dt.constraints"))
src = s1 + genConstraints(com[1], "") + s3;
else if (com.length == 2 && com[0].equals("dt.restrictions"))
src = s1 + genRestrictions(com[1]) + s3;
else if (com.length == 2 && com[0].equals("dictionary"))
src = s1 + dictForDt(com[1]) + s3;
else if (Utilities.existsInList(com[0], "pageheader", "dtheader", "atheader", "mdtheader", "edheader", "mmheader", "drheader", "elheader", "belheader", "extheader", "resourcesheader", "formatsheader", "narrheader", "refheader", "extrasheader", "profilesheader", "txheader", "txheader0", "fmtheader", "igheader", "cmpheader", "atomheader", "dictheader", "ctheader", "adheader", "pdheader", "tdheader", "cdheader", "diheader", "statheader", "ordistheader", "ucheader", "rrheader"))
src = s1 + s3;
else if (com[0].equals("resheader"))
src = s1 + resHeader(name, "Document", com.length > 1 ? com[1] : null) + s3;
else if (com[0].equals("aresheader"))
src = s1 + abstractResHeader(name, "Document", com.length > 1 ? com[1] : null) + s3;
else if (com[0].equals("codelist"))
src = s1 + codelist((CodeSystem) resource, com.length > 1 ? com[1] : null, false, true, file) + s3;
else if (com[0].equals("codelist-nh"))
src = s1 + codelist((CodeSystem) resource, com.length > 1 ? com[1] : null, false, false, file) + s3;
else if (com[0].equals("linkcodelist"))
src = s1 + codelist((CodeSystem) resource, com.length > 1 ? com[1] : null, true, false, file) + s3;
else if (com[0].equals("sct-vs-list"))
src = s1 + getSnomedCTVsList() + s3;
else if (com[0].equals("sct-concept-list"))
src = s1 + getSnomedCTConceptList() + s3;
else if (com[0].equals("codetoc"))
src = s1 + codetoc(com.length > 1 ? com[1] : null) + s3;
else if (com[0].equals("res-category")) {
src = s1 + resCategory(s2.substring(com[0].length() + 1)) + s3;
even = false;
} else if (com[0].equals("res-item")) {
even = !even;
src = s1 + resItem(com[1], even) + s3;
} else if (com[0].equals("resdesc")) {
src = s1 + resDesc(com[1]) + s3;
} else if (com[0].equals("rescat")) {
src = s1 + resCat(com.length == 1 ? null : s2.substring(7)) + s3;
} else if (com[0].equals("w5"))
src = s1 + genW5("true".equals(com[1])) + s3;
else if (com[0].equals("vs-warning"))
src = s1 + vsWarning((ValueSet) resource) + s3;
else if (com[0].equals("res-status-special"))
src = s1 + vsSpecialStatus((DomainResource) resource) + s3;
else if (com[0].equals("file")) {
if (new File(folders.templateDir + com[1] + ".html").exists()) {
src = s1 + TextFile.fileToString(folders.templateDir + com[1] + ".html") + s3;
} else {
src = s1 + TextFile.fileToString(folders.srcDir + com[1] + ".html") + s3;
}
} else if (com[0].equals("conceptmaplistvs")) {
throw new Error("Fix this");
// BindingSpecification bs = definitions.getBindingByName(Utilities.fileTitle(file));
// String ref;
// if (bs == null) {
// ref = "http://hl7.org/fhir/ValueSet/"+Utilities.fileTitle(file);
// } else {
// ref = bs.getReference();
// if (ref.startsWith("valueset-"))
// ref = ref.substring(9);
// ref = "http://hl7.org/fhir/ValueSet/"+ref;
// }
// src = s1 + conceptmaplist(ref, com[1]) + s3;
} else if (com[0].equals("dtmappings"))
src = s1 + genDataTypeMappings(com[1]) + s3;
else if (com[0].equals("dtusage"))
src = s1 + genDataTypeUsage(com[1]) + s3;
else if (com[0].equals("othertabs"))
src = s1 + genOtherTabs(com[1], tabs) + s3;
else if (com[0].equals("toc"))
src = s1 + generateToc() + s3;
else if (com.length != 1)
throw new Exception("Instruction <%" + s2 + "%> not understood parsing page " + file);
else if (com[0].equals("newheader"))
src = s1 + TextFile.fileToString(folders.srcDir + "newheader.html") + s3;
else if (com[0].equals("newheader1"))
src = s1 + TextFile.fileToString(folders.srcDir + "newheader1.html") + s3;
else if (com[0].equals("footer"))
src = s1 + TextFile.fileToString(folders.srcDir + "footer.html") + s3;
else if (com[0].equals("newfooter"))
src = s1 + TextFile.fileToString(folders.srcDir + "newfooter.html") + s3;
else if (com[0].equals("footer1"))
src = s1 + TextFile.fileToString(folders.srcDir + "footer1.html") + s3;
else if (com[0].equals("footer2"))
src = s1 + TextFile.fileToString(folders.srcDir + "footer2.html") + s3;
else if (com[0].equals("footer3"))
src = s1 + TextFile.fileToString(folders.srcDir + "footer3.html") + s3;
else if (com[0].equals("title"))
src = s1 + Utilities.escapeXml(name.toUpperCase().substring(0, 1) + name.substring(1)) + s3;
else if (com[0].equals("xtitle"))
src = s1 + Utilities.escapeXml(name.toUpperCase().substring(0, 1) + name.substring(1)) + s3;
else if (com[0].equals("name"))
src = s1 + name + s3;
else if (com[0].equals("version"))
src = s1 + ini.getStringProperty("FHIR", "version") + s3;
else if (com[0].equals("gendate"))
src = s1 + Config.DATE_FORMAT().format(new Date()) + s3;
else if (com[0].equals("maindiv"))
src = s1 + s3;
else if (com[0].equals("/maindiv"))
src = s1 + s3;
else if (com[0].equals("enteredInErrorTable"))
src = s1 + enteredInErrorTable() + s3;
else if (com[0].equals("events"))
src = s1 + getEventsTable(file) + s3;
else if (com[0].equals("resourcecodes"))
src = s1 + genResCodes() + s3;
else if (com[0].equals("datatypecodes"))
src = s1 + genDTCodes() + s3;
else // src = s1 + genBindingTable(false) + s3;
if (com[0].equals("codeslist"))
src = s1 + genCodeSystemsTable() + s3;
else if (com[0].equals("valuesetslist"))
src = s1 + genValueSetsTable(ig) + s3;
else if (com[0].equals("igvaluesetslist"))
src = s1 + genIGValueSetsTable() + s3;
else if (com[0].equals("namespacelist"))
src = s1 + genNSList() + s3;
else if (com[0].equals("resimplall"))
src = s1 + genResImplList() + s3;
else if (com[0].equals("txurl"))
src = s1 + "http://hl7.org/fhir/" + Utilities.fileTitle(file) + s3;
else if (com[0].equals("vstxurl"))
src = s1 + "http://hl7.org/fhir/ValueSet/" + Utilities.fileTitle(file) + s3;
else if (com[0].equals("csurl")) {
if (resource instanceof CodeSystem)
src = s1 + ((CodeSystem) resource).getUrl() + s3;
else
src = s1 + ((ValueSet) resource).getUrl() + s3;
} else if (com[0].equals("vsurl")) {
if (resource instanceof CodeSystem)
src = s1 + ((CodeSystem) resource).getUrl() + s3;
else
src = s1 + ((ValueSet) resource).getUrl() + s3;
} else if (com[0].equals("txdef"))
src = s1 + generateCodeDefinition(Utilities.fileTitle(file)) + s3;
else if (com[0].equals("vsxref"))
src = s1 + xreferencesForFhir(name) + s3;
else if (com[0].equals("vsdef"))
if (resource instanceof CodeSystem)
src = s1 + Utilities.escapeXml(((CodeSystem) resource).getDescription()) + s3;
else
src = s1 + Utilities.escapeXml(((ValueSet) resource).getDescription()) + s3;
else if (com[0].equals("txusage"))
src = s1 + generateValueSetUsage((ValueSet) resource, genlevel(0), true) + s3;
else if (com[0].equals("vsusage"))
src = s1 + generateValueSetUsage((ValueSet) resource, genlevel(0), true) + s3;
else if (com[0].equals("csusage"))
src = s1 + generateCSUsage((CodeSystem) resource, genlevel(0)) + s3;
else if (com[0].equals("vssummary"))
src = s1 + "todo" + s3;
else if (com[0].equals("piperesources"))
src = s1 + pipeResources() + s3;
else if (com[0].equals("pub-type"))
src = s1 + publicationType + s3;
else // src = s1 + expandValueSet(Utilities.fileTitle(file), resource == null ? null : (ValueSet) resource) + s3;
if (com[0].equals("vsexpansionig"))
src = s1 + expandValueSetIG((ValueSet) resource, true) + s3;
else if (com[0].equals("pub-notice"))
src = s1 + publicationNotice + s3;
else if (com[0].startsWith("!"))
src = s1 + s3;
else if (macros.containsKey(com[0])) {
src = s1 + macros.get(com[0]) + s3;
} else
throw new Exception("Instruction <%" + s2 + "%> not understood parsing page " + file);
}
return src;
}
use of org.hl7.fhir.definitions.model.ImplementationGuideDefn in project kindling by HL7.
the class Publisher method generateIGValueSetsPart2.
private void generateIGValueSetsPart2(ImplementationGuideDefn ig) throws Exception {
for (Resource ae : page.getIgResources().values()) {
if (ae instanceof ValueSet) {
ValueSet vs = (ValueSet) ae;
String name = Utilities.fileTitle((String) ae.getUserData("path"));
String title = vs.getName();
if (vs.getText() == null || vs.getText().getDiv() == null || vs.getText().getDiv().allChildrenAreText() && (Utilities.noString(vs.getText().getDiv().allText()) || !vs.getText().getDiv().allText().matches(".*\\w.*"))) {
RenderingContext lrc = page.getRc().copy().setLocalPrefix("").setTooCostlyNoteEmpty(PageProcessor.TOO_MANY_CODES_TEXT_EMPTY).setTooCostlyNoteNotEmpty(PageProcessor.TOO_MANY_CODES_TEXT_NOT_EMPTY);
RendererFactory.factory(vs, lrc).render(vs);
}
page.getVsValidator().validate(page.getValidationErrors(), name, vs, true, false);
// todo - what should the Oids be
addToResourceFeed(vs, valueSetsFeed, null);
String sf = page.processPageIncludes(title + ".html", TextFile.fileToString(page.getFolders().templateDir + "template-vs-ig.html"), "valueSet", null, name + ".html", vs, null, "Value Set", null, null, wg("vocab"));
sf = addSectionNumbers(title + ".html", "template-valueset", sf, "??", 0, null, ig);
TextFile.stringToFile(sf, page.getFolders().dstDir + name + ".html");
String src = page.processPageIncludesForBook(title + ".html", TextFile.fileToString(page.getFolders().templateDir + "template-vs-ig-book.html"), "valueSet", vs, null, null);
cachePage(name + ".html", src, "Value Set " + title, false);
page.setId(null);
IParser json = new JsonParser().setOutputStyle(OutputStyle.PRETTY);
FileOutputStream s = new FileOutputStream(page.getFolders().dstDir + name + ".json");
json.compose(s, vs);
s.close();
json = new JsonParser().setOutputStyle(OutputStyle.CANONICAL);
s = new FileOutputStream(page.getFolders().dstDir + name + ".canonical.json");
json.compose(s, vs);
s.close();
IParser xml = new XmlParser().setOutputStyle(OutputStyle.PRETTY);
s = new FileOutputStream(page.getFolders().dstDir + name + ".xml");
xml.compose(s, vs);
s.close();
xml = new XmlParser().setOutputStyle(OutputStyle.CANONICAL);
s = new FileOutputStream(page.getFolders().dstDir + name + ".canonical.xml");
xml.compose(s, vs);
s.close();
cloneToXhtml(name, "Definition for Value Set" + vs.getName(), false, "valueset-instance", "Value Set", null, wg("vocab"));
jsonToXhtml(name, "Definition for Value Set" + vs.getName(), resource2Json(vs), "valueset-instance", "Value Set", null, wg("vocab"));
ttlToXhtml(name, "Definition for Value Set" + vs.getName(), resource2Ttl(vs), "valueset-instance", "Value Set", null, wg("vocab"));
}
}
}
use of org.hl7.fhir.definitions.model.ImplementationGuideDefn in project kindling by HL7.
the class Publisher method produceOperation.
private void produceOperation(ImplementationGuideDefn ig, String name, String id, ResourceDefn resource, Operation op, SectionTracker st) throws Exception {
OperationDefinition opd = new ProfileGenerator(page.getDefinitions(), page.getWorkerContext(), page, page.getGenDate(), page.getVersion(), dataElements, fpUsages, page.getFolders().rootDir, page.getUml(), page.getRc()).generate(name, id, resource.getName(), op, resource);
String dir = ig == null ? "" : ig.getCode() + File.separator;
FileOutputStream s = new FileOutputStream(page.getFolders().dstDir + dir + "operation-" + name + ".xml");
new XmlParser().setOutputStyle(OutputStyle.PRETTY).compose(s, opd);
s.close();
s = new FileOutputStream(page.getFolders().dstDir + dir + "operation-" + name + ".canonical.xml");
new XmlParser().setOutputStyle(OutputStyle.CANONICAL).compose(s, opd);
s.close();
cloneToXhtml(dir + "operation-" + name + "", "Operation Definition", true, "resource-instance:OperationDefinition", "Operation definition", resource, resource.getWg());
s = new FileOutputStream(page.getFolders().dstDir + dir + "operation-" + name + ".json");
new JsonParser().setOutputStyle(OutputStyle.PRETTY).compose(s, opd);
s.close();
s = new FileOutputStream(page.getFolders().dstDir + dir + "operation-" + name + ".canonical.json");
new JsonParser().setOutputStyle(OutputStyle.CANONICAL).compose(s, opd);
s.close();
jsonToXhtml(dir + "operation-" + name, "Operation Definition", resource2Json(opd), "resource-instance:OperationDefinition", "Operation definition", resource, resource.getWg());
s = new FileOutputStream(page.getFolders().dstDir + dir + "operation-" + name + ".ttl");
new RdfParser().setOutputStyle(OutputStyle.PRETTY).compose(s, opd);
s.close();
ttlToXhtml(dir + "operation-" + name, "Operation Definition", resource2Ttl(opd), "resource-instance:OperationDefinition", "Operation definition", resource, resource.getWg());
Utilities.copyFile(new CSFile(page.getFolders().dstDir + dir + "operation-" + name + ".xml"), new CSFile(page.getFolders().dstDir + "examples" + File.separator + "operation-" + name + ".xml"));
if (buildFlags.get("all")) {
addToResourceFeed(opd, page.getResourceBundle(), name);
page.getWorkerContext().cacheResource(opd);
}
// now we create a page for the operation
String fnp = resource.getName().toLowerCase() + "-operation-" + op.getName().toLowerCase() + ".html";
String src = TextFile.fileToString(page.getFolders().templateDir + "template-operation.html");
src = page.processPageIncludes(fnp, src, "res-Operations", null, "operation-" + name + ".html", op.getResource(), null, "Operation Definition", op, ig, resource, resource.getWg());
TextFile.stringToFile(insertSectionNumbers(src, st, fnp, 0, null), page.getFolders().dstDir + fnp);
page.getHTMLChecker().registerFile(fnp, "Operation " + op.getName() + " for " + resource.getName(), HTMLLinkChecker.XHTML_TYPE, true);
// now, we create an html page from the narrative
String html = TextFile.fileToString(page.getFolders().templateDir + "template-example.html").replace("<%example%>", new XhtmlComposer(XhtmlComposer.HTML).compose(opd.getText().getDiv()));
html = page.processPageIncludes(dir + "operation-" + name + ".html", html, "resource-instance:OperationDefinition", null, null, null, "Operation Definition", ig, resource, resource.getWg());
TextFile.stringToFile(html, page.getFolders().dstDir + dir + "operation-" + name + ".html");
page.getHTMLChecker().registerFile(dir + "operation-" + name + ".html", "Operation " + op.getName(), HTMLLinkChecker.XHTML_TYPE, true);
// head =
// "<html xmlns=\"http://www.w3.org/1999/xhtml\" xml:lang=\"en\">\r\n<head>\r\n <title>"+Utilities.escapeXml(e.getDescription())+"</title>\r\n <link rel=\"Stylesheet\" href=\"fhir.css\" type=\"text/css\" media=\"screen\"/>\r\n"+
// "</head>\r\n<body>\r\n<p> </p>\r\n<p>"+Utilities.escapeXml(e.getDescription())+"</p>\r\n"+
// "<p><a href=\""+n+".xml.html\">XML</a> <a href=\""+n+".json.html\">JSON</a></p>\r\n";
// tail = "\r\n</body>\r\n</html>\r\n";
// TextFile.stringToFile(head+narrative+tail, page.getFolders().dstDir + n +
// ".html");
}
use of org.hl7.fhir.definitions.model.ImplementationGuideDefn in project kindling by HL7.
the class Publisher method producePackSearchParameter.
private void producePackSearchParameter(ResourceDefn res, Profile pack, SearchParameter sp, SectionTracker st, ImplementationGuideDefn ig) throws Exception {
String title = sp.getId();
sp.setUserData("pack", pack.getId());
String prefix = (ig == null || ig.isCore()) ? "" : ig.getCode() + File.separator;
int level = (ig == null || ig.isCore()) ? 0 : 1;
XmlParser comp = new XmlParser();
FileOutputStream s = new FileOutputStream(page.getFolders().dstDir + prefix + title + ".xml");
comp.setOutputStyle(OutputStyle.PRETTY).compose(s, sp);
s.close();
s = new FileOutputStream(page.getFolders().dstDir + prefix + title + ".canonical.xml");
comp.setOutputStyle(OutputStyle.CANONICAL).compose(s, sp);
s.close();
JsonParser jcomp = new JsonParser();
s = new FileOutputStream(page.getFolders().dstDir + prefix + title + ".json");
jcomp.setOutputStyle(OutputStyle.PRETTY).compose(s, sp);
s.close();
s = new FileOutputStream(page.getFolders().dstDir + prefix + title + ".canonical.json");
jcomp.setOutputStyle(OutputStyle.CANONICAL).compose(s, sp);
s.close();
String src = TextFile.fileToString(page.getFolders().templateDir + "template-search-parameter.html");
src = page.processPageIncludes(sp.getId() + ".html", src, "search-parameter:" + (res == null ? "na" : res.getName()) + "/" + pack.getId() + "/" + sp.getId(), null, sp, null, "Search Parameter", ig, res, res == null ? wg("fhir") : res.getWg());
if (st != null)
src = insertSectionNumbers(src, st, title + ".html", level, null);
page.getHTMLChecker().registerFile(prefix + title + ".html", "SearchParameter " + sp.getName(), HTMLLinkChecker.XHTML_TYPE, true);
TextFile.stringToFile(src, page.getFolders().dstDir + prefix + title + ".html");
cloneToXhtml(prefix + title, "Search Parameter " + sp.getName(), false, "searchparam-instance", "Search Parameter", res, res == null ? wg("fhir") : res.getWg());
String json = resource2Json(sp);
json = "<div class=\"example\">\r\n<p>" + Utilities.escapeXml("SearchParameter " + sp.getName()) + "</p>\r\n<pre class=\"json\">\r\n" + Utilities.escapeXml(json) + "\r\n</pre>\r\n</div>\r\n";
String html = TextFile.fileToString(page.getFolders().templateDir + "template-example-json.html").replace("<%example%>", json);
html = page.processPageIncludes(title + ".json.html", html, "search-parameter:" + (res == null ? "wg" : res.getName()) + "/" + pack.getId() + "/" + sp.getId(), null, sp, null, "Search Parameter", ig, res, res == null ? wg("fhir") : res.getWg());
TextFile.stringToFile(html, page.getFolders().dstDir + prefix + title + ".json.html");
page.getHTMLChecker().registerExternal(prefix + title + ".json.html");
}
Aggregations