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 executedValue = value.length == 1 && value.first is IdentifierParser
? [value.first]
: value.execute(results.toList(), passed);
if (executedValue.length != 1) {
throw FhirPathEvaluationException(
'The "ofType" function requires an argument that '
'resolves to 1 item but was passed the following:',
operation: 'ofType',
arguments: executedValue,
collection: results,
);
}
final finalResults = [];
results.forEach((e) {
if (((passed.isVersion(FhirVersion.r4)
? r4.resourceTypeFromStringMap.keys
.contains((executedValue.first as IdentifierParser).value)
: passed.isVersion(FhirVersion.r5)
? r5.resourceTypeFromStringMap.keys.contains(
(executedValue.first as IdentifierParser).value)
: passed.isVersion(FhirVersion.dstu2)
? dstu2.resourceTypeFromStringMap.keys.contains(
(executedValue.first as IdentifierParser).value)
: stu3.resourceTypeFromStringMap.keys.contains(
(executedValue.first as IdentifierParser).value,
)) &&
e is Map &&
e['resourceType'] ==
(executedValue.first as IdentifierParser).value) ||
((executedValue.first as IdentifierParser).value == 'string' &&
(e is String)) ||
((executedValue.first as IdentifierParser).value == 'boolean' &&
(e is bool || e is FhirBoolean)) ||
((executedValue.first as IdentifierParser).value == 'integer' &&
(e is int || e is FhirInteger) &&
!e.toString().contains('.')) ||
((executedValue.first as IdentifierParser).value == 'decimal' &&
(e is double || e is FhirDecimal) &&
e.toString().contains('.')) ||
((executedValue.first as IdentifierParser).value == 'date' &&
e is FhirDate) ||
((executedValue.first as IdentifierParser).value == 'datetime' &&
(e is DateTime || e is FhirDateTime)) ||
((executedValue.first as IdentifierParser).value == 'time' &&
e is FhirTime) ||
((executedValue.first as IdentifierParser).value == 'quantity' &&
e is FhirPathQuantity)) {
finalResults.add(e);
}
});
return finalResults;
}