From e9e86e4d8ca0db11004926772c052e59c1997560 Mon Sep 17 00:00:00 2001 From: Elham Rababh Date: Wed, 8 Sep 2021 17:57:40 +0300 Subject: [PATCH] add filter on in patient screen by clinic and by all clinic --- .../viewModel/PatientSearchViewModel.dart | 33 ++++ .../In_patient/in_patient_list_page.dart | 158 +++++++++++++++--- .../In_patient/in_patient_screen.dart | 2 +- 3 files changed, 173 insertions(+), 20 deletions(-) diff --git a/lib/core/viewModel/PatientSearchViewModel.dart b/lib/core/viewModel/PatientSearchViewModel.dart index 7f8437b2..43d8b221 100644 --- a/lib/core/viewModel/PatientSearchViewModel.dart +++ b/lib/core/viewModel/PatientSearchViewModel.dart @@ -32,6 +32,8 @@ class PatientSearchViewModel extends BaseViewModel { int inPatientPageSize = 20; int lastSubsetIndex = 19; + List myInpatientClinicList = []; + searchData(String str) { var strExist = str.length > 0 ? true : false; if (strExist) { @@ -184,6 +186,8 @@ class PatientSearchViewModel extends BaseViewModel { } } else { setDefaultInPatientList(); + + generateMyInpatientClinicList(); setState(ViewState.Idle); } } @@ -212,6 +216,14 @@ class PatientSearchViewModel extends BaseViewModel { setState(ViewState.Idle); } + generateMyInpatientClinicList() { + inPatientList.forEach((element) { + if(!myInpatientClinicList.contains(element.clinicDescription)) { + myInpatientClinicList.add(element.clinicDescription); + } + }); + } + addOnFilteredList() { if (lastSubsetIndex < inPatientList.length) { firstSubsetIndex = firstSubsetIndex + @@ -228,6 +240,27 @@ class PatientSearchViewModel extends BaseViewModel { } } + + filterByHospital({ int hospitalId}) { + filteredInPatientItems = []; + for (var i = 0; i < inPatientList.length; i++) { + if (inPatientList[i].projectId == hospitalId) { + filteredInPatientItems.add(inPatientList[i]); + } + } + notifyListeners(); + } + + filterByClinic({ String clinicName}) { + filteredInPatientItems = []; + for (var i = 0; i < inPatientList.length; i++) { + if (inPatientList[i].clinicDescription == clinicName) { + filteredInPatientItems.add(inPatientList[i]); + } + } + notifyListeners(); + } + void clearPatientList() { _inPatientService.inPatientList = []; _inPatientService.myInPatientList = []; diff --git a/lib/screens/patients/In_patient/in_patient_list_page.dart b/lib/screens/patients/In_patient/in_patient_list_page.dart index 56804071..80acb88d 100644 --- a/lib/screens/patients/In_patient/in_patient_list_page.dart +++ b/lib/screens/patients/In_patient/in_patient_list_page.dart @@ -5,6 +5,7 @@ import 'package:doctor_app_flutter/util/translations_delegate_base.dart'; import 'package:doctor_app_flutter/widgets/patients/patient_card/PatientCard.dart'; import 'package:doctor_app_flutter/widgets/shared/app_loader_widget.dart'; import 'package:doctor_app_flutter/widgets/shared/app_scaffold_widget.dart'; +import 'package:doctor_app_flutter/widgets/shared/app_texts_widget.dart'; import 'package:doctor_app_flutter/widgets/shared/errors/error_message.dart'; import 'package:doctor_app_flutter/widgets/shared/loader/gif_loader_container.dart'; import 'package:doctor_app_flutter/widgets/shared/loader/gif_loader_dialog_utils.dart'; @@ -28,6 +29,9 @@ class _InPatientListPageState extends State { TextEditingController _searchController = TextEditingController(); bool isSortDes = false; + bool isAllClinic = true; + bool showBottomSheet = false; + String selectedClinicName; @override void dispose() { @@ -43,8 +47,73 @@ class _InPatientListPageState extends State { body: Column( crossAxisAlignment: CrossAxisAlignment.start, children: [ + // Container( + // height: MediaQuery.of(context).size.height * 0.070, + // ), Container( - height: MediaQuery.of(context).size.height * 0.070, + margin: EdgeInsets.symmetric(horizontal: 14.0, vertical: 10), + child: Row( + mainAxisAlignment: MainAxisAlignment.spaceBetween, + children: [ + InkWell( + child: Row( + children: [ + Radio( + value: 1, + groupValue: isAllClinic ? 1 : 2, + onChanged: (value) { + setState(() { + setState(() { + isAllClinic = true; + showBottomSheet = false; + }); + widget.patientSearchViewModel + .setDefaultInPatientList(); + }); + }, + activeColor: Colors.red, + ), + AppText("All Clinic", fontSize: 15,), + ], + ), + onTap: () { + setState(() { + isAllClinic = true; + showBottomSheet = false; + }); + widget.patientSearchViewModel.setDefaultInPatientList(); + }, + ), + InkWell( + onTap: () { + setState(() { + isAllClinic = false; + showBottomSheet = true; + }); + }, + child: Row( + children: [ + Radio( + value: 2, + groupValue: isAllClinic ? 1 : 2, + onChanged: (value) { + setState(() { + setState(() { + isAllClinic = false; + showBottomSheet = true; + }); + }); + }, + activeColor: Colors.red, + ), + AppText(selectedClinicName ?? "Select Clinic", fontSize: 15,), + Container( + margin: EdgeInsets.only(bottom: 10), + child: Icon(FontAwesomeIcons.sortDown)) + ], + )), + ], + ), ), Container( margin: EdgeInsets.all(16.0), @@ -103,7 +172,7 @@ class _InPatientListPageState extends State { itemCount: widget.patientSearchViewModel .filteredInPatientItems.length, scrollDirection: Axis.vertical, - physics: ScrollPhysics(), + // physics: ScrollPhysics(), shrinkWrap: true, itemBuilder: (context, index) { if (!widget.isMyInPatient) @@ -116,16 +185,14 @@ class _InPatientListPageState extends State { isInpatient: true, isMyPatient: widget .patientSearchViewModel - .filteredInPatientItems[ - index] + .filteredInPatientItems[index] .doctorId == widget.patientSearchViewModel .doctorProfile.doctorID, onTap: () { FocusScopeNode currentFocus = FocusScope.of(context); - if (!currentFocus - .hasPrimaryFocus) { + if (!currentFocus.hasPrimaryFocus) { currentFocus.unfocus(); } @@ -133,8 +200,9 @@ class _InPatientListPageState extends State { PATIENTS_PROFILE, arguments: { "patient": widget - .patientSearchViewModel - .filteredInPatientItems[index], + .patientSearchViewModel + .filteredInPatientItems[ + index], "patientType": "1", "from": "0", "to": "0", @@ -155,8 +223,7 @@ class _InPatientListPageState extends State { ); else if (widget .patientSearchViewModel - .filteredInPatientItems[ - index] + .filteredInPatientItems[index] .doctorId == widget.patientSearchViewModel .doctorProfile.doctorID && @@ -170,16 +237,14 @@ class _InPatientListPageState extends State { isInpatient: true, isMyPatient: widget .patientSearchViewModel - .filteredInPatientItems[ - index] + .filteredInPatientItems[index] .doctorId == widget.patientSearchViewModel .doctorProfile.doctorID, onTap: () { FocusScopeNode currentFocus = FocusScope.of(context); - if (!currentFocus - .hasPrimaryFocus) { + if (!currentFocus.hasPrimaryFocus) { currentFocus.unfocus(); } @@ -187,8 +252,9 @@ class _InPatientListPageState extends State { PATIENTS_PROFILE, arguments: { "patient": widget - .patientSearchViewModel - .filteredInPatientItems[index], + .patientSearchViewModel + .filteredInPatientItems[ + index], "patientType": "1", "from": "0", "to": "0", @@ -210,9 +276,13 @@ class _InPatientListPageState extends State { else return SizedBox(); }), - onNotification: (t) { - if (t is ScrollUpdateNotification && t.metrics.pixels >= t.metrics.maxScrollExtent - 50 ) { - widget.patientSearchViewModel.addOnFilteredList(); + onNotification: (t) { + if (isAllClinic) if (t + is ScrollUpdateNotification && + t.metrics.pixels >= + t.metrics.maxScrollExtent - 50) { + widget.patientSearchViewModel + .addOnFilteredList(); } return; }, @@ -228,6 +298,56 @@ class _InPatientListPageState extends State { ), ], ), + bottomSheet: !showBottomSheet + ? Container( + height: 0, + ) + : Container( + height: 500, + color: Colors.white, + child: ListView.builder( + itemCount: widget + .patientSearchViewModel.myInpatientClinicList.length, + scrollDirection: Axis.vertical, + physics: ScrollPhysics(), + shrinkWrap: true, + itemBuilder: (context, index) { + return InkWell( + onTap: () { + setState(() { + isAllClinic = false; + showBottomSheet = false; + selectedClinicName = widget.patientSearchViewModel + .myInpatientClinicList[index]; + }); + widget.patientSearchViewModel.filterByClinic( + clinicName: widget.patientSearchViewModel + .myInpatientClinicList[index]); + }, + child: Row( + children: [ + Radio( + value: widget.patientSearchViewModel + .myInpatientClinicList[index], + groupValue: selectedClinicName, + onChanged: (value) { + setState(() { + setState(() { + isAllClinic = false; + showBottomSheet = false; + }); + widget.patientSearchViewModel + .filterByClinic(clinicName: value); + }); + }, + activeColor: Colors.red, + ), + AppText(widget.patientSearchViewModel + .myInpatientClinicList[index]), + ], + )); + }), + ), ); } } diff --git a/lib/screens/patients/In_patient/in_patient_screen.dart b/lib/screens/patients/In_patient/in_patient_screen.dart index 76052d23..1a35ad53 100644 --- a/lib/screens/patients/In_patient/in_patient_screen.dart +++ b/lib/screens/patients/In_patient/in_patient_screen.dart @@ -221,7 +221,7 @@ class _InPatientScreenState extends State ), Expanded( child: Scaffold( - extendBodyBehindAppBar: true, + extendBodyBehindAppBar: false, appBar: PreferredSize( preferredSize: Size.fromHeight( MediaQuery.of(context).size.height * 0.070),