diff --git a/lib/core/app_state.dart b/lib/core/app_state.dart index 3e0bbc1..206adc1 100644 --- a/lib/core/app_state.dart +++ b/lib/core/app_state.dart @@ -37,6 +37,8 @@ class AppState { AuthenticatedUser? _authenticatedRootUser; AuthenticatedUser? _authenticatedChildUser; + int? _superUserID; + void setAuthenticatedUser(AuthenticatedUser authenticatedUser, {bool isFamily = false}) { if (isFamily) { _authenticatedChildUser = authenticatedUser; @@ -55,6 +57,10 @@ class AppState { } } + int? get superUserID => _superUserID; + + set setSuperUserID(int? value) => _superUserID = value; + String _userBloodGroup = ""; String get getUserBloodGroup => _userBloodGroup; diff --git a/lib/features/authentication/authentication_repo.dart b/lib/features/authentication/authentication_repo.dart index 3ed05c6..8d1af92 100644 --- a/lib/features/authentication/authentication_repo.dart +++ b/lib/features/authentication/authentication_repo.dart @@ -22,7 +22,16 @@ abstract class AuthenticationRepo { Future>> sendActivationCodeRepo({required dynamic sendActivationCodeReq, String? languageID, bool isRegister = false, bool isFormFamilyFile = false}); Future>> checkActivationCodeRepo( - {required dynamic newRequest, required String? activationCode, required bool isRegister, bool isFormFamilyFile = false, int? patientShareRequestID, int? responseID}); + {required dynamic newRequest, + required String? activationCode, + required bool isRegister, + bool isFormFamilyFile = false, + int? patientShareRequestID, + int? responseID, + bool isSwitchUser = false, + int? patientID, + int? loginType + }); Future>> checkIfUserAgreed({required dynamic commonAuthanticatedRequest}); @@ -187,13 +196,17 @@ class AuthenticationRepoImp implements AuthenticationRepo { } @override - Future>> checkActivationCodeRepo( - {required dynamic newRequest, // could be CheckActivationCodeReq or CheckActivationCodeRegisterReq - required String? activationCode, - required bool isRegister, - bool isFormFamilyFile = false, - int? patientShareRequestID, - int? responseID}) async { + Future>> checkActivationCodeRepo({ + required dynamic newRequest, // could be CheckActivationCodeReq or CheckActivationCodeRegisterReq + required String? activationCode, + required bool isRegister, + bool isFormFamilyFile = false, + int? patientShareRequestID, + int? responseID, + bool isSwitchUser = false, + int? patientID, + int? loginType + }) async { if (isRegister) { newRequest["activationCode"] = activationCode ?? "0000"; newRequest["isSilentLogin"] = activationCode != null ? false : true; @@ -215,18 +228,21 @@ class AuthenticationRepoImp implements AuthenticationRepo { familyRequest["PatientID"] = appState.getAuthenticatedUser()!.patientId ?? 0; familyRequest["LogInTokenID"] = appState.getFamilyFileTokenID; - // // Remove unnecessary keys from familyRequest - // familyRequest.remove("MobileNo"); - // familyRequest.remove("DeviceToken"); - // familyRequest.remove("ProjectOutSA"); - // familyRequest.remove("LoginType"); - // familyRequest.remove("ZipCode"); - // familyRequest.remove("isRegister"); - // familyRequest.remove("SearchType"); - // familyRequest.remove("NationalID"); - // familyRequest.remove("IsSilentLogin"); - // familyRequest.remove("isDentalAllowedBackend"); - // familyRequest.remove("ForRegisteration"); + } + Map switchRequest = {}; + if (isSwitchUser) { + switchRequest = newRequest.toJson(); + + switchRequest['PatientID'] = responseID; + switchRequest['IsSilentLogin'] = true; + switchRequest['LogInTokenID'] = null; + switchRequest['SearchType'] = 2; + if(loginType != 0) { + switchRequest['SuperUser'] = patientID; + switchRequest['DeviceToken'] = null; + }else{ + switchRequest['LoginType'] = 2; + } } @@ -247,7 +263,9 @@ class AuthenticationRepoImp implements AuthenticationRepo { ? familyRequest : isRegister ? newRequest - : newRequest.toJson(), + : isSwitchUser + ? switchRequest + : newRequest.toJson(), onFailure: (error, statusCode, {messageStatus, failureType}) { failure = failureType; }, diff --git a/lib/features/authentication/authentication_view_model.dart b/lib/features/authentication/authentication_view_model.dart index f314cc4..1bdc09e 100644 --- a/lib/features/authentication/authentication_view_model.dart +++ b/lib/features/authentication/authentication_view_model.dart @@ -248,7 +248,7 @@ class AuthenticationViewModel extends ChangeNotifier { await selectDeviceImei(onSuccess: (dynamic respData) async { try { if (respData != null) { - dynamic data = SelectDeviceByImeiRespModelElement.fromJson(respData.toJson()); + dynamic data = await SelectDeviceByImeiRespModelElement.fromJson(respData.toJson()); _appState.setSelectDeviceByImeiRespModelElement(data); LoaderBottomSheet.hideLoader(); @@ -443,7 +443,11 @@ class AuthenticationViewModel extends ChangeNotifier { Function()? onResendActivation, bool isFormFamilyFile = false, dynamic patientShareRequestID, - dynamic responseID}) async { + dynamic responseID, + bool isSwitchUser =false, + int? patientID, + + }) async { bool isForRegister = (_appState.getUserRegistrationPayload.healthId != null || _appState.getUserRegistrationPayload.patientOutSa == true || _appState.getUserRegistrationPayload.patientOutSa == 1); final request = RequestUtils.getCommonRequestWelcome( @@ -511,7 +515,11 @@ class AuthenticationViewModel extends ChangeNotifier { isRegister: false, isFormFamilyFile: isFormFamilyFile, patientShareRequestID: patientShareRequestID, - responseID: responseID); + responseID: responseID, + isSwitchUser: isSwitchUser, + patientID: patientID, + loginType: _appState.superUserID != null ? 0 : 2, + ); resultEither.fold( (failure) async => await _errorHandlerService.handleError( @@ -554,6 +562,9 @@ class AuthenticationViewModel extends ChangeNotifier { // }); } else { if (activation.list != null && activation.list!.isNotEmpty) { + if(isSwitchUser){ + _appState.setSuperUserID = _appState.getAuthenticatedUser()?.patientId; + } _appState.setAuthenticatedUser(activation.list!.first); _appState.setPrivilegeModelList(activation.list!.first.listPrivilege!); } diff --git a/lib/features/authentication/models/resp_models/authenticated_user_resp_model.dart b/lib/features/authentication/models/resp_models/authenticated_user_resp_model.dart index 8848fde..e6a8e17 100644 --- a/lib/features/authentication/models/resp_models/authenticated_user_resp_model.dart +++ b/lib/features/authentication/models/resp_models/authenticated_user_resp_model.dart @@ -69,7 +69,7 @@ class AuthenticatedUser { dynamic authenticatedUserPatientPayType; dynamic authenticatedUserPatientType; dynamic authenticatedUserStatus; - + int? superUser; AuthenticatedUser({ this.setupId, this.patientType, @@ -139,6 +139,7 @@ class AuthenticatedUser { this.authenticatedUserPatientPayType, this.authenticatedUserPatientType, this.authenticatedUserStatus, + this.superUser }); factory AuthenticatedUser.fromRawJson(String str) => AuthenticatedUser.fromJson(json.decode(str)); @@ -214,6 +215,7 @@ class AuthenticatedUser { authenticatedUserPatientPayType: json["patientPayType"], authenticatedUserPatientType: json["patientType"], authenticatedUserStatus: json["status"], + superUser: json["superUser"], ); Map toJson() => { @@ -285,6 +287,7 @@ class AuthenticatedUser { "patientPayType": authenticatedUserPatientPayType, "patientType": authenticatedUserPatientType, "status": authenticatedUserStatus, + "superUser": superUser, }; } diff --git a/lib/features/medical_file/medical_file_repo.dart b/lib/features/medical_file/medical_file_repo.dart index 0997cbc..b90e7fb 100644 --- a/lib/features/medical_file/medical_file_repo.dart +++ b/lib/features/medical_file/medical_file_repo.dart @@ -24,7 +24,7 @@ abstract class MedicalFileRepo { Future>> getPatientMedicalReportPDF(PatientMedicalReportResponseModel patientMedicalReportResponseModel, AuthenticatedUser authenticatedUser); - Future>>> getPatientFamilyFiles(); + Future>>> getPatientFamilyFiles(int status, int patientId); Future>>> getAllPendingRecordsByResponseId({required Map request}); @@ -276,13 +276,13 @@ class MedicalFileRepoImp implements MedicalFileRepo { } @override - Future>>> getPatientFamilyFiles() async { + Future>>> getPatientFamilyFiles(int status, int patientID) async { try { GenericApiModel>? apiResponse; Failure? failure; await apiClient.post( FAMILY_FILES, - body: {"Status": 3}, + body: {"Status": status, "PatientID":patientID}, onFailure: (error, statusCode, {messageStatus, failureType}) { failure = failureType; }, diff --git a/lib/features/medical_file/medical_file_view_model.dart b/lib/features/medical_file/medical_file_view_model.dart index 59363ba..746e592 100644 --- a/lib/features/medical_file/medical_file_view_model.dart +++ b/lib/features/medical_file/medical_file_view_model.dart @@ -46,7 +46,7 @@ class MedicalFileViewModel extends ChangeNotifier { int selectedMedicalReportsTabIndex = 0; static final DialogService _dialogService = getIt.get(); AppState _appState = getIt(); - + AuthenticationViewModel authVM = getIt.get(); MedicalFileViewModel({required this.medicalFileRepo, required this.errorHandlerService}); initMedicalFileProvider() { @@ -285,7 +285,8 @@ class MedicalFileViewModel extends ChangeNotifier { } Future switchFamilyFiles({Function(dynamic)? onSuccess, Function(String)? onError}) async { - final result = await medicalFileRepo.getPatientFamilyFiles(); + // final result = await medicalFileRepo.getPatientFamilyFiles(); + final result = await medicalFileRepo.getPatientFamilyFiles(3,_appState.superUserID !=null ? _appState.superUserID! : _appState.getAuthenticatedUser()!.patientId!); result.fold( (failure) async => await errorHandlerService.handleError( @@ -306,6 +307,8 @@ class MedicalFileViewModel extends ChangeNotifier { patientName: '${_appState.getAuthenticatedUser()!.firstName!} ${_appState.getAuthenticatedUser()!.lastName!}', isActive: true, gender: _appState.getAuthenticatedUser()!.gender!, + age: _appState.getAuthenticatedUser()!.age, + mobileNumber: _appState.getAuthenticatedUser()!.mobileNumber, responseId: _appState.getAuthenticatedUser()!.patientId), ); notifyListeners(); @@ -317,7 +320,19 @@ class MedicalFileViewModel extends ChangeNotifier { ); } + Future switchFamilyFiles( {Function(dynamic)? onSuccess,int? responseID,int? patientID, String? phoneNumber, Function(String)? onError}) async { + authVM.phoneNumberController.text =phoneNumber!.startsWith("0") + ? phoneNumber.replaceFirst("0", "") + : phoneNumber; + + + + await authVM.checkActivationCode(activationCode: '0000', otpTypeEnum: OTPTypeEnum.sms, onWrongActivationCode: (String? str) {}, responseID: responseID, isFormFamilyFile:false, isSwitchUser: true, patientID: patientID, ); + + + } Future addFamilyFile({required OTPTypeEnum otpTypeEnum, required bool isExcludedUser}) async { + LoaderBottomSheet.showLoader(); AuthenticationViewModel authVM = getIt.get(); NavigationService navigationService = getIt.get(); diff --git a/lib/presentation/my_family/my_Family.dart b/lib/presentation/my_family/my_Family.dart index a4be2bf..cb49933 100644 --- a/lib/presentation/my_family/my_Family.dart +++ b/lib/presentation/my_family/my_Family.dart @@ -70,7 +70,10 @@ class _FamilyMedicalScreenState extends State { onTabChange: (int index) {}, ), SizedBox(height: 25.h), - FamilyCards(profiles: widget.profiles, onSelect: widget.onSelect, isShowDetails: true), + FamilyCards(profiles: widget.profiles, onSelect: (FamilyFileResponseModelLists profile){ + medicalVM?.switchFamilyFiles(responseID: profile.responseId, patientID: profile.patientId, phoneNumber: profile.mobileNumber); + + }, isShowDetails: true), SizedBox(height: 20.h), ], ),