|
|
|
|
@ -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;
|
|
|
|
|
|