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 executedAfter = after.execute(results.toList(), passed);

  if (executedAfter.isEmpty) {
    return [];
  }
  if (executedAfter.length != 1) {
    throw FhirPathInvalidExpressionException(
        'Unary negate needs to be applied on a single item. Found instead: $executedAfter');
  }
  if (executedAfter.first is num) {
    return [-(executedAfter.first as num)];
  }
  if (executedAfter.first is FhirPathQuantity) {
    return [
      FhirPathQuantity(-(executedAfter.first as FhirPathQuantity).amount,
          (executedAfter.first as FhirPathQuantity).unit)
    ];
  } else {
    throw FhirPathInvalidExpressionException(
        'Unary negate needs to be followed by an integer, a decimal, or a quantity. Found instead: ${executedAfter.first}');
  }
}