From cd48d83c076a46c50bd5defef4a15932c53f809c Mon Sep 17 00:00:00 2001 From: aamir-csol Date: Wed, 10 Sep 2025 09:19:51 +0300 Subject: [PATCH] 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,