execute method

  1. @override
List execute(
  1. List results,
  2. Map<String, dynamic> passed
)
override

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) {
  final executedBefore = before.execute(results.toList(), passed);
  final executedAfter = after.execute(results.toList(), passed);
  if (executedBefore.isEmpty || executedAfter.isEmpty) {
    return [];
  } else if (executedBefore.length != 1 || executedAfter.length != 1) {
    throw FhirPathEvaluationException(
        'Math Operators require each operand to result in a '
        'single object. The "div" operator was passed the following:\n'
        'Operand 1: $executedBefore\n'
        'Operand 2: $executedAfter',
        operation: 'div',
        collection: results);
  } else if (executedBefore.first is num && executedAfter.first is num) {
    return (executedAfter.first != 0)
        ? [executedBefore.first ~/ executedAfter.first]
        : [];
  } else {
    throw FhirPathEvaluationException(
        'The "div" operator only accepts Integers, and Decimals, '
        'but was passed the following:\n'
        'Operand 1: ${executedBefore.first} (${executedBefore.first.runtimeType})\n'
        'Operand 2: ${executedAfter.first} (${executedAfter.first.runtimeType})',
        operation: 'div',
        collection: results);
  }
}