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

  if (lhs.isEmpty || rhs.isEmpty) {
    return [];
  } else if (lhs.length != rhs.length) {
    return [false];
  } else {
    /// for each entry in lhs and rhs (we checked above to ensure they
    /// were the same length)
    for (var i = 0; i < lhs.length; i++) {
      /// we check to see if any of the values are DateTimes
      if (lhs[i] is FhirDateTime ||
          lhs[i] is FhirDate ||
          rhs[i] is FhirDateTime ||
          rhs[i] is FhirDate) {
        /// As long as one is, we convert them both to strings then back
        /// to DateTimes
        final lhsDateTime = FhirDateTime(lhs[i].toString());
        final rhsDateTime = FhirDateTime(rhs[i].toString());

        final equals = lhsDateTime.isEqual(rhsDateTime);
        if (equals != null) {
          return [equals];
        } else {
          return [];
        }
      }

      /// If they aren't dateTimes we can just compare them as usual
      else {
        if (lhs[i] is ValidatedQuantity || rhs[i] is ValidatedQuantity) {
          if (lhs[i] is ValidatedQuantity) {
            return <dynamic>[lhs[i] == rhs[i]];
          } else {
            return <dynamic>[rhs[i] == lhs[i]];
          }
        }
        if (lhs[i] != rhs[i] || rhs[i] != lhs[i]) {
          return <dynamic>[false];
        }
      }
    }
    return [true];
  }
}