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 executedBefore = before.execute(results.toList(), passed);
final executedAfter = after.execute(results.toList(), passed);
if (executedBefore.isEmpty || executedAfter.isEmpty) {
return [];
} else if (executedBefore.length != 1 || executedAfter.length != 1) {
throw FhirPathEvaluationException(
'Math Operators require each operand to result in a '
'single object. The "-" operator was passed the following:\n'
'Operand 1: $executedBefore\n'
'Operand 2: $executedAfter',
operation: '-',
collection: results);
} else {
switch (executedBefore.first.runtimeType) {
case int:
{
if (executedAfter.first is num) {
return [
(executedBefore.first as int) - (executedAfter.first as num)
];
}
break;
}
case double:
{
if (executedAfter.first is num) {
return [
(executedBefore.first as double) - (executedAfter.first as num)
];
}
break;
}
case FhirPathQuantity:
{
if (executedAfter.first is FhirPathQuantity) {
return [
(executedBefore.first as FhirPathQuantity) -
(executedAfter.first as FhirPathQuantity)
];
}
break;
}
case FhirDateTime:
{
if (executedAfter.first is FhirPathQuantity) {
return [
(executedAfter.first as FhirPathQuantity)
.subtract(executedBefore.first)
.toString()
];
}
break;
}
case FhirDate:
{
if (executedAfter.first is FhirPathQuantity) {
return [
(executedAfter.first as FhirPathQuantity)
.subtract(executedBefore.first)
.toString()
];
}
break;
}
case FhirTime:
{
if (executedAfter.first is FhirPathQuantity) {
return [
(executedAfter.first as FhirPathQuantity)
.subtract(executedBefore.first)
.toString()
];
}
break;
}
case String:
{
if (executedAfter.first is FhirPathQuantity) {
if (FhirDateTime(executedBefore.first).isValid) {
return [
(executedAfter.first as FhirPathQuantity)
.subtract(FhirDateTime(executedBefore.first))
.toString()
];
} else if (FhirTime(executedBefore.first).isValid) {
return [
(executedAfter.first as FhirPathQuantity)
.subtract(FhirTime(executedBefore.first))
.toString()
];
}
}
break;
}
default:
break;
}
throw FhirPathEvaluationException(
'The "-" operator only accepts Integers, Decimals and '
'Quantities, but was passed the following:\n'
'Operand 1: ${executedBefore.first} (${executedBefore.first.runtimeType})\n'
'Operand 2: ${executedAfter.first} (${executedAfter.first.runtimeType})',
operation: '-',
collection: results);
}
}