Search in sources :

Example 1 with QuestionnaireBuilder

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");
}
Also used : XmlParser(org.hl7.fhir.r5.formats.XmlParser) Questionnaire(org.hl7.fhir.r5.model.Questionnaire) LinkedHashMap(java.util.LinkedHashMap) HashMap(java.util.HashMap) FileOutputStream(java.io.FileOutputStream) IniFile(org.hl7.fhir.utilities.IniFile) File(java.io.File) CSFile(org.hl7.fhir.utilities.CSFile) TextFile(org.hl7.fhir.utilities.TextFile) ContactPoint(org.hl7.fhir.r5.model.ContactPoint) QuestionnaireBuilder(org.hl7.fhir.r5.utils.QuestionnaireBuilder) JsonParser(org.hl7.fhir.r5.formats.JsonParser)

Aggregations

File (java.io.File)1 FileOutputStream (java.io.FileOutputStream)1 HashMap (java.util.HashMap)1 LinkedHashMap (java.util.LinkedHashMap)1 JsonParser (org.hl7.fhir.r5.formats.JsonParser)1 XmlParser (org.hl7.fhir.r5.formats.XmlParser)1 ContactPoint (org.hl7.fhir.r5.model.ContactPoint)1 Questionnaire (org.hl7.fhir.r5.model.Questionnaire)1 QuestionnaireBuilder (org.hl7.fhir.r5.utils.QuestionnaireBuilder)1 CSFile (org.hl7.fhir.utilities.CSFile)1 IniFile (org.hl7.fhir.utilities.IniFile)1 TextFile (org.hl7.fhir.utilities.TextFile)1