From d9013a1dc2665f85e2ff833406fe15279bb16a2b Mon Sep 17 00:00:00 2001 From: Haroon Amjad <> Date: Thu, 19 Feb 2026 02:41:26 +0300 Subject: [PATCH] Added immediate patient insurance update API --- lib/core/api/api_client.dart | 2 +- lib/core/api_consts.dart | 4 +- .../book_appointments_view_model.dart | 6 +- .../immediate_livecare_repo.dart | 4 +- .../immediate_livecare_view_model.dart | 22 +++-- .../my_appointments/my_appointments_repo.dart | 54 ++++++++--- .../my_appointments_view_model.dart | 93 ++++++++++--------- ...select_immediate_livecare_clinic_page.dart | 27 ++++-- .../book_appointment/select_clinic_page.dart | 27 ++++-- 9 files changed, 152 insertions(+), 87 deletions(-) diff --git a/lib/core/api/api_client.dart b/lib/core/api/api_client.dart index 00362bd..2c41b86 100644 --- a/lib/core/api/api_client.dart +++ b/lib/core/api/api_client.dart @@ -195,7 +195,7 @@ class ApiClientImp implements ApiClient { } // body['TokenID'] = "@dm!n"; - // body['PatientID'] = 4774018; + // body['PatientID'] = 4773989; // body['PatientTypeID'] = 1; // body['PatientOutSA'] = 0; // body['SessionID'] = "45786230487560q"; diff --git a/lib/core/api_consts.dart b/lib/core/api_consts.dart index f3b946e..708324e 100644 --- a/lib/core/api_consts.dart +++ b/lib/core/api_consts.dart @@ -110,8 +110,6 @@ class ApiConsts { } } - static final String sendPatientUpdateRequest = 'Services/OUTPs.svc/REST/PatientCompanyUpdate'; - static final String selectDeviceImei = 'Services/Patients.svc/REST/Patient_SELECTDeviceIMEIbyIMEI'; static final String checkPatientAuth = 'Services/Authentication.svc/REST/CheckPatientAuthentication'; @@ -918,6 +916,8 @@ var GET_PRESCRIPTION_INSTRUCTIONS_PDF = 'Services/ChatBot_Service.svc/REST/Chatb const DASHBOARD = 'Services/Patients.svc/REST/PatientDashboard'; +const SEND_PATIENT_IMMEDIATE_UPDATE_INSURANCE_REQUEST = 'Services/OUTPs.svc/REST/PatientCompanyUpdate'; + class ApiKeyConstants { static final String googleMapsApiKey = 'AIzaSyB6TERnxIr0yJ3qG4ULBZbu0sAD4tGqtng'; } diff --git a/lib/features/book_appointments/book_appointments_view_model.dart b/lib/features/book_appointments/book_appointments_view_model.dart index c6c5faf..3132dc8 100644 --- a/lib/features/book_appointments/book_appointments_view_model.dart +++ b/lib/features/book_appointments/book_appointments_view_model.dart @@ -464,7 +464,11 @@ class BookAppointmentsViewModel extends ChangeNotifier { final result = await bookAppointmentsRepo.getLiveCareScheduleClinics(_appState.getAuthenticatedUser()!.age!, _appState.getAuthenticatedUser()!.gender!); result.fold( - (failure) async => await errorHandlerService.handleError(failure: failure), + // (failure) async => await errorHandlerService.handleError(failure: failure), + (failure) async { + isClinicsListLoading = false; + notifyListeners(); + }, (apiResponse) { if (apiResponse.messageStatus == 2) { // dialogService.showErrorDialog(message: apiResponse.errorMessage!, onOkPressed: () {}); diff --git a/lib/features/immediate_livecare/immediate_livecare_repo.dart b/lib/features/immediate_livecare/immediate_livecare_repo.dart index eee4adb..cbce4ea 100644 --- a/lib/features/immediate_livecare/immediate_livecare_repo.dart +++ b/lib/features/immediate_livecare/immediate_livecare_repo.dart @@ -89,7 +89,7 @@ class ImmediateLiveCareRepoImp implements ImmediateLiveCareRepo { body: mapDevice, onFailure: (error, statusCode, {messageStatus, failureType}) { failure = failureType; - onError!(error); + // onError!(error); }, onSuccess: (response, statusCode, {messageStatus, errorMessage}) { try { @@ -142,7 +142,7 @@ class ImmediateLiveCareRepoImp implements ImmediateLiveCareRepo { body: mapDevice, onFailure: (error, statusCode, {messageStatus, failureType}) { failure = failureType; - onError!(error); + // onError!(error); }, onSuccess: (response, statusCode, {messageStatus, errorMessage}) { try { diff --git a/lib/features/immediate_livecare/immediate_livecare_view_model.dart b/lib/features/immediate_livecare/immediate_livecare_view_model.dart index 90bf9a0..46f5a65 100644 --- a/lib/features/immediate_livecare/immediate_livecare_view_model.dart +++ b/lib/features/immediate_livecare/immediate_livecare_view_model.dart @@ -174,13 +174,21 @@ class ImmediateLiveCareViewModel extends ChangeNotifier { }, onConfirmTap: () async { Navigator.pop(GetIt.instance().navigatorKey.currentContext!); - Navigator.pop(GetIt.instance().navigatorKey.currentContext!); - Navigator.push( - GetIt.instance().navigatorKey.currentContext!, - CustomPageRoute( - page: InsuranceHomePage(), - ), - ); + + //Call the API to attempt updating patient insurance + LoaderBottomSheet.showLoader(); + myAppointmentsViewModel.sendPatientUpdateRequest(onSuccess: (val) { + LoaderBottomSheet.hideLoader(); + getLiveCareImmediateAppointmentFees(); + }, onError: (err) { + LoaderBottomSheet.hideLoader(); + Navigator.push( + GetIt.instance().navigatorKey.currentContext!, + CustomPageRoute( + page: InsuranceHomePage(), + ), + ); + }); }), ), callBackFunc: () { // Navigator.pop(GetIt.instance().navigatorKey.currentContext!); diff --git a/lib/features/my_appointments/my_appointments_repo.dart b/lib/features/my_appointments/my_appointments_repo.dart index 0c76c9f..567714c 100644 --- a/lib/features/my_appointments/my_appointments_repo.dart +++ b/lib/features/my_appointments/my_appointments_repo.dart @@ -20,7 +20,8 @@ import 'models/req_model/appointment_rate_req_model.dart'; import 'models/resp_models/appointment_details_resp_model.dart'; abstract class MyAppointmentsRepo { - Future>>> getPatientAppointments({required bool isActiveAppointment, required bool isArrivedAppointments, bool isForEyeMeasurement = false}); + Future>>> getPatientAppointments( + {required bool isActiveAppointment, required bool isArrivedAppointments, bool isForEyeMeasurement = false}); Future>> getPatientShareAppointment( {required int projectID, required int clinicID, required String appointmentNo, required bool isLiveCareAppointment}); @@ -67,14 +68,16 @@ abstract class MyAppointmentsRepo { Future>> getAppointmentDetails(int appointmentID, int projectID); - Future>> sendAppointmentRate(int rate, int appointmentNo, int projectID, int doctorID, int clinicID, String note); - Future>> sendDoctorRate(int rate, int appointmentNo, int projectID, int doctorID, int clinicID, String note, String appoDate, String docName, String projectName, String clinicName); + Future>> sendDoctorRate( + int rate, int appointmentNo, int projectID, int doctorID, int clinicID, String note, String appoDate, String docName, String projectName, String clinicName); Future>>> getPatientAppointmentQueueDetails({required int appointmentNo, required int patientID}); Future>> convertPatientToCash({required int projectID}); + + Future>> sendPatientUpdateRequest(); } class MyAppointmentsRepoImp implements MyAppointmentsRepo { @@ -194,9 +197,7 @@ class MyAppointmentsRepoImp implements MyAppointmentsRepo { "AppointmentNo": appointmentNo, "PaymentMethodName": paymentMethodName, "PaymentAmount": payedAmount == 0 ? "0" : payedAmount.toString(), - "PaymentDate": payedAmount == 0 ? "" : "/Date(${DateTime - .now() - .millisecondsSinceEpoch})/", + "PaymentDate": payedAmount == 0 ? "" : "/Date(${DateTime.now().millisecondsSinceEpoch})/", "PaymentReferenceNumber": payedAmount == 0 ? "" : paymentReference, "ProjectID": projectID, "PatientID": patientID, @@ -865,10 +866,8 @@ class MyAppointmentsRepoImp implements MyAppointmentsRepo { } } - @override - Future>> sendAppointmentRate(int rate, int appointmentNo, int projectID, int doctorID, int clinicID, String note) async { - + Future>> sendAppointmentRate(int rate, int appointmentNo, int projectID, int doctorID, int clinicID, String note) async { AppointmentRate appointmentRate = AppointmentRate(); appointmentRate.rate = rate; appointmentRate.appointmentNo = appointmentNo; @@ -879,7 +878,6 @@ class MyAppointmentsRepoImp implements MyAppointmentsRepo { appointmentRate.createdBy = 2; appointmentRate.editedBy = 2; - try { GenericApiModel? apiResponse; Failure? failure; @@ -908,7 +906,8 @@ class MyAppointmentsRepoImp implements MyAppointmentsRepo { } @override - Future>> sendDoctorRate(int rate, int appointmentNo, int projectID, int doctorID, int clinicID, String note, String appoDate, String docName, String projectName, String clinicName) async { + Future>> sendDoctorRate( + int rate, int appointmentNo, int projectID, int doctorID, int clinicID, String note, String appoDate, String docName, String projectName, String clinicName) async { Map request; request = { @@ -991,4 +990,35 @@ class MyAppointmentsRepoImp implements MyAppointmentsRepo { return Left(UnknownFailure(e.toString())); } } -} \ No newline at end of file + + @override + Future> sendPatientUpdateRequest() async { + Map request = {}; + + try { + GenericApiModel? apiResponse; + Failure? failure; + await apiClient.post(SEND_PATIENT_IMMEDIATE_UPDATE_INSURANCE_REQUEST, onFailure: (error, statusCode, {messageStatus, failureType}) { + failure = failureType; + }, onSuccess: (response, statusCode, {messageStatus, errorMessage}) { + try { + final list = (response['MessageStatus'] == 1); + + apiResponse = GenericApiModel( + messageStatus: messageStatus, + statusCode: statusCode, + errorMessage: null, + data: list, + ); + } catch (e) { + failure = DataParsingFailure(e.toString()); + } + }, body: request); + if (failure != null) return Left(failure!); + if (apiResponse == null) return Left(ServerFailure("Unknown error")); + return Right(apiResponse!); + } catch (e) { + return Left(UnknownFailure(e.toString())); + } + } +} diff --git a/lib/features/my_appointments/my_appointments_view_model.dart b/lib/features/my_appointments/my_appointments_view_model.dart index 35bf29b..f887680 100644 --- a/lib/features/my_appointments/my_appointments_view_model.dart +++ b/lib/features/my_appointments/my_appointments_view_model.dart @@ -54,9 +54,6 @@ class MyAppointmentsViewModel extends ChangeNotifier { List patientQueueDetailsList = []; late PatientQueueDetails currentPatientQueueDetails; - - - List patientAppointmentsHistoryList = []; List filteredAppointmentList = []; @@ -344,10 +341,8 @@ class MyAppointmentsViewModel extends ChangeNotifier { notifyListeners(); } - Future getPatientShareAppointment(int projectID, int clinicID, String appointmentNo, bool isLiveCareAppointment, - {Function(dynamic)? onSuccess, Function(String)? onError}) async { - final result = await myAppointmentsRepo.getPatientShareAppointment( - projectID: projectID, clinicID: clinicID, appointmentNo: appointmentNo, isLiveCareAppointment: isLiveCareAppointment); + Future getPatientShareAppointment(int projectID, int clinicID, String appointmentNo, bool isLiveCareAppointment, {Function(dynamic)? onSuccess, Function(String)? onError}) async { + final result = await myAppointmentsRepo.getPatientShareAppointment(projectID: projectID, clinicID: clinicID, appointmentNo: appointmentNo, isLiveCareAppointment: isLiveCareAppointment); result.fold( (failure) async { @@ -421,13 +416,23 @@ class MyAppointmentsViewModel extends ChangeNotifier { }, onConfirmTap: () async { Navigator.pop(GetIt.instance().navigatorKey.currentContext!); - Navigator.pop(GetIt.instance().navigatorKey.currentContext!); - Navigator.push( - GetIt.instance().navigatorKey.currentContext!, - CustomPageRoute( - page: InsuranceHomePage(), - ), - ); + + //Call the API to attempt updating patient insurance + LoaderBottomSheet.showLoader(); + sendPatientUpdateRequest(onSuccess: (val) { + LoaderBottomSheet.hideLoader(); + setIsPatientAppointmentShareLoading(true); + getPatientShareAppointment(projectID, clinicID, appointmentNo, isLiveCareAppointment); + }, onError: (err) { + LoaderBottomSheet.hideLoader(); + Navigator.pop(GetIt.instance().navigatorKey.currentContext!); + Navigator.push( + GetIt.instance().navigatorKey.currentContext!, + CustomPageRoute( + page: InsuranceHomePage(), + ), + ); + }); }), ), callBackFunc: () { // Navigator.pop(GetIt.instance().navigatorKey.currentContext!); @@ -443,6 +448,27 @@ class MyAppointmentsViewModel extends ChangeNotifier { ); } + Future sendPatientUpdateRequest({Function(dynamic)? onSuccess, Function(String)? onError}) async { + final result = await myAppointmentsRepo.sendPatientUpdateRequest(); + + result.fold( + // (failure) async => await errorHandlerService.handleError(failure: failure), + (failure) async { + onError!(failure.message); + }, + (apiResponse) { + if (apiResponse.messageStatus == 2) { + // dialogService.showErrorDialog(message: apiResponse.errorMessage!, onOkPressed: () {}); + } else if (apiResponse.messageStatus == 1) { + notifyListeners(); + if (onSuccess != null) { + onSuccess(apiResponse); + } + } + }, + ); + } + Future convertPatientToCash({required int projectID, Function(dynamic)? onSuccess, Function(String)? onError}) async { final result = await myAppointmentsRepo.convertPatientToCash(projectID: projectID); @@ -465,13 +491,8 @@ class MyAppointmentsViewModel extends ChangeNotifier { } Future addAdvanceNumberRequest( - {required String advanceNumber, - required String paymentReference, - required String appointmentNo, - Function(dynamic)? onSuccess, - Function(String)? onError}) async { - final result = - await myAppointmentsRepo.addAdvanceNumberRequest(advanceNumber: advanceNumber, paymentReference: paymentReference, appointmentNo: appointmentNo); + {required String advanceNumber, required String paymentReference, required String appointmentNo, Function(dynamic)? onSuccess, Function(String)? onError}) async { + final result = await myAppointmentsRepo.addAdvanceNumberRequest(advanceNumber: advanceNumber, paymentReference: paymentReference, appointmentNo: appointmentNo); result.fold( (failure) async => await errorHandlerService.handleError(failure: failure), @@ -489,14 +510,8 @@ class MyAppointmentsViewModel extends ChangeNotifier { } Future generateAppointmentQR( - {required int clinicID, - required int projectID, - required String appointmentNo, - required int isFollowUp, - Function(dynamic)? onSuccess, - Function(String)? onError}) async { - final result = - await myAppointmentsRepo.generateAppointmentQR(clinicID: clinicID, projectID: projectID, appointmentNo: appointmentNo, isFollowUp: isFollowUp); + {required int clinicID, required int projectID, required String appointmentNo, required int isFollowUp, Function(dynamic)? onSuccess, Function(String)? onError}) async { + final result = await myAppointmentsRepo.generateAppointmentQR(clinicID: clinicID, projectID: projectID, appointmentNo: appointmentNo, isFollowUp: isFollowUp); result.fold( (failure) async => await errorHandlerService.handleError(failure: failure), @@ -513,14 +528,13 @@ class MyAppointmentsViewModel extends ChangeNotifier { ); } - Future cancelAppointment( - {required PatientAppointmentHistoryResponseModel patientAppointmentHistoryResponseModel, Function(dynamic)? onSuccess, Function(String)? onError}) async { + Future cancelAppointment({required PatientAppointmentHistoryResponseModel patientAppointmentHistoryResponseModel, Function(dynamic)? onSuccess, Function(String)? onError}) async { final result = await myAppointmentsRepo.cancelAppointment(patientAppointmentHistoryResponseModel: patientAppointmentHistoryResponseModel); result.fold( // (failure) async => await errorHandlerService.handleError(failure: failure), (failure) async { - if(onError != null) { + if (onError != null) { onError(failure.message); } }, @@ -538,8 +552,7 @@ class MyAppointmentsViewModel extends ChangeNotifier { ); } - Future confirmAppointment( - {required PatientAppointmentHistoryResponseModel patientAppointmentHistoryResponseModel, Function(dynamic)? onSuccess, Function(String)? onError}) async { + Future confirmAppointment({required PatientAppointmentHistoryResponseModel patientAppointmentHistoryResponseModel, Function(dynamic)? onSuccess, Function(String)? onError}) async { final result = await myAppointmentsRepo.confirmAppointment(patientAppointmentHistoryResponseModel: patientAppointmentHistoryResponseModel); result.fold( @@ -600,8 +613,7 @@ class MyAppointmentsViewModel extends ChangeNotifier { required int checkInType, Function(dynamic)? onSuccess, Function(String)? onError}) async { - final result = await myAppointmentsRepo.sendCheckInNfcRequest( - patientAppointmentHistoryResponseModel: patientAppointmentHistoryResponseModel, scannedCode: scannedCode, checkInType: checkInType); + final result = await myAppointmentsRepo.sendCheckInNfcRequest(patientAppointmentHistoryResponseModel: patientAppointmentHistoryResponseModel, scannedCode: scannedCode, checkInType: checkInType); result.fold( (failure) async => await errorHandlerService.handleError(failure: failure), @@ -647,12 +659,8 @@ class MyAppointmentsViewModel extends ChangeNotifier { } Future insertLiveCareVIDARequest( - {required clientRequestID, - required PatientAppointmentHistoryResponseModel patientAppointmentHistoryResponseModel, - Function(dynamic)? onSuccess, - Function(String)? onError}) async { - final result = await myAppointmentsRepo.insertLiveCareVIDARequest( - clientRequestID: clientRequestID, patientAppointmentHistoryResponseModel: patientAppointmentHistoryResponseModel); + {required clientRequestID, required PatientAppointmentHistoryResponseModel patientAppointmentHistoryResponseModel, Function(dynamic)? onSuccess, Function(String)? onError}) async { + final result = await myAppointmentsRepo.insertLiveCareVIDARequest(clientRequestID: clientRequestID, patientAppointmentHistoryResponseModel: patientAppointmentHistoryResponseModel); result.fold( (failure) async => await errorHandlerService.handleError(failure: failure), @@ -928,5 +936,4 @@ class MyAppointmentsViewModel extends ChangeNotifier { }, ); } - } diff --git a/lib/presentation/book_appointment/livecare/select_immediate_livecare_clinic_page.dart b/lib/presentation/book_appointment/livecare/select_immediate_livecare_clinic_page.dart index 594bff0..a83dfa0 100644 --- a/lib/presentation/book_appointment/livecare/select_immediate_livecare_clinic_page.dart +++ b/lib/presentation/book_appointment/livecare/select_immediate_livecare_clinic_page.dart @@ -116,7 +116,7 @@ class _SelectImmediateLiveCareClinicPageState extends State { padding: EdgeInsets.only(top: 24.h), shrinkWrap: true, physics: NeverScrollableScrollPhysics(), - itemCount: bookAppointmentsVM.isClinicsListLoading ? 5 : bookAppointmentsVM.liveCareClinicsList.length, + itemCount: bookAppointmentsVM.isClinicsListLoading + ? 5 + : bookAppointmentsVM.liveCareClinicsList.isNotEmpty + ? bookAppointmentsVM.liveCareClinicsList.length + : 1, + + // bookAppointmentsVM.isClinicsListLoading ? 5 : bookAppointmentsVM.liveCareClinicsList.length, + itemBuilder: (context, index) { return bookAppointmentsVM.isClinicsListLoading ? ClinicCard( @@ -163,14 +170,16 @@ class _SelectClinicPageState extends State { duration: Duration(milliseconds: 300), curve: Curves.easeInOut, decoration: RoundedRectangleBorder().toSmoothCornerDecoration(color: AppColors.whiteColor, borderRadius: 24.h, hasShadow: true), - child: ClinicCard( - bookAppointmentsVM: bookAppointmentsVM, - liveCareClinicsResponseModel: bookAppointmentsVM.liveCareClinicsList[index], - clinicsListResponseModel: GetClinicsListResponseModel(), - isLoading: bookAppointmentsVM.isClinicsListLoading, - ).onPress(() { - onLiveCareClinicSelected(bookAppointmentsVM.liveCareClinicsList[index]); - }), + child: bookAppointmentsVM.liveCareClinicsList.isNotEmpty + ? ClinicCard( + bookAppointmentsVM: bookAppointmentsVM, + liveCareClinicsResponseModel: bookAppointmentsVM.liveCareClinicsList[index], + clinicsListResponseModel: GetClinicsListResponseModel(), + isLoading: bookAppointmentsVM.isClinicsListLoading, + ).onPress(() { + onLiveCareClinicSelected(bookAppointmentsVM.liveCareClinicsList[index]); + }) + : Utils.getNoDataWidget(context), ), ), ),