use of org.hl7.fhir.dstu2.model.Narrative in project kindling by HL7.
the class Publisher method addToResourceFeed.
private void addToResourceFeed(ValueSet vs, Bundle dest, String filename) throws Exception {
maybeFixResourceId(vs, filename);
if (vs.getId() == null)
throw new Exception("Resource has no id: " + vs.getName() + " (" + vs.getUrl() + ")");
if (ResourceUtilities.getById(dest, ResourceType.ValueSet, vs.getId()) != null)
throw new Exception("Attempt to add duplicate value set " + vs.getId() + " (" + vs.getName() + ")");
if (!vs.hasText() || !vs.getText().hasDiv()) {
RendererFactory.factory(vs, page.getRc().copy()).render(vs);
}
if (!vs.hasText() || vs.getText().getDiv() == null)
throw new Exception("Example Value Set " + vs.getId() + " does not have any narrative");
ResourceUtilities.meta(vs).setLastUpdated(page.getGenDate().getTime());
if (vs.getUrl().startsWith("http://hl7.org/fhir/") && !vs.getUrl().equals("http://hl7.org/fhir/" + vs.getResourceType().toString() + "/" + vs.getId()))
throw new Exception("URL mismatch on value set: " + vs.getUrl() + " vs " + "http://hl7.org/fhir/" + vs.getResourceType().toString() + "/" + vs.getId());
dest.getEntry().add(new BundleEntryComponent().setResource(vs).setFullUrl("http://hl7.org/fhir/" + vs.fhirType() + "/" + vs.getId()));
}
use of org.hl7.fhir.dstu2.model.Narrative in project kindling by HL7.
the class Publisher method genProfiledTypeProfile.
private void genProfiledTypeProfile(ProfiledType pt) throws Exception {
StructureDefinition profile = new ProfileGenerator(page.getDefinitions(), page.getWorkerContext(), page, page.getGenDate(), page.getVersion(), dataElements, fpUsages, page.getFolders().rootDir, page.getUml(), page.getRc()).generate(pt, page.getValidationErrors());
if (page.getProfiles().has(profile.getUrl()))
throw new Exception("Duplicate Profile URL " + profile.getUrl());
page.getProfiles().see(profile, page.packageInfo());
pt.setProfile(profile);
// todo: what to do in the narrative?
}
use of org.hl7.fhir.dstu2.model.Narrative in project kindling by HL7.
the class Publisher method generateCodeSystemsPart1.
private void generateCodeSystemsPart1() throws Exception {
page.log(" ...code systems", LogMessageType.Process);
for (CodeSystem cs : page.getDefinitions().getCodeSystems().getList()) {
if (cs != null && !cs.hasUserData("external.url")) {
if (!cs.hasText()) {
cs.setText(new Narrative());
cs.getText().setStatus(NarrativeStatus.EMPTY);
}
if (!cs.getText().hasDiv()) {
cs.getText().setDiv(new XhtmlNode(NodeType.Element));
cs.getText().getDiv().setName("div");
}
// if (ToolingExtensions.getOID(cs) == null)
// throw new Exception("No OID on code system "+cs.getUrl());
}
}
}
use of org.hl7.fhir.dstu2.model.Narrative in project kindling by HL7.
the class Publisher method generateConceptMap.
private void generateConceptMap(ConceptMap cm) throws Exception {
String filename = cm.getUserString("path");
RenderingContext lrc = page.getRc().copy().setLocalPrefix("").setTooCostlyNoteEmpty(PageProcessor.TOO_MANY_CODES_TEXT_EMPTY).setTooCostlyNoteNotEmpty(PageProcessor.TOO_MANY_CODES_TEXT_NOT_EMPTY);
RendererFactory.factory(cm, lrc).render(cm);
IParser json = new JsonParser().setOutputStyle(OutputStyle.PRETTY);
FileOutputStream s = new FileOutputStream(page.getFolders().dstDir + Utilities.changeFileExt(filename, ".json"));
json.compose(s, cm);
s.close();
json = new JsonParser().setOutputStyle(OutputStyle.CANONICAL);
s = new FileOutputStream(page.getFolders().dstDir + Utilities.changeFileExt(filename, ".canonical.json"));
json.compose(s, cm);
s.close();
String n = Utilities.changeFileExt(filename, "");
jsonToXhtml(n, cm.getName(), resource2Json(cm), "conceptmap-instance", "Concept Map", null, wg("vocab"));
ttlToXhtml(n, cm.getName(), resource2Ttl(cm), "conceptmap-instance", "Concept Map", null, wg("vocab"));
IParser xml = new XmlParser().setOutputStyle(OutputStyle.PRETTY);
s = new FileOutputStream(page.getFolders().dstDir + Utilities.changeFileExt(filename, ".xml"));
xml.compose(s, cm);
s.close();
xml = new XmlParser().setOutputStyle(OutputStyle.CANONICAL);
s = new FileOutputStream(page.getFolders().dstDir + Utilities.changeFileExt(filename, ".canonical.xml"));
xml.compose(s, cm);
s.close();
cloneToXhtml(n, cm.getName(), false, "conceptmap-instance", "Concept Map", null, wg("vocab"));
// now, we create an html page from the narrative
String narrative = new XhtmlComposer(XhtmlComposer.HTML).compose(cm.getText().getDiv());
String html = TextFile.fileToString(page.getFolders().templateDir + "template-example.html").replace("<%example%>", narrative);
html = page.processPageIncludes(Utilities.changeFileExt(filename, ".html"), html, "conceptmap-instance", null, null, null, "Concept Map", null, null, wg("vocab"));
TextFile.stringToFile(html, page.getFolders().dstDir + Utilities.changeFileExt(filename, ".html"));
conceptMapsFeed.getEntry().add(new BundleEntryComponent().setResource(cm).setFullUrl("http://hl7.org/fhir/" + cm.fhirType() + "/" + cm.getId()));
page.getConceptMaps().see(cm, page.packageInfo());
page.getHTMLChecker().registerFile(n + ".html", cm.getName(), HTMLLinkChecker.XHTML_TYPE, false);
}
use of org.hl7.fhir.dstu2.model.Narrative in project kindling by HL7.
the class PageProcessor method processProfileIncludes.
public String processProfileIncludes(String filename, String fileid, Profile pack, ConstraintStructure profile, String xml, String json, String tx, String src, String master, String path, String intro, String notes, ImplementationGuideDefn ig, boolean isDict, boolean hasNarrative) 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("profileheader"))
src = s1 + profileHeader(fileid, com.length > 1 ? com[1] : "", hasExamples(pack)) + s3;
else 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.length != 1)
throw new Exception("Instruction <%" + s2 + "%> not understood parsing resource " + filename);
else if (com[0].equals("pageheader"))
src = s1 + pageHeader(pack.metadata("name")) + s3;
else if (com[0].equals("level"))
src = s1 + genlevel(level) + 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("StructureDefinition: " + profile.getTitle()) : workingTitle) + s3;
else if (com[0].equals("xtitle"))
src = s1 + (workingTitle == null ? Utilities.escapeXml("StructureDefinition: " + profile.getTitle()) : Utilities.escapeXml(workingTitle)) + s3;
else if (com[0].equals("profiletitle"))
src = s1 + Utilities.escapeXml(pack.metadata("name")) + 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 (!Utilities.noString(pack.metadata("date"))) {
Date d = new SimpleDateFormat("yyyy-MM-dd").parse(pack.metadata("date"));
src = s1 + Config.DATE_FORMAT().format(d) + 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 + Utilities.escapeXml(pack.metadata("description")) + s3;
else if (com[0].equals("status"))
src = s1 + describeStatus(pack.metadata("status")) + s3;
else if (com[0].equals("author"))
src = s1 + Utilities.escapeXml(pack.metadata("author.name")) + 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("profiledesc")) {
src = s1 + Utilities.escapeXml(profile.getResource().getDescription()) + s3;
} else if (com[0].equals("tx"))
src = s1 + tx + s3;
else if (com[0].equals("inv"))
src = s1 + genProfileConstraints(profile.getResource()) + 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 + "todo" + 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"))
src = s1 + ((ig == null || ig.isCore()) ? breadCrumbManager.makelist(filename, "profile:" + path, genlevel(0), profile.getResource().getName()) : ig.makeList(filename, "profile:" + path, genlevel(level), profile.getResource().getName())) + 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(0) + 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("profileurl"))
src = s1 + profile.getResource().getUrl() + 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("base-link"))
src = s1 + baseLink(profile.getResource(), genlevel(level)) + s3;
else if (com[0].equals("profile-structure-table-diff"))
src = s1 + generateProfileStructureTable(profile, true, filename, pack.getId(), genlevel(level)) + s3;
else if (com[0].equals("profile-structure-table"))
src = s1 + generateProfileStructureTable(profile, false, filename, pack.getId(), genlevel(level)) + s3;
else if (com[0].equals("maponthispage"))
src = s1 + mapOnPageProfile(profile.getResource()) + s3;
else if (com[0].equals("mappings"))
src = s1 + mappingsProfile(profile.getResource()) + s3;
else if (com[0].equals("definitions"))
src = s1 + definitionsProfile(profile.getResource(), genlevel(level)) + s3;
else if (com[0].equals("profile.review"))
src = s1 + profileReviewLink(profile) + s3;
else if (com[0].equals("profile.datadictionary"))
src = s1 + profileDictionaryLink(profile) + s3;
else if (com[0].equals("profile.tx"))
src = s1 + getTerminologyNotes(profile.getResource(), level) + s3;
else if (com[0].equals("profile.inv"))
src = s1 + getInvariantList(profile.getResource()) + s3;
else if (com[0].equals("draft-note"))
src = s1 + getDraftNote(pack, genlevel(level)) + s3;
else if (com[0].equals("pagepath"))
src = s1 + filename + s3;
else if (com[0].equals("rellink")) {
if (!filename.contains(".html"))
src = s1 + filename + ".html" + s3;
else
src = s1 + filename + s3;
} else if (com[0].equals("schematron"))
src = s1 + (isDict ? "<i>None</i>" : "<a href=\"" + filename + ".sch\">Schematron</a>") + s3;
else if (com[0].equals("summary"))
src = s1 + generateHumanSummary(profile.getResource(), genlevel(level)) + s3;
else if (com[0].equals("profile-examples"))
src = s1 + generateProfileExamples(pack, profile) + s3;
else if (com[0].equals("profile-extensions-table"))
src = s1 + "<p><i>Todo</i></p>" + s3;
else if (com[0].equals("definitionsonthispage"))
src = s1 + "<p><i>Todo</i></p>" + s3;
else if (com[0].equals("profile.intro"))
src = s1 + genProfileDoco(pack, intro) + s3;
else if (com[0].equals("profile.notes"))
src = s1 + genProfileDoco(pack, notes) + 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 = profile.getWg().getCode();
if (Utilities.noString(wg))
pack.getWg();
if (Utilities.noString(wg) && profile.getDefn() != null)
wg = profile.getDefn().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("fmm-style")) {
String fmm = ToolingExtensions.readStringExtension(profile.getResource(), ToolingExtensions.EXT_FMM_LEVEL);
StandardsStatus ss = ToolingExtensions.getStandardsStatus(profile.getResource());
src = s1 + fmmBarColorStyle(ss, fmm) + s3;
} else if (com[0].equals("fmm")) {
String fmm = profile.getFmm();
if (Utilities.noString(fmm))
fmm = pack.getFmmLevel();
src = s1 + getFmmFromlevel(genlevel(level), fmm) + s3;
} else if (com[0].equals("profile-context"))
src = s1 + getProfileContext(pack.getCandidateResource(), genlevel(level)) + s3;
else if (com[0].equals("sstatus")) {
StandardsStatus ss = ToolingExtensions.getStandardsStatus(profile.getResource());
if (ss == null)
ss = StandardsStatus.INFORMATIVE;
if (ss == StandardsStatus.NORMATIVE && ToolingExtensions.hasExtension(profile.getResource(), ToolingExtensions.EXT_NORMATIVE_VERSION))
src = s1 + "<a href=\"" + genlevel(level) + "versions.html#std-process\">" + ss.toDisplay() + "</a> (from v" + ToolingExtensions.readStringExtension(profile.getResource(), ToolingExtensions.EXT_NORMATIVE_VERSION) + ")" + s3;
else
src = s1 + "<a href=\"" + genlevel(level) + "versions.html#std-process\">" + ss.toDisplay() + "</a>" + s3;
} else if (com[0].equals("past-narrative-link")) {
if (hasNarrative)
src = s1 + s3;
else
src = s1 + "<p><a href=\"#DomainResource.text.div-end\">Jump past Narrative</a></p>" + s3;
} else if (com[0].equals("resurl")) {
if (Utilities.noString(pack.metadata("id")))
src = s1 + s3;
else
src = s1 + "The id of this profile is " + pack.metadata("id") + 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;
}
Aggregations