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 executedValue = value.execute(results.toList(), passed);
  final newResults = value.length != 1 || value.first is! IntegerParser
      ? throw FhirPathEvaluationException(
          'The argument passed to the .take() function was not valid:',
          operation: '.take()',
          arguments: value)
      : executedValue.first is! int
          ? throw FhirPathEvaluationException(
              'The value for .take() was not a number: $value',
              operation: '.take()',
              arguments: value)
          : (executedValue.first as int) <= 0 || results.isEmpty
              ? []
              : (executedValue.first as int) >= results.length
                  ? results
                  : results.sublist(0, executedValue.first as int);
  return newResults;
}