|  |  |  | @ -1,14 +1,9 @@ | 
		
	
		
			
				|  |  |  |  | import 'package:flutter/material.dart'; | 
		
	
		
			
				|  |  |  |  | import 'package:hmg_patient_app_new/core/app_state.dart'; | 
		
	
		
			
				|  |  |  |  | import 'package:hmg_patient_app_new/core/cache_consts.dart' show CacheConst; | 
		
	
		
			
				|  |  |  |  | import 'package:hmg_patient_app_new/core/utils/utils.dart' show Utils; | 
		
	
		
			
				|  |  |  |  | import 'package:hmg_patient_app_new/features/my_appointments/models/facility_selection.dart'; | 
		
	
		
			
				|  |  |  |  | import 'package:hmg_patient_app_new/features/my_appointments/models/resp_models/doctor_list_api_response.dart' show RegionList, PatientDoctorAppointmentListByRegion; | 
		
	
		
			
				|  |  |  |  | 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/models/resp_models/patient_appointment_share_response_model.dart'; | 
		
	
		
			
				|  |  |  |  | import 'package:hmg_patient_app_new/features/my_appointments/my_appointments_repo.dart'; | 
		
	
		
			
				|  |  |  |  | import 'package:hmg_patient_app_new/services/error_handler_service.dart'; | 
		
	
		
			
				|  |  |  |  | import 'package:location/location.dart' show Location; | 
		
	
		
			
				|  |  |  |  | 
 | 
		
	
		
			
				|  |  |  |  | import '../../core/utils/doctor_response_mapper.dart' show DoctorMapper; | 
		
	
		
			
				|  |  |  |  | 
 | 
		
	
	
		
			
				
					|  |  |  | @ -35,11 +30,6 @@ class MyAppointmentsViewModel extends ChangeNotifier { | 
		
	
		
			
				|  |  |  |  | 
 | 
		
	
		
			
				|  |  |  |  |   PatientAppointmentShareResponseModel? patientAppointmentShareResponseModel; | 
		
	
		
			
				|  |  |  |  | 
 | 
		
	
		
			
				|  |  |  |  |   RegionList? hospitalList; | 
		
	
		
			
				|  |  |  |  |   RegionList? filteredHospitalList; | 
		
	
		
			
				|  |  |  |  |   FacilitySelection currentlySelectedFacility = FacilitySelection.ALL; | 
		
	
		
			
				|  |  |  |  |   bool isRegionListLoading = false; | 
		
	
		
			
				|  |  |  |  | 
 | 
		
	
		
			
				|  |  |  |  |   MyAppointmentsViewModel({required this.myAppointmentsRepo, required this.errorHandlerService, required this.appState}); | 
		
	
		
			
				|  |  |  |  | 
 | 
		
	
		
			
				|  |  |  |  |   void onTabChange(int index) { | 
		
	
	
		
			
				
					|  |  |  | @ -57,7 +47,6 @@ class MyAppointmentsViewModel extends ChangeNotifier { | 
		
	
		
			
				|  |  |  |  |     isAppointmentPatientShareLoading = true; | 
		
	
		
			
				|  |  |  |  |     isTimeLineAppointmentsLoading = true; | 
		
	
		
			
				|  |  |  |  |     isPatientMyDoctorsLoading = true; | 
		
	
		
			
				|  |  |  |  |     isRegionListLoading = true; | 
		
	
		
			
				|  |  |  |  |     notifyListeners(); | 
		
	
		
			
				|  |  |  |  |   } | 
		
	
		
			
				|  |  |  |  | 
 | 
		
	
	
		
			
				
					|  |  |  | @ -311,78 +300,4 @@ class MyAppointmentsViewModel extends ChangeNotifier { | 
		
	
		
			
				|  |  |  |  |       }, | 
		
	
		
			
				|  |  |  |  |     ); | 
		
	
		
			
				|  |  |  |  |   } | 
		
	
		
			
				|  |  |  |  | 
 | 
		
	
		
			
				|  |  |  |  |   Future<void> getRegionMappedProjectList() async { | 
		
	
		
			
				|  |  |  |  |     if (hospitalList != null && hospitalList!.registeredDoctorMap != null && hospitalList!.registeredDoctorMap!.isNotEmpty) { | 
		
	
		
			
				|  |  |  |  |       filteredHospitalList = hospitalList; | 
		
	
		
			
				|  |  |  |  |       return; | 
		
	
		
			
				|  |  |  |  |     } | 
		
	
		
			
				|  |  |  |  |     isRegionListLoading = true; | 
		
	
		
			
				|  |  |  |  |     notifyListeners(); | 
		
	
		
			
				|  |  |  |  |     final result = await myAppointmentsRepo.getProjectList(); | 
		
	
		
			
				|  |  |  |  | 
 | 
		
	
		
			
				|  |  |  |  |     result.fold( | 
		
	
		
			
				|  |  |  |  |       (failure) async => await errorHandlerService.handleError(failure: failure), | 
		
	
		
			
				|  |  |  |  |       (apiResponse) async { | 
		
	
		
			
				|  |  |  |  |         if (apiResponse.messageStatus == 2) { | 
		
	
		
			
				|  |  |  |  |           // dialogService.showErrorDialog(message: apiResponse.errorMessage!, onOkPressed: () {}); | 
		
	
		
			
				|  |  |  |  |         } else if (apiResponse.messageStatus == 1) { | 
		
	
		
			
				|  |  |  |  |           var projectList = apiResponse.data!; | 
		
	
		
			
				|  |  |  |  |           hospitalList = await DoctorMapper.getMappedHospitals(projectList, isArabic: false); | 
		
	
		
			
				|  |  |  |  |           var lat = await Utils.getNumFromPrefs(CacheConst.userLat); | 
		
	
		
			
				|  |  |  |  | 
 | 
		
	
		
			
				|  |  |  |  |           var lng = await Utils.getNumFromPrefs(CacheConst.userLong); | 
		
	
		
			
				|  |  |  |  |           var isLocationEnabled = (lat != 0) && (lng != 0); | 
		
	
		
			
				|  |  |  |  |           hospitalList = await DoctorMapper.sortList(isLocationEnabled, hospitalList!); | 
		
	
		
			
				|  |  |  |  | 
 | 
		
	
		
			
				|  |  |  |  |           isRegionListLoading = false; | 
		
	
		
			
				|  |  |  |  |           filteredHospitalList = hospitalList; | 
		
	
		
			
				|  |  |  |  |           notifyListeners(); | 
		
	
		
			
				|  |  |  |  |         } | 
		
	
		
			
				|  |  |  |  |       }, | 
		
	
		
			
				|  |  |  |  |     ); | 
		
	
		
			
				|  |  |  |  |   } | 
		
	
		
			
				|  |  |  |  | 
 | 
		
	
		
			
				|  |  |  |  |   void setSelectedFacility(FacilitySelection selection) { | 
		
	
		
			
				|  |  |  |  |     currentlySelectedFacility = selection; | 
		
	
		
			
				|  |  |  |  |     notifyListeners(); | 
		
	
		
			
				|  |  |  |  |   } | 
		
	
		
			
				|  |  |  |  | 
 | 
		
	
		
			
				|  |  |  |  |   void filterHospitalListByString(String? value, String? selectedRegionId, bool isHMG) { | 
		
	
		
			
				|  |  |  |  |     if (value == null || value.isEmpty) { | 
		
	
		
			
				|  |  |  |  |       filteredHospitalList = hospitalList; | 
		
	
		
			
				|  |  |  |  |     } else { | 
		
	
		
			
				|  |  |  |  |       filteredHospitalList = RegionList(); | 
		
	
		
			
				|  |  |  |  | 
 | 
		
	
		
			
				|  |  |  |  |       var list = isHMG ? hospitalList?.registeredDoctorMap![selectedRegionId]!.hmgDoctorList : hospitalList?.registeredDoctorMap![selectedRegionId]!.hmcDoctorList; | 
		
	
		
			
				|  |  |  |  | 
 | 
		
	
		
			
				|  |  |  |  |       if (list != null && list.isEmpty) { | 
		
	
		
			
				|  |  |  |  |         notifyListeners(); | 
		
	
		
			
				|  |  |  |  |         return; | 
		
	
		
			
				|  |  |  |  |       } | 
		
	
		
			
				|  |  |  |  | 
 | 
		
	
		
			
				|  |  |  |  |       var filteredList = list!.where((element) => element.filterName!.toLowerCase().contains(value.toLowerCase())).toList(); | 
		
	
		
			
				|  |  |  |  |       var regionData = PatientDoctorAppointmentListByRegion(); | 
		
	
		
			
				|  |  |  |  |       if (isHMG) { | 
		
	
		
			
				|  |  |  |  |         regionData.hmgDoctorList = filteredList; | 
		
	
		
			
				|  |  |  |  |         regionData.hmgSize = filteredList.length; | 
		
	
		
			
				|  |  |  |  |       } else { | 
		
	
		
			
				|  |  |  |  |         regionData.hmcDoctorList = filteredList; | 
		
	
		
			
				|  |  |  |  |         regionData.hmcSize = filteredList.length; | 
		
	
		
			
				|  |  |  |  |       } | 
		
	
		
			
				|  |  |  |  | 
 | 
		
	
		
			
				|  |  |  |  |       filteredHospitalList?.registeredDoctorMap = {selectedRegionId!: regionData}; | 
		
	
		
			
				|  |  |  |  |     } | 
		
	
		
			
				|  |  |  |  |     notifyListeners(); | 
		
	
		
			
				|  |  |  |  |   } | 
		
	
		
			
				|  |  |  |  | 
 | 
		
	
		
			
				|  |  |  |  |   Future<bool> isLocationEnabled() async { | 
		
	
		
			
				|  |  |  |  |     return await Location().serviceEnabled(); | 
		
	
		
			
				|  |  |  |  |   } | 
		
	
		
			
				|  |  |  |  | 
 | 
		
	
		
			
				|  |  |  |  |   bool getLocationStatus() { | 
		
	
		
			
				|  |  |  |  |     bool isLocationAvaiable = false; | 
		
	
		
			
				|  |  |  |  |     isLocationEnabled().then((value) => isLocationAvaiable = value); | 
		
	
		
			
				|  |  |  |  |     return isLocationAvaiable; | 
		
	
		
			
				|  |  |  |  |   } | 
		
	
		
			
				|  |  |  |  | } | 
		
	
	
		
			
				
					|  |  |  | 
 |