diff --git a/org.hl7.fhir.r5/src/main/java/org/hl7/fhir/r5/utils/FHIRPathEngine.java b/org.hl7.fhir.r5/src/main/java/org/hl7/fhir/r5/utils/FHIRPathEngine.java
index 67b995299..626edada1 100644
--- a/org.hl7.fhir.r5/src/main/java/org/hl7/fhir/r5/utils/FHIRPathEngine.java
+++ b/org.hl7.fhir.r5/src/main/java/org/hl7/fhir/r5/utils/FHIRPathEngine.java
@@ -1051,7 +1051,7 @@ public class FHIRPathEngine {
switch (exp.getFunction()) {
case Empty: return checkParamCount(lexer, location, exp, 0);
case Not: return checkParamCount(lexer, location, exp, 0);
- case Exists: return checkParamCount(lexer, location, exp, 0);
+ case Exists: return checkParamCount(lexer, location, exp, 0, 1);
case SubsetOf: return checkParamCount(lexer, location, exp, 1);
case SupersetOf: return checkParamCount(lexer, location, exp, 1);
case IsDistinct: return checkParamCount(lexer, location, exp, 0);
@@ -2381,8 +2381,10 @@ public class FHIRPathEngine {
return new TypeDetails(CollectionStatus.SINGLETON, TypeDetails.FP_Boolean);
case Not :
return new TypeDetails(CollectionStatus.SINGLETON, TypeDetails.FP_Boolean);
- case Exists :
+ case Exists : {
+ checkParamTypes(exp.getFunction().toCode(), paramTypes, new TypeDetails(CollectionStatus.SINGLETON, TypeDetails.FP_Boolean));
return new TypeDetails(CollectionStatus.SINGLETON, TypeDetails.FP_Boolean);
+ }
case SubsetOf : {
checkParamTypes(exp.getFunction().toCode(), paramTypes, focus);
return new TypeDetails(CollectionStatus.SINGLETON, TypeDetails.FP_Boolean);
@@ -3307,9 +3309,19 @@ public class FHIRPathEngine {
private List funcExists(ExecutionContext context, List focus, ExpressionNode exp) {
List result = new ArrayList();
boolean empty = true;
- for (Base f : focus)
- if (!f.isEmpty())
+ List pc = new ArrayList();
+ for (Base f : focus) {
+ if (exp.getParameters().size() == 1) {
+ pc.clear();
+ pc.add(f);
+ Equality v = asBool(execute(changeThis(context, f), pc, exp.getParameters().get(0), true));
+ if (v == Equality.True) {
+ empty = false;
+ }
+ } else if (!f.isEmpty()) {
empty = false;
+ }
+ }
result.add(new BooleanType(!empty).noExtensions());
return result;
}