From 6a66f37898efb7d4776ae83415d9cd4b5f73fe4b Mon Sep 17 00:00:00 2001 From: Grahame Grieve Date: Fri, 28 Jun 2024 09:06:42 +1000 Subject: [PATCH] fix rendering bugs (#1671) * fix rendering bugs * release notes --------- Co-authored-by: Grahame Grieve --- RELEASE_NOTES.md | 2 +- .../java/org/hl7/fhir/r5/renderers/PatientRenderer.java | 8 ++++---- .../org/hl7/fhir/r5/renderers/ProfileDrivenRenderer.java | 4 ++-- .../java/org/hl7/fhir/r5/renderers/ResourceRenderer.java | 3 +++ .../fhir/r5/renderers/utils/ResourceWrapperNative.java | 2 +- 5 files changed, 11 insertions(+), 8 deletions(-) diff --git a/RELEASE_NOTES.md b/RELEASE_NOTES.md index 7b06c6ab5..f84f64fa9 100644 --- a/RELEASE_NOTES.md +++ b/RELEASE_NOTES.md @@ -4,4 +4,4 @@ ## Other code changes -* no changes \ No newline at end of file +* Rendering fixes diff --git a/org.hl7.fhir.r5/src/main/java/org/hl7/fhir/r5/renderers/PatientRenderer.java b/org.hl7.fhir.r5/src/main/java/org/hl7/fhir/r5/renderers/PatientRenderer.java index 1a97548b0..45513a24d 100644 --- a/org.hl7.fhir.r5/src/main/java/org/hl7/fhir/r5/renderers/PatientRenderer.java +++ b/org.hl7.fhir.r5/src/main/java/org/hl7/fhir/r5/renderers/PatientRenderer.java @@ -685,10 +685,10 @@ public class PatientRenderer extends ResourceRenderer { private boolean hasRenderablePhoto(ResourceWrapper r) throws UnsupportedEncodingException, FHIRException, IOException { if (r.has("photo")) { List a = r.children("photo"); - for (ResourceWrapper v : a) { - Attachment att = (Attachment) v.getBase(); - if (att.hasContentType() && att.getContentType().startsWith("image/") && - att.getData() != null && (!context.isInlineGraphics() || (att.getData().length > 0 && att.getData().length < MAX_IMAGE_LENGTH))) { + for (ResourceWrapper att : a) { + if (att.has("contentType") && att.primitiveValue("contentType").startsWith("image/") && + att.has("data") && (!context.isInlineGraphics() || (att.primitiveValue("data").length() > 0 && + att.primitiveValue("data").length() < MAX_IMAGE_LENGTH))) { return true; } } diff --git a/org.hl7.fhir.r5/src/main/java/org/hl7/fhir/r5/renderers/ProfileDrivenRenderer.java b/org.hl7.fhir.r5/src/main/java/org/hl7/fhir/r5/renderers/ProfileDrivenRenderer.java index 23bf207cc..a601cae03 100644 --- a/org.hl7.fhir.r5/src/main/java/org/hl7/fhir/r5/renderers/ProfileDrivenRenderer.java +++ b/org.hl7.fhir.r5/src/main/java/org/hl7/fhir/r5/renderers/ProfileDrivenRenderer.java @@ -169,8 +169,8 @@ public class ProfileDrivenRenderer extends ResourceRenderer { } else if (ew.fhirType().equals("ElementDefinition")) { x.tx("todo-bundle"); } else if (!renderDataType(status, parent, x, ew)) { - if (Utilities.existsInList(ew.fhirType(), "Attachment", "Narrative", "Meta", "ProductShelfLife", "RelatedArtifact")) { - throw new NotImplementedException("type "+ew.fhirType()+" not handled. This may be due to unresolved inter-version compatibility issues"); + if (!Utilities.existsInList(ew.fhirType(), "Narrative", "Meta", "ProductShelfLife", "RelatedArtifact")) { + throw new NotImplementedException("type "+ew.fhirType()+" not handled by the rendering framework"); } } } diff --git a/org.hl7.fhir.r5/src/main/java/org/hl7/fhir/r5/renderers/ResourceRenderer.java b/org.hl7.fhir.r5/src/main/java/org/hl7/fhir/r5/renderers/ResourceRenderer.java index d30cce27d..70f691e82 100644 --- a/org.hl7.fhir.r5/src/main/java/org/hl7/fhir/r5/renderers/ResourceRenderer.java +++ b/org.hl7.fhir.r5/src/main/java/org/hl7/fhir/r5/renderers/ResourceRenderer.java @@ -341,6 +341,9 @@ public abstract class ResourceRenderer extends DataRenderer { if (rr == null) { String disp = display != null && display.hasPrimitiveValue() ? displayDataType(display) : actual.primitiveValue(); x.ah(context.prefixLocalHref(actual.primitiveValue())).tx(disp); + } else if (rr.getResource() == null) { + String disp = display != null && display.hasPrimitiveValue() ? displayDataType(display) : "??"; + x.ah(context.prefixLocalHref(rr.getWebPath())).tx(disp); } else { String disp = display != null && display.hasPrimitiveValue() ? displayDataType(display) : RendererFactory.factory(rr.getResource(), context.forContained()).buildSummary(rr.getResource()); x.ah(context.prefixLocalHref(rr.getWebPath())).tx(disp); diff --git a/org.hl7.fhir.r5/src/main/java/org/hl7/fhir/r5/renderers/utils/ResourceWrapperNative.java b/org.hl7.fhir.r5/src/main/java/org/hl7/fhir/r5/renderers/utils/ResourceWrapperNative.java index 95738e245..f8aab4392 100644 --- a/org.hl7.fhir.r5/src/main/java/org/hl7/fhir/r5/renderers/utils/ResourceWrapperNative.java +++ b/org.hl7.fhir.r5/src/main/java/org/hl7/fhir/r5/renderers/utils/ResourceWrapperNative.java @@ -195,7 +195,7 @@ public class ResourceWrapperNative extends ResourceWrapper { public Resource getResourceNative() { ResourceWrapper focus = getResourceWrapper(); - return (Resource) ((ResourceWrapperNative) focus).element; + return focus == null ? null : (Resource) ((ResourceWrapperNative) focus).element; } public boolean hasFormatComment() {