|
|
|
|
@ -1,6 +1,7 @@
|
|
|
|
|
import 'dart:async';
|
|
|
|
|
|
|
|
|
|
import 'package:easy_localization/easy_localization.dart';
|
|
|
|
|
import 'package:firebase_crashlytics/firebase_crashlytics.dart';
|
|
|
|
|
import 'package:flutter/material.dart';
|
|
|
|
|
import 'package:get_it/get_it.dart';
|
|
|
|
|
import 'package:hmg_patient_app_new/core/app_state.dart';
|
|
|
|
|
@ -842,67 +843,73 @@ class BookAppointmentsViewModel extends ChangeNotifier {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Future<void> getDoctorFreeSlots({bool isBookingForLiveCare = false, Function(dynamic)? onSuccess, Function(String)? onError}) async {
|
|
|
|
|
docFreeSlots.clear();
|
|
|
|
|
DateTime date;
|
|
|
|
|
final DateFormat formatter = DateFormat('HH:mm', "en-US");
|
|
|
|
|
final DateFormat dateFormatter = DateFormat('yyyy-MM-dd');
|
|
|
|
|
Map<DateTime, List> _eventsParsed;
|
|
|
|
|
|
|
|
|
|
final result = await bookAppointmentsRepo.getDoctorFreeSlots(
|
|
|
|
|
selectedDoctor.clinicID ?? 0,
|
|
|
|
|
selectedDoctor.projectID ?? 0,
|
|
|
|
|
selectedDoctor.doctorID ?? 0,
|
|
|
|
|
isBookingForLiveCare,
|
|
|
|
|
continueDentalPlan: isContinueDentalPlan,
|
|
|
|
|
onError: onError,
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
result.fold(
|
|
|
|
|
(failure) async {
|
|
|
|
|
print(failure);
|
|
|
|
|
if (onError != null) {
|
|
|
|
|
onError(failure.message);
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
(apiResponse) {
|
|
|
|
|
if (apiResponse.messageStatus == 2) {
|
|
|
|
|
onError!(apiResponse.errorMessage ?? "Unknown error occurred");
|
|
|
|
|
// dialogService.showErrorDialog(message: apiResponse.errorMessage!, onOkPressed: () {});
|
|
|
|
|
} else if (apiResponse.messageStatus == 1) {
|
|
|
|
|
if (apiResponse.data['FreeTimeSlots'] == null || apiResponse.data['FreeTimeSlots'].isEmpty) {
|
|
|
|
|
onError!("No free slots available".tr());
|
|
|
|
|
return;
|
|
|
|
|
// try {
|
|
|
|
|
docFreeSlots.clear();
|
|
|
|
|
DateTime date;
|
|
|
|
|
final DateFormat formatter = DateFormat('HH:mm', "en-US");
|
|
|
|
|
// final DateFormat dateFormatter = DateFormat('yyyy-MM-dd');
|
|
|
|
|
// Map<DateTime, List> _eventsParsed;
|
|
|
|
|
|
|
|
|
|
final result = await bookAppointmentsRepo.getDoctorFreeSlots(
|
|
|
|
|
selectedDoctor.clinicID ?? 0,
|
|
|
|
|
selectedDoctor.projectID ?? 0,
|
|
|
|
|
selectedDoctor.doctorID ?? 0,
|
|
|
|
|
isBookingForLiveCare,
|
|
|
|
|
continueDentalPlan: isContinueDentalPlan,
|
|
|
|
|
onError: onError,
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
result.fold(
|
|
|
|
|
(failure) async {
|
|
|
|
|
print(failure);
|
|
|
|
|
if (onError != null) {
|
|
|
|
|
onError(failure.message);
|
|
|
|
|
}
|
|
|
|
|
initialSlotDuration = apiResponse.data["InitialSlotDuration"];
|
|
|
|
|
freeSlotsResponse = apiResponse.data['FreeTimeSlots'];
|
|
|
|
|
isWaitingAppointmentAvailable = apiResponse.data["IsAllowToBookWaitingAppointment"];
|
|
|
|
|
|
|
|
|
|
// isWaitingAppointmentAvailable = true;
|
|
|
|
|
|
|
|
|
|
freeSlotsResponse.forEach((element) {
|
|
|
|
|
// date = (isLiveCareSchedule != null && isLiveCareSchedule)
|
|
|
|
|
// ? DateUtil.convertStringToDate(element)
|
|
|
|
|
// :
|
|
|
|
|
date = DateUtil.convertStringToDateSaudiTimezone(element, int.parse(selectedDoctor.projectID.toString()));
|
|
|
|
|
slotsList.add(FreeSlot(date, ['slot']));
|
|
|
|
|
docFreeSlots.add(TimeSlot(isoTime: formatter.format(date), start: new DateTime(date.year, date.month, date.day, 0, 0, 0, 0), end: date, vidaDate: element));
|
|
|
|
|
});
|
|
|
|
|
},
|
|
|
|
|
(apiResponse) {
|
|
|
|
|
if (apiResponse.messageStatus == 2) {
|
|
|
|
|
onError!(apiResponse.errorMessage ?? "Unknown error occurred");
|
|
|
|
|
// dialogService.showErrorDialog(message: apiResponse.errorMessage!, onOkPressed: () {});
|
|
|
|
|
} else if (apiResponse.messageStatus == 1) {
|
|
|
|
|
if (apiResponse.data['FreeTimeSlots'] == null || apiResponse.data['FreeTimeSlots'].isEmpty) {
|
|
|
|
|
onError!("No free slots available".tr());
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
initialSlotDuration = apiResponse.data["InitialSlotDuration"];
|
|
|
|
|
freeSlotsResponse = apiResponse.data['FreeTimeSlots'];
|
|
|
|
|
isWaitingAppointmentAvailable = apiResponse.data["IsAllowToBookWaitingAppointment"];
|
|
|
|
|
|
|
|
|
|
// isWaitingAppointmentAvailable = true;
|
|
|
|
|
|
|
|
|
|
freeSlotsResponse.forEach((element) {
|
|
|
|
|
// date = (isLiveCareSchedule != null && isLiveCareSchedule)
|
|
|
|
|
// ? DateUtil.convertStringToDate(element)
|
|
|
|
|
// :
|
|
|
|
|
date = DateUtil.convertStringToDateSaudiTimezone(element, int.parse(selectedDoctor.projectID.toString()));
|
|
|
|
|
slotsList.add(FreeSlot(date, ['slot']));
|
|
|
|
|
docFreeSlots.add(TimeSlot(isoTime: formatter.format(date), start: new DateTime(date.year, date.month, date.day, 0, 0, 0, 0), end: date, vidaDate: element));
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
notifyListeners();
|
|
|
|
|
if (onSuccess != null) {
|
|
|
|
|
onSuccess(apiResponse);
|
|
|
|
|
notifyListeners();
|
|
|
|
|
if (onSuccess != null) {
|
|
|
|
|
onSuccess(apiResponse);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
);
|
|
|
|
|
},
|
|
|
|
|
);
|
|
|
|
|
// } catch(ex) {
|
|
|
|
|
// if (onError != null) {
|
|
|
|
|
// onError(ex.toString());
|
|
|
|
|
// }
|
|
|
|
|
// }
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Future<void> getLiveCareDoctorFreeSlots({bool isBookingForLiveCare = false, Function(dynamic)? onSuccess, Function(String)? onError}) async {
|
|
|
|
|
docFreeSlots.clear();
|
|
|
|
|
DateTime date;
|
|
|
|
|
final DateFormat formatter = DateFormat('HH:mm', "en-US");
|
|
|
|
|
final DateFormat dateFormatter = DateFormat('yyyy-MM-dd');
|
|
|
|
|
Map<DateTime, List> _eventsParsed;
|
|
|
|
|
// final DateFormat dateFormatter = DateFormat('yyyy-MM-dd');
|
|
|
|
|
// Map<DateTime, List> _eventsParsed;
|
|
|
|
|
|
|
|
|
|
final result = await bookAppointmentsRepo.getLiveCareDoctorFreeSlots(
|
|
|
|
|
selectedDoctor.clinicID ?? 0, selectedLiveCareClinic.serviceID ?? 0, selectedDoctor.projectID ?? 0, selectedDoctor.doctorID ?? 0, isBookingForLiveCare,
|
|
|
|
|
|