import 'package:doctor_app_flutter/core/enum/patient_type.dart'; import 'package:doctor_app_flutter/core/enum/viewstate.dart'; import 'package:doctor_app_flutter/core/model/PatientSearchRequestModel.dart'; import 'package:doctor_app_flutter/core/service/patient/out_patient_service.dart'; import 'package:doctor_app_flutter/models/patient/patiant_info_model.dart'; import 'package:doctor_app_flutter/util/date-utils.dart'; import '../../locator.dart'; import 'base_view_model.dart'; class PatientSearchViewModel extends BaseViewModel{ OutPatientService _outPatientService = locator(); List get patientList => _outPatientService.patientList; getOutPatient(PatientSearchRequestModel patientSearchRequestModel , {bool isLocalBusy = false}) async { if(isLocalBusy) { setState(ViewState.BusyLocal); } else { setState(ViewState.Busy); } await _outPatientService.getOutPatient( patientSearchRequestModel); if (_outPatientService.hasError) { error = _outPatientService.error; if(isLocalBusy) { setState(ViewState.ErrorLocal); } else { setState(ViewState.Error); } setState(ViewState.Error); } else { setState(ViewState.Idle); } } getPatientFileInformation(PatientSearchRequestModel patientSearchRequestModel, {bool isLocalBusy = false}) async { setState(ViewState.Busy); await _outPatientService.getPatientFileInformation( patientSearchRequestModel); if (_outPatientService.hasError) { error = _outPatientService.error; setState(ViewState.Error); } else { setState(ViewState.Idle); } } getPatientBasedOnDate ( {item, PatientSearchRequestModel patientSearchRequestModel, PatientType selectedPatientType, bool isSearchWithKeyInfo })async { String dateTo; String dateFrom; if (item == 'Tomorrow') { dateTo = DateUtils.convertDateToFormat( DateTime(DateTime.now().year, DateTime.now().month, DateTime.now().day + 1), 'yyyy-MM-dd'); dateFrom = DateUtils.convertDateToFormat( DateTime(DateTime.now().year, DateTime.now().month, DateTime.now().day + 1), 'yyyy-MM-dd'); } else if (item == 'Next Week') { dateTo = DateUtils.convertDateToFormat( DateTime(DateTime.now().year, DateTime.now().month, DateTime.now().day + 6), 'yyyy-MM-dd'); dateFrom = DateUtils.convertDateToFormat( DateTime(DateTime.now().year, DateTime.now().month, DateTime.now().day + 1), 'yyyy-MM-dd'); } else { dateFrom = DateUtils.convertDateToFormat( DateTime( DateTime.now().year, DateTime.now().month, DateTime.now().day), 'yyyy-MM-dd'); dateTo= DateUtils.convertDateToFormat( DateTime( DateTime.now().year, DateTime.now().month, DateTime.now().day), 'yyyy-MM-dd'); } PatientSearchRequestModel currentModel = PatientSearchRequestModel(); currentModel.patientID = patientSearchRequestModel.patientID; currentModel.firstName = patientSearchRequestModel.firstName; currentModel.lastName = patientSearchRequestModel.lastName; currentModel.middleName = patientSearchRequestModel.middleName; currentModel.from = dateFrom; currentModel.to = dateTo; if(isSearchWithKeyInfo) { await getPatientFileInformation(currentModel); } else { if(selectedPatientType == PatientType.OutPatient) { await getOutPatient(currentModel, isLocalBusy: true); } else { // TODO handel inPatient case } } } }