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 efdcd6c6c..d23f65a01 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 @@ -3629,7 +3629,10 @@ public class InstanceValidator extends BaseValidator implements IResourceValidat Element e = list.get(i); NodeStack ns = stack.push(e, i, e.getProperty().getDefinition(), e.getProperty().getDefinition()); validateQuestionnaireElement(errors, ns, questionnaire, e, parents); - validateQuestionannaireItem(errors, e, questionnaire, ns, list); + List np = new ArrayList(); + np.add(e); + np.addAll(parents); + validateQuestionannaireItem(errors, e, questionnaire, ns, np); } } @@ -3647,7 +3650,9 @@ public class InstanceValidator extends BaseValidator implements IResourceValidat tgt = getQuestionById(questionnaire, ql); if (rule(errors, IssueType.BUSINESSRULE, ns.literalPath, tgt != null, "Unable to find target '"+ql+"' for this question enableWhen")) { if (rule(errors, IssueType.BUSINESSRULE, ns.literalPath, tgt != item, "Target for this question enableWhen can't reference itself")) { - warning(errors, IssueType.BUSINESSRULE, ns.literalPath, isBefore(item, tgt, parents), "The target of this enableWhen rule ("+ql+") comes after the question itself"); + if (!isBefore(item, tgt, parents)) { + warning(errors, IssueType.BUSINESSRULE, ns.literalPath, false, "The target of this enableWhen rule ("+ql+") comes after the question itself"); + } } } } @@ -3659,6 +3664,10 @@ public class InstanceValidator extends BaseValidator implements IResourceValidat private boolean isBefore(Element item, Element tgt, List parents) { // we work up the list, looking for tgt in the children of the parents + if (parents.contains(tgt)) { + // actually, if the target is a parent, that's automatically ok + return true; + } for (Element p : parents) { int i = findIndex(p, item); int t = findIndex(p, tgt);