From 5de5fc8be9d165078b2a92529d37dd8213b3f45b Mon Sep 17 00:00:00 2001 From: haroon amjad Date: Wed, 17 Sep 2025 15:03:07 +0300 Subject: [PATCH] updates --- lib/features/insurance/insurance_repo.dart | 4 +- .../insurance/insurance_view_model.dart | 7 +- .../medical_file/medical_file_repo.dart | 4 +- .../patient_sickleave_response_model.dart | 4 +- .../my_appointments_view_model.dart | 180 ++++++------------ .../prescriptions_view_model.dart | 5 +- .../medical_file/medical_file_page.dart | 12 +- 7 files changed, 80 insertions(+), 136 deletions(-) diff --git a/lib/features/insurance/insurance_repo.dart b/lib/features/insurance/insurance_repo.dart index 874cc28..65f97ae 100644 --- a/lib/features/insurance/insurance_repo.dart +++ b/lib/features/insurance/insurance_repo.dart @@ -9,7 +9,7 @@ import 'package:hmg_patient_app_new/features/insurance/models/resp_models/patien import 'package:hmg_patient_app_new/services/logger_service.dart'; abstract class InsuranceRepo { - Future>>> getPatientInsuranceDetails({required String patientId}); + Future>>> getPatientInsuranceDetails(); Future>>> getPatientInsuranceCardHistory({required String patientId}); @@ -23,7 +23,7 @@ class InsuranceRepoImp implements InsuranceRepo { InsuranceRepoImp({required this.loggerService, required this.apiClient}); @override - Future>>> getPatientInsuranceDetails({required String patientId}) async { + Future>>> getPatientInsuranceDetails() async { Map mapDevice = {}; try { diff --git a/lib/features/insurance/insurance_view_model.dart b/lib/features/insurance/insurance_view_model.dart index 527c180..8319634 100644 --- a/lib/features/insurance/insurance_view_model.dart +++ b/lib/features/insurance/insurance_view_model.dart @@ -49,10 +49,13 @@ class InsuranceViewModel extends ChangeNotifier { } Future getPatientInsuranceDetails({Function(dynamic)? onSuccess, Function(String)? onError}) async { - final result = await insuranceRepo.getPatientInsuranceDetails(patientId: "1231755"); + final result = await insuranceRepo.getPatientInsuranceDetails(); result.fold( - (failure) async => await errorHandlerService.handleError(failure: failure), + // (failure) async => await errorHandlerService.handleError(failure: failure), + (failure) async { + isInsuranceLoading = false; + }, (apiResponse) { if (apiResponse.messageStatus == 2) { // dialogService.showErrorDialog(message: apiResponse.errorMessage!, onOkPressed: () {}); diff --git a/lib/features/medical_file/medical_file_repo.dart b/lib/features/medical_file/medical_file_repo.dart index affe564..bbb4fcd 100644 --- a/lib/features/medical_file/medical_file_repo.dart +++ b/lib/features/medical_file/medical_file_repo.dart @@ -91,13 +91,13 @@ class MedicalFileRepoImp implements MedicalFileRepo { // throw Exception("lab list is empty"); // } - final vaccinesList = list.map((item) => PatientSickLeavesResponseModel.fromJson(item as Map)).toList().cast(); + final sickLeavesList = list.map((item) => PatientSickLeavesResponseModel.fromJson(item as Map)).toList().cast(); apiResponse = GenericApiModel>( messageStatus: messageStatus, statusCode: statusCode, errorMessage: null, - data: vaccinesList, + data: sickLeavesList, ); } catch (e) { failure = DataParsingFailure(e.toString()); diff --git a/lib/features/medical_file/models/patient_sickleave_response_model.dart b/lib/features/medical_file/models/patient_sickleave_response_model.dart index b0381a8..3bf732c 100644 --- a/lib/features/medical_file/models/patient_sickleave_response_model.dart +++ b/lib/features/medical_file/models/patient_sickleave_response_model.dart @@ -14,7 +14,7 @@ class PatientSickLeavesResponseModel { num? actualDoctorRate; String? appointmentDate; String? clinicName; - double? decimalDoctorRate; + num? decimalDoctorRate; String? doctorImageURL; String? doctorName; num? doctorRate; @@ -32,7 +32,7 @@ class PatientSickLeavesResponseModel { String? isInOutPatientDescriptionN; bool? isLiveCareAppointment; dynamic medicalDirectorApprovedStatus; - int? noOfPatientsRate; + num? noOfPatientsRate; dynamic patientName; String? projectName; String? qR; diff --git a/lib/features/my_appointments/my_appointments_view_model.dart b/lib/features/my_appointments/my_appointments_view_model.dart index ce303de..1ada721 100644 --- a/lib/features/my_appointments/my_appointments_view_model.dart +++ b/lib/features/my_appointments/my_appointments_view_model.dart @@ -3,8 +3,7 @@ import 'package:hmg_patient_app_new/core/app_state.dart'; import 'package:hmg_patient_app_new/core/cache_consts.dart' show CacheConst; import 'package:hmg_patient_app_new/core/utils/utils.dart' show Utils; import 'package:hmg_patient_app_new/features/my_appointments/models/facility_selection.dart'; -import 'package:hmg_patient_app_new/features/my_appointments/models/resp_models/doctor_list_api_response.dart' - show RegionList, PatientDoctorAppointmentListByRegion; +import 'package:hmg_patient_app_new/features/my_appointments/models/resp_models/doctor_list_api_response.dart' show RegionList, PatientDoctorAppointmentListByRegion; import 'package:hmg_patient_app_new/features/my_appointments/models/resp_models/patient_appointment_history_response_model.dart'; import 'package:hmg_patient_app_new/features/my_appointments/models/resp_models/patient_appointment_share_response_model.dart'; import 'package:hmg_patient_app_new/features/my_appointments/my_appointments_repo.dart'; @@ -13,7 +12,6 @@ import 'package:location/location.dart' show Location; import '../../core/utils/doctor_response_mapper.dart' show DoctorMapper; - class MyAppointmentsViewModel extends ChangeNotifier { int selectedTabIndex = 0; @@ -26,16 +24,12 @@ class MyAppointmentsViewModel extends ChangeNotifier { bool isTimeLineAppointmentsLoading = false; bool isPatientMyDoctorsLoading = false; - List patientAppointmentsHistoryList = - []; + List patientAppointmentsHistoryList = []; - List - patientUpcomingAppointmentsHistoryList = []; - List - patientArrivedAppointmentsHistoryList = []; + List patientUpcomingAppointmentsHistoryList = []; + List patientArrivedAppointmentsHistoryList = []; - List patientTimelineAppointmentsList = - []; + List patientTimelineAppointmentsList = []; List patientMyDoctorsList = []; @@ -46,15 +40,13 @@ class MyAppointmentsViewModel extends ChangeNotifier { FacilitySelection currentlySelectedFacility = FacilitySelection.ALL; bool isRegionListLoading = false; - MyAppointmentsViewModel( - {required this.myAppointmentsRepo, required this.errorHandlerService,required this.appState}); + MyAppointmentsViewModel({required this.myAppointmentsRepo, required this.errorHandlerService, required this.appState}); void onTabChange(int index) { selectedTabIndex = index; notifyListeners(); } - initAppointmentsViewModel() { patientAppointmentsHistoryList.clear(); patientUpcomingAppointmentsHistoryList.clear(); @@ -89,8 +81,7 @@ class MyAppointmentsViewModel extends ChangeNotifier { notifyListeners(); } - setAppointmentReminder( - bool value, PatientAppointmentHistoryResponseModel item) { + setAppointmentReminder(bool value, PatientAppointmentHistoryResponseModel item) { int index = patientAppointmentsHistoryList.indexOf(item); if (index != -1) { patientAppointmentsHistoryList[index].hasReminder = value; @@ -98,18 +89,12 @@ class MyAppointmentsViewModel extends ChangeNotifier { } } - Future getPatientAppointments( - bool isActiveAppointment, bool isArrivedAppointments, - {Function(dynamic)? onSuccess, Function(String)? onError}) async { - final result = await myAppointmentsRepo.getPatientAppointments( - isActiveAppointment: isActiveAppointment, - isArrivedAppointments: isArrivedAppointments); - final resultArrived = await myAppointmentsRepo.getPatientAppointments( - isActiveAppointment: false, isArrivedAppointments: true); + Future getPatientAppointments(bool isActiveAppointment, bool isArrivedAppointments, {Function(dynamic)? onSuccess, Function(String)? onError}) async { + final result = await myAppointmentsRepo.getPatientAppointments(isActiveAppointment: isActiveAppointment, isArrivedAppointments: isArrivedAppointments); + final resultArrived = await myAppointmentsRepo.getPatientAppointments(isActiveAppointment: false, isArrivedAppointments: true); result.fold( - (failure) async => - await errorHandlerService.handleError(failure: failure), + (failure) async => await errorHandlerService.handleError(failure: failure), (apiResponse) { if (apiResponse.messageStatus == 2) { // dialogService.showErrorDialog(message: apiResponse.errorMessage!, onOkPressed: () {}); @@ -125,8 +110,7 @@ class MyAppointmentsViewModel extends ChangeNotifier { ); resultArrived.fold( - (failure) async => - await errorHandlerService.handleError(failure: failure), + (failure) async => await errorHandlerService.handleError(failure: failure), (apiResponse) { if (apiResponse.messageStatus == 2) { // dialogService.showErrorDialog(message: apiResponse.errorMessage!, onOkPressed: () {}); @@ -141,27 +125,19 @@ class MyAppointmentsViewModel extends ChangeNotifier { }, ); - patientAppointmentsHistoryList - .addAll(patientUpcomingAppointmentsHistoryList); - patientAppointmentsHistoryList - .addAll(patientArrivedAppointmentsHistoryList); + patientAppointmentsHistoryList.addAll(patientUpcomingAppointmentsHistoryList); + patientAppointmentsHistoryList.addAll(patientArrivedAppointmentsHistoryList); - print( - 'Upcoming Appointments: ${patientUpcomingAppointmentsHistoryList.length}'); - print( - 'Arrived Appointments: ${patientArrivedAppointmentsHistoryList.length}'); + print('Upcoming Appointments: ${patientUpcomingAppointmentsHistoryList.length}'); + print('Arrived Appointments: ${patientArrivedAppointmentsHistoryList.length}'); print('All Appointments: ${patientAppointmentsHistoryList.length}'); } - Future getPatientShareAppointment( - int projectID, int clinicID, String appointmentNo, - {Function(dynamic)? onSuccess, Function(String)? onError}) async { - final result = await myAppointmentsRepo.getPatientShareAppointment( - projectID: projectID, clinicID: clinicID, appointmentNo: appointmentNo); + Future getPatientShareAppointment(int projectID, int clinicID, String appointmentNo, {Function(dynamic)? onSuccess, Function(String)? onError}) async { + final result = await myAppointmentsRepo.getPatientShareAppointment(projectID: projectID, clinicID: clinicID, appointmentNo: appointmentNo); result.fold( - (failure) async => - await errorHandlerService.handleError(failure: failure), + (failure) async => await errorHandlerService.handleError(failure: failure), (apiResponse) { if (apiResponse.messageStatus == 2) { // dialogService.showErrorDialog(message: apiResponse.errorMessage!, onOkPressed: () {}); @@ -178,19 +154,11 @@ 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), + (failure) async => await errorHandlerService.handleError(failure: failure), (apiResponse) { if (apiResponse.messageStatus == 2) { // dialogService.showErrorDialog(message: apiResponse.errorMessage!, onOkPressed: () {}); @@ -205,21 +173,11 @@ 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), + (failure) async => await errorHandlerService.handleError(failure: failure), (apiResponse) { if (apiResponse.messageStatus == 2) { // dialogService.showErrorDialog(message: apiResponse.errorMessage!, onOkPressed: () {}); @@ -233,18 +191,11 @@ class MyAppointmentsViewModel extends ChangeNotifier { ); } - Future cancelAppointment( - {required PatientAppointmentHistoryResponseModel - patientAppointmentHistoryResponseModel, - Function(dynamic)? onSuccess, - Function(String)? onError}) async { - final result = await myAppointmentsRepo.cancelAppointment( - patientAppointmentHistoryResponseModel: - patientAppointmentHistoryResponseModel); + 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 => await errorHandlerService.handleError(failure: failure), (apiResponse) { if (apiResponse.messageStatus == 2) { onError!(apiResponse.errorMessage!); @@ -259,18 +210,11 @@ class MyAppointmentsViewModel extends ChangeNotifier { ); } - Future confirmAppointment( - {required PatientAppointmentHistoryResponseModel - patientAppointmentHistoryResponseModel, - Function(dynamic)? onSuccess, - Function(String)? onError}) async { - final result = await myAppointmentsRepo.confirmAppointment( - patientAppointmentHistoryResponseModel: - patientAppointmentHistoryResponseModel); + Future confirmAppointment({required PatientAppointmentHistoryResponseModel patientAppointmentHistoryResponseModel, Function(dynamic)? onSuccess, Function(String)? onError}) async { + final result = await myAppointmentsRepo.confirmAppointment(patientAppointmentHistoryResponseModel: patientAppointmentHistoryResponseModel); result.fold( - (failure) async => - await errorHandlerService.handleError(failure: failure), + (failure) async => await errorHandlerService.handleError(failure: failure), (apiResponse) { if (apiResponse.messageStatus == 2) { onError!(apiResponse.errorMessage!); @@ -307,8 +251,7 @@ class MyAppointmentsViewModel extends ChangeNotifier { patientType: patientType); result.fold( - (failure) async => - await errorHandlerService.handleError(failure: failure), + (failure) async => await errorHandlerService.handleError(failure: failure), (apiResponse) { if (apiResponse.messageStatus == 2) { // dialogService.showErrorDialog(message: apiResponse.errorMessage!, onOkPressed: () {}); @@ -323,21 +266,15 @@ class MyAppointmentsViewModel extends ChangeNotifier { } Future sendCheckInNfcRequest( - {required PatientAppointmentHistoryResponseModel - patientAppointmentHistoryResponseModel, + {required PatientAppointmentHistoryResponseModel patientAppointmentHistoryResponseModel, required String scannedCode, 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), + (failure) async => await errorHandlerService.handleError(failure: failure), (apiResponse) { if (apiResponse.messageStatus == 2) { onError!(apiResponse.errorMessage!); @@ -352,13 +289,14 @@ class MyAppointmentsViewModel extends ChangeNotifier { ); } - Future getPatientMyDoctors( - {Function(dynamic)? onSuccess, Function(String)? onError}) async { + Future getPatientMyDoctors({Function(dynamic)? onSuccess, Function(String)? onError}) async { final result = await myAppointmentsRepo.getPatientDoctorsList(); result.fold( - (failure) async => - await errorHandlerService.handleError(failure: failure), + // (failure) async => await errorHandlerService.handleError(failure: failure), + (failure) async { + isPatientMyDoctorsLoading = false; + }, (apiResponse) { if (apiResponse.messageStatus == 2) { // dialogService.showErrorDialog(message: apiResponse.errorMessage!, onOkPressed: () {}); @@ -375,7 +313,7 @@ class MyAppointmentsViewModel extends ChangeNotifier { } Future getRegionMappedProjectList() async { - if(hospitalList != null && hospitalList!.registeredDoctorMap != null && hospitalList!.registeredDoctorMap!.isNotEmpty){ + if (hospitalList != null && hospitalList!.registeredDoctorMap != null && hospitalList!.registeredDoctorMap!.isNotEmpty) { filteredHospitalList = hospitalList; return; } @@ -384,21 +322,18 @@ class MyAppointmentsViewModel extends ChangeNotifier { final result = await myAppointmentsRepo.getProjectList(); result.fold( - (failure) async => - await errorHandlerService.handleError(failure: failure), + (failure) async => await errorHandlerService.handleError(failure: failure), (apiResponse) async { if (apiResponse.messageStatus == 2) { // dialogService.showErrorDialog(message: apiResponse.errorMessage!, onOkPressed: () {}); } else if (apiResponse.messageStatus == 1) { var projectList = apiResponse.data!; - hospitalList = await DoctorMapper.getMappedHospitals(projectList, - isArabic: false); + hospitalList = await DoctorMapper.getMappedHospitals(projectList, isArabic: false); var lat = await Utils.getNumFromPrefs(CacheConst.userLat); var lng = await Utils.getNumFromPrefs(CacheConst.userLong); var isLocationEnabled = (lat != 0) && (lng != 0); - hospitalList = - await DoctorMapper.sortList(isLocationEnabled, hospitalList!); + hospitalList = await DoctorMapper.sortList(isLocationEnabled, hospitalList!); isRegionListLoading = false; filteredHospitalList = hospitalList; @@ -414,22 +349,21 @@ class MyAppointmentsViewModel extends ChangeNotifier { } void filterHospitalListByString(String? value, String? selectedRegionId, bool isHMG) { - if(value ==null || value.isEmpty){ + if (value == null || value.isEmpty) { filteredHospitalList = hospitalList; } else { filteredHospitalList = RegionList(); - var list = isHMG - ? hospitalList?.registeredDoctorMap![selectedRegionId]!.hmgDoctorList - : hospitalList?.registeredDoctorMap![selectedRegionId]!.hmcDoctorList; + var list = isHMG ? hospitalList?.registeredDoctorMap![selectedRegionId]!.hmgDoctorList : hospitalList?.registeredDoctorMap![selectedRegionId]!.hmcDoctorList; - if(list != null && list.isEmpty){ notifyListeners(); return;} + if (list != null && list.isEmpty) { + notifyListeners(); + return; + } - var filteredList = list!.where((element) => - element.filterName!.toLowerCase().contains(value.toLowerCase()) - ).toList(); + var filteredList = list!.where((element) => element.filterName!.toLowerCase().contains(value.toLowerCase())).toList(); var regionData = PatientDoctorAppointmentListByRegion(); - if(isHMG){ + if (isHMG) { regionData.hmgDoctorList = filteredList; regionData.hmgSize = filteredList.length; } else { @@ -437,19 +371,17 @@ class MyAppointmentsViewModel extends ChangeNotifier { regionData.hmcSize = filteredList.length; } - filteredHospitalList?.registeredDoctorMap = { - selectedRegionId! : regionData - }; + filteredHospitalList?.registeredDoctorMap = {selectedRegionId!: regionData}; } notifyListeners(); } - Future isLocationEnabled() async{ - return await Location().serviceEnabled(); + Future isLocationEnabled() async { + return await Location().serviceEnabled(); } bool getLocationStatus() { - bool isLocationAvaiable = false; + bool isLocationAvaiable = false; isLocationEnabled().then((value) => isLocationAvaiable = value); return isLocationAvaiable; } diff --git a/lib/features/prescriptions/prescriptions_view_model.dart b/lib/features/prescriptions/prescriptions_view_model.dart index 535d78f..f5f32a7 100644 --- a/lib/features/prescriptions/prescriptions_view_model.dart +++ b/lib/features/prescriptions/prescriptions_view_model.dart @@ -68,7 +68,10 @@ class PrescriptionsViewModel extends ChangeNotifier { final result = await prescriptionsRepo.getPatientPrescriptionOrders(patientId: "1231755"); result.fold( - (failure) async => await errorHandlerService.handleError(failure: failure), + // (failure) async => await errorHandlerService.handleError(failure: failure), + (failure) async { + isPrescriptionsOrdersLoading = false; + }, (apiResponse) { if (apiResponse.messageStatus == 2) { // dialogService.showErrorDialog(message: apiResponse.errorMessage!, onOkPressed: () {}); diff --git a/lib/presentation/medical_file/medical_file_page.dart b/lib/presentation/medical_file/medical_file_page.dart index 871a97c..acaf622 100644 --- a/lib/presentation/medical_file/medical_file_page.dart +++ b/lib/presentation/medical_file/medical_file_page.dart @@ -70,6 +70,7 @@ class _MedicalFilePageState extends State { insuranceViewModel.initInsuranceProvider(); medicalFileViewModel.setIsPatientSickLeaveListLoading(true); medicalFileViewModel.getPatientSickLeaveList(); + medicalFileViewModel.onTabChanged(0); } }); super.initState(); @@ -647,9 +648,14 @@ class _MedicalFilePageState extends State { Consumer(builder: (context, insuranceVM, child) { return insuranceVM.isInsuranceLoading ? const MoviesShimmerWidget().paddingSymmetrical(24.h, 0.0) - : PatientInsuranceCard( - insuranceCardDetailsModel: insuranceVM.patientInsuranceList.first, - isInsuranceExpired: DateTime.now().isAfter(DateUtil.convertStringToDate(insuranceVM.patientInsuranceList.first.cardValidTo))); + : insuranceVM.patientInsuranceList.isNotEmpty + ? PatientInsuranceCard( + insuranceCardDetailsModel: insuranceVM.patientInsuranceList.first, + isInsuranceExpired: DateTime.now().isAfter( + DateUtil.convertStringToDate(insuranceVM.patientInsuranceList.first.cardValidTo), + ), + ) + : SizedBox.shrink(); }), SizedBox(height: 10.h), GridView(