From 194e2113ce6940e6986871d2b9390566b1f632bb Mon Sep 17 00:00:00 2001 From: Grahame Grieve Date: Mon, 25 Sep 2023 13:50:02 +1000 Subject: [PATCH] Valid special cases on contained resources and Bundle entries --- .../hl7/fhir/validation/instance/InstanceValidator.java | 8 ++++++-- .../fhir/validation/instance/type/BundleValidator.java | 8 +++++--- 2 files changed, 11 insertions(+), 5 deletions(-) diff --git a/org.hl7.fhir.validation/src/main/java/org/hl7/fhir/validation/instance/InstanceValidator.java b/org.hl7.fhir.validation/src/main/java/org/hl7/fhir/validation/instance/InstanceValidator.java index 2adb56a1b..d5a43e4b1 100644 --- a/org.hl7.fhir.validation/src/main/java/org/hl7/fhir/validation/instance/InstanceValidator.java +++ b/org.hl7.fhir.validation/src/main/java/org/hl7/fhir/validation/instance/InstanceValidator.java @@ -5608,6 +5608,8 @@ public class InstanceValidator extends BaseValidator implements IResourceValidat break; } } + + checkSpecials(hostContext, errors, element, stack, ok, pct, mode); if (typeForResource.getProfile().size() == 1) { long t = System.nanoTime(); @@ -6665,8 +6667,10 @@ public class InstanceValidator extends BaseValidator implements IResourceValidat List performers = new ArrayList<>(); element.getNamedChildren("performer", performers); ok = bpCheck(errors, IssueType.INVALID, element.line(), element.col(), stack.getLiteralPath(), performers.size() > 0, I18nConstants.ALL_OBSERVATIONS_SHOULD_HAVE_A_PERFORMER) && ok; - ok = bpCheck(errors, IssueType.INVALID, element.line(), element.col(), stack.getLiteralPath(), element.getNamedChild("effectiveDateTime") != null || element.getNamedChild("effectivePeriod") != null, I18nConstants.ALL_OBSERVATIONS_SHOULD_HAVE_AN_EFFECTIVEDATETIME_OR_AN_EFFECTIVEPERIOD) && ok; - + ok = bpCheck(errors, IssueType.INVALID, element.line(), element.col(), stack.getLiteralPath(), + element.getNamedChild("effectiveDateTime") != null || element.getNamedChild("effectivePeriod") != null || + element.getNamedChild("effectiveTiming") != null || element.getNamedChild("effectiveInstant") != null, + I18nConstants.ALL_OBSERVATIONS_SHOULD_HAVE_AN_EFFECTIVEDATETIME_OR_AN_EFFECTIVEPERIOD, element.getProperty().typeSummary()) && ok; return ok; } diff --git a/org.hl7.fhir.validation/src/main/java/org/hl7/fhir/validation/instance/type/BundleValidator.java b/org.hl7.fhir.validation/src/main/java/org/hl7/fhir/validation/instance/type/BundleValidator.java index d5cbfa23b..a898da7c2 100644 --- a/org.hl7.fhir.validation/src/main/java/org/hl7/fhir/validation/instance/type/BundleValidator.java +++ b/org.hl7.fhir.validation/src/main/java/org/hl7/fhir/validation/instance/type/BundleValidator.java @@ -115,14 +115,14 @@ public class BundleValidator extends BaseValidator { String rtype = entry.getNamedChild(RESOURCE).fhirType(); int rcount = counter.containsKey(rtype) ? counter.get(rtype)+1 : 0; counter.put(rtype, rcount); + Element res = entry.getNamedChild(RESOURCE); + NodeStack rstack = estack.push(res, -1, null, null); for (BundleValidationRule bvr : validator().getBundleValidationRules()) { if (meetsRule(bvr, rtype, rcount, count)) { StructureDefinition defn = context.fetchResource(StructureDefinition.class, bvr.getProfile()); if (defn == null) { throw new Error(context.formatMessage(I18nConstants.BUNDLE_RULE_PROFILE_UNKNOWN, bvr.getRule(), bvr.getProfile())); } else { - Element res = entry.getNamedChild(RESOURCE); - NodeStack rstack = estack.push(res, -1, null, null); if (validator().isCrumbTrails()) { res.addMessage(signpost(errors, NO_RULE_DATE, IssueType.INFORMATIONAL, res.line(), res.col(), stack.getLiteralPath(), I18nConstants.VALIDATION_VAL_PROFILE_SIGNPOST_BUNDLE_PARAM, defn.getUrl())); } @@ -130,7 +130,9 @@ public class BundleValidator extends BaseValidator { ok = validator().startInner(hostContext, errors, res, res, defn, rstack, false, pct, mode) && ok; } } - } + } + // also, while we're here, check the specials, since this doesn't happen anywhere else + ((InstanceValidator) parent).checkSpecials(hostContext, errors, res, rstack, true, pct, mode); } // todo: check specials