@ -46,7 +46,9 @@ class BaseAppClient {
if ( body = = null | | body [ ' DoctorID ' ] = = null ) {
body ! [ ' DoctorID ' ] = doctorProfile . doctorID ;
}
if ( body [ ' DoctorID ' ] = = " " ) body [ ' DoctorID ' ] = doctorProfile . doctorID ; / / changed from null ; because create update episode not working
if ( body [ ' DoctorID ' ] = = " " )
body [ ' DoctorID ' ] = doctorProfile
. doctorID ; / / changed from null ; because create update episode not working
if ( body [ ' EditedBy ' ] = = null ) body [ ' EditedBy ' ] = doctorProfile . doctorID ;
if ( body [ ' ProjectID ' ] = = null ) {
body [ ' ProjectID ' ] = doctorProfile . projectID ;
@ -92,16 +94,21 @@ class BaseAppClient {
body [ ' IsLoginForDoctorApp ' ] = IS_LOGIN_FOR_DOCTOR_APP ;
body [ ' PatientOutSA ' ] = body [ ' PatientOutSA ' ] ? ? 0 ; / / PATIENT_OUT_SA ;
if ( body [ ' VidaAuthTokenID ' ] = = null ) {
body [ ' VidaAuthTokenID ' ] = await sharedPref . getString ( VIDA_AUTH_TOKEN_ID ) ;
body [ ' VidaAuthTokenID ' ] =
await sharedPref . getString ( VIDA_AUTH_TOKEN_ID ) ;
}
if ( body [ ' VidaRefreshTokenID ' ] = = null ) {
body [ ' VidaRefreshTokenID ' ] = await sharedPref . getString ( VIDA_REFRESH_TOKEN_ID ) ;
body [ ' VidaRefreshTokenID ' ] =
await sharedPref . getString ( VIDA_REFRESH_TOKEN_ID ) ;
}
int ? projectID = await sharedPref . getInt ( PROJECT_ID ) ;
if ( projectID = = 2 | | projectID = = 3 )
body [ ' PatientOutSA ' ] = true ;
else if ( ( body . containsKey ( ' facilityId ' ) & & body [ ' facilityId ' ] = = 2 | | body [ ' facilityId ' ] = = 3 ) | | body [ ' ProjectID ' ] = = 2 | | body [ ' ProjectID ' ] = = 3 )
else if ( ( body . containsKey ( ' facilityId ' ) & & body [ ' facilityId ' ] = = 2 | |
body [ ' facilityId ' ] = = 3 ) | |
body [ ' ProjectID ' ] = = 2 | |
body [ ' ProjectID ' ] = = 3 )
body [ ' PatientOutSA ' ] = true ;
else
body [ ' PatientOutSA ' ] = false ;
@ -128,16 +135,27 @@ class BaseAppClient {
var asd = json . encode ( body ) ;
var asd2 ;
if ( await Utils . checkConnection ( ) ) {
final response = await http . post ( Uri . parse ( url ) , body: json . encode ( body ) , headers: { ' Content-Type ' : ' application/json ' , ' Accept ' : ' application/json ' } ) ;
final response = await http . post ( Uri . parse ( url ) ,
body: json . encode ( body ) ,
headers: {
' Content-Type ' : ' application/json ' ,
' Accept ' : ' application/json '
} ) ;
final int statusCode = response . statusCode ;
if ( statusCode < 200 | | statusCode > = 400 ) {
onFailure ( Utils . generateContactAdminMsg ( ) , statusCode ) ;
if ( body [ ' DoctorID ' ] ! = null )
postFailureResponse ( doctorId: body [ ' DoctorID ' ] , url: url , request: json . encode ( body ) , response: response . body , exception: " $ statusCode " ) ;
postFailureResponse (
doctorId: body [ ' DoctorID ' ] ,
url: url ,
request: json . encode ( body ) ,
response: response . body ,
exception: " $ statusCode " ) ;
} else {
var parsed = json . decode ( response . body . toString ( ) ) ;
if ( parsed [ ' ErrorType ' ] = = 4 ) {
helpers . navigateToUpdatePage ( parsed [ ' ErrorEndUserMessage ' ] , parsed [ ' AndroidLink ' ] , parsed [ ' IOSLink ' ] ) ;
helpers . navigateToUpdatePage ( parsed [ ' ErrorEndUserMessage ' ] ,
parsed [ ' AndroidLink ' ] , parsed [ ' IOSLink ' ] ) ;
}
if ( parsed [ ' IsAuthenticated ' ] ! = null & & ! parsed [ ' IsAuthenticated ' ] ) {
@ -146,11 +164,18 @@ class BaseAppClient {
onSuccess ( parsed , statusCode ) ;
} else {
if ( body [ ' DoctorID ' ] ! = null )
postFailureResponse ( doctorId: body [ ' DoctorID ' ] , url: url , request: json . encode ( body ) , response: response . body , exception: getError ( parsed ) ) ;
postFailureResponse (
doctorId: body [ ' DoctorID ' ] ,
url: url ,
request: json . encode ( body ) ,
response: response . body ,
exception: getError ( parsed ) ) ;
onFailure ( getError ( parsed ) , statusCode ) ;
}
} else if ( ! isAllowAny ) {
await Provider . of < AuthenticationViewModel > ( AppGlobal . CONTEX , listen: false ) . logout ( ) ;
await Provider . of < AuthenticationViewModel > ( AppGlobal . CONTEX ,
listen: false )
. logout ( ) ;
/ / todo nofailure is placed here and but have to handle the response here as well
Utils . showErrorToast ( ' Your session expired Please login again ' ) ;
locator < NavigationService > ( ) . pushNamedAndRemoveUntil ( ROOT ) ;
@ -161,13 +186,26 @@ class BaseAppClient {
} else if ( parsed [ ' MessageStatus ' ] = = 1 ) {
if ( ! parsed [ ' IsAuthenticated ' ] ) {
if ( body [ ' DoctorID ' ] ! = null )
postFailureResponse ( doctorId: body [ ' DoctorID ' ] , url: url , request: json . encode ( body ) , response: response . body , exception: getError ( parsed ) ) ;
postFailureResponse (
doctorId: body [ ' DoctorID ' ] ,
url: url ,
request: json . encode ( body ) ,
response: response . body ,
exception: getError ( parsed ) ) ;
onFailure ( getError ( parsed ) , statusCode ) ;
} else
onSuccess ( parsed , statusCode ) ;
} else {
if ( body [ ' DoctorID ' ] ! = null ) {
final validations = parsed [ ' ValidationErrorsCSI ' ] ? [ ' errors ' ] ? [ ' Validations ' ] ;
if ( validations is List & & validations . isNotEmpty ) {
final error = validations . first [ ' Error ' ] ;
if ( error ! = null ) {
onFailure ( error , statusCode ) ;
return ;
}
}
if ( body [ ' DoctorID ' ] ! = null ) {
postFailureResponse (
doctorId: body [ ' DoctorID ' ] ,
url: url ,
@ -196,7 +234,10 @@ class BaseAppClient {
String url = BASE_URL + endPoint ;
try {
Map < String , String > headers = { ' Content-Type ' : ' application/json ' , ' Accept ' : ' application/json ' } ;
Map < String , String > headers = {
' Content-Type ' : ' application/json ' ,
' Accept ' : ' application/json '
} ;
String ? token = await sharedPref . getString ( TOKEN ) ;
Map < String , dynamic > ? profile = await sharedPref . getObj ( DOCTOR_PROFILE ) ;
@ -210,7 +251,8 @@ class BaseAppClient {
if ( body ! [ ' DoctorID ' ] = = 0 ) {
body [ ' DoctorID ' ] = null ;
}
var languageID = await sharedPref . getStringWithDefaultValue ( APP_Language , ' en ' ) ;
var languageID =
await sharedPref . getStringWithDefaultValue ( APP_Language , ' en ' ) ;
body [ ' SetupID ' ] = body ! . containsKey ( ' SetupID ' )
? body [ ' SetupID ' ] ! = null
? body [ ' SetupID ' ]
@ -230,7 +272,8 @@ class BaseAppClient {
: PATIENT_OUT_SA_PATIENT_REQ ;
if ( body . containsKey ( ' isDentalAllowedBackend ' ) ) {
body [ ' isDentalAllowedBackend ' ] = body . containsKey ( ' isDentalAllowedBackend ' )
body [ ' isDentalAllowedBackend ' ] =
body . containsKey ( ' isDentalAllowedBackend ' )
? body [ ' isDentalAllowedBackend ' ] ! = null
? body [ ' isDentalAllowedBackend ' ]
: IS_DENTAL_ALLOWED_BACKEND
@ -255,8 +298,11 @@ class BaseAppClient {
: PATIENT_TYPE_ID
: PATIENT_TYPE_ID ;
body [ ' TokenID ' ] = body . containsKey ( ' TokenID ' ) ? body [ ' TokenID ' ] ? ? token : token ;
body [ ' PatientID ' ] = body [ ' PatientID ' ] ! = null ? body [ ' PatientID ' ] : patient ! . patientId ? ? patient . patientMRN ;
body [ ' TokenID ' ] =
body . containsKey ( ' TokenID ' ) ? body [ ' TokenID ' ] ? ? token : token ;
body [ ' PatientID ' ] = body [ ' PatientID ' ] ! = null
? body [ ' PatientID ' ]
: patient ! . patientId ? ? patient . patientMRN ;
body [ ' PatientOutSA ' ] = 0 ; / / user [ ' OutSA ' ] ; / / TODO change it
body [ ' SessionID ' ] = SESSION_ID ; / / getSe
@ -283,7 +329,8 @@ class BaseAppClient {
var asd = json . encode ( body ) ;
var asd2 ;
if ( await Utils . checkConnection ( ) ) {
final response = await http . post ( Uri . parse ( url . trim ( ) ) , body: json . encode ( body ) , headers: headers ) ;
final response = await http . post ( Uri . parse ( url . trim ( ) ) ,
body: json . encode ( body ) , headers: headers ) ;
final int statusCode = response . statusCode ;
print ( " statusCode : $ statusCode " ) ;
if ( statusCode < 200 | | statusCode > = 400 | | json = = null ) {
@ -295,7 +342,8 @@ class BaseAppClient {
onSuccess ( parsed , statusCode ) ;
} else {
if ( parsed [ ' ErrorType ' ] = = 4 ) {
helpers . navigateToUpdatePage ( parsed [ ' ErrorEndUserMessage ' ] , parsed [ ' AndroidLink ' ] , parsed [ ' IOSLink ' ] ) ;
helpers . navigateToUpdatePage ( parsed [ ' ErrorEndUserMessage ' ] ,
parsed [ ' AndroidLink ' ] , parsed [ ' IOSLink ' ] ) ;
}
if ( parsed [ ' IsAuthenticated ' ] = = null ) {
if ( parsed [ ' isSMSSent ' ] = = true ) {
@ -309,31 +357,62 @@ class BaseAppClient {
onSuccess ( parsed , statusCode ) ;
} else {
if ( body [ ' DoctorID ' ] ! = null )
postFailureResponse ( doctorId: body [ ' DoctorID ' ] , url: url , request: json . encode ( body ) , response: response . body , exception: getError ( parsed ) ) ;
postFailureResponse (
doctorId: body [ ' DoctorID ' ] ,
url: url ,
request: json . encode ( body ) ,
response: response . body ,
exception: getError ( parsed ) ) ;
onFailure ( getError ( parsed ) , statusCode ) ;
}
}
} else if ( parsed [ ' MessageStatus ' ] = = 1 | | parsed [ ' SMSLoginRequired ' ] = = true ) {
} else if ( parsed [ ' MessageStatus ' ] = = 1 | |
parsed [ ' SMSLoginRequired ' ] = = true ) {
onSuccess ( parsed , statusCode ) ;
} else if ( parsed [ ' MessageStatus ' ] = = 2 & & parsed [ ' IsAuthenticated ' ] ) {
} else if ( parsed [ ' MessageStatus ' ] = = 2 & &
parsed [ ' IsAuthenticated ' ] ) {
if ( parsed [ ' SameClinicApptList ' ] ! = null ) {
onSuccess ( parsed , statusCode ) ;
} else {
if ( parsed [ ' message ' ] = = null & & parsed [ ' ErrorEndUserMessage ' ] = = null ) {
if ( parsed [ ' message ' ] = = null & &
parsed [ ' ErrorEndUserMessage ' ] = = null ) {
if ( parsed [ ' ErrorSearchMsg ' ] = = null ) {
if ( body [ ' DoctorID ' ] ! = null )
postFailureResponse ( doctorId: body [ ' DoctorID ' ] , url: url , request: json . encode ( body ) , response: response . body , exception: " Server Error found with no available message " ) ;
postFailureResponse (
doctorId: body [ ' DoctorID ' ] ,
url: url ,
request: json . encode ( body ) ,
response: response . body ,
exception:
" Server Error found with no available message " ) ;
onFailure ( " Server Error found with no available message " , statusCode ) ;
onFailure ( " Server Error found with no available message " ,
statusCode ) ;
} else {
if ( body [ ' DoctorID ' ] ! = null )
postFailureResponse ( doctorId: body [ ' DoctorID ' ] , url: url , request: json . encode ( body ) , response: response . body , exception: parsed [ ' ErrorSearchMsg ' ] ) ;
postFailureResponse (
doctorId: body [ ' DoctorID ' ] ,
url: url ,
request: json . encode ( body ) ,
response: response . body ,
exception: parsed [ ' ErrorSearchMsg ' ] ) ;
onFailure ( parsed [ ' ErrorSearchMsg ' ] , statusCode ) ;
}
} else {
if ( body [ ' DoctorID ' ] ! = null )
postFailureResponse ( doctorId: body [ ' DoctorID ' ] , url: url , request: json . encode ( body ) , response: response . body , exception: parsed [ ' message ' ] ? ? parsed [ ' ErrorEndUserMessage ' ] ? ? parsed [ ' ErrorMessage ' ] ) ;
onFailure ( parsed [ ' message ' ] ? ? parsed [ ' ErrorEndUserMessage ' ] ? ? parsed [ ' ErrorMessage ' ] , statusCode ) ;
postFailureResponse (
doctorId: body [ ' DoctorID ' ] ,
url: url ,
request: json . encode ( body ) ,
response: response . body ,
exception: parsed [ ' message ' ] ? ?
parsed [ ' ErrorEndUserMessage ' ] ? ?
parsed [ ' ErrorMessage ' ] ) ;
onFailure (
parsed [ ' message ' ] ? ?
parsed [ ' ErrorEndUserMessage ' ] ? ?
parsed [ ' ErrorMessage ' ] ,
statusCode ) ;
}
}
} else {
@ -342,14 +421,27 @@ class BaseAppClient {
} else {
if ( parsed [ ' message ' ] ! = null ) {
if ( body [ ' DoctorID ' ] ! = null )
postFailureResponse ( doctorId: body [ ' DoctorID ' ] , url: url , request: json . encode ( body ) , response: response . body , exception: parsed [ ' message ' ] ) ;
postFailureResponse (
doctorId: body [ ' DoctorID ' ] ,
url: url ,
request: json . encode ( body ) ,
response: response . body ,
exception: parsed [ ' message ' ] ) ;
onFailure ( parsed [ ' message ' ] ? ? parsed [ ' message ' ] , statusCode ) ;
} else {
if ( body [ ' DoctorID ' ] ! = null )
postFailureResponse ( doctorId: body [ ' DoctorID ' ] , url: url , request: json . encode ( body ) , response: response . body , exception: parsed [ ' ErrorEndUserMessage ' ] ? ? parsed [ ' ErrorMessage ' ] ) ;
postFailureResponse (
doctorId: body [ ' DoctorID ' ] ,
url: url ,
request: json . encode ( body ) ,
response: response . body ,
exception: parsed [ ' ErrorEndUserMessage ' ] ? ?
parsed [ ' ErrorMessage ' ] ) ;
onFailure ( parsed [ ' ErrorEndUserMessage ' ] ? ? parsed [ ' ErrorMessage ' ] , statusCode ) ;
onFailure (
parsed [ ' ErrorEndUserMessage ' ] ? ? parsed [ ' ErrorMessage ' ] ,
statusCode ) ;
}
}
}
@ -370,9 +462,14 @@ class BaseAppClient {
if ( parsed [ " ValidationErrors " ] ! = null ) {
error = parsed [ " ValidationErrors " ] [ " StatusMessage " ] . toString ( ) + " \n " ;
if ( parsed [ " ValidationErrors " ] [ " ValidationErrors " ] ! = null & & parsed [ " ValidationErrors " ] [ " ValidationErrors " ] . length ! = 0 ) {
for ( var i = 0 ; i < parsed [ " ValidationErrors " ] [ " ValidationErrors " ] . length ; i + + ) {
error = error ! + parsed [ " ValidationErrors " ] [ " ValidationErrors " ] [ i ] [ " Messages " ] [ 0 ] + " \n " ;
if ( parsed [ " ValidationErrors " ] [ " ValidationErrors " ] ! = null & &
parsed [ " ValidationErrors " ] [ " ValidationErrors " ] . length ! = 0 ) {
for ( var i = 0 ;
i < parsed [ " ValidationErrors " ] [ " ValidationErrors " ] . length ;
i + + ) {
error = error ! +
parsed [ " ValidationErrors " ] [ " ValidationErrors " ] [ i ] [ " Messages " ] [ 0 ] +
" \n " ;
}
}
}
@ -382,7 +479,10 @@ class BaseAppClient {
return error ;
}
get ( { required String endPoint , required Function ( dynamic response , int statusCode ) onSuccess , required Function ( String error , int statusCode ) onFailure } ) async {
get (
{ required String endPoint ,
required Function ( dynamic response , int statusCode ) onSuccess ,
required Function ( String error , int statusCode ) onFailure } ) async {
String token = await sharedPref . getString ( TOKEN ) ;
String url = DOCTOR_ROTATION + endPoint + ' &token= ' + token ;
print ( url ) ;