fhirpath iif() test case fixes

This commit is contained in:
Grahame Grieve 2023-11-22 07:52:47 +11:00
parent 2e19e6bbc1
commit 6aaff35495
3 changed files with 54 additions and 18 deletions

View File

@ -3338,9 +3338,11 @@ public class FHIRPathEngine {
}
case Iif: {
TypeDetails types = new TypeDetails(null);
types.update(paramTypes.get(0));
if (paramTypes.size() > 1) {
types.update(paramTypes.get(1));
checkSingleton(focus, "iif", exp);
checkParamTypes(exp, exp.getFunction().toCode(), paramTypes, new TypeDetails(CollectionStatus.SINGLETON, TypeDetails.FP_Boolean));
types.update(paramTypes.get(1));
if (paramTypes.size() > 2) {
types.update(paramTypes.get(2));
}
return types;
}
@ -3646,6 +3648,12 @@ public class FHIRPathEngine {
}
}
private void checkSingleton(TypeDetails focus, String name, ExpressionNode expr) throws PathEngineException {
if (focus.getCollectionStatus() != CollectionStatus.SINGLETON) {
// typeWarnings.add(new IssueMessage(worker.formatMessage(I18nConstants.FHIRPATH_COLLECTION_STATUS_CONTEXT, name, expr.toString()), I18nConstants.FHIRPATH_COLLECTION_STATUS_CONTEXT));
}
}
private void checkOrdered(TypeDetails focus, String name, ExpressionNode expr) throws PathEngineException {
if (focus.getCollectionStatus() == CollectionStatus.UNORDERED) {
throw makeException(expr, I18nConstants.FHIRPATH_ORDERED_ONLY, name);
@ -4806,9 +4814,12 @@ public class FHIRPathEngine {
}
private List<Base> funcIif(ExecutionContext context, List<Base> focus, ExpressionNode exp) throws FHIRException {
List<Base> n1 = execute(context, focus, exp.getParameters().get(0), true);
if (focus.size() > 1) {
throw makeException(exp, I18nConstants.FHIRPATH_NO_COLLECTION, "iif", focus.size());
}
List<Base> n1 = execute(focus.isEmpty() ? context : changeThis(context, focus.get(0)), focus, exp.getParameters().get(0), true);
Equality v = asBool(n1, exp);
if (v == Equality.True) {
return execute(context, focus, exp.getParameters().get(1), true);
} else if (exp.getParameters().size() < 3) {
@ -4817,7 +4828,7 @@ public class FHIRPathEngine {
return execute(context, focus, exp.getParameters().get(2), true);
}
}
private List<Base> funcTake(ExecutionContext context, List<Base> focus, ExpressionNode exp) throws FHIRException {
List<Base> n1 = execute(context, focus, exp.getParameters().get(0), true);
int i1 = Integer.parseInt(n1.get(0).primitiveValue());
@ -4849,7 +4860,7 @@ public class FHIRPathEngine {
for (Base item : focus) {
result.add(item);
}
for (Base item : execute(context, focus, exp.getParameters().get(0), true)) {
for (Base item : execute(context, baseToList(context.thisItem), exp.getParameters().get(0), true)) {
result.add(item);
}
return result;

View File

@ -3340,9 +3340,11 @@ public class FHIRPathEngine {
}
case Iif: {
TypeDetails types = new TypeDetails(null);
types.update(paramTypes.get(0));
if (paramTypes.size() > 1) {
types.update(paramTypes.get(1));
checkSingleton(focus, "iif", exp);
checkParamTypes(exp, exp.getFunction().toCode(), paramTypes, new TypeDetails(CollectionStatus.SINGLETON, TypeDetails.FP_Boolean));
types.update(paramTypes.get(1));
if (paramTypes.size() > 2) {
types.update(paramTypes.get(2));
}
return types;
}
@ -3647,6 +3649,12 @@ public class FHIRPathEngine {
}
}
}
private void checkSingleton(TypeDetails focus, String name, ExpressionNode expr) throws PathEngineException {
if (focus.getCollectionStatus() != CollectionStatus.SINGLETON) {
// typeWarnings.add(new IssueMessage(worker.formatMessage(I18nConstants.FHIRPATH_COLLECTION_STATUS_CONTEXT, name, expr.toString()), I18nConstants.FHIRPATH_COLLECTION_STATUS_CONTEXT));
}
}
private void checkOrdered(TypeDetails focus, String name, ExpressionNode expr) throws PathEngineException {
if (focus.getCollectionStatus() == CollectionStatus.UNORDERED) {
@ -4809,9 +4817,12 @@ public class FHIRPathEngine {
}
private List<Base> funcIif(ExecutionContext context, List<Base> focus, ExpressionNode exp) throws FHIRException {
List<Base> n1 = execute(context, focus, exp.getParameters().get(0), true);
if (focus.size() > 1) {
throw makeException(exp, I18nConstants.FHIRPATH_NO_COLLECTION, "iif", focus.size());
}
List<Base> n1 = execute(focus.isEmpty() ? context : changeThis(context, focus.get(0)), focus, exp.getParameters().get(0), true);
Equality v = asBool(n1, exp);
if (v == Equality.True) {
return execute(context, focus, exp.getParameters().get(1), true);
} else if (exp.getParameters().size() < 3) {
@ -4852,7 +4863,7 @@ public class FHIRPathEngine {
for (Base item : focus) {
result.add(item);
}
for (Base item : execute(context, focus, exp.getParameters().get(0), true)) {
for (Base item : execute(context, baseToList(context.thisItem), exp.getParameters().get(0), true)) {
result.add(item);
}
return result;

View File

@ -3383,9 +3383,11 @@ public class FHIRPathEngine {
}
case Iif : {
TypeDetails types = new TypeDetails(null);
types.update(paramTypes.get(0));
if (paramTypes.size() > 1) {
types.update(paramTypes.get(1));
checkSingleton(focus, "iif", exp);
checkParamTypes(exp, exp.getFunction().toCode(), paramTypes, new TypeDetails(CollectionStatus.SINGLETON, TypeDetails.FP_Boolean));
types.update(paramTypes.get(1));
if (paramTypes.size() > 2) {
types.update(paramTypes.get(2));
}
return types;
}
@ -3692,6 +3694,15 @@ public class FHIRPathEngine {
throw makeException(expr, I18nConstants.FHIRPATH_WRONG_PARAM_TYPE, funcName, i, a, pt.toString());
}
}
if (actual.getCollectionStatus() != CollectionStatus.SINGLETON && pt.getCollectionStatus() == CollectionStatus.SINGLETON) {
typeWarnings.add(new IssueMessage(worker.formatMessage(I18nConstants.FHIRPATH_COLLECTION_STATUS_PARAMETER, funcName, i, expr.toString()), I18nConstants.FHIRPATH_COLLECTION_STATUS_PARAMETER));
}
}
}
private void checkSingleton(TypeDetails focus, String name, ExpressionNode expr) throws PathEngineException {
if (focus.getCollectionStatus() != CollectionStatus.SINGLETON) {
typeWarnings.add(new IssueMessage(worker.formatMessage(I18nConstants.FHIRPATH_COLLECTION_STATUS_CONTEXT, name, expr.toString()), I18nConstants.FHIRPATH_COLLECTION_STATUS_CONTEXT));
}
}
@ -4811,9 +4822,12 @@ public class FHIRPathEngine {
private List<Base> funcIif(ExecutionContext context, List<Base> focus, ExpressionNode exp) throws FHIRException {
List<Base> n1 = execute(context, focus, exp.getParameters().get(0), true);
if (focus.size() > 1) {
throw makeException(exp, I18nConstants.FHIRPATH_NO_COLLECTION, "iif", focus.size());
}
List<Base> n1 = execute(focus.isEmpty() ? context : changeThis(context, focus.get(0)), focus, exp.getParameters().get(0), true);
Equality v = asBool(n1, exp);
if (v == Equality.True) {
return execute(context, focus, exp.getParameters().get(1), true);
} else if (exp.getParameters().size() < 3) {