Search in sources :

Example 66 with ImplementationGuideDefn

use of org.hl7.fhir.definitions.model.ImplementationGuideDefn 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

ImplementationGuideDefn (org.hl7.fhir.definitions.model.ImplementationGuideDefn)34 FHIRException (org.hl7.fhir.exceptions.FHIRException)25 FileNotFoundException (java.io.FileNotFoundException)22 IOException (java.io.IOException)22 TransformerException (javax.xml.transform.TransformerException)21 CSFile (org.hl7.fhir.utilities.CSFile)21 StructureDefinition (org.hl7.fhir.r5.model.StructureDefinition)19 CommaSeparatedStringBuilder (org.hl7.fhir.utilities.CommaSeparatedStringBuilder)18 ContactPoint (org.hl7.fhir.r5.model.ContactPoint)17 File (java.io.File)16 ArrayList (java.util.ArrayList)16 Profile (org.hl7.fhir.definitions.model.Profile)16 ValueSet (org.hl7.fhir.r5.model.ValueSet)15 IniFile (org.hl7.fhir.utilities.IniFile)15 TextFile (org.hl7.fhir.utilities.TextFile)15 Example (org.hl7.fhir.definitions.model.Example)14 UnsupportedEncodingException (java.io.UnsupportedEncodingException)11 URISyntaxException (java.net.URISyntaxException)11 HashMap (java.util.HashMap)10 TransformerConfigurationException (javax.xml.transform.TransformerConfigurationException)10