From 8cb5171bc98d392e8748642fb07e959ec9ba83a2 Mon Sep 17 00:00:00 2001 From: RoaaGhali98 Date: Tue, 8 Feb 2022 15:56:06 +0200 Subject: [PATCH] Refactor add_prescription_form --- lib/core/service/patient/patient_service.dart | 2 +- .../viewModel/prescription_view_model.dart | 9 +- .../prescription_form_widget.dart | 194 ++++++++---------- .../prescription/prescriptions_page.dart | 13 +- .../procedures/add-favourite-procedure.dart | 10 +- .../base_add_procedure_tab_page.dart | 34 ++- 6 files changed, 121 insertions(+), 141 deletions(-) diff --git a/lib/core/service/patient/patient_service.dart b/lib/core/service/patient/patient_service.dart index 437e5186..5ec06b0f 100644 --- a/lib/core/service/patient/patient_service.dart +++ b/lib/core/service/patient/patient_service.dart @@ -209,7 +209,7 @@ class PatientService extends BaseService { super.error = error; }, body: patient, - ); + ); return patient; } Future getOutPatientPrescriptions(patient) async { diff --git a/lib/core/viewModel/prescription_view_model.dart b/lib/core/viewModel/prescription_view_model.dart index d79c9f95..787b4f78 100644 --- a/lib/core/viewModel/prescription_view_model.dart +++ b/lib/core/viewModel/prescription_view_model.dart @@ -294,13 +294,14 @@ class PrescriptionViewModel extends BaseViewModel { } } - getPrescriptions(PatiantInformtion patient, {String patientType}) async { - setState(ViewState.BusyLocal); + getPrescriptions(PatiantInformtion patient, {String patientType, bool isLocalBusy = true}) async { + if(isLocalBusy) + setState(ViewState.BusyLocal); else setState(ViewState.Busy); await _prescriptionsService.getPrescriptions(patient); if (_prescriptionsService.hasError) { error = _prescriptionsService.error; - if (patientType == "7") - setState(ViewState.ErrorLocal); + if (isLocalBusy) + setState(ViewState.Error); else setState(ViewState.ErrorLocal); } else { diff --git a/lib/screens/prescription/add_prescription/prescription_form_widget.dart b/lib/screens/prescription/add_prescription/prescription_form_widget.dart index 1e68c388..e83c9348 100644 --- a/lib/screens/prescription/add_prescription/prescription_form_widget.dart +++ b/lib/screens/prescription/add_prescription/prescription_form_widget.dart @@ -192,92 +192,92 @@ class _PrescriptionFormWidgetState extends State { ], ), ), - Container( - width: double.infinity, - child: Row( - children: [ - Container( - width: MediaQuery.of(context).size.width * 0.35, - child: AppTextFieldCustom( - height: 38, - validationError: strengthError, - hintText: 'Strength', - isTextFieldHasSuffix: false, - enabled: true, - controller: strengthController, - onChanged: (String value) { - setState(() { - strengthChar = value.length; - }); - if (strengthChar >= 5) { - DrAppToastMsg.showErrorToast( - TranslationBase.of(context) - .only5DigitsAllowedForStrength, - ); - } - }, - inputType: TextInputType.numberWithOptions( - decimal: true, - ), - ), - ), - SizedBox( - width: 5.0, - ), - // Container( - // width: MediaQuery.of(context) - // .size - // .width * - // 0.35, - // child: AppTextFieldCustom( - // height: 38, - // validationError: - // unitError, - // hintText: 'Unit', - // isTextFieldHasSuffix: false, - // enabled: true, - // controller: - // unitController, - // onChanged: (selectedValue) { - // setState(() { - // units = selectedValue; - // units['isDefault'] = true; - // }); - // if (strengthChar >= 5) { - // DrAppToastMsg - // .showErrorToast( - // TranslationBase.of( - // context) - // .only5DigitsAllowedForStrength, - // ); - // } - // }, - // inputType: TextInputType - // .numberWithOptions( - // decimal: true, - // ), - // ), - // ), - PrescriptionTextFiled( - width: MediaQuery.of(context).size.width * 0.510, - element: - widget.medicineViewModel.itemMedicineListUnit.length == 1 - ? widget.medicineViewModel.itemMedicineListUnit[0] - : units, - elementError: unitError, - keyName: 'description', - keyId: 'parameterCode', - hintText: 'Unit', - elementList: widget.medicineViewModel.itemMedicineListUnit, - okFunction: (selectedValue) { + Row( + children: [ + Container( + width: MediaQuery.of(context).size.width * 0.35, + child: AppTextFieldCustom( + validationError: strengthError, + hintText: 'Strength', + isTextFieldHasSuffix: false, + enabled: true, + controller: strengthController, + onChanged: (String value) { setState(() { - units = selectedValue; - units['isDefault'] = true; + strengthChar = value.length; }); + if (strengthChar >= 5) { + DrAppToastMsg.showErrorToast( + TranslationBase.of(context) + .only5DigitsAllowedForStrength, + ); + } }, + inputType: TextInputType.numberWithOptions( + decimal: true, + ), ), - ], - ), + + + + + ), + SizedBox( + width: 5.0, + ), + // Container( + // width: MediaQuery.of(context) + // .size + // .width * + // 0.35, + // child: AppTextFieldCustom( + // height: 38, + // validationError: + // unitError, + // hintText: 'Unit', + // isTextFieldHasSuffix: false, + // enabled: true, + // controller: + // unitController, + // onChanged: (selectedValue) { + // setState(() { + // units = selectedValue; + // units['isDefault'] = true; + // }); + // if (strengthChar >= 5) { + // DrAppToastMsg + // .showErrorToast( + // TranslationBase.of( + // context) + // .only5DigitsAllowedForStrength, + // ); + // } + // }, + // inputType: TextInputType + // .numberWithOptions( + // decimal: true, + // ), + // ), + // ), + PrescriptionTextFiled( + width: MediaQuery.of(context).size.width * 0.510, + element: + widget.medicineViewModel.itemMedicineListUnit.length == 1 + ? widget.medicineViewModel.itemMedicineListUnit[0] + : units, + elementError: unitError, + keyName: 'description', + keyId: 'parameterCode', + hintText: 'Unit', + elementList: widget.medicineViewModel.itemMedicineListUnit, + okFunction: (selectedValue) { + setState(() { + units = selectedValue; + units['isDefault'] = true; + }); + }, + ), + ], ), SizedBox(height: spaceBetweenTextFields), PrescriptionTextFiled( @@ -378,8 +378,7 @@ class _PrescriptionFormWidgetState extends State { ], ), ), - SizedBox(height: spaceBetweenTextFields), - Container( + SizedBox(height: spaceBetweenTextFields), Container( color: Colors.transparent, child: InkWell( onTap: () => selectDate(context, widget.prescriptionViewModel), @@ -397,7 +396,6 @@ class _PrescriptionFormWidgetState extends State { ? "${AppDateUtils.convertStringToDateFormat(selectedDate.toString(), "yyyy-MM-dd")}" : null, enabled: false, - controller: strengthController, ), // TextField( @@ -538,32 +536,6 @@ class _PrescriptionFormWidgetState extends State { } } - openDrugToDrug( - MedicineViewModel medicineViewModel, PrescriptionViewModel modelPrescription) { - showModalBottomSheet( - context: context, - builder: (context) { - return AddDrugWidget( - patient: widget.patient, - medicineModel: widget.medicineViewModel, - modelPrescription: widget.prescriptionViewModel, - prescriptionList: widget.prescriptionList, - route: route, - doseTime: doseTime, - duration: duration, - frequency: frequency, - units: units, - uom: uom, - x: x, - selectedMedication: widget.selectedMedication, - strength: strengthController.text, - indication: indicationController.text, - instruction: instructionController.text, - selectedDate: selectedDate, - ); - }); - } - addMedicationButton(MedicineViewModel model) async { await locator().logEvent( eventCategory: "Add Prescription Form", diff --git a/lib/screens/prescription/prescriptions_page.dart b/lib/screens/prescription/prescriptions_page.dart index 40bebf17..8ae6148e 100644 --- a/lib/screens/prescription/prescriptions_page.dart +++ b/lib/screens/prescription/prescriptions_page.dart @@ -27,23 +27,16 @@ class PrescriptionsPage extends StatelessWidget { @override Widget build(BuildContext context) { final routeArgs = ModalRoute.of(context).settings.arguments as Map; - PatientViewModel patientViewModel; PatiantInformtion patient = routeArgs['patient']; String patientType = routeArgs['patientType']; String arrivalType = routeArgs['arrivalType']; bool isInpatient = routeArgs['isInpatient']; bool isFromLiveCare = routeArgs['isFromLiveCare']; - bool isSelectInpatient = routeArgs['isSelectInpatient']; return BaseView( onModelReady: (model) async { - await model.getOutPatientPrescriptions( - patient.admissionNo == null - ? model.getPrescriptions(patient, patientType: patientType) - : model.getMedicationForInPatient(patient), - isLocalBusy: true, - context: context, - patientInformation: patient - ); + patient.admissionNo == null + ? model.getPrescriptions(patient, patientType: patientType, isLocalBusy: false) + : model.getMedicationForInPatient(patient); }, builder: (_, model, w) => AppScaffold( baseViewModel: model, diff --git a/lib/screens/procedures/add-favourite-procedure.dart b/lib/screens/procedures/add-favourite-procedure.dart index ff84dcf0..e24af0b3 100644 --- a/lib/screens/procedures/add-favourite-procedure.dart +++ b/lib/screens/procedures/add-favourite-procedure.dart @@ -48,9 +48,7 @@ class _AddFavouriteProcedureState extends State { @override Widget build(BuildContext context) { return BaseView( - onModelReady: (model) async { - }, - builder: (BuildContext context, ProcedureViewModel model, Widget child) => + builder: (BuildContext context, ProcedureViewModel model_, Widget child) => AppScaffold( isShowAppBar: false, baseViewModel: model, @@ -59,12 +57,12 @@ class _AddFavouriteProcedureState extends State { Container( height: MediaQuery.of(context).size.height * 0.070, ), - (model.templateList.length != 0) + (widget.previousProcedureViewModel.templateList.length != 0) ? Expanded( child: EntityListCheckboxSearchFavProceduresWidget( isProcedure: !(widget.procedureType == ProcedureType.PRESCRIPTION), - model: model, + model: widget.previousProcedureViewModel, removeFavProcedure: (item) { setState(() { entityList.remove(item); @@ -102,7 +100,7 @@ class _AddFavouriteProcedureState extends State { title: widget.procedureType.getAddButtonTitle(context) ?? TranslationBase.of(context).addSelectedProcedures, color: AppGlobal.appGreenColor, - disabled: model.templateList.length == 0 ? true : false, + disabled: widget.previousProcedureViewModel.templateList.length == 0 ? true : false, fontWeight: FontWeight.w700, onPressed: () { if (widget.procedureType == ProcedureType.PRESCRIPTION) { diff --git a/lib/screens/procedures/base_add_procedure_tab_page.dart b/lib/screens/procedures/base_add_procedure_tab_page.dart index b4fc9573..a3ea04f2 100644 --- a/lib/screens/procedures/base_add_procedure_tab_page.dart +++ b/lib/screens/procedures/base_add_procedure_tab_page.dart @@ -10,7 +10,10 @@ import 'package:doctor_app_flutter/widgets/shared/app_texts_widget.dart'; import 'package:doctor_app_flutter/widgets/shared/network_base_view.dart'; import 'package:doctor_app_flutter/widgets/shared/text_fields/text_fields_utils.dart'; import 'package:flutter/material.dart'; +import 'package:provider/provider.dart'; +import '../../core/viewModel/project_view_model.dart'; +import '../../util/tab_helper.dart'; import 'ProcedureType.dart'; import 'add-favourite-procedure.dart'; import 'add-procedure-page.dart'; @@ -71,7 +74,6 @@ class _BaseAddProcedureTabPageState extends State return BaseView( onModelReady: (model) async { await model.getProcedureTemplate(categoryID: widget.procedureType.getCategoryId()); - }, builder: (BuildContext context, ProcedureViewModel model, Widget child) => AppScaffold( @@ -124,13 +126,16 @@ class _BaseAddProcedureTabPageState extends State tabWidget( screenSize, _activeTab == 0, + procedureType .getFavouriteTabName(context), + isFirst: true,context: context ), tabWidget( screenSize, _activeTab == 1, procedureType.getAllLabelName(context), + isLast: true,context: context ), ], ), @@ -181,16 +186,27 @@ class _BaseAddProcedureTabPageState extends State ); } - Widget tabWidget(Size screenSize, bool isActive, String title, - {int counter = -1}) { + Widget tabWidget( + Size screenSize, + bool isActive, + String title, { + int counter = -1, + bool isFirst = false, + bool isMiddle = false, + bool isLast = false, + context, + }) { + ProjectViewModel projectViewModel = Provider.of(context); + return Center( child: Container( - height: screenSize.height * 0.070, - decoration: TextFieldsUtils.containerBorderDecoration( - isActive ? Color(0xFFD02127) : Color(0xFFEAEAEA), - isActive ? Color(0xFFD02127) : Color(0xFFEAEAEA), - borderRadius: 4, - borderWidth: 0), + height: TabHelper.getTabHeight(context), + decoration: TabHelper.getBoxTabsBoxDecoration( + isActive: isActive, + isFirst: isFirst, + isMiddle: isMiddle, + isLast: isLast, + projectViewModel: projectViewModel), child: Row( mainAxisAlignment: MainAxisAlignment.center, children: [