use of org.hl7.fhir.r4b.renderers.utils.BaseWrappers.ResourceWrapper in project org.hl7.fhir.core by hapifhir.
the class NarrativeGenerator method displayLeaf.
private boolean displayLeaf(ResourceWrapper res, BaseWrapper ew, ElementDefinition defn, XhtmlNode x, String name, boolean showCodeDetails) throws FHIRException, UnsupportedEncodingException, IOException {
if (ew == null)
return false;
Base e = ew.getBase();
Map<String, String> displayHints = readDisplayHints(defn);
if (name.endsWith("[x]"))
name = name.substring(0, name.length() - 3);
if (!showCodeDetails && e instanceof PrimitiveType && isDefault(displayHints, ((PrimitiveType) e)))
return false;
if (e instanceof StringType) {
x.addText(name + ": " + ((StringType) e).getValue());
return true;
} else if (e instanceof CodeType) {
x.addText(name + ": " + ((CodeType) e).getValue());
return true;
} else if (e instanceof IdType) {
x.addText(name + ": " + ((IdType) e).getValue());
return true;
} else if (e instanceof DateTimeType) {
x.addText(name + ": " + ((DateTimeType) e).toHumanDisplay());
return true;
} else if (e instanceof InstantType) {
x.addText(name + ": " + ((InstantType) e).toHumanDisplay());
return true;
} else if (e instanceof Extension) {
x.addText("Extensions: todo");
return true;
} else if (e instanceof org.hl7.fhir.dstu2016may.model.DateType) {
x.addText(name + ": " + ((org.hl7.fhir.dstu2016may.model.DateType) e).toHumanDisplay());
return true;
} else if (e instanceof Enumeration) {
// todo: look up a display name if there is one
x.addText(((Enumeration<?>) e).getValue().toString());
return true;
} else if (e instanceof BooleanType) {
if (((BooleanType) e).getValue()) {
x.addText(name);
return true;
}
} else if (e instanceof CodeableConcept) {
renderCodeableConcept((CodeableConcept) e, x, showCodeDetails);
return true;
} else if (e instanceof Coding) {
renderCoding((Coding) e, x, showCodeDetails);
return true;
} else if (e instanceof Annotation) {
renderAnnotation((Annotation) e, x, showCodeDetails);
return true;
} else if (e instanceof org.hl7.fhir.dstu2016may.model.IntegerType) {
x.addText(Integer.toString(((org.hl7.fhir.dstu2016may.model.IntegerType) e).getValue()));
return true;
} else if (e instanceof org.hl7.fhir.dstu2016may.model.DecimalType) {
x.addText(((org.hl7.fhir.dstu2016may.model.DecimalType) e).getValue().toString());
return true;
} else if (e instanceof Identifier) {
renderIdentifier((Identifier) e, x);
return true;
} else if (e instanceof HumanName) {
renderHumanName((HumanName) e, x);
return true;
} else if (e instanceof SampledData) {
renderSampledData((SampledData) e, x);
return true;
} else if (e instanceof Address) {
renderAddress((Address) e, x);
return true;
} else if (e instanceof ContactPoint) {
renderContactPoint((ContactPoint) e, x);
return true;
} else if (e instanceof Timing) {
renderTiming((Timing) e, x);
return true;
} else if (e instanceof Quantity) {
renderQuantity((Quantity) e, x, showCodeDetails);
return true;
} else if (e instanceof Ratio) {
renderQuantity(((Ratio) e).getNumerator(), x, showCodeDetails);
x.addText("/");
renderQuantity(((Ratio) e).getDenominator(), x, showCodeDetails);
return true;
} else if (e instanceof Period) {
Period p = (Period) e;
x.addText(name + ": ");
x.addText(!p.hasStart() ? "??" : p.getStartElement().toHumanDisplay());
x.addText(" --> ");
x.addText(!p.hasEnd() ? "(ongoing)" : p.getEndElement().toHumanDisplay());
return true;
} else if (e instanceof Reference) {
Reference r = (Reference) e;
if (r.hasDisplayElement())
x.addText(r.getDisplay());
else if (r.hasReferenceElement()) {
ResourceWithReference tr = resolveReference(res, r.getReference());
// getDisplayForReference(tr.getReference()));
x.addText(tr == null ? r.getReference() : "????");
} else
x.addText("??");
return true;
} else if (e instanceof Narrative) {
return false;
} else if (e instanceof Resource) {
return false;
} else if (!(e instanceof Attachment))
throw new NotImplementedException("type " + e.getClass().getName() + " not handled yet");
return false;
}
use of org.hl7.fhir.r4b.renderers.utils.BaseWrappers.ResourceWrapper 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.ResourceWrapper in project org.hl7.fhir.core by hapifhir.
the class QuestionnaireResponseRenderer method addTreeRoot.
private Row addTreeRoot(HierarchicalTableGenerator gen, List<Row> rows, ResourceWrapper q) throws IOException {
Row r = gen.new Row();
rows.add(r);
r.setIcon("icon_q_root.gif", "QuestionnaireResponseRoot");
r.getCells().add(gen.new Cell(null, null, q.getId(), null, null));
r.getCells().add(gen.new Cell(null, null, "", null, null));
r.getCells().add(gen.new Cell(null, null, "QuestionnaireResponse", null, null));
r.getCells().add(gen.new Cell(null, null, "", null, null));
return r;
}
use of org.hl7.fhir.r4b.renderers.utils.BaseWrappers.ResourceWrapper in project org.hl7.fhir.core by hapifhir.
the class QuestionnaireResponseRenderer method renderAnswer.
public void renderAnswer(HierarchicalTableGenerator gen, ResourceWrapper q, Row r, BaseWrapper ans) throws UnsupportedEncodingException, IOException {
List<BaseWrapper> items;
Base b = ans.get("value[x]");
if (b == null) {
r.getCells().add(gen.new Cell(null, null, "null!", null, null));
} else if (b.isPrimitive()) {
r.getCells().add(gen.new Cell(null, null, b.primitiveValue(), null, null));
} else {
XhtmlNode x = new XhtmlNode(NodeType.Element, "span");
Cell cell = gen.new Cell(null, null, null, null, null);
Piece p = gen.new Piece("span");
p.getChildren().add(x);
cell.addPiece(p);
render(x, (DataType) b);
r.getCells().add(cell);
}
items = ans.children("item");
for (BaseWrapper si : items) {
renderTreeItem(gen, r.getSubRows(), q, si);
}
}
use of org.hl7.fhir.r4b.renderers.utils.BaseWrappers.ResourceWrapper in project org.hl7.fhir.core by hapifhir.
the class ProfileDrivenRenderer method addColumnValues.
private boolean addColumnValues(ResourceWrapper res, XhtmlNode tr, List<ElementDefinition> grandChildren, BaseWrapper v, boolean showCodeDetails, Map<String, String> displayHints, String path, int indent) throws FHIRException, UnsupportedEncodingException, IOException, EOperationOutcome {
boolean b = false;
for (ElementDefinition e : grandChildren) {
PropertyWrapper p = v.getChildByName(e.getPath().substring(e.getPath().lastIndexOf(".") + 1));
XhtmlNode td = tr.td();
if (p == null || p.getValues().size() == 0 || p.getValues().get(0) == null) {
b = true;
td.tx(" ");
} else {
for (BaseWrapper vv : p.getValues()) {
b = true;
td.sep(", ");
renderLeaf(res, vv, e, td, td, false, showCodeDetails, displayHints, path, indent);
}
}
}
return b;
}
Aggregations