From 413c047b561dbfe972096ed9e63b2e2a6fa93237 Mon Sep 17 00:00:00 2001 From: Grahame Grieve Date: Mon, 18 Mar 2024 14:35:59 +1100 Subject: [PATCH] more fixing rendering --- .../hl7/fhir/r5/renderers/utils/BaseWrappers.java | 1 + .../hl7/fhir/r5/renderers/utils/DOMWrappers.java | 13 +++++++++++++ .../hl7/fhir/r5/renderers/utils/DirectWrappers.java | 6 ++++++ .../fhir/r5/renderers/utils/ElementWrappers.java | 5 +++++ 4 files changed, 25 insertions(+) diff --git a/org.hl7.fhir.r5/src/main/java/org/hl7/fhir/r5/renderers/utils/BaseWrappers.java b/org.hl7.fhir.r5/src/main/java/org/hl7/fhir/r5/renderers/utils/BaseWrappers.java index 67a09994d..66ba376f7 100644 --- a/org.hl7.fhir.r5/src/main/java/org/hl7/fhir/r5/renderers/utils/BaseWrappers.java +++ b/org.hl7.fhir.r5/src/main/java/org/hl7/fhir/r5/renderers/utils/BaseWrappers.java @@ -62,6 +62,7 @@ public class BaseWrappers { public interface BaseWrapper extends WrapperBase { public Base getBase() throws UnsupportedEncodingException, IOException, FHIRException; + public ResourceWrapper getResource() throws UnsupportedEncodingException, IOException, FHIRException; // for contained, etc public PropertyWrapper getChildByName(String tail); public String fhirType(); } diff --git a/org.hl7.fhir.r5/src/main/java/org/hl7/fhir/r5/renderers/utils/DOMWrappers.java b/org.hl7.fhir.r5/src/main/java/org/hl7/fhir/r5/renderers/utils/DOMWrappers.java index d62204ca6..8f33c2980 100644 --- a/org.hl7.fhir.r5/src/main/java/org/hl7/fhir/r5/renderers/utils/DOMWrappers.java +++ b/org.hl7.fhir.r5/src/main/java/org/hl7/fhir/r5/renderers/utils/DOMWrappers.java @@ -102,6 +102,19 @@ public class DOMWrappers { return type; } + @Override + public ResourceWrapper getResource() throws UnsupportedEncodingException, IOException, FHIRException { + Element r = XMLUtil.getFirstChild(element); + StructureDefinition sd = getContext().getContext().fetchTypeDefinition(r.getLocalName()); + if (sd == null) { + throw new FHIRException("Unable to find definition for type "+type+" @ "+definition.getPath()); + } + if (sd.getKind() != StructureDefinitionKind.RESOURCE) { + throw new FHIRException("Definition for type "+type+" is not for a resource @ "+definition.getPath()); + } + return new ResourceWrapperElement(context, r, sd); + } + } public static class PropertyWrapperElement extends RendererWrapperImpl implements PropertyWrapper { diff --git a/org.hl7.fhir.r5/src/main/java/org/hl7/fhir/r5/renderers/utils/DirectWrappers.java b/org.hl7.fhir.r5/src/main/java/org/hl7/fhir/r5/renderers/utils/DirectWrappers.java index 37304c3a9..b7c72d40f 100644 --- a/org.hl7.fhir.r5/src/main/java/org/hl7/fhir/r5/renderers/utils/DirectWrappers.java +++ b/org.hl7.fhir.r5/src/main/java/org/hl7/fhir/r5/renderers/utils/DirectWrappers.java @@ -5,6 +5,7 @@ import java.io.UnsupportedEncodingException; import java.util.ArrayList; import java.util.List; +import org.hl7.fhir.exceptions.FHIRException; import org.hl7.fhir.r5.model.Base; import org.hl7.fhir.r5.model.CanonicalResource; import org.hl7.fhir.r5.model.DomainResource; @@ -164,6 +165,11 @@ public class DirectWrappers { return wrapped.fhirType(); } + @Override + public ResourceWrapper getResource() throws UnsupportedEncodingException, IOException, FHIRException { + return new DirectWrappers.ResourceWrapperDirect(getContext(), (Resource) wrapped); + } + } public static class ResourceWrapperDirect extends WrapperBaseImpl implements ResourceWrapper { diff --git a/org.hl7.fhir.r5/src/main/java/org/hl7/fhir/r5/renderers/utils/ElementWrappers.java b/org.hl7.fhir.r5/src/main/java/org/hl7/fhir/r5/renderers/utils/ElementWrappers.java index 568344a5f..fcdb83fae 100644 --- a/org.hl7.fhir.r5/src/main/java/org/hl7/fhir/r5/renderers/utils/ElementWrappers.java +++ b/org.hl7.fhir.r5/src/main/java/org/hl7/fhir/r5/renderers/utils/ElementWrappers.java @@ -109,6 +109,11 @@ public class ElementWrappers { return element.fhirType(); } + @Override + public ResourceWrapper getResource() throws UnsupportedEncodingException, IOException, FHIRException { + return new ElementWrappers.ResourceWrapperMetaElement(getContext(), element); + } + } public static class ResourceWrapperMetaElement extends WrapperBaseImpl implements ResourceWrapper {