diff --git a/lib/screens/patients/patient_search_screen.dart b/lib/screens/patients/patient_search_screen.dart index de2572f8..cfc2c753 100644 --- a/lib/screens/patients/patient_search_screen.dart +++ b/lib/screens/patients/patient_search_screen.dart @@ -2,6 +2,7 @@ import 'package:doctor_app_flutter/config/shared_pref_kay.dart'; import 'package:doctor_app_flutter/models/patient/patient_model.dart'; import 'package:doctor_app_flutter/routes.dart'; import 'package:doctor_app_flutter/util/dr_app_shared_pref.dart'; +import 'package:doctor_app_flutter/util/helpers.dart'; import 'package:flutter/services.dart'; import '../../config/size_config.dart'; @@ -19,6 +20,7 @@ import '../../config/config.dart'; import '../../models/doctor_profile_model.dart'; DrAppSharedPreferances sharedPref = new DrAppSharedPreferances(); +Helpers helpers = Helpers(); // OWNER : Ibrahim albitar // DATE : 19-04-2020 @@ -32,7 +34,7 @@ class PatientSearchScreen extends StatefulWidget { class _PatientSearchScreenState extends State { String _selectedType = '1'; String _selectedLocation = '1'; - + String error = ''; final GlobalKey _formKey = GlobalKey(); bool _autoValidate = false; @@ -59,45 +61,50 @@ class _PatientSearchScreenState extends State { PatientOutSA: false); void _validateInputs() async { - print("####IBRAHIM TEST#####" + _patientSearchFormValues.From); - // _patientSearchFormValues.TokenID = - List doctorProfiles = await sharedPref.getObj(DOCTOR_PROFILE); - DoctorProfileModel doctorProfile = DoctorProfileModel.fromJson(doctorProfiles[0]); - print(doctorProfile.doctorName); - if (_formKey.currentState.validate()) { + try { + print("####IBRAHIM TEST#####" + _patientSearchFormValues.From); + // _patientSearchFormValues.TokenID = + List doctorProfiles = await sharedPref.getObj(DOCTOR_PROFILE); + DoctorProfileModel doctorProfile = + DoctorProfileModel.fromJson(doctorProfiles[0]); + print(doctorProfile.doctorName); + if (_formKey.currentState.validate()) { //*****If all data are correct then save data to out variables**** - - _patientSearchFormValues.setFrom = "0"; - _patientSearchFormValues.setTo = "0"; - print("***************Check validate1*************"); - - print(_patientSearchFormValues.getFirstName.trim().length); - print("***************Check validate2*************"); + _formKey.currentState.save(); - _patientSearchFormValues.setFrom = "0"; - _patientSearchFormValues.setTo = "0"; - - //*********************************** */ - sharedPref.setString(TOKEN, '@dm!n'); - sharedPref.setString(SLECTED_PATIENT_TYPE, _selectedType); - print('_selectedType${_selectedType}'); - String token = await sharedPref.getString(TOKEN); - int projectID = await sharedPref.getInt(PROJECT_ID); - _patientSearchFormValues.TokenID = token; - _patientSearchFormValues.ProjectID = 15; //projectID; - // print(_patientSearchFormValues.PatientMobileNumber+"dfdfdfddf"); - Navigator.of(context).pushNamed(PATIENTS, arguments: { - "patientSearchForm": _patientSearchFormValues, - "selectedType": _selectedType - }); - } else { + + //*********************************** */ + sharedPref.setString(TOKEN, '@dm!n'); + sharedPref.setString(SLECTED_PATIENT_TYPE, _selectedType); + print('_selectedType${_selectedType}'); + String token = await sharedPref.getString(TOKEN); + int projectID = await sharedPref.getInt(PROJECT_ID); + _patientSearchFormValues.TokenID = token; + _patientSearchFormValues.ProjectID = 15; //projectID; + // print(_patientSearchFormValues.PatientMobileNumber+"dfdfdfddf"); + Navigator.of(context).pushNamed(PATIENTS, arguments: { + "patientSearchForm": _patientSearchFormValues, + "selectedType": _selectedType + }); + } else { // If all data are not valid then start auto validation. - setState(() { - _autoValidate = true; - }); + setState(() { + _autoValidate = true; + }); + } + } catch (err) { + handelCatchErrorCase(err); } } + handelCatchErrorCase(err) { + //isLoading = false; + //isError = true; + error = helpers.generateContactAdminMsg(err); + //notifyListeners(); + throw err; + } + @override Widget build(BuildContext context) { return AppScaffold( @@ -187,17 +194,13 @@ class _PatientSearchScreenState extends State { AppTextFormField( hintText: 'First Name', onSaved: (value) { - // _patientSearchFormValues.FirstName = value; value == null ? _patientSearchFormValues.setFirstName = "0" : _patientSearchFormValues.setFirstName = value; - print("**********Value********"); - print(value.toString().trim().isEmpty); - print("**********Value********"); + if (value.toString().trim().isEmpty) { - _patientSearchFormValues.setFirstName = "0"; } }, @@ -211,19 +214,14 @@ class _PatientSearchScreenState extends State { AppTextFormField( hintText: 'Middle Name', onSaved: (value) { - //_patientSearchFormValues.MiddleName = value; - value == null ? _patientSearchFormValues.setMiddleName = "0" : _patientSearchFormValues.setMiddleName = value; - - // value.toString().trim().isEmpty - // ? _patientSearchFormValues.setMiddleName = - // "0" - // : _patientSearchFormValues.setMiddleName = - // value; + if (value.toString().trim().isEmpty) { + _patientSearchFormValues.setMiddleName = "0"; + } }, // validator: (value) { // return TextValidator().validateName(value); @@ -235,16 +233,13 @@ class _PatientSearchScreenState extends State { AppTextFormField( hintText: 'Last Name', onSaved: (value) { - // _patientSearchFormValues.LastName = value; value == null ? _patientSearchFormValues.setLastName = "0" : _patientSearchFormValues.setLastName = value; - - // value.toString().trim().isEmpty - // ? _patientSearchFormValues.setLastName = "0" - // : _patientSearchFormValues.setLastName = - // value; + if (value.toString().trim().isEmpty) { + _patientSearchFormValues.setLastName = "0"; + } }, // validator: (value) { // return TextValidator().validateName(value); @@ -266,8 +261,11 @@ class _PatientSearchScreenState extends State { .setPatientMobileNumber = "0" : _patientSearchFormValues .setPatientMobileNumber = value; - // _patientSearchFormValues.PatientMobileNumber = - // value; + + if (value.toString().trim().isEmpty) { + _patientSearchFormValues + .setPatientMobileNumber = "0"; + } }, ), SizedBox( @@ -285,6 +283,9 @@ class _PatientSearchScreenState extends State { ? _patientSearchFormValues.setPatientID = 0 : _patientSearchFormValues.setPatientID = int.parse(value); + if (value.toString().trim().isEmpty) { + _patientSearchFormValues.setPatientID = 0; + } }), SizedBox( height: 10, diff --git a/lib/screens/patients/patients_screen.dart b/lib/screens/patients/patients_screen.dart index c8d70165..076473ba 100644 --- a/lib/screens/patients/patients_screen.dart +++ b/lib/screens/patients/patients_screen.dart @@ -15,6 +15,7 @@ import 'package:doctor_app_flutter/routes.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:flutter/material.dart'; import 'package:intl/intl.dart'; import 'package:provider/provider.dart'; @@ -202,7 +203,6 @@ class _PatientsScreenState extends State { return newDate.toString(); } - filterBooking(String str) { this.responseModelList = this.responseModelList2; @@ -231,21 +231,13 @@ class _PatientsScreenState extends State { } } - String checkDate(String dateString) { - String date; DateTime checkedTime = DateTime.parse(dateString); DateTime currentTime = DateTime.now(); - // print("currentTime.day="+currentTime.day.toString()); - // print("checkedTime.day="+checkedTime.day.toString()); - // print("currentTime.month="+currentTime.month.toString()); - // print("checkedTime.month="+checkedTime.month.toString()); - // print("currentTime.year="+currentTime.year.toString()); - // print("checkedTime.year="+checkedTime.year.toString()); + if ((currentTime.year == checkedTime.year) && (currentTime.month == checkedTime.month) && (currentTime.day == checkedTime.day)) { - return "Today"; } else if ((currentTime.year == checkedTime.year) && (currentTime.month == checkedTime.month)) { @@ -254,11 +246,11 @@ class _PatientsScreenState extends State { } else if ((currentTime.day - checkedTime.day) == -1) { return "Tomorrow"; } - + if ((currentTime.day - checkedTime.day) <= -2) { return "Next Week"; } else { - return "Old Date"; + return "Old Date"; } } return "Old Date"; @@ -275,111 +267,118 @@ class _PatientsScreenState extends State { body: patientsProv.isLoading ? DrAppCircularProgressIndeicator() : patientsProv.isError - ? Center( - child: Text( - patientsProv.error, - style: TextStyle(color: Theme.of(context).errorColor), - ), - ) - : Container( - - child: ListView(scrollDirection: Axis.vertical, children: < - Widget>[ - Container( - child: litems == null - ? Column( - children: [ - Container( - child: Center( - child: - Padding( - padding: const EdgeInsets.fromLTRB(0, 250, 0, 0), - child: DrAppCircularProgressIndeicator(), - )), - ), - - ], - ) - : Column( - children: [ - Padding( - padding: EdgeInsets.only( - top: - MediaQuery.of(context).size.height * + ? DrAppEmbeddedError(error: patientsProv.error) + : litems == null + ? DrAppEmbeddedError( + error: 'You don\'t have any ' + + patientTypetitle + + " patiant") + : Container( + child: + ListView(scrollDirection: Axis.vertical, children: < + Widget>[ + Container( + child: litems == null + ? Column( + children: [ + Container( + child: Center( + child: Padding( + padding: const EdgeInsets.fromLTRB( + 0, 250, 0, 0), + child: + DrAppCircularProgressIndeicator(), + )), + ), + ], + ) + : Column( + children: [ + Padding( + padding: EdgeInsets.only( + top: MediaQuery.of(context) + .size + .height * 0.03), - child: SERVICES_PATIANT2[ - int.parse(patientType)] == - "List_MyOutPatient" - ? _locationBar(context) - : Container(), - ), - SizedBox(height: 10.0), - Container( - width: SizeConfig.screenWidth * 0.80, - child: TextField( - controller: _controller, - onChanged: (String str) { - - this.searchData(str); - }, - decoration: buildInputDecoration( - context, 'Search patiant'), - ), - ), - Container( - margin: EdgeInsets.fromLTRB(15, 0, 15, 0), - child: Column( - children: responseModelList - .map((PatiantInformtion item) { - return InkWell( - child: CardWithBgWidget( - widget: Column( - crossAxisAlignment: - CrossAxisAlignment.start, - children: [ - AppText( - item.firstName + - " " + - item.lastName + - "- " + - item.patientId.toString(), - fontSize: 2.5 * - SizeConfig.textMultiplier, - fontWeight: FontWeight.bold, - ), - SizedBox( - height: 8, - ), - SERVICES_PATIANT2[int.parse( - patientType)] == - "List_MyOutPatient" - ? AppText( - convertDate(item - .appointmentDate - .toString()), - fontSize: 2.5 * - SizeConfig - .textMultiplier) - : AppText( - item.nationalityName, - fontSize: 2.5 * - SizeConfig - .textMultiplier) - ], - ), - ), - onTap: () { - Navigator.of(context).pushNamed( - PATIENTS_PROFILE, - arguments: {"patient": item}); + child: SERVICES_PATIANT2[ + int.parse(patientType)] == + "List_MyOutPatient" + ? _locationBar(context) + : Container(), + ), + SizedBox(height: 10.0), + Container( + width: SizeConfig.screenWidth * 0.80, + child: TextField( + controller: _controller, + onChanged: (String str) { + this.searchData(str); }, - ); - }).toList(), - ), - ), - ], - )) - ]))); + decoration: buildInputDecoration( + context, 'Search patiant'), + ), + ), + Container( + margin: + EdgeInsets.fromLTRB(15, 0, 15, 0), + child: Column( + children: responseModelList + .map((PatiantInformtion item) { + return InkWell( + child: CardWithBgWidget( + widget: Column( + crossAxisAlignment: + CrossAxisAlignment.start, + children: [ + AppText( + item.firstName + + " " + + item.lastName + + "- " + + item.patientId + .toString(), + fontSize: 2.5 * + SizeConfig + .textMultiplier, + fontWeight: + FontWeight.bold, + ), + SizedBox( + height: 8, + ), + SERVICES_PATIANT2[int.parse( + patientType)] == + "List_MyOutPatient" + ? AppText( + convertDate(item + .appointmentDate + .toString()), + fontSize: 2.5 * + SizeConfig + .textMultiplier) + : AppText( + item + .nationalityName, + fontSize: 2.5 * + SizeConfig + .textMultiplier) + ], + ), + ), + onTap: () { + Navigator.of(context).pushNamed( + PATIENTS_PROFILE, + arguments: { + "patient": item + }); + }, + ); + }).toList(), + ), + ), + ], + )) + ]))); } //***********amjad update**buildInputDecoration ***to search box******** @@ -422,15 +421,12 @@ class _PatientsScreenState extends State { fontWeight: FontWeight.bold), ), onTap: () { - print(_locations.indexOf(item)); - filterBooking(item.toString()); setState(() { _activeLocation = _locations.indexOf(item); - }); }), _isActive diff --git a/lib/widgets/patients/dynamic_elements.dart b/lib/widgets/patients/dynamic_elements.dart index f8e3e6ac..8b6fc5a8 100644 --- a/lib/widgets/patients/dynamic_elements.dart +++ b/lib/widgets/patients/dynamic_elements.dart @@ -50,35 +50,61 @@ class _DynamicElementsState extends State { AppTextFormField( textInputType: TextInputType.number, hintText: 'From', - controller: _fromDateController, - // validator: (value) { - // return TextValidator().validateDate(_fromDateController.text); - // }, + controller: _fromDateController, //_fromDateController, + inputFormatter: ONLY_DATE, onTap: () { _presentDatePicker('_selectedFromDate'); }, + + // validator: (value) { + // return TextValidator().validateDate(_fromDateController.text); + // }, + /* + *@author: Amjad Amireh + *@Date:13/5/2020 + *@param: + *@return:check if field empty added static value + + *@desc: + */ onSaved: (value) { - widget._patientSearchFormValues.From = _fromDateController.text; + if (_fromDateController.text.toString().trim().isEmpty) { + widget._patientSearchFormValues.From = "0"; + } else { + widget._patientSearchFormValues.From = + _fromDateController.text; + } }, ), - SizedBox( height: 10, ), AppTextFormField( textInputType: TextInputType.number, hintText: 'TO', - controller: _toDateController, + controller: _fromDateController, //_toDateController, onTap: () { _presentDatePicker('_selectedToDate'); }, // validator: (value) { // return TextValidator().validateDate(_toDateController.text); // }, + /* + *@author: Amjad Amireh + *@Date:13/5/2020 + *@param: + *@return:check if field empty added static value + + *@desc: + */ inputFormatter: ONLY_DATE, onSaved: (value) { - widget._patientSearchFormValues.To = _toDateController.text; + if (_toDateController.text.toString().trim().isEmpty) { + widget._patientSearchFormValues.To = "0"; + } else { + widget._patientSearchFormValues.To = _toDateController.text; + } }, ), ],