Merge remote-tracking branch 'origin/master' into maptype

maptype
Sultan khan 1 day ago
commit b3fa4c9bdf

Binary file not shown.

@ -175,4 +175,78 @@ class AppState {
setRatedVisible(bool value) { setRatedVisible(bool value) {
isRatedVisible = 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/app_state.dart';
import 'package:hmg_patient_app_new/core/common_models/generic_api_model.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/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/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/features/authentication/models/resp_models/select_device_by_imei.dart';
import 'package:hmg_patient_app_new/services/logger_service.dart'; import 'package:hmg_patient_app_new/services/logger_service.dart';
@ -214,56 +215,6 @@ class AuthenticationRepoImp implements AuthenticationRepo {
int? patientID, int? patientID,
int? loginType}) async { int? loginType}) async {
AppState appState = getIt.get<AppState>(); 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) { if (isRegister) {
newRequest["activationCode"] = activationCode ?? "0000"; 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 zipCode = _getZipCodeFromRequest(newRequest);
final isOthersCountry = zipCode == '0'; final isOthersCountry = zipCode == '0';
final endpoint = isFormFamilyFile final endpoint = isFormFamilyFile
@ -336,15 +286,40 @@ class AuthenticationRepoImp implements AuthenticationRepo {
GenericApiModel<dynamic>? apiResponse; GenericApiModel<dynamic>? apiResponse;
Failure? failure; Failure? failure;
await apiClient.post( // Determine the payload to send
endpoint, var requestBody = isFormFamilyFile
body: isFormFamilyFile
? familyRequest ? familyRequest
: isRegister : isRegister
? newRequest ? newRequest
: isSwitchUser : isSwitchUser
? switchRequest ? switchRequest
: newRequest.toJson(), : 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: requestBody,
onFailure: (error, statusCode, {messageStatus, failureType}) { onFailure: (error, statusCode, {messageStatus, failureType}) {
failure = failureType; failure = failureType;
}, },
@ -611,7 +586,7 @@ class AuthenticationRepoImp implements AuthenticationRepo {
} }
@override @override
Future<Either<Failure, GenericApiModel<dynamic>>> getServicePrivilege() { Future<Either<Failure, GenericApiModel>> getServicePrivilege() {
Map<String, dynamic> mapDevice = {}; Map<String, dynamic> mapDevice = {};
try { try {
GenericApiModel<dynamic>? apiResponse; GenericApiModel<dynamic>? apiResponse;

@ -385,7 +385,7 @@ class AuthenticationViewModel extends ChangeNotifier {
mobileNumber: phoneNumber, mobileNumber: phoneNumber,
selectedLoginType: otpTypeEnum.toInt(), selectedLoginType: otpTypeEnum.toInt(),
zipCode: selectedCountrySignup.countryCode, zipCode: selectedCountrySignup.countryCode,
nationalId:nationalIdOrFileNumber, nationalId: nationalIdOrFileNumber,
isFileNo: isForRegister ? isPatientHasFile(request: payload) : false, isFileNo: isForRegister ? isPatientHasFile(request: payload) : false,
patientId: isFormFamilyFile ? _appState.getAuthenticatedUser()!.patientId : 0, patientId: isFormFamilyFile ? _appState.getAuthenticatedUser()!.patientId : 0,
isForRegister: isForRegister, isForRegister: isForRegister,
@ -615,13 +615,21 @@ class AuthenticationViewModel extends ChangeNotifier {
_appState.setSuperUserID = null; _appState.setSuperUserID = null;
_appState.setIsChildLoggedIn = false; _appState.setIsChildLoggedIn = false;
activation.list!.first.isParentUser = true; 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 { } else {
_appState.setSuperUserID = _appState.getAuthenticatedUser()?.patientId; _appState.setSuperUserID = _appState.getAuthenticatedUser()?.patientId;
_appState.setIsChildLoggedIn = true; _appState.setIsChildLoggedIn = true;
activation.list!.first.isParentUser = false; activation.list!.first.isParentUser = false;
_appState.addUserSwitchPayload(activation.list!.first.toJson(), isSuperUser: false);
} }
} else { } else {
activation.list!.first.isParentUser = true; activation.list!.first.isParentUser = true;
_appState.addUserSwitchPayload(activation.list!.first.toJson(), isSuperUser: true);
} }
activation.list!.first.bloodGroup = activation.patientBloodType; activation.list!.first.bloodGroup = activation.patientBloodType;
activation.list!.first.zipCode = selectedCountrySignup == CountryEnum.others ? '0' : selectedCountrySignup.countryCode; activation.list!.first.zipCode = selectedCountrySignup == CountryEnum.others ? '0' : selectedCountrySignup.countryCode;
@ -1152,6 +1160,7 @@ class AuthenticationViewModel extends ChangeNotifier {
_appState.setVidaPlusProjectList([]); _appState.setVidaPlusProjectList([]);
_appState.setHMCProjectList([]); _appState.setHMCProjectList([]);
_appState.setProjectsDetailList([]); _appState.setProjectsDetailList([]);
_appState.clearUserSwitchPayloads();
await clearDefaultInputValues(); await clearDefaultInputValues();
_navigationService.pushAndReplace(AppRoutes.landingScreen); _navigationService.pushAndReplace(AppRoutes.landingScreen);
} catch (e) { } catch (e) {

@ -1,4 +1,5 @@
import 'dart:async'; import 'dart:async';
import 'dart:convert';
import 'package:easy_localization/easy_localization.dart'; import 'package:easy_localization/easy_localization.dart';
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
@ -79,8 +80,7 @@ class _FamilyCardsState extends State<FamilyCards> {
children: [ children: [
Utils.buildSvgWithAssets(icon: AppAssets.alertSquare), Utils.buildSvgWithAssets(icon: AppAssets.alertSquare),
SizedBox(width: 8.h), SizedBox(width: 8.h),
LocaleKeys.whoCanViewMyMedicalFile.tr(context: context).toText14(color: AppColors.textColor, isUnderLine: true, weight: FontWeight.w500) LocaleKeys.whoCanViewMyMedicalFile.tr(context: context).toText14(color: AppColors.textColor, isUnderLine: true, weight: FontWeight.w500).onPress(() {
.onPress(() {
dialogService.showFamilyBottomSheetWithoutHWithChild( dialogService.showFamilyBottomSheetWithoutHWithChild(
label: LocaleKeys.manageFiles.tr(context: context), label: LocaleKeys.manageFiles.tr(context: context),
message: "", message: "",
@ -136,17 +136,10 @@ class _FamilyCardsState extends State<FamilyCards> {
? AppColors.textGreenColor ? AppColors.textGreenColor
: AppColors.alertColor), : AppColors.alertColor),
SizedBox(height: 8.h), SizedBox(height: 8.h),
Wrap( Wrap(alignment: WrapAlignment.start, crossAxisAlignment: WrapCrossAlignment.start, runAlignment: WrapAlignment.start, spacing: 0.h, children: [
alignment: WrapAlignment.start,
crossAxisAlignment: WrapCrossAlignment.start,
runAlignment: WrapAlignment.start,
spacing: 0.h,
children: [
(profile.patientName ?? "").toText14(isBold: false, isCenter: false, maxlines: 1, weight: FontWeight.w600), (profile.patientName ?? "").toText14(isBold: false, isCenter: false, maxlines: 1, weight: FontWeight.w600),
(getStatusTextByRequest( (getStatusTextByRequest(FamilyFileEnum.values.firstWhere((e) => e.toInt == profile.status), profile.isRequestFromMySide ?? false))
FamilyFileEnum.values.firstWhere((e) => e.toInt == profile.status), profile.isRequestFromMySide ?? false)) .toText12(isBold: false, isCenter: false, maxLine: 1, fontWeight: FontWeight.w500, color: AppColors.greyTextColor),
.toText12(
isBold: false, isCenter: false, maxLine: 1, fontWeight: FontWeight.w500, color: AppColors.greyTextColor),
]), ]),
SizedBox(height: 8.h), SizedBox(height: 8.h),
CustomChipWidget( CustomChipWidget(
@ -318,7 +311,11 @@ class _FamilyCardsState extends State<FamilyCards> {
final profile = widget.profileViewList![index]; final profile = widget.profileViewList![index];
final isActive = (profile.responseId == appState.getAuthenticatedUser()?.patientId); final isActive = (profile.responseId == appState.getAuthenticatedUser()?.patientId);
final isParentUser = appState.getAuthenticatedUser()?.isParentUser ?? false; 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( return Container(
padding: EdgeInsets.symmetric(vertical: 15.h, horizontal: 15.h), padding: EdgeInsets.symmetric(vertical: 15.h, horizontal: 15.h),
decoration: RoundedRectangleBorder().toSmoothCornerDecoration(color: AppColors.whiteColor, borderRadius: 24.r), decoration: RoundedRectangleBorder().toSmoothCornerDecoration(color: AppColors.whiteColor, borderRadius: 24.r),
@ -469,10 +466,10 @@ class _FamilyCardsState extends State<FamilyCards> {
alignment: WrapAlignment.start, alignment: WrapAlignment.start,
children: [ children: [
(profile.patientName ?? "").toText14(isBold: false, isCenter: true, maxlines: 1, weight: FontWeight.w600), (profile.patientName ?? "").toText14(isBold: false, isCenter: true, maxlines: 1, weight: FontWeight.w600),
SizedBox(width: 2.w,), SizedBox(
(getStatusTextByRequest( width: 2.w,
FamilyFileEnum.values.firstWhere((e) => e.toInt == profile.status), profile.isRequestFromMySide ?? false)) ),
.toText14( (getStatusTextByRequest(FamilyFileEnum.values.firstWhere((e) => e.toInt == profile.status), profile.isRequestFromMySide ?? false)).toText14(
isBold: false, isBold: false,
isCenter: true, isCenter: true,
maxlines: 1, maxlines: 1,

Loading…
Cancel
Save