first commit
This commit is contained in:
@@ -0,0 +1,90 @@
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,153 @@
|
||||
// GENERATED CODE - DO NOT MODIFY BY HAND
|
||||
|
||||
part of 'dashboard_store.dart';
|
||||
|
||||
// **************************************************************************
|
||||
// StoreGenerator
|
||||
// **************************************************************************
|
||||
|
||||
// ignore_for_file: non_constant_identifier_names, unnecessary_brace_in_string_interps, unnecessary_lambdas, prefer_expression_function_bodies, lines_longer_than_80_chars, avoid_as, avoid_annotating_with_dynamic, no_leading_underscores_for_local_identifiers
|
||||
|
||||
mixin _$DashboardStore on _DashboardStoreBase, Store {
|
||||
late final _$isLoadingAtom = Atom(
|
||||
name: '_DashboardStoreBase.isLoading',
|
||||
context: context,
|
||||
);
|
||||
|
||||
@override
|
||||
bool get isLoading {
|
||||
_$isLoadingAtom.reportRead();
|
||||
return super.isLoading;
|
||||
}
|
||||
|
||||
@override
|
||||
set isLoading(bool value) {
|
||||
_$isLoadingAtom.reportWrite(value, super.isLoading, () {
|
||||
super.isLoading = value;
|
||||
});
|
||||
}
|
||||
|
||||
late final _$doctorInfoAtom = Atom(
|
||||
name: '_DashboardStoreBase.doctorInfo',
|
||||
context: context,
|
||||
);
|
||||
|
||||
@override
|
||||
DoctorInfoModel get doctorInfo {
|
||||
_$doctorInfoAtom.reportRead();
|
||||
return super.doctorInfo;
|
||||
}
|
||||
|
||||
@override
|
||||
set doctorInfo(DoctorInfoModel value) {
|
||||
_$doctorInfoAtom.reportWrite(value, super.doctorInfo, () {
|
||||
super.doctorInfo = value;
|
||||
});
|
||||
}
|
||||
|
||||
late final _$metricsAtom = Atom(
|
||||
name: '_DashboardStoreBase.metrics',
|
||||
context: context,
|
||||
);
|
||||
|
||||
@override
|
||||
DashboardMetricsModel get metrics {
|
||||
_$metricsAtom.reportRead();
|
||||
return super.metrics;
|
||||
}
|
||||
|
||||
@override
|
||||
set metrics(DashboardMetricsModel value) {
|
||||
_$metricsAtom.reportWrite(value, super.metrics, () {
|
||||
super.metrics = value;
|
||||
});
|
||||
}
|
||||
|
||||
late final _$recentPatientsAtom = Atom(
|
||||
name: '_DashboardStoreBase.recentPatients',
|
||||
context: context,
|
||||
);
|
||||
|
||||
@override
|
||||
ObservableList<PatientSummaryModel> get recentPatients {
|
||||
_$recentPatientsAtom.reportRead();
|
||||
return super.recentPatients;
|
||||
}
|
||||
|
||||
@override
|
||||
set recentPatients(ObservableList<PatientSummaryModel> value) {
|
||||
_$recentPatientsAtom.reportWrite(value, super.recentPatients, () {
|
||||
super.recentPatients = value;
|
||||
});
|
||||
}
|
||||
|
||||
late final _$todayAppointmentsAtom = Atom(
|
||||
name: '_DashboardStoreBase.todayAppointments',
|
||||
context: context,
|
||||
);
|
||||
|
||||
@override
|
||||
ObservableList<PatientSummaryModel> get todayAppointments {
|
||||
_$todayAppointmentsAtom.reportRead();
|
||||
return super.todayAppointments;
|
||||
}
|
||||
|
||||
@override
|
||||
set todayAppointments(ObservableList<PatientSummaryModel> value) {
|
||||
_$todayAppointmentsAtom.reportWrite(value, super.todayAppointments, () {
|
||||
super.todayAppointments = value;
|
||||
});
|
||||
}
|
||||
|
||||
late final _$errorMessageAtom = Atom(
|
||||
name: '_DashboardStoreBase.errorMessage',
|
||||
context: context,
|
||||
);
|
||||
|
||||
@override
|
||||
String? get errorMessage {
|
||||
_$errorMessageAtom.reportRead();
|
||||
return super.errorMessage;
|
||||
}
|
||||
|
||||
@override
|
||||
set errorMessage(String? value) {
|
||||
_$errorMessageAtom.reportWrite(value, super.errorMessage, () {
|
||||
super.errorMessage = value;
|
||||
});
|
||||
}
|
||||
|
||||
late final _$loadDashboardDataAsyncAction = AsyncAction(
|
||||
'_DashboardStoreBase.loadDashboardData',
|
||||
context: context,
|
||||
);
|
||||
|
||||
@override
|
||||
Future<void> loadDashboardData() {
|
||||
return _$loadDashboardDataAsyncAction.run(() => super.loadDashboardData());
|
||||
}
|
||||
|
||||
late final _$changeWaitingStatusAsyncAction = AsyncAction(
|
||||
'_DashboardStoreBase.changeWaitingStatus',
|
||||
context: context,
|
||||
);
|
||||
|
||||
@override
|
||||
Future<bool> changeWaitingStatus(int patientId, String nuevoEstado) {
|
||||
return _$changeWaitingStatusAsyncAction.run(
|
||||
() => super.changeWaitingStatus(patientId, nuevoEstado),
|
||||
);
|
||||
}
|
||||
|
||||
@override
|
||||
String toString() {
|
||||
return '''
|
||||
isLoading: ${isLoading},
|
||||
doctorInfo: ${doctorInfo},
|
||||
metrics: ${metrics},
|
||||
recentPatients: ${recentPatients},
|
||||
todayAppointments: ${todayAppointments},
|
||||
errorMessage: ${errorMessage}
|
||||
''';
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user