fix rendering issues found in main build

This commit is contained in:
Grahame Grieve 2020-06-17 12:22:40 +10:00
parent c67c3c2892
commit faf31afda1
5 changed files with 92 additions and 38 deletions

View File

@ -17,6 +17,7 @@ import org.hl7.fhir.r5.renderers.utils.BaseWrappers.ResourceWrapper;
import org.hl7.fhir.r5.renderers.utils.DirectWrappers;
import org.hl7.fhir.r5.renderers.utils.RenderingContext;
import org.hl7.fhir.r5.renderers.utils.Resolver.ResourceContext;
import org.hl7.fhir.r5.renderers.utils.Resolver.ResourceWithReference;
import org.hl7.fhir.utilities.Utilities;
import org.hl7.fhir.utilities.xhtml.XhtmlNode;
@ -24,8 +25,8 @@ public class DiagnosticReportRenderer extends ResourceRenderer {
public class ObservationNode {
private String ref;
private ResourceWrapper obs;
private List<ObservationNode> contained = new ArrayList<ObservationNode>();
private ResourceWithReference obs;
private List<ObservationNode> contained;
}
@ -59,7 +60,7 @@ public class DiagnosticReportRenderer extends ResourceRenderer {
render(h2, getProperty(dr, "issued").value());
}
XhtmlNode tbl = x.table( "grid");
XhtmlNode tbl = x.table("grid");
XhtmlNode tr = tbl.tr();
XhtmlNode tdl = tr.td();
XhtmlNode tdr = tr.td();
@ -96,7 +97,7 @@ public class DiagnosticReportRenderer extends ResourceRenderer {
pw = getProperty(dr, "result");
if (valued(pw)) {
List<ObservationNode> observations = fetchObservations(pw.getValues());
List<ObservationNode> observations = fetchObservations(pw.getValues(), dr);
buildObservationsTable(x, observations);
}
@ -149,11 +150,25 @@ public class DiagnosticReportRenderer extends ResourceRenderer {
c.tx("to do");
}
private List<ObservationNode> fetchObservations(List<BaseWrapper> list) {
return new ArrayList<ObservationNode>();
private List<ObservationNode> fetchObservations(List<BaseWrapper> list, ResourceWrapper rw) throws UnsupportedEncodingException, FHIRException, IOException {
List<ObservationNode> res = new ArrayList<ObservationNode>();
for (BaseWrapper b : list) {
if (b.has("reference")) {
ObservationNode obs = new ObservationNode();
obs.ref = b.get("reference").primitiveValue();
obs.obs = resolveReference(rw, obs.ref);
if (obs.obs.getResource() != null) {
PropertyWrapper t = getProperty(obs.obs.getResource(), "contained");
if (t.hasValues()) {
obs.contained = fetchObservations(t.getValues(), rw);
}
}
res.add(obs);
}
}
return res;
}
private void buildObservationsTable(XhtmlNode root, List<ObservationNode> observations) {
XhtmlNode tbl = root.table( "none");
for (ObservationNode o : observations) {
@ -163,16 +178,21 @@ public class DiagnosticReportRenderer extends ResourceRenderer {
private void addObservationToTable(XhtmlNode tbl, ObservationNode o, int i) {
XhtmlNode tr = tbl.tr();
if (o.obs == null) {
if (o.obs.getReference() == null) {
XhtmlNode td = tr.td().colspan("6");
td.i().tx("This Observation could not be resolved");
} else {
addObservationToTable(tr, o.obs, i);
// todo: contained observations
}
for (ObservationNode c : o.contained) {
addObservationToTable(tbl, c, i+1);
}
if (o.obs.getResource() != null) {
addObservationToTable(tr, o.obs.getResource(), i);
} else {
tr.td().tx("Unable to resolve Observation: "+o.obs.getReference());
}
if (o.contained != null) {
for (ObservationNode c : o.contained) {
addObservationToTable(tbl, c, i+1);
}
}
}
}
private void addObservationToTable(XhtmlNode tr, ResourceWrapper obs, int i) {
@ -180,7 +200,7 @@ public class DiagnosticReportRenderer extends ResourceRenderer {
// code (+bodysite)
XhtmlNode td = tr.td();
PropertyWrapper pw = getProperty(obs, "result");
PropertyWrapper pw = getProperty(obs, "code");
if (valued(pw)) {
render(td, pw.value());
}
@ -195,12 +215,7 @@ public class DiagnosticReportRenderer extends ResourceRenderer {
td = tr.td();
pw = getProperty(obs, "value[x]");
if (valued(pw)) {
if (pw.getTypeCode().equals("CodeableConcept"))
render(td, pw.value());
else if (pw.getTypeCode().equals("string"))
render(td, pw.value());
else
td.addText(pw.getTypeCode()+" not rendered yet");
render(td, pw.value());
}
// units

View File

@ -53,6 +53,7 @@ public class ListRenderer extends ResourceRenderer {
td.tx("Code: "+displayBase(list.get("code")));
}
tr = t.tr();
td = tr.td();
if (list.has("subject")) {
td.tx("Subject: ");
shortForRef(td, list.get("subject"));
@ -80,27 +81,27 @@ public class ListRenderer extends ResourceRenderer {
}
t = x.table("grid");
tr = t.tr().style("backgound-color: #eeeeee");
td.b().tx("Items");
tr.td().b().tx("Items");
if (date) {
td.tx("Date");
tr.td().tx("Date");
}
if (flag) {
td.tx("Flag");
tr.td().tx("Flag");
}
if (deleted) {
td.tx("Deleted");
tr.td().tx("Deleted");
}
for (BaseWrapper e : list.children("entry")) {
tr = t.tr();
shortForRef(td, e.get("item"));
shortForRef(tr.td(), e.get("item"));
if (date) {
td.tx(e.has("date") ? e.get("date").dateTimeValue().toHumanDisplay() : "");
tr.td().tx(e.has("date") ? e.get("date").dateTimeValue().toHumanDisplay() : "");
}
if (flag) {
td.tx(e.has("flag") ? displayBase(e.get("flag")) : "");
tr.td().tx(e.has("flag") ? displayBase(e.get("flag")) : "");
}
if (deleted) {
td.tx(e.has("deleted") ? e.get("deleted").primitiveValue() : "");
tr.td().tx(e.has("deleted") ? e.get("deleted").primitiveValue() : "");
}
}
return false;
@ -211,8 +212,10 @@ public class ListRenderer extends ResourceRenderer {
disp = url;
}
x.tx(disp);
} else {
} else if (r.getResource() != null) {
RendererFactory.factory(r.getResource().getName(), context).renderReference(r.getResource(), x, (Reference) ref);
} else {
RendererFactory.factory(url, context).renderReference(r.getResource(), x, (Reference) ref);
}
} else if (disp != null) {
x.tx(disp);

View File

@ -21,6 +21,7 @@ import org.hl7.fhir.r5.model.Base64BinaryType;
import org.hl7.fhir.r5.model.BooleanType;
import org.hl7.fhir.r5.model.CodeType;
import org.hl7.fhir.r5.model.CodeableConcept;
import org.hl7.fhir.r5.model.CodeableReference;
import org.hl7.fhir.r5.model.Coding;
import org.hl7.fhir.r5.model.ContactDetail;
import org.hl7.fhir.r5.model.ContactPoint;
@ -227,7 +228,7 @@ public class ProfileDrivenRenderer extends ResourceRenderer {
first = false;
else if (last)
x.tx(", ");
last = displayLeaf(res, v, child, x, p.getName(), showCodeDetails) || last;
last = displayLeaf(res, v, child, x, p.getName(), showCodeDetails, false) || last;
}
}
}
@ -353,6 +354,10 @@ public class ProfileDrivenRenderer extends ResourceRenderer {
}
private boolean displayLeaf(ResourceWrapper res, BaseWrapper ew, ElementDefinition defn, XhtmlNode x, String name, boolean showCodeDetails) throws FHIRException, UnsupportedEncodingException, IOException {
return displayLeaf(res, ew, defn, x, name, showCodeDetails, true);
}
private boolean displayLeaf(ResourceWrapper res, BaseWrapper ew, ElementDefinition defn, XhtmlNode x, String name, boolean showCodeDetails, boolean allowLinks) throws FHIRException, UnsupportedEncodingException, IOException {
if (ew == null)
return false;
Base e = ew.getBase();
@ -399,6 +404,14 @@ public class ProfileDrivenRenderer extends ResourceRenderer {
x.addText(name);
return true;
}
} else if (e instanceof CodeableReference) {
if (((CodeableReference) e).hasReference()) {
Reference r = ((CodeableReference) e).getReference();
renderReference(res, x, r, allowLinks);
} else {
renderCodeableConcept(x, ((CodeableReference) e).getConcept(), showCodeDetails);
}
return true;
} else if (e instanceof CodeableConcept) {
renderCodeableConcept(x, (CodeableConcept) e, showCodeDetails);
return true;

View File

@ -118,9 +118,13 @@ public abstract class ResourceRenderer extends DataRenderer {
}
public void renderReference(ResourceWrapper rw, XhtmlNode x, Reference r) throws UnsupportedEncodingException, IOException {
XhtmlNode c = x;
renderReference(rw, x, r, true);
}
public void renderReference(ResourceWrapper rw, XhtmlNode x, Reference r, boolean allowLinks) throws UnsupportedEncodingException, IOException {
XhtmlNode c = null;
ResourceWithReference tr = null;
if (r.hasReferenceElement()) {
if (r.hasReferenceElement() && allowLinks) {
tr = resolveReference(rw, r.getReference());
if (!r.getReference().startsWith("#")) {
@ -129,6 +133,8 @@ public abstract class ResourceRenderer extends DataRenderer {
else
c = x.ah(r.getReference());
}
} else {
c = x.span(null, null);
}
// what to display: if text is provided, then that. if the reference was resolved, then show the generated narrative
if (r.hasDisplayElement()) {
@ -178,7 +184,7 @@ public abstract class ResourceRenderer extends DataRenderer {
protected ResourceWithReference resolveReference(ResourceWrapper res, String url) {
if (url == null)
return null;
if (url.startsWith("#")) {
if (url.startsWith("#") && res != null) {
for (ResourceWrapper r : res.getContained()) {
if (r.getId().equals(url.substring(1)))
return new ResourceWithReference(null, r);
@ -249,8 +255,12 @@ public abstract class ResourceRenderer extends DataRenderer {
protected ResourceWrapper fetchResource(BaseWrapper subject) throws UnsupportedEncodingException, FHIRException, IOException {
if (context.getResolver() == null)
return null;
String url = subject.getChildByName("reference").value().getBase().primitiveValue();
PropertyWrapper ref = subject.getChildByName("reference");
if (ref == null || !ref.hasValues()) {
return null;
}
String url = ref.value().getBase().primitiveValue();
ResourceWithReference rr = context.getResolver().resolve(context, url);
return rr == null ? null : rr.getResource();
}

View File

@ -64,6 +64,10 @@ public class DOMWrappers {
public List<PropertyWrapper> children() {
if (list == null) {
children = context.getProfileUtilities().getChildList(structure, definition);
if (children.isEmpty() && type != null) {
StructureDefinition sdt = context.getWorker().fetchTypeDefinition(type);
children = context.getProfileUtilities().getChildList(sdt, sdt.getSnapshot().getElementFirstRep());
}
list = new ArrayList<PropertyWrapper>();
for (ElementDefinition child : children) {
List<Element> elements = new ArrayList<Element>();
@ -140,8 +144,17 @@ public class DOMWrappers {
@Override
public String getTypeCode() {
if (definition == null || definition.getType().size() != 1)
throw new Error("not handled");
if (definition == null || definition.getType().size() != 1) {
if (values.size() != 1) {
throw new Error("not handled");
}
String tn = values.get(0).getLocalName().substring(tail(definition.getPath()).replace("[x]", "").length());
if (isPrimitive(Utilities.uncapitalize(tn))) {
return Utilities.uncapitalize(tn);
} else {
return tn;
}
}
return definition.getType().get(0).getWorkingCode();
}