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 leftOperand = before.execute(results.toList(), passed);
  final rightOperand = after.execute(results.toList(), passed);

  if (leftOperand.isEmpty) {
    return [false];
  }

  if (rightOperand.isEmpty) {
    return [];
  }

  if (rightOperand.length > 1) {
    throw FhirPathEvaluationException(
      "The 'contains' operator is expecting a single item on its right side. Found $rightOperand",
      operation: 'contains',
      collection: results,
    );
  }

  final rightItem = rightOperand.first.toString();

  return [
    leftOperand.firstWhere(
          (leftItem) => leftItem.toString() == rightItem,
          orElse: () => null,
        ) !=
        null,
  ];
}