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.length > 1 || executedAfter.length > 1) {
    throw FhirPathEvaluationException(
        'String concatenation operates on 2 single items. '
        'The "&" operator was passed the following:\n'
        'Operand 1: $executedBefore\n'
        'Operand 2: $executedAfter',
        operation: '&',
        collection: results);
  }

  if (executedBefore.isEmpty && executedAfter.isEmpty) {
    return [''];
  } else if (executedBefore.isNotEmpty &&
      executedBefore.first is String &&
      executedAfter.isEmpty) {
    return [(executedBefore.first as String)];
  } else if (executedBefore.isEmpty &&
      executedAfter.isNotEmpty &&
      executedAfter.first is String) {
    return [(executedAfter.first as String)];
  } else if (executedBefore.first is String &&
      executedAfter.first is String) {
    return [
      (executedBefore.first as String) + (executedAfter.first as String)
    ];
  } else {
    throw FhirPathEvaluationException(
        'The "&" operator only accepts Strings, but was passed '
        'the following:\n'
        'Operand 1: ${executedBefore.first} (${executedBefore.first.runtimeType})\n'
        'Operand 2: ${executedAfter.first} (${executedAfter.first.runtimeType})',
        operation: '&',
        collection: results);
  }
}