use of org.hl7.fhir.r5.utils.QuestionnaireBuilder 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