Search in sources :

Example 1 with MappingsGenerator

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

the class PageProcessor method mappingsExtension.

private String mappingsExtension(StructureDefinition ed) throws IOException {
    MappingsGenerator m = new MappingsGenerator(definitions);
    m.generate(ed);
    return m.getMappings();
}
Also used : MappingsGenerator(org.hl7.fhir.definitions.generators.specification.MappingsGenerator)

Example 2 with MappingsGenerator

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

the class PageProcessor method genDataTypeMappings.

private String genDataTypeMappings(String name) throws Exception {
    if (name.equals("primitives")) {
        StringBuilder b = new StringBuilder();
        b.append("<table class=\"grid\">\r\n");
        b.append("<tr>");
        b.append("<td><b>Data Type</b></td>");
        b.append("<td><b>V2</b></td>");
        b.append("<td><b>RIM</b></td>");
        b.append("</tr>");
        List<String> names = new ArrayList<String>();
        names.addAll(definitions.getPrimitives().keySet());
        Collections.sort(names);
        for (String n : names) {
            DefinedCode dc = definitions.getPrimitives().get(n);
            if (dc instanceof PrimitiveType) {
                PrimitiveType pt = (PrimitiveType) dc;
                b.append("<tr>");
                b.append("<td>").append(n).append("</td>");
                b.append("<td>").append(pt.getV2()).append("</td>");
                b.append("<td>").append(pt.getV3()).append("</td>");
                b.append("</tr>");
            }
        }
        b.append("</table>\r\n");
        return b.toString();
    } else {
        List<ElementDefn> list = new ArrayList<ElementDefn>();
        // list.addAll(definitions.getStructures().values());
        // list.addAll(definitions.getTypes().values());
        // list.addAll(definitions.getInfrastructure().values());
        list.add(definitions.getElementDefn(name));
        MappingsGenerator maps = new MappingsGenerator(definitions);
        maps.generate(list);
        return maps.getMappings();
    }
}
Also used : CommaSeparatedStringBuilder(org.hl7.fhir.utilities.CommaSeparatedStringBuilder) DefinedCode(org.hl7.fhir.definitions.model.DefinedCode) ArrayList(java.util.ArrayList) ElementDefn(org.hl7.fhir.definitions.model.ElementDefn) PrimitiveType(org.hl7.fhir.definitions.model.PrimitiveType) MappingsGenerator(org.hl7.fhir.definitions.generators.specification.MappingsGenerator)

Example 3 with MappingsGenerator

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

the class PageProcessor method mappingsProfile.

/*
  private String profileExampleList(ProfileDefn profile, Map<String, Example> examples, String example) {
    if (examples == null || examples.isEmpty())
      return "<p>No Examples Provided.</p>";
    else if (examples.size() == 1)
      return example;
    else{
      StringBuilder s = new StringBuilder();

      boolean started = false;
      List<String> names = new ArrayList<String>();
      names.addAll(examples.keySet());
      Collections.sort(names);
      for (String n : names) {
        Example e = examples.get(n);
        if (!started)
          s.append("<p>Example Index:</p>\r\n<table class=\"list\">\r\n");
        started = true;
        if (e.getFileTitle().equals("capabilitystatement-base") || e.getFileTitle().equals("capabilitystatement-base2") || e.getFileTitle().equals("profiles-resources"))
          s.append("<tr><td>"+Utilities.escapeXml(e.getDescription())+"</td>");
        else
          s.append("<tr><td><a href=\""+e.getFileTitle()+".html\">"+Utilities.escapeXml(e.getDescription())+"</a></td>");
        s.append("<td><a href=\""+e.getFileTitle()+".xml.html\">XML</a></td>");
        s.append("<td><a href=\""+e.getFileTitle()+".json.html\">JSON</a></td>");
        s.append("</tr>");
      }

      //  }
      if (started)
        s.append("</table>\r\n");
      return s.toString();
    }
  }
  */
private String mappingsProfile(StructureDefinition source) throws IOException {
    MappingsGenerator m = new MappingsGenerator(definitions);
    m.generate(source);
    return m.getMappings();
}
Also used : MappingsGenerator(org.hl7.fhir.definitions.generators.specification.MappingsGenerator)

Example 4 with MappingsGenerator

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

the class PageProcessor method mapOnThisPage.

public String mapOnThisPage(String mappings) {
    if (mappings == null) {
        List<ElementDefn> list = new ArrayList<ElementDefn>();
        list.addAll(definitions.getTypes().values());
        list.addAll(definitions.getInfrastructure().values());
        MappingsGenerator maps = new MappingsGenerator(definitions);
        maps.generate(list);
        mappings = maps.getMappingsList();
    }
    if (Utilities.noString(mappings))
        return "";
    String[] entries = mappings.split("\\|");
    StringBuilder b = new StringBuilder();
    b.append("<div class=\"itoc\">\r\n<p>Mappings:</p>\r\n");
    for (String e : entries) {
        String[] p = e.split("#");
        if (p.length == 2)
            b.append("<p class=\"link\"><a href=\"#" + p[1] + "\">" + Utilities.escapeXml(p[0]) + "</a></p>");
        if (p.length == 1)
            b.append("<p class=\"link\"><a href=\"#\">" + Utilities.escapeXml(p[0]) + "</a></p>");
    }
    b.append("</div>\r\n");
    return b.toString();
}
Also used : CommaSeparatedStringBuilder(org.hl7.fhir.utilities.CommaSeparatedStringBuilder) ElementDefn(org.hl7.fhir.definitions.model.ElementDefn) ArrayList(java.util.ArrayList) MappingsGenerator(org.hl7.fhir.definitions.generators.specification.MappingsGenerator)

Example 5 with MappingsGenerator

use of org.hl7.fhir.definitions.generators.specification.MappingsGenerator 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)

Aggregations

MappingsGenerator (org.hl7.fhir.definitions.generators.specification.MappingsGenerator)6 File (java.io.File)2 FileOutputStream (java.io.FileOutputStream)2 ArrayList (java.util.ArrayList)2 HashMap (java.util.HashMap)2 LinkedHashMap (java.util.LinkedHashMap)2 DictHTMLGenerator (org.hl7.fhir.definitions.generators.specification.DictHTMLGenerator)2 SvgGenerator (org.hl7.fhir.definitions.generators.specification.SvgGenerator)2 TerminologyNotesGenerator (org.hl7.fhir.definitions.generators.specification.TerminologyNotesGenerator)2 ElementDefn (org.hl7.fhir.definitions.model.ElementDefn)2 CSFile (org.hl7.fhir.utilities.CSFile)2 CommaSeparatedStringBuilder (org.hl7.fhir.utilities.CommaSeparatedStringBuilder)2 IniFile (org.hl7.fhir.utilities.IniFile)2 TextFile (org.hl7.fhir.utilities.TextFile)2 Gson (com.google.gson.Gson)1 GsonBuilder (com.google.gson.GsonBuilder)1 JsonObject (com.google.gson.JsonObject)1 FileNotFoundException (java.io.FileNotFoundException)1 IOException (java.io.IOException)1 UnsupportedEncodingException (java.io.UnsupportedEncodingException)1