use of org.hl7.fhir.r4b.renderers.utils.BaseWrappers.BaseWrapper in project org.hl7.fhir.core by hapifhir.
the class NarrativeGenerator method renderLeaf.
private void renderLeaf(ResourceWrapper res, BaseWrapper ew, ElementDefinition defn, XhtmlNode x, boolean title, boolean showCodeDetails, Map<String, String> displayHints, String path) throws FHIRException, UnsupportedEncodingException, IOException {
if (ew == null)
return;
Base e = ew.getBase();
if (e instanceof StringType)
x.addText(((StringType) e).getValue());
else if (e instanceof CodeType)
x.addText(((CodeType) e).getValue());
else if (e instanceof IdType)
x.addText(((IdType) e).getValue());
else if (e instanceof Extension)
return;
else if (e instanceof InstantType)
x.addText(((InstantType) e).toHumanDisplay());
else if (e instanceof DateTimeType)
x.addText(((DateTimeType) e).toHumanDisplay());
else if (e instanceof Base64BinaryType)
x.addText(new Base64().encodeAsString(((Base64BinaryType) e).getValue()));
else if (e instanceof org.hl7.fhir.dstu3.model.DateType)
x.addText(((org.hl7.fhir.dstu3.model.DateType) e).toHumanDisplay());
else if (e instanceof Enumeration) {
Object ev = ((Enumeration<?>) e).getValue();
// todo: look up a display name if there is one
x.addText(ev == null ? "" : ev.toString());
} else if (e instanceof BooleanType)
x.addText(((BooleanType) e).getValue().toString());
else if (e instanceof CodeableConcept) {
renderCodeableConcept((CodeableConcept) e, x, showCodeDetails);
} else if (e instanceof Coding) {
renderCoding((Coding) e, x, showCodeDetails);
} else if (e instanceof Annotation) {
renderAnnotation((Annotation) e, x);
} else if (e instanceof Identifier) {
renderIdentifier((Identifier) e, x);
} else if (e instanceof org.hl7.fhir.dstu3.model.IntegerType) {
x.addText(Integer.toString(((org.hl7.fhir.dstu3.model.IntegerType) e).getValue()));
} else if (e instanceof org.hl7.fhir.dstu3.model.DecimalType) {
x.addText(((org.hl7.fhir.dstu3.model.DecimalType) e).getValue().toString());
} else if (e instanceof HumanName) {
renderHumanName((HumanName) e, x);
} else if (e instanceof SampledData) {
renderSampledData((SampledData) e, x);
} else if (e instanceof Address) {
renderAddress((Address) e, x);
} else if (e instanceof ContactPoint) {
renderContactPoint((ContactPoint) e, x);
} else if (e instanceof UriType) {
renderUri((UriType) e, x);
} else if (e instanceof Timing) {
renderTiming((Timing) e, x);
} else if (e instanceof Range) {
renderRange((Range) e, x);
} else if (e instanceof Quantity) {
renderQuantity((Quantity) e, x, showCodeDetails);
} else if (e instanceof Ratio) {
renderQuantity(((Ratio) e).getNumerator(), x, showCodeDetails);
x.tx("/");
renderQuantity(((Ratio) e).getDenominator(), x, showCodeDetails);
} else if (e instanceof Period) {
Period p = (Period) e;
x.addText(!p.hasStart() ? "??" : p.getStartElement().toHumanDisplay());
x.tx(" --> ");
x.addText(!p.hasEnd() ? "(ongoing)" : p.getEndElement().toHumanDisplay());
} else if (e instanceof Reference) {
Reference r = (Reference) e;
XhtmlNode c = x;
ResourceWithReference tr = null;
if (r.hasReferenceElement()) {
tr = resolveReference(res, r.getReference());
if (!r.getReference().startsWith("#")) {
if (tr != null && tr.getReference() != null)
c = x.ah(tr.getReference());
else
c = x.ah(r.getReference());
}
}
// what to display: if text is provided, then that. if the reference was resolved, then show the generated narrative
if (r.hasDisplayElement()) {
c.addText(r.getDisplay());
if (tr != null && tr.getResource() != null) {
c.tx(". Generated Summary: ");
generateResourceSummary(c, tr.getResource(), true, r.getReference().startsWith("#"));
}
} else if (tr != null && tr.getResource() != null) {
generateResourceSummary(c, tr.getResource(), r.getReference().startsWith("#"), r.getReference().startsWith("#"));
} else {
c.addText(r.getReference());
}
} else if (e instanceof Resource) {
return;
} else if (e instanceof ElementDefinition) {
x.tx("todo-bundle");
} else if (e != null && !(e instanceof Attachment) && !(e instanceof Narrative) && !(e instanceof Meta)) {
StructureDefinition sd = context.fetchTypeDefinition(e.fhirType());
if (sd == null)
throw new NotImplementedException("type " + e.getClass().getName() + " not handled yet, and no structure found");
else
generateByProfile(res, sd, ew, sd.getSnapshot().getElement(), sd.getSnapshot().getElementFirstRep(), getChildrenForPath(sd.getSnapshot().getElement(), sd.getSnapshot().getElementFirstRep().getPath()), x, path, showCodeDetails);
}
}
use of org.hl7.fhir.r4b.renderers.utils.BaseWrappers.BaseWrapper in project org.hl7.fhir.core by hapifhir.
the class NarrativeGenerator method generateByProfile.
private void generateByProfile(ResourceWrapper res, StructureDefinition profile, BaseWrapper e, List<ElementDefinition> allElements, ElementDefinition defn, List<ElementDefinition> children, XhtmlNode x, String path, boolean showCodeDetails, int indent, ResourceContext rc) throws FHIRException, UnsupportedEncodingException, IOException {
if (children.isEmpty()) {
renderLeaf(res, e, defn, x, false, showCodeDetails, readDisplayHints(defn), path, indent, rc);
} else {
for (PropertyWrapper p : splitExtensions(profile, e.children())) {
if (p.hasValues()) {
ElementDefinition child = getElementDefinition(children, path + "." + p.getName(), p);
if (child != null) {
Map<String, String> displayHints = readDisplayHints(child);
if (!exemptFromRendering(child)) {
List<ElementDefinition> grandChildren = getChildrenForPath(allElements, path + "." + p.getName());
filterGrandChildren(grandChildren, path + "." + p.getName(), p);
if (p.getValues().size() > 0 && child != null) {
if (isPrimitive(child)) {
XhtmlNode para = x.para();
String name = p.getName();
if (name.endsWith("[x]"))
name = name.substring(0, name.length() - 3);
if (showCodeDetails || !isDefaultValue(displayHints, p.getValues())) {
para.b().addText(name);
para.tx(": ");
if (renderAsList(child) && p.getValues().size() > 1) {
XhtmlNode list = x.ul();
for (BaseWrapper v : p.getValues()) renderLeaf(res, v, child, list.li(), false, showCodeDetails, displayHints, path, indent, rc);
} else {
boolean first = true;
for (BaseWrapper v : p.getValues()) {
if (first)
first = false;
else
para.tx(", ");
renderLeaf(res, v, child, para, false, showCodeDetails, displayHints, path, indent, rc);
}
}
}
} else if (canDoTable(path, p, grandChildren)) {
x.addTag(getHeader()).addText(Utilities.capitalize(Utilities.camelCase(Utilities.pluralizeMe(p.getName()))));
XhtmlNode tbl = x.table("grid");
XhtmlNode tr = tbl.tr();
// work around problem with empty table rows
tr.td().tx("-");
addColumnHeadings(tr, grandChildren);
for (BaseWrapper v : p.getValues()) {
if (v != null) {
tr = tbl.tr();
// work around problem with empty table rows
tr.td().tx("*");
addColumnValues(res, tr, grandChildren, v, showCodeDetails, displayHints, path, indent, rc);
}
}
} else {
for (BaseWrapper v : p.getValues()) {
if (v != null) {
XhtmlNode bq = x.addTag("blockquote");
bq.para().b().addText(p.getName());
generateByProfile(res, profile, v, allElements, child, grandChildren, bq, path + "." + p.getName(), showCodeDetails, indent + 1, rc);
}
}
}
}
}
}
}
}
}
}
use of org.hl7.fhir.r4b.renderers.utils.BaseWrappers.BaseWrapper in project org.hl7.fhir.core by hapifhir.
the class NarrativeGenerator method generateDiagnosticReport.
public XhtmlNode generateDiagnosticReport(ResourceWrapper dr) {
XhtmlNode root = new XhtmlNode(NodeType.Element, "div");
XhtmlNode h2 = root.h2();
displayCodeableConcept(h2, getProperty(dr, "code").value());
h2.tx(" ");
PropertyWrapper pw = getProperty(dr, "category");
if (valued(pw)) {
h2.tx("(");
displayCodeableConcept(h2, pw.value());
h2.tx(") ");
}
displayDate(h2, getProperty(dr, "issued").value());
XhtmlNode tbl = root.table("grid");
XhtmlNode tr = tbl.tr();
XhtmlNode tdl = tr.td();
XhtmlNode tdr = tr.td();
populateSubjectSummary(tdl, getProperty(dr, "subject").value());
tdr.b().tx("Report Details");
tdr.br();
pw = getProperty(dr, "perfomer");
if (valued(pw)) {
tdr.addText(pluralise("Performer", pw.getValues().size()) + ":");
for (BaseWrapper v : pw.getValues()) {
tdr.tx(" ");
displayReference(tdr, v);
}
tdr.br();
}
pw = getProperty(dr, "identifier");
if (valued(pw)) {
tdr.addText(pluralise("Identifier", pw.getValues().size()) + ":");
for (BaseWrapper v : pw.getValues()) {
tdr.tx(" ");
displayIdentifier(tdr, v);
}
tdr.br();
}
pw = getProperty(dr, "request");
if (valued(pw)) {
tdr.addText(pluralise("Request", pw.getValues().size()) + ":");
for (BaseWrapper v : pw.getValues()) {
tdr.tx(" ");
displayReferenceId(tdr, v);
}
tdr.br();
}
pw = getProperty(dr, "result");
if (valued(pw)) {
List<ObservationNode> observations = fetchObservations(pw.getValues());
buildObservationsTable(root, observations);
}
pw = getProperty(dr, "conclusion");
if (valued(pw))
displayText(root.para(), pw.value());
pw = getProperty(dr, "result");
if (valued(pw)) {
XhtmlNode p = root.para();
p.b().tx("Coded Diagnoses :");
for (BaseWrapper v : pw.getValues()) {
tdr.tx(" ");
displayCodeableConcept(tdr, v);
}
}
return root;
}
use of org.hl7.fhir.r4b.renderers.utils.BaseWrappers.BaseWrapper in project org.hl7.fhir.core by hapifhir.
the class PatientRenderer method display.
@Override
public String display(ResourceWrapper pat) throws UnsupportedEncodingException, IOException {
Identifier id = null;
PropertyWrapper pw = getProperty(pat, "identifier");
for (BaseWrapper t : pw.getValues()) {
id = chooseId(id, (Identifier) t.getBase());
}
pw = getProperty(pat, "name");
HumanName n = null;
for (BaseWrapper t : pw.getValues()) {
n = chooseName(n, (HumanName) t);
}
String gender = null;
pw = getProperty(pat, "gender");
if (valued(pw)) {
pw.value().getBase().primitiveValue();
}
DateType dt = null;
pw = getProperty(pat, "birthDate");
if (valued(pw)) {
dt = (DateType) pw.value().getBase();
}
return display(n, gender, dt, id);
}
use of org.hl7.fhir.r4b.renderers.utils.BaseWrappers.BaseWrapper in project org.hl7.fhir.core by hapifhir.
the class ProfileDrivenRenderer method generateElementByProfile.
public void generateElementByProfile(ResourceWrapper res, StructureDefinition profile, List<ElementDefinition> allElements, XhtmlNode x, String path, boolean showCodeDetails, int indent, PropertyWrapper p, ElementDefinition child) throws UnsupportedEncodingException, IOException, EOperationOutcome {
Map<String, String> displayHints = readDisplayHints(child);
if ("DomainResource.contained".equals(child.getBase().getPath())) {
// if (p.getValues().size() > 0 && child != null) {
// for (BaseWrapper v : p.getValues()) {
// x.an(v.get("id").primitiveValue());
// }
// }
} else if (!exemptFromRendering(child)) {
if (isExtension(p)) {
hasExtensions = true;
}
List<ElementDefinition> grandChildren = getChildrenForPath(allElements, path + "." + p.getName());
filterGrandChildren(grandChildren, path + "." + p.getName(), p);
if (p.getValues().size() > 0) {
if (isPrimitive(child)) {
XhtmlNode para = x.isPara() ? para = x : x.para();
String name = p.getName();
if (name.endsWith("[x]"))
name = name.substring(0, name.length() - 3);
if (showCodeDetails || !isDefaultValue(displayHints, p.getValues())) {
para.b().addText(name);
para.tx(": ");
if (renderAsList(child) && p.getValues().size() > 1) {
XhtmlNode list = x.ul();
for (BaseWrapper v : p.getValues()) renderLeaf(res, v, child, x, list.li(), false, showCodeDetails, displayHints, path, indent);
} else {
boolean first = true;
for (BaseWrapper v : p.getValues()) {
if (first) {
first = false;
} else {
para.tx(", ");
}
renderLeaf(res, v, child, x, para, false, showCodeDetails, displayHints, path, indent);
}
}
}
} else if (canDoTable(path, p, grandChildren, x)) {
XhtmlNode xn = new XhtmlNode(NodeType.Element, getHeader());
xn.addText(Utilities.capitalize(Utilities.camelCase(Utilities.pluralizeMe(p.getName()))));
XhtmlNode tbl = new XhtmlNode(NodeType.Element, "table");
tbl.setAttribute("class", "grid");
XhtmlNode tr = tbl.tr();
// work around problem with empty table rows
tr.td().tx("-");
boolean add = addColumnHeadings(tr, grandChildren);
for (BaseWrapper v : p.getValues()) {
if (v != null) {
tr = tbl.tr();
// work around problem with empty table rows
tr.td().tx("*");
add = addColumnValues(res, tr, grandChildren, v, showCodeDetails, displayHints, path, indent) || add;
}
}
if (add) {
x.add(xn);
x.add(tbl);
}
} else if (isExtension(p)) {
for (BaseWrapper v : p.getValues()) {
if (v != null) {
PropertyWrapper vp = v.getChildByName("value");
PropertyWrapper ev = v.getChildByName("extension");
if (vp.hasValues()) {
BaseWrapper vv = vp.value();
XhtmlNode para = x.para();
para.b().addText(p.getStructure().present());
para.tx(": ");
renderLeaf(res, vv, child, x, para, false, showCodeDetails, displayHints, path, indent);
} else if (ev.hasValues()) {
XhtmlNode bq = x.addTag("blockquote");
bq.para().b().addText(isExtension(p) ? p.getStructure().present() : p.getName());
for (BaseWrapper vv : ev.getValues()) {
StructureDefinition ex = context.getWorker().fetchTypeDefinition("Extension");
List<ElementDefinition> children = getChildrenForPath(ex.getSnapshot().getElement(), "Extension");
generateByProfile(res, ex, vv, allElements, child, children, bq, "Extension", showCodeDetails, indent + 1);
}
}
}
}
} else {
for (BaseWrapper v : p.getValues()) {
if (v != null) {
XhtmlNode bq = x.addTag("blockquote");
bq.para().b().addText(isExtension(p) ? p.getStructure().present() : p.getName());
generateByProfile(res, profile, v, allElements, child, grandChildren, bq, path + "." + p.getName(), showCodeDetails, indent + 1);
}
}
}
}
}
}
Aggregations