|
|
|
|
@ -1,19 +1,12 @@
|
|
|
|
|
import 'package:flutter/material.dart';
|
|
|
|
|
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/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';
|
|
|
|
|
import 'package:hmg_patient_app_new/services/error_handler_service.dart';
|
|
|
|
|
import 'package:location/location.dart' show Location;
|
|
|
|
|
|
|
|
|
|
import '../../core/utils/doctor_response_mapper.dart' show DoctorMapper;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class MyAppointmentsViewModel extends ChangeNotifier {
|
|
|
|
|
int selectedTabIndex = 0;
|
|
|
|
|
|
|
|
|
|
@ -26,30 +19,24 @@ class MyAppointmentsViewModel extends ChangeNotifier {
|
|
|
|
|
bool isTimeLineAppointmentsLoading = false;
|
|
|
|
|
bool isPatientMyDoctorsLoading = false;
|
|
|
|
|
|
|
|
|
|
List<PatientAppointmentHistoryResponseModel> patientAppointmentsHistoryList =
|
|
|
|
|
[];
|
|
|
|
|
List<PatientAppointmentHistoryResponseModel> patientAppointmentsHistoryList = [];
|
|
|
|
|
|
|
|
|
|
List<PatientAppointmentHistoryResponseModel>
|
|
|
|
|
patientUpcomingAppointmentsHistoryList = [];
|
|
|
|
|
List<PatientAppointmentHistoryResponseModel>
|
|
|
|
|
patientArrivedAppointmentsHistoryList = [];
|
|
|
|
|
List<PatientAppointmentHistoryResponseModel> patientUpcomingAppointmentsHistoryList = [];
|
|
|
|
|
List<PatientAppointmentHistoryResponseModel> patientArrivedAppointmentsHistoryList = [];
|
|
|
|
|
|
|
|
|
|
List<PatientAppointmentHistoryResponseModel> patientTimelineAppointmentsList =
|
|
|
|
|
[];
|
|
|
|
|
List<PatientAppointmentHistoryResponseModel> patientTimelineAppointmentsList = [];
|
|
|
|
|
|
|
|
|
|
List<PatientAppointmentHistoryResponseModel> patientMyDoctorsList = [];
|
|
|
|
|
|
|
|
|
|
PatientAppointmentShareResponseModel? patientAppointmentShareResponseModel;
|
|
|
|
|
|
|
|
|
|
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();
|
|
|
|
|
@ -83,8 +70,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;
|
|
|
|
|
@ -92,18 +78,12 @@ class MyAppointmentsViewModel extends ChangeNotifier {
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Future<void> 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<void> 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: () {});
|
|
|
|
|
@ -119,8 +99,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: () {});
|
|
|
|
|
@ -135,27 +114,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<void> 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<void> 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: () {});
|
|
|
|
|
@ -172,19 +143,11 @@ class MyAppointmentsViewModel extends ChangeNotifier {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Future<void> 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: () {});
|
|
|
|
|
@ -199,21 +162,11 @@ class MyAppointmentsViewModel extends ChangeNotifier {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Future<void> 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: () {});
|
|
|
|
|
@ -227,18 +180,11 @@ class MyAppointmentsViewModel extends ChangeNotifier {
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Future<void> cancelAppointment(
|
|
|
|
|
{required PatientAppointmentHistoryResponseModel
|
|
|
|
|
patientAppointmentHistoryResponseModel,
|
|
|
|
|
Function(dynamic)? onSuccess,
|
|
|
|
|
Function(String)? onError}) async {
|
|
|
|
|
final result = await myAppointmentsRepo.cancelAppointment(
|
|
|
|
|
patientAppointmentHistoryResponseModel:
|
|
|
|
|
patientAppointmentHistoryResponseModel);
|
|
|
|
|
Future<void> 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!);
|
|
|
|
|
@ -253,18 +199,11 @@ class MyAppointmentsViewModel extends ChangeNotifier {
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Future<void> confirmAppointment(
|
|
|
|
|
{required PatientAppointmentHistoryResponseModel
|
|
|
|
|
patientAppointmentHistoryResponseModel,
|
|
|
|
|
Function(dynamic)? onSuccess,
|
|
|
|
|
Function(String)? onError}) async {
|
|
|
|
|
final result = await myAppointmentsRepo.confirmAppointment(
|
|
|
|
|
patientAppointmentHistoryResponseModel:
|
|
|
|
|
patientAppointmentHistoryResponseModel);
|
|
|
|
|
Future<void> 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!);
|
|
|
|
|
@ -301,8 +240,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: () {});
|
|
|
|
|
@ -317,21 +255,15 @@ class MyAppointmentsViewModel extends ChangeNotifier {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Future<void> 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!);
|
|
|
|
|
@ -346,13 +278,14 @@ class MyAppointmentsViewModel extends ChangeNotifier {
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Future<void> getPatientMyDoctors(
|
|
|
|
|
{Function(dynamic)? onSuccess, Function(String)? onError}) async {
|
|
|
|
|
Future<void> 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: () {});
|
|
|
|
|
|