Search in sources :

Example 1 with TerminologyNotesGenerator

use of org.hl7.fhir.definitions.generators.specification.TerminologyNotesGenerator in project kindling by HL7.

the class Publisher method produceProfile.

private void produceProfile(ResourceDefn resource, Profile pack, ConstraintStructure profile, SectionTracker st, String intro, String notes, String prefix, ImplementationGuideDefn ig) throws Exception {
    File tmp = Utilities.createTempFile("tmp", ".tmp");
    String title = profile.getId();
    int level = (ig == null || ig.isCore()) ? 0 : 1;
    // you have to validate a profile, because it has to be merged with it's
    // base resource to fill out all the missing bits
    // validateProfile(profile);
    ByteArrayOutputStream bs = new ByteArrayOutputStream();
    XmlSpecGenerator gen = new XmlSpecGenerator(bs, title + "-definitions.html", "", page, ig.isCore() ? "" : "../");
    gen.generate(profile.getResource());
    gen.close();
    String xml = new String(bs.toByteArray());
    bs = new ByteArrayOutputStream();
    JsonSpecGenerator genJ = new JsonSpecGenerator(bs, title + "-definitions.html", "", page, ig.isCore() ? "" : "../", page.getVersion().toCode());
    genJ.generate(profile.getResource());
    genJ.close();
    String json = new String(bs.toByteArray());
    XmlParser comp = new XmlParser();
    FileOutputStream s = new FileOutputStream(page.getFolders().dstDir + prefix + title + ".profile.xml");
    comp.setOutputStyle(OutputStyle.PRETTY).compose(s, profile.getResource());
    s.close();
    Utilities.copyFile(new CSFile(page.getFolders().dstDir + prefix + title + ".profile.xml"), new CSFile(page.getFolders().dstDir + "examples" + File.separator + title + ".profile.xml"));
    JsonParser jcomp = new JsonParser();
    s = new FileOutputStream(page.getFolders().dstDir + prefix + title + ".profile.json");
    jcomp.setOutputStyle(OutputStyle.PRETTY).compose(s, profile.getResource());
    s.close();
    // String shex = new ShExGenerator(page.getWorkerContext()).generate(HTMLLinkPolicy.NONE, profile.getResource());
    // TextFile.stringToFile(shex, Utilities.changeFileExt(page.getFolders().dstDir + prefix +title + ".profile.shex", ".shex"));
    // shexToXhtml(prefix +title + ".profile", "ShEx statement for " + prefix +title, shex, "profile-instance:type:" + title, "Type");
    TerminologyNotesGenerator tgen = new TerminologyNotesGenerator(new FileOutputStream(tmp), page);
    tgen.generate(level == 0 ? "" : "../", profile);
    tgen.close();
    String tx = TextFile.fileToString(tmp.getAbsolutePath());
    String src = TextFile.fileToString(page.getFolders().templateDir + "template-profile.html");
    src = page.processProfileIncludes(profile.getId(), profile.getId(), pack, profile, xml, json, tx, src, title + ".html", (resource == null ? profile.getResource().getType() : resource.getName()) + "/" + pack.getId() + "/" + profile.getId(), intro, notes, ig, false, false);
    if (st != null)
        src = insertSectionNumbers(src, st, title + ".html", level, null);
    else if (ig != null && !ig.isCore()) {
        src = addSectionNumbers(title + ".html", title, src, null, 1, null, ig);
        st = page.getSectionTrackerCache().get(ig.getCode() + "::" + title);
    }
    page.getHTMLChecker().registerFile(prefix + title + ".html", "StructureDefinition " + profile.getResource().getName(), HTMLLinkChecker.XHTML_TYPE, false);
    TextFile.stringToFile(src, page.getFolders().dstDir + prefix + title + ".html");
    new ProfileUtilities(page.getWorkerContext(), page.getValidationErrors(), page).generateSchematrons(new FileOutputStream(page.getFolders().dstDir + prefix + title + ".sch"), profile.getResource());
    if (pack.getExamples().size() > 0) {
        src = TextFile.fileToString(page.getFolders().templateDir + "template-profile-examples.html");
        src = page.processProfileIncludes(profile.getId(), profile.getId(), pack, profile, xml, json, tx, src, title + ".html", (resource == null ? profile.getResource().getType() : resource.getName()) + "/" + pack.getId() + "/" + profile.getId(), intro, notes, ig, false, false);
        page.getHTMLChecker().registerFile(prefix + title + "-examples.html", "Examples for StructureDefinition " + profile.getResource().getName(), HTMLLinkChecker.XHTML_TYPE, true);
        TextFile.stringToFile(src, page.getFolders().dstDir + prefix + title + "-examples.html");
    }
    src = TextFile.fileToString(page.getFolders().templateDir + "template-profile-definitions.html");
    src = page.processProfileIncludes(profile.getId(), profile.getId(), pack, profile, xml, json, tx, src, title + ".html", (resource == null ? profile.getResource().getType() : resource.getName()) + "/" + pack.getId() + "/" + profile.getId(), intro, notes, ig, false, false);
    if (st != null)
        src = insertSectionNumbers(src, st, title + "-definitions.html", level, null);
    page.getHTMLChecker().registerFile(prefix + title + "-definitions.html", "Definitions for StructureDefinition " + profile.getResource().getName(), HTMLLinkChecker.XHTML_TYPE, true);
    TextFile.stringToFile(src, page.getFolders().dstDir + prefix + title + "-definitions.html");
    src = TextFile.fileToString(page.getFolders().templateDir + "template-profile-mappings.html");
    src = page.processProfileIncludes(profile.getId(), profile.getId(), pack, profile, xml, json, tx, src, title + ".html", (resource == null ? profile.getResource().getType() : resource.getName()) + "/" + pack.getId() + "/" + profile.getId(), intro, notes, ig, false, false);
    if (st != null)
        src = insertSectionNumbers(src, st, title + "-mappings.html", level, null);
    page.getHTMLChecker().registerFile(prefix + title + "-mappings.html", "Mappings for StructureDefinition " + profile.getResource().getName(), HTMLLinkChecker.XHTML_TYPE, true);
    TextFile.stringToFile(src, page.getFolders().dstDir + prefix + title + "-mappings.html");
    try {
        processQuestionnaire(resource, profile.getResource(), st, false, prefix, ig);
    } catch (Exception e) {
        e.printStackTrace();
        page.log("Questionnaire Generation Failed: " + e.getMessage(), LogMessageType.Error);
    }
    new ReviewSpreadsheetGenerator().generate(page.getFolders().dstDir + prefix + Utilities.changeFileExt((String) profile.getResource().getUserData("filename"), "-review.xls"), "Health Level Seven International", page.getGenDate(), profile.getResource(), page);
    // xml to xhtml of xml
    // first pass is to strip the xsi: stuff. seems to need double
    // processing in order to delete namespace crap
    DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
    factory.setNamespaceAware(true);
    DocumentBuilder builder = factory.newDocumentBuilder();
    Document xdoc = builder.parse(new CSFileInputStream(page.getFolders().dstDir + prefix + title + ".profile.xml"));
    XmlGenerator xmlgen = new XmlGenerator();
    xmlgen.generate(xdoc.getDocumentElement(), tmp, "http://hl7.org/fhir", xdoc.getDocumentElement().getLocalName());
    // reload it now
    builder = factory.newDocumentBuilder();
    xdoc = builder.parse(new CSFileInputStream(tmp.getAbsolutePath()));
    XhtmlGenerator xhtml = new XhtmlGenerator(new ExampleAdorner(page.getDefinitions(), page.genlevel(level)));
    ByteArrayOutputStream b = new ByteArrayOutputStream();
    xhtml.generate(xdoc, b, "StructureDefinition", profile.getTitle(), 0, true, title + ".profile.xml.html");
    String html = TextFile.fileToString(page.getFolders().templateDir + "template-profile-example-xml.html").replace("<%example%>", b.toString());
    html = page.processProfileIncludes(title + ".profile.xml.html", profile.getId(), pack, profile, "", "", "", html, title + ".html", (resource == null ? profile.getResource().getType() : resource.getName()) + "/" + pack.getId() + "/" + profile.getId(), intro, notes, ig, false, hasNarrative(xdoc));
    TextFile.stringToFile(html, page.getFolders().dstDir + prefix + title + ".profile.xml.html");
    page.getHTMLChecker().registerFile(prefix + title + ".profile.xml.html", "StructureDefinition", HTMLLinkChecker.XHTML_TYPE, false);
    String n = prefix + title + ".profile";
    json = resource2Json(profile.getResource());
    json = "<div class=\"example\">\r\n<p>" + Utilities.escapeXml("StructureDefinition for " + profile.getResource().getDescription()) + "</p>\r\n<p><a href=\"" + title + ".profile.json\">Raw JSON</a></p>\r\n<pre class=\"json\">\r\n" + Utilities.escapeXml(json) + "\r\n</pre>\r\n</div>\r\n";
    html = TextFile.fileToString(page.getFolders().templateDir + "template-profile-example-json.html").replace("<%example%>", json);
    html = page.processProfileIncludes(title + ".profile.json.html", profile.getId(), pack, profile, "", "", "", html, title + ".html", (resource == null ? profile.getResource().getType() : resource.getName()) + "/" + pack.getId() + "/" + profile.getId(), intro, notes, ig, false, false);
    TextFile.stringToFile(html, page.getFolders().dstDir + prefix + title + ".profile.json.html");
    // page.getEpub().registerFile(n + ".json.html", description, EPubManager.XHTML_TYPE);
    page.getHTMLChecker().registerExternal(n + ".json.html");
    tmp.delete();
}
Also used : XmlParser(org.hl7.fhir.r5.formats.XmlParser) XmlSpecGenerator(org.hl7.fhir.definitions.generators.specification.XmlSpecGenerator) JsonSpecGenerator(org.hl7.fhir.definitions.generators.specification.JsonSpecGenerator) DocumentBuilderFactory(javax.xml.parsers.DocumentBuilderFactory) XmlGenerator(org.hl7.fhir.utilities.xml.XmlGenerator) TerminologyNotesGenerator(org.hl7.fhir.definitions.generators.specification.TerminologyNotesGenerator) ByteArrayOutputStream(java.io.ByteArrayOutputStream) CSFile(org.hl7.fhir.utilities.CSFile) Document(org.w3c.dom.Document) XhtmlDocument(org.hl7.fhir.utilities.xhtml.XhtmlDocument) ContactPoint(org.hl7.fhir.r5.model.ContactPoint) TransformerException(javax.xml.transform.TransformerException) IOException(java.io.IOException) FHIRException(org.hl7.fhir.exceptions.FHIRException) FileNotFoundException(java.io.FileNotFoundException) UnsupportedEncodingException(java.io.UnsupportedEncodingException) ReviewSpreadsheetGenerator(org.hl7.fhir.definitions.generators.specification.ReviewSpreadsheetGenerator) XhtmlGenerator(org.hl7.fhir.utilities.xml.XhtmlGenerator) ProfileUtilities(org.hl7.fhir.r5.conformance.ProfileUtilities) DocumentBuilder(javax.xml.parsers.DocumentBuilder) 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) CSFileInputStream(org.hl7.fhir.utilities.CSFileInputStream) JsonParser(org.hl7.fhir.r5.formats.JsonParser)

Example 2 with TerminologyNotesGenerator

use of org.hl7.fhir.definitions.generators.specification.TerminologyNotesGenerator in project kindling by HL7.

the class PageProcessor method tsForDt.

private String tsForDt(String dt) throws Exception {
    File tmp = Utilities.createTempFile("tmp", ".tmp");
    tmp.deleteOnExit();
    TerminologyNotesGenerator gen = new TerminologyNotesGenerator(new FileOutputStream(tmp), this);
    TypeParser tp = new TypeParser(version.toCode());
    TypeRef t = tp.parse(dt, false, null, workerContext, true).get(0);
    ElementDefn e = definitions.getElementDefn(t.getName());
    if (e == null) {
        gen.close();
        throw new Exception("unable to find definition for " + dt);
    } else {
        gen.generate("", e);
        gen.close();
    }
    String val = TextFile.fileToString(tmp.getAbsolutePath()) + "\r\n";
    tmp.delete();
    return val;
}
Also used : ITypeParser(org.hl7.fhir.r5.renderers.utils.RenderingContext.ITypeParser) TypeParser(org.hl7.fhir.definitions.parsers.TypeParser) TerminologyNotesGenerator(org.hl7.fhir.definitions.generators.specification.TerminologyNotesGenerator) TypeRef(org.hl7.fhir.definitions.model.TypeRef) FileOutputStream(java.io.FileOutputStream) ElementDefn(org.hl7.fhir.definitions.model.ElementDefn) IniFile(org.hl7.fhir.utilities.IniFile) File(java.io.File) CSFile(org.hl7.fhir.utilities.CSFile) TextFile(org.hl7.fhir.utilities.TextFile) UcumException(org.fhir.ucum.UcumException) TransformerException(javax.xml.transform.TransformerException) TransformerConfigurationException(javax.xml.transform.TransformerConfigurationException) IOException(java.io.IOException) FHIRException(org.hl7.fhir.exceptions.FHIRException) URISyntaxException(java.net.URISyntaxException) PathEngineException(org.hl7.fhir.exceptions.PathEngineException) DefinitionException(org.hl7.fhir.exceptions.DefinitionException) FileNotFoundException(java.io.FileNotFoundException) NotImplementedException(org.apache.commons.lang3.NotImplementedException)

Example 3 with TerminologyNotesGenerator

use of org.hl7.fhir.definitions.generators.specification.TerminologyNotesGenerator 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"));
}
Also used : JsonObject(com.google.gson.JsonObject) DocumentBuilderFactory(javax.xml.parsers.DocumentBuilderFactory) XhtmlParser(org.hl7.fhir.utilities.xhtml.XhtmlParser) LinkedHashMap(java.util.LinkedHashMap) HashMap(java.util.HashMap) DictHTMLGenerator(org.hl7.fhir.definitions.generators.specification.DictHTMLGenerator) Element(org.w3c.dom.Element) JsonObject(com.google.gson.JsonObject) Gson(com.google.gson.Gson) MappingsGenerator(org.hl7.fhir.definitions.generators.specification.MappingsGenerator) Operation(org.hl7.fhir.definitions.model.Operation) Document(org.w3c.dom.Document) XhtmlDocument(org.hl7.fhir.utilities.xhtml.XhtmlDocument) Profile(org.hl7.fhir.definitions.model.Profile) StructureDefinition(org.hl7.fhir.r5.model.StructureDefinition) Example(org.hl7.fhir.definitions.model.Example) ConceptMap(org.hl7.fhir.r5.model.ConceptMap) GsonBuilder(com.google.gson.GsonBuilder) TerminologyNotesGenerator(org.hl7.fhir.definitions.generators.specification.TerminologyNotesGenerator) TransformerException(javax.xml.transform.TransformerException) IOException(java.io.IOException) FHIRException(org.hl7.fhir.exceptions.FHIRException) FileNotFoundException(java.io.FileNotFoundException) UnsupportedEncodingException(java.io.UnsupportedEncodingException) SvgGenerator(org.hl7.fhir.definitions.generators.specification.SvgGenerator) ProfileUtilities(org.hl7.fhir.r5.conformance.ProfileUtilities) DocumentBuilder(javax.xml.parsers.DocumentBuilder) 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)

Example 4 with TerminologyNotesGenerator

use of org.hl7.fhir.definitions.generators.specification.TerminologyNotesGenerator in project kindling by HL7.

the class Publisher method produceExtensionDefinition.

private void produceExtensionDefinition(StructureDefinition ed) throws FileNotFoundException, Exception {
    if (!ped.contains(ed)) {
        ped.add(ed);
        ImplementationGuideDefn ig = page.getDefinitions().getIgs().get(ed.getUserString(ToolResourceUtilities.NAME_RES_IG));
        String prefix = ig.isCore() ? "" : ig.getCode() + File.separator;
        String filename = ed.getUserString("filename");
        FileOutputStream s = new FileOutputStream(page.getFolders().dstDir + prefix + filename + ".xml");
        new XmlParser().setOutputStyle(OutputStyle.PRETTY).compose(s, ed);
        s.close();
        s = new FileOutputStream(page.getFolders().dstDir + prefix + filename + ".canonical.xml");
        new XmlParser().setOutputStyle(OutputStyle.CANONICAL).compose(s, ed);
        s.close();
        s = new FileOutputStream(page.getFolders().dstDir + prefix + filename + ".json");
        new JsonParser().setOutputStyle(OutputStyle.PRETTY).compose(s, ed);
        s.close();
        s = new FileOutputStream(page.getFolders().dstDir + prefix + filename + ".canonical.json");
        new JsonParser().setOutputStyle(OutputStyle.CANONICAL).compose(s, ed);
        s.close();
        cloneToXhtml(prefix + filename, ed.getName(), false, "summary-instance", ed.getUrl(), null, wg(ed));
        jsonToXhtml(prefix + filename, ed.getName(), resource2Json(ed), "extension", ed.getUrl(), null, wg(ed));
        ttlToXhtml(prefix + filename, ed.getName(), resource2Ttl(ed), "extension", ed.getUrl(), null, wg(ed));
        ByteArrayOutputStream bytes = new ByteArrayOutputStream();
        XmlSpecGenerator gen = new XmlSpecGenerator(bytes, filename + "-definitions.html", null, /*"http://hl7.org/fhir/"*/
        page, page.genlevel(ig.isCore() ? 0 : 1));
        gen.generateExtension(ed);
        gen.close();
        String xml = bytes.toString();
        bytes = new ByteArrayOutputStream();
        JsonSpecGenerator genj = new JsonSpecGenerator(bytes, filename + "-definitions.html", null, /*"http://hl7.org/fhir/"*/
        page, page.genlevel(ig.isCore() ? 0 : 1), page.getVersion().toCode());
        genj.generateExtension(ed);
        genj.close();
        String json = bytes.toString();
        bytes = new ByteArrayOutputStream();
        TurtleSpecGenerator gent = new TurtleSpecGenerator(bytes, filename + "-definitions.html", null, /*"http://hl7.org/fhir/"*/
        page, page.genlevel(ig.isCore() ? 0 : 1), page.getVersion().toCode());
        gent.generateExtension(ed);
        gent.close();
        String ttl = bytes.toString();
        bytes = new ByteArrayOutputStream();
        TerminologyNotesGenerator tgen = new TerminologyNotesGenerator(bytes, page);
        tgen.generateExtension("", ed);
        tgen.close();
        String tx = bytes.toString();
        String src = TextFile.fileToString(page.getFolders().templateDir + "template-extension-mappings.html");
        src = page.processExtensionIncludes(filename, ed, xml, json, ttl, tx, src, filename + ".html", ig);
        page.getHTMLChecker().registerFile(prefix + filename + "-mappings.html", "Mappings for Extension " + ed.getName(), HTMLLinkChecker.XHTML_TYPE, true);
        TextFile.stringToFile(src, page.getFolders().dstDir + prefix + filename + "-mappings.html");
        src = TextFile.fileToString(page.getFolders().templateDir + "template-extension-definitions.html");
        src = page.processExtensionIncludes(filename, ed, xml, json, ttl, tx, src, filename + ".html", ig);
        page.getHTMLChecker().registerFile(prefix + filename + "-definitions.html", "Definitions for Extension " + ed.getName(), HTMLLinkChecker.XHTML_TYPE, true);
        TextFile.stringToFile(src, page.getFolders().dstDir + prefix + filename + "-definitions.html");
        src = TextFile.fileToString(page.getFolders().templateDir + "template-extension.html");
        src = page.processExtensionIncludes(filename, ed, xml, json, ttl, tx, src, filename + ".html", ig);
        page.getHTMLChecker().registerFile(prefix + filename + ".html", "Extension " + ed.getName(), HTMLLinkChecker.XHTML_TYPE, true);
        TextFile.stringToFile(src, page.getFolders().dstDir + prefix + filename + ".html");
    }
}
Also used : XmlParser(org.hl7.fhir.r5.formats.XmlParser) XmlSpecGenerator(org.hl7.fhir.definitions.generators.specification.XmlSpecGenerator) JsonSpecGenerator(org.hl7.fhir.definitions.generators.specification.JsonSpecGenerator) TerminologyNotesGenerator(org.hl7.fhir.definitions.generators.specification.TerminologyNotesGenerator) FileOutputStream(java.io.FileOutputStream) TurtleSpecGenerator(org.hl7.fhir.definitions.generators.specification.TurtleSpecGenerator) ByteArrayOutputStream(java.io.ByteArrayOutputStream) ImplementationGuideDefn(org.hl7.fhir.definitions.model.ImplementationGuideDefn) JsonParser(org.hl7.fhir.r5.formats.JsonParser)

Example 5 with TerminologyNotesGenerator

use of org.hl7.fhir.definitions.generators.specification.TerminologyNotesGenerator in project kindling by HL7.

the class PageProcessor method produceDataTypeTx.

private String produceDataTypeTx(String dtname) throws Exception {
    TypeDefn dt = definitions.getElementDefn(dtname);
    ByteArrayOutputStream bs = new ByteArrayOutputStream();
    TerminologyNotesGenerator tgen = new TerminologyNotesGenerator(bs, this);
    tgen.setNoHeader(true);
    tgen.generate("", dt);
    tgen.close();
    return new String(bs.toByteArray());
}
Also used : TypeDefn(org.hl7.fhir.definitions.model.TypeDefn) TerminologyNotesGenerator(org.hl7.fhir.definitions.generators.specification.TerminologyNotesGenerator) ByteArrayOutputStream(java.io.ByteArrayOutputStream)

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