|
|
|
|
import 'package:doctor_app_flutter/core/enum/filter_type.dart';
|
|
|
|
|
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/patient_muse/PatientSearchRequestModel.dart';
|
|
|
|
|
import 'package:doctor_app_flutter/core/service/patient/out_patient_service.dart';
|
|
|
|
|
import 'package:doctor_app_flutter/core/service/patient/patientInPatientService.dart';
|
|
|
|
|
import 'package:doctor_app_flutter/core/service/special_clinics/special_clinic_service.dart';
|
|
|
|
|
import 'package:doctor_app_flutter/models/dashboard/get_special_clinical_care_mapping_List_Respose_Model.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<OutPatientService>();
|
|
|
|
|
SpecialClinicsService _specialClinicsService = locator<SpecialClinicsService>();
|
|
|
|
|
|
|
|
|
|
List<PatiantInformtion> get patientList => _outPatientService.patientList;
|
|
|
|
|
List<GetSpecialClinicalCareMappingListResponseModel> get specialClinicalCareMappingList => _specialClinicsService.specialClinicalCareMappingList;
|
|
|
|
|
|
|
|
|
|
List<PatiantInformtion> filterData = [];
|
|
|
|
|
|
|
|
|
|
DateTime? selectedFromDate;
|
|
|
|
|
DateTime? selectedToDate;
|
|
|
|
|
|
|
|
|
|
searchData(String str) {
|
|
|
|
|
var strExist = str.length > 0 ? true : false;
|
|
|
|
|
if (strExist) {
|
|
|
|
|
filterData = [];
|
|
|
|
|
for (var i = 0; i < _outPatientService.patientList.length; i++) {
|
|
|
|
|
String firstName = _outPatientService.patientList[i].firstName!.toUpperCase();
|
|
|
|
|
String lastName = _outPatientService.patientList[i].lastName!.toUpperCase();
|
|
|
|
|
String mobile = _outPatientService.patientList[i].mobileNumber!.toUpperCase();
|
|
|
|
|
String patientID = _outPatientService.patientList[i].patientId.toString();
|
|
|
|
|
|
|
|
|
|
if (firstName.contains(str.toUpperCase()) ||
|
|
|
|
|
lastName.contains(str.toUpperCase()) ||
|
|
|
|
|
mobile.contains(str) ||
|
|
|
|
|
patientID.contains(str)) {
|
|
|
|
|
filterData.add(_outPatientService.patientList[i]);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
notifyListeners();
|
|
|
|
|
} else {
|
|
|
|
|
filterData = _outPatientService.patientList;
|
|
|
|
|
notifyListeners();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
getOutPatient(PatientSearchRequestModel patientSearchRequestModel, {bool isLocalBusy = false}) async {
|
|
|
|
|
if (isLocalBusy) {
|
|
|
|
|
setState(ViewState.BusyLocal);
|
|
|
|
|
} else {
|
|
|
|
|
setState(ViewState.Busy);
|
|
|
|
|
}
|
|
|
|
|
await getDoctorProfile(isGetProfile: true);
|
|
|
|
|
patientSearchRequestModel.doctorID = doctorProfile!.doctorID;
|
|
|
|
|
await _outPatientService.getOutPatient(patientSearchRequestModel);
|
|
|
|
|
if (_outPatientService.hasError) {
|
|
|
|
|
error = _outPatientService.error!;
|
|
|
|
|
if (isLocalBusy) {
|
|
|
|
|
setState(ViewState.ErrorLocal);
|
|
|
|
|
} else {
|
|
|
|
|
setState(ViewState.Error);
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
filterData = _outPatientService.patientList;
|
|
|
|
|
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 {
|
|
|
|
|
filterData = _outPatientService.patientList;
|
|
|
|
|
setState(ViewState.Idle);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
getPatientBasedOnDate(
|
|
|
|
|
{item,
|
|
|
|
|
PatientSearchRequestModel? patientSearchRequestModel,
|
|
|
|
|
PatientType? selectedPatientType,
|
|
|
|
|
bool? isSearchWithKeyInfo,
|
|
|
|
|
OutPatientFilterType? outPatientFilterType}) async {
|
|
|
|
|
String dateTo;
|
|
|
|
|
String dateFrom;
|
|
|
|
|
if (OutPatientFilterType.Previous == outPatientFilterType) {
|
|
|
|
|
selectedFromDate = DateTime(DateTime.now().year, DateTime.now().month - 1, DateTime.now().day);
|
|
|
|
|
selectedToDate = DateTime(DateTime.now().year, DateTime.now().month, DateTime.now().day - 1);
|
|
|
|
|
dateTo = AppDateUtils.convertDateToFormat(selectedToDate!, 'yyyy-MM-dd');
|
|
|
|
|
dateFrom = AppDateUtils.convertDateToFormat(selectedFromDate!, 'yyyy-MM-dd');
|
|
|
|
|
} else if (OutPatientFilterType.NextWeek == outPatientFilterType) {
|
|
|
|
|
dateTo = AppDateUtils.convertDateToFormat(
|
|
|
|
|
DateTime(DateTime.now().year, DateTime.now().month, DateTime.now().day + 6), 'yyyy-MM-dd');
|
|
|
|
|
|
|
|
|
|
dateFrom = AppDateUtils.convertDateToFormat(
|
|
|
|
|
DateTime(DateTime.now().year, DateTime.now().month, DateTime.now().day + 1), 'yyyy-MM-dd');
|
|
|
|
|
} else {
|
|
|
|
|
dateFrom = AppDateUtils.convertDateToFormat(
|
|
|
|
|
DateTime(DateTime.now().year, DateTime.now().month, DateTime.now().day), 'yyyy-MM-dd');
|
|
|
|
|
dateTo = AppDateUtils.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.doctorID = patientSearchRequestModel.doctorID;
|
|
|
|
|
currentModel.from = dateFrom;
|
|
|
|
|
currentModel.to = dateTo;
|
|
|
|
|
await getOutPatient(currentModel, isLocalBusy: true);
|
|
|
|
|
filterData = _outPatientService.patientList;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
PatientInPatientService _inPatientService = locator<PatientInPatientService>();
|
|
|
|
|
|
|
|
|
|
List<PatiantInformtion> get inPatientList => _inPatientService.inPatientList;
|
|
|
|
|
|
|
|
|
|
List<PatiantInformtion> get myIinPatientList => _inPatientService.myInPatientList;
|
|
|
|
|
|
|
|
|
|
List<PatiantInformtion> filteredInPatientItems = [];
|
|
|
|
|
|
|
|
|
|
Future getInPatientList(PatientSearchRequestModel requestModel, {bool isMyInpatient = false, bool isLocalBusy = false}) async {
|
|
|
|
|
await getDoctorProfile();
|
|
|
|
|
if(isLocalBusy) {
|
|
|
|
|
setState(ViewState.BusyLocal);
|
|
|
|
|
} else{
|
|
|
|
|
setState(ViewState.Busy);
|
|
|
|
|
}
|
|
|
|
|
if (inPatientList.length == 0) await _inPatientService.getInPatientList(requestModel, false);
|
|
|
|
|
if (_inPatientService.hasError) {
|
|
|
|
|
error = _inPatientService.error!;
|
|
|
|
|
if(isLocalBusy) {
|
|
|
|
|
setState(ViewState.ErrorLocal);
|
|
|
|
|
} else{
|
|
|
|
|
setState(ViewState.Error);
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
// setDefaultInPatientList();
|
|
|
|
|
setState(ViewState.Idle);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Future setDefaultInPatientList() async {
|
|
|
|
|
setState(ViewState.BusyLocal);
|
|
|
|
|
await getDoctorProfile();
|
|
|
|
|
filteredInPatientItems.clear();
|
|
|
|
|
if (inPatientList.length > 0) filteredInPatientItems.addAll(inPatientList);
|
|
|
|
|
setState(ViewState.Idle);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void clearPatientList() {
|
|
|
|
|
_inPatientService.inPatientList = [];
|
|
|
|
|
_inPatientService.myInPatientList = [];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void filterSearchResults(String query) {
|
|
|
|
|
var strExist = query.length > 0 ? true : false;
|
|
|
|
|
if (strExist) {
|
|
|
|
|
filteredInPatientItems = [];
|
|
|
|
|
for (var i = 0; i < inPatientList.length; i++) {
|
|
|
|
|
String firstName = inPatientList[i].firstName!.toUpperCase();
|
|
|
|
|
String lastName = inPatientList[i].lastName!.toUpperCase();
|
|
|
|
|
String mobile = inPatientList[i].mobileNumber!.toUpperCase();
|
|
|
|
|
String patientID = inPatientList[i].patientId.toString();
|
|
|
|
|
|
|
|
|
|
if (firstName.contains(query.toUpperCase()) ||
|
|
|
|
|
lastName.contains(query.toUpperCase()) ||
|
|
|
|
|
mobile.contains(query) ||
|
|
|
|
|
patientID.contains(query)) {
|
|
|
|
|
filteredInPatientItems.add(inPatientList[i]);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
notifyListeners();
|
|
|
|
|
} else {
|
|
|
|
|
if (inPatientList.length > 0) filteredInPatientItems.clear();
|
|
|
|
|
filteredInPatientItems.addAll(inPatientList);
|
|
|
|
|
notifyListeners();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
getSpecialClinicalCareMappingList(clinicId,
|
|
|
|
|
{bool isLocalBusy = false}) async {
|
|
|
|
|
if (isLocalBusy) {
|
|
|
|
|
setState(ViewState.BusyLocal);
|
|
|
|
|
} else {
|
|
|
|
|
setState(ViewState.Busy);
|
|
|
|
|
}
|
|
|
|
|
await _specialClinicsService.getSpecialClinicalCareMappingList(clinicId);
|
|
|
|
|
if (_specialClinicsService.hasError) {
|
|
|
|
|
error = _specialClinicsService.error!;
|
|
|
|
|
if (isLocalBusy) {
|
|
|
|
|
setState(ViewState.ErrorLocal);
|
|
|
|
|
} else {
|
|
|
|
|
setState(ViewState.Error);
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
setState(ViewState.Idle);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|