fix issue with contained resources not rendering

This commit is contained in:
Grahame Grieve 2022-11-02 20:56:17 +11:00
parent ca96bbfdc4
commit c8bf2aa4e5
1 changed files with 38 additions and 22 deletions

View File

@ -68,6 +68,7 @@ import org.hl7.fhir.r5.renderers.utils.DirectWrappers;
import org.hl7.fhir.r5.renderers.utils.DirectWrappers.BaseWrapperDirect; import org.hl7.fhir.r5.renderers.utils.DirectWrappers.BaseWrapperDirect;
import org.hl7.fhir.r5.renderers.utils.DirectWrappers.PropertyWrapperDirect; import org.hl7.fhir.r5.renderers.utils.DirectWrappers.PropertyWrapperDirect;
import org.hl7.fhir.r5.renderers.utils.DirectWrappers.ResourceWrapperDirect; import org.hl7.fhir.r5.renderers.utils.DirectWrappers.ResourceWrapperDirect;
import org.hl7.fhir.r5.renderers.utils.ElementWrappers;
import org.hl7.fhir.r5.renderers.utils.RenderingContext; 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.ResourceContext;
import org.hl7.fhir.r5.renderers.utils.Resolver.ResourceWithReference; import org.hl7.fhir.r5.renderers.utils.Resolver.ResourceWithReference;
@ -103,7 +104,7 @@ public class ProfileDrivenRenderer extends ResourceRenderer {
boolean idDone = false; boolean idDone = false;
XhtmlNode p = x.para(); XhtmlNode p = x.para();
if (context.isAddGeneratedNarrativeHeader()) { if (context.isAddGeneratedNarrativeHeader()) {
p.b().tx("Generated Narrative: "+r.fhirType()); p.b().tx("Generated Narrative: "+r.fhirType()+(context.isContained() ? " #"+r.getId() : ""));
if (!Utilities.noString(r.getId())) { if (!Utilities.noString(r.getId())) {
p.an(r.getId()); p.an(r.getId());
} }
@ -756,35 +757,50 @@ public class ProfileDrivenRenderer extends ResourceRenderer {
if (children.isEmpty()) { if (children.isEmpty()) {
renderLeaf(res, e, defn, x, x, false, showCodeDetails, readDisplayHints(defn), path, indent); renderLeaf(res, e, defn, x, x, false, showCodeDetails, readDisplayHints(defn), path, indent);
} else { } else {
for (PropertyWrapper p : splitExtensions(profile, e.children())) { List<PropertyWrapper> pl = splitExtensions(profile, e.children());
if (p.hasValues()) { for (PropertyWrapper p : pl) {
ElementDefinition child = getElementDefinition(children, path+"."+p.getName(), p); generateForProperty(res, profile, allElements, children, x, path, showCodeDetails, indent, false, p);
if (child == null) { }
child = p.getElementDefinition(); for (PropertyWrapper p : pl) {
} generateForProperty(res, profile, allElements, children, x, path, showCodeDetails, indent, true, p);
if (child != null) { }
if (!child.getBase().hasPath() || !child.getBase().getPath().startsWith("Resource.")) { }
generateElementByProfile(res, profile, allElements, x, path, showCodeDetails, indent, p, child); }
}
} private void generateForProperty(ResourceWrapper res, StructureDefinition profile,
List<ElementDefinition> allElements, List<ElementDefinition> children, XhtmlNode x, String path,
boolean showCodeDetails, int indent, boolean round2, PropertyWrapper p)
throws UnsupportedEncodingException, IOException, EOperationOutcome {
if (p.hasValues()) {
ElementDefinition child = getElementDefinition(children, path+"."+p.getName(), p);
if (child == null) {
child = p.getElementDefinition();
}
if (child != null) {
if (!child.getBase().hasPath() || !child.getBase().getPath().startsWith("Resource.")) {
generateElementByProfile(res, profile, allElements, x, path, showCodeDetails, indent, p, child, round2);
} }
} }
} }
} }
public void generateElementByProfile(ResourceWrapper res, StructureDefinition profile, List<ElementDefinition> allElements, XhtmlNode x, String path, 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 { boolean showCodeDetails, int indent, PropertyWrapper p, ElementDefinition child, boolean round2) throws UnsupportedEncodingException, IOException, EOperationOutcome {
Map<String, String> displayHints = readDisplayHints(child); Map<String, String> displayHints = readDisplayHints(child);
if ("DomainResource.contained".equals(child.getBase().getPath())) { if ("DomainResource.contained".equals(child.getBase().getPath())) {
// for (BaseWrapper v : p.getValues()) { if (round2) {
// x.hr(); for (BaseWrapper v : p.getValues()) {
// RenderingContext ctxt = context.clone(); if (!RendererFactory.hasSpecificRenderer(v.fhirType())) {
// ctxt.setContained(true); x.hr();
// ResourceRenderer rnd = RendererFactory.factory(v.fhirType(), ctxt); RenderingContext ctxt = context.copy();
// ResourceWrapper rw = new ElementWrappers.ResourceWrapperMetaElement(ctxt, (org.hl7.fhir.r5.elementmodel.Element) v.getBase()); ctxt.setContained(true);
// rnd.render(x.blockquote(), rw); ResourceRenderer rnd = RendererFactory.factory(v.fhirType(), ctxt);
// } ResourceWrapper rw = new ElementWrappers.ResourceWrapperMetaElement(ctxt, (org.hl7.fhir.r5.elementmodel.Element) v.getBase());
} else if (!exemptFromRendering(child)) { rnd.render(x.blockquote(), rw);
}
}
}
} else if (!round2 && !exemptFromRendering(child)) {
if (isExtension(p)) { if (isExtension(p)) {
hasExtensions = true; hasExtensions = true;
} }