use of org.hl7.fhir.definitions.model.ImplementationGuideDefn in project kindling by HL7.
the class ProfileGenerator method generate.
public StructureDefinition generate(Profile pack, ConstraintStructure profile, ResourceDefn resource, String id, String html, ImplementationGuideDefn usage, List<ValidationMessage> issues, ResourceDefn baseResource) throws Exception {
if (profile.getResource() != null)
return profile.getResource();
StructureDefinition p = new StructureDefinition();
p.setId(FormatUtilities.makeId(id));
p.setUrl("http://hl7.org/fhir/StructureDefinition/" + id);
if (usage != null && !usage.isCore()) {
if (!id.startsWith(usage.getCode() + "-"))
throw new Exception("Error: " + id + " must start with " + usage.getCode() + "-");
}
if (!resource.getRoot().getTypes().isEmpty() && (resource.getRoot().getTypes().get(0).getProfile() != null))
p.setBaseDefinition(resource.getRoot().getTypes().get(0).getProfile());
else
p.setBaseDefinition("http://hl7.org/fhir/StructureDefinition/" + resource.getName());
if (definitions.hasType(resource.getName()))
p.setKind(StructureDefinitionKind.COMPLEXTYPE);
else
p.setKind(StructureDefinitionKind.RESOURCE);
p.setType(resource.getName());
p.setDerivation(TypeDerivationRule.CONSTRAINT);
p.setAbstract(false);
p.setUserData("filename", id);
p.setUserData("path", ((usage == null || usage.isCore()) ? "" : usage.getCode() + File.separator) + id + ".html");
p.setTitle(pack.metadata("display"));
p.setFhirVersion(version);
p.setVersion(version.toCode());
if (pack.hasMetadata("summary-" + profile.getTitle()))
ToolingExtensions.addMarkdownExtension(p, "http://hl7.org/fhir/StructureDefinition/structuredefinition-summary", pack.metadata("summary-" + profile.getTitle()));
ToolResourceUtilities.updateUsage(p, usage.getCode());
p.setName(pack.metadata("name"));
p.setPublisher(pack.metadata("author.name"));
if (pack.hasMetadata("author.reference"))
p.addContact().getTelecom().add(Factory.newContactPoint(ContactPointSystem.URL, pack.metadata("author.reference")));
// <code> opt Zero+ Coding assist with indexing and finding</code>
p.setDescription(resource.getRoot().getShortDefn());
if (!p.hasDescriptionElement() && pack.hasMetadata("description"))
p.setDescription(preProcessMarkdown(pack.metadata("description"), "pack.description"));
p.setPurpose(resource.getRoot().getRequirements());
if (!p.hasPurpose() && pack.hasMetadata("requirements"))
p.setPurpose(pack.metadata("requirements"));
p.setExperimental(Utilities.existsInList(pack.metadata("Experimental"), "y", "Y", "true", "TRUE", "1"));
if (pack.hasMetadata("date"))
p.setDateElement(Factory.newDateTime(pack.metadata("date").substring(0, 10)));
else
p.setDate(genDate.getTime());
if (pack.hasMetadata("fmm-level"))
ToolingExtensions.addIntegerExtension(p, ToolingExtensions.EXT_FMM_LEVEL, Integer.parseInt(pack.getFmmLevel()));
else if (pack.hasMetadata("fmm"))
ToolingExtensions.addIntegerExtension(p, ToolingExtensions.EXT_FMM_LEVEL, Integer.parseInt(pack.metadata("fmm")));
else if (!Utilities.noString(resource.getFmmLevel()))
ToolingExtensions.addIntegerExtension(p, ToolingExtensions.EXT_FMM_LEVEL, Integer.parseInt(resource.getFmmLevel()));
else if (baseResource != null && !Utilities.noString(baseResource.getFmmLevel()))
ToolingExtensions.addIntegerExtension(p, ToolingExtensions.EXT_FMM_LEVEL, Integer.parseInt(baseResource.getFmmLevel()));
if (pack.hasMetadata("workgroup"))
ToolingExtensions.setCodeExtension(p, ToolingExtensions.EXT_WORKGROUP, pack.getWg());
else if (resource.getWg() != null)
ToolingExtensions.setCodeExtension(p, ToolingExtensions.EXT_WORKGROUP, resource.getWg().getCode());
else if (baseResource != null && baseResource.getWg() != null)
ToolingExtensions.setCodeExtension(p, ToolingExtensions.EXT_WORKGROUP, baseResource.getWg().getCode());
if (pack.hasMetadata("Standards-Status"))
ToolingExtensions.setStandardsStatus(p, StandardsStatus.fromCode(pack.metadata("Standards-Status")), null);
else
ToolingExtensions.setStandardsStatus(p, resource.getStatus(), null);
if (pack.hasMetadata("status"))
p.setStatus(PublicationStatus.fromCode(pack.metadata("status")));
if (pack.getMetadata().containsKey("code"))
for (String s : pack.getMetadata().get("code")) if (!Utilities.noString(s))
p.getKeyword().add(Factory.makeCoding(s));
if (pack.hasMetadata("datadictionary"))
ToolingExtensions.setStringExtension(p, "http://hl7.org/fhir/StructureDefinition/datadictionary", pack.metadata("datadictionary"));
Set<String> containedSlices = new HashSet<String>();
p.setDifferential(new StructureDefinitionDifferentialComponent());
defineElement(pack, p, p.getDifferential().getElement(), resource.getRoot(), resource.getName(), containedSlices, new ArrayList<ProfileGenerator.SliceHandle>(), SnapShotMode.None, true, null, null, false);
List<String> names = new ArrayList<String>();
names.addAll(resource.getSearchParams().keySet());
Collections.sort(names);
for (String pn : names) {
pack.getSearchParameters().add(makeSearchParam(p, pack.getId() + "-" + resource.getName() + "-" + pn, resource.getName(), resource.getSearchParams().get(pn), resource));
}
StructureDefinition base = definitions.getSnapShotForBase(p.getBaseDefinition());
List<String> errors = new ArrayList<String>();
new ProfileUtilities(context, null, pkp).sortDifferential(base, p, p.getName(), errors, false);
for (String s : errors) issues.add(new ValidationMessage(Source.ProfileValidator, IssueType.STRUCTURE, -1, -1, p.getUrl(), s, IssueSeverity.WARNING));
reset();
// ok, c is the differential. now we make the snapshot
new ProfileUtilities(context, issues, pkp).generateSnapshot(base, p, "http://hl7.org/fhir/StructureDefinition/" + p.getType(), "http://hl7.org/fhir", p.getName());
reset();
p.getDifferential().getElement().get(0).getType().clear();
p.getSnapshot().getElement().get(0).getType().clear();
addElementConstraintToSnapshot(p);
XhtmlNode div = new XhtmlNode(NodeType.Element, "div");
div.addText("to do");
p.setText(new Narrative());
p.getText().setStatus(NarrativeStatus.GENERATED);
p.getText().setDiv(div);
new ProfileUtilities(context, issues, pkp).setIds(p, false);
checkHasTypes(p);
return p;
}
use of org.hl7.fhir.definitions.model.ImplementationGuideDefn in project kindling by HL7.
the class PageProcessor method loadXmlNotes.
private String loadXmlNotes(String name, String suffix, boolean checkHeaders, String definition, StructureDefinition sd, List<String> tabs, ImplementationGuideDefn ig, WorkGroup wg) throws Exception {
String filename;
if (definitions.hasLogicalModel(name)) {
LogicalModel lm = definitions.getLogicalModel(name);
filename = Utilities.changeFileExt(lm.getSource(), "-" + suffix + ".xml");
} else
filename = folders.srcDir + name + File.separatorChar + name + "-" + suffix + ".xml";
return loadXmlNotesFromFile(filename, checkHeaders, definition, null, tabs, ig, wg);
}
use of org.hl7.fhir.definitions.model.ImplementationGuideDefn in project kindling by HL7.
the class PageProcessor method produceRefExtensions.
private String produceRefExtensions(ResourceDefn resource) {
int count = 0;
Map<String, StructureDefinition> map = new HashMap<String, StructureDefinition>();
for (StructureDefinition sd : workerContext.getExtensionDefinitions()) {
boolean refers = false;
for (ElementDefinition ed : sd.getSnapshot().getElement()) {
for (TypeRefComponent tr : ed.getType()) {
for (UriType u : tr.getTargetProfile()) if (u.getValue().endsWith("/" + resource.getName()))
refers = true;
}
if (refers)
map.put(sd.getId(), sd);
}
}
StringBuilder b = new StringBuilder();
for (String s : sorted(map.keySet())) {
StructureDefinition cs = map.get(s);
count++;
b.append(" <tr>\r\n");
String ref = cs.getUserString("path");
b.append(" <td><a href=\"").append(ref).append("\">").append(Utilities.escapeXml(cs.getId())).append("</a></td>\r\n");
b.append(" <td>").append(Utilities.escapeXml(cs.getName())).append("</td>\r\n");
Profile ap = (Profile) cs.getUserData("profile");
if (ap == null)
b.append(" <td></td>\r\n");
else {
ImplementationGuideDefn ig = definitions.getIgs().get(ap.getCategory());
b.append(" <td>for <a href=\"" + ig.getPrefix() + ap.getId().toLowerCase() + ".html\">" + Utilities.escapeXml(ap.getTitle()) + "</a></td>\r\n");
}
b.append(" </tr>\r\n");
}
if (count == 0)
b.append("<tr><td colspan=\"\3\">No Extensions refer to this resource</td></tr>");
map.clear();
for (StructureDefinition sd : workerContext.getExtensionDefinitions()) {
boolean refers = false;
for (ElementDefinition ed : sd.getSnapshot().getElement()) {
for (TypeRefComponent tr : ed.getType()) {
for (UriType u : tr.getTargetProfile()) if (u.getValue().endsWith("/Any") || u.getValue().endsWith("/Resource") || u.getValue().endsWith("/DomainResource"))
refers = true;
}
if (refers)
map.put(sd.getId(), sd);
}
}
b.append("<tr><td colspan=\"\3\">Extensions that refer to Any resource</td></tr>");
for (String s : sorted(map.keySet())) {
StructureDefinition cs = map.get(s);
count++;
b.append(" <tr>\r\n");
String ref = cs.getUserString("path");
b.append(" <td><a href=\"").append(ref).append("\">").append(Utilities.escapeXml(cs.getId())).append("</a></td>\r\n");
b.append(" <td>").append(Utilities.escapeXml(cs.getName())).append("</td>\r\n");
Profile ap = (Profile) cs.getUserData("profile");
if (ap == null)
b.append(" <td></td>\r\n");
else {
ImplementationGuideDefn ig = definitions.getIgs().get(ap.getCategory());
b.append(" <td>for <a href=\"" + ig.getPrefix() + ap.getId() + ".html\">" + Utilities.escapeXml(ap.getTitle()) + "</a></td>\r\n");
}
b.append(" </tr>\r\n");
}
return b.toString();
}
use of org.hl7.fhir.definitions.model.ImplementationGuideDefn in project kindling by HL7.
the class PageProcessor method processConformancePackageIncludes.
public String processConformancePackageIncludes(Profile pack, String src, String intro, String notes, String resourceName, ImplementationGuideDefn ig) throws Exception {
String workingTitle = null;
int level = (ig == null || 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("settitle")) {
workingTitle = s2.substring(9).replace("{", "<%").replace("}", "%>");
src = s1 + s3;
} else if (com[0].equals("setlevel")) {
level = Integer.parseInt(com[1]);
src = s1 + s3;
} else if (com.length != 1)
throw new Exception("Instruction <%" + s2 + "%> not understood parsing profile " + pack.getId());
else if (com[0].equals("pageheader"))
src = s1 + pageHeader(pack.getId().toUpperCase().substring(0, 1) + pack.getId().substring(1)) + 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(pack.getTitle()) : workingTitle) + s3;
else if (com[0].equals("xtitle"))
src = s1 + Utilities.escapeXml(pack.getId().toUpperCase().substring(0, 1) + pack.getId().substring(1)) + s3;
else if (com[0].equals("name"))
src = s1 + pack.getId() + s3;
else if (com[0].equals("package.intro"))
src = s1 + (intro == null ? pack.metadata("description") : intro) + s3;
else if (com[0].equals("package.notes"))
src = s1 + (notes == null ? "" : notes) + s3;
else if (com[0].equals("canonicalname"))
src = s1 + makeCanonical(pack.getId()) + s3;
else if (com[0].equals("prettyname"))
src = s1 + makePretty(pack.getId()) + s3;
else if (com[0].equals("version"))
src = s1 + version + s3;
else if (com[0].equals("gendate"))
src = s1 + Config.DATE_FORMAT().format(new Date()) + s3;
else if (com[0].equals("maindiv"))
src = s1 + "<div class=\"content\">" + s3;
else if (com[0].equals("/maindiv"))
src = s1 + "</div>" + s3;
else if (com[0].equals("mappings-table"))
src = s1 + genMappingsTable() + s3;
else if (com[0].equals("id"))
src = s1 + pack.getId() + s3;
else if (com[0].equals("events"))
src = s1 + getEventsTable(pack.getId()) + s3;
else if (com[0].equals("resourcecodes"))
src = s1 + genResCodes() + s3;
else if (com[0].equals("datatypecodes"))
src = s1 + genDTCodes() + s3;
else if (com[0].equals("allparams"))
src = s1 + allParamlist() + s3;
else // src = s1 + genBindingsTable() + s3;
if (com[0].equals("codeslist"))
src = s1 + genCodeSystemsTable() + s3;
else // src = s1 + genValueSetsTable() + s3;
if (com[0].equals("igvaluesetslist"))
src = s1 + genIGValueSetsTable() + s3;
else if (com[0].equals("namespacelist"))
src = s1 + genNSList() + s3;
else if (com[0].equals("conceptmapslist"))
src = s1 + genConceptMapsTable() + s3;
else // src = s1 + genBindingTable(false) + s3;
if (com[0].equals("resimplall"))
src = s1 + genResImplList() + s3;
else if (com[0].equals("breadcrumb"))
src = s1 + breadCrumbManager.make(pack.getId()) + s3;
else if (com[0].equals("navlist"))
src = s1 + breadCrumbManager.navlist(pack.getId(), genlevel(level)) + s3;
else if (com[0].equals("breadcrumblist"))
src = s1 + ((ig == null || ig.isCore()) ? breadCrumbManager.makelist(pack.getId(), "profile:" + resourceName + "/" + pack.getId(), genlevel(level), pack.getTitle()) : ig.makeList(pack.getId(), "profile:" + resourceName + "/" + pack.getId(), genlevel(level), pack.getTitle())) + 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("pub-type"))
src = s1 + publicationType + s3;
else if (com[0].equals("pub-notice"))
src = s1 + publicationNotice + s3;
else if (com[0].equals("level"))
src = s1 + genlevel(level) + s3;
else if (com[0].equals("pagepath"))
src = s1 + pack.getId() + s3;
else if (com[0].equals("rellink")) {
if (pack.getId().contains(".html"))
throw new Error("Invalid link: " + pack.getId() + " at " + workingTitle);
src = s1 + Utilities.URLEncode(pack.getId() + ".html") + s3;
} else if (com[0].equals("baseURL"))
src = s1 + Utilities.URLEncode(baseURL) + s3;
else if (com[0].equals("description"))
src = s1 + Utilities.escapeXml(pack.getDescription()) + s3;
else if (com[0].equals("package-content"))
src = s1 + getPackageContent(pack, genlevel(level)) + 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].equals("package.search"))
src = s1 + getSearch(pack) + s3;
else if (com[0].startsWith("!"))
src = s1 + s3;
else if (com[0].equals("wg")) {
String wg = pack.getWg();
if (Utilities.noString(wg) && definitions.hasResource(resourceName))
wg = definitions.getResourceByName(resourceName).getWg().getCode();
if (wg == null || !definitions.getWorkgroups().containsKey(wg))
src = s1 + "(No assigned work group) (" + wg + ") (4)" + s3;
else
src = s1 + "<a _target=\"blank\" href=\"" + definitions.getWorkgroups().get(wg).getUrl() + "\">" + definitions.getWorkgroups().get(wg).getName() + "</a> Work Group" + 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 profile " + pack.getId());
}
return src;
}
use of org.hl7.fhir.definitions.model.ImplementationGuideDefn in project kindling by HL7.
the class PageProcessor method genProfilelist.
private String genProfilelist() throws Exception {
StringBuilder b = new StringBuilder();
b.append("<table class=\"grid\">\r\n");
b.append(" <tr>\r\n");
b.append(" <td><b>Name</b></td>\r\n");
b.append(" <td><b>Description</b></td>\r\n");
b.append(" <td><b>Kind</b></td>\r\n");
b.append(" <td><b><a href=\"versions.html#Maturity\">FMM</a></b></td>");
b.append(" </tr>\r\n");
b.append(" <tr>\r\n");
b.append(" <td colspan=\"2\"><b>General</b></td>\r\n");
b.append(" </tr>\r\n");
List<String> names = new ArrayList<String>();
names.addAll(definitions.getPackMap().keySet());
Collections.sort(names);
for (String s : names) {
Profile ap = definitions.getPackMap().get(s);
ImplementationGuideDefn ig = definitions.getIgs().get(ap.getCategory());
b.append(" <tr>\r\n");
b.append(" <td><a href=\"").append(ig.getPrefix() + ap.getId().toLowerCase()).append(".html\">").append(Utilities.escapeXml(ap.getTitle())).append("</a></td>\r\n");
b.append(" <td>").append(Utilities.escapeXml(ap.getDescription())).append("</td>\r\n");
b.append(" <td>").append(Utilities.escapeXml(ap.describeKind())).append("</td>\r\n");
b.append(" <td>").append(Utilities.escapeXml(ap.getFmmLevel())).append("</td>\r\n");
b.append(" </tr>\r\n");
}
for (String n : definitions.sortedResourceNames()) {
ResourceDefn r = definitions.getResourceByName(n);
if (!r.getConformancePackages().isEmpty()) {
b.append(" <tr>\r\n");
b.append(" <td colspan=\"4\"><b>" + r.getName() + "</b></td>\r\n");
b.append(" </tr>\r\n");
for (Profile p : r.getConformancePackages()) {
ImplementationGuideDefn ig = definitions.getIgs().get(p.getCategory());
b.append(" <tr>\r\n");
b.append(" <td><a href=\"" + ig.getPrefix() + p.getId().toLowerCase() + ".html\">" + Utilities.escapeXml(p.getTitle()) + "</a></td>\r\n");
b.append(" <td>" + Utilities.escapeXml(p.getDescription()) + "</td>\r\n");
b.append(" <td>" + Utilities.escapeXml(p.describeKind()) + "</td>\r\n");
b.append(" <td>" + Utilities.escapeXml(p.getFmmLevel()) + "</td>\r\n");
b.append(" </tr>\r\n");
}
}
}
b.append("</table>\r\n");
return b.toString();
}
Aggregations