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);
if (executedBefore.length != 1) {
throw FhirPathEvaluationException(
'The "as" operation requires a left operand with 1 item, '
'but was passed the following\n'
'Operand 1: $before',
operation: 'as',
arguments: before,
collection: results);
} else if (after.length != 1 || after.first is! IdentifierParser) {
throw FhirPathEvaluationException(
'The "as" operation requires a right operand that '
'has a single item that resolves to an identifier, but was passed:\n'
'Operand 2: $after',
operation: 'as',
arguments: after,
collection: results);
}
final identifierValue = (after.first as IdentifierParser).value;
if (((passed.isVersion(FhirVersion.r4)
? r4.resourceTypeFromStringMap.keys.contains(identifierValue)
: passed.isVersion(FhirVersion.r5)
? r5.resourceTypeFromStringMap.keys
.contains(identifierValue)
: passed.isVersion(FhirVersion.dstu2)
? dstu2.resourceTypeFromStringMap.keys
.contains(identifierValue)
: stu3.resourceTypeFromStringMap.keys
.contains(identifierValue)) &&
executedBefore.first is Map &&
executedBefore.first['resourceType'] == identifierValue) ||
(identifierValue.toLowerCase() == 'string' &&
(executedBefore.first is String)) ||
(identifierValue.toLowerCase() == 'boolean' &&
(executedBefore.first is bool ||
executedBefore.first is FhirBoolean)) ||
(identifierValue.toLowerCase() == 'integer' &&
(executedBefore.first is int ||
executedBefore.first is FhirInteger)) ||
(identifierValue.toLowerCase() == 'decimal' &&
(executedBefore.first is double ||
executedBefore.first is FhirDecimal)) ||
(identifierValue.toLowerCase() == 'date' &&
executedBefore.first is FhirDate) ||
(identifierValue.toLowerCase() == 'datetime' &&
(executedBefore.first is DateTime ||
executedBefore.first is FhirDateTime)) ||
(identifierValue.toLowerCase() == 'time' &&
executedBefore.first is FhirTime) ||
(identifierValue == 'quantity' &&
executedBefore.first is FhirPathQuantity)) {
return executedBefore;
}
if (FhirDatatypes.contains(identifierValue)) {
final polymorphicString = 'value$identifierValue';
final polymorphicIdentifier = IdentifierParser(polymorphicString);
final polymorphicParserList = ParserList([polymorphicIdentifier]);
return polymorphicParserList.execute(results.toList(), passed);
}
return [];
}