From e2adc629b83e0d24f9dd8e2ee6d6a805b37e813b Mon Sep 17 00:00:00 2001 From: Sultan khan Date: Tue, 28 Apr 2026 19:09:24 +0300 Subject: [PATCH] e-referral issue and registration crashlytics issue fixed. --- assets/langs/ar-SA.json | 4 +- assets/langs/en-US.json | 4 +- .../authentication_view_model.dart | 50 ++++++++++++------- .../hmg_services/hmg_services_view_model.dart | 37 +++++++------- .../authentication/register_step2.dart | 10 ++-- .../e_referral/e_referral_form_manager.dart | 12 +++++ .../widget/e_referral_other_details.dart | 22 ++++++++ 7 files changed, 95 insertions(+), 44 deletions(-) diff --git a/assets/langs/ar-SA.json b/assets/langs/ar-SA.json index f0e830f7..b034ed89 100644 --- a/assets/langs/ar-SA.json +++ b/assets/langs/ar-SA.json @@ -1841,5 +1841,7 @@ "thisAboveInfoPrescription": "تم تحليل الوصفة الطبية هذه بواسطة الذكاء الاصطناعي، وهي لا تُعدّ نصيحة طبية. استشر طبيبك المختص للتشخيص والعلاج.", "liveCareNotificationPermissionsMessage": "يتطلب لايف كير أذونات الإشعارات، يرجى السماح بهذه الأذونات للمتابعة.", "weatherIndicators": "طقس", - "submitRating": "إرسال التقييم" + "submitRating": "إرسال التقييم", + "maxOneFileAllowed": "يمكن رفع ملف واحد فقط", + "fileSizeExceedsLimit": "يجب ألا يتجاوز حجم الملف 1 ميغابايت" } diff --git a/assets/langs/en-US.json b/assets/langs/en-US.json index e17992f9..ece2f0d9 100644 --- a/assets/langs/en-US.json +++ b/assets/langs/en-US.json @@ -1831,7 +1831,9 @@ "thisAboveInfoPrescription": "This prescription was analyzed by AI, and it is not medical advice. Consult your healthcare provider for diagnosis and treatment.", "liveCareNotificationPermissionsMessage": "LiveCare requires Notifications permission, Please allow to proceed.", "weatherIndicators": "Weather", - "submitRating": "Submit" + "submitRating": "Submit", + "maxOneFileAllowed": "Only 1 file can be uploaded", + "fileSizeExceedsLimit": "File size must not exceed 1 MB" } diff --git a/lib/features/authentication/authentication_view_model.dart b/lib/features/authentication/authentication_view_model.dart index d02607c5..ef48f388 100644 --- a/lib/features/authentication/authentication_view_model.dart +++ b/lib/features/authentication/authentication_view_model.dart @@ -1033,24 +1033,33 @@ class AuthenticationViewModel extends ChangeNotifier { } Future insertPatientIMEIData(int loginType) async { + final authenticatedUser = _appState.getAuthenticatedUser(); + if (authenticatedUser == null) { + log("insertPatientIMEIData: authenticatedUser is null, skipping."); + return; + } + if (authenticatedUser.patientId == null) { + log("insertPatientIMEIData: patientId is null, skipping."); + return; + } final resultEither = await _authenticationRepo.insertPatientIMEIData( patientIMEIDataRequest: PatientInsertDeviceImei( imei: _appState.deviceToken, deviceTypeId: _appState.getDeviceTypeID(), - patientId: _appState.getAuthenticatedUser()!.patientId!, - patientIdentificationNo: _appState.getAuthenticatedUser()!.patientIdentificationNo!, - identificationNo: _appState.getAuthenticatedUser()!.patientIdentificationNo!, - firstName: _appState.getAuthenticatedUser()!.firstName!, - lastName: _appState.getAuthenticatedUser()!.lastName!, - patientTypeId: _appState.getAuthenticatedUser()!.patientType, - mobileNo: _appState.getAuthenticatedUser()!.mobileNumber!, + patientId: authenticatedUser.patientId!, + patientIdentificationNo: authenticatedUser.patientIdentificationNo ?? '', + identificationNo: authenticatedUser.patientIdentificationNo ?? '', + firstName: authenticatedUser.firstName ?? '', + lastName: authenticatedUser.lastName ?? '', + patientTypeId: authenticatedUser.patientType, + mobileNo: authenticatedUser.mobileNumber ?? '', logInTypeId: loginType, - patientOutSa: _appState.getAuthenticatedUser()!.outSa!, - outSa: _appState.getAuthenticatedUser()!.outSa == 1 ? true : false, + patientOutSa: authenticatedUser.outSa ?? 0, + outSa: authenticatedUser.outSa == 1 ? true : false, biometricEnabled: loginType == 1 || loginType == 2 ? false : true, - firstNameN: _appState.getAuthenticatedUser()!.firstNameN, - lastNameN: _appState.getAuthenticatedUser()!.lastNameN, - zipCode: _appState.getAuthenticatedUser()!.zipCode //selectedCountrySignup == CountryEnum.others ? '0': selectedCountrySignup.countryCode, + firstNameN: authenticatedUser.firstNameN, + lastNameN: authenticatedUser.lastNameN, + zipCode: authenticatedUser.zipCode //selectedCountrySignup == CountryEnum.others ? '0': selectedCountrySignup.countryCode, ) .toJson()); resultEither.fold((failure) async => await _errorHandlerService.handleError(failure: failure), (apiResponse) async { @@ -1064,22 +1073,27 @@ class AuthenticationViewModel extends ChangeNotifier { } Future insertPatientDeviceData(int loginType) async { + final authenticatedUser = _appState.getAuthenticatedUser(); + if (authenticatedUser == null || authenticatedUser.patientId == null) { + log("insertPatientDeviceData: authenticatedUser or patientId is null, skipping."); + return; + } 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!, + patientId: authenticatedUser.patientId!, + patientTypeId: authenticatedUser.patientType, + patientOutSa: authenticatedUser.outSa ?? 0, 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) + patientMobileNumber: authenticatedUser.mobileNumber, + nationalId: authenticatedUser.patientIdentificationNo, + gender: authenticatedUser.gender) .toJson()); resultEither.fold((failure) async { // await _errorHandlerService.handleError(failure: failure); diff --git a/lib/features/hmg_services/hmg_services_view_model.dart b/lib/features/hmg_services/hmg_services_view_model.dart index 9f468f76..5ced7d57 100644 --- a/lib/features/hmg_services/hmg_services_view_model.dart +++ b/lib/features/hmg_services/hmg_services_view_model.dart @@ -135,7 +135,7 @@ class HmgServicesViewModel extends ChangeNotifier { notifyListeners(); await errorHandlerService.handleError(failure: failure); if (onError != null) { - onError(failure.toString()); + onError(failure.message); } }, (apiResponse) { @@ -168,7 +168,7 @@ class HmgServicesViewModel extends ChangeNotifier { notifyListeners(); await errorHandlerService.handleError(failure: failure); if (onError != null) { - onError(failure.toString()); + onError(failure.message); } }, (apiResponse) { @@ -207,7 +207,7 @@ class HmgServicesViewModel extends ChangeNotifier { notifyListeners(); await errorHandlerService.handleError(failure: failure); if (onError != null) { - onError(failure.toString()); + onError(failure.message); } }, (apiResponse) { @@ -242,7 +242,7 @@ class HmgServicesViewModel extends ChangeNotifier { notifyListeners(); await errorHandlerService.handleError(failure: failure); if (onError != null) { - onError(failure.toString()); + onError(failure.message); } }, (apiResponse) { @@ -335,7 +335,7 @@ class HmgServicesViewModel extends ChangeNotifier { notifyListeners(); await errorHandlerService.handleError(failure: failure); if (onError != null) { - onError(failure.toString()); + onError(failure.message); } }, (apiResponse) { @@ -379,7 +379,7 @@ class HmgServicesViewModel extends ChangeNotifier { notifyListeners(); await errorHandlerService.handleError(failure: failure); if (onError != null) { - onError(failure.toString()); + onError(failure.message); } }, (apiResponse) { @@ -412,7 +412,7 @@ class HmgServicesViewModel extends ChangeNotifier { notifyListeners(); await errorHandlerService.handleError(failure: failure); if (onError != null) { - onError(failure.toString()); + onError(failure.message); } }, (apiResponse) { @@ -451,7 +451,7 @@ class HmgServicesViewModel extends ChangeNotifier { notifyListeners(); await errorHandlerService.handleError(failure: failure); if (onError != null) { - onError(failure.toString()); + onError(failure.message); } }, (apiResponse) { @@ -498,7 +498,7 @@ class HmgServicesViewModel extends ChangeNotifier { notifyListeners(); await errorHandlerService.handleError(failure: failure); if (onError != null) { - onError(failure.toString()); + onError(failure.message); } }, (apiResponse) { @@ -577,7 +577,7 @@ class HmgServicesViewModel extends ChangeNotifier { notifyListeners(); await errorHandlerService.handleError(failure: failure); if (onError != null) { - onError(failure.toString()); + onError(failure.message); } }, (apiResponse) { @@ -609,7 +609,7 @@ class HmgServicesViewModel extends ChangeNotifier { notifyListeners(); await errorHandlerService.handleError(failure: failure); if (onError != null) { - onError(failure.toString()); + onError(failure.message); } }, (apiResponse) { @@ -646,7 +646,7 @@ class HmgServicesViewModel extends ChangeNotifier { notifyListeners(); await errorHandlerService.handleError(failure: failure); if (onError != null) { - onError(failure.toString()); + onError(failure.message); } }, (apiResponse) { @@ -687,7 +687,7 @@ class HmgServicesViewModel extends ChangeNotifier { notifyListeners(); await errorHandlerService.handleError(failure: failure); if (onError != null) { - onError(failure.toString()); + onError(failure.message); } }, (apiResponse) { @@ -718,9 +718,8 @@ class HmgServicesViewModel extends ChangeNotifier { result.fold( (failure) async { notifyListeners(); - // await errorHandlerService.handleError(failure: failure); if (onError != null) { - onError(failure.toString()); + onError(failure.message); } }, (apiResponse) { @@ -753,7 +752,7 @@ class HmgServicesViewModel extends ChangeNotifier { notifyListeners(); await errorHandlerService.handleError(failure: failure); if (onError != null) { - onError(failure.toString()); + onError(failure.message); } }, (apiResponse) { @@ -837,7 +836,7 @@ class HmgServicesViewModel extends ChangeNotifier { notifyListeners(); await errorHandlerService.handleError(failure: failure); if (onError != null) { - onError(failure.toString()); + onError(failure.message); } }, (apiResponse) { @@ -872,7 +871,7 @@ class HmgServicesViewModel extends ChangeNotifier { notifyListeners(); await errorHandlerService.handleError(failure: failure); if (onError != null) { - onError(failure.toString()); + onError(failure.message); } }, (apiResponse) { @@ -908,7 +907,7 @@ class HmgServicesViewModel extends ChangeNotifier { notifyListeners(); await errorHandlerService.handleError(failure: failure); if (onError != null) { - onError(failure.toString()); + onError(failure.message); } }, (apiResponse) { diff --git a/lib/presentation/authentication/register_step2.dart b/lib/presentation/authentication/register_step2.dart index 4a628fd3..ffde3227 100644 --- a/lib/presentation/authentication/register_step2.dart +++ b/lib/presentation/authentication/register_step2.dart @@ -60,8 +60,8 @@ class _RegisterNew extends State { var name = authVM!.isUserFromUAE() ? "" : appState.getLanguageCode() == "en" - ? ("${appState.getNHICUserData.firstNameEn!.toUpperCase()} ${appState.getNHICUserData.lastNameEn!.toUpperCase()}") - : ("${appState.getNHICUserData.firstNameAr!.toUpperCase()} ${appState.getNHICUserData.lastNameAr!.toUpperCase()}"); + ? ("${(appState.getNHICUserData.firstNameEn ?? '').toUpperCase()} ${(appState.getNHICUserData.lastNameEn ?? '').toUpperCase()}").trim() + : ("${(appState.getNHICUserData.firstNameAr ?? '').toUpperCase()} ${(appState.getNHICUserData.lastNameAr ?? '').toUpperCase()}").trim(); return Scaffold( backgroundColor: AppColors.bgScaffoldColor, appBar: CustomAppBar( @@ -267,8 +267,8 @@ class _RegisterNew extends State { : TextInputWidget( labelText: LocaleKeys.maritalStatus.tr(context: context), hintText: appState.isArabic() - ? (MaritalStatusTypeExtension.fromValue(appState.getNHICUserData.maritalStatusCode)!.typeAr) - : (MaritalStatusTypeExtension.fromValue(appState.getNHICUserData.maritalStatusCode)!.type), + ? (MaritalStatusTypeExtension.fromValue(appState.getNHICUserData.maritalStatusCode)?.typeAr ?? '') + : (MaritalStatusTypeExtension.fromValue(appState.getNHICUserData.maritalStatusCode)?.type ?? ''), isEnable: true, prefix: null, isAllowRadius: false, @@ -352,7 +352,7 @@ class _RegisterNew extends State { ), TextInputWidget( labelText: LocaleKeys.dob.tr(context: context), - hintText: authVM!.isUserFromUAE() ? appState.getUserRegistrationPayload.dob! : appState.getNHICUserData.dateOfBirth ?? "", + hintText: authVM!.isUserFromUAE() ? (appState.getUserRegistrationPayload.dob ?? '') : (appState.getNHICUserData.dateOfBirth ?? ""), controller: authVM!.isUserFromUAE() ? authVM!.dobController : null, isEnable: false, prefix: null, diff --git a/lib/presentation/e_referral/e_referral_form_manager.dart b/lib/presentation/e_referral/e_referral_form_manager.dart index 9e5cbe8c..bcdd6915 100644 --- a/lib/presentation/e_referral/e_referral_form_manager.dart +++ b/lib/presentation/e_referral/e_referral_form_manager.dart @@ -129,6 +129,18 @@ class ReferralFormManager extends ChangeNotifier { notifyListeners(); // Only notify when errors change } + void setFieldError(String field, String? message) { + switch (field) { + case 'medicalReport': + _errors.medicalReport = message; + break; + case 'insuredDocument': + _errors.insuredDocument = message; + break; + } + notifyListeners(); + } + void clearAllErrors() { _errors.requesterName = null; _errors.requesterPhone = null; diff --git a/lib/presentation/e_referral/widget/e_referral_other_details.dart b/lib/presentation/e_referral/widget/e_referral_other_details.dart index c30b67c3..cb0f434d 100644 --- a/lib/presentation/e_referral/widget/e_referral_other_details.dart +++ b/lib/presentation/e_referral/widget/e_referral_other_details.dart @@ -289,6 +289,17 @@ class _OtherDetailsStepState extends State { } void _addMedicalReport(String image, File file, ReferralFormManager formManager) { + // Max 1 file + if (formManager.formData.medicalReportImages.isNotEmpty) { + formManager.setFieldError('medicalReport', LocaleKeys.maxOneFileAllowed.tr(context: context)); + return; + } + // Max 1 MB + final fileSizeInBytes = file.lengthSync(); + if (fileSizeInBytes > 1 * 1024 * 1024) { + formManager.setFieldError('medicalReport', LocaleKeys.fileSizeExceedsLimit.tr(context: context)); + return; + } final newAttachment = EReferralAttachment( fileName: 'medical_report_${formManager.formData.medicalReportImages.length + 1}.png', base64String: image @@ -304,6 +315,17 @@ class _OtherDetailsStepState extends State { } void _addInsuranceDocument(String image, File file, ReferralFormManager formManager) { + // Max 1 file + if (formManager.formData.insuredPatientImages.isNotEmpty) { + formManager.setFieldError('insuredDocument', LocaleKeys.maxOneFileAllowed.tr(context: context)); + return; + } + // Max 1 MB + final fileSizeInBytes = file.lengthSync(); + if (fileSizeInBytes > 1 * 1024 * 1024) { + formManager.setFieldError('insuredDocument', LocaleKeys.fileSizeExceedsLimit.tr(context: context)); + return; + } final newAttachment = EReferralAttachment( fileName: 'insurance_${formManager.formData.insuredPatientImages.length + 1}.png', base64String: image -- 2.30.2