diff --git a/lib/core/api_consts.dart b/lib/core/api_consts.dart index a034570..daa094e 100644 --- a/lib/core/api_consts.dart +++ b/lib/core/api_consts.dart @@ -803,6 +803,7 @@ class ApiConsts { static final String insertPatientDeviceIMEIData = 'Services/Patients.svc/REST/Patient_INSERTDeviceIMEI'; static final String insertPatientMobileData = 'Services/MobileNotifications.svc/REST/Insert_PatientMobileDeviceInfo'; + static final String getPrivileges = 'Services/Patients.svc/REST/Service_Privilege'; // static values for Api static final double appVersionID = 18.7; diff --git a/lib/core/app_state.dart b/lib/core/app_state.dart index 4ab98f6..3c4555e 100644 --- a/lib/core/app_state.dart +++ b/lib/core/app_state.dart @@ -1,7 +1,10 @@ import 'dart:io'; import 'package:easy_localization/easy_localization.dart'; -import 'package:hmg_patient_app_new/core/common_models/VidaPlusProjectListModel.dart'; +import 'package:hmg_patient_app_new/core/common_models/privilege/HMCProjectListModel.dart'; +import 'package:hmg_patient_app_new/core/common_models/privilege/PrivilegeModel.dart'; +import 'package:hmg_patient_app_new/core/common_models/privilege/ProjectDetailListModel.dart'; +import 'package:hmg_patient_app_new/core/common_models/privilege/VidaPlusProjectListModel.dart'; import 'package:hmg_patient_app_new/features/authentication/models/resp_models/authenticated_user_resp_model.dart'; import 'package:hmg_patient_app_new/features/authentication/models/resp_models/check_user_staus_nhic_response_model.dart'; import 'package:hmg_patient_app_new/features/authentication/models/resp_models/select_device_by_imei.dart'; @@ -37,7 +40,7 @@ class AppState { if (isFamily) { _authenticatedChildUser = authenticatedUser; } else { - setIsAuthenticated = true; + setIsAuthenticated = true; _authenticatedRootUser = authenticatedUser; } } @@ -93,11 +96,26 @@ class AppState { set setDeviceTypeID(v) => deviceTypeID = v; List vidaPlusProjectList = []; + List privilegeModelList = []; + List hMCProjectListModel = []; + List projectDetailListModel = []; setVidaPlusProjectList(List vidaPlusProjectListModelInput) { vidaPlusProjectList = vidaPlusProjectListModelInput; } + setPrivilegeModelList(List privilegeModelListInput) { + privilegeModelList = privilegeModelListInput; + } + + setHMCProjectList(List hMCProjectListModelInput) { + hMCProjectListModel = hMCProjectListModelInput; + } + + setProjectsDetailList(List projectDetailListModelInput) { + projectDetailListModel = projectDetailListModelInput; + } + CheckUserStatusResponseNHIC? _nHICUserData; CheckUserStatusResponseNHIC get getNHICUserData => _nHICUserData!; @@ -106,7 +124,6 @@ class AppState { _nHICUserData = value; } - RegistrationDataModelPayload? _userRegistrationPayload; RegistrationDataModelPayload get getUserRegistrationPayload => _userRegistrationPayload ?? RegistrationDataModelPayload(); diff --git a/lib/core/common_models/privilege/HMCProjectListModel.dart b/lib/core/common_models/privilege/HMCProjectListModel.dart new file mode 100644 index 0000000..6af7bfb --- /dev/null +++ b/lib/core/common_models/privilege/HMCProjectListModel.dart @@ -0,0 +1,15 @@ +class HMCProjectListModel { + int? projectID; + + HMCProjectListModel({this.projectID}); + + HMCProjectListModel.fromJson(Map json) { + projectID = json['ProjectID']; + } + + Map toJson() { + final Map data = new Map(); + data['ProjectID'] = this.projectID; + return data; + } +} diff --git a/lib/core/common_models/privilege/PrivilegeModel.dart b/lib/core/common_models/privilege/PrivilegeModel.dart new file mode 100644 index 0000000..587490b --- /dev/null +++ b/lib/core/common_models/privilege/PrivilegeModel.dart @@ -0,0 +1,24 @@ +class PrivilegeModel { + int? iD; + String? serviceName; + bool? privilege; + dynamic region; + + PrivilegeModel({this.iD, this.serviceName, this.privilege, this.region}); + + PrivilegeModel.fromJson(Map json) { + iD = json['ID']; + serviceName = json['ServiceName']; + privilege = json['Previlege']; + region = json['Region']; + } + + Map toJson() { + final Map data = new Map(); + data['ID'] = this.iD; + data['ServiceName'] = this.serviceName; + data['Previlege'] = this.privilege; + data['Region'] = this.region; + return data; + } +} diff --git a/lib/core/common_models/privilege/ProjectDetailListModel.dart b/lib/core/common_models/privilege/ProjectDetailListModel.dart new file mode 100644 index 0000000..782c376 --- /dev/null +++ b/lib/core/common_models/privilege/ProjectDetailListModel.dart @@ -0,0 +1,32 @@ +class ProjectDetailListModel { + int? projectID; + String? latitude; + String? longitude; + int? geofenceRadius; + String? checkInQrCode; + + ProjectDetailListModel( + {this.projectID, + this.latitude, + this.longitude, + this.geofenceRadius, + this.checkInQrCode}); + + ProjectDetailListModel.fromJson(Map json) { + projectID = json['ProjectID']; + latitude = json['Latitude']; + longitude = json['Longitude']; + geofenceRadius = json['GeofenceRadius']; + checkInQrCode = json['CheckInQrCode']; + } + + Map toJson() { + final Map data = new Map(); + data['ProjectID'] = this.projectID; + data['Latitude'] = this.latitude; + data['Longitude'] = this.longitude; + data['GeofenceRadius'] = this.geofenceRadius; + data['CheckInQrCode'] = this.checkInQrCode; + return data; + } +} diff --git a/lib/core/common_models/VidaPlusProjectListModel.dart b/lib/core/common_models/privilege/VidaPlusProjectListModel.dart similarity index 100% rename from lib/core/common_models/VidaPlusProjectListModel.dart rename to lib/core/common_models/privilege/VidaPlusProjectListModel.dart diff --git a/lib/core/utils/request_utils.dart b/lib/core/utils/request_utils.dart index 1bf1e06..f54432c 100644 --- a/lib/core/utils/request_utils.dart +++ b/lib/core/utils/request_utils.dart @@ -20,6 +20,9 @@ class RequestUtils { bool fileNo = false; if (nationId.isNotEmpty) { fileNo = nationId.length < 10; + if (fileNo) { + patientId = int.tryParse(nationId); + } } var request = SendActivationRequest(); if (phoneNumber.isNotEmpty) { @@ -51,18 +54,17 @@ class RequestUtils { return request; } - static dynamic getCommonRequestWelcome({ - required String phoneNumber, - required OTPTypeEnum otpTypeEnum, - required String? deviceToken, - required bool patientOutSA, - required String? loginTokenID, - required var registeredData, - int? patientId, - required String nationIdText, - required String countryCode, - required int loginType - }) { + static dynamic getCommonRequestWelcome( + {required String phoneNumber, + required OTPTypeEnum otpTypeEnum, + required String? deviceToken, + required bool patientOutSA, + required String? loginTokenID, + required var registeredData, + int? patientId, + required String nationIdText, + required String countryCode, + required int loginType}) { bool fileNo = false; if (nationIdText.isNotEmpty) { fileNo = nationIdText.length < 10; @@ -86,7 +88,7 @@ class RequestUtils { } else { if (fileNo) { request.patientID = patientId ?? int.parse(nationIdText); - request.patientIdentificationID = request.nationalID = "" as int?; + request.patientIdentificationID = request.nationalID = 0; request.searchType = 2; } else { request.patientID = 0; diff --git a/lib/core/utils/utils.dart b/lib/core/utils/utils.dart index 216da22..ebb7037 100644 --- a/lib/core/utils/utils.dart +++ b/lib/core/utils/utils.dart @@ -10,6 +10,7 @@ import 'package:fluttertoast/fluttertoast.dart'; import 'package:google_api_availability/google_api_availability.dart'; import 'package:hmg_patient_app_new/core/app_assets.dart'; import 'package:hmg_patient_app_new/core/app_state.dart'; +import 'package:hmg_patient_app_new/core/common_models/privilege/ProjectDetailListModel.dart'; import 'package:hmg_patient_app_new/core/dependencies.dart'; import 'package:hmg_patient_app_new/core/utils/size_utils.dart'; import 'package:hmg_patient_app_new/extensions/string_extensions.dart'; @@ -22,6 +23,8 @@ import 'package:hmg_patient_app_new/widgets/loading_dialog.dart'; import 'package:lottie/lottie.dart'; import 'package:shared_preferences/shared_preferences.dart'; +import 'dart:math' as dartMath; + class Utils { static AppState appState = getIt.get(); static NavigationService navigationService = getIt.get(); @@ -346,6 +349,34 @@ class Utils { return isVidaPlus; } + static ProjectDetailListModel getProjectDetailObj(AppState appState, int projectID) { + ProjectDetailListModel projectDetailListModel = ProjectDetailListModel(); + for (var element in appState.projectDetailListModel) { + if (element.projectID == projectID) { + projectDetailListModel = element; + } + } + return projectDetailListModel; + } + + static double distance(double lat1, double lon1, double lat2, double lon2) { + const r = 6372.8; // Earth radius in kilometers + + final dLat = _toRadians(lat2 - lat1); + final dLon = _toRadians(lon2 - lon1); + final lat1Radians = _toRadians(lat1); + final lat2Radians = _toRadians(lat2); + + final a = _haversin(dLat) + dartMath.cos(lat1Radians) * dartMath.cos(lat2Radians) * _haversin(dLon); + final c = 2 * dartMath.asin(dartMath.sqrt(a)); + + return r * c; + } + + static double _toRadians(double degrees) => degrees * dartMath.pi / 180; + + static num _haversin(double radians) => dartMath.pow(dartMath.sin(radians / 2), 2); + static getPhoneNumberWithoutZero(String number) { String newNumber = ""; if (number.startsWith('0')) { diff --git a/lib/features/authentication/authentication_repo.dart b/lib/features/authentication/authentication_repo.dart index e64e4ba..d81094c 100644 --- a/lib/features/authentication/authentication_repo.dart +++ b/lib/features/authentication/authentication_repo.dart @@ -4,12 +4,15 @@ import 'package:dartz/dartz.dart'; import 'package:hmg_patient_app_new/core/api/api_client.dart'; import 'package:hmg_patient_app_new/core/api_consts.dart'; import 'package:hmg_patient_app_new/core/common_models/generic_api_model.dart'; +import 'package:hmg_patient_app_new/core/common_models/privilege/PrivilegeModel.dart'; import 'package:hmg_patient_app_new/core/exceptions/api_failure.dart'; import 'package:hmg_patient_app_new/features/authentication/models/request_models/check_activation_code_register_request_model.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'; abstract class AuthenticationRepo { + Future>> getServicePrivilege(); + Future>> selectDeviceByImei({required String firebaseToken}); Future>> checkPatientAuthentication({required dynamic checkPatientAuthenticationReq}); @@ -32,7 +35,6 @@ abstract class AuthenticationRepo { Future>> insertPatientIMEIData({required dynamic patientIMEIDataRequest}); Future>> insertPatientDeviceData({required dynamic patientDeviceDataRequest}); - } class AuthenticationRepoImp implements AuthenticationRepo { @@ -390,7 +392,6 @@ class AuthenticationRepoImp implements AuthenticationRepo { @override Future> insertPatientDeviceData({required patientDeviceDataRequest}) { - try { GenericApiModel? apiResponse; Failure? failure; @@ -421,4 +422,38 @@ class AuthenticationRepoImp implements AuthenticationRepo { return Future.value(Left(UnknownFailure(e.toString()))); } } + + @override + Future>> getServicePrivilege() { + Map mapDevice = {}; + try { + GenericApiModel? apiResponse; + Failure? failure; + return apiClient.post( + ApiConsts.getPrivileges, + body: mapDevice, + onFailure: (error, statusCode, {messageStatus, failureType}) { + failure = failureType; + }, + onSuccess: (response, statusCode, {messageStatus, errorMessage}) { + try { + apiResponse = GenericApiModel( + messageStatus: messageStatus, + statusCode: statusCode, + errorMessage: errorMessage, + data: response, + ); + } catch (e) { + failure = DataParsingFailure(e.toString()); + } + }, + ).then((_) { + if (failure != null) return Left(failure!); + if (apiResponse == null) return Left(ServerFailure("Unknown error")); + return Right(apiResponse!); + }); + } catch (e) { + return Future.value(Left(UnknownFailure(e.toString()))); + } + } } diff --git a/lib/features/authentication/authentication_view_model.dart b/lib/features/authentication/authentication_view_model.dart index 0797c6d..0add5a0 100644 --- a/lib/features/authentication/authentication_view_model.dart +++ b/lib/features/authentication/authentication_view_model.dart @@ -6,6 +6,10 @@ import 'package:hijri_gregorian_calendar/hijri_gregorian_calendar.dart'; import 'package:hmg_patient_app_new/core/app_state.dart'; import 'package:hmg_patient_app_new/core/cache_consts.dart'; import 'package:hmg_patient_app_new/core/common_models/nationality_country_model.dart'; +import 'package:hmg_patient_app_new/core/common_models/privilege/HMCProjectListModel.dart'; +import 'package:hmg_patient_app_new/core/common_models/privilege/PrivilegeModel.dart'; +import 'package:hmg_patient_app_new/core/common_models/privilege/ProjectDetailListModel.dart'; +import 'package:hmg_patient_app_new/core/common_models/privilege/VidaPlusProjectListModel.dart'; import 'package:hmg_patient_app_new/core/enums.dart'; import 'package:hmg_patient_app_new/core/utils/loading_utils.dart'; import 'package:hmg_patient_app_new/core/utils/request_utils.dart'; @@ -53,7 +57,11 @@ class AuthenticationViewModel extends ChangeNotifier { _authenticationRepo = authenticationRepo, _localAuthService = localAuthService; - final TextEditingController nationalIdController = TextEditingController(), phoneNumberController = TextEditingController(), dobController = TextEditingController(), nameController = TextEditingController(), emailController = TextEditingController(); + final TextEditingController nationalIdController = TextEditingController(), + phoneNumberController = TextEditingController(), + dobController = TextEditingController(), + nameController = TextEditingController(), + emailController = TextEditingController(); CountryEnum selectedCountrySignup = CountryEnum.saudiArabia; MaritalStatusTypeEnum? maritalStatus; GenderTypeEnum? genderType; @@ -366,18 +374,18 @@ class AuthenticationViewModel extends ChangeNotifier { required Function(String? message) onWrongActivationCode, }) async { final request = RequestUtils.getCommonRequestWelcome( - phoneNumber: phoneNumberController.text, - otpTypeEnum: otpTypeEnum, - deviceToken: _appState.deviceToken, - patientOutSA: true, - loginTokenID: _appState.appAuthToken, - registeredData: null, - nationIdText: nationalIdController.text, - countryCode: selectedCountrySignup.countryCode, - loginType: loginTypeEnum.toInt - ).toJson(); - - bool isForRegister = (_appState.getUserRegistrationPayload.healthId != null || _appState.getUserRegistrationPayload.patientOutSa == true); + phoneNumber: phoneNumberController.text, + otpTypeEnum: otpTypeEnum, + deviceToken: _appState.deviceToken, + patientOutSA: true, + loginTokenID: _appState.appAuthToken, + registeredData: null, + nationIdText: nationalIdController.text, + countryCode: selectedCountrySignup.countryCode, + loginType: loginTypeEnum.toInt) + .toJson(); + + bool isForRegister = (_appState.getUserRegistrationPayload.healthId != null || _appState.getUserRegistrationPayload.patientOutSa == true); if (isForRegister) { if (_appState.getUserRegistrationPayload.patientOutSa == true) request['DOB'] = _appState.getUserRegistrationPayload.dob; request['HealthId'] = _appState.getUserRegistrationPayload.healthId; @@ -514,12 +522,12 @@ class AuthenticationViewModel extends ChangeNotifier { _localAuthService.authenticate().then((value) async { if (value) { // we have to handle this if verification true; - if(!_appState.isAuthenticated) { + if (!_appState.isAuthenticated) { loginTypeEnum = (_appState.deviceTypeID == 1 ? LoginTypeEnum.face : LoginTypeEnum.fingerprint); print(loginTypeEnum); - checkActivationCode(otpTypeEnum:OTPTypeEnum.faceIDFingerprint , activationCode: null, onWrongActivationCode: (String? message) {}); + checkActivationCode(otpTypeEnum: OTPTypeEnum.faceIDFingerprint, activationCode: null, onWrongActivationCode: (String? message) {}); insertPatientIMEIData((_appState.deviceTypeID == 1 ? LoginTypeEnum.face.toInt : LoginTypeEnum.fingerprint.toInt)); - }else { + } else { // authenticated = true; insertPatientIMEIData((_appState.deviceTypeID == 1 ? LoginTypeEnum.face.toInt : LoginTypeEnum.fingerprint.toInt)); } @@ -535,20 +543,19 @@ class AuthenticationViewModel extends ChangeNotifier { checkLastLoginStatus(Function() onSuccess) async { Future.delayed(Duration(seconds: 1), () { - if (_appState.getSelectDeviceByImeiRespModelElement != null && - (_appState.getSelectDeviceByImeiRespModelElement!.logInType == 1 || _appState.getSelectDeviceByImeiRespModelElement!.logInType == 4)) { - phoneNumberController.text = (_appState.getAuthenticatedUser()!.mobileNumber!.startsWith("0") - ? _appState.getAuthenticatedUser()!.mobileNumber!.replaceFirst("0", "") - : _appState.getAuthenticatedUser()!.mobileNumber)!; + if (_appState.getSelectDeviceByImeiRespModelElement != null && + (_appState.getSelectDeviceByImeiRespModelElement!.logInType == 1 || _appState.getSelectDeviceByImeiRespModelElement!.logInType == 4)) { + phoneNumberController.text = + (_appState.getAuthenticatedUser()!.mobileNumber!.startsWith("0") ? _appState.getAuthenticatedUser()!.mobileNumber!.replaceFirst("0", "") : _appState.getAuthenticatedUser()!.mobileNumber)!; nationalIdController.text = _appState.getAuthenticatedUser()!.nationalityId!; onSuccess(); - } else if((loginTypeEnum == LoginTypeEnum.sms || loginTypeEnum == LoginTypeEnum.whatsapp && _appState.getSelectDeviceByImeiRespModelElement == null) && _appState.getAuthenticatedUser() != null){ - phoneNumberController.text = (_appState.getAuthenticatedUser()!.mobileNumber!.startsWith("0") - ? _appState.getAuthenticatedUser()!.mobileNumber!.replaceFirst("0", "") - : _appState.getAuthenticatedUser()!.mobileNumber)!; - nationalIdController.text = _appState.getAuthenticatedUser()!.nationalityId!; - onSuccess(); - } + } else if ((loginTypeEnum == LoginTypeEnum.sms || loginTypeEnum == LoginTypeEnum.whatsapp && _appState.getSelectDeviceByImeiRespModelElement == null) && + _appState.getAuthenticatedUser() != null) { + phoneNumberController.text = + (_appState.getAuthenticatedUser()!.mobileNumber!.startsWith("0") ? _appState.getAuthenticatedUser()!.mobileNumber!.replaceFirst("0", "") : _appState.getAuthenticatedUser()!.mobileNumber)!; + nationalIdController.text = _appState.getAuthenticatedUser()!.nationalityId!; + onSuccess(); + } }); } @@ -583,9 +590,7 @@ class AuthenticationViewModel extends ChangeNotifier { }); } - - Future onRegistrationComplete() async{ - + Future onRegistrationComplete() async { // if (emailAddress.text.isEmpty) { // Utils.showErrorToast(TranslationBase.of(context).enterEmailAddress); // return; @@ -596,7 +601,6 @@ class AuthenticationViewModel extends ChangeNotifier { //authVM!.clearDefaultInputValues(); } - Future checkUserStatusForRegistration({required dynamic response, required dynamic request}) async { if (response is Map) { _appState.setAppAuthToken = response["LogInTokenID"]; @@ -703,22 +707,52 @@ class AuthenticationViewModel extends ChangeNotifier { _appState.setUserRegistrationPayload = RegistrationDataModelPayload.fromJson(request); } - Future insertPatientIMEIData(int loginType) async{ - - final resultEither = await _authenticationRepo.insertPatientIMEIData(patientIMEIDataRequest: PatientInsertDeviceImei(imei: _appState.deviceToken, deviceTypeId: _appState.getDeviceTypeID(), patientId: _appState.getAuthenticatedUser()!.patientId!, patientIdentificationNo:_appState.getAuthenticatedUser()!.nationalityId!, firstName: _appState.getAuthenticatedUser()!.firstName!, lastName: _appState.getAuthenticatedUser()!.lastName!, patientTypeId: _appState.getAuthenticatedUser()!.patientType, mobileNo:_appState.getAuthenticatedUser()!.mobileNumber!, logInTypeId: loginType, patientOutSa:_appState.getAuthenticatedUser()!.outSa!, outSa: _appState.getAuthenticatedUser()!.outSa == 1 ? true :false, biometricEnabled: loginType == 1 || loginType ==2 ? false :true, firstNameN:_appState.getAuthenticatedUser()!.firstNameN , lastNameN:_appState.getAuthenticatedUser()!.lastNameN ).toJson()); - resultEither.fold((failure) async => await _errorHandlerService.handleError(failure: failure), (apiResponse) async { - if (apiResponse.messageStatus == 1) { - log("Insert IMEI Success"); - insertPatientDeviceData( loginType); - } else { - log("Insert IMEI Failed"); - } - }); - - } - Future insertPatientDeviceData(int loginType) async{ + Future insertPatientIMEIData(int loginType) async { + final resultEither = await _authenticationRepo.insertPatientIMEIData( + patientIMEIDataRequest: PatientInsertDeviceImei( + imei: _appState.deviceToken, + deviceTypeId: _appState.getDeviceTypeID(), + patientId: _appState.getAuthenticatedUser()!.patientId!, + patientIdentificationNo: _appState.getAuthenticatedUser()!.patientIdentificationNo!, + firstName: _appState.getAuthenticatedUser()!.firstName!, + lastName: _appState.getAuthenticatedUser()!.lastName!, + patientTypeId: _appState.getAuthenticatedUser()!.patientType, + mobileNo: _appState.getAuthenticatedUser()!.mobileNumber!, + logInTypeId: loginType, + patientOutSa: _appState.getAuthenticatedUser()!.outSa!, + outSa: _appState.getAuthenticatedUser()!.outSa == 1 ? true : false, + biometricEnabled: loginType == 1 || loginType == 2 ? false : true, + firstNameN: _appState.getAuthenticatedUser()!.firstNameN, + lastNameN: _appState.getAuthenticatedUser()!.lastNameN, + ).toJson()); + resultEither.fold((failure) async => await _errorHandlerService.handleError(failure: failure), (apiResponse) async { + if (apiResponse.messageStatus == 1) { + log("Insert IMEI Success"); + insertPatientDeviceData(loginType); + } else { + log("Insert IMEI Failed"); + } + }); + } - final resultEither = await _authenticationRepo.insertPatientDeviceData(patientDeviceDataRequest: InsertPatientMobileDeviceInfo(deviceToken: _appState.deviceToken, deviceTypeId: _appState.getDeviceTypeID(), patientId: _appState.getAuthenticatedUser()!.patientId!, patientTypeId: _appState.getAuthenticatedUser()!.patientType, patientOutSa:_appState.getAuthenticatedUser()!.outSa!, loginType: loginType, languageId: _appState.getLanguageID(), latitude: _appState.userLat, longitude:_appState.userLong, voipToken: "", deviceType: _appState.deviceTypeID, patientMobileNumber:_appState.getAuthenticatedUser()!.mobileNumber, nationalId: _appState.getAuthenticatedUser()!.patientIdentificationNo, gender: _appState.getAuthenticatedUser()!.gender ).toJson()); + Future insertPatientDeviceData(int loginType) async { + final resultEither = await _authenticationRepo.insertPatientDeviceData( + patientDeviceDataRequest: InsertPatientMobileDeviceInfo( + deviceToken: _appState.deviceToken, + deviceTypeId: _appState.getDeviceTypeID(), + patientId: _appState.getAuthenticatedUser()!.patientId!, + patientTypeId: _appState.getAuthenticatedUser()!.patientType, + patientOutSa: _appState.getAuthenticatedUser()!.outSa!, + loginType: loginType, + languageId: _appState.getLanguageID(), + latitude: _appState.userLat, + longitude: _appState.userLong, + voipToken: "", + deviceType: _appState.deviceTypeID, + patientMobileNumber: _appState.getAuthenticatedUser()!.mobileNumber, + nationalId: _appState.getAuthenticatedUser()!.patientIdentificationNo, + gender: _appState.getAuthenticatedUser()!.gender) + .toJson()); resultEither.fold((failure) async => await _errorHandlerService.handleError(failure: failure), (apiResponse) async { if (apiResponse.messageStatus == 1) { log("Insert Device Data Success"); @@ -726,7 +760,6 @@ class AuthenticationViewModel extends ChangeNotifier { log("Insert IMEI Failed"); } }); - } @override @@ -736,4 +769,41 @@ class AuthenticationViewModel extends ChangeNotifier { myFocusNode.dispose(); super.dispose(); } + + Future getServicePrivilege() async { + final resultEither = await _authenticationRepo.getServicePrivilege(); + List privilegeModelList = []; + List vidaPlusProjectListModel = []; + List hMCProjectListModel = []; + List projectDetailListModel = []; + + resultEither.fold( + (failure) async => await _errorHandlerService.handleError(failure: failure), + (apiResponse) async { + if (apiResponse.messageStatus == 2) { + await _dialogService.showErrorBottomSheet(message: apiResponse.errorMessage ?? "ErrorEmpty"); + } else { + apiResponse.data["ServicePrivilegeList"].forEach((v) { + privilegeModelList.add(PrivilegeModel.fromJson(v)); + }); + _appState.setPrivilegeModelList(privilegeModelList); + + apiResponse.data["ProjectListVidaPlus"].forEach((v) { + vidaPlusProjectListModel.add(VidaPlusProjectListModel.fromJson(v)); + }); + _appState.setVidaPlusProjectList(vidaPlusProjectListModel); + + apiResponse.data["HMCProjectList"].forEach((v) { + hMCProjectListModel.add(HMCProjectListModel.fromJson(v)); + }); + _appState.setHMCProjectList(hMCProjectListModel); + + apiResponse.data["ProjectDetailList"].forEach((v) { + projectDetailListModel.add(ProjectDetailListModel.fromJson(v)); + }); + _appState.setProjectsDetailList(projectDetailListModel); + } + }, + ); + } } diff --git a/lib/presentation/appointments/widgets/appointment_checkin_bottom_sheet.dart b/lib/presentation/appointments/widgets/appointment_checkin_bottom_sheet.dart index f8e0f59..77fec61 100644 --- a/lib/presentation/appointments/widgets/appointment_checkin_bottom_sheet.dart +++ b/lib/presentation/appointments/widgets/appointment_checkin_bottom_sheet.dart @@ -2,6 +2,10 @@ import 'package:easy_localization/easy_localization.dart'; import 'package:flutter/material.dart'; import 'package:flutter_nfc_kit/flutter_nfc_kit.dart'; import 'package:hmg_patient_app_new/core/app_assets.dart'; +import 'package:hmg_patient_app_new/core/app_state.dart'; +import 'package:hmg_patient_app_new/core/common_models/privilege/ProjectDetailListModel.dart'; +import 'package:hmg_patient_app_new/core/dependencies.dart'; +import 'package:hmg_patient_app_new/core/location_util.dart'; import 'package:hmg_patient_app_new/core/utils/size_utils.dart'; import 'package:hmg_patient_app_new/core/utils/utils.dart'; import 'package:hmg_patient_app_new/extensions/string_extensions.dart'; @@ -25,8 +29,12 @@ class AppointmentCheckinBottomSheet extends StatelessWidget { bool _supportsNFC = false; + late LocationUtils locationUtils; + ProjectDetailListModel projectDetailListModel = ProjectDetailListModel(); + @override Widget build(BuildContext context) { + AppState _appState = getIt.get(); FlutterNfcKit.nfcAvailability.then((value) { _supportsNFC = (value == NFCAvailability.available); }); @@ -38,7 +46,25 @@ class AppointmentCheckinBottomSheet extends StatelessWidget { "Live Location".needTranslation, "Verify your location to be at hospital to check in".needTranslation, ).onPress(() { - Navigator.of(context).pop(); + // locationUtils = LocationUtils( + // isShowConfirmDialog: false, + // navigationService: myAppointmentsViewModel.navigationService, + // appState: myAppointmentsViewModel.appState, + // ); + locationUtils.getCurrentLocation(callBack: (value) { + projectDetailListModel = Utils.getProjectDetailObj(_appState, patientAppointmentHistoryResponseModel.projectID); + double dist = Utils.distance(value.latitude, value.longitude, double.parse(projectDetailListModel.latitude!), double.parse(projectDetailListModel.longitude!)).ceilToDouble() * 1000; + print(dist); + if (dist <= projectDetailListModel.geofenceRadius!) { + sendCheckInRequest(projectDetailListModel.checkInQrCode!, context); + } else { + showCommonBottomSheetWithoutHeight(context, + title: "Error".needTranslation, + child: Utils.getErrorWidget(loadingText: "Please ensure you're within the hospital location to perform online check-in.".needTranslation), callBackFunc: () { + Navigator.of(context).pop(); + }, isFullScreen: false); + } + }); }), SizedBox(height: 16.h), checkInOptionCard( diff --git a/lib/presentation/authentication/quick_login.dart b/lib/presentation/authentication/quick_login.dart index c5f540b..ff70dab 100644 --- a/lib/presentation/authentication/quick_login.dart +++ b/lib/presentation/authentication/quick_login.dart @@ -122,7 +122,7 @@ class _QuickLogin extends State { child: CustomButton( text: LocaleKeys.notNow.tr(), onPressed: () { - Navigator.pop(context, true); + Navigator.pop(context, "true"); }, backgroundColor: Color(0xffFEE9EA), borderColor: Color(0xffFEE9EA), diff --git a/lib/presentation/authentication/saved_login_screen.dart b/lib/presentation/authentication/saved_login_screen.dart index 55cbadf..589616f 100644 --- a/lib/presentation/authentication/saved_login_screen.dart +++ b/lib/presentation/authentication/saved_login_screen.dart @@ -34,13 +34,17 @@ class _SavedLogin extends State { void initState() { authVm = context.read(); appState = getIt.get(); - loginType = LoginTypeExtension.fromValue(appState.getSelectDeviceByImeiRespModelElement!.logInType!)!; + loginType = LoginTypeExtension.fromValue(appState.getSelectDeviceByImeiRespModelElement!.logInType!)!; authVm.phoneNumberController.text = appState.getSelectDeviceByImeiRespModelElement!.mobile!.startsWith("0") ? appState.getSelectDeviceByImeiRespModelElement!.mobile!.replaceFirst("0", "") : appState.getSelectDeviceByImeiRespModelElement!.mobile!; authVm.nationalIdController.text = appState.getSelectDeviceByImeiRespModelElement!.identificationNo!; + if (loginType == LoginTypeEnum.fingerprint || loginType == LoginTypeEnum.face) { + authVm.loginWithFingerPrintFace(); + } + super.initState(); } @@ -80,8 +84,7 @@ class _SavedLogin extends State { children: [ // Last login info - ("${LocaleKeys.lastloginBy.tr()} ${loginType.displayName}") - .toText14(isBold: true, color: AppColors.greyTextColor), + ("${LocaleKeys.lastloginBy.tr()} ${loginType.displayName}").toText14(isBold: true, color: AppColors.greyTextColor), (appState.getSelectDeviceByImeiRespModelElement!.createdOn != null ? DateUtil.getFormattedDate(DateUtil.convertStringToDate(appState.getSelectDeviceByImeiRespModelElement!.createdOn!), "d MMMM, y 'at' HH:mm") : '--') @@ -89,7 +92,8 @@ class _SavedLogin extends State { Container( margin: EdgeInsets.all(16.h), - child: Utils.buildSvgWithAssets(icon: getTypeIcons(appState.getSelectDeviceByImeiRespModelElement!.logInType!), height: 54, width: 54, iconColor: loginType.toInt == 4 ? null : AppColors.primaryRedColor)), + child: Utils.buildSvgWithAssets( + icon: getTypeIcons(appState.getSelectDeviceByImeiRespModelElement!.logInType!), height: 54, width: 54, iconColor: loginType.toInt == 4 ? null : AppColors.primaryRedColor)), // Face ID login button SizedBox( height: 45, @@ -232,7 +236,6 @@ class _SavedLogin extends State { textColor: Color(0xFF2E3039), borderWidth: 2, padding: EdgeInsets.fromLTRB(0, 14, 0, 14), - ), const Spacer(flex: 2), // OR divider diff --git a/lib/presentation/home/landing_page.dart b/lib/presentation/home/landing_page.dart index b55632b..55afffe 100644 --- a/lib/presentation/home/landing_page.dart +++ b/lib/presentation/home/landing_page.dart @@ -42,7 +42,7 @@ class _LandingPageState extends State { authVM.savePushTokenToAppState(); if (mounted) { authVM.checkLastLoginStatus(() { - showQuickLogin(context, false); + showQuickLogin(context, false); }); } super.initState(); @@ -326,19 +326,17 @@ class _LandingPageState extends State { context, title: "", child: QuickLogin( - isDone: isDone, + isDone: isDone, onPressed: () { // sharedPref.setBool(HAS_ENABLED_QUICK_LOGIN, true); authVM.loginWithFingerPrintFace(); }, ), - height:isDone == false ? ResponsiveExtension.screenHeight * 0.5 : ResponsiveExtension.screenHeight * 0.3, + height: isDone == false ? ResponsiveExtension.screenHeight * 0.5 : ResponsiveExtension.screenHeight * 0.3, isFullScreen: false, callBackFunc: (str) { isDone = true; - setState(() { - - }); + setState(() {}); }, ); } diff --git a/lib/splashPage.dart b/lib/splashPage.dart index b852cd4..f85f01e 100644 --- a/lib/splashPage.dart +++ b/lib/splashPage.dart @@ -9,6 +9,8 @@ import 'package:flutter_zoom_videosdk/native/zoom_videosdk.dart'; import 'package:hmg_patient_app_new/core/api_consts.dart'; import 'package:hmg_patient_app_new/core/app_assets.dart'; import 'package:hmg_patient_app_new/core/utils/utils.dart'; +import 'package:hmg_patient_app_new/features/authentication/authentication_view_model.dart'; + // import 'package:hmg_patient_app_new/presentation/authantication/login.dart'; import 'package:hmg_patient_app_new/presentation/home/landing_page.dart'; import 'package:hmg_patient_app_new/presentation/home/navigation_screen.dart'; @@ -26,6 +28,8 @@ class SplashPage extends StatefulWidget { } class _SplashScreenState extends State { + late AuthenticationViewModel authVm; + Future initializeStuff() async { Timer( Duration(milliseconds: 500), @@ -34,7 +38,8 @@ class _SplashScreenState extends State { PushNotificationHandler().init(context); // Asyncronously }, ); - Timer(Duration(seconds: 3, milliseconds: 500), () async { + await authVm.getServicePrivilege(); + Timer(Duration(seconds: 2, milliseconds: 500), () async { LocalNotification.init(onNotificationClick: (payload) {}); Navigator.of(context).pushReplacement( FadePage( @@ -51,8 +56,6 @@ class _SplashScreenState extends State { zoom.initSdk(initConfig); } - - /// load the Privilege from service Future loadPrivilege() async { // ProjectViewModel projectProvider = Provider.of(context, listen: false); @@ -71,9 +74,9 @@ class _SplashScreenState extends State { PushNotificationHandler().init(context); // Asyncronously } - @override void initState() { + authVm = context.read(); super.initState(); initializeStuff(); } @@ -87,8 +90,7 @@ class _SplashScreenState extends State { children: [ Padding( padding: EdgeInsets.symmetric(horizontal: 53), - child: Image.asset(AppAssets.hmg_logo, - fit: BoxFit.fitWidth, width: MediaQuery.of(context).size.width), + child: Image.asset(AppAssets.hmg_logo, fit: BoxFit.fitWidth, width: MediaQuery.of(context).size.width), ), Align( alignment: Alignment.bottomCenter, @@ -97,18 +99,12 @@ class _SplashScreenState extends State { children: [ Text( "Powered by", - style: TextStyle( - fontSize: 14, - fontWeight: FontWeight.w400, - color: AppColors.textColor, - letterSpacing: -0.56, - height: 16 / 14), + style: TextStyle(fontSize: 14, fontWeight: FontWeight.w400, color: AppColors.textColor, letterSpacing: -0.56, height: 16 / 14), ), SizedBox( height: 5, ), - Utils.buildSvgWithAssets( - icon: AppAssets.cloud_logo, width: 40, height: 40), + Utils.buildSvgWithAssets(icon: AppAssets.cloud_logo, width: 40, height: 40), SizedBox(height: 7), // Text( // "Version 1.1.0",