@ -4,21 +4,32 @@ import 'package:flutter_svg/flutter_svg.dart';
import ' package:hmg_patient_app/config/config.dart ' ;
import ' package:hmg_patient_app/config/shared_pref_kay.dart ' ;
import ' package:hmg_patient_app/core/service/client/base_app_client.dart ' ;
import ' package:hmg_patient_app/core/viewModels/appointment_rate_view_model.dart ' ;
import ' package:hmg_patient_app/core/viewModels/project_view_model.dart ' ;
import ' package:hmg_patient_app/extensions/string_extensions.dart ' ;
import ' package:hmg_patient_app/locator.dart ' ;
import ' package:hmg_patient_app/models/Appointments/toDoCountProviderModel.dart ' ;
import ' package:hmg_patient_app/models/Authentication/authenticated_user.dart ' ;
import ' package:hmg_patient_app/models/Authentication/check_activation_code_response.dart ' ;
import ' package:hmg_patient_app/models/Authentication/check_paitent_authentication_req.dart ' ;
import ' package:hmg_patient_app/models/Authentication/select_device_imei_res.dart ' ;
import ' package:hmg_patient_app/models/InPatientServices/get_admission_info_response_model.dart ' ;
import ' package:hmg_patient_app/models/InPatientServices/get_admission_request_info_response_model.dart ' ;
import ' package:hmg_patient_app/new_ui/otp/otp_validation_bootmsheet_widget.dart ' ;
import ' package:hmg_patient_app/pages/landing/landing_page.dart ' ;
import ' package:hmg_patient_app/pages/login/user-login-agreement-page.dart ' ;
import ' package:hmg_patient_app/pages/login/welcome.dart ' ;
import ' package:hmg_patient_app/pages/rateAppointment/rate_appointment_doctor.dart ' ;
import ' package:hmg_patient_app/services/authentication/auth_provider.dart ' hide sharedPref ;
import ' package:hmg_patient_app/services/clinic_services/get_clinic_service.dart ' ;
import ' package:hmg_patient_app/uitl/app_toast.dart ' ;
import ' package:hmg_patient_app/uitl/date_uitl.dart ' ;
import ' package:hmg_patient_app/uitl/gif_loader_dialog_utils.dart ' ;
import ' package:hmg_patient_app/uitl/translations_delegate_base.dart ' ;
import ' package:hmg_patient_app/uitl/utils.dart ' hide sharedPref ;
import ' package:hmg_patient_app/widgets/otp/sms-popup.dart ' ;
import ' package:hmg_patient_app/widgets/text/app_texts_widget.dart ' ;
import ' package:hmg_patient_app/widgets/transitions/fade_page.dart ' ;
import ' package:local_auth/local_auth.dart ' ;
import ' package:provider/provider.dart ' ;
@ -42,12 +53,14 @@ class _SavedLogin extends State<SavedLogin> {
final authService = new AuthProvider ( ) ;
late ProjectViewModel projectViewModel ;
late ToDoCountProviderModel toDoProvider ;
AppointmentRateViewModel appointmentRateViewModel = locator < AppointmentRateViewModel > ( ) ;
@ override
Widget build ( BuildContext context ) {
projectViewModel = Provider . of ( context ) ;
toDoProvider = Provider . of ( context ) ;
return Scaffold (
backgroundColor: const Color ( 0xFFF8F8FA ) ,
body: SafeArea (
@ -168,7 +181,7 @@ class _SavedLogin extends State<SavedLogin> {
onPressed: ( ) {
int ? val = Utils . onOtpBtnPressed ( OTPType . sms , phoneController ) ;
if ( val ! = null ) {
/ / checkUserAuthentication ( val ) ;
checkUserAuthentication ( val ) ;
}
} ,
backgroundColor: Colors . red ,
@ -234,8 +247,8 @@ class _SavedLogin extends State<SavedLogin> {
) ,
) ; } ,
child: const Text (
' Guest ' ,
child: Text (
TranslationBase . of ( context ) . guest ,
style: TextStyle (
color: Color ( 0xFFED1C2B ) ,
fontSize: 16 ,
@ -254,8 +267,8 @@ class _SavedLogin extends State<SavedLogin> {
) ;
} ,
child: const Text (
' Switch account ' ,
child: Text (
TranslationBase . of ( context ) . switchAccount ,
style: TextStyle (
color: Color ( 0xFFED1C2B ) ,
fontSize: 16 ,
@ -350,7 +363,7 @@ class _SavedLogin extends State<SavedLogin> {
/ / this . loginTokenID = result [ ' LogInTokenID ' ] ;
/ / this . patientOutSA = result [ ' PatientOutSA ' ] ;
/ / setDefault ( ) ;
checkActivationCode ( lastLogin , result [ ' LogInTokenID ' ] ) ;
checkActivationCode ( null , lastLogin , result [ ' LogInTokenID ' ] ) ;
}
} ) . catchError ( ( err ) {
GifLoaderDialogUtils . hideDialog ( context ) ;
@ -359,8 +372,7 @@ class _SavedLogin extends State<SavedLogin> {
}
checkActivationCode ( int loginType , String loginToken ) async {
checkActivationCode ( String ? value , int loginType , String loginToken ) async {
AppGlobal . context = context ;
GifLoaderDialogUtils . showMyDialog ( context ) ;
var request = authService . getCommonRequest (
@ -370,7 +382,7 @@ class _SavedLogin extends State<SavedLogin> {
mobileNumber: int . parse ( widget . savedLoginData . mobile ! ) ,
zipCode: widget . savedLoginData . outSA = = 1 ? ' 971 ' : ' 966 ' ,
patientOutSA: widget . savedLoginData . outSA ,
loginTokenID: loginToken ,
loginTokenID: " " ,
selectedOption: loginType ,
user: widget . savedLoginData ,
) . toJson ( ) ;
@ -401,7 +413,7 @@ class _SavedLogin extends State<SavedLogin> {
{
sharedPref . remove ( FAMILY_FILE ) ,
result . list . isFamily = false ,
/ / userData = result . list ,
/ / userData = result . list ,
sharedPref . setString ( BLOOD_TYPE , result . patientBloodType ? ? " " ) ,
/ / Remove o + from here Added by Aamir
authenticatedUserObject . user = result . list ,
@ -411,7 +423,7 @@ class _SavedLogin extends State<SavedLogin> {
/ / loginTokenID = result . logInTokenID ,
await sharedPref . setObject ( LOGIN_TOKEN_ID , result . logInTokenID ) ,
await sharedPref . setString ( TOKEN , result . authenticationTokenID ) ,
/ / checkIfUserAgreedBefore ( result ) ,
checkIfUserAgreedBefore ( result , loginType ) ,
projectViewModel . analytics . loginRegistration . login_successful ( ) ,
}
}
@ -431,6 +443,130 @@ class _SavedLogin extends State<SavedLogin> {
} ) ;
}
checkIfUserAgreedBefore ( CheckActivationCode result , int type ) {
if ( projectViewModel . havePrivilege ( 109 ) ) {
this . authService . checkIfUserAgreed ( ) . then ( ( result ) {
if ( result [ ' IsPatientAlreadyAgreed ' ] ) {
goToHome ( type ) ;
} else {
this . authService . getUserAgreementContent ( ) . then ( ( result ) {
GifLoaderDialogUtils . hideDialog ( AppGlobal . context ) ;
Navigator . pushAndRemoveUntil (
context ,
FadePage (
page: UserLoginAgreementPage (
userAgreementText: result [ ' UserAgreementContent ' ] ,
authenticatedUserObject: authenticatedUserObject ,
appointmentRateViewModel: appointmentRateViewModel ,
selectedOption: type ,
isArabic: projectViewModel . isArabic ,
) ,
) ,
( r ) = > false ) ;
} ) . catchError ( ( err ) {
GifLoaderDialogUtils . hideDialog ( context ) ;
print ( err ) ;
} ) ;
}
} ) . catchError ( ( err ) {
GifLoaderDialogUtils . hideDialog ( context ) ;
print ( err ) ;
} ) ;
} else {
goToHome ( type ) ;
}
/ / if ( result . isNeedUserAgreement = = true ) {
/ / / / move to agreement page .
/ / } else {
/ / goToHome ( ) ;
/ / }
}
goToHome ( int type ) async {
authenticatedUserObject . isLogin = true ;
appointmentRateViewModel . isLogin = true ;
projectViewModel . isLogin = true ;
projectViewModel . user = authenticatedUserObject . user ;
await authenticatedUserObject . getUser ( getUser: true ) ;
/ / GifLoaderDialogUtils . hideDialog ( context ) ;
getToDoCount ( ) ;
checkIfIsInPatient ( ) {
bool isAdmitted = false ;
bool hasAdmissionRequest = false ;
GetAdmissionInfoResponseModel getAdmissionInfoResponseModel ;
GetAdmissionRequestInfoResponseModel getAdmissionRequestInfoResponseModel ;
ClinicListService service = new ClinicListService ( ) ;
service . checkIfInPatientAPI ( context ) . then ( ( res ) {
if ( res [ ' MessageStatus ' ] = = 1 ) {
isAdmitted = res [ ' isAdmitted ' ] ;
hasAdmissionRequest = res [ ' hasAdmissionRequests ' ] ;
print ( " IS ADMITTED: $ isAdmitted " ) ;
print ( " Has Admission Request: $ hasAdmissionRequest " ) ;
if ( isAdmitted ) {
if ( res [ ' PatientAdmittedInformation ' ] . length ! = 0 ) {
getAdmissionInfoResponseModel = GetAdmissionInfoResponseModel . fromJson ( res [ ' PatientAdmittedInformation ' ] [ 0 ] ) ;
projectViewModel . setInPatientProjectID ( res [ ' PatientAdmittedInformation ' ] [ 0 ] [ ' ProjectID ' ] ) ;
projectViewModel . setInPatientAdmissionInfo ( getAdmissionInfoResponseModel ) ;
projectViewModel . setIsPatientAdmitted ( true ) ;
}
}
if ( hasAdmissionRequest ) {
if ( res [ ' MedicalInstruction ' ] . length ! = 0 ) {
getAdmissionRequestInfoResponseModel = GetAdmissionRequestInfoResponseModel . fromJson ( res [ ' MedicalInstruction ' ] [ 0 ] ) ;
/ / projectViewModel . setInPatientProjectID ( res [ ' MedicalInstruction ' ] [ 0 ] [ ' ProjectID ' ] ) ;
projectViewModel . setInPatientProjectID ( res [ ' MedicalInstruction ' ] [ 0 ] [ ' projectId ' ] ) ;
projectViewModel . setInPatientAdmissionRequest ( getAdmissionRequestInfoResponseModel ) ;
projectViewModel . setPatientHasAdmissionRequest ( true ) ;
}
}
} else { }
} ) ;
} ( ) ;
appointmentRateViewModel
. getIsLastAppointmentRatedList ( projectViewModel . isArabic ? 1 : 2 )
. then ( ( value ) = > {
GifLoaderDialogUtils . hideDialog ( AppGlobal . context ) ,
if ( appointmentRateViewModel . isHaveAppointmentNotRate )
{
Navigator . pushAndRemoveUntil (
context ,
FadePage (
page: RateAppointmentDoctor ( ) ,
) ,
( r ) = > false )
}
else
{
Navigator . pushAndRemoveUntil (
context ,
FadePage (
page: LandingPage ( ) ,
) ,
( r ) = > false )
} ,
insertIMEI ( type )
} )
. catchError ( ( err ) {
print ( err ) ;
} ) ;
}
getToDoCount ( ) {
toDoProvider . setState ( 0 , 0 , true , " 0 " ) ;
ClinicListService service = new ClinicListService ( ) ;
service . getActiveAppointmentNo ( context ) . then ( ( res ) {
if ( res [ ' MessageStatus ' ] = = 1 ) {
toDoProvider . setState ( res [ ' AppointmentActiveNumber ' ] , res [ ' AncillaryOrderListCount ' ] , true , " 0 " ) ;
/ / toDoProvider . setState ( res [ ' AppointmentActiveNumber ' ] , true , " 0 " ) ;
} else { }
} ) . catchError ( ( err ) {
print ( err ) ;
} ) ;
}
insertIMEI ( lastLogin ) {
@ -438,4 +574,95 @@ class _SavedLogin extends State<SavedLogin> {
print ( err ) ;
} ) ;
}
checkUserAuthentication ( type ) {
/ / showLoader ( true ) ;
GifLoaderDialogUtils . showMyDialog ( context ) ;
var req = this . authService . getCommonRequest ( type: type ,
registerd_data: null ,
deviceToken: widget . savedLoginData . iMEI ,
mobileNumber: int . parse ( widget . savedLoginData . mobile ! ) ,
zipCode: widget . savedLoginData . outSA = = 1 ? ' 971 ' : ' 966 ' ,
patientOutSA: widget . savedLoginData . outSA ,
loginTokenID: " " ,
selectedOption: type ,
user: widget . savedLoginData , ) ;
var request = CheckPatientAuthenticationReq . fromJson ( req . toJson ( ) ) ;
sharedPref . setObject ( REGISTER_DATA_FOR_REGISTER , request ) ;
authService
. checkPatientAuthentication ( request )
. then ( ( value ) = > {
GifLoaderDialogUtils . hideDialog ( context ) ,
if ( value [ ' isSMSSent ' ] )
{
sharedPref . setString ( LOGIN_TOKEN_ID , value [ ' LogInTokenID ' ] ) ,
/ / this . loginTokenID = value [ ' LogInTokenID ' ] ,
sharedPref . setObject ( REGISTER_DATA_FOR_LOGIIN , request ) ,
/ / Future . delayed ( Duration ( seconds: 1 ) , ( ) {
this . sendActivationCode ( type , value [ ' LogInTokenID ' ] )
/ / } )
}
else
{
if ( value [ ' IsAuthenticated ' ] ) { this . checkActivationCode ( null , type , value [ ' LogInTokenID ' ] ) }
else {
AppToast . showErrorToast ( message: value [ ' errorMessage ' ] ) ,
Navigator . pushAndRemoveUntil (
context ,
FadePage (
page: WelcomeLogin ( ) ,
) ,
( r ) = > false )
}
}
} )
. catchError ( ( err ) {
print ( err ) ;
GifLoaderDialogUtils . hideDialog ( context ) ;
} ) ;
}
sendActivationCode ( type , String loginToken ) async {
var request = this . authService . getCommonRequest ( type: type ,
registerd_data: null ,
deviceToken: widget . savedLoginData . iMEI ,
mobileNumber: int . parse ( widget . savedLoginData . mobile ! ) ,
zipCode: widget . savedLoginData . outSA = = 1 ? ' 971 ' : ' 966 ' ,
patientOutSA: widget . savedLoginData . outSA ,
loginTokenID: loginToken ,
selectedOption: type ,
user: widget . savedLoginData , ) ;
request . sMSSignature = await SMSOTP . getSignature ( ) ;
GifLoaderDialogUtils . showMyDialog ( context ) ;
request . dob = " " ;
request . healthId = " " ;
request . isHijri = 0 ;
await this . authService . sendActivationCode ( request ) . then ( ( result ) {
GifLoaderDialogUtils . hideDialog ( context ) ;
if ( result ! = null & & result [ ' isSMSSent ' ] = = true ) {
this . startSMSService ( type , loginToken ) ;
}
} ) . catchError ( ( r ) {
GifLoaderDialogUtils . hideDialog ( context ) ;
AppToast . showErrorToast ( message: r . toString ( ) ) ;
} ) ;
}
var tempType ;
startSMSService ( type , String loginToken ) {
tempType = type ;
SMSOTP (
context ,
type ,
phoneController . text ,
( value ) {
this . checkActivationCode ( value , type , loginToken ) ;
} ,
( ) = > {
Navigator . pop ( context ) ,
} ,
) . displayDialog ( context ) ;
}
}