add filtration on level of clinic

merge-requests/829/head
Elham Rababh 5 years ago
parent 8fc4b1596b
commit 9317173c05

@ -186,30 +186,48 @@ class PatientSearchViewModel extends BaseViewModel {
} }
} else { } else {
setDefaultInPatientList(); setDefaultInPatientList();
generateMyInpatientClinicList(); generateMyInpatientClinicList();
setState(ViewState.Idle); setState(ViewState.Idle);
} }
} }
sortInPatient({bool isDes = false}) { sortInPatient({bool isDes = false, bool isAllClinic}) {
if (isDes) if (isAllClinic
filteredInPatientItems.sort((PatiantInformtion a, PatiantInformtion b) => ? inPatientList.length > 0
b.admissionDateWithDateTimeForm : filteredInPatientItems.length > 0) {
.compareTo(a.admissionDateWithDateTimeForm)); List<PatiantInformtion> localInPatient =
else isAllClinic ? [...inPatientList] : [...filteredInPatientItems];
filteredInPatientItems.sort((PatiantInformtion a, PatiantInformtion b) => if (isDes)
a.admissionDateWithDateTimeForm localInPatient.sort((PatiantInformtion a, PatiantInformtion b) => b
.compareTo(b.admissionDateWithDateTimeForm)); .admissionDateWithDateTimeForm
.compareTo(a.admissionDateWithDateTimeForm));
else
localInPatient.sort((PatiantInformtion a, PatiantInformtion b) => a
.admissionDateWithDateTimeForm
.compareTo(b.admissionDateWithDateTimeForm));
if (isAllClinic) {
resetInPatientPagination();
filteredInPatientItems
.addAll(localInPatient.sublist(firstSubsetIndex, lastSubsetIndex));
} else {
filteredInPatientItems.clear();
filteredInPatientItems.addAll(localInPatient);
}
}
setState(ViewState.Idle); setState(ViewState.Idle);
} }
Future setDefaultInPatientList() async { resetInPatientPagination() {
setState(ViewState.BusyLocal);
await getDoctorProfile();
filteredInPatientItems.clear(); filteredInPatientItems.clear();
firstSubsetIndex = 0; firstSubsetIndex = 0;
lastSubsetIndex = inPatientPageSize - 1; lastSubsetIndex = inPatientPageSize - 1;
}
Future setDefaultInPatientList() async {
setState(ViewState.BusyLocal);
await getDoctorProfile();
resetInPatientPagination();
if (inPatientList.length > 0) if (inPatientList.length > 0)
filteredInPatientItems filteredInPatientItems
.addAll(inPatientList.sublist(firstSubsetIndex, lastSubsetIndex)); .addAll(inPatientList.sublist(firstSubsetIndex, lastSubsetIndex));
@ -218,7 +236,7 @@ class PatientSearchViewModel extends BaseViewModel {
generateMyInpatientClinicList() { generateMyInpatientClinicList() {
inPatientList.forEach((element) { inPatientList.forEach((element) {
if(!myInpatientClinicList.contains(element.clinicDescription)) { if (!myInpatientClinicList.contains(element.clinicDescription)) {
myInpatientClinicList.add(element.clinicDescription); myInpatientClinicList.add(element.clinicDescription);
} }
}); });
@ -240,8 +258,7 @@ class PatientSearchViewModel extends BaseViewModel {
} }
} }
filterByHospital({int hospitalId}) {
filterByHospital({ int hospitalId}) {
filteredInPatientItems = []; filteredInPatientItems = [];
for (var i = 0; i < inPatientList.length; i++) { for (var i = 0; i < inPatientList.length; i++) {
if (inPatientList[i].projectId == hospitalId) { if (inPatientList[i].projectId == hospitalId) {
@ -251,7 +268,7 @@ class PatientSearchViewModel extends BaseViewModel {
notifyListeners(); notifyListeners();
} }
filterByClinic({ String clinicName}) { filterByClinic({String clinicName}) {
filteredInPatientItems = []; filteredInPatientItems = [];
for (var i = 0; i < inPatientList.length; i++) { for (var i = 0; i < inPatientList.length; i++) {
if (inPatientList[i].clinicDescription == clinicName) { if (inPatientList[i].clinicDescription == clinicName) {
@ -266,28 +283,61 @@ class PatientSearchViewModel extends BaseViewModel {
_inPatientService.myInPatientList = []; _inPatientService.myInPatientList = [];
} }
void filterSearchResults(String query) { void filterSearchResults(String query, {bool isAllClinic}) {
var strExist = query.length > 0 ? true : false; var strExist = query.length > 0 ? true : false;
if (strExist) { if (isAllClinic) {
filteredInPatientItems = []; if (strExist) {
for (var i = 0; i < inPatientList.length; i++) { filteredInPatientItems = [];
String firstName = inPatientList[i].firstName.toUpperCase(); for (var i = 0; i < inPatientList.length; i++) {
String lastName = inPatientList[i].lastName.toUpperCase(); String firstName = inPatientList[i].firstName.toUpperCase();
String mobile = inPatientList[i].mobileNumber.toUpperCase(); String lastName = inPatientList[i].lastName.toUpperCase();
String patientID = inPatientList[i].patientId.toString(); String mobile = inPatientList[i].mobileNumber.toUpperCase();
String patientID = inPatientList[i].patientId.toString();
if (firstName.contains(query.toUpperCase()) ||
lastName.contains(query.toUpperCase()) || if (firstName.contains(query.toUpperCase()) ||
mobile.contains(query) || lastName.contains(query.toUpperCase()) ||
patientID.contains(query)) { mobile.contains(query) ||
filteredInPatientItems.add(inPatientList[i]); patientID.contains(query)) {
filteredInPatientItems.add(inPatientList[i]);
}
} }
notifyListeners();
} else {
if (inPatientList.length > 0) filteredInPatientItems.clear();
filteredInPatientItems.addAll(inPatientList);
notifyListeners();
} }
notifyListeners();
} else { } else {
if (inPatientList.length > 0) filteredInPatientItems.clear(); List<PatiantInformtion> localFilteredInPatientItems = [
filteredInPatientItems.addAll(inPatientList); ...filteredInPatientItems
notifyListeners(); ];
if (strExist) {
filteredInPatientItems.clear();
for (var i = 0; i < localFilteredInPatientItems.length; i++) {
String firstName =
localFilteredInPatientItems[i].firstName.toUpperCase();
String lastName =
localFilteredInPatientItems[i].lastName.toUpperCase();
String mobile =
localFilteredInPatientItems[i].mobileNumber.toUpperCase();
String patientID =
localFilteredInPatientItems[i].patientId.toString();
if (firstName.contains(query.toUpperCase()) ||
lastName.contains(query.toUpperCase()) ||
mobile.contains(query) ||
patientID.contains(query)) {
filteredInPatientItems.add(localFilteredInPatientItems[i]);
}
}
notifyListeners();
} else {
if (localFilteredInPatientItems.length > 0)
filteredInPatientItems.clear();
filteredInPatientItems.addAll(localFilteredInPatientItems);
notifyListeners();
}
} }
} }

@ -30,6 +30,7 @@ class _InPatientListPageState extends State<InPatientListPage> {
bool isSortDes = false; bool isSortDes = false;
bool isAllClinic = true; bool isAllClinic = true;
bool hasQuery = false;
bool showBottomSheet = false; bool showBottomSheet = false;
String selectedClinicName; String selectedClinicName;
@ -47,11 +48,8 @@ class _InPatientListPageState extends State<InPatientListPage> {
body: Column( body: Column(
crossAxisAlignment: CrossAxisAlignment.start, crossAxisAlignment: CrossAxisAlignment.start,
children: [ children: [
// Container(
// height: MediaQuery.of(context).size.height * 0.070,
// ),
Container( Container(
margin: EdgeInsets.symmetric(horizontal: 14.0, vertical: 10), margin: EdgeInsets.only(left: 10.0,right: 10, top: 10),
child: Row( child: Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween, mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [ children: [
@ -73,7 +71,10 @@ class _InPatientListPageState extends State<InPatientListPage> {
}, },
activeColor: Colors.red, activeColor: Colors.red,
), ),
AppText("All Clinic", fontSize: 15,), AppText(
"All Clinic",
fontSize: 15,
),
], ],
), ),
onTap: () { onTap: () {
@ -106,7 +107,10 @@ class _InPatientListPageState extends State<InPatientListPage> {
}, },
activeColor: Colors.red, activeColor: Colors.red,
), ),
AppText(selectedClinicName ?? "Select Clinic", fontSize: 15,), AppText(
selectedClinicName ?? "Select Clinic",
fontSize: 15,
),
Container( Container(
margin: EdgeInsets.only(bottom: 10), margin: EdgeInsets.only(bottom: 10),
child: Icon(FontAwesomeIcons.sortDown)) child: Icon(FontAwesomeIcons.sortDown))
@ -116,7 +120,7 @@ class _InPatientListPageState extends State<InPatientListPage> {
), ),
), ),
Container( Container(
margin: EdgeInsets.all(16.0), margin: EdgeInsets.only(left: 16, right: 16, bottom: 16, top:5),
child: Stack( child: Stack(
children: [ children: [
AppTextFieldCustom( AppTextFieldCustom(
@ -131,7 +135,11 @@ class _InPatientListPageState extends State<InPatientListPage> {
), ),
controller: _searchController, controller: _searchController,
onChanged: (value) { onChanged: (value) {
widget.patientSearchViewModel.filterSearchResults(value); setState(() {
hasQuery = true;
});
widget.patientSearchViewModel
.filterSearchResults(value, isAllClinic: isAllClinic);
}), }),
Positioned( Positioned(
right: 35, right: 35,
@ -148,7 +156,7 @@ class _InPatientListPageState extends State<InPatientListPage> {
onPressed: () { onPressed: () {
GifLoaderDialogUtils.showMyDialog(context); GifLoaderDialogUtils.showMyDialog(context);
widget.patientSearchViewModel widget.patientSearchViewModel
.sortInPatient(isDes: isSortDes); .sortInPatient(isDes: isSortDes, isAllClinic:isAllClinic);
isSortDes = !isSortDes; isSortDes = !isSortDes;
GifLoaderDialogUtils.hideDialog(context); GifLoaderDialogUtils.hideDialog(context);
}, },
@ -277,7 +285,7 @@ class _InPatientListPageState extends State<InPatientListPage> {
return SizedBox(); return SizedBox();
}), }),
onNotification: (t) { onNotification: (t) {
if (isAllClinic) if (t if (isAllClinic && !hasQuery) if (t
is ScrollUpdateNotification && is ScrollUpdateNotification &&
t.metrics.pixels >= t.metrics.pixels >=
t.metrics.maxScrollExtent - 50) { t.metrics.maxScrollExtent - 50) {

Loading…
Cancel
Save