@ -6,6 +6,10 @@ import 'package:hijri_gregorian_calendar/hijri_gregorian_calendar.dart';
import ' package:hmg_patient_app_new/core/app_state.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/cache_consts.dart ' ;
import ' package:hmg_patient_app_new/core/common_models/nationality_country_model.dart ' ;
import ' package:hmg_patient_app_new/core/common_models/nationality_country_model.dart ' ;
import ' package:hmg_patient_app_new/core/common_models/privilege/HMCProjectListModel.dart ' ;
import ' package:hmg_patient_app_new/core/common_models/privilege/PrivilegeModel.dart ' ;
import ' package:hmg_patient_app_new/core/common_models/privilege/ProjectDetailListModel.dart ' ;
import ' package:hmg_patient_app_new/core/common_models/privilege/VidaPlusProjectListModel.dart ' ;
import ' package:hmg_patient_app_new/core/enums.dart ' ;
import ' package:hmg_patient_app_new/core/enums.dart ' ;
import ' package:hmg_patient_app_new/core/utils/loading_utils.dart ' ;
import ' package:hmg_patient_app_new/core/utils/loading_utils.dart ' ;
import ' package:hmg_patient_app_new/core/utils/request_utils.dart ' ;
import ' package:hmg_patient_app_new/core/utils/request_utils.dart ' ;
@ -53,7 +57,11 @@ class AuthenticationViewModel extends ChangeNotifier {
_authenticationRepo = authenticationRepo ,
_authenticationRepo = authenticationRepo ,
_localAuthService = localAuthService ;
_localAuthService = localAuthService ;
final TextEditingController nationalIdController = TextEditingController ( ) , phoneNumberController = TextEditingController ( ) , dobController = TextEditingController ( ) , nameController = TextEditingController ( ) , emailController = TextEditingController ( ) ;
final TextEditingController nationalIdController = TextEditingController ( ) ,
phoneNumberController = TextEditingController ( ) ,
dobController = TextEditingController ( ) ,
nameController = TextEditingController ( ) ,
emailController = TextEditingController ( ) ;
CountryEnum selectedCountrySignup = CountryEnum . saudiArabia ;
CountryEnum selectedCountrySignup = CountryEnum . saudiArabia ;
MaritalStatusTypeEnum ? maritalStatus ;
MaritalStatusTypeEnum ? maritalStatus ;
GenderTypeEnum ? genderType ;
GenderTypeEnum ? genderType ;
@ -374,8 +382,8 @@ class AuthenticationViewModel extends ChangeNotifier {
registeredData: null ,
registeredData: null ,
nationIdText: nationalIdController . text ,
nationIdText: nationalIdController . text ,
countryCode: selectedCountrySignup . countryCode ,
countryCode: selectedCountrySignup . countryCode ,
loginType: loginTypeEnum . toInt
loginType: loginTypeEnum . toInt )
) . toJson ( ) ;
. toJson ( ) ;
bool isForRegister = ( _appState . getUserRegistrationPayload . healthId ! = null | | _appState . getUserRegistrationPayload . patientOutSa = = true ) ;
bool isForRegister = ( _appState . getUserRegistrationPayload . healthId ! = null | | _appState . getUserRegistrationPayload . patientOutSa = = true ) ;
if ( isForRegister ) {
if ( isForRegister ) {
@ -537,15 +545,14 @@ class AuthenticationViewModel extends ChangeNotifier {
Future . delayed ( Duration ( seconds: 1 ) , ( ) {
Future . delayed ( Duration ( seconds: 1 ) , ( ) {
if ( _appState . getSelectDeviceByImeiRespModelElement ! = null & &
if ( _appState . getSelectDeviceByImeiRespModelElement ! = null & &
( _appState . getSelectDeviceByImeiRespModelElement ! . logInType = = 1 | | _appState . getSelectDeviceByImeiRespModelElement ! . logInType = = 4 ) ) {
( _appState . getSelectDeviceByImeiRespModelElement ! . logInType = = 1 | | _appState . getSelectDeviceByImeiRespModelElement ! . logInType = = 4 ) ) {
phoneNumberController . text = ( _appState . getAuthenticatedUser ( ) ! . mobileNumber ! . startsWith ( " 0 " )
phoneNumberController . text =
? _appState . getAuthenticatedUser ( ) ! . mobileNumber ! . replaceFirst ( " 0 " , " " )
( _appState . getAuthenticatedUser ( ) ! . mobileNumber ! . startsWith ( " 0 " ) ? _appState . getAuthenticatedUser ( ) ! . mobileNumber ! . replaceFirst ( " 0 " , " " ) : _appState . getAuthenticatedUser ( ) ! . mobileNumber ) ! ;
: _appState . getAuthenticatedUser ( ) ! . mobileNumber ) ! ;
nationalIdController . text = _appState . getAuthenticatedUser ( ) ! . nationalityId ! ;
nationalIdController . text = _appState . getAuthenticatedUser ( ) ! . nationalityId ! ;
onSuccess ( ) ;
onSuccess ( ) ;
} else if ( ( loginTypeEnum = = LoginTypeEnum . sms | | loginTypeEnum = = LoginTypeEnum . whatsapp & & _appState . getSelectDeviceByImeiRespModelElement = = null ) & & _appState . getAuthenticatedUser ( ) ! = null ) {
} else if ( ( loginTypeEnum = = LoginTypeEnum . sms | | loginTypeEnum = = LoginTypeEnum . whatsapp & & _appState . getSelectDeviceByImeiRespModelElement = = null ) & &
phoneNumberController. text = ( _appState. getAuthenticatedUser ( ) ! . mobileNumber ! . startsWith ( " 0 " )
_appState. getAuthenticatedUser ( ) ! = null ) {
? _appState . getAuthenticatedUser ( ) ! . mobileNumber ! . replaceFirst ( " 0 " , " " )
phoneNumberController . text =
: _appState . getAuthenticatedUser ( ) ! . mobileNumber ) ! ;
( _appState . getAuthenticatedUser ( ) ! . mobileNumber ! . startsWith ( " 0 " ) ? _appState . getAuthenticatedUser ( ) ! . mobileNumber ! . replaceFirst ( " 0 " , " " ) : _appState . getAuthenticatedUser ( ) ! . mobileNumber ) ! ;
nationalIdController . text = _appState . getAuthenticatedUser ( ) ! . nationalityId ! ;
nationalIdController . text = _appState . getAuthenticatedUser ( ) ! . nationalityId ! ;
onSuccess ( ) ;
onSuccess ( ) ;
}
}
@ -583,9 +590,7 @@ class AuthenticationViewModel extends ChangeNotifier {
} ) ;
} ) ;
}
}
Future < void > onRegistrationComplete ( ) async {
Future < void > onRegistrationComplete ( ) async {
/ / if ( emailAddress . text . isEmpty ) {
/ / if ( emailAddress . text . isEmpty ) {
/ / Utils . showErrorToast ( TranslationBase . of ( context ) . enterEmailAddress ) ;
/ / Utils . showErrorToast ( TranslationBase . of ( context ) . enterEmailAddress ) ;
/ / return ;
/ / return ;
@ -596,7 +601,6 @@ class AuthenticationViewModel extends ChangeNotifier {
/ / authVM ! . clearDefaultInputValues ( ) ;
/ / authVM ! . clearDefaultInputValues ( ) ;
}
}
Future < void > checkUserStatusForRegistration ( { required dynamic response , required dynamic request } ) async {
Future < void > checkUserStatusForRegistration ( { required dynamic response , required dynamic request } ) async {
if ( response is Map ) {
if ( response is Map ) {
_appState . setAppAuthToken = response [ " LogInTokenID " ] ;
_appState . setAppAuthToken = response [ " LogInTokenID " ] ;
@ -704,8 +708,23 @@ class AuthenticationViewModel extends ChangeNotifier {
}
}
Future < void > insertPatientIMEIData ( int loginType ) async {
Future < void > insertPatientIMEIData ( int loginType ) async {
final resultEither = await _authenticationRepo . insertPatientIMEIData (
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 ( ) ) ;
patientIMEIDataRequest: PatientInsertDeviceImei (
imei: _appState . deviceToken ,
deviceTypeId: _appState . getDeviceTypeID ( ) ,
patientId: _appState . getAuthenticatedUser ( ) ! . patientId ! ,
patientIdentificationNo: _appState . getAuthenticatedUser ( ) ! . patientIdentificationNo ! ,
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 {
resultEither . fold ( ( failure ) async = > await _errorHandlerService . handleError ( failure: failure ) , ( apiResponse ) async {
if ( apiResponse . messageStatus = = 1 ) {
if ( apiResponse . messageStatus = = 1 ) {
log ( " Insert IMEI Success " ) ;
log ( " Insert IMEI Success " ) ;
@ -714,11 +733,26 @@ class AuthenticationViewModel extends ChangeNotifier {
log ( " Insert IMEI Failed " ) ;
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 ( ) ) ;
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 {
resultEither . fold ( ( failure ) async = > await _errorHandlerService . handleError ( failure: failure ) , ( apiResponse ) async {
if ( apiResponse . messageStatus = = 1 ) {
if ( apiResponse . messageStatus = = 1 ) {
log ( " Insert Device Data Success " ) ;
log ( " Insert Device Data Success " ) ;
@ -726,7 +760,6 @@ class AuthenticationViewModel extends ChangeNotifier {
log ( " Insert IMEI Failed " ) ;
log ( " Insert IMEI Failed " ) ;
}
}
} ) ;
} ) ;
}
}
@ override
@ override
@ -736,4 +769,41 @@ class AuthenticationViewModel extends ChangeNotifier {
myFocusNode . dispose ( ) ;
myFocusNode . dispose ( ) ;
super . dispose ( ) ;
super . dispose ( ) ;
}
}
Future < void > getServicePrivilege ( ) async {
final resultEither = await _authenticationRepo . getServicePrivilege ( ) ;
List < PrivilegeModel > privilegeModelList = [ ] ;
List < VidaPlusProjectListModel > vidaPlusProjectListModel = [ ] ;
List < HMCProjectListModel > hMCProjectListModel = [ ] ;
List < ProjectDetailListModel > projectDetailListModel = [ ] ;
resultEither . fold (
( failure ) async = > await _errorHandlerService . handleError ( failure: failure ) ,
( apiResponse ) async {
if ( apiResponse . messageStatus = = 2 ) {
await _dialogService . showErrorBottomSheet ( message: apiResponse . errorMessage ? ? " ErrorEmpty " ) ;
} else {
apiResponse . data [ " ServicePrivilegeList " ] . forEach ( ( v ) {
privilegeModelList . add ( PrivilegeModel . fromJson ( v ) ) ;
} ) ;
_appState . setPrivilegeModelList ( privilegeModelList ) ;
apiResponse . data [ " ProjectListVidaPlus " ] . forEach ( ( v ) {
vidaPlusProjectListModel . add ( VidaPlusProjectListModel . fromJson ( v ) ) ;
} ) ;
_appState . setVidaPlusProjectList ( vidaPlusProjectListModel ) ;
apiResponse . data [ " HMCProjectList " ] . forEach ( ( v ) {
hMCProjectListModel . add ( HMCProjectListModel . fromJson ( v ) ) ;
} ) ;
_appState . setHMCProjectList ( hMCProjectListModel ) ;
apiResponse . data [ " ProjectDetailList " ] . forEach ( ( v ) {
projectDetailListModel . add ( ProjectDetailListModel . fromJson ( v ) ) ;
} ) ;
_appState . setProjectsDetailList ( projectDetailListModel ) ;
}
} ,
) ;
}
}
}