From f36518188882e660bdee687347cef4e93429994f Mon Sep 17 00:00:00 2001 From: haroon amjad Date: Mon, 12 May 2025 16:38:43 +0300 Subject: [PATCH] Pharmacy intervention null error fix, Update to stores VersionID 9.7 --- lib/client/base_app_client.dart | 516 +++++++++++++------------------- lib/config/config.dart | 2 +- pubspec.yaml | 2 +- 3 files changed, 211 insertions(+), 309 deletions(-) diff --git a/lib/client/base_app_client.dart b/lib/client/base_app_client.dart index 4147cfed..9289173c 100644 --- a/lib/client/base_app_client.dart +++ b/lib/client/base_app_client.dart @@ -25,11 +25,11 @@ class BaseAppClient { //TODO change the post fun to nun static when you change all service post(String endPoint, {Map? body, - required Function(dynamic response, int statusCode) onSuccess, - required Function(String error, int statusCode) onFailure, - bool isAllowAny = false, - bool isLiveCare = false, - bool isFallLanguage = false}) async { + required Function(dynamic response, int statusCode) onSuccess, + required Function(String error, int statusCode) onFailure, + bool isAllowAny = false, + bool isLiveCare = false, + bool isFallLanguage = false}) async { String url; if (isLiveCare) url = BASE_URL_LIVE_CARE + endPoint; @@ -46,9 +46,7 @@ class BaseAppClient { if (body == null || body['DoctorID'] == null) { body!['DoctorID'] = doctorProfile.doctorID.toString(); } - 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.toString(); if (body['ProjectID'] == null) { body['ProjectID'] = doctorProfile.projectID.toString(); @@ -64,8 +62,8 @@ class BaseAppClient { body['SetupID'] = body.containsKey('SetupID') ? body['SetupID'] != null - ? body['SetupID'] - : await sharedPref.getString(DOCTOR_SETUP_ID) + ? body['SetupID'] + : await sharedPref.getString(DOCTOR_SETUP_ID) : await sharedPref.getString(DOCTOR_SETUP_ID); if (body['EditedBy'] == '') { @@ -94,21 +92,16 @@ class BaseAppClient { body['IsLoginForDoctorApp'] = IS_LOGIN_FOR_DOCTOR_APP.toString(); 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'; @@ -135,27 +128,15 @@ 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"); + if (body['DoctorID'] != null) 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']) { @@ -163,19 +144,11 @@ class BaseAppClient { if (parsed['ErrorCode'] == '699') { onSuccess(parsed, statusCode); } else { - if (body['DoctorID'] != null) - postFailureResponse( - doctorId: body['DoctorID'], - url: url, - request: json.encode(body), - response: response.body, - exception: getError(parsed)); + if (body['DoctorID'] != null) 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(AppGlobal.CONTEX, - listen: false) - .logout(); + await Provider.of(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().pushNamedAndRemoveUntil(ROOT); @@ -185,13 +158,7 @@ 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)); + if (body['DoctorID'] != null) postFailureResponse(doctorId: body['DoctorID'], url: url, request: json.encode(body), response: response.body, exception: getError(parsed)); onFailure(getError(parsed), statusCode); } else onSuccess(parsed, statusCode); @@ -205,18 +172,13 @@ class BaseAppClient { return; } } - if (body['DoctorID'] != null) { - postFailureResponse( - doctorId: body['DoctorID'], - url: url, - request: json.encode(body), - response: response.body, - exception: getError(parsed)); - } - onFailure(getError(parsed), statusCode); + if (body['DoctorID'] != null) { + postFailureResponse(doctorId: body['DoctorID'], url: url, request: json.encode(body), response: response.body, exception: getError(parsed)); } + onFailure(getError(parsed), statusCode); } - } else { + } + } else { onFailure('Please Check The Internet Connection', -1); } } catch (e) { @@ -225,264 +187,204 @@ class BaseAppClient { } } - postPatient(String endPoint, - {Map? body, - required Function(dynamic response, int statusCode) onSuccess, - required Function(String error, int statusCode) onFailure, - PatiantInformtion? patient, - bool isExternal = false}) async { + postPatient(String endPoint, + {Map? body, + required Function(dynamic response, int statusCode) onSuccess, + required Function(String error, int statusCode) onFailure, + PatiantInformtion? patient, + bool isExternal = false}) async { String url = BASE_URL + endPoint; try { - Map headers = { - 'Content-Type': 'application/json', - 'Accept': 'application/json' - }; - - String? token = await sharedPref.getString(TOKEN); - Map? profile = await sharedPref.getObj(DOCTOR_PROFILE); - - if (profile != null) { - DoctorProfileModel doctorProfile = DoctorProfileModel.fromJson(profile); - if (body!['DoctorID'] == null) { - body['DoctorID'] = doctorProfile.doctorID; - } - } - if (body!['DoctorID'] == 0) { - body['DoctorID'] = null; - } - var languageID = - await sharedPref.getStringWithDefaultValue(APP_Language, 'en'); - body['SetupID'] = body!.containsKey('SetupID') - ? body['SetupID'] != null - ? body['SetupID'] - : await sharedPref.getString(DOCTOR_SETUP_ID) - : await sharedPref.getString(DOCTOR_SETUP_ID); - - body['VersionID'] = VERSION_ID; - body['Channel'] = CHANNEL; - body['LanguageID'] = languageID == 'ar' ? 1 : 2; - - body['IPAdress'] = "10.20.10.20"; - body['generalid'] = GENERAL_ID; - body['PatientOutSA'] = body.containsKey('PatientOutSA') - ? body['PatientOutSA'] != null - ? body['PatientOutSA'] - : PATIENT_OUT_SA_PATIENT_REQ - : PATIENT_OUT_SA_PATIENT_REQ; - - if (body.containsKey('isDentalAllowedBackend')) { - body['isDentalAllowedBackend'] = - body.containsKey('isDentalAllowedBackend') - ? body['isDentalAllowedBackend'] != null - ? body['isDentalAllowedBackend'] - : IS_DENTAL_ALLOWED_BACKEND - : IS_DENTAL_ALLOWED_BACKEND; - } + Map headers = {'Content-Type': 'application/json', 'Accept': 'application/json'}; - body['DeviceTypeID'] = Platform.isAndroid ? 1 : 2; - - body['PatientType'] = body.containsKey('PatientType') - ? body['PatientType'] != null - ? body['PatientType'] - : patient!.patientType != null - ? patient.patientType - : PATIENT_TYPE - : PATIENT_TYPE; - - body['PatientTypeID'] = body.containsKey('PatientTypeID') - ? body['PatientTypeID'] != null - ? body['PatientTypeID'] - : patient!.patientType != null - ? patient.patientType - : 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['PatientOutSA'] = 0; //user['OutSA']; //TODO change it - body['SessionID'] = SESSION_ID; //getSe - - int? projectID = await sharedPref.getInt(PROJECT_ID); - if (projectID == 2 || projectID == 3) - body['PatientOutSA'] = true; - else - body['PatientOutSA'] = false; - - // if(!body.containsKey('ProjectID')) { - // if (projectID != null) { - // body['ProjectID'] = 313; - // } else { - // body['ProjectID'] = 0; - // } - // } - - // body['DoctorID'] = 24; //3844083 - // body['TokenID'] = "@dm!n"; - - print("URL : $url"); - print("Body : ${json.encode(body)}"); - 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 int statusCode = response.statusCode; - print("statusCode :$statusCode"); - if (statusCode < 200 || statusCode >= 400 || json == null) { - onFailure('Error While Fetching data', statusCode); - } else { - // var parsed = json.decode(response.body.toString()); - var parsed = json.decode(utf8.decode(response.bodyBytes)); - if (parsed['Response_Message'] != null) { - onSuccess(parsed, statusCode); - } else { - if (parsed['ErrorType'] == 4) { - helpers.navigateToUpdatePage(parsed['ErrorEndUserMessage'], - parsed['AndroidLink'], parsed['IOSLink']); - } - if (parsed['IsAuthenticated'] == null) { - if (parsed['isSMSSent'] == true) { - onSuccess(parsed, statusCode); - } else if (parsed['MessageStatus'] == 1) { - onSuccess(parsed, statusCode); - } else if (parsed['Result'] == 'OK') { - onSuccess(parsed, statusCode); - } else { - if (parsed != null) { - onSuccess(parsed, statusCode); - } else { - if (body['DoctorID'] != null) - 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) { - onSuccess(parsed, statusCode); - } else if (parsed['MessageStatus'] == 2 && - parsed['IsAuthenticated']) { - if (parsed['SameClinicApptList'] != null) { - onSuccess(parsed, statusCode); - } else { - 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"); - - 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']); - 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); - } - } - } else { - if (parsed['SameClinicApptList'] != null) { - onSuccess(parsed, statusCode); - } 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']); - - 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']); - - onFailure( - parsed['ErrorEndUserMessage'] ?? parsed['ErrorMessage'], - statusCode); - } - } - } - } - } - } else { - onFailure('Please Check The Internet Connection', -1); - } + String? token = await sharedPref.getString(TOKEN); + Map? profile = await sharedPref.getObj(DOCTOR_PROFILE); + + if (profile != null) { + DoctorProfileModel doctorProfile = DoctorProfileModel.fromJson(profile); + if (body!['DoctorID'] == null) { + body['DoctorID'] = doctorProfile.doctorID; + } + } + if (body!['DoctorID'] == 0) { + body['DoctorID'] = null; + } + var languageID = await sharedPref.getStringWithDefaultValue(APP_Language, 'en'); + body['SetupID'] = body!.containsKey('SetupID') + ? body['SetupID'] != null + ? body['SetupID'] + : await sharedPref.getString(DOCTOR_SETUP_ID) + : await sharedPref.getString(DOCTOR_SETUP_ID); + + body['VersionID'] = VERSION_ID; + body['Channel'] = CHANNEL; + body['LanguageID'] = languageID == 'ar' ? 1 : 2; + + body['IPAdress'] = "10.20.10.20"; + body['generalid'] = GENERAL_ID; + body['PatientOutSA'] = body.containsKey('PatientOutSA') + ? body['PatientOutSA'] != null + ? body['PatientOutSA'] + : PATIENT_OUT_SA_PATIENT_REQ + : PATIENT_OUT_SA_PATIENT_REQ; + + if (body.containsKey('isDentalAllowedBackend')) { + body['isDentalAllowedBackend'] = body.containsKey('isDentalAllowedBackend') + ? body['isDentalAllowedBackend'] != null + ? body['isDentalAllowedBackend'] + : IS_DENTAL_ALLOWED_BACKEND + : IS_DENTAL_ALLOWED_BACKEND; + } + + body['DeviceTypeID'] = Platform.isAndroid ? 1 : 2; + + body['PatientType'] = body.containsKey('PatientType') + ? body['PatientType'] != null + ? body['PatientType'] + : patient!.patientType != null + ? patient.patientType + : PATIENT_TYPE + : PATIENT_TYPE; + + body['PatientTypeID'] = body.containsKey('PatientTypeID') + ? body['PatientTypeID'] != null + ? body['PatientTypeID'] + : patient!.patientType != null + ? patient.patientType + : 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['PatientOutSA'] = 0; //user['OutSA']; //TODO change it + body['SessionID'] = SESSION_ID; //getSe + + int? projectID = await sharedPref.getInt(PROJECT_ID); + if (projectID == 2 || projectID == 3) + body['PatientOutSA'] = true; + else + body['PatientOutSA'] = false; + + // if(!body.containsKey('ProjectID')) { + // if (projectID != null) { + // body['ProjectID'] = 313; + // } else { + // body['ProjectID'] = 0; + // } + // } + + // body['DoctorID'] = 24; //3844083 + // body['TokenID'] = "@dm!n"; + + print("URL : $url"); + print("Body : ${json.encode(body)}"); + 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 int statusCode = response.statusCode; + print("statusCode :$statusCode"); + if (statusCode < 200 || statusCode >= 400 || json == null) { + onFailure('Error While Fetching data', statusCode); + } else { + // var parsed = json.decode(response.body.toString()); + var parsed = json.decode(utf8.decode(response.bodyBytes)); + if (parsed['Response_Message'] != null) { + onSuccess(parsed, statusCode); + } else { + if (parsed['ErrorType'] == 4) { + helpers.navigateToUpdatePage(parsed['ErrorEndUserMessage'], parsed['AndroidLink'], parsed['IOSLink']); + } + if (parsed['IsAuthenticated'] == null) { + if (parsed['isSMSSent'] == true) { + onSuccess(parsed, statusCode); + } else if (parsed['MessageStatus'] == 1) { + onSuccess(parsed, statusCode); + } else if (parsed['Result'] == 'OK') { + onSuccess(parsed, statusCode); + } else { + if (parsed != null) { + onSuccess(parsed, statusCode); + } else { + if (body['DoctorID'] != null) 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) { + onSuccess(parsed, statusCode); + } else if (parsed['MessageStatus'] == 2 && parsed['IsAuthenticated']) { + if (parsed['SameClinicApptList'] != null) { + onSuccess(parsed, statusCode); + } else { + 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"); + + 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']); + 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); + } + } + } else { + if (parsed['SameClinicApptList'] != null) { + onSuccess(parsed, statusCode); + } 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']); + + 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']); + + onFailure(parsed['ErrorEndUserMessage'] ?? parsed['ErrorMessage'], statusCode); + } + } + } + } + } + } else { + onFailure('Please Check The Internet Connection', -1); + } } catch (e) { - print(e); - onFailure(e.toString(), -1); - } + print(e); + onFailure(e.toString(), -1); } + } - String getError(parsed) { + String getError(parsed) { //TODO change this fun String? error = parsed['ErrorEndUserMessage'] ?? parsed['ErrorMessage']; 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"; - } - } + 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 (error == null || error == "null" || error == "null\n") { - return Utils.generateContactAdminMsg(); + return Utils.generateContactAdminMsg(); } 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); @@ -490,10 +392,10 @@ class BaseAppClient { final int statusCode = response.statusCode; if (statusCode < 200 || statusCode >= 400) { - onFailure(Utils.generateContactAdminMsg(), statusCode); + onFailure(Utils.generateContactAdminMsg(), statusCode); } else { - var parsed = json.decode(response.body.toString()); - onSuccess(parsed, statusCode); - } + var parsed = json.decode(response.body.toString()); + onSuccess(parsed, statusCode); } } +} diff --git a/lib/config/config.dart b/lib/config/config.dart index 3607a8c8..2385fe15 100644 --- a/lib/config/config.dart +++ b/lib/config/config.dart @@ -413,7 +413,7 @@ const TRANSACTION_NO = 0; const LANGUAGE_ID = 2; const STAMP = '2020-04-27T12:17:17.721Z'; const IP_ADDRESS = '9.9.9.9'; -const VERSION_ID = 9.6; +const VERSION_ID = 9.7; const CHANNEL = 9; const SESSION_ID = 'BlUSkYymTt'; const IS_LOGIN_FOR_DOCTOR_APP = true; diff --git a/pubspec.yaml b/pubspec.yaml index b6962700..fb9088fb 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -11,7 +11,7 @@ description: A new Flutter project. # In iOS, build-name is used as CFBundleShortVersionString while build-number used as CFBundleVersion. # Read more about iOS versioning at # https://developer.apple.com/library/archive/documentation/General/Reference/InfoPlistKeyReference/Articles/CoreFoundationKeys.html -version: 1.4.22+33 +version: 1.4.24+1 environment: