execute method
The iterable, nested function that evaluates the entire FHIRPath expression one object at a time
Implementation
@override
List execute(List results, Map<String, dynamic> passed) {
// The regular .execute method on CommaParser does not implement the
// short-circuit logic. Bespoke execution path required.
if (value.first is! CommaParser) {
// While this happens at eval time, it is due to incorrect syntax
throw FhirPathInvalidExpressionException(
'The function iif must have a criterion expression, followed by '
' a true-result collection, and an optional other-wise-result. '
'Instead it has: ${value.first}',
);
}
final CommaParser criterionResultParser = value.first as CommaParser;
FhirPathParser criterionExpressionParser;
FhirPathParser trueResultParser;
FhirPathParser? otherwiseResultParser;
if (criterionResultParser.before.first is CommaParser) {
criterionExpressionParser =
(criterionResultParser.before.first as CommaParser).before;
trueResultParser =
(criterionResultParser.before.first as CommaParser).after;
otherwiseResultParser = criterionResultParser.after;
} else {
criterionExpressionParser = criterionResultParser.before;
trueResultParser = criterionResultParser.after;
}
final criterionCollection =
criterionExpressionParser.execute(results.toList(), passed);
final criterion = SingletonEvaluation.toBool(criterionCollection,
name: 'criterion expression', operation: 'iif', collection: results);
// Short-circuit: Only evaluate what matches the criterion.
if (criterion == true) {
final newResults = trueResultParser.execute(results, passed);
return newResults;
} else {
if (otherwiseResultParser == null) {
return [];
} else {
return otherwiseResultParser.execute(results, passed);
}
}
}