From fb8974efd5faf3a1e08fd3036260b5f62ec719f0 Mon Sep 17 00:00:00 2001 From: Grahame Grieve Date: Sun, 17 Nov 2019 19:05:24 +1100 Subject: [PATCH] fix problem with rootResource and Bundles and contained resources --- .../fhir/r5/validation/InstanceValidator.java | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/org.hl7.fhir.validation/src/main/java/org/hl7/fhir/r5/validation/InstanceValidator.java b/org.hl7.fhir.validation/src/main/java/org/hl7/fhir/r5/validation/InstanceValidator.java index d9aabc531..d82d4e361 100644 --- a/org.hl7.fhir.validation/src/main/java/org/hl7/fhir/r5/validation/InstanceValidator.java +++ b/org.hl7.fhir.validation/src/main/java/org/hl7/fhir/r5/validation/InstanceValidator.java @@ -189,6 +189,15 @@ public class InstanceValidator extends BaseValidator implements IResourceValidat return res; } + public ValidatorHostContext forEntry(Element element) { + ValidatorHostContext res = new ValidatorHostContext(appContext); + res.rootResource = element; + res.resource = element; + res.container = resource; + res.profile = profile; + return res; + } + public ValidatorHostContext forProfile(StructureDefinition profile) { ValidatorHostContext res = new ValidatorHostContext(appContext); res.resource = resource; @@ -3917,10 +3926,15 @@ private boolean isAnswerRequirementFulfilled(QuestionnaireItemComponent qItem, L StructureDefinition profile = this.context.fetchResource(StructureDefinition.class, "http://hl7.org/fhir/StructureDefinition/" + resourceName); sdTime = sdTime + (System.nanoTime() - t); // special case: resource wrapper is reset if we're crossing a bundle boundary, but not otherwise - if (element.getSpecial() == SpecialElement.BUNDLE_ENTRY || element.getSpecial() == SpecialElement.BUNDLE_OUTCOME || element.getSpecial() == SpecialElement.PARAMETER ) + ValidatorHostContext hc = null; + if (element.getSpecial() == SpecialElement.BUNDLE_ENTRY || element.getSpecial() == SpecialElement.BUNDLE_OUTCOME || element.getSpecial() == SpecialElement.PARAMETER ) { resource = element; + hc = hostContext.forEntry(element); + } else { + hc = hostContext.forContained(element); + } if (rule(errors, IssueType.INVALID, element.line(), element.col(), stack.getLiteralPath(), profile != null, "No profile found for contained resource of type '" + resourceName + "'")) - validateResource(hostContext.forContained(element), errors, resource, element, profile, null, idstatus, stack, false); + validateResource(hc, errors, resource, element, profile, null, idstatus, stack, false); } private void validateDocument(List errors, List entries, Element composition, NodeStack stack, String fullUrl, String id) {