|  |  |  | @ -1,6 +1,6 @@ | 
		
	
		
			
				|  |  |  |  | import 'dart:convert'; | 
		
	
		
			
				|  |  |  |  | import 'dart:developer'; | 
		
	
		
			
				|  |  |  |  | 
 | 
		
	
		
			
				|  |  |  |  | import 'package:flutter/services.dart' show rootBundle; | 
		
	
		
			
				|  |  |  |  | import 'package:flutter/material.dart'; | 
		
	
		
			
				|  |  |  |  | import 'package:hijri_gregorian_calendar/hijri_gregorian_calendar.dart'; | 
		
	
		
			
				|  |  |  |  | import 'package:hmg_patient_app_new/core/app_state.dart'; | 
		
	
	
		
			
				
					|  |  |  | @ -14,6 +14,7 @@ import 'package:hmg_patient_app_new/core/utils/validation_utils.dart'; | 
		
	
		
			
				|  |  |  |  | import 'package:hmg_patient_app_new/extensions/string_extensions.dart'; | 
		
	
		
			
				|  |  |  |  | import 'package:hmg_patient_app_new/features/authentication/authentication_repo.dart'; | 
		
	
		
			
				|  |  |  |  | import 'package:hmg_patient_app_new/features/authentication/models/request_models/check_activation_code_register_request_model.dart'; | 
		
	
		
			
				|  |  |  |  | import 'package:hmg_patient_app_new/features/authentication/models/request_models/registration_payload_model.dart'; | 
		
	
		
			
				|  |  |  |  | import 'package:hmg_patient_app_new/features/authentication/models/resp_models/check_activation_code_resp_model.dart'; | 
		
	
		
			
				|  |  |  |  | import 'package:hmg_patient_app_new/features/authentication/models/resp_models/check_user_staus_nhic_response_model.dart'; | 
		
	
		
			
				|  |  |  |  | import 'package:hmg_patient_app_new/features/authentication/models/resp_models/select_device_by_imei.dart'; | 
		
	
	
		
			
				
					|  |  |  | @ -52,7 +53,7 @@ class AuthenticationViewModel extends ChangeNotifier { | 
		
	
		
			
				|  |  |  |  |         _authenticationRepo = authenticationRepo, | 
		
	
		
			
				|  |  |  |  |         _localAuthService = localAuthService; | 
		
	
		
			
				|  |  |  |  | 
 | 
		
	
		
			
				|  |  |  |  |   final TextEditingController nationalIdController = TextEditingController(), phoneNumberController = TextEditingController(), dobController = TextEditingController(); | 
		
	
		
			
				|  |  |  |  |   final TextEditingController nationalIdController = TextEditingController(), phoneNumberController = TextEditingController(), dobController = TextEditingController(), nameController = TextEditingController(); | 
		
	
		
			
				|  |  |  |  |   CountryEnum selectedCountrySignup = CountryEnum.saudiArabia; | 
		
	
		
			
				|  |  |  |  |   MaritalStatusTypeEnum? maritalStatus; | 
		
	
		
			
				|  |  |  |  |   GenderTypeEnum? genderType; | 
		
	
	
		
			
				
					|  |  |  | @ -66,23 +67,8 @@ class AuthenticationViewModel extends ChangeNotifier { | 
		
	
		
			
				|  |  |  |  | 
 | 
		
	
		
			
				|  |  |  |  |   //================== | 
		
	
		
			
				|  |  |  |  | 
 | 
		
	
		
			
				|  |  |  |  |   bool isDubai = false; | 
		
	
		
			
				|  |  |  |  |   bool authenticated = false; | 
		
	
		
			
				|  |  |  |  |   late int mobileNumber; | 
		
	
		
			
				|  |  |  |  |   String errorMsg = ''; | 
		
	
		
			
				|  |  |  |  |   var registerd_data; | 
		
	
		
			
				|  |  |  |  |   bool isMoreOption = false; | 
		
	
		
			
				|  |  |  |  |   var zipCode; | 
		
	
		
			
				|  |  |  |  |   var patientOutSA; | 
		
	
		
			
				|  |  |  |  |   var loginTokenID; | 
		
	
		
			
				|  |  |  |  |   var loginType; | 
		
	
		
			
				|  |  |  |  |   var deviceToken; | 
		
	
		
			
				|  |  |  |  |   var lastLogin; | 
		
	
		
			
				|  |  |  |  |   final FocusNode myFocusNode = FocusNode(); | 
		
	
		
			
				|  |  |  |  |   late int selectedOption = 1; | 
		
	
		
			
				|  |  |  |  |   bool onlySMSBox = false; | 
		
	
		
			
				|  |  |  |  |   int fingrePrintBefore = 0; | 
		
	
		
			
				|  |  |  |  | 
 | 
		
	
		
			
				|  |  |  |  |   var healthId; | 
		
	
		
			
				|  |  |  |  | 
 | 
		
	
		
			
				|  |  |  |  |   Future<void> onLoginPressed() async { | 
		
	
	
		
			
				
					|  |  |  | @ -138,8 +124,8 @@ class AuthenticationViewModel extends ChangeNotifier { | 
		
	
		
			
				|  |  |  |  |     notifyListeners(); | 
		
	
		
			
				|  |  |  |  |   } | 
		
	
		
			
				|  |  |  |  | 
 | 
		
	
		
			
				|  |  |  |  |   void loadCountriesData({required BuildContext context}) async { | 
		
	
		
			
				|  |  |  |  |     final String response = await DefaultAssetBundle.of(context).loadString('assets/json/countriesList.json'); | 
		
	
		
			
				|  |  |  |  |   Future<void> loadCountriesData() async { | 
		
	
		
			
				|  |  |  |  |     final String response = await rootBundle.loadString('assets/json/countriesList.json'); | 
		
	
		
			
				|  |  |  |  |     final List<dynamic> data = json.decode(response); | 
		
	
		
			
				|  |  |  |  |     countriesList = data.map((e) => NationalityCountries.fromJson(e)).toList(); | 
		
	
		
			
				|  |  |  |  |   } | 
		
	
	
		
			
				
					|  |  |  | @ -168,6 +154,18 @@ class AuthenticationViewModel extends ChangeNotifier { | 
		
	
		
			
				|  |  |  |  |     notifyListeners(); | 
		
	
		
			
				|  |  |  |  |   } | 
		
	
		
			
				|  |  |  |  | 
 | 
		
	
		
			
				|  |  |  |  |   bool isUserFromUAE() { | 
		
	
		
			
				|  |  |  |  |     bool isFromUAE = false; | 
		
	
		
			
				|  |  |  |  |     if (_appState.getUserRegistrationPayload.patientOutSa != 0) { | 
		
	
		
			
				|  |  |  |  |       isFromUAE = true; | 
		
	
		
			
				|  |  |  |  |     } | 
		
	
		
			
				|  |  |  |  |     return isFromUAE; | 
		
	
		
			
				|  |  |  |  |   } | 
		
	
		
			
				|  |  |  |  | 
 | 
		
	
		
			
				|  |  |  |  |   void savePushTokenToAppState() async { | 
		
	
		
			
				|  |  |  |  |     _appState.deviceToken = await Utils.getStringFromPrefs(CacheConst.pushToken); | 
		
	
		
			
				|  |  |  |  |   } | 
		
	
		
			
				|  |  |  |  | 
 | 
		
	
		
			
				|  |  |  |  |   Future<void> selectDeviceImei({required Function(dynamic data) onSuccess, Function(String)? onError}) async { | 
		
	
		
			
				|  |  |  |  |     // LoadingUtils.showFullScreenLoading(); | 
		
	
		
			
				|  |  |  |  |     // String firebaseToken = _appState.deviceToken; | 
		
	
	
		
			
				
					|  |  |  | @ -299,9 +297,9 @@ class AuthenticationViewModel extends ChangeNotifier { | 
		
	
		
			
				|  |  |  |  |   } | 
		
	
		
			
				|  |  |  |  | 
 | 
		
	
		
			
				|  |  |  |  |   Future<void> sendActivationCode({required OTPTypeEnum otpTypeEnum, required String nationalIdOrFileNumber, required String phoneNumber, dynamic payload}) async { | 
		
	
		
			
				|  |  |  |  |     bool isForRegister = await checkIsUserComingForRegister(request: payload); | 
		
	
		
			
				|  |  |  |  |     bool isPatientOutSA = await isPatientOutsideSA(request: payload); | 
		
	
		
			
				|  |  |  |  |     bool isFileNo = await isPatientHasFile(request: payload); | 
		
	
		
			
				|  |  |  |  |     bool isForRegister = checkIsUserComingForRegister(request: payload); | 
		
	
		
			
				|  |  |  |  |     bool isPatientOutSA = isPatientOutsideSA(request: payload); | 
		
	
		
			
				|  |  |  |  |     bool isFileNo = isPatientHasFile(request: payload); | 
		
	
		
			
				|  |  |  |  | 
 | 
		
	
		
			
				|  |  |  |  |     var request = RequestUtils.getCommonRequestSendActivationCode( | 
		
	
		
			
				|  |  |  |  |         otpTypeEnum: otpTypeEnum, | 
		
	
	
		
			
				
					|  |  |  | @ -351,10 +349,9 @@ class AuthenticationViewModel extends ChangeNotifier { | 
		
	
		
			
				|  |  |  |  |     ); | 
		
	
		
			
				|  |  |  |  |   } | 
		
	
		
			
				|  |  |  |  | 
 | 
		
	
		
			
				|  |  |  |  |   Future<bool> checkIsUserComingForRegister({required dynamic request}) async { | 
		
	
		
			
				|  |  |  |  |   bool checkIsUserComingForRegister({required dynamic request}) { | 
		
	
		
			
				|  |  |  |  |     bool isUserComingForRegister = false; | 
		
	
		
			
				|  |  |  |  |     print(request); | 
		
	
		
			
				|  |  |  |  |     if (request != null && request['isRegister']) { | 
		
	
		
			
				|  |  |  |  |     if (request != null && request['isRegister'] == true) { | 
		
	
		
			
				|  |  |  |  |       isUserComingForRegister = true; | 
		
	
		
			
				|  |  |  |  |     } | 
		
	
		
			
				|  |  |  |  |     return isUserComingForRegister; | 
		
	
	
		
			
				
					|  |  |  | @ -376,18 +373,20 @@ class AuthenticationViewModel extends ChangeNotifier { | 
		
	
		
			
				|  |  |  |  |       countryCode: selectedCountrySignup.countryCode, | 
		
	
		
			
				|  |  |  |  |     ).toJson(); | 
		
	
		
			
				|  |  |  |  | 
 | 
		
	
		
			
				|  |  |  |  |     bool isForRegister = healthId != null || isDubai; | 
		
	
		
			
				|  |  |  |  |     bool isForRegister = _appState.getUserRegistrationPayload.healthId != null || _appState.getUserRegistrationPayload.patientOutSa == true; | 
		
	
		
			
				|  |  |  |  |     if (isForRegister) { | 
		
	
		
			
				|  |  |  |  |       if (isDubai) request['DOB'] = dob; | 
		
	
		
			
				|  |  |  |  |       request['HealthId'] = healthId; | 
		
	
		
			
				|  |  |  |  |       request['IsHijri'] = calenderType.toInt; | 
		
	
		
			
				|  |  |  |  |       if (_appState.getUserRegistrationPayload.patientOutSa == true) request['DOB'] = _appState.getUserRegistrationPayload.dob; | 
		
	
		
			
				|  |  |  |  |       request['HealthId'] = _appState.getUserRegistrationPayload.healthId; | 
		
	
		
			
				|  |  |  |  |       request['IsHijri'] = _appState.getUserRegistrationPayload.isHijri; | 
		
	
		
			
				|  |  |  |  | 
 | 
		
	
		
			
				|  |  |  |  |       final resultEither = await _authenticationRepo.checkActivationCodeRepo(newRequest: request, activationCode: activationCode.toString(), isRegister: true); | 
		
	
		
			
				|  |  |  |  | 
 | 
		
	
		
			
				|  |  |  |  |       resultEither.fold((failure) async => await _errorHandlerService.handleError(failure: failure), (apiResponse) { | 
		
	
		
			
				|  |  |  |  |         final activation = CheckActivationCode.fromJson(apiResponse.data as Map<String, dynamic>); | 
		
	
		
			
				|  |  |  |  |         if (registerd_data?.isRegister == true) { | 
		
	
		
			
				|  |  |  |  |           _navigationService.popUntilNamed(AppRoutes.registerNewScreen); | 
		
	
		
			
				|  |  |  |  |         if (_appState.getUserRegistrationPayload.isRegister == true) { | 
		
	
		
			
				|  |  |  |  |           //TODO: KSA Version Came Hre | 
		
	
		
			
				|  |  |  |  |           loadCountriesData(); | 
		
	
		
			
				|  |  |  |  |           _navigationService.pushAndReplace(AppRoutes.registerStepTwo); | 
		
	
		
			
				|  |  |  |  |           // Navigator.popUntil(context, (route) => Utils.route(route, equalsTo: RegisterNew)); | 
		
	
		
			
				|  |  |  |  |           return; | 
		
	
		
			
				|  |  |  |  |         } | 
		
	
	
		
			
				
					|  |  |  | @ -409,8 +408,8 @@ class AuthenticationViewModel extends ChangeNotifier { | 
		
	
		
			
				|  |  |  |  |         } else if (activation.messageStatus == 2) { | 
		
	
		
			
				|  |  |  |  |           onWrongActivationCode(activation.errorEndUserMessage); | 
		
	
		
			
				|  |  |  |  |           return; | 
		
	
		
			
				|  |  |  |  |         } else if (registerd_data?.isRegister == true) { | 
		
	
		
			
				|  |  |  |  |           _navigationService.popUntilNamed(AppRoutes.registerNewScreen); | 
		
	
		
			
				|  |  |  |  |         } else if (_appState.getUserRegistrationPayload.isRegister == true) { | 
		
	
		
			
				|  |  |  |  |           _navigationService.pushAndReplace(AppRoutes.registerStepTwo); | 
		
	
		
			
				|  |  |  |  |           // Navigator.popUntil(context, (route) => Utils.route(route, equalsTo: RegisterNew)); | 
		
	
		
			
				|  |  |  |  |           return; | 
		
	
		
			
				|  |  |  |  |         } else { | 
		
	
	
		
			
				
					|  |  |  | @ -520,7 +519,6 @@ class AuthenticationViewModel extends ChangeNotifier { | 
		
	
		
			
				|  |  |  |  |         notifyListeners(); | 
		
	
		
			
				|  |  |  |  |       } | 
		
	
		
			
				|  |  |  |  |     }); | 
		
	
		
			
				|  |  |  |  |     this.selectedOption = selectedOption; | 
		
	
		
			
				|  |  |  |  |     notifyListeners(); | 
		
	
		
			
				|  |  |  |  |   } | 
		
	
		
			
				|  |  |  |  | 
 | 
		
	
	
		
			
				
					|  |  |  | @ -586,16 +584,16 @@ class AuthenticationViewModel extends ChangeNotifier { | 
		
	
		
			
				|  |  |  |  |       } else { | 
		
	
		
			
				|  |  |  |  |         request['forRegister'] = true; | 
		
	
		
			
				|  |  |  |  |         request['isRegister'] = true; | 
		
	
		
			
				|  |  |  |  |         if (await isPatientOutsideSA(request: response)) { | 
		
	
		
			
				|  |  |  |  |           print("=======IN SA======="); | 
		
	
		
			
				|  |  |  |  |           chekUserNHICData(request: request); | 
		
	
		
			
				|  |  |  |  |         } else { | 
		
	
		
			
				|  |  |  |  |         if (isPatientOutsideSA(request: response)) { | 
		
	
		
			
				|  |  |  |  |           print("=======OUT SA======="); | 
		
	
		
			
				|  |  |  |  |           _appState.setAppAuthToken = response['LogInTokenID']; | 
		
	
		
			
				|  |  |  |  |           sendActivationCode( | 
		
	
		
			
				|  |  |  |  |               otpTypeEnum: OTPTypeEnumExtension.fromInt(request["OTP_SendType"]), | 
		
	
		
			
				|  |  |  |  |               nationalIdOrFileNumber: request["PatientIdentificationID"].toString(), | 
		
	
		
			
				|  |  |  |  |               phoneNumber: request["PatientMobileNumber"].toString()); | 
		
	
		
			
				|  |  |  |  |         } else { | 
		
	
		
			
				|  |  |  |  |           print("=======IN SA======="); | 
		
	
		
			
				|  |  |  |  |           chekUserNHICData(request: request); | 
		
	
		
			
				|  |  |  |  |         } | 
		
	
		
			
				|  |  |  |  |       } | 
		
	
		
			
				|  |  |  |  |     } else { | 
		
	
	
		
			
				
					|  |  |  | @ -604,23 +602,20 @@ class AuthenticationViewModel extends ChangeNotifier { | 
		
	
		
			
				|  |  |  |  |     } | 
		
	
		
			
				|  |  |  |  |   } | 
		
	
		
			
				|  |  |  |  | 
 | 
		
	
		
			
				|  |  |  |  |   Future<bool> isPatientOutsideSA({required dynamic request}) { | 
		
	
		
			
				|  |  |  |  |     try { | 
		
	
		
			
				|  |  |  |  |       if (request is Map<String, dynamic> && request.containsKey("PatientOutSA")) { | 
		
	
		
			
				|  |  |  |  |         if (!request["PatientOutSA"]) { | 
		
	
		
			
				|  |  |  |  |           return Future.value(true); | 
		
	
		
			
				|  |  |  |  |         } else { | 
		
	
		
			
				|  |  |  |  |           return Future.value(false); | 
		
	
		
			
				|  |  |  |  |         } | 
		
	
		
			
				|  |  |  |  |   bool isPatientOutsideSA({required dynamic request}) { | 
		
	
		
			
				|  |  |  |  |     bool isOutSideSa = false; | 
		
	
		
			
				|  |  |  |  |     if (request is Map<String, dynamic> && request.containsKey("PatientOutSA")) { | 
		
	
		
			
				|  |  |  |  |       if (request["PatientOutSA"] == true) { | 
		
	
		
			
				|  |  |  |  |         isOutSideSa = true; | 
		
	
		
			
				|  |  |  |  |       } else { | 
		
	
		
			
				|  |  |  |  |         return Future.value(false); | 
		
	
		
			
				|  |  |  |  |         isOutSideSa = false; | 
		
	
		
			
				|  |  |  |  |       } | 
		
	
		
			
				|  |  |  |  |     } catch (e) { | 
		
	
		
			
				|  |  |  |  |       return Future.value(false); | 
		
	
		
			
				|  |  |  |  |     } | 
		
	
		
			
				|  |  |  |  |     print(isOutSideSa); | 
		
	
		
			
				|  |  |  |  |     return isOutSideSa; | 
		
	
		
			
				|  |  |  |  |   } | 
		
	
		
			
				|  |  |  |  | 
 | 
		
	
		
			
				|  |  |  |  |   Future<bool> isPatientHasFile({required dynamic request}) async { | 
		
	
		
			
				|  |  |  |  |   bool isPatientHasFile({required dynamic request}) { | 
		
	
		
			
				|  |  |  |  |     bool isFile = false; | 
		
	
		
			
				|  |  |  |  |     if (request != null && request["NationalID"] != null) { | 
		
	
		
			
				|  |  |  |  |       isFile = request["NationalID"].length < 10; | 
		
	
	
		
			
				
					|  |  |  | @ -632,13 +627,12 @@ class AuthenticationViewModel extends ChangeNotifier { | 
		
	
		
			
				|  |  |  |  |     final resultEither = await _authenticationRepo.checkUserStatus(commonAuthanticatedRequest: request); | 
		
	
		
			
				|  |  |  |  |     resultEither.fold((failure) async => await _errorHandlerService.handleError(failure: failure), (apiResponse) async { | 
		
	
		
			
				|  |  |  |  |       if (apiResponse.data is Map) { | 
		
	
		
			
				|  |  |  |  |         _appState.setNHICUserData = CheckUserStatusResponseNHIC.fromJson(apiResponse.data as Map<String, dynamic>); | 
		
	
		
			
				|  |  |  |  |         setNHICData(apiResponse.data, request); | 
		
	
		
			
				|  |  |  |  |         sendActivationCode( | 
		
	
		
			
				|  |  |  |  |           otpTypeEnum: OTPTypeEnumExtension.fromInt(request["OTP_SendType"]), | 
		
	
		
			
				|  |  |  |  |           nationalIdOrFileNumber: request["PatientIdentificationID"].toString(), | 
		
	
		
			
				|  |  |  |  |           phoneNumber: request["PatientMobileNumber"].toString(), | 
		
	
		
			
				|  |  |  |  |           payload: request, | 
		
	
		
			
				|  |  |  |  |         ); | 
		
	
		
			
				|  |  |  |  |             otpTypeEnum: OTPTypeEnumExtension.fromInt(request["OTP_SendType"]), | 
		
	
		
			
				|  |  |  |  |             nationalIdOrFileNumber: request["PatientIdentificationID"].toString(), | 
		
	
		
			
				|  |  |  |  |             phoneNumber: request["PatientMobileNumber"].toString(), | 
		
	
		
			
				|  |  |  |  |             payload: request); | 
		
	
		
			
				|  |  |  |  |       } | 
		
	
		
			
				|  |  |  |  |     }); | 
		
	
		
			
				|  |  |  |  | 
 | 
		
	
	
		
			
				
					|  |  |  | @ -678,6 +672,12 @@ class AuthenticationViewModel extends ChangeNotifier { | 
		
	
		
			
				|  |  |  |  |     // }); | 
		
	
		
			
				|  |  |  |  |   } | 
		
	
		
			
				|  |  |  |  | 
 | 
		
	
		
			
				|  |  |  |  |   void setNHICData(dynamic data, dynamic request) { | 
		
	
		
			
				|  |  |  |  |     _appState.setNHICUserData = CheckUserStatusResponseNHIC.fromJson(data as Map<String, dynamic>); | 
		
	
		
			
				|  |  |  |  |     request["healthId"] = _appState.getNHICUserData.healthId; | 
		
	
		
			
				|  |  |  |  |     _appState.setUserRegistrationPayload = RegistrationDataModelPayload.fromJson(request); | 
		
	
		
			
				|  |  |  |  |   } | 
		
	
		
			
				|  |  |  |  | 
 | 
		
	
		
			
				|  |  |  |  |     Future<void>  insertPatientIMEIData(int loginType) async{ | 
		
	
		
			
				|  |  |  |  | 
 | 
		
	
		
			
				|  |  |  |  |       final resultEither = await _authenticationRepo.insertPatientIMEIData(patientIMEIDataRequest: PatientInsertDeviceImei(imei: _appState.deviceToken, deviceTypeId: _appState.getDeviceTypeID(), patientId: _appState.getAuthenticatedUser()!.patientId!, patientIdentificationNo:_appState.getAuthenticatedUser()!.nationalityId!, firstName:  _appState.getAuthenticatedUser()!.firstName!,  lastName:  _appState.getAuthenticatedUser()!.lastName!, patientTypeId: _appState.getAuthenticatedUser()!.patientType, mobileNo:_appState.getAuthenticatedUser()!.mobileNumber!, logInTypeId: loginType, patientOutSa:_appState.getAuthenticatedUser()!.outSa! ).toJson()); | 
		
	
	
		
			
				
					|  |  |  | 
 |