From 284c0e53353b0e73dd781eec17e0499597f56d6a Mon Sep 17 00:00:00 2001 From: Grahame Grieve Date: Thu, 21 Nov 2024 20:36:18 +1100 Subject: [PATCH] NPE fixes --- .../java/org/hl7/fhir/r5/elementmodel/Element.java | 14 ++++++++++++++ .../org/hl7/fhir/r5/fhirpath/FHIRPathEngine.java | 9 +++++++-- .../org/hl7/fhir/r5/renderers/BundleRenderer.java | 2 +- 3 files changed, 22 insertions(+), 3 deletions(-) diff --git a/org.hl7.fhir.r5/src/main/java/org/hl7/fhir/r5/elementmodel/Element.java b/org.hl7.fhir.r5/src/main/java/org/hl7/fhir/r5/elementmodel/Element.java index 7d0b7a6e1..3fe1814a6 100644 --- a/org.hl7.fhir.r5/src/main/java/org/hl7/fhir/r5/elementmodel/Element.java +++ b/org.hl7.fhir.r5/src/main/java/org/hl7/fhir/r5/elementmodel/Element.java @@ -1110,6 +1110,20 @@ public class Element extends Base implements NamedItem { return null; } + public String getExtensionString(String url) { + if (children != null) { + for (Element child : children) { + if (extensionList.contains(child.getName())) { + String u = child.getChildValue("url"); + if (url.equals(u)) { + return child.getNamedChildValue("value"); + } + } + } + } + return null; + } + public List getExtensions(String url) { List list = new ArrayList<>(); if (children != null) { diff --git a/org.hl7.fhir.r5/src/main/java/org/hl7/fhir/r5/fhirpath/FHIRPathEngine.java b/org.hl7.fhir.r5/src/main/java/org/hl7/fhir/r5/fhirpath/FHIRPathEngine.java index cdec2b25d..558f1bb17 100644 --- a/org.hl7.fhir.r5/src/main/java/org/hl7/fhir/r5/fhirpath/FHIRPathEngine.java +++ b/org.hl7.fhir.r5/src/main/java/org/hl7/fhir/r5/fhirpath/FHIRPathEngine.java @@ -6572,8 +6572,13 @@ public class FHIRPathEngine { } private ElementDefinitionMatch getElementDefinitionById(StructureDefinition sd, String ref) { - if (ref.startsWith(sd.getUrl()+"#")) { - ref = ref.replace(sd.getUrl()+"#", "#"); + StructureDefinition sdt = sd; + while (sdt != null) { + if (ref.startsWith(sdt.getUrl()+"#")) { + ref = ref.replace(sdt.getUrl()+"#", "#"); + break; + } + sdt = worker.fetchResource(StructureDefinition.class, sdt.getBaseDefinition()); } for (ElementDefinition ed : sd.getSnapshot().getElement()) { if (ref.equals("#"+ed.getId())) { diff --git a/org.hl7.fhir.r5/src/main/java/org/hl7/fhir/r5/renderers/BundleRenderer.java b/org.hl7.fhir.r5/src/main/java/org/hl7/fhir/r5/renderers/BundleRenderer.java index 0b40c7fa7..cbdb7f5a1 100644 --- a/org.hl7.fhir.r5/src/main/java/org/hl7/fhir/r5/renderers/BundleRenderer.java +++ b/org.hl7.fhir.r5/src/main/java/org/hl7/fhir/r5/renderers/BundleRenderer.java @@ -289,7 +289,7 @@ public class BundleRenderer extends ResourceRenderer { public static boolean allEntriesAreHistoryProvenance(List entries) throws UnsupportedEncodingException, FHIRException, IOException { for (ResourceWrapper be : entries) { - if (!"Provenance".equals(be.child("resource").fhirType())) { + if (!be.has("child") || !"Provenance".equals(be.child("resource").fhirType())) { return false; } }