|
|
|
|
@ -1,3 +1,5 @@
|
|
|
|
|
import 'dart:async';
|
|
|
|
|
|
|
|
|
|
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/view_state.dart';
|
|
|
|
|
@ -129,11 +131,40 @@ class PatientSearchViewModel extends BaseViewModel {
|
|
|
|
|
List<PatiantInformtion> get inPatientList => _inPatientService.inPatientList;
|
|
|
|
|
|
|
|
|
|
List<PatiantInformtion> get myIinPatientList => _inPatientService.myInPatientList;
|
|
|
|
|
|
|
|
|
|
List<PatiantInformtion> mainList = [];
|
|
|
|
|
List<PatiantInformtion> filteredInPatientItems = [];
|
|
|
|
|
List<PatiantInformtion> filteredMyInPatientItems = [];
|
|
|
|
|
PatientSearchRequestModel? requestModel;
|
|
|
|
|
bool isVidaPlusProject = false;
|
|
|
|
|
bool paginationLoading = false;
|
|
|
|
|
|
|
|
|
|
/// Resets all state variables in the ViewModel to their default values.
|
|
|
|
|
void resetViewModel() {
|
|
|
|
|
// 1. Clear all lists that hold patient data.
|
|
|
|
|
mainList.clear();
|
|
|
|
|
filteredInPatientItems.clear();
|
|
|
|
|
filteredMyInPatientItems.clear();
|
|
|
|
|
_inPatientService.inPatientList.clear();
|
|
|
|
|
_inPatientService.myInPatientList.clear();
|
|
|
|
|
|
|
|
|
|
// 2. Reset the pagination request model and flags.
|
|
|
|
|
requestModel = null;
|
|
|
|
|
isVidaPlusProject = false;
|
|
|
|
|
paginationLoading = false;
|
|
|
|
|
|
|
|
|
|
// 3. Reset pagination counters (if you have them).
|
|
|
|
|
// Based on your code, you have a `resetInPatientPagination` function that does this.
|
|
|
|
|
resetInPatientPagination();
|
|
|
|
|
|
|
|
|
|
// 4. Clear any existing error messages.
|
|
|
|
|
error = null;
|
|
|
|
|
|
|
|
|
|
// 5. Set the view state back to Idle.
|
|
|
|
|
// It's good practice to notify listeners after a major state change.
|
|
|
|
|
setState(ViewState.Idle);
|
|
|
|
|
}
|
|
|
|
|
Future getInPatientList(PatientSearchRequestModel requestModel, {bool isMyInpatient = false, bool isLocalBusy = false, bool isVidaPlusProject = false, bool isForceFullRefresh = false}) async {
|
|
|
|
|
resetViewModel();
|
|
|
|
|
await getDoctorProfile();
|
|
|
|
|
if (isLocalBusy) {
|
|
|
|
|
setState(ViewState.BusyLocal);
|
|
|
|
|
@ -141,6 +172,10 @@ class PatientSearchViewModel extends BaseViewModel {
|
|
|
|
|
setState(ViewState.Busy);
|
|
|
|
|
}
|
|
|
|
|
if (inPatientList.length == 0 || isForceFullRefresh) await _inPatientService.getInPatientList(requestModel, false, isVidaPlusProject: isVidaPlusProject);
|
|
|
|
|
if(isVidaPlusProject) {
|
|
|
|
|
this.requestModel = requestModel;
|
|
|
|
|
this.isVidaPlusProject = isVidaPlusProject;
|
|
|
|
|
}
|
|
|
|
|
if (_inPatientService.hasError) {
|
|
|
|
|
error = _inPatientService.error;
|
|
|
|
|
if (isLocalBusy) {
|
|
|
|
|
@ -154,17 +189,42 @@ class PatientSearchViewModel extends BaseViewModel {
|
|
|
|
|
setState(ViewState.Idle);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
FutureOr<void> paginatedInPatientCall(String? selectedClinicName, String? query, bool? isSortDes,{bool isMyInPatient = false,bool isAllClinic = false }) async {
|
|
|
|
|
|
|
|
|
|
if(isVidaPlusProject = false) return;
|
|
|
|
|
|
|
|
|
|
if(this.requestModel == null) return;
|
|
|
|
|
PatientSearchRequestModel requestModel = this.requestModel!;
|
|
|
|
|
requestModel.pageIndex = (requestModel.pageIndex??0)+1;
|
|
|
|
|
paginationLoading = true;
|
|
|
|
|
notifyListeners();
|
|
|
|
|
await _inPatientService.getInPatientList(requestModel, false, isVidaPlusProject: isVidaPlusProject);
|
|
|
|
|
paginationLoading = false;
|
|
|
|
|
notifyListeners();
|
|
|
|
|
if (_inPatientService.hasError) {
|
|
|
|
|
error = _inPatientService.error;
|
|
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
this.requestModel = requestModel;
|
|
|
|
|
await setDefaultInPatientList(isFromPagination: true);
|
|
|
|
|
generateInpatientClinicList(isFromPagination: true);
|
|
|
|
|
sortInPatient(isDes:isSortDes == true, isAllClinic: isAllClinic, isMyInPatient: isMyInPatient );
|
|
|
|
|
filterSearchResults(query!, isAllClinic: isAllClinic, isMyInPatient: isMyInPatient);
|
|
|
|
|
filterByClinic(clinicName: selectedClinicName!);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
sortInPatient({bool isDes = false, bool isAllClinic = false, bool isMyInPatient = false}) {
|
|
|
|
|
if (isMyInPatient
|
|
|
|
|
? myIinPatientList.length > 0
|
|
|
|
|
: isAllClinic
|
|
|
|
|
? inPatientList.length > 0
|
|
|
|
|
? mainList.length > 0
|
|
|
|
|
: filteredInPatientItems.length > 0) {
|
|
|
|
|
List<PatiantInformtion> localInPatient = isMyInPatient
|
|
|
|
|
? [...filteredMyInPatientItems]
|
|
|
|
|
: isAllClinic
|
|
|
|
|
? [...inPatientList]
|
|
|
|
|
? [...mainList]
|
|
|
|
|
: [...filteredInPatientItems];
|
|
|
|
|
if (isDes)
|
|
|
|
|
localInPatient.sort((PatiantInformtion a, PatiantInformtion b) => b.admissionDateWithDateTimeForm!.compareTo(a.admissionDateWithDateTimeForm!));
|
|
|
|
|
@ -188,16 +248,19 @@ class PatientSearchViewModel extends BaseViewModel {
|
|
|
|
|
filteredInPatientItems.clear();
|
|
|
|
|
firstSubsetIndex = 0;
|
|
|
|
|
lastSubsetIndex = inPatientPageSize - 1;
|
|
|
|
|
requestModel?.pageIndex = 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Future setDefaultInPatientList() async {
|
|
|
|
|
Future setDefaultInPatientList({isFromPagination = false}) async {
|
|
|
|
|
setState(ViewState.BusyLocal);
|
|
|
|
|
await getDoctorProfile();
|
|
|
|
|
resetInPatientPagination();
|
|
|
|
|
if(isFromPagination == false) {
|
|
|
|
|
resetInPatientPagination();
|
|
|
|
|
}
|
|
|
|
|
if (inPatientList.length > 0) {
|
|
|
|
|
lastSubsetIndex = (inPatientList.length < inPatientPageSize - 1 ? inPatientList.length : inPatientPageSize - 1);
|
|
|
|
|
|
|
|
|
|
filteredInPatientItems.addAll(inPatientList.sublist(firstSubsetIndex, lastSubsetIndex));
|
|
|
|
|
// lastSubsetIndex = (inPatientList.length < inPatientPageSize - 1 ? inPatientList.length : inPatientPageSize - 1);
|
|
|
|
|
mainList.addAll(inPatientList);
|
|
|
|
|
filteredInPatientItems.addAll(inPatientList);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (myIinPatientList.length > 0) {
|
|
|
|
|
@ -206,8 +269,10 @@ class PatientSearchViewModel extends BaseViewModel {
|
|
|
|
|
setState(ViewState.Idle);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
generateInpatientClinicList() {
|
|
|
|
|
InpatientClinicList.clear();
|
|
|
|
|
generateInpatientClinicList({bool isFromPagination = false}) {
|
|
|
|
|
if(isFromPagination == false) {
|
|
|
|
|
InpatientClinicList.clear();
|
|
|
|
|
}
|
|
|
|
|
inPatientList.forEach((element) {
|
|
|
|
|
if (!InpatientClinicList.contains(element.clinicDescription)) {
|
|
|
|
|
InpatientClinicList.add(element.clinicDescription!);
|
|
|
|
|
@ -242,15 +307,20 @@ class PatientSearchViewModel extends BaseViewModel {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
filterByClinic({required String clinicName}) {
|
|
|
|
|
if(clinicName.isEmpty) return;
|
|
|
|
|
filteredInPatientItems = [];
|
|
|
|
|
for (var i = 0; i < inPatientList.length; i++) {
|
|
|
|
|
if (inPatientList[i].clinicDescription == clinicName) {
|
|
|
|
|
filteredInPatientItems.add(inPatientList[i]);
|
|
|
|
|
for (var i = 0; i < mainList.length; i++) {
|
|
|
|
|
if (mainList[i].clinicDescription == clinicName) {
|
|
|
|
|
filteredInPatientItems.add(mainList[i]);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
notifyListeners();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void resetFilters(){
|
|
|
|
|
filteredInPatientItems = mainList;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void clearPatientList() {
|
|
|
|
|
_inPatientService.inPatientList = [];
|
|
|
|
|
_inPatientService.myInPatientList = [];
|
|
|
|
|
@ -260,7 +330,7 @@ class PatientSearchViewModel extends BaseViewModel {
|
|
|
|
|
var strExist = query.length > 0 ? true : false;
|
|
|
|
|
|
|
|
|
|
if (isMyInPatient) {
|
|
|
|
|
List<PatiantInformtion> localFilteredMyInPatientItems = [...myIinPatientList];
|
|
|
|
|
List<PatiantInformtion> localFilteredMyInPatientItems = [...filteredMyInPatientItems];
|
|
|
|
|
|
|
|
|
|
if (strExist) {
|
|
|
|
|
filteredMyInPatientItems.clear();
|
|
|
|
|
@ -276,28 +346,28 @@ class PatientSearchViewModel extends BaseViewModel {
|
|
|
|
|
}
|
|
|
|
|
notifyListeners();
|
|
|
|
|
} else {
|
|
|
|
|
if (myIinPatientList.length > 0) filteredMyInPatientItems.clear();
|
|
|
|
|
filteredMyInPatientItems.addAll(myIinPatientList);
|
|
|
|
|
if (filteredMyInPatientItems.length > 0) filteredMyInPatientItems.clear();
|
|
|
|
|
filteredMyInPatientItems.addAll(localFilteredMyInPatientItems);
|
|
|
|
|
notifyListeners();
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
if (isAllClinic) {
|
|
|
|
|
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();
|
|
|
|
|
for (var i = 0; i < mainList.length; i++) {
|
|
|
|
|
String firstName = mainList[i].firstName!.toUpperCase();
|
|
|
|
|
String lastName = mainList[i].lastName!.toUpperCase();
|
|
|
|
|
String mobile = mainList[i].mobileNumber!.toUpperCase();
|
|
|
|
|
String patientID = mainList[i].patientId.toString();
|
|
|
|
|
|
|
|
|
|
if (firstName.contains(query.toUpperCase()) || lastName.contains(query.toUpperCase()) || mobile.contains(query) || patientID.contains(query)) {
|
|
|
|
|
filteredInPatientItems.add(inPatientList[i]);
|
|
|
|
|
filteredInPatientItems.add(mainList[i]);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
notifyListeners();
|
|
|
|
|
} else {
|
|
|
|
|
if (inPatientList.length > 0) filteredInPatientItems.clear();
|
|
|
|
|
filteredInPatientItems.addAll(inPatientList);
|
|
|
|
|
if (mainList.length > 0) filteredInPatientItems.clear();
|
|
|
|
|
filteredInPatientItems.addAll(mainList);
|
|
|
|
|
notifyListeners();
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
|