toBool static method
Returns a bool interpretation of the input
Returns null for empty input.
Implementation
static bool? toBool(
List<dynamic> input, {
String? name,
String? operation,
List<dynamic>? collection,
}) {
if (input.isEmpty) {
return null;
}
if (input.length > 1) {
throw FhirPathEvaluationException(
'The $name is required to be '
'either an empty value, or a single value. Instead it evaluated to: $input.',
operation: operation,
collection: collection,
);
}
if (input.first is bool) {
return input.first as bool;
}
if (input.first == 0 ||
(input.first is String &&
[
'false',
'f',
'no',
'n',
'0',
'0.0',
].contains(input.first.toString().toLowerCase()))) {
return false;
}
// A single item that is not specifically a false boolean is true.
return true;
}