Refactor add_prescription_form

merge-requests/967/head
RoaaGhali98 3 years ago
parent 0147481c27
commit 8cb5171bc9

@ -209,7 +209,7 @@ class PatientService extends BaseService {
super.error = error;
},
body: patient,
);
); return patient;
}
Future getOutPatientPrescriptions(patient) async {

@ -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 {

@ -192,92 +192,92 @@ class _PrescriptionFormWidgetState extends State<PrescriptionFormWidget> {
],
),
),
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<PrescriptionFormWidget> {
],
),
),
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<PrescriptionFormWidget> {
? "${AppDateUtils.convertStringToDateFormat(selectedDate.toString(), "yyyy-MM-dd")}"
: null,
enabled: false,
controller: strengthController,
),
// TextField(
@ -538,32 +536,6 @@ class _PrescriptionFormWidgetState extends State<PrescriptionFormWidget> {
}
}
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<AnalyticsService>().logEvent(
eventCategory: "Add Prescription Form",

@ -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<PrescriptionViewModel>(
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,

@ -48,9 +48,7 @@ class _AddFavouriteProcedureState extends State<AddFavouriteProcedure> {
@override
Widget build(BuildContext context) {
return BaseView<ProcedureViewModel>(
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<AddFavouriteProcedure> {
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<AddFavouriteProcedure> {
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) {

@ -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<BaseAddProcedureTabPage>
return BaseView<ProcedureViewModel>(
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<BaseAddProcedureTabPage>
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<BaseAddProcedureTabPage>
);
}
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: [

Loading…
Cancel
Save