Merge branch 'master' into haroon_dev

# Conflicts:
#	lib/presentation/my_family/widget/family_cards.dart
pull/212/head
haroon amjad 17 hours ago
commit 92101d2b05

Binary file not shown.

@ -175,4 +175,78 @@ class AppState {
setRatedVisible(bool value) {
isRatedVisible = value;
}
Map<String, dynamic> _userSwitchPayloads = {};
int _childSwitchCounter = 0;
Map<String, dynamic> get getUserSwitchPayloads => _userSwitchPayloads;
void addUserSwitchPayload(dynamic payload, {bool isSuperUser = false}) {
var patientID = payload is Map ? payload['patientid'] : null;
if (patientID == null) {
if (isSuperUser) {
_userSwitchPayloads['superUser'] = payload;
_childSwitchCounter = 0;
} else {
_childSwitchCounter++;
if (_childSwitchCounter == 1) {
_userSwitchPayloads['child'] = payload;
} else {
_userSwitchPayloads['child$_childSwitchCounter'] = payload;
}
}
return;
}
String? existingKey;
for (var entry in _userSwitchPayloads.entries) {
if (entry.value is Map && entry.value['PatientID'] == patientID) {
existingKey = entry.key;
break;
}
}
if (isSuperUser) {
if (existingKey != null && existingKey != 'superUser') {
_userSwitchPayloads.remove(existingKey);
}
_userSwitchPayloads['superUser'] = payload;
_childSwitchCounter = 0;
} else {
if (existingKey != null) {
_userSwitchPayloads[existingKey] = payload;
} else {
_childSwitchCounter++;
if (_childSwitchCounter == 1) {
_userSwitchPayloads['child'] = payload;
} else {
_userSwitchPayloads['child$_childSwitchCounter'] = payload;
}
}
}
}
dynamic getUserSwitchPayload({required String userType}) {
return _userSwitchPayloads[userType];
}
dynamic getUserSwitchPayloadByIndex({bool isSuperUser = false, int? childIndex}) {
if (isSuperUser) {
return _userSwitchPayloads['superUser'];
} else if (childIndex != null) {
if (childIndex == 1) {
return _userSwitchPayloads['child'];
} else {
return _userSwitchPayloads['child$childIndex'];
}
}
return null;
}
void clearUserSwitchPayloads() {
_userSwitchPayloads.clear();
_childSwitchCounter = 0;
}
}

@ -6,6 +6,7 @@ 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/common_models/generic_api_model.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/exceptions/api_failure.dart';
import 'package:hmg_patient_app_new/features/authentication/models/resp_models/select_device_by_imei.dart';
import 'package:hmg_patient_app_new/services/logger_service.dart';
@ -214,56 +215,6 @@ class AuthenticationRepoImp implements AuthenticationRepo {
int? patientID,
int? loginType}) async {
AppState appState = getIt.get<AppState>();
// if (isRegister) {
// newRequest["activationCode"] = activationCode ?? "0000";
// newRequest["isSilentLogin"] = activationCode != null ? false : true;
// } else {
// newRequest.activationCode = activationCode ?? "0000";
// newRequest.isSilentLogin = activationCode != null ? false : true;
// newRequest.projectOutSA = newRequest.zipCode == '966' ? false : true;
// newRequest.isDentalAllowedBackend = false;
// newRequest.forRegisteration = newRequest.isRegister ?? false;
// newRequest.isRegister = false;
// }
// Map<String, dynamic> familyRequest = {};
// if (isFormFamilyFile) {
// AppState appState = getIt.get<AppState>();
// familyRequest = {};
// familyRequest['PatientShareRequestID'] = patientShareRequestID;
// familyRequest['ResponseID'] = responseID;
// familyRequest['Status'] = 3;
// familyRequest["PatientID"] = appState.getAuthenticatedUser()!.patientId ?? 0;
// familyRequest["LogInTokenID"] = appState.getFamilyFileTokenID;
// familyRequest["activationCode"] = activationCode ?? "0000";
// familyRequest["PatientMobileNumber"] = newRequest.patientMobileNumber;
// familyRequest["PatientIdentificationID"] = newRequest.patientIdentificationID;
// }
// Map<String, dynamic> 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;
// }
//
// if (appState.getSuperUserID == responseID) {
// // switchRequest['LoginType'] = 3;
// switchRequest['PatientIdentificationID'] = "";
// // switchRequest['ProjectOutSA'] = newRequest.zipCode == '966' ? false : true;
// switchRequest.remove('NationalID');
// switchRequest.remove('isDentalAllowedBackend');
// switchRequest.remove('ProjectOutSA');
// switchRequest.remove('ForRegisteration');
// appState.setSuperUserID = null;
// }
// }
if (isRegister) {
newRequest["activationCode"] = activationCode ?? "0000";
@ -321,7 +272,6 @@ class AuthenticationRepoImp implements AuthenticationRepo {
}
}
// Determine which API to use based on zipCode
final zipCode = _getZipCodeFromRequest(newRequest);
final isOthersCountry = zipCode == '0';
final endpoint = isFormFamilyFile
@ -336,15 +286,40 @@ class AuthenticationRepoImp implements AuthenticationRepo {
GenericApiModel<dynamic>? apiResponse;
Failure? failure;
// Determine the payload to send
var requestBody = isFormFamilyFile
? familyRequest
: isRegister
? newRequest
: isSwitchUser
? switchRequest
: newRequest.toJson();
if (isSwitchUser) {
Map<String, dynamic> allUsersPayload;
var switchingPatientID;
var superUserPatientID;
bool isSwitchingToSuperUser = false;
allUsersPayload = appState.getUserSwitchPayloads;
switchingPatientID = switchRequest["PatientID"];
superUserPatientID = allUsersPayload['superUser']['PatientID'];
isSwitchingToSuperUser = (appState.getSuperUserID == responseID) || (allUsersPayload.containsKey('superUser') && superUserPatientID == switchingPatientID);
if (isSwitchingToSuperUser) {
var superUserPayload = appState.getUserSwitchPayloadByIndex(isSuperUser: true);
if (superUserPayload != null) {
requestBody['DeviceToken'] = newRequest.deviceToken;
requestBody['ProjectOutSA'] = 0;
requestBody['PatientIdentificationID'] = "";
requestBody.removeWhere((key, value) => ['NationalID', 'isDentalAllowedBackend', 'ForRegisteration'].contains(key));
}
}
}
await apiClient.post(
endpoint,
body: isFormFamilyFile
? familyRequest
: isRegister
? newRequest
: isSwitchUser
? switchRequest
: newRequest.toJson(),
body: requestBody,
onFailure: (error, statusCode, {messageStatus, failureType}) {
failure = failureType;
},
@ -611,7 +586,7 @@ class AuthenticationRepoImp implements AuthenticationRepo {
}
@override
Future<Either<Failure, GenericApiModel<dynamic>>> getServicePrivilege() {
Future<Either<Failure, GenericApiModel>> getServicePrivilege() {
Map<String, dynamic> mapDevice = {};
try {
GenericApiModel<dynamic>? apiResponse;

@ -403,7 +403,7 @@ class AuthenticationViewModel extends ChangeNotifier {
mobileNumber: phoneNumber,
selectedLoginType: otpTypeEnum.toInt(),
zipCode: selectedCountrySignup.countryCode,
nationalId:nationalIdOrFileNumber,
nationalId: nationalIdOrFileNumber,
isFileNo: isForRegister ? isPatientHasFile(request: payload) : false,
patientId: isFormFamilyFile ? _appState.getAuthenticatedUser()!.patientId : 0,
isForRegister: isForRegister,
@ -633,13 +633,21 @@ class AuthenticationViewModel extends ChangeNotifier {
_appState.setSuperUserID = null;
_appState.setIsChildLoggedIn = false;
activation.list!.first.isParentUser = true;
var allUsersPayload = _appState.getUserSwitchPayloads;
if ((allUsersPayload.containsKey('superUser') && allUsersPayload['superUser'] != null)) {
_appState.addUserSwitchPayload(activation.list!.first.toJson(), isSuperUser: false);
} else {
_appState.addUserSwitchPayload(activation.list!.first.toJson(), isSuperUser: true);
}
} else {
_appState.setSuperUserID = _appState.getAuthenticatedUser()?.patientId;
_appState.setIsChildLoggedIn = true;
activation.list!.first.isParentUser = false;
_appState.addUserSwitchPayload(activation.list!.first.toJson(), isSuperUser: false);
}
} else {
activation.list!.first.isParentUser = true;
_appState.addUserSwitchPayload(activation.list!.first.toJson(), isSuperUser: true);
}
activation.list!.first.bloodGroup = activation.patientBloodType;
activation.list!.first.zipCode = selectedCountrySignup == CountryEnum.others ? '0' : selectedCountrySignup.countryCode;
@ -1174,6 +1182,7 @@ class AuthenticationViewModel extends ChangeNotifier {
_appState.setVidaPlusProjectList([]);
_appState.setHMCProjectList([]);
_appState.setProjectsDetailList([]);
_appState.clearUserSwitchPayloads();
await clearDefaultInputValues();
_navigationService.pushAndReplace(AppRoutes.landingScreen);
} catch (e) {

@ -1,4 +1,5 @@
import 'dart:async';
import 'dart:convert';
import 'package:easy_localization/easy_localization.dart';
import 'package:flutter/material.dart';
@ -79,8 +80,7 @@ class _FamilyCardsState extends State<FamilyCards> {
children: [
Utils.buildSvgWithAssets(icon: AppAssets.alertSquare),
SizedBox(width: 8.h),
LocaleKeys.whoCanViewMyMedicalFile.tr(context: context).toText14(color: AppColors.textColor, isUnderLine: true, isBold: true)
.onPress(() {
LocaleKeys.whoCanViewMyMedicalFile.tr(context: context).toText14(color: AppColors.textColor, isUnderLine: true, isBold: true).onPress(() {
dialogService.showFamilyBottomSheetWithoutHWithChild(
label: LocaleKeys.manageFiles.tr(context: context),
message: "",
@ -136,18 +136,13 @@ class _FamilyCardsState extends State<FamilyCards> {
? AppColors.textGreenColor
: AppColors.alertColor),
SizedBox(height: 8.h),
Wrap(
alignment: WrapAlignment.start,
crossAxisAlignment: WrapCrossAlignment.start,
runAlignment: WrapAlignment.start,
spacing: 0.h,
children: [
(profile.patientName ?? "").toText14(isBold: true, isCenter: false, maxlines: 1),
Wrap(alignment: WrapAlignment.start, crossAxisAlignment: WrapCrossAlignment.start, runAlignment: WrapAlignment.start, spacing: 0.h, children: [
(profile.patientName ?? "").toText14(isBold: true, isCenter: false, maxlines: 1),
(getStatusTextByRequest(
FamilyFileEnum.values.firstWhere((e) => e.toInt == profile.status), profile.isRequestFromMySide ?? false))
.toText12(
isCenter: false, maxLine: 1, isBold: true, color: AppColors.greyTextColor),
]),
]),
SizedBox(height: 8.h),
CustomChipWidget(
height: 30.h,
@ -319,7 +314,11 @@ class _FamilyCardsState extends State<FamilyCards> {
final profile = widget.profileViewList![index];
final isActive = (profile.responseId == appState.getAuthenticatedUser()?.patientId);
final isParentUser = appState.getAuthenticatedUser()?.isParentUser ?? false;
final canSwitch = isParentUser || (!isParentUser && profile.responseId == appState.getSuperUserID);
print(jsonEncode(appState.getUserSwitchPayloads));
final isSuperUser = appState.getUserSwitchPayloads;
// TODO: canSwitch functionality is currently disabled - set to true to allow all switches
// Original logic: final canSwitch = isParentUser || (!isParentUser && profile.responseId == appState.getSuperUserID);
final canSwitch = true; // Disabled - allows all users to switch
return Container(
padding: EdgeInsets.symmetric(vertical: 15.h, horizontal: 15.h),
decoration: RoundedRectangleBorder().toSmoothCornerDecoration(color: AppColors.whiteColor, borderRadius: 24.r),
@ -470,10 +469,10 @@ class _FamilyCardsState extends State<FamilyCards> {
alignment: WrapAlignment.start,
children: [
(profile.patientName ?? "").toText14(isBold: true, isCenter: true, maxlines: 1),
SizedBox(width: 2.w,),
(getStatusTextByRequest(
FamilyFileEnum.values.firstWhere((e) => e.toInt == profile.status), profile.isRequestFromMySide ?? false))
.toText14(
SizedBox(
width: 2.w,
),
(getStatusTextByRequest(FamilyFileEnum.values.firstWhere((e) => e.toInt == profile.status), profile.isRequestFromMySide ?? false)).toText14(
isBold: false,
isCenter: true,
maxlines: 1,

Loading…
Cancel
Save