use of org.hl7.fhir.definitions.model.DefinedCode in project kindling by HL7.
the class Publisher method producePrimitiveTypeProfile.
private void producePrimitiveTypeProfile(DefinedCode type) throws Exception {
String fn = type.getCode().toLowerCase() + ".profile.xml";
StructureDefinition rp = type.getProfile();
FileOutputStream s = new FileOutputStream(page.getFolders().dstDir + fn);
new XmlParser().setOutputStyle(OutputStyle.PRETTY).compose(s, rp);
s.close();
s = new FileOutputStream(page.getFolders().dstDir + Utilities.changeFileExt(fn, ".canonical.xml"));
new XmlParser().setOutputStyle(OutputStyle.CANONICAL).compose(s, rp);
s.close();
s = new FileOutputStream(page.getFolders().dstDir + Utilities.changeFileExt(fn, ".json"));
new JsonParser().setOutputStyle(OutputStyle.PRETTY).compose(s, rp);
s.close();
s = new FileOutputStream(page.getFolders().dstDir + Utilities.changeFileExt(fn, ".canonical.json"));
new JsonParser().setOutputStyle(OutputStyle.CANONICAL).compose(s, rp);
s.close();
String shex = new ShExGenerator(page.getWorkerContext()).generate(HTMLLinkPolicy.NONE, rp);
TextFile.stringToFile(shex, Utilities.changeFileExt(page.getFolders().dstDir + fn, ".shex"));
Utilities.copyFile(new CSFile(page.getFolders().dstDir + fn), new CSFile(Utilities.path(page.getFolders().dstDir, "examples", fn)));
addToResourceFeed(rp, page.getTypeBundle(), (fn));
// saveAsPureHtml(rp, new FileOutputStream(page.getFolders().dstDir+ "html"
// + File.separator + "datatypes.html"));
cloneToXhtml(type.getCode().toLowerCase() + ".profile", "StructureDefinition for " + type.getCode(), false, "profile-instance:type:" + type.getCode(), "Type", null, wg("mnm"));
jsonToXhtml(type.getCode().toLowerCase() + ".profile", "StructureDefinition for " + type.getCode(), resource2Json(rp), "profile-instance:type:" + type.getCode(), "Type", null, wg("mnm"));
ttlToXhtml(type.getCode().toLowerCase() + ".profile", "StructureDefinition for " + type.getCode(), resource2Ttl(rp), "profile-instance:type:" + type.getCode(), "Type", null, wg("mnm"));
shexToXhtml(type.getCode().toLowerCase(), "ShEx statement for " + type.getCode(), shex, "profile-instance:type:" + type.getCode(), "Type", null, wg("mnm"));
}
use of org.hl7.fhir.definitions.model.DefinedCode in project kindling by HL7.
the class Publisher method processProfiles.
@SuppressWarnings("unchecked")
private void processProfiles() throws Exception {
page.log(" ...process profiles (base)", LogMessageType.Process);
// first, for each type and resource, we build it's master profile
for (DefinedCode t : page.getDefinitions().getPrimitives().values()) {
if (t instanceof PrimitiveType)
genPrimitiveTypeProfile((PrimitiveType) t);
else
genPrimitiveTypeProfile((DefinedStringPattern) t);
}
genXhtmlProfile();
for (TypeDefn t : page.getDefinitions().getTypes().values()) genTypeProfile(t);
for (TypeDefn t : page.getDefinitions().getInfrastructure().values()) genTypeProfile(t);
page.log(" ...process profiles (resources)", LogMessageType.Process);
for (ResourceDefn r : page.getDefinitions().getBaseResources().values()) {
r.setConformancePack(makeConformancePack(r));
r.setProfile(new ProfileGenerator(page.getDefinitions(), page.getWorkerContext(), page, page.getGenDate(), page.getVersion(), dataElements, fpUsages, page.getFolders().rootDir, page.getUml(), page.getRc()).generate(r.getConformancePack(), r, "core", false));
if (page.getProfiles().has(r.getProfile().getUrl()))
throw new Exception("Duplicate Profile URL " + r.getProfile().getUrl());
page.getProfiles().see(r.getProfile(), page.packageInfo());
ResourceTableGenerator rtg = new ResourceTableGenerator(page.getFolders().dstDir, page, null, true, page.getVersion());
r.getProfile().getText().setDiv(new XhtmlNode(NodeType.Element, "div"));
r.getProfile().getText().getDiv().getChildNodes().add(rtg.generate(r, "", false));
}
for (String rn : page.getDefinitions().sortedResourceNames()) {
ResourceDefn r = page.getDefinitions().getResourceByName(rn);
r.setConformancePack(makeConformancePack(r));
r.setProfile(new ProfileGenerator(page.getDefinitions(), page.getWorkerContext(), page, page.getGenDate(), page.getVersion(), dataElements, fpUsages, page.getFolders().rootDir, page.getUml(), page.getRc()).generate(r.getConformancePack(), r, "core", false));
if (page.getProfiles().has(r.getProfile().getUrl()))
throw new Exception("Duplicate Profile URL " + r.getProfile().getUrl());
page.getProfiles().see(r.getProfile(), page.packageInfo());
ResourceTableGenerator rtg = new ResourceTableGenerator(page.getFolders().dstDir, page, null, true, page.getVersion());
r.getProfile().getText().setDiv(new XhtmlNode(NodeType.Element, "div"));
r.getProfile().getText().getDiv().getChildNodes().add(rtg.generate(r, "", false));
}
for (ResourceDefn r : page.getDefinitions().getResourceTemplates().values()) {
r.setConformancePack(makeConformancePack(r));
r.setProfile(new ProfileGenerator(page.getDefinitions(), page.getWorkerContext(), page, page.getGenDate(), page.getVersion(), dataElements, fpUsages, page.getFolders().rootDir, page.getUml(), page.getRc()).generate(r.getConformancePack(), r, "core", true));
ResourceTableGenerator rtg = new ResourceTableGenerator(page.getFolders().dstDir, page, null, true, page.getVersion());
r.getProfile().getText().setDiv(new XhtmlNode(NodeType.Element, "div"));
r.getProfile().getText().getDiv().getChildNodes().add(rtg.generate(r, "", true));
if (page.getProfiles().has(r.getProfile().getUrl()))
throw new Exception("Duplicate Profile URL " + r.getProfile().getUrl());
page.getProfiles().see(r.getProfile(), page.packageInfo());
}
for (ProfiledType pt : page.getDefinitions().getConstraints().values()) {
genProfiledTypeProfile(pt);
}
page.log(" ...process profiles (extensions)", LogMessageType.Process);
for (StructureDefinition ex : page.getWorkerContext().getExtensionDefinitions()) processExtension(ex);
for (ResourceDefn r : page.getDefinitions().getResources().values()) {
// boolean logged = false;
for (Profile ap : r.getConformancePackages()) {
// logged = true;
for (ConstraintStructure p : ap.getProfiles()) processProfile(ap, p, ap.getId(), r);
}
}
page.log(" ...process profiles (packs)", LogMessageType.Process);
// we have profiles scoped by resources, and stand alone profiles
for (Profile ap : page.getDefinitions().getPackList()) {
// page.log(" ... pack "+ap.getId(), LogMessageType.Process);
for (ConstraintStructure p : ap.getProfiles()) processProfile(ap, p, ap.getId(), null);
}
page.log(" ...process logical models", LogMessageType.Process);
for (ImplementationGuideDefn ig : page.getDefinitions().getSortedIgs()) {
for (LogicalModel lm : ig.getLogicalModels()) {
page.log(" ...process logical model " + lm.getId(), LogMessageType.Process);
if (lm.getDefinition() == null)
lm.setDefinition(new ProfileGenerator(page.getDefinitions(), page.getWorkerContext(), page, page.getGenDate(), page.getVersion(), dataElements, fpUsages, page.getFolders().rootDir, page.getUml(), page.getRc()).generateLogicalModel(ig, lm.getResource()));
}
}
// now, validate the profiles
for (Profile ap : page.getDefinitions().getPackList()) for (ConstraintStructure p : ap.getProfiles()) validateProfile(p);
for (ResourceDefn r : page.getDefinitions().getResources().values()) for (Profile ap : r.getConformancePackages()) for (ConstraintStructure p : ap.getProfiles()) validateProfile(p);
page.log(" ...Check FHIR Path Expressions", LogMessageType.Process);
StringBuilder b = new StringBuilder();
FHIRPathEngine fp = new FHIRPathEngine(page.getWorkerContext());
fp.setHostServices(page.getExpressionResolver());
for (FHIRPathUsage p : fpUsages) {
checkExpression(b, fp, p);
}
TextFile.stringToFile(b.toString(), Utilities.path(page.getFolders().dstDir, "fhirpaths.txt"));
checkAllOk();
}
use of org.hl7.fhir.definitions.model.DefinedCode in project kindling by HL7.
the class PageProcessor method produceStructureDefinitionExamples.
private String produceStructureDefinitionExamples(ResourceDefn resource) throws Exception {
StringBuilder s = new StringBuilder();
s.append("<div id=\"tabs\">\r\n");
s.append("<ul>\r\n");
s.append(" <li><a href=\"#tabs-1\">Base Types</a></li>\r\n");
s.append(" <li><a href=\"#tabs-2\">Resources</a></li>\r\n");
s.append(" <li><a href=\"#tabs-3\">Constraints</a></li>\r\n");
s.append(" <li><a href=\"#tabs-4\">Extensions</a></li>\r\n");
s.append(" <li><a href=\"#tabs-5\">Examples</a></li>\r\n");
s.append("</ul>\r\n");
s.append("<div id=\"tabs-1\">\r\n");
// base types
s.append("<table class=\"list\">\r\n");
genStructureExampleCategory(s, "Abstract Types", "3");
genStructureExample(s, definitions.getElementLink(), "element.profile", "element", "Element");
genStructureExample(s, definitions.getBackboneLink(), "backboneelement.profile", "backboneelement", "BackBoneElement");
genStructureExample(s, "resource.html", "resource.profile", "resource", "Resource");
genStructureExample(s, "domainresource.html", "domainresource.profile", "domainresource", "DomainResource");
genStructureExampleCategory(s, "Primitive Types", "3");
List<String> names = new ArrayList<String>();
names.addAll(definitions.getPrimitives().keySet());
Collections.sort(names);
for (String n : names) {
DefinedCode dc = definitions.getPrimitives().get(n);
genStructureExample(s, "datatypes.html#" + dc.getCode(), dc.getCode().toLowerCase() + ".profile", dc.getCode().toLowerCase(), dc.getCode());
}
genStructureExampleCategory(s, "Data Types", "3");
names.clear();
names.addAll(definitions.getTypes().keySet());
names.addAll(definitions.getInfrastructure().keySet());
Collections.sort(names);
for (String n : names) {
org.hl7.fhir.definitions.model.TypeDefn t = definitions.getTypes().get(n);
if (t == null)
t = definitions.getInfrastructure().get(n);
genStructureExample(s, getLinkFor("", t.getName()), t.getName().toLowerCase() + ".profile", t.getName().toLowerCase(), t.getName());
}
s.append("</table>\r\n");
s.append("</div>\r\n");
s.append("<div id=\"tabs-2\">\r\n");
s.append("<table class=\"list\">\r\n");
genStructureExampleCategory(s, "Resources", "3");
for (String n : definitions.sortedResourceNames()) {
ResourceDefn r = definitions.getResources().get(n);
genStructureExample(s, r.getName().toLowerCase() + ".html", r.getName().toLowerCase() + ".profile", r.getName().toLowerCase(), r.getName());
}
s.append("</table>\r\n");
s.append("</div>\r\n");
s.append("<div id=\"tabs-3\">\r\n");
s.append("<table class=\"list\">\r\n");
Map<String, ConstraintStructure> constraints = new HashMap<String, ConstraintStructure>();
for (Profile pp : definitions.getPackList()) {
for (ConstraintStructure p : pp.getProfiles()) constraints.put(p.getId(), p);
}
for (String rn : definitions.sortedResourceNames()) for (Profile ap : definitions.getResourceByName(rn).getConformancePackages()) for (ConstraintStructure p : ap.getProfiles()) constraints.put(p.getId(), p);
names.clear();
names.addAll(constraints.keySet());
Collections.sort(names);
for (ImplementationGuideDefn ig : definitions.getSortedIgs()) {
boolean started = false;
for (String n : names) {
ConstraintStructure p = constraints.get(n);
if (ig == p.getUsage()) {
if (!started) {
started = true;
genStructureExampleCategory(s, ig.getName(), "3");
}
String prefix = ig.isCore() ? "" : ig.getCode() + "/";
genStructureExample(s, prefix + p.getId().toLowerCase() + ".html", prefix + p.getId().toLowerCase() + ".profile", p.getId().toLowerCase(), p.getTitle());
}
}
}
s.append("</table>\r\n");
s.append("</div>\r\n");
s.append("<div id=\"tabs-4\">\r\n");
s.append("<table class=\"list\">\r\n");
names.clear();
for (StructureDefinition sd : workerContext.getExtensionDefinitions()) names.add(sd.getUrl());
Collections.sort(names);
for (ImplementationGuideDefn ig : definitions.getSortedIgs()) {
boolean started = false;
for (String n : names) {
StructureDefinition ed = workerContext.fetchResource(StructureDefinition.class, n);
if (ig.getCode().equals(ToolResourceUtilities.getUsage(ed))) {
if (!started) {
started = true;
genStructureExampleCategory(s, ig.getName(), "3");
}
String prefix = ig.isCore() ? "" : ig.getCode() + "/";
genStructureExample(s, prefix + "extension-" + ed.getId().toLowerCase() + ".html", prefix + "extension-" + ed.getId().toLowerCase(), ed.getId().toLowerCase(), ed.getUrl().startsWith("http://hl7.org/fhir/StructureDefinition/") ? ed.getUrl().substring(40) : ed.getUrl(), ed.getName());
}
}
}
s.append("</table>\r\n");
s.append("</div>\r\n");
s.append("<div id=\"tabs-5\">\r\n");
s.append("<table class=\"list\">\r\n");
for (Example e : resource.getExamples()) {
if (e.isRegistered() && Utilities.noString(e.getIg()))
produceExampleListEntry(s, e, null, null);
}
for (Profile p : resource.getConformancePackages()) {
for (Example e : p.getExamples()) {
produceExampleListEntry(s, e, p, null);
}
}
for (Profile p : definitions.getPackList()) {
ImplementationGuideDefn ig = definitions.getIgs().get(p.getCategory());
for (Example e : p.getExamples()) {
String rn = e.getResourceName();
if (Utilities.noString(rn))
rn = e.getXml().getDocumentElement().getNodeName();
if (rn.equals(resource.getName()))
produceExampleListEntry(s, e, p, ig);
}
}
for (ImplementationGuideDefn ig : definitions.getSortedIgs()) {
if (ig.getIg() != null) {
for (ImplementationGuideDefinitionResourceComponent res : ig.getIg().getDefinition().getResource()) {
Example e = (Example) res.getUserData(ToolResourceUtilities.NAME_RES_EXAMPLE);
if (res.hasExample() && e != null && e.getResourceName().equals(resource.getName()))
produceExampleListEntry(s, res, ig);
}
}
}
s.append("</table>\r\n");
s.append("</div>\r\n");
s.append("</div>\r\n");
s.append("\r\n");
s.append("<script src=\"external/jquery/jquery.js\"> </script>\r\n");
s.append("<script src=\"jquery-ui.min.js\"> </script>\r\n");
s.append("<script>\r\n");
s.append("try {\r\n");
s.append(" var currentTabIndex = sessionStorage.getItem('fhir-sdelist-tab-index');\r\n");
s.append("}\r\n");
s.append("catch(exception){\r\n");
s.append("}\r\n");
s.append("\r\n");
s.append("if (!currentTabIndex)\r\n");
s.append(" currentTabIndex = '0';\r\n");
s.append(" \r\n");
s.append("$( '#tabs' ).tabs({\r\n");
s.append(" active: currentTabIndex,\r\n");
s.append(" activate: function( event, ui ) {\r\n");
s.append(" var active = $('.selector').tabs('option', 'active');\r\n");
s.append(" currentTabIndex = ui.newTab.index();\r\n");
s.append(" document.activeElement.blur();\r\n");
s.append(" try {\r\n");
s.append(" sessionStorage.setItem('fhir-sdelist-tab-index', currentTabIndex);\r\n");
s.append(" }\r\n");
s.append(" catch(exception){\r\n");
s.append(" }\r\n");
s.append(" }\r\n");
s.append(" });\r\n");
s.append("</script>\r\n");
s.append("\r\n");
return s.toString();
}
use of org.hl7.fhir.definitions.model.DefinedCode in project kindling by HL7.
the class PageProcessor method genResImplList.
private String genResImplList() {
StringBuilder html = new StringBuilder();
List<String> res = new ArrayList<String>();
for (ResourceDefn n : definitions.getResources().values()) res.add(n.getName());
for (DefinedCode c : definitions.getKnownResources().values()) {
if (res.contains(c.getComment()))
html.append(" <tr><td>" + c.getCode() + "</td><td></td><td><a href=\"" + c.getComment() + ".xsd\">Schema</a></td><td><a href=\"" + c.getComment() + ".xml\">Example</a></td><td><a href=\"" + c.getComment() + ".json\">JSON Example</a></td>\r\n");
}
return html.toString();
}
use of org.hl7.fhir.definitions.model.DefinedCode 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();
}
}
Aggregations