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();
}
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();
}
}
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();
}
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();
}
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"));
}
Aggregations