use of org.hl7.fhir.r5.model.Questionnaire in project kindling by HL7.
the class BreadCrumbManager method makelist.
public String makelist(String name, String type, String prefix, String title) throws Exception {
StringBuilder b = new StringBuilder();
if (name.equals("index")) {
b.append(" <li><b>Home</b></li>\r\n");
} else {
// b.append(" <li><a href=\""+prefix+"index.html\">"+translations.getMessage("HOME", "Home")+"</a></li>\r\n");
if (!name.endsWith(".html"))
name = name + ".html";
String nt = Utilities.changeFileExt(name, "");
if (map.containsKey(nt) && Utilities.noString(type)) {
String[] path = map.get(nt).split("\\.");
Page focus = home;
for (int i = 0; i < path.length - 1; i++) {
focus = getChild(focus, path[i]);
if (focus.getFilename() != null)
b.append(" <li><a href=\"" + prefix + focus.getFilename() + "\">" + imgLink(prefix, focus) + Utilities.escapeXml(focus.getTitle()) + "</a></li>\r\n");
}
focus = getChild(focus, path[path.length - 1]);
b.append(" <li><b>" + imgLink(prefix, focus) + Utilities.escapeXml(focus.resource) + "</b></li>");
} else if (map.containsKey(name)) {
String[] path = map.get(name).split("\\.");
Page focus = home;
for (int i = 0; i < path.length - 1; i++) {
focus = getChild(focus, path[i]);
if (focus.getFilename() != null)
b.append(" <li><a href=\"" + prefix + focus.getFilename() + "\">" + imgLink(prefix, focus) + Utilities.escapeXml(focus.getTitle()) + "</a></li>\r\n");
}
focus = getChild(focus, path[path.length - 1]);
b.append(" <li><b>" + imgLink(prefix, focus) + Utilities.escapeXml(focus.getTitle()) + "</b></li>");
} else if (map.containsKey(type) && !type.equals("resource")) {
String[] path = map.get(type).split("\\.");
Page focus = home;
for (int i = 0; i < path.length - 1; i++) {
focus = getChild(focus, path[i]);
b.append(" <li><a href=\"" + prefix + focus.getFilename() + "\">" + imgLink(prefix, focus) + Utilities.escapeXml(focus.getTitle()) + "</a></li>");
}
b.append(" <li><b>" + imgLink(prefix, focus) + Utilities.escapeXml(title) + "</b></li>");
} else if (type.equals("example") && name.contains("-") && map.containsKey(name.substring(0, name.indexOf("-")))) {
String[] path = map.get(name.substring(0, name.indexOf("-"))).split("\\.");
Page focus = home;
for (int i = 0; i < path.length; i++) {
focus = getChild(focus, path[i]);
if (focus.type == PageType.resource)
b.append(" <li><a href=\"" + prefix + focus.getReference().toLowerCase() + ".html\">" + imgLink(prefix, focus) + Utilities.escapeXml(focus.getReference()) + "</a></li>");
else
b.append(" <li><a href=\"" + prefix + focus.getFilename() + "\">" + imgLink(prefix, focus) + Utilities.escapeXml(focus.getTitle()) + "</a></li>");
}
b.append(" <li><b>Example</b></li>");
} else {
String s = map.get(type.substring(type.indexOf(":") + 1).toLowerCase());
if (type.startsWith("resource-instance") && type.contains(":")) {
if (s == null)
throw new Exception("Unable to find map for " + type);
String[] path = s.split("\\.");
Page focus = home;
for (int i = 0; i < path.length; i++) {
focus = getChild(focus, path[i]);
if (focus.type == PageType.resource)
b.append(" <li><a href=\"" + prefix + focus.getReference().toLowerCase() + ".html\">" + imgLink(prefix, focus) + Utilities.escapeXml(focus.getReference()) + "</a></li>");
else
b.append(" <li><a href=\"" + prefix + focus.getFilename() + "\">" + imgLink(prefix, focus) + Utilities.escapeXml(Utilities.escapeXml(focus.getTitle())) + "</a></li>");
}
if (type.startsWith("resource-instance"))
b.append(" <li><b>Example Instance</b></li>");
else
b.append(" <li><b>Profile Instance</b></li>");
} else if (type.startsWith("resource-questionnaire") && type.contains(":")) {
if (s == null)
throw new Exception("Unable to find map for " + type);
String[] path = s.split("\\.");
Page focus = home;
for (int i = 0; i < path.length; i++) {
focus = getChild(focus, path[i]);
if (focus.type == PageType.resource)
b.append(" <li><a href=\"" + prefix + focus.getReference().toLowerCase() + ".html\">" + imgLink(prefix, focus) + Utilities.escapeXml(focus.getReference()) + "</a></li>");
else
b.append(" <li><a href=\"" + prefix + focus.getFilename() + "\">" + imgLink(prefix, focus) + Utilities.escapeXml(focus.getTitle()) + "</a></li>");
}
b.append(" <li><b>Generated Questionnaire</b></li>");
} else if (type.equals("valueset-instance") && name.contains(".")) {
String[] path = map.get("terminologies-valuesets.html").split("\\.");
Page focus = home;
for (int i = 0; i < path.length; i++) {
focus = getChild(focus, path[i]);
if (focus.type == PageType.resource)
b.append(" <li><a href=\"" + prefix + focus.getReference().toLowerCase() + ".html\">" + imgLink(prefix, focus) + Utilities.escapeXml(focus.getReference()) + "</a></li>");
else
b.append(" <li><a href=\"" + prefix + focus.getFilename() + "\">" + imgLink(prefix, focus) + Utilities.escapeXml(focus.getTitle()) + "</a></li>");
}
b.append(" <li><a href=\"" + prefix + name.substring(0, name.indexOf(".")) + ".html\">" + Utilities.escapeXml(name.substring(0, name.indexOf("."))) + "</a></li>");
b.append(" <li><b>Instance</b></li>");
} else if (type.equals("conceptmap-instance") && name.contains(".")) {
String[] path = map.get("terminologies-conceptmaps.html").split("\\.");
Page focus = home;
for (int i = 0; i < path.length; i++) {
focus = getChild(focus, path[i]);
if (focus.type == PageType.resource)
b.append(" <li><a href=\"" + prefix + focus.getReference().toLowerCase() + ".html\">" + imgLink(prefix, focus) + Utilities.escapeXml(focus.getReference()) + "</a></li>");
else
b.append(" <li><a href=\"" + prefix + focus.getFilename() + "\">" + imgLink(prefix, focus) + Utilities.escapeXml(focus.getTitle()) + "</a></li>");
}
b.append(" <li><b>Example</b></li>");
} else if (type.startsWith("res") && map.containsKey(Utilities.fileTitle(name))) {
String[] path = map.get(Utilities.fileTitle(name)).split("\\.");
Page focus = home;
for (int i = 0; i < path.length - 1; i++) {
focus = getChild(focus, path[i]);
b.append(" <li><a href=\"" + prefix + focus.getFilename() + "\">" + imgLink(prefix, focus) + Utilities.escapeXml(focus.getTitle()) + "</a></li>");
}
focus = getChild(focus, path[path.length - 1]);
if (type.equals("resource")) {
b.append(" <li><b>" + Utilities.escapeXml(focus.getReference()) + "</b></li>");
} else {
b.append(" <li><a href=\"" + focus.getReference().toLowerCase() + ".html\">" + imgLink(prefix, focus) + Utilities.escapeXml(focus.getReference()) + "</a></li>");
b.append(" <li><b>" + Utilities.escapeXml(type.substring(4)) + "</b></li>");
}
} else if (type.startsWith("profile:")) {
String p = s;
if (p == null) {
// the bit after profile is resource.pack.profile
String[] path = type.substring(type.indexOf(":") + 1).split("\\/");
if (map.containsKey(path[0].toLowerCase())) {
String[] path2 = map.get(path[0].toLowerCase()).split("\\.");
Page focus = home;
for (int i = 0; i < path2.length - 1; i++) {
focus = getChild(focus, path2[i]);
b.append(" <li><a href=\"" + prefix + focus.getFilename() + "\">" + imgLink(prefix, focus) + Utilities.escapeXml(focus.getTitle()) + "</a></li>");
}
focus = getChild(focus, path2[path2.length - 1]);
b.append(" <li><a href=\"" + focus.getReference().toLowerCase() + ".html\">" + imgLink(prefix, focus) + Utilities.escapeXml(focus.getReference()) + "</a></li>");
} else {
if (!Utilities.noString(path[0]))
b.append(" <li><a href=\"" + prefix + path[0].toLowerCase() + ".html\">" + Utilities.escapeXml(path[0]) + "</a></li>");
if (Utilities.noString(path[0]) || definitions.hasResource(path[0]))
b.append(" <li><a href=\"" + prefix + (Utilities.noString(path[0]) ? "profilelist" : path[0].toLowerCase() + "-profiles") + ".html\">Profiles</a></li>");
}
Profile pack = definitions.hasResource(path[0]) ? definitions.getResourceByName(path[0]).getConformancePackage(path[1]) : null;
if (pack == null || !("profile".equals(pack.metadata("navigation")) && pack.getProfiles().size() == 1))
b.append(" <li><a href=\"" + prefix + path[1].toLowerCase() + ".html\">Profile</a></li>");
// b.append(" <li><a href=\""+prefix+path[0].toLowerCase()+".html\">"+path[0]+"</a></li>");
} else {
String[] path = p.split("\\.");
Page focus = home;
for (int i = 0; i < path.length; i++) {
focus = getChild(focus, path[i]);
if (focus.type == PageType.resource)
b.append(" <li><a href=\"" + prefix + focus.getReference().toLowerCase() + ".html\">" + imgLink(prefix, focus) + Utilities.escapeXml(focus.getReference()) + "</a></li>");
else
b.append(" <li><a href=\"" + prefix + focus.getFilename() + "\">" + imgLink(prefix, focus) + Utilities.escapeXml(focus.getTitle()) + "</a></li>");
}
}
b.append(" <li><b>" + Utilities.escapeXml(title) + "</b></li>");
} else if (type.startsWith("profile-instance:type")) {
String[] path = map.get("datatypes.html").split("\\.");
Page focus = home;
for (int i = 0; i < path.length; i++) {
focus = getChild(focus, path[i]);
if (focus.type == PageType.resource)
b.append(" <li><a href=\"" + prefix + focus.getReference().toLowerCase() + ".html\">" + imgLink(prefix, focus) + Utilities.escapeXml(focus.getReference()) + "</a></li>");
else
b.append(" <li><a href=\"" + prefix + focus.getFilename() + "\">" + imgLink(prefix, focus) + Utilities.escapeXml(focus.getTitle()) + "</a></li>");
}
b.append(" <li><b>Profile</b></li>");
} else if (type.startsWith("profile-instance:resource")) {
// TODO: profile-questionnaire:
String t = type.substring(type.lastIndexOf(":") + 1);
if (t == null)
throw new Exception("Unable to read type " + type);
String obj = map.get(t.toLowerCase());
if (obj == null)
throw new Exception("Unable to find type " + t);
if (type.startsWith("profile-instance:resource")) {
String[] path = obj.split("\\.");
Page focus = home;
for (int i = 0; i < path.length; i++) {
focus = getChild(focus, path[i]);
if (focus.type == PageType.resource)
b.append(" <li><a href=\"" + prefix + focus.getReference().toLowerCase() + ".html\">" + imgLink(prefix, focus) + Utilities.escapeXml(focus.getReference()) + "</a></li>");
else
b.append(" <li><a href=\"" + prefix + focus.getFilename() + "\">" + imgLink(prefix, focus) + Utilities.escapeXml(focus.getTitle()) + "</a></li>");
}
b.append(" <li><b>Profile Instance</b></li>");
} else if (type.startsWith("profile-instance:res:")) {
String[] path = obj.split("\\.");
Page focus = home;
for (int i = 0; i < path.length; i++) {
focus = getChild(focus, path[i]);
if (focus.type == PageType.resource)
b.append(" <li><a href=\"" + prefix + focus.getReference().toLowerCase() + ".html\">" + imgLink(prefix, focus) + Utilities.escapeXml(focus.getReference()) + "</a></li>");
else
b.append(" <li><a href=\"" + prefix + focus.getFilename() + "\">" + imgLink(prefix, focus) + Utilities.escapeXml(focus.getTitle()) + "</a></li>");
}
b.append(" <li><a href=\"" + prefix + Utilities.fileTitle(name) + ".html\">" + Utilities.escapeXml(title) + "</a></li>");
b.append(" <li><b>Profile Instance</b></li>");
}
} else if (type.startsWith("profile-instance") || type.startsWith("profile-questionnaire")) {
String[] path = map.get("profilelist.html").split("\\.");
Page focus = home;
for (int i = 0; i < path.length; i++) {
focus = getChild(focus, path[i]);
if (focus.type == PageType.resource)
b.append(" <li><a href=\"" + prefix + focus.getReference().toLowerCase() + ".html\">" + imgLink(prefix, focus) + Utilities.escapeXml(focus.getReference()) + "</a></li>");
else
b.append(" <li><a href=\"" + prefix + focus.getFilename() + "\">" + imgLink(prefix, focus) + Utilities.escapeXml(focus.getTitle()) + "</a></li>");
}
b.append(" <li><b>Profile</b></li>");
} else if (type.startsWith("v2:")) {
String[] path = map.get("v2Vocab").split("\\.");
Page focus = home;
for (int i = 0; i < path.length - 1; i++) {
focus = getChild(focus, path[i]);
b.append(" <li><a href=\"" + prefix + focus.getFilename() + "\">" + imgLink(prefix, focus) + Utilities.escapeXml(focus.getTitle()) + "</a></li>");
}
b.append(" <li><a href=\"index.html\">" + Utilities.escapeXml(title) + "</a></li>");
b.append(" <li><b>Instance</b></li>");
} else if (type.startsWith("v3:")) {
String[] path = map.get("v3Vocab").split("\\.");
Page focus = home;
for (int i = 0; i < path.length - 1; i++) {
focus = getChild(focus, path[i]);
b.append(" <li><a href=\"" + prefix + focus.getFilename() + "\">" + imgLink(prefix, focus) + Utilities.escapeXml(focus.getTitle()) + "</a></li>");
}
b.append(" <li><a href=\"index.html\">" + Utilities.escapeXml(Utilities.fileTitle(name.substring(3))) + "</a></li>");
b.append(" <li><b>Instance</b></li>");
} else if (type.startsWith("sid:")) {
String[] path = map.get("terminologies.html").split("\\.");
Page focus = home;
for (int i = 0; i < path.length - 1; i++) {
focus = getChild(focus, path[i]);
b.append(" <li><a href=\"" + prefix + focus.getFilename() + "\">" + imgLink(prefix, focus) + Utilities.escapeXml(focus.getTitle()) + "</a></li>");
}
b.append(" <li><a href=\"" + prefix + "terminologies.html\">Terminologies</a></li>");
b.append(" <li><a href=\"" + prefix + "terminologies-systems.html\">Systems</a></li>");
b.append(" <li><b>SID: " + Utilities.escapeXml(type.substring(4)) + "</b></li>");
} else if ((name.startsWith("extension-") || name.startsWith("cqif\\extension-")) && name.endsWith(".html")) {
String url = title;
StructureDefinition ext = context.fetchResource(StructureDefinition.class, url);
if (!ext.hasContext() || ext.getContextFirstRep().getType() != ExtensionContextType.ELEMENT) {
b.append(" <li>??? " + Utilities.escapeXml(name) + " / " + Utilities.escapeXml(type) + "</li>\r\n");
System.out.println("no breadcrumb: name = " + name + ", type = " + type + ", prefix = " + prefix + ", title = '" + title + "'");
} else {
String[] path;
String ttl;
String fn;
String[] p = ext.getContextFirstRep().getExpression().split("\\.");
if (definitions.hasType(p[0])) {
path = map.get("datatypes.html").split("\\.");
ttl = "Data Types";
fn = "datatypes";
} else {
String rn = p[0];
ttl = rn;
if (ttl.equals("*"))
ttl = "Resource";
fn = ttl.toLowerCase();
String m = map.get(fn);
if (m == null)
path = new String[] { "??" };
else
path = m.split("\\.");
}
Page focus = home;
for (int i = 0; i < path.length; i++) {
focus = getChild(focus, path[i]);
if (focus.getFilename() != null)
b.append(" <li><a href=\"" + prefix + focus.getFilename() + "\">" + imgLink(prefix, focus) + Utilities.escapeXml(focus.getTitle()) + "</a></li>\r\n");
}
b.append(" <li><a href=\"" + fn + ".html\">" + Utilities.escapeXml(ttl) + "</a></li>");
b.append(" <li><b>Extension</b></li>");
}
} else if (type.equals("logical-model")) {
String m = map.get(head(name).toLowerCase() + ".html");
if (m != null) {
String[] path = m.split("\\.");
Page focus = home;
for (int i = 0; i < path.length; i++) {
focus = getChild(focus, path[i]);
if (focus.type == PageType.resource)
b.append(" <li><a href=\"" + prefix + focus.getReference().toLowerCase() + ".html\">" + imgLink(prefix, focus) + Utilities.escapeXml(focus.getReference()) + "</a></li>");
else
b.append(" <li><a href=\"" + prefix + focus.getFilename() + "\">" + imgLink(prefix, focus) + Utilities.escapeXml(focus.getTitle()) + "</a></li>");
}
} else
System.out.println("no breadcrumb: name = " + name + ", type = " + type + ", prefix = " + prefix + ", title = '" + title + "'");
b.append(" <li><b>Logical Model</b></li>");
} else if (type.startsWith("search-parameter:") || type.equals("searchparam-instance")) {
b.append(" <li><a href=\"foundation-module.html\"><img src=\"foundation.png\"/> Foundation</a></li>\r\n");
b.append(" <li><a href=\"http.html\">RESTful API</a></li>\r\n");
b.append(" <li><a href=\"search.html\">Search</a></li>\r\n");
b.append(" <li><b>Search Parameter</b></li>\r\n");
} else if (name.startsWith("codesystem-")) {
b.append(" <li><a href=\"terminology-module.html\"><img src=\"terminology.png\"/> Terminology</a></li>\r\n");
b.append(" <li><a href=\"terminologies-systems.html\">Code Systems</a></li>\r\n");
b.append(" <li><b>Code System</b></li>\r\n");
} else if (name.equals("qa.html")) {
b.append(" <li><b>QA Page</b></li>\r\n");
} else {
System.out.println("no breadcrumb: name = " + name + ", type = " + type + ", prefix = " + prefix + ", title = '" + title + "'");
}
}
}
b.append(" <!-- " + Utilities.escapeXml(name) + " / " + Utilities.escapeXml(type) + " / " + Utilities.escapeXml(title) + "-->\r\n");
return b.toString();
}
use of org.hl7.fhir.r5.model.Questionnaire in project kindling by HL7.
the class ProfileGenerator method generateElementDefinition.
private void generateElementDefinition(StructureDefinition source, ElementDefinition ed, ElementDefinition parent) throws Exception {
String id = ed.getPath().replace("[x]", "X");
if (id.length() > 64)
id = id.substring(0, 64);
if (!id.contains("."))
// throw new Exception("Don't generate data element for root of resources or types");
return;
if (!ed.hasType())
// throw new Exception("Don't generate data element for reference elements");
return;
if (Utilities.existsInList(ed.getType().get(0).getCode(), "Element", "BackboneElement"))
// throw new Exception("Don't generate data element for elements that are not leaves");
return;
StructureDefinition de;
if (des.containsKey(id)) {
de = des.get("de-" + id);
// do it again because we now have more information to generate with
de.getSnapshot().getElement().clear();
de.getExtension().clear();
} else {
de = new StructureDefinition();
de.setId("de-" + id);
des.put(id, de);
de.setUrl("http://hl7.org/fhir/StructureDefinition/" + de.getId());
if (de.getId().contains("."))
definitions.addNs(de.getUrl(), "Data Element " + ed.getPath(), definitions.getSrcFile(id.substring(0, id.indexOf("."))) + "-definitions.html#" + id);
if (dataElements != null)
dataElements.addEntry().setResource(de).setFullUrl(de.getUrl());
}
if (!de.hasMeta())
de.setMeta(new Meta());
de.getMeta().setLastUpdatedElement(new InstantType(genDate));
de.setVersion(version.toCode());
de.setName(ed.getPath());
de.setStatus(PublicationStatus.DRAFT);
de.setExperimental(true);
de.setTitle(de.getName());
de.setDate(genDate.getTime());
de.setPublisher("HL7 FHIR Standard");
de.addContact().getTelecom().add(Factory.newContactPoint(ContactPointSystem.URL, "http://hl7.org/fhir"));
de.setDescription("Data Element for " + ed.getPath());
de.setPurpose("Data Elements are defined for each element to assist in questionnaire construction etc");
de.setFhirVersion(version);
de.setKind(StructureDefinitionKind.LOGICAL);
de.setType("DataElement");
de.setAbstract(false);
de.setType(de.getName());
de.setBaseDefinition("http://hl7.org/fhir/StructureDefinition/Element");
de.setDerivation(TypeDerivationRule.SPECIALIZATION);
de.getMapping().addAll(source.getMapping());
ElementDefinition ted = ed.copy();
de.getSnapshot().addElement(ted);
ted.makeBase();
}
use of org.hl7.fhir.r5.model.Questionnaire in project kindling by HL7.
the class PageProcessor method resHeader.
private String resHeader(String n, String title, String mode) throws Exception {
StringBuilder b = new StringBuilder();
if (n.contains("-"))
n = n.substring(0, n.indexOf('-'));
ResourceDefn res = definitions.getResourceByName(title);
boolean hasOps = !res.getOperations().isEmpty();
boolean isAbstract = res.isAbstract();
b.append("<ul class=\"nav nav-tabs\">");
b.append(makeHeaderTab("Content", n + ".html", mode == null || "content".equals(mode)));
if (!isAbstract)
b.append(makeHeaderTab("Examples", n + "-examples.html", "examples".equals(mode)));
b.append(makeHeaderTab("Detailed Descriptions", n + "-definitions.html", "definitions".equals(mode)));
if (!isAbstract)
b.append(makeHeaderTab("Mappings", n + "-mappings.html", "mappings".equals(mode)));
if (!isAbstract)
b.append(makeHeaderTab("Profiles & Extensions", n + "-profiles.html", "profiles".equals(mode)));
// b.append(makeHeaderTab("HTML Form", n+"-questionnaire.html", "questionnaire".equals(mode)));
if (hasOps)
b.append(makeHeaderTab("Operations", n + "-operations.html", "operations".equals(mode)));
if (new File(Utilities.path(folders.rootDir, "implementations", "r3maps", "R4toR3", title + ".map")).exists())
b.append(makeHeaderTab("R3 Conversions", n + "-version-maps.html", "conversion".equals(mode)));
b.append("</ul>\r\n");
return b.toString();
}
use of org.hl7.fhir.r5.model.Questionnaire 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.r5.model.Questionnaire in project kindling by HL7.
the class Publisher method processQuestionnaire.
private void processQuestionnaire(ResourceDefn res, StructureDefinition profile, SectionTracker st, boolean isResource, String prefix, ImplementationGuideDefn ig) throws Exception {
QuestionnaireBuilder qb = new QuestionnaireBuilder(page.getWorkerContext());
qb.setProfile(profile);
qb.build();
Questionnaire q = qb.getQuestionnaire();
FileOutputStream s = new FileOutputStream(page.getFolders().dstDir + prefix + profile.getId().toLowerCase() + "-questionnaire.json");
new JsonParser().setOutputStyle(OutputStyle.PRETTY).compose(s, q);
s.close();
s = new FileOutputStream(page.getFolders().dstDir + prefix + profile.getId().toLowerCase() + "-questionnaire.canonical.json");
new JsonParser().setOutputStyle(OutputStyle.CANONICAL).compose(s, q);
s.close();
s = new FileOutputStream(page.getFolders().dstDir + prefix + profile.getId().toLowerCase() + "-questionnaire.xml");
new XmlParser().setOutputStyle(OutputStyle.PRETTY).compose(s, q);
s.close();
s = new FileOutputStream(page.getFolders().dstDir + prefix + profile.getId().toLowerCase() + "-questionnaire.canonical.xml");
new XmlParser().setOutputStyle(OutputStyle.CANONICAL).compose(s, q);
s.close();
String json = "<div class=\"example\">\r\n<p>Generated Questionnaire for " + profile.getId() + "</p>\r\n<pre class=\"json\">\r\n" + Utilities.escapeXml(new JsonParser().setOutputStyle(OutputStyle.PRETTY).composeString(q)) + "\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(prefix + profile.getId().toLowerCase() + "-questionnaire.json.html", html, (isResource ? "resource-questionnaire:" : "profile-questionnaire:") + profile.getId(), null, null, null, "Questionnaire", ig, res, res == null ? wg("fhir") : res.getWg());
TextFile.stringToFile(html, page.getFolders().dstDir + prefix + profile.getId().toLowerCase() + "-questionnaire.json.html");
String xml = "<div class=\"example\">\r\n<p>Generated Questionnaire for " + profile.getId() + "</p>\r\n<pre class=\"json\">\r\n" + Utilities.escapeXml(new XmlParser().setOutputStyle(OutputStyle.PRETTY).composeString(q)) + "\r\n</pre>\r\n</div>\r\n";
html = TextFile.fileToString(page.getFolders().templateDir + "template-example-xml.html").replace("<%example%>", xml);
html = page.processPageIncludes(prefix + profile.getId().toLowerCase() + "-questionnaire.xml.html", html, (isResource ? "resource-questionnaire:" : "profile-questionnaire:") + profile.getId(), null, null, null, "Questionnaire", ig, res, res == null ? wg("fhir") : res.getWg());
TextFile.stringToFile(html, page.getFolders().dstDir + prefix + profile.getId().toLowerCase() + "-questionnaire.xml.html");
if (false) {
File tmpTransform = Utilities.createTempFile("tmp", ".html");
// if (web) {
HashMap<String, String> params = new HashMap<String, String>();
params.put("suppressWarnings", "true");
XsltUtilities.saxonTransform(// directory for xslt references
Utilities.path(page.getFolders().rootDir, "implementations", "xmltools"), // source to run xslt on
page.getFolders().dstDir + prefix + profile.getId().toLowerCase() + "-questionnaire.xml", // xslt file to run
Utilities.path(page.getFolders().rootDir, "implementations", "xmltools", "QuestionnaireToHTML.xslt"), // file to produce
tmpTransform.getAbsolutePath(), // handle to self to implement URI resolver for terminology fetching
this, params);
// } else
// TextFile.stringToFile("test", tmpTransform.getAbsolutePath());
// now, generate the form
html = TextFile.fileToString(page.getFolders().templateDir + (isResource ? "template-questionnaire.html" : "template-profile-questionnaire.html")).replace("<%questionnaire%>", loadHtmlForm(tmpTransform.getAbsolutePath()));
} else
html = "<html><p>Not generated in this build</p></html>";
html = page.processPageIncludes(profile.getId().toLowerCase() + "-questionnaire.html", html, (isResource ? "resource-questionnaire:" : "profile-questionnaire:") + profile.getId(), null, profile, null, "Questionnaire", ig, res, res == null ? wg("fhir") : res.getWg());
int level = (ig == null || ig.isCore()) ? 0 : 1;
if (st != null)
html = insertSectionNumbers(html, st, profile.getId().toLowerCase() + "-questionnaire.html", level, null);
TextFile.stringToFile(html, page.getFolders().dstDir + prefix + profile.getId().toLowerCase() + "-questionnaire.html");
page.getHTMLChecker().registerExternal(prefix + profile.getId().toLowerCase() + "-questionnaire.html");
page.getHTMLChecker().registerExternal(prefix + profile.getId().toLowerCase() + "-questionnaire.json.html");
page.getHTMLChecker().registerExternal(prefix + profile.getId().toLowerCase() + "-questionnaire.xml.html");
}
Aggregations