|
|
|
|
@ -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';
|
|
|
|
|
@ -49,7 +50,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;
|
|
|
|
|
@ -62,23 +63,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 {
|
|
|
|
|
@ -134,8 +120,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();
|
|
|
|
|
}
|
|
|
|
|
@ -164,6 +150,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;
|
|
|
|
|
@ -293,9 +291,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,
|
|
|
|
|
@ -345,10 +343,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;
|
|
|
|
|
@ -370,18 +367,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;
|
|
|
|
|
}
|
|
|
|
|
@ -403,8 +402,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 {
|
|
|
|
|
@ -513,7 +512,6 @@ class AuthenticationViewModel extends ChangeNotifier {
|
|
|
|
|
notifyListeners();
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
this.selectedOption = selectedOption;
|
|
|
|
|
notifyListeners();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@ -569,16 +567,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 {
|
|
|
|
|
@ -587,23 +585,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;
|
|
|
|
|
@ -615,13 +610,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);
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
@ -661,6 +655,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);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@override
|
|
|
|
|
void dispose() {
|
|
|
|
|
nationalIdController.dispose();
|
|
|
|
|
|