diff --git a/lib/core/viewModel/PatientSearchViewModel.dart b/lib/core/viewModel/PatientSearchViewModel.dart index 9ef94647..7fbd7d1f 100644 --- a/lib/core/viewModel/PatientSearchViewModel.dart +++ b/lib/core/viewModel/PatientSearchViewModel.dart @@ -16,6 +16,9 @@ class PatientSearchViewModel extends BaseViewModel{ List filterData = []; + DateTime selectedFromDate; + DateTime selectedToDate; + searchData(String str) { var strExist = str.length > 0 ? true : false; if (strExist) { @@ -83,14 +86,19 @@ class PatientSearchViewModel extends BaseViewModel{ String dateTo; String dateFrom; if (item == 'Previous') { + + 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 = DateUtils.convertDateToFormat( - DateTime(DateTime.now().year, DateTime.now().month, - DateTime.now().day-1), + selectedToDate, 'yyyy-MM-dd'); dateFrom = DateUtils.convertDateToFormat( - DateTime(DateTime.now().year, DateTime.now().month-3, - DateTime.now().day), + selectedFromDate, 'yyyy-MM-dd'); + + } else if (item == 'Next Week') { diff --git a/lib/screens/patients/out_patient/filter_date_page.dart b/lib/screens/patients/out_patient/filter_date_page.dart index 034f6136..193c1ec2 100644 --- a/lib/screens/patients/out_patient/filter_date_page.dart +++ b/lib/screens/patients/out_patient/filter_date_page.dart @@ -16,6 +16,7 @@ class FilterDatePage extends StatefulWidget { final OutPatientFilterType outPatientFilterType; final PatientSearchViewModel patientSearchViewModel; + const FilterDatePage( {Key key, this.outPatientFilterType, this.patientSearchViewModel}) : super(key: key); @@ -25,11 +26,15 @@ class FilterDatePage extends StatefulWidget { } class _FilterDatePageState extends State { - DateTime selectedFromDate; - DateTime selectedToDate; + @override + void initState() { + // TODO: implement initState + super.initState(); + } @override Widget build(BuildContext context) { + var screenSize; return AppScaffold( isShowAppBar: false, @@ -77,10 +82,10 @@ class _FilterDatePageState extends State { .of( context) .fromDate, - selectedFromDate != null + widget.patientSearchViewModel.selectedFromDate != null ? "${DateUtils .convertStringToDateFormat( - selectedFromDate.toString(), + widget.patientSearchViewModel.selectedFromDate.toString(), "yyyy-MM-dd")}" : null, true, @@ -110,10 +115,10 @@ class _FilterDatePageState extends State { .of( context) .toDate, - selectedToDate != null + widget.patientSearchViewModel.selectedToDate != null ? "${DateUtils .convertStringToDateFormat( - selectedToDate.toString(), + widget.patientSearchViewModel.selectedToDate.toString(), "yyyy-MM-dd")}" : null, true, @@ -164,31 +169,45 @@ class _FilterDatePageState extends State { padding: 10, color: Color(0xFF359846), onPressed: () async { - if (selectedFromDate == null || - selectedToDate == null) { + if (widget.patientSearchViewModel.selectedFromDate == + null || + widget.patientSearchViewModel.selectedToDate == + null) { Helpers.showErrorToast( "Please Select All The date Fields "); } else { - String dateTo = DateUtils.convertDateToFormat( - selectedToDate, - 'yyyy-MM-dd'); - String dateFrom = DateUtils.convertDateToFormat( - selectedFromDate, - 'yyyy-MM-dd'); + Duration difference = widget + .patientSearchViewModel.selectedToDate + .difference( + widget.patientSearchViewModel.selectedFromDate); + if (difference.inDays > 90) { + Helpers.showErrorToast( + "The difference between from date and end date must be less than 3 months"); + } else { + String dateTo = DateUtils.convertDateToFormat( + widget.patientSearchViewModel.selectedToDate, + 'yyyy-MM-dd'); + String dateFrom = DateUtils.convertDateToFormat( + widget.patientSearchViewModel.selectedFromDate, + 'yyyy-MM-dd'); - PatientSearchRequestModel currentModel = PatientSearchRequestModel(); - currentModel.to = dateTo; - currentModel.from= dateFrom; - GifLoaderDialogUtils.showMyDialog(context); - await widget.patientSearchViewModel.getOutPatient( - currentModel, isLocalBusy: true); - GifLoaderDialogUtils.hideDialog(context); - if(widget.patientSearchViewModel.state == ViewState.ErrorLocal) { - Helpers.showErrorToast(widget.patientSearchViewModel.error); - }else { - Navigator.of(context).pop(); - } + PatientSearchRequestModel currentModel = + PatientSearchRequestModel(); + currentModel.to = dateTo; + currentModel.from = dateFrom; + GifLoaderDialogUtils.showMyDialog(context); + await widget.patientSearchViewModel + .getOutPatient(currentModel, isLocalBusy: true); + GifLoaderDialogUtils.hideDialog(context); + if (widget.patientSearchViewModel.state == + ViewState.ErrorLocal) { + Helpers.showErrorToast( + widget.patientSearchViewModel.error); + } else { + Navigator.of(context).pop(); + } + } } }, ), @@ -208,8 +227,8 @@ class _FilterDatePageState extends State { {bool isFromDate = true, DateTime firstDate, lastDate}) async { Helpers.hideKeyboard(context); DateTime selectedDate = isFromDate - ? this.selectedFromDate ?? firstDate - : this.selectedToDate ?? lastDate; + ? this.widget.patientSearchViewModel.selectedFromDate ?? firstDate + : this.widget.patientSearchViewModel.selectedToDate ?? lastDate; final DateTime picked = await showDatePicker( context: context, initialDate: selectedDate, @@ -220,11 +239,11 @@ class _FilterDatePageState extends State { if (picked != null) { if (isFromDate) { setState(() { - this.selectedFromDate = picked; + this.widget.patientSearchViewModel.selectedFromDate = picked; }); } else { setState(() { - this.selectedToDate = picked; + this.widget.patientSearchViewModel.selectedToDate = picked; }); } } @@ -235,9 +254,9 @@ class _FilterDatePageState extends State { return DateTime( DateTime .now() - .year, DateTime + .year -20, DateTime .now() - .month - 3, DateTime + .month, DateTime .now() .day); } else { @@ -254,14 +273,8 @@ class _FilterDatePageState extends State { getLastDate(OutPatientFilterType outPatientFilterType) { if (outPatientFilterType == OutPatientFilterType.Previous) { - return DateTime( - DateTime - .now() - .year, DateTime - .now() - .month, (DateTime - .now() - .day - 1)); + return DateTime(DateTime.now().year, DateTime.now().month, + DateTime.now().day-1); } else { return DateTime( DateTime diff --git a/lib/screens/patients/out_patient/out_patient_screen.dart b/lib/screens/patients/out_patient/out_patient_screen.dart index f99f791b..953e7722 100644 --- a/lib/screens/patients/out_patient/out_patient_screen.dart +++ b/lib/screens/patients/out_patient/out_patient_screen.dart @@ -199,7 +199,7 @@ class _OutPatientsScreenState extends State { , prefix: IconButton( icon: Icon( - _activeLocation == 1 + _activeLocation !=0 ? DoctorApp.filter_1 : FontAwesomeIcons.slidersH, color: Colors.black, @@ -208,7 +208,7 @@ class _OutPatientsScreenState extends State { padding: EdgeInsets.only( bottom: 30), - onPressed: _activeLocation == 1 ? null : () { + onPressed: _activeLocation !=0 ? null : () { Navigator.push(context, MaterialPageRoute( builder: (BuildContext context) => FilterDatePage(outPatientFilterType: outPatientFilterType,patientSearchViewModel: model,)));