use of org.hl7.fhir.r5.model.Narrative in project org.hl7.fhir.core by hapifhir.
the class NarrativeGenerator method generateByProfile.
private boolean generateByProfile(DomainResource r, StructureDefinition profile, boolean showCodeDetails) {
XhtmlNode x = new XhtmlNode(NodeType.Element, "div");
x.para().b().tx("Generated Narrative" + (showCodeDetails ? " with Details" : ""));
try {
generateByProfile(r, profile, r, profile.getSnapshot().getElement(), profile.getSnapshot().getElement().get(0), getChildrenForPath(profile.getSnapshot().getElement(), r.getResourceType().toString()), x, r.getResourceType().toString(), showCodeDetails);
} catch (Exception e) {
e.printStackTrace();
x.para().b().setAttribute("style", "color: maroon").tx("Exception generating Narrative: " + e.getMessage());
}
inject(r, x, NarrativeStatus.GENERATED);
return true;
}
use of org.hl7.fhir.r5.model.Narrative in project org.hl7.fhir.core by hapifhir.
the class NarrativeGenerator method generate.
/**
* This generate is optimised for the FHIR build process itself in as much as it
* generates hyperlinks in the narrative that are only going to be correct for
* the purposes of the build. This is to be reviewed in the future.
*
* @param vs
* @param codeSystems
* @throws IOException
* @throws DefinitionException
* @throws FHIRFormatError
* @throws Exception
*/
public boolean generate(ResourceContext rcontext, CodeSystem cs, boolean header) throws FHIRFormatError, DefinitionException, IOException {
XhtmlNode x = new XhtmlNode(NodeType.Element, "div");
boolean hasExtensions = false;
hasExtensions = generateDefinition(x, cs, header);
inject(cs, x, hasExtensions ? NarrativeStatus.EXTENSIONS : NarrativeStatus.GENERATED);
return true;
}
use of org.hl7.fhir.r5.model.Narrative in project org.hl7.fhir.core by hapifhir.
the class JsonParser method composeNarrativeInner.
protected void composeNarrativeInner(Narrative element) throws IOException {
composeElement(element);
if (element.hasStatusElement()) {
composeEnumerationCore("status", element.getStatusElement(), new Narrative.NarrativeStatusEnumFactory(), false);
composeEnumerationExtras("status", element.getStatusElement(), new Narrative.NarrativeStatusEnumFactory(), false);
}
if (element.hasDiv()) {
XhtmlNode node = element.getDiv();
if (node.getNsDecl() == null) {
node.attribute("xmlns", XHTML_NS);
}
composeXhtml("div", node);
}
}
use of org.hl7.fhir.r5.model.Narrative in project org.hl7.fhir.core by hapifhir.
the class BundleRenderer method render.
public XhtmlNode render(Bundle b) throws FHIRFormatError, DefinitionException, IOException, FHIRException, EOperationOutcome {
if (b.getType() == BundleType.DOCUMENT) {
if (!b.hasEntry() || !(b.getEntryFirstRep().hasResource() && b.getEntryFirstRep().getResource() instanceof Composition)) {
throw new FHIRException("Invalid document - first entry is not a Composition");
}
XhtmlNode x = new XhtmlNode(NodeType.Element, "div");
renderDocument(x, b);
return x;
} else if ((b.getType() == BundleType.COLLECTION && allEntresAreHistoryProvenance(b))) {
return null;
} else {
XhtmlNode root = new XhtmlNode(NodeType.Element, "div");
root.para().addText(formatMessage(RENDER_BUNDLE_HEADER_ROOT, b.getId(), b.getType().toCode()));
int i = 0;
for (BundleEntryComponent be : b.getEntry()) {
i++;
if (be.hasFullUrl())
root.an(makeInternalBundleLink(be.getFullUrl()));
if (be.hasResource() && be.getResource().hasId())
root.an(be.getResource().getResourceType().name() + "_" + be.getResource().getId());
root.hr();
if (be.hasFullUrl()) {
root.para().addText(formatMessage(RENDER_BUNDLE_HEADER_ENTRY_URL, Integer.toString(i), be.getFullUrl()));
} else {
root.para().addText(formatMessage(RENDER_BUNDLE_HEADER_ENTRY, Integer.toString(i)));
}
if (be.hasRequest())
renderRequest(root, be.getRequest());
if (be.hasSearch())
renderSearch(root, be.getSearch());
if (be.hasResponse())
renderResponse(root, be.getResponse());
if (be.hasResource()) {
root.para().addText(formatMessage(RENDER_BUNDLE_RESOURCE, be.getResource().fhirType()));
if (be.hasResource()) {
XhtmlNode xn = null;
if (be.getResource() instanceof DomainResource) {
DomainResource dr = (DomainResource) be.getResource();
xn = dr.getText().getDiv();
}
if (xn == null || xn.isEmpty()) {
ResourceRenderer rr = RendererFactory.factory(be.getResource(), context);
try {
xn = rr.build(be.getResource());
} catch (Exception e) {
xn = makeExceptionXhtml(e, "generating narrative");
}
}
root.blockquote().getChildNodes().addAll(checkInternalLinks(b, xn.getChildNodes()));
}
}
}
return root;
}
}
use of org.hl7.fhir.r5.model.Narrative in project org.hl7.fhir.core by hapifhir.
the class BundleRenderer method addSection.
private void addSection(XhtmlNode x, BaseWrapper section, int level, boolean nested) throws UnsupportedEncodingException, FHIRException, IOException {
if (section.has("title") || section.has("code") || section.has("text") || section.has("section")) {
XhtmlNode div = x.div();
if (section.has("title")) {
div.h(level).tx(section.get("title").primitiveValue());
} else if (section.has("code")) {
renderBase(div.h(level), section.get("code"));
}
if (section.has("text")) {
Base narrative = section.get("text");
x.addChildren(narrative.getXhtml());
}
if (section.has("section")) {
List<BaseWrapper> sections = section.children("section");
for (BaseWrapper child : sections) {
if (nested) {
addSection(x.blockquote(), child, level + 1, true);
} else {
addSection(x, child, level + 1, true);
}
}
}
}
// children
}
Aggregations