diff --git a/lib/features/my_appointments/my_appointments_view_model.dart b/lib/features/my_appointments/my_appointments_view_model.dart index 1689b57a..88fb8e64 100644 --- a/lib/features/my_appointments/my_appointments_view_model.dart +++ b/lib/features/my_appointments/my_appointments_view_model.dart @@ -56,6 +56,7 @@ class MyAppointmentsViewModel extends ChangeNotifier { bool isAppointmentDataToBeLoaded = true; bool isMyDoctorsDataToBeLoaded = true; bool isArrivedAppointmentDataLoaded = false; + bool isFullArrivedAppointmentsLoaded = false; bool isEyeMeasurementsAppointmentsLoading = false; @@ -178,6 +179,7 @@ class MyAppointmentsViewModel extends ChangeNotifier { isMyAppointmentsLoading = true; isTimeLineAppointmentsLoading = true; patientMyDoctorsList.clear(); + isFullArrivedAppointmentsLoaded = false; } isTamaraDetailsLoading = true; isAppointmentPatientShareLoading = true; @@ -276,6 +278,12 @@ class MyAppointmentsViewModel extends ChangeNotifier { getPatientAppointmentQueueDetails(); } } + + // Skip API call if full data is already loaded and we're not requesting timeline view + if (!isForTimeLine && isFullArrivedAppointmentsLoaded && !isAppointmentDataToBeLoaded) { + return; + } + if (!isAppointmentDataToBeLoaded) return; patientAppointmentsByClinic.clear(); @@ -323,6 +331,7 @@ class MyAppointmentsViewModel extends ChangeNotifier { if (!isForTimeLine) { patientAllArrivedAppointmentsHistoryList = apiResponse.data!; isArrivedAppointmentDataLoaded = true; + isFullArrivedAppointmentsLoaded = true; } notifyListeners(); if (onSuccess != null) { @@ -354,6 +363,49 @@ class MyAppointmentsViewModel extends ChangeNotifier { notifyListeners(); } + /// Loads full arrived appointments list if not already loaded + /// This is called when navigating to My Appointments page from landing page + Future loadFullArrivedAppointmentsIfNeeded({Function(dynamic)? onSuccess, Function(String)? onError}) async { + // Skip if already loaded + if (isFullArrivedAppointmentsLoaded) { + return; + } + + setIsAppointmentsHistoryLoading(true); + + // Fetch full arrived appointments (isForTimeLine = false) + final result = await myAppointmentsRepo.getPatientAppointments(isActiveAppointment: false, isArrivedAppointments: true, isForTimeLine: false); + + result.fold( + (failure) async => await errorHandlerService.handleError(failure: failure), + (apiResponse) { + if (apiResponse.messageStatus == 2) { + // Handle error + } else if (apiResponse.messageStatus == 1) { + patientArrivedAppointmentsHistoryList = apiResponse.data!; + patientAllArrivedAppointmentsHistoryList = apiResponse.data!; + isArrivedAppointmentDataLoaded = true; + isFullArrivedAppointmentsLoaded = true; + + // Rebuild the combined list + patientAppointmentsHistoryList.clear(); + patientAppointmentsHistoryList.addAll(patientUpcomingAppointmentsHistoryList); + patientAppointmentsHistoryList.addAll(patientArrivedAppointmentsHistoryList); + + isMyAppointmentsLoading = false; + + // Update filtered list based on current tab + updateListWRTTab(selectedTabIndex); + + notifyListeners(); + if (onSuccess != null) { + onSuccess(apiResponse); + } + } + }, + ); + } + void getFiltersForSelectedAppointmentList(List filteredAppointmentList) { availableFilters.clear(); if (filteredAppointmentList.isEmpty == true) return; diff --git a/lib/presentation/appointments/my_appointments_page.dart b/lib/presentation/appointments/my_appointments_page.dart index 3512472d..5606c935 100644 --- a/lib/presentation/appointments/my_appointments_page.dart +++ b/lib/presentation/appointments/my_appointments_page.dart @@ -45,8 +45,10 @@ class _MyAppointmentsPageState extends State { scheduleMicrotask(() { if (!myAppointmentsViewModel.isMyAppointmentsLoading) { myAppointmentsViewModel.initAppointmentsViewModel(); - myAppointmentsViewModel.getPatientAppointments(true, false); + myAppointmentsViewModel.getPatientAppointments(true, false, isForTimeLine: false); } + // Load full arrived appointments if not already loaded + myAppointmentsViewModel.loadFullArrivedAppointmentsIfNeeded(); }); super.initState(); } diff --git a/lib/presentation/habib_wallet/wallet_payment_confirm_page.dart b/lib/presentation/habib_wallet/wallet_payment_confirm_page.dart index eea9ec10..537a7dd8 100644 --- a/lib/presentation/habib_wallet/wallet_payment_confirm_page.dart +++ b/lib/presentation/habib_wallet/wallet_payment_confirm_page.dart @@ -176,6 +176,7 @@ class _WalletPaymentConfirmPageState extends State { ); }); }, onError: (err) { + LoaderBottomSheet.showLoader(); showCommonBottomSheetWithoutHeight( context, child: Utils.getErrorWidget(loadingText: err.toString()), diff --git a/lib/presentation/home/landing_page.dart b/lib/presentation/home/landing_page.dart index 2df8f77c..334e60e9 100644 --- a/lib/presentation/home/landing_page.dart +++ b/lib/presentation/home/landing_page.dart @@ -154,7 +154,7 @@ class _LandingPageState extends State { immediateLiveCareViewModel.initImmediateLiveCare(); immediateLiveCareViewModel.getPatientLiveCareHistory(); myAppointmentsViewModel.initAppointmentsViewModel(); - myAppointmentsViewModel.getPatientAppointments(true, false); + myAppointmentsViewModel.getPatientAppointments(true, false, isForTimeLine: true); emergencyServicesViewModel.checkPatientERAdvanceBalance(); // myAppointmentsViewModel.getPatientAppointmentQueueDetails(); notificationsViewModel.initNotificationsViewModel(); @@ -212,7 +212,7 @@ class _LandingPageState extends State { // Refresh Appointments Data myAppointmentsViewModel.setIsAppointmentDataToBeLoaded(true); myAppointmentsViewModel.initAppointmentsViewModel(); - myAppointmentsViewModel.getPatientAppointments(true, false); + myAppointmentsViewModel.getPatientAppointments(true, false, isForTimeLine: true); // Refresh Appointments Data habibWalletVM.initHabibWalletProvider(); diff --git a/lib/presentation/profile_settings/widgets/update_emergency_contact_widget.dart b/lib/presentation/profile_settings/widgets/update_emergency_contact_widget.dart index f1a34565..d617ac22 100644 --- a/lib/presentation/profile_settings/widgets/update_emergency_contact_widget.dart +++ b/lib/presentation/profile_settings/widgets/update_emergency_contact_widget.dart @@ -41,7 +41,7 @@ class _UpdateEmergencyContactDialogState extends State