From cd48d83c076a46c50bd5defef4a15932c53f809c Mon Sep 17 00:00:00 2001 From: aamir-csol Date: Wed, 10 Sep 2025 09:19:51 +0300 Subject: [PATCH 1/4] signup --- lib/core/app_state.dart | 3 +- lib/core/utils/request_utils.dart | 55 +++++++++++++++++++ .../authentication_view_model.dart | 24 ++++---- .../registration_payload_model.dart | 22 ++++++++ .../authentication/register_step2.dart | 9 ++- 5 files changed, 93 insertions(+), 20 deletions(-) diff --git a/lib/core/app_state.dart b/lib/core/app_state.dart index 4408844..05fe59a 100644 --- a/lib/core/app_state.dart +++ b/lib/core/app_state.dart @@ -37,7 +37,7 @@ class AppState { if (isFamily) { _authenticatedChildUser = authenticatedUser; } else { - setIsAuthenticated = true; + setIsAuthenticated = true; _authenticatedRootUser = authenticatedUser; } } @@ -106,7 +106,6 @@ class AppState { _nHICUserData = value; } - RegistrationDataModelPayload? _userRegistrationPayload; RegistrationDataModelPayload get getUserRegistrationPayload => _userRegistrationPayload!; diff --git a/lib/core/utils/request_utils.dart b/lib/core/utils/request_utils.dart index 1045d9c..2a26e10 100644 --- a/lib/core/utils/request_utils.dart +++ b/lib/core/utils/request_utils.dart @@ -2,6 +2,9 @@ import 'package:hmg_patient_app_new/core/api_consts.dart'; import 'package:hmg_patient_app_new/core/app_state.dart'; import 'package:hmg_patient_app_new/core/dependencies.dart'; import 'package:hmg_patient_app_new/core/enums.dart'; +import 'package:hmg_patient_app_new/core/utils/date_util.dart'; +import 'package:hmg_patient_app_new/extensions/string_extensions.dart'; +import 'package:hmg_patient_app_new/features/authentication/models/request_models/registration_payload_model.dart'; import 'package:hmg_patient_app_new/features/authentication/models/request_models/send_activation_request_model.dart'; import 'package:hmg_patient_app_new/features/common/models/commong_authanticated_req_model.dart'; @@ -169,4 +172,56 @@ class RequestUtils { request.tokenId = null; return request; } + + static dynamic getUserSignupCompletionRequest() { + AppState appState = getIt.get(); + + bool isDubai = appState.getUserRegistrationPayload.patientOutSa == 1 ? true : false; + List names = appState.getUserRegistrationPayload.fullName != null ? appState.getUserRegistrationPayload.fullName!.split(" ") : []; + + var dob = appState.getUserRegistrationPayload.dob; + + return { + "Patientobject": { + "TempValue": true, + "PatientIdentificationType": + (isDubai ? appState.getNHICUserData.idNumber!.substring(0, 1) : appState.getUserRegistrationPayload.patientIdentificationId?.toString().substring(0, 1)) == "1" ? 1 : 2, + "PatientIdentificationNo": isDubai ? appState.getNHICUserData.idNumber! : appState.getUserRegistrationPayload.patientIdentificationId, + "MobileNumber": appState.getUserRegistrationPayload.patientMobileNumber ?? 0, + "PatientOutSA": (appState.getUserRegistrationPayload.zipCode == CountryEnum.saudiArabia.countryCode || appState.getUserRegistrationPayload.zipCode == '+966') ? 0 : 1, + "FirstNameN": isDubai ? "..." : appState.getNHICUserData.firstNameAr, + "FirstName": isDubai ? (names.isNotEmpty ? names[0] : "...") : appState.getNHICUserData.firstNameEn, + "MiddleNameN": isDubai ? "..." : appState.getNHICUserData.secondNameAr, + "MiddleName": isDubai ? "..." : appState.getNHICUserData.secondNameEn, + "LastNameN": isDubai ? "..." : appState.getNHICUserData.lastNameAr, + "LastName": isDubai ? (names.length > 1 ? names[1] : "...") : appState.getNHICUserData.lastNameEn, + "StrDateofBirth": dob, + "DateofBirth": DateUtil.convertISODateToJsonDate((dob ?? "").replaceAll('/', '-')), + "Gender": isDubai ? (appState.getUserRegistrationPayload.gender == GenderTypeEnum.male ? 1 : 2) : (appState.getNHICUserData.gender == 'M' ? 1 : 2), + "NationalityID": isDubai ? "UAE" : appState.getUserRegistrationPayload.nationalityCode, + "eHealthIDField": isDubai ? null : appState.getNHICUserData.healthId, + "DateofBirthN": DateTime.now(), + "EmailAddress": appState.getUserRegistrationPayload.emailAddress, + "SourceType": (appState.getUserRegistrationPayload.zipCode == CountryEnum.saudiArabia.countryCode || appState.getUserRegistrationPayload.zipCode == '+966') ? 1 : 2, + "PreferredLanguage": appState.getLanguageCode() == "ar" ? (isDubai ? "1" : 1) : (isDubai ? "2" : 2), + "Marital": isDubai + ? (appState.getUserRegistrationPayload.maritalStatus == MaritalStatusTypeEnum.single + ? '0' + : appState.getUserRegistrationPayload.maritalStatus == MaritalStatusTypeEnum.married + ? '1' + : '2') + : (appState.getNHICUserData.maritalStatusCode == 'U' + ? '0' + : appState.getNHICUserData.maritalStatusCode == 'M' + ? '1' + : '2'), + }, + "PatientIdentificationID": isDubai ? appState.getUserRegistrationPayload.patientIdentificationId : appState.getNHICUserData.idNumber, + "PatientMobileNumber": appState.getUserRegistrationPayload.patientMobileNumber.toString()[0] == '0' + ? appState.getUserRegistrationPayload.patientMobileNumber + : '0${appState.getUserRegistrationPayload.patientMobileNumber}', + if (isDubai) "DOB": dob, + if (isDubai) "IsHijri": appState.getUserRegistrationPayload.isHijri, + }; + } } diff --git a/lib/features/authentication/authentication_view_model.dart b/lib/features/authentication/authentication_view_model.dart index fbfa2b1..e1a4d32 100644 --- a/lib/features/authentication/authentication_view_model.dart +++ b/lib/features/authentication/authentication_view_model.dart @@ -50,7 +50,11 @@ class AuthenticationViewModel extends ChangeNotifier { _authenticationRepo = authenticationRepo, _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; MaritalStatusTypeEnum? maritalStatus; GenderTypeEnum? genderType; @@ -558,20 +562,14 @@ class AuthenticationViewModel extends ChangeNotifier { }); } - - Future onRegistrationComplete() async{ - - // if (emailAddress.text.isEmpty) { - // Utils.showErrorToast(TranslationBase.of(context).enterEmailAddress); - // return; - // } else { - // Navigator.of(context).pop(); - // registerNow(); - // } - //authVM!.clearDefaultInputValues(); + Future onRegistrationComplete() async { + var request = RequestUtils.getUserSignupCompletionRequest(); + clearDefaultInputValues(); + print("============= Final Payload ==============="); + print(request); + print("==========================================="); } - Future checkUserStatusForRegistration({required dynamic response, required dynamic request}) async { if (response is Map) { _appState.setAppAuthToken = response["LogInTokenID"]; diff --git a/lib/features/authentication/models/request_models/registration_payload_model.dart b/lib/features/authentication/models/request_models/registration_payload_model.dart index fa4f612..93c409b 100644 --- a/lib/features/authentication/models/request_models/registration_payload_model.dart +++ b/lib/features/authentication/models/request_models/registration_payload_model.dart @@ -1,5 +1,7 @@ import 'dart:convert'; +import 'package:hmg_patient_app_new/core/enums.dart'; + class RegistrationDataModelPayload { int? patientMobileNumber; String? zipCode; @@ -14,6 +16,11 @@ class RegistrationDataModelPayload { bool? forRegister; bool? isRegister; String? healthId; + String? emailAddress; + String? nationalityCode; + GenderTypeEnum? gender; + MaritalStatusTypeEnum? maritalStatus; + String? fullName; RegistrationDataModelPayload({ this.patientMobileNumber, @@ -29,6 +36,11 @@ class RegistrationDataModelPayload { this.forRegister, this.isRegister, this.healthId, + this.emailAddress, + this.nationalityCode, + this.gender, + this.maritalStatus, + this.fullName, }); factory RegistrationDataModelPayload.fromRawJson(String str) => RegistrationDataModelPayload.fromJson(json.decode(str)); @@ -49,6 +61,11 @@ class RegistrationDataModelPayload { forRegister: json["forRegister"], isRegister: json["isRegister"], healthId: json["healthId"], + emailAddress: json["emailAddress"], + nationalityCode: json["nationalityCode"], + gender: json["gender"], + maritalStatus: json["maritalStatus"], + fullName: json["fullName"], ); Map toJson() => { @@ -65,5 +82,10 @@ class RegistrationDataModelPayload { "forRegister": forRegister, "isRegister": isRegister, "healthId": healthId, + "emailAddress": emailAddress, + "nationalityCode": nationalityCode, + "gender": gender, + "maritalStatus": maritalStatus, + "fullName": fullName, }; } diff --git a/lib/presentation/authentication/register_step2.dart b/lib/presentation/authentication/register_step2.dart index bd23be1..da46888 100644 --- a/lib/presentation/authentication/register_step2.dart +++ b/lib/presentation/authentication/register_step2.dart @@ -46,7 +46,7 @@ class _RegisterNew extends State { appBar: CustomAppBar( onBackPressed: () { Navigator.of(context).pop(); - authVM!.clearDefaultInputValues(); + // authVM!.clearDefaultInputValues(); }, onLanguageChanged: (lang) {}, hideLogoAndLang: true, @@ -224,8 +224,7 @@ class _RegisterNew extends State { isBorderAllowed: false, isAllowLeadingIcon: true, isReadOnly: true, - leadingIcon: AppAssets.call, - onChange: (value) {}) + leadingIcon: AppAssets.call) .paddingSymmetrical(0.h, 16.h), Divider( height: 1, @@ -233,8 +232,8 @@ class _RegisterNew extends State { ), TextInputWidget( labelText: LocaleKeys.dob.tr(), - hintText: authVM!.isUserFromUAE() ? appState.getUserRegistrationPayload.dob! : (appState.getNHICUserData.dateOfBirth ?? ""), - controller: authVM!.dobController, + hintText: authVM!.isUserFromUAE() ? appState.getUserRegistrationPayload.dob! : appState.getNHICUserData.dateOfBirth ?? "", + controller: authVM!.isUserFromUAE() ? authVM!.dobController : null, isEnable: authVM!.isUserFromUAE() ? true : false, prefix: null, isBorderAllowed: false, From 8c5506415804a1c786def3f1e30423b0838c63fb Mon Sep 17 00:00:00 2001 From: aamir-csol Date: Wed, 10 Sep 2025 16:42:22 +0300 Subject: [PATCH 2/4] signup completed --- lib/core/api_consts.dart | 1 + lib/core/app_state.dart | 1 + lib/core/utils/request_utils.dart | 50 ++-- .../authentication/authentication_repo.dart | 36 ++- .../authentication_view_model.dart | 85 ++++--- .../registration_payload_model.dart | 238 ++++++++++++++---- lib/presentation/authentication/register.dart | 2 +- .../authentication/register_step2.dart | 6 +- 8 files changed, 318 insertions(+), 101 deletions(-) diff --git a/lib/core/api_consts.dart b/lib/core/api_consts.dart index daa094e..a603cf9 100644 --- a/lib/core/api_consts.dart +++ b/lib/core/api_consts.dart @@ -804,6 +804,7 @@ class ApiConsts { static final String insertPatientMobileData = 'Services/MobileNotifications.svc/REST/Insert_PatientMobileDeviceInfo'; static final String getPrivileges = 'Services/Patients.svc/REST/Service_Privilege'; + static final String registerUser = 'Services/Authentication.svc/REST/PatientRegistration'; // static values for Api static final double appVersionID = 18.7; diff --git a/lib/core/app_state.dart b/lib/core/app_state.dart index 3c4555e..52500bf 100644 --- a/lib/core/app_state.dart +++ b/lib/core/app_state.dart @@ -5,6 +5,7 @@ import 'package:hmg_patient_app_new/core/common_models/privilege/HMCProjectListM 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/features/authentication/models/request_models/send_activation_request_model.dart'; import 'package:hmg_patient_app_new/features/authentication/models/resp_models/authenticated_user_resp_model.dart'; import 'package:hmg_patient_app_new/features/authentication/models/resp_models/check_user_staus_nhic_response_model.dart'; import 'package:hmg_patient_app_new/features/authentication/models/resp_models/select_device_by_imei.dart'; diff --git a/lib/core/utils/request_utils.dart b/lib/core/utils/request_utils.dart index 21b5952..fb6624d 100644 --- a/lib/core/utils/request_utils.dart +++ b/lib/core/utils/request_utils.dart @@ -1,3 +1,5 @@ +import 'package:easy_localization/easy_localization.dart'; +import 'package:hijri_gregorian_calendar/hijri_gregorian_calendar.dart'; import 'package:hmg_patient_app_new/core/api_consts.dart'; import 'package:hmg_patient_app_new/core/app_state.dart'; import 'package:hmg_patient_app_new/core/dependencies.dart'; @@ -63,7 +65,7 @@ class RequestUtils { required String? deviceToken, required bool patientOutSA, required String? loginTokenID, - required var registeredData, + required RegistrationDataModelPayload registeredData, int? patientId, required String nationIdText, required String countryCode, @@ -84,8 +86,8 @@ class RequestUtils { if (registeredData != null) { request.searchType = registeredData.searchType ?? 1; - request.patientID = registeredData.patientID ?? 0; - request.patientIdentificationID = request.nationalID = registeredData.patientIdentificationID ?? '0'; + request.patientID = registeredData.patientId ?? 0; + request.patientIdentificationID = request.nationalID = (registeredData.patientIdentificationId ?? 0); request.dob = registeredData.dob; request.isRegister = registeredData.isRegister; } else { @@ -135,9 +137,10 @@ class RequestUtils { request.patientIdentificationID = request.nationalID = payload["PatientIdentificationID"] ?? '0'; request.dob = payload["DOB"]; request.isRegister = payload["isRegister"]; - request.healthId = _appState.getNHICUserData.healthId; + request.healthId = patientOutSA ? null : _appState.getNHICUserData.healthId; request.isHijri = payload["IsHijri"]; request.deviceToken = _appState.deviceToken; + request.projectOutSA = patientOutSA; } else { request.searchType = isFileNo ? 2 : 1; request.patientID = patientId ?? 0; @@ -176,20 +179,25 @@ class RequestUtils { return request; } - static dynamic getUserSignupCompletionRequest() { + static dynamic getUserSignupCompletionRequest({String? fullName, String? emailAddress, GenderTypeEnum? gender, MaritalStatusTypeEnum? maritalStatus}) { AppState appState = getIt.get(); bool isDubai = appState.getUserRegistrationPayload.patientOutSa == 1 ? true : false; - List names = appState.getUserRegistrationPayload.fullName != null ? appState.getUserRegistrationPayload.fullName!.split(" ") : []; + List names = fullName != null ? fullName.split(" ") : []; var dob = appState.getUserRegistrationPayload.dob; + final DateFormat dateFormat1 = DateFormat('MM/dd/yyyy'); + final DateFormat dateFormat2 = DateFormat('dd/MM/yyyy'); + DateTime gregorianDate = dateFormat2.parse(dob!); + HijriGregDate hijriDate = HijriGregConverter.gregorianToHijri(gregorianDate); + String? date = "${hijriDate.day}/${hijriDate.month}/${hijriDate.year}"; return { "Patientobject": { "TempValue": true, "PatientIdentificationType": - (isDubai ? appState.getNHICUserData.idNumber!.substring(0, 1) : appState.getUserRegistrationPayload.patientIdentificationId?.toString().substring(0, 1)) == "1" ? 1 : 2, - "PatientIdentificationNo": isDubai ? appState.getNHICUserData.idNumber! : appState.getUserRegistrationPayload.patientIdentificationId, + (isDubai ? appState.getUserRegistrationPayload.patientIdentificationId?.toString().substring(0, 1) : appState.getNHICUserData.idNumber!.substring(0, 1)) == "1" ? 1 : 2, + "PatientIdentificationNo": isDubai ? appState.getUserRegistrationPayload.patientIdentificationId.toString() : appState.getNHICUserData.idNumber.toString(), "MobileNumber": appState.getUserRegistrationPayload.patientMobileNumber ?? 0, "PatientOutSA": (appState.getUserRegistrationPayload.zipCode == CountryEnum.saudiArabia.countryCode || appState.getUserRegistrationPayload.zipCode == '+966') ? 0 : 1, "FirstNameN": isDubai ? "..." : appState.getNHICUserData.firstNameAr, @@ -198,19 +206,19 @@ class RequestUtils { "MiddleName": isDubai ? "..." : appState.getNHICUserData.secondNameEn, "LastNameN": isDubai ? "..." : appState.getNHICUserData.lastNameAr, "LastName": isDubai ? (names.length > 1 ? names[1] : "...") : appState.getNHICUserData.lastNameEn, - "StrDateofBirth": dob, + "StrDateofBirth": dateFormat1.format(dateFormat2.parse(dob)), "DateofBirth": DateUtil.convertISODateToJsonDate((dob ?? "").replaceAll('/', '-')), - "Gender": isDubai ? (appState.getUserRegistrationPayload.gender == GenderTypeEnum.male ? 1 : 2) : (appState.getNHICUserData.gender == 'M' ? 1 : 2), - "NationalityID": isDubai ? "UAE" : appState.getUserRegistrationPayload.nationalityCode, + "Gender": isDubai ? (gender == GenderTypeEnum.male ? 1 : 2) : (appState.getNHICUserData.gender == 'M' ? 1 : 2), + "NationalityID": isDubai ? "UAE" : appState.getNHICUserData.nationalityCode, "eHealthIDField": isDubai ? null : appState.getNHICUserData.healthId, - "DateofBirthN": DateTime.now(), - "EmailAddress": appState.getUserRegistrationPayload.emailAddress, - "SourceType": (appState.getUserRegistrationPayload.zipCode == CountryEnum.saudiArabia.countryCode || appState.getUserRegistrationPayload.zipCode == '+966') ? 1 : 2, + "DateofBirthN": date, + "EmailAddress": emailAddress, + "SourceType": (appState.getUserRegistrationPayload.zipCode == CountryEnum.saudiArabia.countryCode || appState.getUserRegistrationPayload.zipCode == '+966') ? "1" : "2", "PreferredLanguage": appState.getLanguageCode() == "ar" ? (isDubai ? "1" : 1) : (isDubai ? "2" : 2), "Marital": isDubai - ? (appState.getUserRegistrationPayload.maritalStatus == MaritalStatusTypeEnum.single + ? (maritalStatus == MaritalStatusTypeEnum.single ? '0' - : appState.getUserRegistrationPayload.maritalStatus == MaritalStatusTypeEnum.married + : maritalStatus == MaritalStatusTypeEnum.married ? '1' : '2') : (appState.getNHICUserData.maritalStatusCode == 'U' @@ -219,12 +227,16 @@ class RequestUtils { ? '1' : '2'), }, - "PatientIdentificationID": isDubai ? appState.getUserRegistrationPayload.patientIdentificationId : appState.getNHICUserData.idNumber, + "PatientIdentificationID": isDubai ? appState.getUserRegistrationPayload.patientIdentificationId.toString() : appState.getNHICUserData.idNumber.toString(), "PatientMobileNumber": appState.getUserRegistrationPayload.patientMobileNumber.toString()[0] == '0' ? appState.getUserRegistrationPayload.patientMobileNumber : '0${appState.getUserRegistrationPayload.patientMobileNumber}', - if (isDubai) "DOB": dob, - if (isDubai) "IsHijri": appState.getUserRegistrationPayload.isHijri, + "DOB": dob, + "IsHijri": appState.getUserRegistrationPayload.isHijri, + "PatientOutSA": (appState.getUserRegistrationPayload.zipCode == CountryEnum.saudiArabia.countryCode || appState.getUserRegistrationPayload.zipCode == '+966') ? 0 : 1, + "isDentalAllowedBackend": appState.getUserRegistrationPayload.isDentalAllowedBackend, + "ZipCode": appState.getUserRegistrationPayload.zipCode, + if (!isDubai) "HealthId": appState.getNHICUserData.healthId, }; } } diff --git a/lib/features/authentication/authentication_repo.dart b/lib/features/authentication/authentication_repo.dart index d81094c..22ca90f 100644 --- a/lib/features/authentication/authentication_repo.dart +++ b/lib/features/authentication/authentication_repo.dart @@ -32,6 +32,8 @@ abstract class AuthenticationRepo { Future>> checkUserStatus({required dynamic commonAuthanticatedRequest}); + Future>> registerUser({required dynamic registrationPayloadDataModelRequest}); + Future>> insertPatientIMEIData({required dynamic patientIMEIDataRequest}); Future>> insertPatientDeviceData({required dynamic patientDeviceDataRequest}); @@ -182,7 +184,6 @@ class AuthenticationRepoImp implements AuthenticationRepo { newRequest.projectOutSA = newRequest.zipCode == '966' ? false : true; newRequest.isDentalAllowedBackend = false; newRequest.forRegisteration = newRequest.isRegister ?? false; - newRequest.isRegister = false; } @@ -357,6 +358,39 @@ class AuthenticationRepoImp implements AuthenticationRepo { } } + @override + Future>> registerUser({required dynamic registrationPayloadDataModelRequest}) async { + try { + GenericApiModel? apiResponse; + Failure? failure; + await apiClient.post( + ApiConsts.registerUser, + body: registrationPayloadDataModelRequest, + onFailure: (error, statusCode, {messageStatus, failureType}) { + failure = failureType; + }, + onSuccess: (response, statusCode, {messageStatus, errorMessage}) { + try { + apiResponse = GenericApiModel( + messageStatus: messageStatus, + statusCode: statusCode, + errorMessage: errorMessage, + data: response, + ); + } catch (e) { + failure = DataParsingFailure(e.toString()); + } + }, + ); + + if (failure != null) return Left(failure!); + if (apiResponse == null) return Left(ServerFailure("Unknown error")); + return Right(apiResponse!); + } catch (e) { + return Left(UnknownFailure(e.toString())); + } + } + @override Future> insertPatientIMEIData({required patientIMEIDataRequest}) { try { diff --git a/lib/features/authentication/authentication_view_model.dart b/lib/features/authentication/authentication_view_model.dart index 6d5f3c1..7122482 100644 --- a/lib/features/authentication/authentication_view_model.dart +++ b/lib/features/authentication/authentication_view_model.dart @@ -107,6 +107,8 @@ class AuthenticationViewModel extends ChangeNotifier { isTermsAccepted = false; selectedCountrySignup = CountryEnum.saudiArabia; pickedCountryByUAEUser = null; + _appState.setUserRegistrationPayload = RegistrationDataModelPayload(); + _appState.setNHICUserData = CheckUserStatusResponseNHIC(); } void onCountryChange(CountryEnum country) { @@ -308,40 +310,27 @@ class AuthenticationViewModel extends ChangeNotifier { } Future sendActivationCode({required OTPTypeEnum otpTypeEnum, required String nationalIdOrFileNumber, required String phoneNumber, dynamic payload}) async { - bool isForRegister = checkIsUserComingForRegister(request: payload); - bool isPatientOutSA = isPatientOutsideSA(request: payload); - bool isFileNo = isPatientHasFile(request: payload); - var request = RequestUtils.getCommonRequestSendActivationCode( otpTypeEnum: otpTypeEnum, mobileNumber: phoneNumber, selectedLoginType: otpTypeEnum.toInt(), zipCode: selectedCountrySignup.countryCode, nationalId: int.parse(nationalIdOrFileNumber), - isFileNo: isFileNo, + isFileNo: isPatientHasFile(request: payload), patientId: 0, - isForRegister: isForRegister, - patientOutSA: isPatientOutSA, + isForRegister: checkIsUserComingForRegister(request: payload), + patientOutSA: isPatientOutsideSA(request: payload), payload: payload); // TODO: GET APP SMS SIGNATURE HERE request.sMSSignature = "enKTDcqbOVd"; - // GifLoaderDialogUtils.showMyDialog(context); - // bool isForRegister = healthId != null || isDubai; - // if (isForRegister) { - // if (!isDubai) { - // request.dob = dob; //isHijri == 1 ? dob : dateFormat2.format(dateFormat.parse(dob)); - // } - // request.healthId = healthId; - // request.isHijri = calenderType.toInt; - // } else { - // // request.dob = ""; - // // request.healthId = ""; - // // request.isHijri = 0; - // } + if (checkIsUserComingForRegister(request: payload)) { + _appState.setUserRegistrationPayload = RegistrationDataModelPayload.fromJson(payload); + print("====== Demo =========="); + } - final resultEither = await _authenticationRepo.sendActivationCodeRepo(sendActivationCodeReq: request, isRegister: isForRegister, languageID: 'er'); + final resultEither = await _authenticationRepo.sendActivationCodeRepo(sendActivationCodeReq: request, isRegister: checkIsUserComingForRegister(request: payload), languageID: 'er'); resultEither.fold( (failure) async => await _errorHandlerService.handleError(failure: failure), @@ -377,19 +366,29 @@ class AuthenticationViewModel extends ChangeNotifier { phoneNumber: phoneNumberController.text, otpTypeEnum: otpTypeEnum, deviceToken: _appState.deviceToken, - patientOutSA: true, + patientOutSA: _appState.getUserRegistrationPayload.projectOutSa == 1 ? true : false, loginTokenID: _appState.appAuthToken, - registeredData: null, + registeredData: _appState.getUserRegistrationPayload, nationIdText: nationalIdController.text, countryCode: selectedCountrySignup.countryCode, loginType: loginTypeEnum.toInt) .toJson(); - bool isForRegister = (_appState.getUserRegistrationPayload.healthId != null || _appState.getUserRegistrationPayload.patientOutSa == true); + bool isForRegister = (_appState.getUserRegistrationPayload.healthId != null || _appState.getUserRegistrationPayload.patientOutSa == 1) ? true : false; if (isForRegister) { - if (_appState.getUserRegistrationPayload.patientOutSa == true) request['DOB'] = _appState.getUserRegistrationPayload.dob; + if (_appState.getUserRegistrationPayload.patientOutSa == 0) request['DOB'] = _appState.getUserRegistrationPayload.dob; request['HealthId'] = _appState.getUserRegistrationPayload.healthId; request['IsHijri'] = _appState.getUserRegistrationPayload.isHijri; + request["PatientOutSA"] = _appState.getUserRegistrationPayload.projectOutSa == true ? 1 : 0; + request["ForRegisteration"] = _appState.getUserRegistrationPayload.isRegister; + request["isRegister"] = false; + + // if (request.containsKey("OTP_SendType")) { + // request.remove("OTP_SendType"); + // print("====== Demo: Removed OTP_SendType for Register state"); + // } + + print("====== Req"); final resultEither = await _authenticationRepo.checkActivationCodeRepo(newRequest: request, activationCode: activationCode.toString(), isRegister: true); @@ -591,11 +590,27 @@ class AuthenticationViewModel extends ChangeNotifier { } Future onRegistrationComplete() async { - var request = RequestUtils.getUserSignupCompletionRequest(); - clearDefaultInputValues(); + var request = RequestUtils.getUserSignupCompletionRequest(fullName: nameController.text, emailAddress: emailController.text, gender: genderType, maritalStatus: maritalStatus); + // print("============= Final Payload ==============="); print(request); - print("==========================================="); + print("=================== ===================="); + + final resultEither = await _authenticationRepo.registerUser(registrationPayloadDataModelRequest: request); + resultEither.fold((failure) async => await _errorHandlerService.handleError(failure: failure), (apiResponse) async { + if (apiResponse.data is String) { + //TODO: Here We Need to Show a Dialog Of Something in the case of Fail With OK and Cancel and the Display Variable WIll be result. + } else { + print(apiResponse.data as Map); + if (apiResponse.data["MessageStatus"] == 1) { + //TODO: Here We Need to Show a Dialog Of Something in the case of Success. + clearDefaultInputValues(); // This will Clear All Default Values Of User. + _navigationService.pushAndReplace(AppRoutes.loginScreen); + } + } + }); + + return; } Future checkUserStatusForRegistration({required dynamic response, required dynamic request}) async { @@ -616,7 +631,8 @@ class AuthenticationViewModel extends ChangeNotifier { sendActivationCode( otpTypeEnum: OTPTypeEnumExtension.fromInt(request["OTP_SendType"]), nationalIdOrFileNumber: request["PatientIdentificationID"].toString(), - phoneNumber: request["PatientMobileNumber"].toString()); + phoneNumber: request["PatientMobileNumber"].toString(), + payload: request); } else { print("=======IN SA======="); chekUserNHICData(request: request); @@ -630,13 +646,12 @@ class AuthenticationViewModel extends ChangeNotifier { bool isPatientOutsideSA({required dynamic request}) { bool isOutSideSa = false; - if (request is Map && request.containsKey("PatientOutSA")) { - if (request["PatientOutSA"] == true) { - isOutSideSa = true; - } else { - isOutSideSa = false; - } + if (request["PatientOutSA"] == true || request["PatientOutSA"] == 1) { + isOutSideSa = true; + } else { + isOutSideSa = false; } + print(isOutSideSa); return isOutSideSa; } diff --git a/lib/features/authentication/models/request_models/registration_payload_model.dart b/lib/features/authentication/models/request_models/registration_payload_model.dart index 93c409b..bbb31f9 100644 --- a/lib/features/authentication/models/request_models/registration_payload_model.dart +++ b/lib/features/authentication/models/request_models/registration_payload_model.dart @@ -1,20 +1,128 @@ +// import 'dart:convert'; +// +// import 'package:hmg_patient_app_new/core/enums.dart'; +// +// class RegistrationDataModelPayload { +// int? patientMobileNumber; +// String? zipCode; +// int? searchType; +// int? patientId; +// int? patientIdentificationId; +// int? otpSendType; +// int? patientOutSa; +// bool? isDentalAllowedBackend; +// String? dob; +// int? isHijri; +// bool? forRegister; +// bool? isRegister; +// String? healthId; +// String? emailAddress; +// String? nationalityCode; +// GenderTypeEnum? gender; +// MaritalStatusTypeEnum? maritalStatus; +// String? fullName; +// +// RegistrationDataModelPayload({ +// this.patientMobileNumber, +// this.zipCode, +// this.searchType, +// this.patientId, +// this.patientIdentificationId, +// this.otpSendType, +// this.patientOutSa, +// this.isDentalAllowedBackend, +// this.dob, +// this.isHijri, +// this.forRegister, +// this.isRegister, +// this.healthId, +// this.emailAddress, +// this.nationalityCode, +// this.gender, +// this.maritalStatus, +// this.fullName, +// }); +// +// factory RegistrationDataModelPayload.fromRawJson(String str) => RegistrationDataModelPayload.fromJson(json.decode(str)); +// +// String toRawJson() => json.encode(toJson()); +// +// factory RegistrationDataModelPayload.fromJson(Map json) => RegistrationDataModelPayload( +// patientMobileNumber: json["PatientMobileNumber"], +// zipCode: json["ZipCode"], +// searchType: json["SearchType"], +// patientId: json["PatientID"], +// patientIdentificationId: json["PatientIdentificationID"], +// otpSendType: json["OTP_SendType"], +// patientOutSa: json["PatientOutSA"], +// isDentalAllowedBackend: json["isDentalAllowedBackend"], +// dob: json["DOB"], +// isHijri: json["IsHijri"], +// forRegister: json["forRegister"], +// isRegister: json["isRegister"], +// healthId: json["healthId"], +// emailAddress: json["emailAddress"], +// nationalityCode: json["nationalityCode"], +// gender: json["gender"], +// maritalStatus: json["maritalStatus"], +// fullName: json["fullName"], +// ); +// +// Map toJson() => { +// "PatientMobileNumber": patientMobileNumber, +// "ZipCode": zipCode, +// "SearchType": searchType, +// "PatientID": patientId, +// "PatientIdentificationID": patientIdentificationId, +// "OTP_SendType": otpSendType, +// "PatientOutSA": patientOutSa, +// "isDentalAllowedBackend": isDentalAllowedBackend, +// "DOB": dob, +// "IsHijri": isHijri, +// "forRegister": forRegister, +// "isRegister": isRegister, +// "healthId": healthId, +// "emailAddress": emailAddress, +// "nationalityCode": nationalityCode, +// "gender": gender, +// "maritalStatus": maritalStatus, +// "fullName": fullName, +// }; +// } + + import 'dart:convert'; import 'package:hmg_patient_app_new/core/enums.dart'; class RegistrationDataModelPayload { int? patientMobileNumber; + String? mobileNo; + String? deviceToken; + bool? projectOutSa; + int? loginType; String? zipCode; + bool? isRegister; + String? logInTokenId; int? searchType; int? patientId; + int? nationalId; int? patientIdentificationId; int? otpSendType; + String? languageId; + String? versionId; + String? channel; + String? ipAdress; + String? generalid; int? patientOutSa; bool? isDentalAllowedBackend; + String? deviceTypeId; + String? smsSignature; String? dob; int? isHijri; - bool? forRegister; - bool? isRegister; + String? patientType; + String? latitude; + String? longitude; String? healthId; String? emailAddress; String? nationalityCode; @@ -22,19 +130,35 @@ class RegistrationDataModelPayload { MaritalStatusTypeEnum? maritalStatus; String? fullName; + RegistrationDataModelPayload({ this.patientMobileNumber, + this.mobileNo, + this.deviceToken, + this.projectOutSa, + this.loginType, this.zipCode, + this.isRegister, + this.logInTokenId, this.searchType, this.patientId, + this.nationalId, this.patientIdentificationId, this.otpSendType, + this.languageId, + this.versionId, + this.channel, + this.ipAdress, + this.generalid, this.patientOutSa, this.isDentalAllowedBackend, + this.deviceTypeId, + this.smsSignature, this.dob, this.isHijri, - this.forRegister, - this.isRegister, + this.patientType, + this.latitude, + this.longitude, this.healthId, this.emailAddress, this.nationalityCode, @@ -48,44 +172,74 @@ class RegistrationDataModelPayload { String toRawJson() => json.encode(toJson()); factory RegistrationDataModelPayload.fromJson(Map json) => RegistrationDataModelPayload( - patientMobileNumber: json["PatientMobileNumber"], - zipCode: json["ZipCode"], - searchType: json["SearchType"], - patientId: json["PatientID"], - patientIdentificationId: json["PatientIdentificationID"], - otpSendType: json["OTP_SendType"], - patientOutSa: json["PatientOutSA"], - isDentalAllowedBackend: json["isDentalAllowedBackend"], - dob: json["DOB"], - isHijri: json["IsHijri"], - forRegister: json["forRegister"], - isRegister: json["isRegister"], - healthId: json["healthId"], - emailAddress: json["emailAddress"], - nationalityCode: json["nationalityCode"], - gender: json["gender"], - maritalStatus: json["maritalStatus"], - fullName: json["fullName"], - ); + patientMobileNumber: json["PatientMobileNumber"], + mobileNo: json["MobileNo"], + deviceToken: json["DeviceToken"], + projectOutSa: json["ProjectOutSA"], + loginType: json["LoginType"], + zipCode: json["ZipCode"], + isRegister: json["isRegister"], + logInTokenId: json["LogInTokenID"], + searchType: json["SearchType"], + patientId: json["PatientID"], + nationalId: json["NationalID"], + patientIdentificationId: json["PatientIdentificationID"], + otpSendType: json["OTP_SendType"], + languageId: json["LanguageID"], + versionId: json["VersionID"], + channel: json["Channel"], + ipAdress: json["IPAdress"], + generalid: json["generalid"], + patientOutSa: json["PatientOutSA"], + isDentalAllowedBackend: json["isDentalAllowedBackend"], + deviceTypeId: json["DeviceTypeID"], + smsSignature: json["SMSSignature"], + dob: json["DOB"], + isHijri: json["IsHijri"], + patientType: json["PatientType"], + latitude: json["Latitude"], + longitude: json["Longitude"], + healthId: json["healthId"], + emailAddress: json["emailAddress"], + nationalityCode: json["nationalityCode"], + gender: json["gender"], + maritalStatus: json["maritalStatus"], + fullName: json["fullName"], + ); Map toJson() => { - "PatientMobileNumber": patientMobileNumber, - "ZipCode": zipCode, - "SearchType": searchType, - "PatientID": patientId, - "PatientIdentificationID": patientIdentificationId, - "OTP_SendType": otpSendType, - "PatientOutSA": patientOutSa, - "isDentalAllowedBackend": isDentalAllowedBackend, - "DOB": dob, - "IsHijri": isHijri, - "forRegister": forRegister, - "isRegister": isRegister, - "healthId": healthId, - "emailAddress": emailAddress, - "nationalityCode": nationalityCode, - "gender": gender, - "maritalStatus": maritalStatus, - "fullName": fullName, - }; + "PatientMobileNumber": patientMobileNumber, + "MobileNo": mobileNo, + "DeviceToken": deviceToken, + "ProjectOutSA": projectOutSa, + "LoginType": loginType, + "ZipCode": zipCode, + "isRegister": isRegister, + "LogInTokenID": logInTokenId, + "SearchType": searchType, + "PatientID": patientId, + "NationalID": nationalId, + "PatientIdentificationID": patientIdentificationId, + "OTP_SendType": otpSendType, + "LanguageID": languageId, + "VersionID": versionId, + "Channel": channel, + "IPAdress": ipAdress, + "generalid": generalid, + "PatientOutSA": patientOutSa, + "isDentalAllowedBackend": isDentalAllowedBackend, + "DeviceTypeID": deviceTypeId, + "SMSSignature": smsSignature, + "DOB": dob, + "IsHijri": isHijri, + "PatientType": patientType, + "Latitude": latitude, + "Longitude": longitude, + "healthId": healthId, + "emailAddress": emailAddress, + "nationalityCode": nationalityCode, + "gender": gender, + "maritalStatus": maritalStatus, + "fullName": fullName, + }; } diff --git a/lib/presentation/authentication/register.dart b/lib/presentation/authentication/register.dart index f238582..efb0a18 100644 --- a/lib/presentation/authentication/register.dart +++ b/lib/presentation/authentication/register.dart @@ -213,7 +213,7 @@ class _RegisterNew extends State { countryCode: authVM.selectedCountrySignup.countryCode, initialPhoneNumber: "", textController: authVM.phoneNumberController, - isEnableCountryDropdown: true, + isEnableCountryDropdown: false, onCountryChange: authVM.onCountryChange, onChange: authVM.onPhoneNumberChange, buttons: [ diff --git a/lib/presentation/authentication/register_step2.dart b/lib/presentation/authentication/register_step2.dart index da46888..0757420 100644 --- a/lib/presentation/authentication/register_step2.dart +++ b/lib/presentation/authentication/register_step2.dart @@ -217,8 +217,8 @@ class _RegisterNew extends State { TextInputWidget( labelText: LocaleKeys.mobileNumber.tr(), hintText: (appState.getUserRegistrationPayload.patientMobileNumber.toString() ?? ""), - controller: authVM!.phoneNumberController, - isEnable: true, + controller: null, + isEnable: false, prefix: null, isAllowRadius: false, isBorderAllowed: false, @@ -255,7 +255,7 @@ class _RegisterNew extends State { icon: AppAssets.cancel, onPressed: () { Navigator.of(context).pop(); - authVM!.clearDefaultInputValues(); + // authVM!.clearDefaultInputValues(); }, backgroundColor: AppColors.secondaryLightRedColor, borderColor: AppColors.secondaryLightRedColor, From 2b18e08e64acaad24aae84440c7bd5dde77ad077 Mon Sep 17 00:00:00 2001 From: aamir-csol Date: Wed, 10 Sep 2025 16:44:19 +0300 Subject: [PATCH 3/4] signup completed --- lib/presentation/authentication/register_step2.dart | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/presentation/authentication/register_step2.dart b/lib/presentation/authentication/register_step2.dart index 0757420..d7071a4 100644 --- a/lib/presentation/authentication/register_step2.dart +++ b/lib/presentation/authentication/register_step2.dart @@ -234,13 +234,13 @@ class _RegisterNew extends State { labelText: LocaleKeys.dob.tr(), hintText: authVM!.isUserFromUAE() ? appState.getUserRegistrationPayload.dob! : appState.getNHICUserData.dateOfBirth ?? "", controller: authVM!.isUserFromUAE() ? authVM!.dobController : null, - isEnable: authVM!.isUserFromUAE() ? true : false, + isEnable: false, prefix: null, isBorderAllowed: false, isAllowLeadingIcon: true, isReadOnly: true, leadingIcon: AppAssets.birthday_cake, - selectionType: authVM!.isUserFromUAE() ? SelectionTypeEnum.calendar : null, + selectionType: null, ).paddingSymmetrical(0.h, 16.h), ], ), From 70810fa14ca2a66faf81c0dc1094cd931a46d24d Mon Sep 17 00:00:00 2001 From: aamir-csol Date: Wed, 10 Sep 2025 17:01:06 +0300 Subject: [PATCH 4/4] signup completed --- .../authentication_view_model.dart | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/lib/features/authentication/authentication_view_model.dart b/lib/features/authentication/authentication_view_model.dart index 7122482..0cf38f5 100644 --- a/lib/features/authentication/authentication_view_model.dart +++ b/lib/features/authentication/authentication_view_model.dart @@ -15,6 +15,7 @@ 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/utils.dart'; import 'package:hmg_patient_app_new/core/utils/validation_utils.dart'; +import 'package:hmg_patient_app_new/extensions/context_extensions.dart'; import 'package:hmg_patient_app_new/extensions/string_extensions.dart'; import 'package:hmg_patient_app_new/features/authentication/authentication_repo.dart'; import 'package:hmg_patient_app_new/features/authentication/models/request_models/check_activation_code_register_request_model.dart'; @@ -30,6 +31,7 @@ import 'package:hmg_patient_app_new/services/dialog_service.dart'; import 'package:hmg_patient_app_new/services/error_handler_service.dart'; import 'package:hmg_patient_app_new/services/localauth_service.dart'; import 'package:hmg_patient_app_new/services/navigation_service.dart'; +import 'package:hmg_patient_app_new/widgets/bottomsheet/exception_bottom_sheet.dart'; import 'models/request_models/insert_patient_mobile_deviceinfo.dart'; import 'models/request_models/patient_insert_device_imei_request.dart'; @@ -615,19 +617,31 @@ class AuthenticationViewModel extends ChangeNotifier { Future checkUserStatusForRegistration({required dynamic response, required dynamic request}) async { if (response is Map) { - _appState.setAppAuthToken = response["LogInTokenID"]; if (response["MessageStatus"] == 2) { print(response["ErrorEndUserMessage"]); return; } if (response['hasFile'] == true) { //TODO: Show Here Ok And Cancel Dialog and On OKPress it will go for sendActivationCode + + _navigationService.context?.showBottomSheet( + child: ExceptionBottomSheet( + message: response["ErrorMessage"], + showCancel: true, + showOKButton: true, + onOkPressed: () { + _navigationService.popUntilNamed(AppRoutes.loginScreen); + }, + onCancelPressed: () { + _navigationService.pop(); + }, + )); } else { request['forRegister'] = true; request['isRegister'] = true; + _appState.setAppAuthToken = response['LogInTokenID']; if (isPatientOutsideSA(request: response)) { print("=======OUT SA======="); - _appState.setAppAuthToken = response['LogInTokenID']; sendActivationCode( otpTypeEnum: OTPTypeEnumExtension.fromInt(request["OTP_SendType"]), nationalIdOrFileNumber: request["PatientIdentificationID"].toString(),