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, org.hl7.fhir.exceptions.FHIRException {
XhtmlNode x = new XhtmlNode(NodeType.Element, "div");
x.para().b().tx("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.para().b().setAttribute("style", "color: maroon").tx("Exception generating Narrative: " + e.getMessage());
}
inject(er, x, NarrativeStatus.GENERATED);
String b = new XhtmlComposer(XhtmlComposer.XML, pretty).compose(x);
return b;
}
use of org.hl7.fhir.dstu2.model.Narrative in project org.hl7.fhir.core by hapifhir.
the class JsonParser method composeNarrativeProperties.
protected void composeNarrativeProperties(Narrative element) throws IOException {
composeDataTypeProperties(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.dstu2.model.Narrative in project org.hl7.fhir.core by hapifhir.
the class XmlParserBase method compose.
/**
* Compose a resource to a stream, possibly using pretty presentation for a human reader, and maybe a different choice in the xhtml narrative (used in the spec in one place, but should not be used in production)
* @
*/
public void compose(OutputStream stream, Resource resource, boolean htmlPretty) throws IOException {
XMLWriter writer = new XMLWriter(stream, "UTF-8");
writer.setPretty(style == OutputStyle.PRETTY);
writer.start();
compose(writer, resource, htmlPretty);
writer.end();
}
use of org.hl7.fhir.dstu2.model.Narrative in project org.hl7.fhir.core by hapifhir.
the class ProfileDrivenRenderer method generateByProfile.
private boolean generateByProfile(StructureDefinition profile, boolean showCodeDetails) {
XhtmlNode x = new XhtmlNode(NodeType.Element, "div");
if (context.isAddGeneratedNarrativeHeader()) {
x.para().b().tx("Generated Narrative" + (showCodeDetails ? " with Details" : ""));
}
try {
generateByProfile(rcontext.getResourceResource(), profile, rcontext.getResourceResource(), profile.getSnapshot().getElement(), profile.getSnapshot().getElement().get(0), getChildrenForPath(profile.getSnapshot().getElement(), rcontext.getResourceResource().getResourceType().toString()), x, rcontext.getResourceResource().getResourceType().toString(), showCodeDetails);
} catch (Exception e) {
e.printStackTrace();
x.para().b().style("color: maroon").tx("Exception generating Narrative: " + e.getMessage());
}
inject(rcontext.getResourceResource(), x, NarrativeStatus.GENERATED);
return true;
}
use of org.hl7.fhir.dstu2.model.Narrative in project org.hl7.fhir.core by hapifhir.
the class ProfileDrivenRenderer method render.
@Override
public boolean render(XhtmlNode x, ResourceWrapper r) throws FHIRFormatError, DefinitionException, IOException {
if (context.isAddGeneratedNarrativeHeader()) {
x.para().b().tx("Generated Narrative");
}
if (context.isTechnicalMode()) {
renderResourceHeader(r, x);
}
try {
StructureDefinition sd = r.getDefinition();
if (sd == null) {
throw new FHIRException("Cannot find definition for " + r.fhirType());
} else {
ElementDefinition ed = sd.getSnapshot().getElement().get(0);
containedIds.clear();
hasExtensions = false;
generateByProfile(r, sd, r.root(), sd.getSnapshot().getElement(), ed, context.getProfileUtilities().getChildList(sd, ed), x, r.fhirType(), context.isTechnicalMode(), 0);
}
} catch (Exception e) {
System.out.println("Error Generating Narrative for " + r.fhirType() + "/" + r.getId() + ": " + e.getMessage());
e.printStackTrace();
x.para().b().style("color: maroon").tx("Exception generating Narrative: " + e.getMessage());
}
return hasExtensions;
}
Aggregations