91 lines
2.6 KiB
Dart
91 lines
2.6 KiB
Dart
import 'package:mobx/mobx.dart';
|
|||
|
|
import '../../data/models/dashboard_metrics_model.dart';
|
||
|
|
import '../../data/models/doctor_info_model.dart';
|
||
|
|
import '../../data/models/patient_summary_model.dart';
|
||
|
|
import '../../data/services/dashboard_service.dart';
|
||
|
|
|
||
|
|
part 'dashboard_store.g.dart';
|
||
|
|
|
||
|
|
// ignore: library_private_types_in_public_api
|
||
|
|
class DashboardStore = _DashboardStoreBase with _$DashboardStore;
|
||
|
|
|
||
|
|
abstract class _DashboardStoreBase with Store {
|
||
|
|
final DashboardService service;
|
||
|
|
|
||
|
|
_DashboardStoreBase({DashboardService? dashboardService})
|
||
|
|
: service = dashboardService ?? DashboardService();
|
||
|
|
|
||
|
|
@observable
|
||
|
|
bool isLoading = true;
|
||
|
|
|
||
|
|
@observable
|
||
|
|
DoctorInfoModel doctorInfo = const DoctorInfoModel(
|
||
|
|
nombreDoctor: 'Dr. Luis A. Castro Sosa',
|
||
|
|
especialidad: 'Cirujano Urólogo',
|
||
|
|
descripEspecialidad: '',
|
||
|
|
descripGeneral: '',
|
||
|
|
);
|
||
|
|
|
||
|
|
@observable
|
||
|
|
DashboardMetricsModel metrics = const DashboardMetricsModel();
|
||
|
|
|
||
|
|
@observable
|
||
|
|
ObservableList<PatientSummaryModel> recentPatients = ObservableList<PatientSummaryModel>();
|
||
|
|
|
||
|
|
@observable
|
||
|
|
ObservableList<PatientSummaryModel> todayAppointments = ObservableList<PatientSummaryModel>();
|
||
|
|
|
||
|
|
@observable
|
||
|
|
String? errorMessage;
|
||
|
|
|
||
|
|
int get enEsperaCount =>
|
||
|
|
todayAppointments.where((a) => a.isEnEspera).length;
|
||
|
|
|
||
|
|
@action
|
||
|
|
Future<void> loadDashboardData() async {
|
||
|
|
isLoading = true;
|
||
|
|
errorMessage = null;
|
||
|
|
try {
|
||
|
|
final config = await service.getDoctorConfig();
|
||
|
|
final metricsData = await service.getDashboardMetrics();
|
||
|
|
final recents = await service.getRecentPatients();
|
||
|
|
final appts = await service.getTodayAppointments();
|
||
|
|
|
||
|
|
runInAction(() {
|
||
|
|
doctorInfo = config;
|
||
|
|
metrics = metricsData;
|
||
|
|
recentPatients = ObservableList.of(recents);
|
||
|
|
todayAppointments = ObservableList.of(appts);
|
||
|
|
isLoading = false;
|
||
|
|
});
|
||
|
|
} catch (e) {
|
||
|
|
runInAction(() {
|
||
|
|
errorMessage = e.toString();
|
||
|
|
isLoading = false;
|
||
|
|
});
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
@action
|
||
|
|
Future<bool> changeWaitingStatus(int patientId, String nuevoEstado) async {
|
||
|
|
final success = await service.updatePatientWaitingStatus(patientId, nuevoEstado);
|
||
|
|
if (success) {
|
||
|
|
runInAction(() {
|
||
|
|
final index = todayAppointments.indexWhere((p) => p.id == patientId);
|
||
|
|
if (index != -1) {
|
||
|
|
todayAppointments[index] =
|
||
|
|
todayAppointments[index].copyWith(estadoEspera: nuevoEstado);
|
||
|
|
}
|
||
|
|
final recentIndex = recentPatients.indexWhere((p) => p.id == patientId);
|
||
|
|
if (recentIndex != -1) {
|
||
|
|
recentPatients[recentIndex] =
|
||
|
|
recentPatients[recentIndex].copyWith(estadoEspera: nuevoEstado);
|
||
|
|
}
|
||
|
|
});
|
||
|
|
}
|
||
|
|
return success;
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
|