execute method
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());
/// As long as they are both valid we try and compare them
if (lhsDateTime.isValid && rhsDateTime.isValid) {
try {
if (lhsDateTime != rhsDateTime) {
var lhsDatePrecision =
'-'.allMatches(lhsDateTime.toString()).length;
lhsDatePrecision = lhsDatePrecision > 2 ? 2 : lhsDatePrecision;
var rhsDatePrecision =
'-'.allMatches(rhsDateTime.toString()).length;
rhsDatePrecision = rhsDatePrecision > 2 ? 2 : rhsDatePrecision;
var lhsTimePrecision =
':'.allMatches(lhsDateTime.toString()).length;
lhsTimePrecision = lhsTimePrecision > 2 ? 2 : lhsTimePrecision;
var rhsTimePrecision =
':'.allMatches(rhsDateTime.toString()).length;
rhsTimePrecision = rhsTimePrecision > 2 ? 2 : rhsTimePrecision;
if (lhsDatePrecision != rhsDatePrecision ||
lhsTimePrecision != rhsTimePrecision) {
return <dynamic>[];
} else {
return <dynamic>[false];
}
}
} catch (e) {
return <dynamic>[];
}
} else {
/// If not it means only one is, so this is false
return <dynamic>[false];
}
}
/// If they aren't dateTimes we can just compare them as usual
else {
if (lhs[i] is FhirPathQuantity || rhs[i] is FhirPathQuantity) {
if (lhs[i] is FhirPathQuantity) {
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];
}
}