You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
RSGDoctorApp/lib/core/viewModel/PatientSearchViewModel.dart

109 lines
3.6 KiB
Dart

5 years ago
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';
5 years ago
import 'package:doctor_app_flutter/util/date-utils.dart';
import '../../locator.dart';
import 'base_view_model.dart';
class PatientSearchViewModel extends BaseViewModel{
OutPatientService _outPatientService = locator<OutPatientService>();
List<PatiantInformtion> get patientList => _outPatientService.patientList;
5 years ago
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;
5 years ago
if(isLocalBusy) {
setState(ViewState.ErrorLocal);
} else {
setState(ViewState.Error);
}
setState(ViewState.Error);
} else {
setState(ViewState.Idle);
}
}
5 years ago
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);
}
}
5 years ago
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
}
}
}
}