getTaskStatus function

Status getTaskStatus(
  1. Iterable<TaskModel> tasks
)

Implementation

Status getTaskStatus(Iterable<TaskModel> tasks) {
  final statusMap = {
    Status.delivered.toValue(): Status.delivered,
    Status.notAdministered.toValue(): Status.notAdministered,
    Status.visited.toValue(): Status.visited,
    Status.notVisited.toValue(): Status.notVisited,
    Status.beneficiaryRefused.toValue(): Status.beneficiaryRefused,
    Status.beneficiaryReferred.toValue(): Status.beneficiaryReferred,
    Status.administeredSuccess.toValue(): Status.administeredSuccess,
    Status.administeredFailed.toValue(): Status.administeredFailed,
    Status.inComplete.toValue(): Status.inComplete,
    Status.toAdminister.toValue(): Status.toAdminister,
    Status.closeHousehold.toValue(): Status.closeHousehold,
  };

  if (tasks.isEmpty) {
    return Status.registered.toValue();
  } else {
    final mappedStatus = statusMap[tasks.last.status ?? Status.registered];
    if (mappedStatus != null) {
      return mappedStatus;
    }
  }

  return Status.registered.toValue();
}