|
|
|
|
@ -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';
|
|
|
|
|
@ -271,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
|
|
|
|
|
@ -282,14 +282,12 @@ class AuthenticationRepoImp implements AuthenticationRepo {
|
|
|
|
|
? ApiConsts.checkActivationCodeOthers
|
|
|
|
|
: ApiConsts.checkActivationCode;
|
|
|
|
|
|
|
|
|
|
// Store the payload in AppState
|
|
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
GenericApiModel<dynamic>? apiResponse;
|
|
|
|
|
Failure? failure;
|
|
|
|
|
|
|
|
|
|
// Determine the payload to send
|
|
|
|
|
final requestBody = isFormFamilyFile
|
|
|
|
|
var requestBody = isFormFamilyFile
|
|
|
|
|
? familyRequest
|
|
|
|
|
: isRegister
|
|
|
|
|
? newRequest
|
|
|
|
|
@ -297,32 +295,24 @@ class AuthenticationRepoImp implements AuthenticationRepo {
|
|
|
|
|
? switchRequest
|
|
|
|
|
: newRequest.toJson();
|
|
|
|
|
|
|
|
|
|
if (!isSwitchUser) {
|
|
|
|
|
print("Initial Super User Payload");
|
|
|
|
|
appState.addUserSwitchPayload(requestBody, isSuperUser: true);
|
|
|
|
|
print(requestBody);
|
|
|
|
|
} else if (isSwitchUser) {
|
|
|
|
|
// User is switching profiles
|
|
|
|
|
if (appState.getSuperUserID == responseID) {
|
|
|
|
|
// Switching back to the super user account
|
|
|
|
|
print("Switching Back to Super User");
|
|
|
|
|
appState.addUserSwitchPayload(requestBody, isSuperUser: true);
|
|
|
|
|
print(requestBody);
|
|
|
|
|
} else {
|
|
|
|
|
var superUserPaylod = appState.getUserSwitchPayloadByIndex(isSuperUser: true);
|
|
|
|
|
if (appState.getSuperUserID == null && superUserPaylod != null) {
|
|
|
|
|
if (superUserPaylod != null) {
|
|
|
|
|
// requestBody['LoginType'] = loginType;
|
|
|
|
|
// requestBody['PatientIdentificationID'] = "";
|
|
|
|
|
// requestBody['DeviceToken'] = newRequest.deviceToken;
|
|
|
|
|
// requestBody.removeWhere((key, value) => ['NationalID', 'isDentalAllowedBackend', 'ProjectOutSA', 'ForRegisteration', 'PatientID'].contains(key));
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
print("Switch to Family Where Super User Is ${appState.getSuperUserID}");
|
|
|
|
|
appState.addUserSwitchPayload(requestBody, isSuperUser: false);
|
|
|
|
|
print(requestBody);
|
|
|
|
|
} else {
|
|
|
|
|
print("Switching Into Family File Member");
|
|
|
|
|
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));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
@ -596,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;
|
|
|
|
|
|