From 31ffd846672bc5347decb9765151a1896f073fa3 Mon Sep 17 00:00:00 2001 From: Grahame Grieve Date: Fri, 24 Nov 2023 08:49:59 +1100 Subject: [PATCH] Checking parameter type for where() and all() --- .../src/main/java/org/hl7/fhir/r5/model/TypeDetails.java | 9 +++++++++ .../main/java/org/hl7/fhir/r5/utils/FHIRPathEngine.java | 4 +++- 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/org.hl7.fhir.r5/src/main/java/org/hl7/fhir/r5/model/TypeDetails.java b/org.hl7.fhir.r5/src/main/java/org/hl7/fhir/r5/model/TypeDetails.java index 6905e9ef4..fb918f501 100644 --- a/org.hl7.fhir.r5/src/main/java/org/hl7/fhir/r5/model/TypeDetails.java +++ b/org.hl7.fhir.r5/src/main/java/org/hl7/fhir/r5/model/TypeDetails.java @@ -44,6 +44,7 @@ import org.hl7.fhir.exceptions.DefinitionException; import org.hl7.fhir.r5.context.IWorkerContext; import org.hl7.fhir.r5.model.ElementDefinition.ElementDefinitionBindingComponent; import org.hl7.fhir.r5.model.ExpressionNode.CollectionStatus; +import org.hl7.fhir.r5.model.StructureDefinition.StructureDefinitionKind; import org.hl7.fhir.r5.model.TypeDetails.ProfiledTypeSorter; import org.hl7.fhir.utilities.CommaSeparatedStringBuilder; import org.hl7.fhir.utilities.Utilities; @@ -253,6 +254,14 @@ public class TypeDetails { return true; } } + t = ProfiledType.ns(n); + StructureDefinition sd = context.fetchTypeDefinition(t); + if (sd != null && sd.getKind() != StructureDefinitionKind.LOGICAL && Utilities.existsInList(sd.getType(), "boolean", "string", "integer", "decimal", "Quantity", "dateTime", "time")) { + t = FP_NS+"System."+Utilities.capitalize(sd.getType()); + if (typesContains(t)) { + return true; + } + } } for (String n: tn) { String id = n.contains("#") ? n.substring(0, n.indexOf("#")) : n; 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 dea5b4b99..940383481 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 @@ -3272,6 +3272,7 @@ public class FHIRPathEngine { case Count : return new TypeDetails(CollectionStatus.SINGLETON, TypeDetails.FP_Integer); case Where : + checkParamTypes(exp, exp.getFunction().toCode(), paramTypes, new TypeDetails(CollectionStatus.SINGLETON, TypeDetails.FP_Boolean)); // special case: where the focus is Reference, and the parameter to where is resolve() "is", we will suck up the target types if (focus.hasType("Reference")) { boolean canRestrictTargets = !exp.getParameters().isEmpty(); @@ -3298,6 +3299,7 @@ public class FHIRPathEngine { case Select : return paramTypes.get(0); case All : + checkParamTypes(exp, exp.getFunction().toCode(), paramTypes, new TypeDetails(CollectionStatus.SINGLETON, TypeDetails.FP_Boolean)); return new TypeDetails(CollectionStatus.SINGLETON, TypeDetails.FP_Boolean); case Repeat : return paramTypes.get(0); @@ -3681,7 +3683,7 @@ public class FHIRPathEngine { } - private void checkParamTypes(ExpressionNode expr, String funcName, List paramTypes, TypeDetails... typeSet) throws PathEngineException { + private void checkParamTypes(ExpressionNode expr, String funcName,List paramTypes, TypeDetails... typeSet) throws PathEngineException { int i = 0; for (TypeDetails pt : typeSet) { if (i == paramTypes.size()) {