allDosesDelivered function
bool
allDosesDelivered(
- List<
TaskModel> ? tasks, - ProjectCycle? selectedCycle,
- List<
SideEffectModel> ? sideEffects, - IndividualModel? individualModel,
Implementation
bool allDosesDelivered(
List<TaskModel>? tasks,
ProjectCycle? selectedCycle,
List<SideEffectModel>? sideEffects,
IndividualModel? individualModel,
) {
if (selectedCycle == null ||
selectedCycle.id == 0 ||
(selectedCycle.deliveries ?? []).isEmpty) {
return true;
} else {
if ((tasks ?? []).isNotEmpty) {
final lastCycle = int.tryParse(tasks?.last.additionalFields?.fields
.where(
(e) => e.key == AdditionalFieldsType.cycleIndex.name,
)
.firstOrNull
?.value ??
'');
final lastDose = int.tryParse(tasks?.last.additionalFields?.fields
.where(
(e) => e.key == AdditionalFieldsType.doseIndex.name,
)
.firstOrNull
?.value ??
'');
if (lastDose != null &&
lastDose == selectedCycle.deliveries?.length &&
lastCycle != null &&
lastCycle == selectedCycle.id &&
tasks?.last.status != Status.delivered.name) {
return true;
} else if (selectedCycle.id == lastCycle &&
tasks?.last.status == Status.delivered.name) {
return false;
} else if ((sideEffects ?? []).isNotEmpty) {
return recordedSideEffect(selectedCycle, tasks?.last, sideEffects);
} else {
return false;
}
} else {
return false;
}
}
}