|
|
|
|
@ -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';
|
|
|
|
|
@ -26,6 +27,9 @@ import 'package:hmg_patient_app_new/services/error_handler_service.dart';
|
|
|
|
|
import 'package:hmg_patient_app_new/services/localauth_service.dart';
|
|
|
|
|
import 'package:hmg_patient_app_new/services/navigation_service.dart';
|
|
|
|
|
|
|
|
|
|
import 'models/request_models/insert_patient_mobile_deviceinfo.dart';
|
|
|
|
|
import 'models/request_models/patient_insert_device_imei_request.dart';
|
|
|
|
|
|
|
|
|
|
class AuthenticationViewModel extends ChangeNotifier {
|
|
|
|
|
final AuthenticationRepo _authenticationRepo;
|
|
|
|
|
final AppState _appState;
|
|
|
|
|
@ -49,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(), emailController = TextEditingController();
|
|
|
|
|
CountryEnum selectedCountrySignup = CountryEnum.saudiArabia;
|
|
|
|
|
MaritalStatusTypeEnum? maritalStatus;
|
|
|
|
|
GenderTypeEnum? genderType;
|
|
|
|
|
@ -59,26 +63,12 @@ class AuthenticationViewModel extends ChangeNotifier {
|
|
|
|
|
|
|
|
|
|
NationalityCountries? pickedCountryByUAEUser;
|
|
|
|
|
CalenderEnum calenderType = CalenderEnum.gregorian;
|
|
|
|
|
LoginTypeEnum loginTypeEnum = LoginTypeEnum.sms;
|
|
|
|
|
|
|
|
|
|
//==================
|
|
|
|
|
|
|
|
|
|
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 +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();
|
|
|
|
|
}
|
|
|
|
|
@ -164,11 +154,22 @@ 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;
|
|
|
|
|
// String firebaseToken = await Utils.getStringFromPrefs(CacheConst.pushToken);
|
|
|
|
|
String firebaseToken = "fY1fq_cITMmUCztA3UKKL9:APA91bEb2ZcdCPQPq3QsA0NW6a6btFvN-JjB1Pn3ZCoCzBMmVUhhh1ZQMtRn9tYPQ5G-jHDLiEpVAlBuRCVMkLDxa-zijsqbIui-4A-ynwclDWGFT4bUHTc";
|
|
|
|
|
String firebaseToken = await Utils.getStringFromPrefs(CacheConst.pushToken);
|
|
|
|
|
// == ""
|
|
|
|
|
// ? "dOGRRszQQMGe_9wA5Hx3kO:APA91bFV5IcIJXvcCXXk0tc2ddtZgWwCPq7sGSuPr-YW7iiJpQZKgFGN9GAzCVOWL8MfheaP1slE8MdxB7lczdPBGdONQ7WbMmhgHcsUCUktq-hsapGXXqc"
|
|
|
|
|
// : _appState.deviceToken;
|
|
|
|
|
@ -242,9 +243,11 @@ class AuthenticationViewModel extends ChangeNotifier {
|
|
|
|
|
Future<void> checkUserAuthentication({required OTPTypeEnum otpTypeEnum, Function(dynamic)? onSuccess, Function(String)? onError}) async {
|
|
|
|
|
// TODO: THIS SHOULD BE REMOVED LATER ON AND PASSED FROM APP STATE DIRECTLY INTO API CLIENT. BECAUSE THIS API ONLY NEEDS FEW PARAMS FROM USER
|
|
|
|
|
|
|
|
|
|
// if (phoneNumberController.text.isEmpty) {
|
|
|
|
|
// phoneNumberController.text = "504278212";
|
|
|
|
|
// }
|
|
|
|
|
loginTypeEnum = otpTypeEnum == OTPTypeEnum.sms ? LoginTypeEnum.sms : LoginTypeEnum.whatsapp;
|
|
|
|
|
|
|
|
|
|
if (phoneNumberController.text.isEmpty) {
|
|
|
|
|
phoneNumberController.text = "504278212";
|
|
|
|
|
}
|
|
|
|
|
bool isValidated = ValidationUtils.isValidatePhoneAndId(
|
|
|
|
|
phoneNumber: phoneNumberController.text,
|
|
|
|
|
nationalId: nationalIdController.text,
|
|
|
|
|
@ -286,7 +289,7 @@ class AuthenticationViewModel extends ChangeNotifier {
|
|
|
|
|
await checkActivationCode(
|
|
|
|
|
otpTypeEnum: otpTypeEnum,
|
|
|
|
|
onWrongActivationCode: (String? message) {},
|
|
|
|
|
activationCode: 0000,
|
|
|
|
|
activationCode: null, //todo silent login case halded on the repo itself..
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
@ -296,9 +299,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,
|
|
|
|
|
@ -348,17 +351,16 @@ 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;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Future<void> checkActivationCode({
|
|
|
|
|
required int activationCode,
|
|
|
|
|
required String? activationCode,
|
|
|
|
|
required OTPTypeEnum otpTypeEnum,
|
|
|
|
|
required Function(String? message) onWrongActivationCode,
|
|
|
|
|
}) async {
|
|
|
|
|
@ -371,20 +373,23 @@ class AuthenticationViewModel extends ChangeNotifier {
|
|
|
|
|
registeredData: null,
|
|
|
|
|
nationIdText: nationalIdController.text,
|
|
|
|
|
countryCode: selectedCountrySignup.countryCode,
|
|
|
|
|
loginType: loginTypeEnum.toInt
|
|
|
|
|
).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;
|
|
|
|
|
}
|
|
|
|
|
@ -392,7 +397,7 @@ class AuthenticationViewModel extends ChangeNotifier {
|
|
|
|
|
} else {
|
|
|
|
|
final resultEither = await _authenticationRepo.checkActivationCodeRepo(
|
|
|
|
|
newRequest: CheckActivationCodeRegisterReq.fromJson(request),
|
|
|
|
|
activationCode: activationCode.toString(),
|
|
|
|
|
activationCode: activationCode,
|
|
|
|
|
isRegister: false,
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
@ -406,8 +411,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 {
|
|
|
|
|
@ -418,6 +423,7 @@ class AuthenticationViewModel extends ChangeNotifier {
|
|
|
|
|
_appState.setAppAuthToken = activation.authenticationTokenId;
|
|
|
|
|
final request = RequestUtils.getAuthanticatedCommonRequest().toJson();
|
|
|
|
|
bool isUserAgreedBefore = await checkIfUserAgreedBefore(request: request);
|
|
|
|
|
insertPatientIMEIData(loginTypeEnum.toInt);
|
|
|
|
|
clearDefaultInputValues();
|
|
|
|
|
if (isUserAgreedBefore) {
|
|
|
|
|
navigateToHomeScreen();
|
|
|
|
|
@ -487,7 +493,7 @@ class AuthenticationViewModel extends ChangeNotifier {
|
|
|
|
|
phoneNumber: phoneNumber,
|
|
|
|
|
checkActivationCode: (int activationCode) async {
|
|
|
|
|
await checkActivationCode(
|
|
|
|
|
activationCode: activationCode,
|
|
|
|
|
activationCode: activationCode.toString(),
|
|
|
|
|
otpTypeEnum: otpTypeEnum,
|
|
|
|
|
onWrongActivationCode: (String? value) {
|
|
|
|
|
onWrongActivationCode(message: value);
|
|
|
|
|
@ -503,12 +509,20 @@ class AuthenticationViewModel extends ChangeNotifier {
|
|
|
|
|
await _dialogService.showErrorBottomSheet(message: message ?? "Something went wrong. ", onOkPressed: () {});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
loginWithFingerPrintFace(int selectedOption) async {
|
|
|
|
|
_localAuthService.authenticate().then((value) {
|
|
|
|
|
loginWithFingerPrintFace() async {
|
|
|
|
|
_localAuthService.authenticate().then((value) async {
|
|
|
|
|
if (value) {
|
|
|
|
|
// we have to handle this if verification true;
|
|
|
|
|
checkActivationCode(otpTypeEnum: OTPTypeEnum.faceIDFingerprint, activationCode: 0000, onWrongActivationCode: (String? message) {});
|
|
|
|
|
// authenticated = true;
|
|
|
|
|
if(!_appState.isAuthenticated) {
|
|
|
|
|
loginTypeEnum = (_appState.deviceTypeID == 1 ? LoginTypeEnum.face : LoginTypeEnum.fingerprint);
|
|
|
|
|
print(loginTypeEnum);
|
|
|
|
|
checkActivationCode(otpTypeEnum:OTPTypeEnum.faceIDFingerprint , activationCode: null, onWrongActivationCode: (String? message) {});
|
|
|
|
|
insertPatientIMEIData((_appState.deviceTypeID == 1 ? LoginTypeEnum.face.toInt : LoginTypeEnum.fingerprint.toInt));
|
|
|
|
|
}else {
|
|
|
|
|
// authenticated = true;
|
|
|
|
|
insertPatientIMEIData((_appState.deviceTypeID == 1 ? LoginTypeEnum.face.toInt : LoginTypeEnum.fingerprint.toInt));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
notifyListeners();
|
|
|
|
|
// navigateToHomeScreen();
|
|
|
|
|
} else {
|
|
|
|
|
@ -516,20 +530,28 @@ class AuthenticationViewModel extends ChangeNotifier {
|
|
|
|
|
notifyListeners();
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
this.selectedOption = selectedOption;
|
|
|
|
|
notifyListeners();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
checkLastLoginStatus(Function() onSuccess) async {
|
|
|
|
|
Future.delayed(Duration(seconds: 1), () {
|
|
|
|
|
if (_appState.getSelectDeviceByImeiRespModelElement != null &&
|
|
|
|
|
(_appState.getSelectDeviceByImeiRespModelElement!.logInType == 1 || _appState.getSelectDeviceByImeiRespModelElement!.logInType == 4)) {
|
|
|
|
|
Future.delayed(Duration(seconds: 1), () {
|
|
|
|
|
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)!;
|
|
|
|
|
nationalIdController.text = _appState.getAuthenticatedUser()!.nationalityId!;
|
|
|
|
|
onSuccess();
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Future<void> onRegisterPress({required OTPTypeEnum otpTypeEnum}) async {
|
|
|
|
|
Future<void> onRegistrationStart({required OTPTypeEnum otpTypeEnum}) async {
|
|
|
|
|
bool isOutSidePatient = selectedCountrySignup.countryCode == CountryEnum.unitedArabEmirates.countryCode ? true : false;
|
|
|
|
|
|
|
|
|
|
final request = await RequestUtils.getPatientAuthenticationRequest(
|
|
|
|
|
@ -560,6 +582,20 @@ class AuthenticationViewModel extends ChangeNotifier {
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Future<void> onRegistrationComplete() async{
|
|
|
|
|
|
|
|
|
|
// if (emailAddress.text.isEmpty) {
|
|
|
|
|
// Utils.showErrorToast(TranslationBase.of(context).enterEmailAddress);
|
|
|
|
|
// return;
|
|
|
|
|
// } else {
|
|
|
|
|
// Navigator.of(context).pop();
|
|
|
|
|
// registerNow();
|
|
|
|
|
// }
|
|
|
|
|
//authVM!.clearDefaultInputValues();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Future<void> checkUserStatusForRegistration({required dynamic response, required dynamic request}) async {
|
|
|
|
|
if (response is Map) {
|
|
|
|
|
_appState.setAppAuthToken = response["LogInTokenID"];
|
|
|
|
|
@ -572,16 +608,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 {
|
|
|
|
|
@ -590,23 +626,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;
|
|
|
|
|
@ -618,13 +651,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);
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
@ -664,6 +696,38 @@ 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!, outSa: _appState.getAuthenticatedUser()!.outSa == 1 ? true :false, biometricEnabled: loginType == 1 || loginType ==2 ? false :true, firstNameN:_appState.getAuthenticatedUser()!.firstNameN , lastNameN:_appState.getAuthenticatedUser()!.lastNameN ).toJson());
|
|
|
|
|
resultEither.fold((failure) async => await _errorHandlerService.handleError(failure: failure), (apiResponse) async {
|
|
|
|
|
if (apiResponse.messageStatus == 1) {
|
|
|
|
|
log("Insert IMEI Success");
|
|
|
|
|
insertPatientDeviceData( loginType);
|
|
|
|
|
} else {
|
|
|
|
|
log("Insert IMEI Failed");
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
Future<void> insertPatientDeviceData(int loginType) async{
|
|
|
|
|
|
|
|
|
|
final resultEither = await _authenticationRepo.insertPatientDeviceData(patientDeviceDataRequest: InsertPatientMobileDeviceInfo(deviceToken: _appState.deviceToken, deviceTypeId: _appState.getDeviceTypeID(), patientId: _appState.getAuthenticatedUser()!.patientId!, patientTypeId: _appState.getAuthenticatedUser()!.patientType, patientOutSa:_appState.getAuthenticatedUser()!.outSa!, loginType: loginType, languageId: _appState.getLanguageID(), latitude: _appState.userLat, longitude:_appState.userLong, voipToken: "", deviceType: _appState.deviceTypeID, patientMobileNumber:_appState.getAuthenticatedUser()!.mobileNumber, nationalId: _appState.getAuthenticatedUser()!.patientIdentificationNo, gender: _appState.getAuthenticatedUser()!.gender ).toJson());
|
|
|
|
|
resultEither.fold((failure) async => await _errorHandlerService.handleError(failure: failure), (apiResponse) async {
|
|
|
|
|
if (apiResponse.messageStatus == 1) {
|
|
|
|
|
log("Insert Device Data Success");
|
|
|
|
|
} else {
|
|
|
|
|
log("Insert IMEI Failed");
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@override
|
|
|
|
|
void dispose() {
|
|
|
|
|
nationalIdController.dispose();
|
|
|
|
|
|