use of org.hl7.fhir.r4b.renderers.utils.BaseWrappers.PropertyWrapper in project org.hl7.fhir.core by hapifhir.
the class NarrativeGenerator method filterGrandChildren.
private void filterGrandChildren(List<ElementDefinition> grandChildren, String string, PropertyWrapper prop) {
List<ElementDefinition> toRemove = new ArrayList<ElementDefinition>();
toRemove.addAll(grandChildren);
for (BaseWrapper b : prop.getValues()) {
List<ElementDefinition> list = new ArrayList<ElementDefinition>();
for (ElementDefinition ed : toRemove) {
PropertyWrapper p = b.getChildByName(tail(ed.getPath()));
if (p != null && p.hasValues())
list.add(ed);
}
toRemove.removeAll(list);
}
grandChildren.removeAll(toRemove);
}
use of org.hl7.fhir.r4b.renderers.utils.BaseWrappers.PropertyWrapper 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.PropertyWrapper in project org.hl7.fhir.core by hapifhir.
the class NarrativeGenerator method addObservationToTable.
private void addObservationToTable(XhtmlNode tr, ResourceWrapper obs, int i) {
// TODO Auto-generated method stub
// code (+bodysite)
XhtmlNode td = tr.td();
PropertyWrapper pw = getProperty(obs, "result");
if (valued(pw)) {
displayCodeableConcept(td, pw.value());
}
pw = getProperty(obs, "bodySite");
if (valued(pw)) {
td.tx(" (");
displayCodeableConcept(td, pw.value());
td.tx(")");
}
// value / dataAbsentReason (in red)
td = tr.td();
pw = getProperty(obs, "value[x]");
if (valued(pw)) {
if (pw.getTypeCode().equals("CodeableConcept"))
displayCodeableConcept(td, pw.value());
else if (pw.getTypeCode().equals("string"))
displayText(td, pw.value());
else
td.addText(pw.getTypeCode() + " not rendered yet");
}
// units
td = tr.td();
td.tx("to do");
// reference range
td = tr.td();
td.tx("to do");
// flags (status other than F, interpretation, )
td = tr.td();
td.tx("to do");
// issued if different to DR
td = tr.td();
td.tx("to do");
}
use of org.hl7.fhir.r4b.renderers.utils.BaseWrappers.PropertyWrapper in project org.hl7.fhir.core by hapifhir.
the class NarrativeGenerator method generateResourceSummary.
private void generateResourceSummary(XhtmlNode x, ResourceWrapper res, boolean textAlready, boolean showCodeDetails, ResourceContext rc) throws FHIRException, UnsupportedEncodingException, IOException {
if (!textAlready) {
XhtmlNode div = res.getNarrative();
if (div != null) {
if (div.allChildrenAreText())
x.getChildNodes().addAll(div.getChildNodes());
if (div.getChildNodes().size() == 1 && div.getChildNodes().get(0).allChildrenAreText())
x.getChildNodes().addAll(div.getChildNodes().get(0).getChildNodes());
}
x.tx("Generated Summary: ");
}
String path = res.getName();
StructureDefinition profile = context.fetchResource(StructureDefinition.class, path);
if (profile == null)
x.tx("unknown resource " + path);
else {
boolean firstElement = true;
boolean last = false;
for (PropertyWrapper p : res.children()) {
ElementDefinition child = getElementDefinition(profile.getSnapshot().getElement(), path + "." + p.getName(), p);
if (p.getValues().size() > 0 && p.getValues().get(0) != null && child != null && isPrimitive(child) && includeInSummary(child)) {
if (firstElement)
firstElement = false;
else if (last)
x.tx("; ");
boolean first = true;
last = false;
for (BaseWrapper v : p.getValues()) {
if (first)
first = false;
else if (last)
x.tx(", ");
last = displayLeaf(res, v, child, x, p.getName(), showCodeDetails, rc) || last;
}
}
}
}
}
use of org.hl7.fhir.r4b.renderers.utils.BaseWrappers.PropertyWrapper in project org.hl7.fhir.core by hapifhir.
the class NarrativeGenerator method splitExtensions.
private List<PropertyWrapper> splitExtensions(StructureDefinition profile, List<PropertyWrapper> children) throws UnsupportedEncodingException, IOException, FHIRException {
List<PropertyWrapper> results = new ArrayList<PropertyWrapper>();
Map<String, PropertyWrapper> map = new HashMap<String, PropertyWrapper>();
for (PropertyWrapper p : children) if (p.getName().equals("extension") || p.getName().equals("modifierExtension")) {
// we're going to split these up, and create a property for each url
if (p.hasValues()) {
for (BaseWrapper v : p.getValues()) {
Extension ex = (Extension) v.getBase();
String url = ex.getUrl();
StructureDefinition ed = context.fetchResource(StructureDefinition.class, url);
if (p.getName().equals("modifierExtension") && ed == null)
throw new DefinitionException("Unknown modifier extension " + url);
PropertyWrapper pe = map.get(p.getName() + "[" + url + "]");
if (pe == null) {
if (ed == null) {
if (url.startsWith("http://hl7.org/fhir"))
throw new DefinitionException("unknown extension " + url);
System.out.println("unknown extension " + url);
pe = new PropertyWrapperDirect(new Property(p.getName() + "[" + url + "]", p.getTypeCode(), p.getDefinition(), p.getMinCardinality(), p.getMaxCardinality(), ex));
} else {
ElementDefinition def = ed.getSnapshot().getElement().get(0);
pe = new PropertyWrapperDirect(new Property(p.getName() + "[" + url + "]", "Extension", def.getDefinition(), def.getMin(), def.getMax().equals("*") ? Integer.MAX_VALUE : Integer.parseInt(def.getMax()), ex));
((PropertyWrapperDirect) pe).wrapped.setStructure(ed);
}
results.add(pe);
} else
pe.getValues().add(v);
}
}
} else
results.add(p);
return results;
}
Aggregations