diff --git a/lib/core/viewModel/PatientSearchViewModel.dart b/lib/core/viewModel/PatientSearchViewModel.dart index 455e8788..fc37cbed 100644 --- a/lib/core/viewModel/PatientSearchViewModel.dart +++ b/lib/core/viewModel/PatientSearchViewModel.dart @@ -1,7 +1,9 @@ +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/PatientSearchRequestModel.dart'; import 'package:doctor_app_flutter/core/service/patient/out_patient_service.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'; @@ -11,19 +13,29 @@ class PatientSearchViewModel extends BaseViewModel{ List get patientList => _outPatientService.patientList; - getOutPatient(PatientSearchRequestModel patientSearchRequestModel) async { - setState(ViewState.Busy); + getOutPatient(PatientSearchRequestModel patientSearchRequestModel , {bool isLocalBusy = false}) async { + if(isLocalBusy) { + setState(ViewState.BusyLocal); + } else { + setState(ViewState.Busy); + } + await _outPatientService.getOutPatient( patientSearchRequestModel); if (_outPatientService.hasError) { error = _outPatientService.error; + if(isLocalBusy) { + setState(ViewState.ErrorLocal); + } else { + setState(ViewState.Error); + } setState(ViewState.Error); } else { setState(ViewState.Idle); } } - getPatientFileInformation(PatientSearchRequestModel patientSearchRequestModel) async { + getPatientFileInformation(PatientSearchRequestModel patientSearchRequestModel, {bool isLocalBusy = false}) async { setState(ViewState.Busy); await _outPatientService.getPatientFileInformation( patientSearchRequestModel); @@ -35,4 +47,63 @@ class PatientSearchViewModel extends BaseViewModel{ } } + + + getPatientBasedOnDate ( + {item, PatientSearchRequestModel patientSearchRequestModel, PatientType selectedPatientType, + bool isSearchWithKeyInfo })async { + String dateTo; + String dateFrom; + if (item == 'Tomorrow') { + dateTo = DateUtils.convertDateToFormat( + DateTime(DateTime.now().year, DateTime.now().month, + DateTime.now().day + 1), + 'yyyy-MM-dd'); + dateFrom = DateUtils.convertDateToFormat( + DateTime(DateTime.now().year, DateTime.now().month, + DateTime.now().day + 1), + 'yyyy-MM-dd'); + } else if (item == 'Next Week') { + + + dateTo = DateUtils.convertDateToFormat( + DateTime(DateTime.now().year, DateTime.now().month, + DateTime.now().day + 6), + 'yyyy-MM-dd'); + + dateFrom = DateUtils.convertDateToFormat( + DateTime(DateTime.now().year, DateTime.now().month, + DateTime.now().day + 1), + 'yyyy-MM-dd'); + } else { + dateFrom = DateUtils.convertDateToFormat( + DateTime( + DateTime.now().year, DateTime.now().month, DateTime.now().day), + 'yyyy-MM-dd'); + dateTo= DateUtils.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.from = dateFrom; + currentModel.to = dateTo; + + + if(isSearchWithKeyInfo) { + await getPatientFileInformation(currentModel); + } else { + if(selectedPatientType == PatientType.OutPatient) { + await getOutPatient(currentModel, isLocalBusy: true); + } else { + // TODO handel inPatient case + } + } + + } + } \ No newline at end of file diff --git a/lib/screens/home/home_screen.dart b/lib/screens/home/home_screen.dart index 47bc1d0b..f81cb803 100644 --- a/lib/screens/home/home_screen.dart +++ b/lib/screens/home/home_screen.dart @@ -465,44 +465,6 @@ class _HomeScreenState extends State { child: new ListView( scrollDirection: Axis.horizontal, children: [ - HomePageCard( - color: Colors.black, - margin: EdgeInsets.all(5), - child: Column( - mainAxisAlignment: - MainAxisAlignment.center, - crossAxisAlignment: - CrossAxisAlignment.start, - children: [ - Padding( - padding: EdgeInsets.only( - top: 10, left: 10, right: 0), - child: Icon( - DoctorApp.search, - size: 32, - color: Colors.white, - )), - Container( - padding: EdgeInsets.all(10), - child: AppText( - "New:"+TranslationBase.of(context) - .searchPatient, - color: Colors.white, - textAlign: TextAlign.start, - fontSize: 13, - )) - ], - ), - hasBorder: false, - onTap: () { - Navigator.push( - context, - MaterialPageRoute( - builder: (context) => - PatientSearchScreenNew(), - )); - }, - ), HomePageCard( color: Colors.red[800], margin: EdgeInsets.all(5), @@ -574,15 +536,22 @@ class _HomeScreenState extends State { ), hasBorder: false, onTap: () { - getRequestHeader(false); - Navigator.of(context) - .pushNamed(PATIENTS, arguments: { - "patientSearchForm": - _patientSearchFormValues, - "selectedType": "0", - "arrivalType": "1", - "isInpatient": false - }); + // getRequestHeader(false); + // Navigator.of(context) + // .pushNamed(PATIENTS, arguments: { + // "patientSearchForm": + // _patientSearchFormValues, + // "selectedType": "0", + // "arrivalType": "1", + // "isInpatient": false + // }); + + Navigator.push( + context, + MaterialPageRoute( + builder: (context) => + PatientSearchScreenNew(), + )); }, ), HomePageCard( diff --git a/lib/screens/patients/patient_search/patient_search_screen_new.dart b/lib/screens/patients/patient_search/patient_search_screen_new.dart index f383cf40..7da76ec2 100644 --- a/lib/screens/patients/patient_search/patient_search_screen_new.dart +++ b/lib/screens/patients/patient_search/patient_search_screen_new.dart @@ -2,7 +2,7 @@ import 'package:doctor_app_flutter/core/enum/patient_type.dart'; import 'package:doctor_app_flutter/core/model/PatientSearchRequestModel.dart'; import 'package:doctor_app_flutter/core/viewModel/PatientSearchViewModel.dart'; import 'package:doctor_app_flutter/screens/base/base_view.dart'; -import 'package:doctor_app_flutter/screens/patients/patient_search/patients_screen_new.dart'; +import 'package:doctor_app_flutter/screens/patients/patient_search/patients_screen_search.dart'; import 'package:doctor_app_flutter/screens/patients/profile/soap_update/shared_soap_widgets/bottom_sheet_title.dart'; import 'package:doctor_app_flutter/util/translations_delegate_base.dart'; import 'package:doctor_app_flutter/widgets/shared/app_scaffold_widget.dart'; diff --git a/lib/screens/patients/patient_search/patients_screen_new.dart b/lib/screens/patients/patient_search/patients_screen_search.dart similarity index 75% rename from lib/screens/patients/patient_search/patients_screen_new.dart rename to lib/screens/patients/patient_search/patients_screen_search.dart index 5b3b5a77..d78f41d2 100644 --- a/lib/screens/patients/patient_search/patients_screen_new.dart +++ b/lib/screens/patients/patient_search/patients_screen_search.dart @@ -15,7 +15,7 @@ import 'package:doctor_app_flutter/models/patient/patient_model.dart'; import 'package:doctor_app_flutter/models/patient/topten_users_res_model.dart'; import 'package:doctor_app_flutter/routes.dart'; import 'package:doctor_app_flutter/screens/base/base_view.dart'; -import 'package:doctor_app_flutter/util/date-utils.dart'; +import 'package:doctor_app_flutter/screens/patients/profile/soap_update/shared_soap_widgets/bottom_sheet_title.dart'; import 'package:doctor_app_flutter/util/helpers.dart'; import 'package:doctor_app_flutter/util/translations_delegate_base.dart'; import 'package:doctor_app_flutter/widgets/patients/PatientCard.dart'; @@ -23,7 +23,6 @@ import 'package:doctor_app_flutter/widgets/patients/clinic_list_dropdwon.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/dr_app_circular_progress_Indeicator.dart'; -import 'package:doctor_app_flutter/widgets/shared/errors/dr_app_embedded_error.dart'; import 'package:doctor_app_flutter/widgets/shared/loader/gif_loader_dialog_utils.dart'; import 'package:doctor_app_flutter/widgets/shared/text_fields/app_text_form_field.dart'; import 'package:flutter/material.dart'; @@ -92,27 +91,6 @@ class _PatientsScreenNewState extends State { final _controller = TextEditingController(); PatientModel patient; - var _patientSearchFormValues = PatientModel( - FirstName: "0", - MiddleName: "0", - LastName: "0", - PatientMobileNumber: "0", - PatientIdentificationID: "0", - PatientID: 0, - From: DateUtils.convertDateToFormat(DateTime.now(), 'yyyy-MM-dd') - .toString(), - To: DateUtils.convertDateToFormat(DateTime.now(), 'yyyy-MM-dd') - .toString(), - LanguageID: 2, - stamp: "2020-03-02T13:56:39.170Z", - IPAdress: "11.11.11.11", - VersionID: 1.2, - Channel: 9, - TokenID: "2Fi7HoIHB0eDyekVa6tCJg==", - SessionID: "5G0yXn0Jnq", - IsLoginForDoctorApp: true, - PatientOutSA: false); - searchData(String str) { this.responseModelList = this.responseModelList2; var strExist = str.length > 0 ? true : false; @@ -217,8 +195,7 @@ class _PatientsScreenNewState extends State { }, builder: (_, model, w) => AppScaffold( appBarTitle: "Search Patient", - isShowAppBar: widget.isAppbar, - // isLoading: _isLoading, + isShowAppBar: false, baseViewModel: model, body: model.patientList.isEmpty ? Column( @@ -227,18 +204,20 @@ class _PatientsScreenNewState extends State { SizedBox( height: 10.0, ), - if (widget.selectedPatientType == PatientType.OutPatient) - Container( - padding: EdgeInsets.all(5), - decoration: BoxDecoration( - color: Colors.white, - border: Border.all(color: Colors.grey), - borderRadius: BorderRadius.circular(10)), - child: ClinicList( - clinicId: clinicId, - onClinicChange: (newValue) { - clinicId = newValue; - changeClinic(newValue, context, model); + if (widget.selectedPatientType == + PatientType.OutPatient && + !widget.isSearchWithKeyInfo) + Container( + padding: EdgeInsets.all(5), + decoration: BoxDecoration( + color: Colors.white, + border: Border.all(color: Colors.grey), + borderRadius: BorderRadius.circular(10)), + child: ClinicList( + clinicId: clinicId, + onClinicChange: (newValue) { + clinicId = newValue; + changeClinic(newValue, context, model); }, )), Padding( @@ -247,7 +226,8 @@ class _PatientsScreenNewState extends State { 0.03), // child: _locationBar(context) child: - widget.selectedPatientType == PatientType.OutPatient + (widget.selectedPatientType == PatientType.OutPatient && + widget.isSearchWithKeyInfo) ? _locationBar(context, model) : Container(), ) @@ -298,6 +278,47 @@ class _PatientsScreenNewState extends State { ) : Column( children: [ + + Container( + padding: EdgeInsets.only( + left: 0, right: 5, bottom: 5, top: 5), + decoration: BoxDecoration( + color: Colors.white, + ), + height: 115, + child: Container( + padding: EdgeInsets.only( + left: 10, right: 10), + margin: EdgeInsets.only(top: 60), + child: Column( + children: [ + Row( + mainAxisAlignment: + MainAxisAlignment.spaceBetween, + children: [ + RichText( + text: TextSpan( + style: TextStyle( + fontSize:20, + color: Colors.black), + children: [ + new TextSpan( + + text: "Search for 1111", + style: TextStyle( + color: Color(0xFF2B353E), + fontWeight: FontWeight.bold, + fontFamily: 'Poppins', + fontSize: 22)), + ], + ), + ), + ], + ), + ], + ), + ), + ), SizedBox(height: 18.5), Container( width: SizeConfig.screenWidth * 0.9, @@ -351,7 +372,9 @@ class _PatientsScreenNewState extends State { .height * 0.03), // child: _locationBar(context) - child: widget.selectedPatientType == PatientType.OutPatient? _locationBar(context, model) + child: widget.selectedPatientType == + PatientType.OutPatient && !widget.isSearchWithKeyInfo + ? _locationBar(context, model) : Container(), ), SizedBox( @@ -522,6 +545,7 @@ class _PatientsScreenNewState extends State { }); } + //TODO Replace it with time bar. Widget _locationBar(BuildContext _context, model) { return Container( height: MediaQuery.of(context).size.height * 0.0619, @@ -567,13 +591,17 @@ class _PatientsScreenNewState extends State { ), )), ), - onTap: () { - //filterBooking(item.toString()); - + onTap: () async { setState(() { _activeLocation = _locations.indexOf(item); }); - filterPatient(item.toString(), model); + GifLoaderDialogUtils.showMyDialog(context); + await model.getPatientBasedOnDate(item: item, + selectedPatientType: widget.selectedPatientType, + patientSearchRequestModel: widget + .patientSearchRequestModel, + isSearchWithKeyInfo: widget.isSearchWithKeyInfo); + GifLoaderDialogUtils.hideDialog(context); }), _isActive ? Container( @@ -592,141 +620,4 @@ class _PatientsScreenNewState extends State { ), ); } - - filterPatient(item, model) { - if (item == 'Tomorrow') { - _patientSearchFormValues.To = DateUtils.convertDateToFormat( - DateTime(DateTime.now().year, DateTime.now().month, - DateTime.now().day + 1), - 'yyyy-MM-dd'); - _patientSearchFormValues.From = DateUtils.convertDateToFormat( - DateTime(DateTime.now().year, DateTime.now().month, - DateTime.now().day + 1), - 'yyyy-MM-dd'); - } else if (item == 'Next Week') { - _patientSearchFormValues.From = DateUtils.convertDateToFormat( - DateTime(DateTime.now().year, DateTime.now().month, - DateTime.now().day + 1), - 'yyyy-MM-dd'); - - _patientSearchFormValues.To = DateUtils.convertDateToFormat( - DateTime(DateTime.now().year, DateTime.now().month, - DateTime.now().day + 6), - 'yyyy-MM-dd'); - } else { - _patientSearchFormValues.From = DateUtils.convertDateToFormat( - DateTime( - DateTime.now().year, DateTime.now().month, DateTime.now().day), - 'yyyy-MM-dd'); - _patientSearchFormValues.To = DateUtils.convertDateToFormat( - DateTime( - DateTime.now().year, DateTime.now().month, DateTime.now().day), - 'yyyy-MM-dd'); - } - searchPatient(model); - } - - searchPatient(model) { - GifLoaderDialogUtils.showMyDialog(context); - int val2 = int.parse(patientType); - GetPatientArrivalListRequestModel getPatientArrivalListRequestModel; - if (val2 == 0) { - patient = PatientModel( - From: _patientSearchFormValues.From, - To: _patientSearchFormValues.To, - FirstName: "0", - MiddleName: "0", - LastName: "0", - PatientMobileNumber: "0", - PatientIdentificationID: "0", - PatientID: 0, - ); - } - - model - .getPatientList( - val2 == 7 ? getPatientArrivalListRequestModel.toJson() : patient, - patientType, - isView: isView) - .then((res) { - setState(() { - GifLoaderDialogUtils.hideDialog(context); - if (res != null && res['MessageStatus'] == 1) { - if (val2 == 7) { - if (res[SERVICES_PATIANT2[val2]] == null) { - _isError = true; - _isLoading = false; - this.error = error.toString(); - } else { - var localList = []; - if (res["patientArrivalList"]["entityList"] == null) { - res["patientArrivalList"]["entityList"] = []; - } - res["patientArrivalList"]["entityList"].forEach((v) { - Map mergedPatient = { - ...v, - ...v["patientDetails"] - }; - localList.add(mergedPatient); - }); - lItems = localList; - } - } else { - if (isView == false && val2 == 1) { - lItems = res['GetPatientFileInformation_PRMList'] - .where((i) => i['PatientTypeDescription'] == 'Permanent File') - .toList(); - } else { - lItems = res[SERVICES_PATIANT2[val2]]; - } - } - parsed = lItems; - responseModelList = new ModelResponse.fromJson(parsed).list; - if (val2 == 7) { - responseModelList.sort((a, b) { - if (b.startTime != null && b.startTime != null) { - try { - DateTime now = DateTime.now(); - DateFormat dateFormat = DateFormat("yyyy-MM-dd HH:mm"); - String formattedDate = - DateFormat('yyyy-MM-dd ' + a.startTime).format(now); - DateTime dateTimeA = dateFormat.parse(formattedDate); - String formattedDateB = - DateFormat('yyyy-MM-dd ' + b.startTime).format(now); - DateTime dateTimeB = dateFormat.parse(formattedDateB); - var adate = dateTimeA; //a.startTime; - var bdate = dateTimeB; - return adate.compareTo(bdate); - } on Exception catch (_) { - print('never reached'); - var adate = a.startTime; //a.startTime; - var bdate = b.startTime; - return adate.compareTo(bdate); - } - } else { - var adate = convertDateFormat(a.appointmentDate); - var bdate = convertDateFormat(b.appointmentDate); - return bdate.compareTo(adate); - } - }); - } - responseModelList2 = responseModelList; - _isError = false; - } else { - _isError = true; - error = - model.error ?? res['ErrorEndUserMessage'] ?? res['ErrorMessage']; - } - - _isLoading = false; - }); - }).catchError((error) { - GifLoaderDialogUtils.hideDialog(context); - setState(() { - _isError = true; - _isLoading = false; - this.error = error.toString(); - }); - }); - } } diff --git a/lib/screens/patients/patient_search/time_bar.dart b/lib/screens/patients/patient_search/time_bar.dart new file mode 100644 index 00000000..0d376b02 --- /dev/null +++ b/lib/screens/patients/patient_search/time_bar.dart @@ -0,0 +1,102 @@ +import 'package:doctor_app_flutter/config/size_config.dart'; +import 'package:doctor_app_flutter/core/enum/patient_type.dart'; +import 'package:doctor_app_flutter/core/model/PatientSearchRequestModel.dart'; +import 'package:doctor_app_flutter/core/viewModel/PatientSearchViewModel.dart'; +import 'package:doctor_app_flutter/util/translations_delegate_base.dart'; +import 'package:doctor_app_flutter/widgets/shared/loader/gif_loader_dialog_utils.dart'; +import 'package:flutter/material.dart'; +import 'package:hexcolor/hexcolor.dart'; + +class TimeBar extends StatefulWidget { + final PatientSearchViewModel model; + final PatientType selectedPatientType; + final PatientSearchRequestModel patientSearchRequestModel; + final bool isSearchWithKeyInfo; + + + const TimeBar({Key key, this.model, this.selectedPatientType, this.patientSearchRequestModel, this.isSearchWithKeyInfo}) : super(key: key); + @override + _TimeBarState createState() => _TimeBarState(); +} + +class _TimeBarState extends State { + + + @override + Widget build(BuildContext context) { + List _locations = [ + TranslationBase.of(context).today, + TranslationBase.of(context).tomorrow, + TranslationBase.of(context).nextWeek, + ]; + int _activeLocation = 0; + return Container( + height: MediaQuery.of(context).size.height * 0.0619, + width: SizeConfig.screenWidth * 0.94, + decoration: BoxDecoration( + color: Color(0Xffffffff), + borderRadius: BorderRadius.circular(12.5), + // border: Border.all( + // width: 0.5, + // ), + ), + child: Row( + mainAxisAlignment: MainAxisAlignment.spaceEvenly, + mainAxisSize: MainAxisSize.max, + crossAxisAlignment: CrossAxisAlignment.center, + children: _locations.map((item) { + bool _isActive = _locations[_activeLocation] == item ? true : false; + return Column(mainAxisSize: MainAxisSize.min, children: [ + InkWell( + child: Center( + child: Container( + height: MediaQuery.of(context).size.height * 0.058, + width: SizeConfig.screenWidth * 0.2334, + decoration: BoxDecoration( + borderRadius: BorderRadius.only( + bottomRight: Radius.circular(12.5), + topRight: Radius.circular(12.5), + topLeft: Radius.circular(9.5), + bottomLeft: Radius.circular(9.5)), + color: _isActive ? HexColor("#B8382B") : Colors.white, + ), + child: Center( + child: Text( + item, + style: TextStyle( + fontSize: 12, + color: _isActive + ? Colors.white + : Colors.black, //Colors.black, + + fontWeight: FontWeight.normal, + ), + ), + )), + ), + onTap: () async{ + setState(() { + _activeLocation = _locations.indexOf(item); + }); + GifLoaderDialogUtils.showMyDialog(context); + await widget.model.getPatientBasedOnDate(item:item,selectedPatientType:widget.selectedPatientType, patientSearchRequestModel:widget.patientSearchRequestModel, isSearchWithKeyInfo:widget.isSearchWithKeyInfo); + GifLoaderDialogUtils.hideDialog(context); + }), + _isActive + ? Container( + decoration: BoxDecoration( + borderRadius: BorderRadius.only( + bottomRight: Radius.circular(10), + topRight: Radius.circular(10)), + color: Colors.white), + alignment: Alignment.center, + height: 1, + width: SizeConfig.screenWidth * 0.23, + ) + : Container() + ]); + }).toList(), + ), + ); + } +}