Search in sources :

Example 6 with TerminologyNotesGenerator

use of org.hl7.fhir.definitions.generators.specification.TerminologyNotesGenerator 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();
}
Also used : XmlParser(org.hl7.fhir.r5.formats.XmlParser) LinkedHashMap(java.util.LinkedHashMap) HashMap(java.util.HashMap) TerminologyNotesGenerator(org.hl7.fhir.definitions.generators.specification.TerminologyNotesGenerator) DictHTMLGenerator(org.hl7.fhir.definitions.generators.specification.DictHTMLGenerator) MappingsGenerator(org.hl7.fhir.definitions.generators.specification.MappingsGenerator) SvgGenerator(org.hl7.fhir.definitions.generators.specification.SvgGenerator) 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) JsonParser(org.hl7.fhir.r5.formats.JsonParser) RdfParser(org.hl7.fhir.r5.formats.RdfParser)

Aggregations

TerminologyNotesGenerator (org.hl7.fhir.definitions.generators.specification.TerminologyNotesGenerator)6 FileOutputStream (java.io.FileOutputStream)5 File (java.io.File)4 CSFile (org.hl7.fhir.utilities.CSFile)4 IniFile (org.hl7.fhir.utilities.IniFile)4 TextFile (org.hl7.fhir.utilities.TextFile)4 ByteArrayOutputStream (java.io.ByteArrayOutputStream)3 FileNotFoundException (java.io.FileNotFoundException)3 IOException (java.io.IOException)3 TransformerException (javax.xml.transform.TransformerException)3 FHIRException (org.hl7.fhir.exceptions.FHIRException)3 JsonParser (org.hl7.fhir.r5.formats.JsonParser)3 XmlParser (org.hl7.fhir.r5.formats.XmlParser)3 UnsupportedEncodingException (java.io.UnsupportedEncodingException)2 HashMap (java.util.HashMap)2 LinkedHashMap (java.util.LinkedHashMap)2 DocumentBuilder (javax.xml.parsers.DocumentBuilder)2 DocumentBuilderFactory (javax.xml.parsers.DocumentBuilderFactory)2 DictHTMLGenerator (org.hl7.fhir.definitions.generators.specification.DictHTMLGenerator)2 JsonSpecGenerator (org.hl7.fhir.definitions.generators.specification.JsonSpecGenerator)2