use of org.hl7.fhir.definitions.model.ImplementationGuideDefn in project kindling by HL7.
the class PageProcessor method igRegistryList.
private String igRegistryList(String purpose, String type) throws Exception {
StringBuilder b = new StringBuilder();
boolean first = true;
for (ImplementationGuideDefn ig : definitions.getSortedIgs()) {
if (!ig.isCore()) {
boolean found = false;
if ("terminology".equals(purpose)) {
for (ValueSet vs : definitions.getValuesets().getList()) {
if (vs.getUserData(ToolResourceUtilities.NAME_RES_IG) == ig)
found = true;
}
for (ConceptMap cm : conceptMaps.getList()) {
if (cm.getUserData(ToolResourceUtilities.NAME_RES_IG) == ig)
found = true;
}
} else if ("extension".equals(purpose)) {
for (StructureDefinition ex : workerContext.getExtensionDefinitions()) {
if (ig.getCode().equals(ToolResourceUtilities.getUsage(ex))) {
found = true;
}
}
} else if ("profile".equals(purpose)) {
for (StructureDefinition ex : workerContext.getProfiles()) {
if (ig.getCode().equals(ToolResourceUtilities.getUsage(ex))) {
found = true;
}
}
} else
throw new Exception("Purpose " + purpose + " not supported yet");
ImplementationGuideDefinitionPageComponent p = ig.getRegistryPage(type);
if (found && p != null) {
if (first)
first = false;
else
b.append(" | ");
b.append("<a href=\"");
b.append(ig.getCode());
b.append("/" + p.getNameUrlType().getValue() + "#" + purpose + "\">");
b.append(ig.getBrief());
b.append("</a>");
}
}
}
return b.toString();
}
use of org.hl7.fhir.definitions.model.ImplementationGuideDefn in project kindling by HL7.
the class ExampleAdorner method getState.
@Override
public XhtmlGeneratorAdornerState getState(XhtmlGenerator ref, XhtmlGeneratorAdornerState state, Element node) throws Exception {
if (state == null) {
if (node == null)
return new ExampleAdornerState(State.Unknown, "", null, "", "");
else if (definitions.hasResource(node.getLocalName()))
return new ExampleAdornerState(State.Element, node.getLocalName(), definitions.getResourceByName(node.getLocalName()).getRoot(), "", "");
else
return new ExampleAdornerState(State.Unknown, "", null, "", "");
} else {
ExampleAdornerState s = (ExampleAdornerState) state;
if (s.getState() == State.Element) {
if (s.definition == null) {
System.out.println("??");
}
if (// account for extra element
s.definition != null && "Resource".equals(s.definition.typeCode()) && (s.getPath().endsWith(".entry.resource") || s.getPath().endsWith(".contained")) && definitions.isResource(node.getNodeName()))
return new ExampleAdornerState(State.Element, s.getPath(), definitions.getResourceByName(node.getNodeName()).getRoot(), "", "");
String p = s.getPath() + "." + node.getNodeName();
ElementDefn e = s.getDefinition().getElementByName(node.getLocalName(), true, definitions, "adorn example", false);
if (e == null && definitions.hasElementDefn(s.getDefinition().typeCodeNoParams())) {
// well, we see if it's inherited...
ElementDefn t = definitions.getElementDefn(s.getDefinition().typeCodeNoParams());
while (t != null && e == null) {
e = t.getElementByName(node.getLocalName(), true, definitions, "adorn example", false);
if (e != null)
p = t.getName() + "." + e.getName();
else if (definitions.hasElementDefn(t.typeCodeNoParams()))
t = definitions.getElementDefn(t.typeCodeNoParams());
else
t = null;
}
} else if (e != null)
p = s.getPath() + "." + e.getName();
if (e == null)
return new ExampleAdornerState(State.Unknown, s.getPath(), null, "", "");
if (!e.isBaseResourceElement() && e.typeCode().contains("Reference") && !e.typeCode().contains("CodeableReference"))
return new ExampleAdornerState(State.Reference, p, e, "", "");
else if (!e.isBaseResourceElement() && e.typeCode().contains("canonical"))
return new ExampleAdornerState(State.Reference, p, e, "", "");
else if (!e.isBaseResourceElement() && e.typeCode().equals("uri"))
return new ExampleAdornerState(State.Reference, p, e, "", "");
else
return new ExampleAdornerState(State.Element, p, e, "", "");
} else if (s.getState() == State.Reference) {
if (node.getLocalName().equals("reference")) {
String type = extractType(node.getAttribute("value"));
String id = extractId(node.getAttribute("value"), type);
if (id == null)
return new ExampleAdornerState(State.Element, s.getPath() + ".reference", null, "", "");
ResourceDefn r = definitions.getResourceByName(type);
if (r == null)
throw new Exception("unable to find type " + type);
for (Example e : r.getExamples()) {
if (id.equals(e.getId()))
if (Utilities.noString(e.getIg())) {
return new ExampleAdornerState(State.Reference, s.getPath() + ".reference", s.getDefinition(), "<a href=\"" + prefix + e.getTitle() + ".xml.html\">", "</a>");
} else {
ImplementationGuideDefn ig = definitions.getIgs().get(e.getIg());
return new ExampleAdornerState(State.Reference, s.getPath() + ".reference", s.getDefinition(), "<a href=\"" + prefix + ig.getPrefix() + e.getTitle() + ".xml.html\">", "</a>");
}
if (e.getXml() != null && e.getXml().getDocumentElement().getLocalName().equals("feed")) {
List<Element> entries = new ArrayList<Element>();
XMLUtil.getNamedChildren(e.getXml().getDocumentElement(), "entry", entries);
String url = "http://hl7.org/fhir/" + type + "/" + id;
for (Element c : entries) {
String t = XMLUtil.getNamedChild(c, "id").getAttribute("value");
if (url.equals(t))
return new ExampleAdornerState(State.Reference, s.getPath() + ".reference", s.getDefinition(), "<a href=\"" + prefix + e.getTitle() + ".xml.html#" + id + "\">", "</a>");
}
}
}
return new ExampleAdornerState(State.Reference, s.getPath() + ".reference", s.getDefinition(), "<font color=\"red\">", "</font>");
} else
return new ExampleAdornerState(State.Reference, s.getPath(), s.getDefinition(), "", "");
} else
// else
return new ExampleAdornerState(State.Unknown, s.getPath(), null, "", "");
}
}
use of org.hl7.fhir.definitions.model.ImplementationGuideDefn in project kindling by HL7.
the class PageProcessor method produceProfiles.
private String produceProfiles(ResourceDefn resource) {
int count = 0;
Map<String, CSPair> map = new HashMap<String, CSPair>();
for (Profile ap : resource.getConformancePackages()) {
for (ConstraintStructure cs : ap.getProfiles()) {
if (coversResource(cs, resource.getName()))
map.put(cs.getTitle(), new CSPair(ap, cs));
}
}
for (Profile ap : definitions.getPackList()) {
for (ConstraintStructure cs : ap.getProfiles()) {
if (coversResource(cs, resource.getName()))
map.put(cs.getTitle(), new CSPair(ap, cs));
}
}
StringBuilder b = new StringBuilder();
for (String s : sorted(map.keySet())) {
CSPair cs = map.get(s);
ImplementationGuideDefn ig = definitions.getIgs().get(cs.p.getCategory());
if (ig == null) {
throw new FHIRException("The profile " + cs.cs.getId() + " is not registered in an IG");
}
count++;
b.append(" <tr>\r\n");
String ref = (ig.isCore() ? "" : ig.getCode() + File.separator) + cs.cs.getId() + ".html";
b.append(" <td><a href=\"").append(ref).append("\">").append(Utilities.escapeXml(cs.cs.getTitle())).append("</a></td>\r\n");
b.append(" <td>").append(Utilities.escapeXml(cs.p.getDescription())).append("</td>\r\n");
ref = (ig.isCore() ? "" : ig.getCode() + File.separator) + cs.p.getId().toLowerCase() + ".html";
b.append(" <td><a href=\"").append(ref).append("\">").append(Utilities.escapeXml(cs.p.getTitle())).append("</a></td>\r\n");
b.append(" </tr>\r\n");
}
if (count == 0)
return "<p>No Profiles defined for this resource</p>";
return "<table class=\"list\">\r\n" + " <tr><td><b>Profile</b></td><td><b>Description</b></td><td><b>Context</b></td></tr>\r\n" + b.toString() + "</table>\r\n";
}
use of org.hl7.fhir.definitions.model.ImplementationGuideDefn in project kindling by HL7.
the class PageProcessor method processExtensionIncludes.
public String processExtensionIncludes(String filename, StructureDefinition ed, String xml, String json, String ttl, String tx, String src, String pagePath, ImplementationGuideDefn ig) throws Exception {
String workingTitle = null;
int level = ig.isCore() ? 0 : 1;
while (src.contains("<%") || src.contains("[%")) {
int i1 = src.indexOf("<%");
int i2 = src.indexOf("%>");
if (i1 == -1) {
i1 = src.indexOf("[%");
i2 = src.indexOf("%]");
}
String s1 = src.substring(0, i1);
String s2 = src.substring(i1 + 2, i2).trim();
String s3 = src.substring(i2 + 2);
String[] com = s2.split(" ");
if (com[0].equals("file")) {
if (new File(folders.templateDir + com[1] + ".html").exists()) {
src = s1 + TextFile.fileToString(folders.templateDir + com[1] + ".html") + s3;
} else {
src = s1 + TextFile.fileToString(folders.srcDir + com[1] + ".html") + s3;
}
} else if (com[0].equals("extDefnHeader"))
src = s1 + extDefnHeader(filename, com.length > 1 ? com[1] : null) + s3;
else if (com[0].equals("extension-table"))
src = s1 + generateExtensionTable(ed, filename, com[1], genlevel(level)) + s3;
else if (com[0].equals("settitle")) {
workingTitle = s2.substring(9).replace("{", "<%").replace("}", "%>");
src = s1 + s3;
} else if (com.length != 1)
throw new Exception("Instruction <%" + s2 + "%> not understood parsing resource " + filename);
else if (com[0].equals("pageheader"))
src = s1 + pageHeader(ed.getName()) + s3;
else if (com[0].equals("newheader"))
src = s1 + TextFile.fileToString(folders.srcDir + "newheader.html") + s3;
else if (com[0].equals("newheader1"))
src = s1 + TextFile.fileToString(folders.srcDir + "newheader1.html") + s3;
else if (com[0].equals("footer"))
src = s1 + TextFile.fileToString(folders.srcDir + "footer.html") + s3;
else if (com[0].equals("newfooter"))
src = s1 + TextFile.fileToString(folders.srcDir + "newfooter.html") + s3;
else if (com[0].equals("footer1"))
src = s1 + TextFile.fileToString(folders.srcDir + "footer1.html") + s3;
else if (com[0].equals("footer2"))
src = s1 + TextFile.fileToString(folders.srcDir + "footer2.html") + s3;
else if (com[0].equals("footer3"))
src = s1 + TextFile.fileToString(folders.srcDir + "footer3.html") + s3;
else if (com[0].equals("title"))
src = s1 + (workingTitle == null ? Utilities.escapeXml(ed.getName()) : workingTitle) + s3;
else if (com[0].equals("xtitle"))
src = s1 + "Extension: " + Utilities.escapeXml(ed.getName()) + s3;
else if (com[0].equals("filetitle"))
src = s1 + (filename.contains(".") ? filename.substring(0, filename.lastIndexOf(".")) : filename) + s3;
else if (com[0].equals("name"))
src = s1 + filename + s3;
else if (com[0].equals("date")) {
if (ed.hasDate())
src = s1 + ed.getDateElement().toHumanDisplay() + s3;
else
src = s1 + "[no date]" + s3;
} else if (com[0].equals("version"))
src = s1 + ini.getStringProperty("FHIR", "version") + s3;
else if (com[0].equals("gendate"))
src = s1 + Config.DATE_FORMAT().format(new Date()) + s3;
else if (com[0].equals("definition"))
src = s1 + processor.process(Utilities.escapeXml(ed.getDescription()), "Definition on " + ed.getId()) + s3;
else if (com[0].equals("ext-comments")) {
if (ed.getDifferential().getElementFirstRep().hasComment())
src = s1 + "<p><b>Comment</b>: " + processor.process(Utilities.escapeXml(ed.getDifferential().getElementFirstRep().getComment()), "Definition on " + ed.getId()) + "</p>" + s3;
else
src = s1 + s3;
} else if (com[0].equals("status"))
src = s1 + (ed.getStatus() == null ? "??" : ed.getStatus().toCode()) + s3;
else if (com[0].equals("author"))
src = s1 + Utilities.escapeXml(ed.getPublisher()) + s3;
else if (com[0].equals("xml"))
src = s1 + xml + s3;
else if (com[0].equals("json"))
src = s1 + json + s3;
else if (com[0].equals("ttl"))
src = s1 + ttl + s3;
else if (com[0].equals("tx"))
src = s1 + tx + s3;
else if (com[0].equals("inv"))
src = s1 + genExtensionConstraints(ed) + s3;
else if (com[0].equals("plural"))
src = s1 + Utilities.pluralizeMe(filename) + s3;
else if (com[0].equals("notes"))
src = s1 + "todo" + /*Utilities.fileToString(folders.srcDir + filename+File.separatorChar+filename+".html")*/
s3;
else if (com[0].equals("dictionary"))
src = s1 + definitionsProfile(ed, genlevel(level)) + s3;
else if (com[0].equals("breadcrumb"))
src = s1 + breadCrumbManager.make(filename) + s3;
else if (com[0].equals("navlist"))
src = s1 + breadCrumbManager.navlist(filename, genlevel(level)) + s3;
else if (com[0].equals("breadcrumblist")) {
String crumbTitle = ed.getUrl();
src = s1 + ((ig == null || ig.isCore()) ? breadCrumbManager.makelist(filename, "extension:" + ed.getName(), genlevel(level), crumbTitle) : ig.makeList(filename, "extension:" + ed.getName(), genlevel(level), crumbTitle)) + s3;
} else if (com[0].equals("year"))
src = s1 + new SimpleDateFormat("yyyy").format(new Date()) + s3;
else if (com[0].equals("buildId"))
src = s1 + buildId + s3;
else if (com[0].equals("level"))
src = s1 + genlevel(level) + s3;
else if (com[0].equals("pub-type"))
src = s1 + publicationType + s3;
else if (com[0].equals("pub-notice"))
src = s1 + publicationNotice + s3;
else if (com[0].equals("pagepath"))
src = s1 + pagePath + s3;
else if (com[0].equals("extensionurl"))
src = s1 + ed.getUrl() + s3;
else if (com[0].equals("rellink")) {
if (!pagePath.contains(".html"))
throw new Error("Invalid link: " + pagePath + " at " + workingTitle);
src = s1 + Utilities.URLEncode(pagePath) + s3;
} else if (com[0].equals("baseURL"))
src = s1 + Utilities.URLEncode(baseURL) + s3;
else if (com[0].equals("baseURLn"))
src = s1 + Utilities.appendForwardSlash(baseURL) + s3;
else if (com[0].equals("mappings"))
src = s1 + mappingsExtension(ed) + s3;
else if (com[0].equals("definitions"))
src = s1 + definitionsExtension(ed, "") + s3;
else if (com[0].equals("pubdetails")) {
src = s1 + "Extension maintained by: " + Utilities.escapeXml(ed.getPublisher()) + s3;
} else if (com[0].equals("extref"))
src = s1 + "" + s3;
else if (com[0].equals("context-info"))
src = s1 + describeExtensionContext(ed) + s3;
else if (com[0].equals("ext-name"))
src = s1 + Utilities.escapeXml(ed.getName()) + s3;
else if (com[0].equals("search-footer"))
src = s1 + searchFooter(level) + s3;
else if (com[0].equals("search-header"))
src = s1 + searchHeader(level) + s3;
else if (com[0].startsWith("!"))
src = s1 + s3;
else if (com[0].equals("wg")) {
String wg = ToolingExtensions.readStringExtension(ed, ToolingExtensions.EXT_WORKGROUP);
src = s1 + (wg == null || !definitions.getWorkgroups().containsKey(wg) ? "(No assigned work group) (" + wg + ") (3)" : "<a _target=\"blank\" href=\"" + definitions.getWorkgroups().get(wg).getUrl() + "\">" + definitions.getWorkgroups().get(wg).getName() + "</a> Work Group") + s3;
} else if (com[0].equals("fmm-style")) {
String fmm = ed == null ? "N/A" : ToolingExtensions.readStringExtension(ed, ToolingExtensions.EXT_FMM_LEVEL);
StandardsStatus ss = ToolingExtensions.getStandardsStatus(ed);
src = s1 + fmmBarColorStyle(ss, fmm) + s3;
} else if (com[0].equals("fmm")) {
String fmm = ToolingExtensions.readStringExtension(ed, ToolingExtensions.EXT_FMM_LEVEL);
StandardsStatus ss = ToolingExtensions.getStandardsStatus(ed);
if (StandardsStatus.EXTERNAL == ss)
src = s1 + getFmmFromlevel(genlevel(level), "N/A") + s3;
else if (StandardsStatus.NORMATIVE == ss)
src = s1 + getFmmFromlevel(genlevel(level), "<a href=\"" + genlevel(level) + "versions.html#std-process\">N</a>") + s3;
else
src = s1 + getFmmFromlevel(genlevel(level), fmm) + s3;
} else if (com[0].equals("sstatus")) {
StandardsStatus ss = ToolingExtensions.getStandardsStatus(ed);
if (ss == null)
ss = StandardsStatus.INFORMATIVE;
src = s1 + "<a href=\"" + genlevel(level) + "versions.html#std-process\">Informative</a>" + s3;
} else if (com[0].equals("profile-context")) {
src = s1 + getProfileContext(ed, genlevel(level)) + s3;
} else if (com[0].equals("res-type-count")) {
src = s1 + definitions.getResources().size() + s3;
} else if (macros.containsKey(com[0])) {
src = s1 + macros.get(com[0]) + s3;
} else
throw new Exception("Instruction <%" + s2 + "%> not understood parsing resource " + filename);
}
return src;
}
use of org.hl7.fhir.definitions.model.ImplementationGuideDefn in project kindling by HL7.
the class PageProcessor method jsonToXhtml.
public void jsonToXhtml(String src, String dst, String name, String description, int level, String json, String pageType, String crumbTitle, ImplementationGuideDefn ig, ResourceDefn rd, WorkGroup wg) throws Exception {
String n = new File(dst).getName();
n = n.substring(0, n.length() - 10);
json = "<div class=\"example\">\r\n<p>" + Utilities.escapeXml(description) + "</p>\r\n<pre class=\"json\">\r\n" + Utilities.escapeXml(json) + "\r\n</pre>\r\n</div>\r\n";
String html = ("<%setlevel " + Integer.toString(level) + "%>" + TextFile.fileToString(folders.srcDir + "template-example-json.html")).replace("<%example%>", json);
html = processPageIncludes(n + ".json.html", html, pageType, null, null, null, crumbTitle, ig, rd, wg);
TextFile.stringToFile(html, dst);
htmlchecker.registerExternal(dst);
}
Aggregations