From 6fd43a281d3a4840e1baa1b0bd33a4d7c2722fa2 Mon Sep 17 00:00:00 2001 From: ibrahim albitar Date: Sun, 14 Jun 2020 16:02:44 +0300 Subject: [PATCH] fixing --- lib/providers/patients_provider.dart | 84 +++++------- .../profile/refer_patient_screen.dart | 128 ++++++++++++------ lib/widgets/shared/app_text_form_field.dart | 4 +- 3 files changed, 122 insertions(+), 94 deletions(-) diff --git a/lib/providers/patients_provider.dart b/lib/providers/patients_provider.dart index 6da89e74..2d1f4fe1 100644 --- a/lib/providers/patients_provider.dart +++ b/lib/providers/patients_provider.dart @@ -63,7 +63,7 @@ class PatientsProvider with ChangeNotifier { STPReferralFrequencyRequest(); ClinicByProjectIdRequest _clinicByProjectIdRequest = ClinicByProjectIdRequest(); - ReferToDoctorRequest _referToDoctorRequest = ReferToDoctorRequest(); + ReferToDoctorRequest _referToDoctorRequest; PatiantInformtion _selectedPatient; @@ -486,7 +486,7 @@ class PatientsProvider with ChangeNotifier { *@Date:3/6/2020 *@desc: referToDoctor */ - referToDoctor(context, + referToDoctor(context, {String selectedDoctorID, String selectedClinicID, int admissionNo, @@ -500,56 +500,42 @@ class PatientsProvider with ChangeNotifier { int projectID}) async { setBasicData(); try { - if (await Helpers.checkConnection()) { - String token = await sharedPref.getString(TOKEN); - Map profile = await sharedPref.getObj(DOCTOR_PROFILE); - DoctorProfileModel doctorProfile = - new DoctorProfileModel.fromJson(profile); - int doctorID = doctorProfile.doctorID; - int clinicId = doctorProfile.clinicID; - _referToDoctorRequest = ReferToDoctorRequest( - projectID: projectID, - admissionNo: admissionNo, - roomID: roomID, - referralClinic: selectedClinicID.toString(), - referralDoctor: selectedDoctorID.toString(), - createdBy: doctorID, - editedBy: doctorID, - patientID: patientID, - patientTypeID: patientTypeID, - referringClinic: clinicId, - referringDoctor: doctorID, - referringDoctorRemarks: referringDoctorRemarks, - priority: priority, - frequency: frequency, - extension: extension, - tokenID: token); - - final response = await AppClient.post(PATIENT_REFER_TO_DOCTOR_URL, - body: json.encode(_referToDoctorRequest)); - final int statusCode = response.statusCode; - isLoading = false; - - if (statusCode < 200 || statusCode >= 400 || json == null) { - isError = true; - error = 'Error While Fetching data'; - } else { - var res = json.decode(response.body); - print('$res'); - if (res['MessageStatus'] == 1) { - print('Done : \n $res'); + String token = await sharedPref.getString(TOKEN); + Map profile = await sharedPref.getObj(DOCTOR_PROFILE); + DoctorProfileModel doctorProfile = + new DoctorProfileModel.fromJson(profile); + int doctorID = doctorProfile.doctorID; + int clinicId = doctorProfile.clinicID; + _referToDoctorRequest = ReferToDoctorRequest( + projectID: projectID, + admissionNo: admissionNo, + roomID: roomID, + referralClinic: selectedClinicID.toString(), + referralDoctor: selectedDoctorID.toString(), + createdBy: doctorID, + editedBy: doctorID, + patientID: patientID, + patientTypeID: patientTypeID, + referringClinic: clinicId, + referringDoctor: doctorID, + referringDoctorRemarks: referringDoctorRemarks, + priority: priority, + frequency: frequency, + extension: extension, + tokenID: token); + await BaseAppClient.post(PATIENT_REFER_TO_DOCTOR_URL, + onSuccess: (dynamic response, int statusCode) { + // print('Done : \n $res'); Navigator.pop(context); - } else { + }, + onFailure: (String error, int statusCode) { + isLoading = false; isError = true; - error = res['ErrorMessage'] ?? res['ErrorEndUserMessage']; - } - } - } else { - isLoading = false; - isError = true; - error = 'Please Check The Internet Connection'; - } + this.error = error; + }, + body: _referToDoctorRequest.toJson()); notifyListeners(); + } catch (err) { handelCatchErrorCase(err); } diff --git a/lib/screens/patients/profile/refer_patient_screen.dart b/lib/screens/patients/profile/refer_patient_screen.dart index 24146ca5..1da89f97 100644 --- a/lib/screens/patients/profile/refer_patient_screen.dart +++ b/lib/screens/patients/profile/refer_patient_screen.dart @@ -15,6 +15,7 @@ import '../../../util/dr_app_shared_pref.dart'; import '../../../widgets/shared/app_scaffold_widget.dart'; import '../../../widgets/shared/app_texts_widget.dart'; import '../../../widgets/shared/dr_app_circular_progress_Indeicator.dart'; +import '../../../util/extenstions.dart'; DrAppSharedPreferances sharedPref = new DrAppSharedPreferances(); @@ -37,6 +38,7 @@ class _ReferPatientState extends State { final _remarksController = TextEditingController(); final _extController = TextEditingController(); var _isInit = true; + bool isValid; var clinicId; var doctorId; @@ -49,14 +51,17 @@ class _ReferPatientState extends State { List _priorities = ['Very Urgent', 'Urgent', 'Routine']; int _activePriority = 2; + FocusNode myFocusNode; + @override void didChangeDependencies() { super.didChangeDependencies(); if (_isInit) { + myFocusNode = FocusNode(); doctorsList = null; patientsProv = Provider.of(context); patientsProv.getClinicsList(); - patientsProv.getReferralFrequancyList(); + patientsProv.getReferralFrequancyList(); } _isInit = false; } @@ -70,10 +75,9 @@ class _ReferPatientState extends State { : patientsProv.isError ? DrAppEmbeddedError(error: patientsProv.error) : patientsProv.clinicsList == null - ? DrAppEmbeddedError( - error: 'Something Wrong!') + ? DrAppEmbeddedError(error: 'Something Wrong!') : SingleChildScrollView( - child: Column( + child: Column( mainAxisAlignment: MainAxisAlignment.start, crossAxisAlignment: CrossAxisAlignment.start, children: [ @@ -128,13 +132,17 @@ class _ReferPatientState extends State { setState(() { _selectedDoctor = null; _selectedClinic = newValue; - var clinicInfo = patientsProv.clinicsList.where((i) => + var clinicInfo = patientsProv + .clinicsList + .where((i) => i['ClinicDescription'] .toString() - .contains(_selectedClinic)).toList(); - - clinicId = - clinicInfo[0]['ClinicID'].toString(); + .contains( + _selectedClinic)) + .toList(); + + clinicId = clinicInfo[0]['ClinicID'] + .toString(); patientsProv.getDoctorsList(clinicId); }) @@ -208,15 +216,16 @@ class _ReferPatientState extends State { onChanged: (newValue) => { setState(() { _selectedDoctor = newValue; - doctorsList = patientsProv.doctorsList; - - var doctorInfo = - doctorsList.where((i) => - i['DoctorName'] - .toString() - .contains(_selectedDoctor)).toList(); - doctorId = doctorInfo[0]['DoctorID'].toString(); - + doctorsList = + patientsProv.doctorsList; + + var doctorInfo = doctorsList + .where((i) => i['DoctorName'] + .toString() + .contains(_selectedDoctor)) + .toList(); + doctorId = doctorInfo[0]['DoctorID'] + .toString(); }) }, items: patientsProv @@ -320,13 +329,16 @@ class _ReferPatientState extends State { onChanged: (newValue) => { setState(() { _selectedReferralFrequancy = newValue; - var freqInfo = - patientsProv.referalFrequancyList.singleWhere((i) => - i['Description'] - .toString() - .contains(_selectedReferralFrequancy)); - freqId = - freqInfo['ParameterCode'].toString(); + var freqInfo = patientsProv + .referalFrequancyList + .singleWhere((i) => i[ + 'Description'] + .toString() + .contains( + _selectedReferralFrequancy)); + freqId = freqInfo['ParameterCode'] + .toString(); + myFocusNode.requestFocus(); }) }, items: patientsProv @@ -357,6 +369,7 @@ class _ReferPatientState extends State { padding: const EdgeInsets.all(10.0), child: AppTextFormField( hintText: "Remarks", + focusNode: myFocusNode, controller: _remarksController, inputFormatter: ONLY_LETTERS, textInputType: TextInputType.text, @@ -364,14 +377,27 @@ class _ReferPatientState extends State { ), ), Padding( - padding: const EdgeInsets.all(20.0), - child: AppButton(title: "Send", color: Color(PRIMARY_COLOR),onPressed: ()=>{ - referToDoctor(context) - },), - ) + padding: const EdgeInsets.all(20.0), + child: Column( + children: [ + AppText( + "Please fill all fields..!", + color: Colors.red, + fontWeight: FontWeight.bold, + margin: 10, + visibility: + isValid == null ? false : !isValid, + ), + AppButton( + title: "Send", + color: Color(PRIMARY_COLOR), + onPressed: () => {referToDoctor(context)}, + ) + ], + )) ], ), - ), + ), ); } @@ -456,21 +482,35 @@ class _ReferPatientState extends State { return time; } - void referToDoctor(context){ + void referToDoctor(context) { + if (!validation()) { + return; + } + final routeArgs = ModalRoute.of(context).settings.arguments as Map; PatiantInformtion patient = routeArgs['patient']; patientsProv.referToDoctor(context, - extension: _extController.value.text, - admissionNo:int.parse( patient.admissionNo), - referringDoctorRemarks: _remarksController.value.text, - frequency: freqId, - patientID: patient.patientId, - patientTypeID: patient.patientType, - priority: (_activePriority + 1).toString(), - roomID: patient.roomId, - selectedClinicID: clinicId.toString(), - selectedDoctorID: doctorId.toString(), - projectID: patient.projectId - ); + extension: _extController.value.text, + admissionNo: int.parse(patient.admissionNo), + referringDoctorRemarks: _remarksController.value.text, + frequency: freqId, + patientID: patient.patientId, + patientTypeID: patient.patientType, + priority: (_activePriority + 1).toString(), + roomID: patient.roomId, + selectedClinicID: clinicId.toString(), + selectedDoctorID: doctorId.toString(), + projectID: patient.projectId); + } + + bool validation() { + setState(() { + isValid = !_extController.value.text.isNullOrEmpty() && + !_remarksController.value.text.isNullOrEmpty() && + freqId != null && + clinicId != null && + doctorId != null; + }); + return isValid; } } diff --git a/lib/widgets/shared/app_text_form_field.dart b/lib/widgets/shared/app_text_form_field.dart index fd50ad66..06dfb9e7 100644 --- a/lib/widgets/shared/app_text_form_field.dart +++ b/lib/widgets/shared/app_text_form_field.dart @@ -18,7 +18,8 @@ class AppTextFormField extends FormField { TextEditingController controller, bool autovalidate = true, TextInputType textInputType, - String hintText + String hintText, + FocusNode focusNode }) : super( onSaved: onSaved, validator: validator, @@ -27,6 +28,7 @@ class AppTextFormField extends FormField { return Column( children: [ TextFormField( + focusNode: focusNode, keyboardType: textInputType, inputFormatters: [WhitelistingTextInputFormatter(RegExp(inputFormatter)),], onChanged: onChanged?? (value){