@ -1,6 +1,11 @@
 
			
		
	
		
		
			
				
					
					import  ' package:easy_localization/easy_localization.dart ' ; import  ' package:easy_localization/easy_localization.dart ' ;  
			
		
	
		
		
			
				
					
					import  ' package:flutter/material.dart ' ; import  ' package:flutter/material.dart ' ;  
			
		
	
		
		
			
				
					
					import  ' package:hmg_patient_app_new/core/app_state.dart ' ;  
			
		
	
		
		
			
				
					
					import  ' package:hmg_patient_app_new/core/dependencies.dart ' ;  
			
		
	
		
		
			
				
					
					import  ' package:hmg_patient_app_new/core/utils/date_util.dart ' ; import  ' package:hmg_patient_app_new/core/utils/date_util.dart ' ;  
			
		
	
		
		
			
				
					
					import  ' package:hmg_patient_app_new/core/utils/loading_utils.dart ' ;  
			
		
	
		
		
			
				
					
					import  ' package:hmg_patient_app_new/core/utils/size_utils.dart ' ;  
			
		
	
		
		
			
				
					
					import  ' package:hmg_patient_app_new/core/utils/utils.dart ' ;  
			
		
	
		
		
			
				
					
					import  ' package:hmg_patient_app_new/extensions/string_extensions.dart ' ; import  ' package:hmg_patient_app_new/extensions/string_extensions.dart ' ;  
			
		
	
		
		
			
				
					
					import  ' package:hmg_patient_app_new/features/book_appointments/book_appointments_repo.dart ' ; import  ' package:hmg_patient_app_new/features/book_appointments/book_appointments_repo.dart ' ;  
			
		
	
		
		
			
				
					
					import  ' package:hmg_patient_app_new/features/book_appointments/models/free_slot.dart ' ; import  ' package:hmg_patient_app_new/features/book_appointments/models/free_slot.dart ' ;  
			
		
	
	
		
		
			
				
					
						
						
						
							
								 
						
					 
					@ -8,7 +13,14 @@ import 'package:hmg_patient_app_new/features/book_appointments/models/resp_model
 
			
		
	
		
		
			
				
					
					import  ' package:hmg_patient_app_new/features/book_appointments/models/resp_models/doctors_list_response_model.dart ' ; import  ' package:hmg_patient_app_new/features/book_appointments/models/resp_models/doctors_list_response_model.dart ' ;  
			
		
	
		
		
			
				
					
					import  ' package:hmg_patient_app_new/features/book_appointments/models/resp_models/get_clinic_list_response_model.dart ' ; import  ' package:hmg_patient_app_new/features/book_appointments/models/resp_models/get_clinic_list_response_model.dart ' ;  
			
		
	
		
		
			
				
					
					import  ' package:hmg_patient_app_new/features/book_appointments/models/timeslots.dart ' ; import  ' package:hmg_patient_app_new/features/book_appointments/models/timeslots.dart ' ;  
			
		
	
		
		
			
				
					
					import  ' package:hmg_patient_app_new/features/my_appointments/models/resp_models/patient_appointment_history_response_model.dart ' ;  
			
		
	
		
		
			
				
					
					import  ' package:hmg_patient_app_new/features/my_appointments/my_appointments_view_model.dart ' ;  
			
		
	
		
		
			
				
					
					import  ' package:hmg_patient_app_new/generated/locale_keys.g.dart ' ;  
			
		
	
		
		
			
				
					
					import  ' package:hmg_patient_app_new/presentation/home/navigation_screen.dart ' ;  
			
		
	
		
		
			
				
					
					import  ' package:hmg_patient_app_new/services/error_handler_service.dart ' ; import  ' package:hmg_patient_app_new/services/error_handler_service.dart ' ;  
			
		
	
		
		
			
				
					
					import  ' package:hmg_patient_app_new/services/navigation_service.dart ' ;  
			
		
	
		
		
			
				
					
					import  ' package:hmg_patient_app_new/widgets/common_bottom_sheet.dart ' ;  
			
		
	
		
		
			
				
					
					import  ' package:hmg_patient_app_new/widgets/transitions/fade_page.dart ' ;  
			
		
	
		
		
			
				
					
					
 
			
		
	
		
		
			
				
					
					class  BookAppointmentsViewModel  extends  ChangeNotifier  { class  BookAppointmentsViewModel  extends  ChangeNotifier  {  
			
		
	
		
		
			
				
					
					  int  selectedTabIndex  =  0 ; 
  int  selectedTabIndex  =  0 ; 
 
			
		
	
	
		
		
			
				
					
						
						
						
							
								 
						
					 
					@ -18,6 +30,8 @@ class BookAppointmentsViewModel extends ChangeNotifier {
 
			
		
	
		
		
			
				
					
					  bool  isDoctorProfileLoading  =  false ; 
  bool  isDoctorProfileLoading  =  false ; 
 
			
		
	
		
		
			
				
					
					  bool  isDoctorSearchByNameStarted  =  false ; 
  bool  isDoctorSearchByNameStarted  =  false ; 
 
			
		
	
		
		
			
				
					
					
 
			
		
	
		
		
			
				
					
					  int  initialSlotDuration  =  0 ; 
 
			
		
	
		
		
			
				
					
					
 
			
		
	
		
		
			
				
					
					  List < GetClinicsListResponseModel >  clinicsList  =  [ ] ; 
  List < GetClinicsListResponseModel >  clinicsList  =  [ ] ; 
 
			
		
	
		
		
			
				
					
					  List < GetClinicsListResponseModel >  _filteredClinicsList  =  [ ] ; 
  List < GetClinicsListResponseModel >  _filteredClinicsList  =  [ ] ; 
 
			
		
	
		
		
			
				
					
					
 
			
		
	
	
		
		
			
				
					
						
						
						
							
								 
						
					 
					@ -42,8 +56,12 @@ class BookAppointmentsViewModel extends ChangeNotifier {
 
			
		
	
		
		
			
				
					
					
 
			
		
	
		
		
			
				
					
					  BookAppointmentsRepo  bookAppointmentsRepo ; 
  BookAppointmentsRepo  bookAppointmentsRepo ; 
 
			
		
	
		
		
			
				
					
					  ErrorHandlerService  errorHandlerService ; 
  ErrorHandlerService  errorHandlerService ; 
 
			
		
	
		
		
			
				
					
					  final  NavigationService  navigationService ; 
 
			
		
	
		
		
			
				
					
					  MyAppointmentsViewModel  myAppointmentsViewModel ; 
 
			
		
	
		
		
			
				
					
					
 
			
		
	
		
		
			
				
					
					  late  AppState  _appState ; 
 
			
		
	
		
		
			
				
					
					
 
			
		
	
		
		
			
				
					
					  BookAppointmentsViewModel ( { required  this . bookAppointmentsRepo ,  required  this . errorHandlerService } ) ; 
  BookAppointmentsViewModel ( { required  this . bookAppointmentsRepo ,  required  this . errorHandlerService , required  this . navigationService ,  required  this . myAppointmentsViewModel  }) ; 
 
			
				
				
			
		
	
		
		
	
		
		
			
				
					
					
 
			
		
	
		
		
			
				
					
					  void  initializeFilteredList ( )  { 
  void  initializeFilteredList ( )  { 
 
			
		
	
		
		
			
				
					
					    _filteredClinicsList  =  List . from ( clinicsList ) ; 
    _filteredClinicsList  =  List . from ( clinicsList ) ; 
 
			
		
	
	
		
		
			
				
					
						
						
						
							
								 
						
					 
					@ -60,6 +78,7 @@ class BookAppointmentsViewModel extends ChangeNotifier {
 
			
		
	
		
		
			
				
					
					  } 
  } 
 
			
		
	
		
		
			
				
					
					
 
			
		
	
		
		
			
				
					
					  initBookAppointmentViewModel ( )  { 
  initBookAppointmentViewModel ( )  { 
 
			
		
	
		
		
			
				
					
					    _appState  =  getIt < AppState > ( ) ; 
 
			
		
	
		
		
			
				
					
					    isClinicsListLoading  =  true ; 
    isClinicsListLoading  =  true ; 
 
			
		
	
		
		
			
				
					
					    isDoctorsListLoading  =  true ; 
    isDoctorsListLoading  =  true ; 
 
			
		
	
		
		
			
				
					
					    isDoctorProfileLoading  =  true ; 
    isDoctorProfileLoading  =  true ; 
 
			
		
	
	
		
		
			
				
					
						
							
								 
						
						
							
								 
						
						
					 
					@ -206,12 +225,13 @@ class BookAppointmentsViewModel extends ChangeNotifier {
 
			
		
	
		
		
			
				
					
					          onError ! ( apiResponse . errorMessage  ? ?  " Unknown error occurred " ) ; 
          onError ! ( apiResponse . errorMessage  ? ?  " Unknown error occurred " ) ; 
 
			
		
	
		
		
			
				
					
					          / /  dialogService . showErrorDialog ( message:  apiResponse . errorMessage ! ,  onOkPressed:  ( )  { } ) ; 
          / /  dialogService . showErrorDialog ( message:  apiResponse . errorMessage ! ,  onOkPressed:  ( )  { } ) ; 
 
			
		
	
		
		
			
				
					
					        }  else  if  ( apiResponse . messageStatus  = =  1 )  { 
        }  else  if  ( apiResponse . messageStatus  = =  1 )  { 
 
			
		
	
		
		
			
				
					
					          if  ( apiResponse . data  = =  null  | |  apiResponse . data ! . isEmpty )  { 
          if  ( apiResponse . data [ ' FreeTimeSlots ' ] = =  null  | |  apiResponse . data [ ' FreeTimeSlots ' ] . isEmpty )  { 
 
			
				
				
			
		
	
		
		
	
		
		
			
				
					
					            onError ! ( " No free slots available " . tr ( ) ) ; 
            onError ! ( " No free slots available " . tr ( ) ) ; 
 
			
		
	
		
		
			
				
					
					            return ; 
            return ; 
 
			
		
	
		
		
			
				
					
					          } 
          } 
 
			
		
	
		
		
			
				
					
					          freeSlotsResponse  =  apiResponse . data ; 
          initialSlotDuration  =  apiResponse . data [ " InitialSlotDuration " ] ; 
 
			
				
				
			
		
	
		
		
			
				
					
					          apiResponse . data ! . forEach ( ( element )  { 
          freeSlotsResponse  =  apiResponse . data [ ' FreeTimeSlots ' ] ; 
 
			
				
				
			
		
	
		
		
	
		
		
	
		
		
			
				
					
					          freeSlotsResponse . forEach ( ( element )  { 
 
			
		
	
		
		
			
				
					
					            / /  date  =  ( isLiveCareSchedule  ! =  null  & &  isLiveCareSchedule ) 
            / /  date  =  ( isLiveCareSchedule  ! =  null  & &  isLiveCareSchedule ) 
 
			
		
	
		
		
			
				
					
					            / /      ?  DateUtil . convertStringToDate ( element ) 
            / /      ?  DateUtil . convertStringToDate ( element ) 
 
			
		
	
		
		
			
				
					
					            / /      : 
            / /      : 
 
			
		
	
	
		
		
			
				
					
						
						
						
							
								 
						
					 
					@ -228,4 +248,136 @@ class BookAppointmentsViewModel extends ChangeNotifier {
 
			
		
	
		
		
			
				
					
					      } , 
      } , 
 
			
		
	
		
		
			
				
					
					    ) ; 
    ) ; 
 
			
		
	
		
		
			
				
					
					  } 
  } 
 
			
		
	
		
		
			
				
					
					
 
			
		
	
		
		
			
				
					
					  Future < void >  cancelAppointment ( { required  PatientAppointmentHistoryResponseModel  patientAppointmentHistoryResponseModel ,  Function ( dynamic ) ?  onSuccess ,  Function ( String ) ?  onError } )  async  { 
 
			
		
	
		
		
			
				
					
					    final  result  =  await  bookAppointmentsRepo . cancelAppointment ( patientAppointmentHistoryResponseModel:  patientAppointmentHistoryResponseModel ) ; 
 
			
		
	
		
		
			
				
					
					
 
			
		
	
		
		
			
				
					
					    result . fold ( 
 
			
		
	
		
		
			
				
					
					      ( failure )  async  = >  await  errorHandlerService . handleError ( failure:  failure ) , 
 
			
		
	
		
		
			
				
					
					      ( apiResponse )  { 
 
			
		
	
		
		
			
				
					
					        if  ( apiResponse . messageStatus  = =  2 )  { 
 
			
		
	
		
		
			
				
					
					          onError ! ( apiResponse . errorMessage ! ) ; 
 
			
		
	
		
		
			
				
					
					          / /  dialogService . showErrorDialog ( message:  apiResponse . errorMessage ! ,  onOkPressed:  ( )  { } ) ; 
 
			
		
	
		
		
			
				
					
					        }  else  if  ( apiResponse . messageStatus  = =  1 )  { 
 
			
		
	
		
		
			
				
					
					          notifyListeners ( ) ; 
 
			
		
	
		
		
			
				
					
					          if  ( onSuccess  ! =  null )  { 
 
			
		
	
		
		
			
				
					
					            onSuccess ( apiResponse ) ; 
 
			
		
	
		
		
			
				
					
					          } 
 
			
		
	
		
		
			
				
					
					        } 
 
			
		
	
		
		
			
				
					
					      } , 
 
			
		
	
		
		
			
				
					
					    ) ; 
 
			
		
	
		
		
			
				
					
					  } 
 
			
		
	
		
		
			
				
					
					
 
			
		
	
		
		
			
				
					
					  / / TODO:  Handle  the  cases  for  LiveCare  Schedule ,  Dental  &  Laser  Clinics 
 
			
		
	
		
		
			
				
					
					  Future < void >  insertSpecificAppointment ( 
 
			
		
	
		
		
			
				
					
					      { 
 
			
		
	
		
		
			
				
					
					      / /  required  int  docID , 
 
			
		
	
		
		
			
				
					
					      / /  required  int  clinicID , 
 
			
		
	
		
		
			
				
					
					      / /  required  int  projectID , 
 
			
		
	
		
		
			
				
					
					      / /  required  String  selectedTime , 
 
			
		
	
		
		
			
				
					
					      / /  required  String  selectedDate , 
 
			
		
	
		
		
			
				
					
					      / /  required  int  initialSlotDuration , 
 
			
		
	
		
		
			
				
					
					      / /  required  int  genderID , 
 
			
		
	
		
		
			
				
					
					      / /  required  int  userAge , 
 
			
		
	
		
		
			
				
					
					      String ?  procedureID , 
 
			
		
	
		
		
			
				
					
					      num ?  testTypeEnum , 
 
			
		
	
		
		
			
				
					
					      num ?  testProcedureEnum , 
 
			
		
	
		
		
			
				
					
					      int ?  invoiceNumber , 
 
			
		
	
		
		
			
				
					
					      int ?  lineItemNo , 
 
			
		
	
		
		
			
				
					
					      String ?  invoiceNoVP , 
 
			
		
	
		
		
			
				
					
					      Function ( dynamic  p1 ) ?  onSuccess , 
 
			
		
	
		
		
			
				
					
					      Function ( dynamic  p1 ) ?  onError } )  async  { 
 
			
		
	
		
		
			
				
					
					    _appState  =  getIt < AppState > ( ) ; 
 
			
		
	
		
		
			
				
					
					    final  result  =  await  bookAppointmentsRepo . insertSpecificAppointment ( 
 
			
		
	
		
		
			
				
					
					        docID:  selectedDoctor . doctorID ! , 
 
			
		
	
		
		
			
				
					
					        clinicID:  selectedDoctor . clinicID ! , 
 
			
		
	
		
		
			
				
					
					        projectID:  selectedDoctor . projectID ! , 
 
			
		
	
		
		
			
				
					
					        selectedDate:  selectedAppointmentDate , 
 
			
		
	
		
		
			
				
					
					        selectedTime:  selectedAppointmentTime , 
 
			
		
	
		
		
			
				
					
					        initialSlotDuration:  initialSlotDuration , 
 
			
		
	
		
		
			
				
					
					        genderID:  _appState . getAuthenticatedUser ( ) ! . gender ! , 
 
			
		
	
		
		
			
				
					
					        userAge:  _appState . getAuthenticatedUser ( ) ! . age ! , 
 
			
		
	
		
		
			
				
					
					        onError:  onError ) ; 
 
			
		
	
		
		
			
				
					
					
 
			
		
	
		
		
			
				
					
					    result . fold ( 
 
			
		
	
		
		
			
				
					
					      ( failure )  async  { 
 
			
		
	
		
		
			
				
					
					        print ( failure ) ; 
 
			
		
	
		
		
			
				
					
					      } , 
 
			
		
	
		
		
			
				
					
					      ( apiResponse )  { 
 
			
		
	
		
		
			
				
					
					        if  ( apiResponse . messageStatus  = =  2 )  { 
 
			
		
	
		
		
			
				
					
					          / /  onError ! ( apiResponse ) ; 
 
			
		
	
		
		
			
				
					
					          LoadingUtils . hideFullScreenLoader ( ) ; 
 
			
		
	
		
		
			
				
					
					          showCommonBottomSheetWithoutHeight ( 
 
			
		
	
		
		
			
				
					
					            title:  LocaleKeys . notice . tr ( context:  navigationService . navigatorKey . currentContext ! ) , 
 
			
		
	
		
		
			
				
					
					            navigationService . navigatorKey . currentContext ! , 
 
			
		
	
		
		
			
				
					
					            child:  Utils . getWarningWidget ( 
 
			
		
	
		
		
			
				
					
					                loadingText:  apiResponse . data [ " ErrorEndUserMessage " ] , 
 
			
		
	
		
		
			
				
					
					                isShowActionButtons:  true , 
 
			
		
	
		
		
			
				
					
					                onCancelTap:  ( )  { 
 
			
		
	
		
		
			
				
					
					                  navigationService . pop ( ) ; 
 
			
		
	
		
		
			
				
					
					                } , 
 
			
		
	
		
		
			
				
					
					                onConfirmTap:  ( )  async  { 
 
			
		
	
		
		
			
				
					
					                  navigationService . pop ( ) ; 
 
			
		
	
		
		
			
				
					
					                  PatientAppointmentHistoryResponseModel  patientAppointmentHistoryResponseModel  =  PatientAppointmentHistoryResponseModel ( 
 
			
		
	
		
		
			
				
					
					                    appointmentNo:  apiResponse . data [ " SameClinicApptList " ] [ 0 ] [ ' AppointmentNo ' ] , 
 
			
		
	
		
		
			
				
					
					                    clinicID:  apiResponse . data [ " SameClinicApptList " ] [ 0 ] [ ' ClinicID ' ] , 
 
			
		
	
		
		
			
				
					
					                    projectID:  apiResponse . data [ " SameClinicApptList " ] [ 0 ] [ ' ProjectID ' ] , 
 
			
		
	
		
		
			
				
					
					                    endDate:  apiResponse . data [ " SameClinicApptList " ] [ 0 ] [ ' EndTime ' ] , 
 
			
		
	
		
		
			
				
					
					                    startTime:  apiResponse . data [ " SameClinicApptList " ] [ 0 ] [ ' StartTime ' ] , 
 
			
		
	
		
		
			
				
					
					                    doctorID:  apiResponse . data [ " SameClinicApptList " ] [ 0 ] [ ' DoctorID ' ] , 
 
			
		
	
		
		
			
				
					
					                    isLiveCareAppointment:  apiResponse . data [ " SameClinicApptList " ] [ 0 ] [ ' IsLiveCareAppointment ' ] , 
 
			
		
	
		
		
			
				
					
					                    originalClinicID:  0 , 
 
			
		
	
		
		
			
				
					
					                    originalProjectID:  0 , 
 
			
		
	
		
		
			
				
					
					                    appointmentDate:  apiResponse . data [ " SameClinicApptList " ] [ 0 ] [ ' AppointmentDate ' ] , 
 
			
		
	
		
		
			
				
					
					                  ) ; 
 
			
		
	
		
		
			
				
					
					
 
			
		
	
		
		
			
				
					
					                  showCommonBottomSheet ( navigationService . navigatorKey . currentContext ! , 
 
			
		
	
		
		
			
				
					
					                      child:  Utils . getLoadingWidget ( loadingText:  " Cancelling your previous appointment.... " . needTranslation ) , 
 
			
		
	
		
		
			
				
					
					                      callBackFunc:  ( str )  { } , 
 
			
		
	
		
		
			
				
					
					                      title:  " " , 
 
			
		
	
		
		
			
				
					
					                      height:  ResponsiveExtension . screenHeight  *  0.3 , 
 
			
		
	
		
		
			
				
					
					                      isCloseButtonVisible:  false , 
 
			
		
	
		
		
			
				
					
					                      isDismissible:  false , 
 
			
		
	
		
		
			
				
					
					                      isFullScreen:  false ) ; 
 
			
		
	
		
		
			
				
					
					                  await  cancelAppointment ( patientAppointmentHistoryResponseModel:  patientAppointmentHistoryResponseModel ) . then ( ( val )  async  { 
 
			
		
	
		
		
			
				
					
					                    navigationService . pop ( ) ; 
 
			
		
	
		
		
			
				
					
					                    Future . delayed ( Duration ( milliseconds:  50 ) ) . then ( ( value )  async  { } ) ; 
 
			
		
	
		
		
			
				
					
					                    LoadingUtils . showFullScreenLoader ( barrierDismissible:  true ,  isSuccessDialog:  false ,  loadingText:  " Booking your appointment... " . needTranslation ) ; 
 
			
		
	
		
		
			
				
					
					                    await  insertSpecificAppointment ( 
 
			
		
	
		
		
			
				
					
					                        onError:  ( err )  { } , 
 
			
		
	
		
		
			
				
					
					                        onSuccess:  ( apiResp )  async  { 
 
			
		
	
		
		
			
				
					
					                          LoadingUtils . hideFullScreenLoader ( ) ; 
 
			
		
	
		
		
			
				
					
					                          await  Future . delayed ( Duration ( milliseconds:  50 ) ) . then ( ( value )  async  { 
 
			
		
	
		
		
			
				
					
					                            LoadingUtils . showFullScreenLoader ( barrierDismissible:  true ,  isSuccessDialog:  true ,  loadingText:  LocaleKeys . appointmentSuccess . tr ( ) ) ; 
 
			
		
	
		
		
			
				
					
					                            await  Future . delayed ( Duration ( milliseconds:  4000 ) ) . then ( ( value )  { 
 
			
		
	
		
		
			
				
					
					                              LoadingUtils . hideFullScreenLoader ( ) ; 
 
			
		
	
		
		
			
				
					
					                              Navigator . pushAndRemoveUntil ( 
 
			
		
	
		
		
			
				
					
					                                  navigationService . navigatorKey . currentContext ! , 
 
			
		
	
		
		
			
				
					
					                                  FadePage ( 
 
			
		
	
		
		
			
				
					
					                                    page:  LandingNavigation ( ) , 
 
			
		
	
		
		
			
				
					
					                                  ) , 
 
			
		
	
		
		
			
				
					
					                                  ( r )  = >  false ) ; 
 
			
		
	
		
		
			
				
					
					                            } ) ; 
 
			
		
	
		
		
			
				
					
					                          } ) ; 
 
			
		
	
		
		
			
				
					
					                        } ) ; 
 
			
		
	
		
		
			
				
					
					                  } ) ; 
 
			
		
	
		
		
			
				
					
					                } ) , 
 
			
		
	
		
		
			
				
					
					            callBackFunc:  ( )  { } , 
 
			
		
	
		
		
			
				
					
					            isFullScreen:  false , 
 
			
		
	
		
		
			
				
					
					            isCloseButtonVisible:  true , 
 
			
		
	
		
		
			
				
					
					          ) ; 
 
			
		
	
		
		
			
				
					
					        }  else  if  ( apiResponse . messageStatus  = =  1 )  { 
 
			
		
	
		
		
			
				
					
					          if  ( apiResponse . data  = =  null  | |  apiResponse . data ! . isEmpty )  { 
 
			
		
	
		
		
			
				
					
					            onError ! ( " No free slots available " . tr ( ) ) ; 
 
			
		
	
		
		
			
				
					
					            return ; 
 
			
		
	
		
		
			
				
					
					          } 
 
			
		
	
		
		
			
				
					
					
 
			
		
	
		
		
			
				
					
					          notifyListeners ( ) ; 
 
			
		
	
		
		
			
				
					
					          if  ( onSuccess  ! =  null )  { 
 
			
		
	
		
		
			
				
					
					            onSuccess ( apiResponse ) ; 
 
			
		
	
		
		
			
				
					
					          } 
 
			
		
	
		
		
			
				
					
					        } 
 
			
		
	
		
		
			
				
					
					      } , 
 
			
		
	
		
		
			
				
					
					    ) ; 
 
			
		
	
		
		
			
				
					
					  } 
 
			
		
	
		
		
			
				
					
					} }