diff --git a/lib/core/api_consts.dart b/lib/core/api_consts.dart index bd2eb71..6c9a835 100644 --- a/lib/core/api_consts.dart +++ b/lib/core/api_consts.dart @@ -723,7 +723,7 @@ const DEACTIVATE_ACCOUNT = 'Services/Patients.svc/REST/PatientAppleActivation_In class ApiConsts { static const maxSmallScreen = 660; - static AppEnvironmentTypeEnum appEnvironmentType = AppEnvironmentTypeEnum.prod; + static AppEnvironmentTypeEnum appEnvironmentType = AppEnvironmentTypeEnum.uat; // static String baseUrl = 'https://uat.hmgwebservices.com/'; // HIS API URL UAT diff --git a/lib/features/authentication/authentication_view_model.dart b/lib/features/authentication/authentication_view_model.dart index bb41af6..eb4cd78 100644 --- a/lib/features/authentication/authentication_view_model.dart +++ b/lib/features/authentication/authentication_view_model.dart @@ -48,6 +48,7 @@ class AuthenticationViewModel extends ChangeNotifier { final DialogService _dialogService; final NavigationService _navigationService; final LocalAuthService _localAuthService; + AuthenticationViewModel({ required AppState appState, required AuthenticationRepo authenticationRepo, @@ -106,7 +107,6 @@ class AuthenticationViewModel extends ChangeNotifier { } Future clearDefaultInputValues() async { - nationalIdController.clear(); phoneNumberController.clear(); emailController.clear(); @@ -622,19 +622,20 @@ class AuthenticationViewModel extends ChangeNotifier { } checkLastLoginStatus(Function() onSuccess) async { - Future.delayed(Duration(seconds: 1), () async { - if(cacheService.getBool(key: CacheConst.quickLoginEnabled) == null){ + if (cacheService.getBool(key: CacheConst.quickLoginEnabled) == null) { if (_appState.getSelectDeviceByImeiRespModelElement != null && (_appState.getSelectDeviceByImeiRespModelElement!.logInType == 1 || _appState.getSelectDeviceByImeiRespModelElement!.logInType == 4)) { - phoneNumberController.text = - (_appState.getAuthenticatedUser()!.mobileNumber!.startsWith("0") ? _appState.getAuthenticatedUser()!.mobileNumber!.replaceFirst("0", "") : _appState.getAuthenticatedUser()!.mobileNumber)!; + phoneNumberController.text = (_appState.getAuthenticatedUser()!.mobileNumber!.startsWith("0") + ? _appState.getAuthenticatedUser()!.mobileNumber!.replaceFirst("0", "") + : _appState.getAuthenticatedUser()!.mobileNumber)!; nationalIdController.text = _appState.getAuthenticatedUser()!.nationalityId!; onSuccess(); } else if ((loginTypeEnum == LoginTypeEnum.sms || loginTypeEnum == LoginTypeEnum.whatsapp && _appState.getSelectDeviceByImeiRespModelElement == null) && _appState.getAuthenticatedUser() != null) { - phoneNumberController.text = - (_appState.getAuthenticatedUser()!.mobileNumber!.startsWith("0") ? _appState.getAuthenticatedUser()!.mobileNumber!.replaceFirst("0", "") : _appState.getAuthenticatedUser()!.mobileNumber)!; + phoneNumberController.text = (_appState.getAuthenticatedUser()!.mobileNumber!.startsWith("0") + ? _appState.getAuthenticatedUser()!.mobileNumber!.replaceFirst("0", "") + : _appState.getAuthenticatedUser()!.mobileNumber)!; nationalIdController.text = _appState.getAuthenticatedUser()!.nationalityId!; onSuccess(); } diff --git a/lib/features/book_appointments/book_appointments_repo.dart b/lib/features/book_appointments/book_appointments_repo.dart index 5a93879..f41fbc4 100644 --- a/lib/features/book_appointments/book_appointments_repo.dart +++ b/lib/features/book_appointments/book_appointments_repo.dart @@ -7,6 +7,7 @@ import 'package:hmg_patient_app_new/core/utils/date_util.dart'; import 'package:hmg_patient_app_new/features/book_appointments/models/resp_models/doctor_profile_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/my_appointments/models/resp_models/hospital_model.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/services/logger_service.dart'; @@ -40,6 +41,9 @@ abstract class BookAppointmentsRepo { String? invoiceNoVP, Function(dynamic)? onSuccess, Function(String)? onError}); + + Future>>> + getProjectList(); } class BookAppointmentsRepoImp implements BookAppointmentsRepo { @@ -362,4 +366,47 @@ class BookAppointmentsRepoImp implements BookAppointmentsRepo { return Left(UnknownFailure(e.toString())); } } + + @override + Future>>> + getProjectList() async { + Map request = {}; + + try { + GenericApiModel>? apiResponse; + Failure? failure; + await apiClient.post( + GET_PROJECT_LIST, + body: request, + onFailure: (error, statusCode, {messageStatus, failureType}) { + failure = failureType; + }, + onSuccess: (response, statusCode, {messageStatus, errorMessage}) { + try { + final list = response['ListProject']; + + final appointmentsList = list + .map((item) => + HospitalsModel.fromJson(item as Map)) + .toList() + .cast(); + + apiResponse = GenericApiModel>( + messageStatus: messageStatus, + statusCode: statusCode, + errorMessage: null, + data: appointmentsList, + ); + } catch (e) { + failure = DataParsingFailure(e.toString()); + } + }, + ); + if (failure != null) return Left(failure!); + if (apiResponse == null) return Left(ServerFailure("Unknown error")); + return Right(apiResponse!); + } catch (e) { + return Left(UnknownFailure(e.toString())); + } + } } diff --git a/lib/features/book_appointments/book_appointments_view_model.dart b/lib/features/book_appointments/book_appointments_view_model.dart index 854b4fc..271db44 100644 --- a/lib/features/book_appointments/book_appointments_view_model.dart +++ b/lib/features/book_appointments/book_appointments_view_model.dart @@ -1,8 +1,10 @@ import 'package:easy_localization/easy_localization.dart'; 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'; 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/doctor_response_mapper.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'; @@ -13,6 +15,8 @@ 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/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/my_appointments/models/facility_selection.dart'; +import 'package:hmg_patient_app_new/features/my_appointments/models/resp_models/doctor_list_api_response.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'; @@ -21,6 +25,7 @@ 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'; +import 'package:location/location.dart' show Location; class BookAppointmentsViewModel extends ChangeNotifier { int selectedTabIndex = 0; @@ -60,6 +65,10 @@ class BookAppointmentsViewModel extends ChangeNotifier { MyAppointmentsViewModel myAppointmentsViewModel; late AppState _appState; + RegionList? hospitalList; + RegionList? filteredHospitalList; + FacilitySelection currentlySelectedFacility = FacilitySelection.ALL; + bool isRegionListLoading = false; BookAppointmentsViewModel({required this.bookAppointmentsRepo, required this.errorHandlerService, required this.navigationService, required this.myAppointmentsViewModel}); @@ -380,4 +389,84 @@ class BookAppointmentsViewModel extends ChangeNotifier { }, ); } + + Future getRegionMappedProjectList() async { + if(hospitalList != null && hospitalList!.registeredDoctorMap != null && hospitalList!.registeredDoctorMap!.isNotEmpty){ + filteredHospitalList = hospitalList; + return; + } + isRegionListLoading = true; + notifyListeners(); + final result = await bookAppointmentsRepo.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 isLocationEnabled() async{ + return await Location().serviceEnabled(); + } + + bool getLocationStatus() { + bool isLocationAvaiable = false; + isLocationEnabled().then((value) => isLocationAvaiable = value); + return isLocationAvaiable; + } } diff --git a/lib/features/my_appointments/my_appointments_repo.dart b/lib/features/my_appointments/my_appointments_repo.dart index 44c3954..e4745cb 100644 --- a/lib/features/my_appointments/my_appointments_repo.dart +++ b/lib/features/my_appointments/my_appointments_repo.dart @@ -39,8 +39,7 @@ abstract class MyAppointmentsRepo { Future>>> getPatientDoctorsList(); - Future>>> - getProjectList(); + } class MyAppointmentsRepoImp implements MyAppointmentsRepo { @@ -496,47 +495,4 @@ class MyAppointmentsRepoImp implements MyAppointmentsRepo { return Left(UnknownFailure(e.toString())); } } - - @override - Future>>> - getProjectList() async { - Map request = {}; - - try { - GenericApiModel>? apiResponse; - Failure? failure; - await apiClient.post( - GET_PROJECT_LIST, - body: request, - onFailure: (error, statusCode, {messageStatus, failureType}) { - failure = failureType; - }, - onSuccess: (response, statusCode, {messageStatus, errorMessage}) { - try { - final list = response['ListProject']; - - final appointmentsList = list - .map((item) => - HospitalsModel.fromJson(item as Map)) - .toList() - .cast(); - - apiResponse = GenericApiModel>( - messageStatus: messageStatus, - statusCode: statusCode, - errorMessage: null, - data: appointmentsList, - ); - } catch (e) { - failure = DataParsingFailure(e.toString()); - } - }, - ); - if (failure != null) return Left(failure!); - if (apiResponse == null) return Left(ServerFailure("Unknown error")); - return Right(apiResponse!); - } catch (e) { - return Left(UnknownFailure(e.toString())); - } - } } diff --git a/lib/presentation/appointments/widgets/faculity_selection/facility_type_selection_widget.dart b/lib/presentation/appointments/widgets/faculity_selection/facility_type_selection_widget.dart index 64af81e..e1ff677 100644 --- a/lib/presentation/appointments/widgets/faculity_selection/facility_type_selection_widget.dart +++ b/lib/presentation/appointments/widgets/faculity_selection/facility_type_selection_widget.dart @@ -5,6 +5,7 @@ import 'package:hmg_patient_app_new/core/app_assets.dart'; import 'package:hmg_patient_app_new/core/utils/size_utils.dart'; import 'package:hmg_patient_app_new/extensions/string_extensions.dart'; import 'package:hmg_patient_app_new/extensions/widget_extensions.dart'; +import 'package:hmg_patient_app_new/features/book_appointments/book_appointments_view_model.dart'; import 'package:hmg_patient_app_new/features/my_appointments/appointment_via_region_viewmodel.dart'; import 'package:hmg_patient_app_new/features/my_appointments/models/facility_selection.dart'; import 'package:hmg_patient_app_new/features/my_appointments/my_appointments_view_model.dart' @@ -15,7 +16,7 @@ import 'package:hmg_patient_app_new/theme/colors.dart'; import 'package:provider/provider.dart' show Provider; class FacilityTypeSelectionWidget extends StatelessWidget { - late MyAppointmentsViewModel myAppointmentsViewModel; + late BookAppointmentsViewModel bookAppointmentViewModel; late AppointmentViaRegionViewmodel regionalViewModel; final String selectedRegion; @@ -23,7 +24,7 @@ class FacilityTypeSelectionWidget extends StatelessWidget { @override Widget build(BuildContext context) { - myAppointmentsViewModel = Provider.of(context); + bookAppointmentViewModel = Provider.of(context); regionalViewModel = Provider.of(context); return Column( crossAxisAlignment: CrossAxisAlignment.start, @@ -50,7 +51,7 @@ class FacilityTypeSelectionWidget extends StatelessWidget { title: "HMG".needTranslation, subTitle: LocaleKeys.hospitalsWithCount.tr(namedArgs: { 'count': - "${myAppointmentsViewModel.hospitalList?.registeredDoctorMap?[selectedRegion]?.hmgSize ?? 0}" + "${bookAppointmentViewModel.hospitalList?.registeredDoctorMap?[selectedRegion]?.hmgSize ?? 0}" }), ).onPress( () { @@ -65,7 +66,7 @@ class FacilityTypeSelectionWidget extends StatelessWidget { title: "HMC".needTranslation, subTitle: LocaleKeys.medicalCentersWithCount.tr(namedArgs: { 'count': - "${myAppointmentsViewModel.hospitalList?.registeredDoctorMap?[selectedRegion]?.hmcSize ?? 0}" + "${bookAppointmentViewModel.hospitalList?.registeredDoctorMap?[selectedRegion]?.hmcSize ?? 0}" })).onPress( () { regionalViewModel.setFacility(FacilitySelection.HMC.name); diff --git a/lib/presentation/appointments/widgets/hospital_bottom_sheet/hospital_bottom_sheet_body.dart b/lib/presentation/appointments/widgets/hospital_bottom_sheet/hospital_bottom_sheet_body.dart index 803d75c..242c7ca 100644 --- a/lib/presentation/appointments/widgets/hospital_bottom_sheet/hospital_bottom_sheet_body.dart +++ b/lib/presentation/appointments/widgets/hospital_bottom_sheet/hospital_bottom_sheet_body.dart @@ -4,6 +4,7 @@ import 'package:flutter/material.dart'; import 'package:hmg_patient_app_new/core/enums.dart'; import 'package:hmg_patient_app_new/core/utils/size_utils.dart'; import 'package:hmg_patient_app_new/extensions/string_extensions.dart'; +import 'package:hmg_patient_app_new/features/book_appointments/book_appointments_view_model.dart'; import 'package:hmg_patient_app_new/features/my_appointments/appointment_via_region_viewmodel.dart'; import 'package:hmg_patient_app_new/features/my_appointments/models/facility_selection.dart'; import 'package:hmg_patient_app_new/features/my_appointments/my_appointments_view_model.dart'; @@ -16,7 +17,7 @@ import 'package:hmg_patient_app_new/widgets/input_widget.dart'; import 'package:provider/provider.dart'; class HospitalBottomSheetBody extends StatelessWidget { - late MyAppointmentsViewModel appointmentsViewModel; + late BookAppointmentsViewModel appointmentsViewModel; late AppointmentViaRegionViewmodel regionalViewModel; final TextEditingController searchText = TextEditingController(); @@ -24,7 +25,7 @@ class HospitalBottomSheetBody extends StatelessWidget { @override Widget build(BuildContext context) { - appointmentsViewModel = Provider.of(context); + appointmentsViewModel = Provider.of(context); regionalViewModel = Provider.of(context); return Column( crossAxisAlignment: CrossAxisAlignment.start, diff --git a/lib/presentation/appointments/widgets/hospital_bottom_sheet/type_selection_widget.dart b/lib/presentation/appointments/widgets/hospital_bottom_sheet/type_selection_widget.dart index 8f09e1a..b023f7a 100644 --- a/lib/presentation/appointments/widgets/hospital_bottom_sheet/type_selection_widget.dart +++ b/lib/presentation/appointments/widgets/hospital_bottom_sheet/type_selection_widget.dart @@ -2,6 +2,7 @@ import 'package:flutter/material.dart'; import 'package:hmg_patient_app_new/core/app_assets.dart'; import 'package:hmg_patient_app_new/extensions/string_extensions.dart'; import 'package:hmg_patient_app_new/extensions/widget_extensions.dart'; +import 'package:hmg_patient_app_new/features/book_appointments/book_appointments_view_model.dart'; import 'package:hmg_patient_app_new/features/my_appointments/models/facility_selection.dart'; import 'package:hmg_patient_app_new/features/my_appointments/my_appointments_view_model.dart'; import 'package:hmg_patient_app_new/theme/colors.dart'; @@ -17,7 +18,7 @@ class TypeSelectionWidget extends StatelessWidget { @override Widget build(BuildContext context) { - return Consumer( + return Consumer( builder: (_, data, __) => Row( spacing: 8, mainAxisSize: MainAxisSize.max, diff --git a/lib/presentation/appointments/widgets/region_bottomsheet/region_list_widget.dart b/lib/presentation/appointments/widgets/region_bottomsheet/region_list_widget.dart index d68637b..180185f 100644 --- a/lib/presentation/appointments/widgets/region_bottomsheet/region_list_widget.dart +++ b/lib/presentation/appointments/widgets/region_bottomsheet/region_list_widget.dart @@ -4,6 +4,7 @@ import 'package:flutter/material.dart'; import 'package:hmg_patient_app_new/core/utils/size_utils.dart'; import 'package:hmg_patient_app_new/core/utils/utils.dart' show Utils; import 'package:hmg_patient_app_new/extensions/widget_extensions.dart'; +import 'package:hmg_patient_app_new/features/book_appointments/book_appointments_view_model.dart'; import 'package:hmg_patient_app_new/features/my_appointments/appointment_via_region_viewmodel.dart'; import 'package:hmg_patient_app_new/features/my_appointments/my_appointments_view_model.dart' show MyAppointmentsViewModel; @@ -20,7 +21,7 @@ class RegionBottomSheetBody extends StatefulWidget { } class _RegionBottomSheetBodyState extends State { - late MyAppointmentsViewModel myAppointmentsViewModel; + late BookAppointmentsViewModel myAppointmentsViewModel; late AppointmentViaRegionViewmodel regionalViewModel; @override @@ -33,9 +34,9 @@ class _RegionBottomSheetBodyState extends State { @override Widget build(BuildContext context) { - myAppointmentsViewModel = Provider.of(context); + myAppointmentsViewModel = Provider.of(context); regionalViewModel = Provider.of(context); - return Consumer( + return Consumer( builder: (context, myAppointmentsVM, child) { if (myAppointmentsVM.isRegionListLoading) { return Container( diff --git a/lib/presentation/authentication/register.dart b/lib/presentation/authentication/register.dart index 8ec988d..f9da835 100644 --- a/lib/presentation/authentication/register.dart +++ b/lib/presentation/authentication/register.dart @@ -296,6 +296,7 @@ class _RegisterNew extends State { borderColor: AppColors.borderOnlyColor, textColor: AppColors.textColor, icon: AppAssets.whatsapp, + iconColor: null, ), ), ],