use of org.hl7.fhir.dstu2.model.Narrative in project org.hl7.fhir.core by hapifhir.
the class NarrativeGenerator method inject.
private void inject(DomainResource r, XhtmlNode x, NarrativeStatus status) {
if (!r.hasText() || !r.getText().hasDiv() || r.getText().getDiv().getChildNodes().isEmpty()) {
r.setText(new Narrative());
r.getText().setDiv(x);
r.getText().setStatus(status);
} else {
XhtmlNode n = r.getText().getDiv();
n.addTag("hr");
n.getChildNodes().addAll(x.getChildNodes());
}
}
use of org.hl7.fhir.dstu2.model.Narrative in project org.hl7.fhir.core by hapifhir.
the class NarrativeGenerator method generateByProfile.
private String generateByProfile(Element er, StructureDefinition profile, boolean showCodeDetails) throws IOException {
XhtmlNode x = new XhtmlNode(NodeType.Element, "div");
x.addTag("p").addTag("b").addText("Generated Narrative" + (showCodeDetails ? " with Details" : ""));
try {
generateByProfile(er, profile, er, profile.getSnapshot().getElement(), profile.getSnapshot().getElement().get(0), getChildrenForPath(profile.getSnapshot().getElement(), er.getLocalName()), x, er.getLocalName(), showCodeDetails);
} catch (Exception e) {
e.printStackTrace();
x.addTag("p").addTag("b").setAttribute("style", "color: maroon").addText("Exception generating Narrative: " + e.getMessage());
}
inject(er, x, NarrativeStatus.GENERATED);
return new XhtmlComposer(true, false).compose(x);
}
use of org.hl7.fhir.dstu2.model.Narrative in project org.hl7.fhir.core by hapifhir.
the class Factory method newNarrative.
public static Narrative newNarrative(NarrativeStatus status, String html) throws IOException, FHIRException {
Narrative n = new Narrative();
n.setStatus(status);
try {
n.setDiv(new XhtmlParser().parseFragment("<div>" + Utilities.escapeXml(html) + "</div>"));
} catch (org.hl7.fhir.exceptions.FHIRException e) {
throw new FHIRException(e.getMessage(), e);
}
return n;
}
use of org.hl7.fhir.dstu2.model.Narrative in project org.hl7.fhir.core by hapifhir.
the class NarrativeGenerator method generateDocumentNarrative.
public XhtmlNode generateDocumentNarrative(Bundle feed) {
/*
When the document is presented for human consumption, applications must present the collated narrative portions of the following resources in order:
* The Composition resource
* The Subject resource
* Resources referenced in the section.content
*/
XhtmlNode root = new XhtmlNode(NodeType.Element, "div");
Composition comp = (Composition) feed.getEntry().get(0).getResource();
root.getChildNodes().add(comp.getText().getDiv());
Resource subject = ResourceUtilities.getById(feed, null, comp.getSubject().getReference());
if (subject != null && subject instanceof DomainResource) {
root.hr();
root.getChildNodes().add(((DomainResource) subject).getText().getDiv());
}
List<SectionComponent> sections = comp.getSection();
renderSections(feed, root, sections, 1);
return root;
}
use of org.hl7.fhir.dstu2.model.Narrative in project org.hl7.fhir.core by hapifhir.
the class NarrativeGenerator method generate.
public String generate(ResourceContext rcontext, org.hl7.fhir.dstu3.elementmodel.Element er, boolean showCodeDetails) throws IOException, DefinitionException {
if (rcontext == null)
rcontext = new ResourceContext(null, er);
XhtmlNode x = new XhtmlNode(NodeType.Element, "div");
x.para().b().tx("Generated Narrative" + (showCodeDetails ? " with Details" : ""));
try {
ResurceWrapperMetaElement resw = new ResurceWrapperMetaElement(er);
BaseWrapperMetaElement base = new BaseWrapperMetaElement(er, null, er.getProperty().getStructure(), er.getProperty().getDefinition());
base.children();
generateByProfile(resw, er.getProperty().getStructure(), base, er.getProperty().getStructure().getSnapshot().getElement(), er.getProperty().getDefinition(), base.children, x, er.fhirType(), showCodeDetails);
} catch (Exception e) {
e.printStackTrace();
x.para().b().setAttribute("style", "color: maroon").tx("Exception generating Narrative: " + e.getMessage());
}
inject(er, x, NarrativeStatus.GENERATED);
return new XhtmlComposer(XhtmlComposer.XML).compose(x);
}
Aggregations