diff --git a/lib/screens/prescription/add_prescription/add_prescription_form.dart b/lib/screens/prescription/add_prescription/add_prescription_form.dart index 3201a6ed..a5889a5a 100644 --- a/lib/screens/prescription/add_prescription/add_prescription_form.dart +++ b/lib/screens/prescription/add_prescription/add_prescription_form.dart @@ -1,54 +1,24 @@ import 'package:autocomplete_textfield/autocomplete_textfield.dart'; -import 'package:doctor_app_flutter/config/config.dart'; -import 'package:doctor_app_flutter/config/size_config.dart'; -import 'package:doctor_app_flutter/core/enum/viewstate.dart'; -import 'package:doctor_app_flutter/core/model/Prescriptions/post_prescrition_req_model.dart'; import 'package:doctor_app_flutter/core/model/Prescriptions/prescription_model.dart'; +import 'package:doctor_app_flutter/core/model/patient/patiant_info_model.dart'; import 'package:doctor_app_flutter/core/model/search_drug/get_medication_response_model.dart'; import 'package:doctor_app_flutter/core/provider/robot_provider.dart'; -import 'package:doctor_app_flutter/core/service/AnalyticsService.dart'; import 'package:doctor_app_flutter/core/viewModel/medicine_view_model.dart'; import 'package:doctor_app_flutter/core/viewModel/prescription_view_model.dart'; -import 'package:doctor_app_flutter/core/viewModel/project_view_model.dart'; -import 'package:doctor_app_flutter/icons_app/doctor_app_icons.dart'; -import 'package:doctor_app_flutter/locator.dart'; -import 'package:doctor_app_flutter/core/model/SOAP/GetAssessmentReqModel.dart'; -import 'package:doctor_app_flutter/core/model/patient/patiant_info_model.dart'; import 'package:doctor_app_flutter/screens/base/base_view.dart'; -import 'package:doctor_app_flutter/screens/prescription/add_prescription/drugtodrug.dart'; import 'package:doctor_app_flutter/screens/prescription/add_prescription/prescription_form_widget.dart'; import 'package:doctor_app_flutter/screens/prescription/add_prescription/search_preescription_widget.dart'; -import 'package:doctor_app_flutter/screens/prescription/prescription_text_filed.dart'; -import 'package:doctor_app_flutter/util/date-utils.dart'; -import 'package:doctor_app_flutter/util/dr_app_toast_msg.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/medicine/medicine_item_widget.dart'; -import 'package:doctor_app_flutter/widgets/shared/TextFields.dart'; -import 'package:doctor_app_flutter/widgets/shared/app_texts_widget.dart'; -import 'package:doctor_app_flutter/widgets/shared/buttons/app_buttons_widget.dart'; -import 'package:doctor_app_flutter/widgets/shared/loader/gif_loader_dialog_utils.dart'; import 'package:doctor_app_flutter/widgets/shared/network_base_view.dart'; -import 'package:doctor_app_flutter/widgets/shared/speech-text-popup.dart'; -import 'package:doctor_app_flutter/widgets/shared/text_fields/app-textfield-custom.dart'; -import 'package:doctor_app_flutter/widgets/shared/text_fields/app_text_form_field.dart'; import 'package:flutter/material.dart'; -import 'package:flutter/services.dart'; -import 'package:hexcolor/hexcolor.dart'; -import 'package:permission_handler/permission_handler.dart'; -import 'package:provider/provider.dart'; -import 'package:speech_to_text/speech_recognition_error.dart'; import 'package:speech_to_text/speech_to_text.dart' as stt; -import 'add_drug_widget.dart'; - class AddPrescriptionForm extends StatefulWidget { final PrescriptionViewModel prescriptionViewModel; final PatiantInformtion patient; final List prescriptionList; - - AddPrescriptionForm(this.prescriptionViewModel, this.patient, this.prescriptionList, ); + AddPrescriptionForm( + this.prescriptionViewModel, this.patient, this.prescriptionList); @override _AddPrescriptionFormState createState() => _AddPrescriptionFormState(); @@ -61,9 +31,10 @@ class _AddPrescriptionFormState extends State { String durationError; String unitError; String strengthError; - int selectedType; + bool visibilitySearch = true; + TextEditingController strengthController = TextEditingController(); TextEditingController unitController = TextEditingController(); TextEditingController indicationController = TextEditingController(); @@ -107,21 +78,21 @@ class _AddPrescriptionFormState extends State { onModelReady: (model) async { // // await getPatientAssessment(getAssessmentReqModel); // model.onInitiateAllPrescription(groupProcedures: widget.groupProcedures, patient: widget.patient); - await model.getAssessmentList(patientInfo: widget.patient,isLocalBusy: true); - - + await model.getAssessmentList( + patientInfo: widget.patient, isLocalBusy: true); }, builder: ( BuildContext context, MedicineViewModel model, - Widget child,) => + Widget child, + ) => NetworkBaseView( - baseViewModel: model, - child: GestureDetector( - onTap: () { + baseViewModel: model, + child: GestureDetector( + onTap: () { FocusScope.of(context).requestFocus(new FocusNode()); - }, - child: DraggableScrollableSheet( + }, + child: DraggableScrollableSheet( initialChildSize: 0.98, maxChildSize: 0.98, minChildSize: 0.9, @@ -151,24 +122,42 @@ class _AddPrescriptionFormState extends State { key: formKey, child: Column( children: [ - SearchPrescriptionWidget( - spaceBetweenTextFields: spaceBetweenTextFields, - medicineViewModel: model, - prescriptionViewModel: widget.prescriptionViewModel, + Visibility( + visible: visibilitySearch, + child: SearchPrescriptionWidget( + spaceBetweenTextFields: + spaceBetweenTextFields, + medicineViewModel: model, + prescriptionViewModel: + widget.prescriptionViewModel, + onItemSelected: + (GetMedicationResponseModel + medication) { + setState(() { + visibilitySearch = !visibilitySearch; + _selectedMedication = medication; + }); + }, + ), ), - - Container( + Visibility( + visible: !visibilitySearch, + child: Container( child: Column( children: [ PrescriptionFormWidget( patient: widget.patient, - prescriptionViewModel: widget.prescriptionViewModel, + prescriptionViewModel: + widget.prescriptionViewModel, medicineViewModel: model, - prescriptionList: widget.prescriptionList, + prescriptionList: + widget.prescriptionList, + selectedMedication: _selectedMedication, ), ], ), ), + ), ], ), ), diff --git a/lib/screens/prescription/add_prescription/prescription_form_widget.dart b/lib/screens/prescription/add_prescription/prescription_form_widget.dart index b75aa52b..9569fa94 100644 --- a/lib/screens/prescription/add_prescription/prescription_form_widget.dart +++ b/lib/screens/prescription/add_prescription/prescription_form_widget.dart @@ -2,6 +2,7 @@ import 'package:autocomplete_textfield/autocomplete_textfield.dart'; import 'package:doctor_app_flutter/config/config.dart'; import 'package:doctor_app_flutter/config/size_config.dart'; import 'package:doctor_app_flutter/core/model/Prescriptions/prescription_model.dart'; +import 'package:doctor_app_flutter/core/model/patient/patiant_info_model.dart'; import 'package:doctor_app_flutter/core/model/search_drug/get_medication_response_model.dart'; import 'package:doctor_app_flutter/core/provider/robot_provider.dart'; import 'package:doctor_app_flutter/core/service/AnalyticsService.dart'; @@ -9,7 +10,6 @@ import 'package:doctor_app_flutter/core/viewModel/medicine_view_model.dart'; import 'package:doctor_app_flutter/core/viewModel/prescription_view_model.dart'; import 'package:doctor_app_flutter/icons_app/doctor_app_icons.dart'; import 'package:doctor_app_flutter/locator.dart'; -import 'package:doctor_app_flutter/core/model/patient/patiant_info_model.dart'; import 'package:doctor_app_flutter/screens/prescription/prescription_text_filed.dart'; import 'package:doctor_app_flutter/util/date-utils.dart'; import 'package:doctor_app_flutter/util/dr_app_toast_msg.dart'; @@ -25,19 +25,23 @@ import 'package:flutter/services.dart'; import 'package:hexcolor/hexcolor.dart'; import 'package:speech_to_text/speech_recognition_error.dart'; import 'package:speech_to_text/speech_to_text.dart' as stt; -import 'add_drug_widget.dart'; - +import 'add_drug_widget.dart'; class PrescriptionFormWidget extends StatefulWidget { final PatiantInformtion patient; final List prescriptionList; final PrescriptionViewModel prescriptionViewModel; final MedicineViewModel medicineViewModel; + final GetMedicationResponseModel selectedMedication; - - const PrescriptionFormWidget({Key key, this.patient, this.prescriptionList, - this.prescriptionViewModel, this.medicineViewModel,}); + const PrescriptionFormWidget( + {Key key, + this.patient, + this.prescriptionList, + this.prescriptionViewModel, + this.medicineViewModel, + this.selectedMedication}); @override _PrescriptionFormWidgetState createState() => _PrescriptionFormWidgetState(); @@ -64,11 +68,10 @@ class _PrescriptionFormWidgetState extends State { final myController = TextEditingController(); DateTime selectedDate; int strengthChar; - GetMedicationResponseModel _selectedMedication; PrescriptionViewModel prescriptionViewModel; GlobalKey key = - new GlobalKey>(); + new GlobalKey>(); TextEditingController drugIdController = TextEditingController(); TextEditingController doseController = TextEditingController(); @@ -89,7 +92,6 @@ class _PrescriptionFormWidgetState extends State { dynamic box; dynamic x; - setSelectedType(int val) { setState(() { selectedType = val; @@ -153,445 +155,366 @@ class _PrescriptionFormWidgetState extends State { @override Widget build(BuildContext context) { final screenSize = MediaQuery.of(context).size; - return Visibility( - visible: visibilitySearch, - child: Column( - children: [ - AppText( - _selectedMedication?.description ?? - "", - fontWeight: FontWeight.w600, - ), - SizedBox( - height: 15.0, - ), - Container( - child: Row( - mainAxisAlignment: MainAxisAlignment.start, - children: [ - SizedBox(width: 6,), - AppText( - TranslationBase.of(context) - .orderType, - fontWeight: FontWeight.w500, - ), - SizedBox(width: 18,), - Radio( - activeColor: - AppGlobal.appRedColor, - value: 1, - groupValue: selectedType, - onChanged: (value) { - setSelectedType(value); - }, - ), - Text(TranslationBase.of(context) - .regular), - ], - ), + return Column( + children: [ + AppText( + widget.selectedMedication?.description ?? "", + fontWeight: FontWeight.w600, + ), + SizedBox( + height: 15.0, + ), + Container( + child: Row( + mainAxisAlignment: MainAxisAlignment.start, + children: [ + SizedBox( + width: 6, + ), + AppText( + TranslationBase.of(context).orderType, + fontWeight: FontWeight.w500, + ), + SizedBox( + width: 18, + ), + Radio( + activeColor: AppGlobal.appRedColor, + value: 1, + groupValue: selectedType, + onChanged: (value) { + setSelectedType(value); + }, + ), + Text(TranslationBase.of(context).regular), + ], ), - 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) { + ), + 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(() { - units = selectedValue; - units['isDefault'] = true; + strengthChar = value.length; }); + if (strengthChar >= 5) { + DrAppToastMsg.showErrorToast( + TranslationBase.of(context) + .only5DigitsAllowedForStrength, + ); + } }, - ), - ], - ), - ), - SizedBox( - height: spaceBetweenTextFields), - PrescriptionTextFiled( - elementList: - widget.medicineViewModel.itemMedicineListRoute, - element: widget.medicineViewModel.itemMedicineListRoute - .length == - 1 - ? route = widget.medicineViewModel.itemMedicineListRoute[0] - : route, - elementError: routeError, - keyId: 'parameterCode', - keyName: 'description', - okFunction: (selectedValue) { - setState(() { - route = selectedValue; - route['isDefault'] = true; - }); - }, - hintText: - TranslationBase.of(context) - .route, - ), - SizedBox( - height: spaceBetweenTextFields), - PrescriptionTextFiled( - hintText: TranslationBase.of(context).frequency, - elementError: frequencyError, - // element: frequency, - element: widget.medicineViewModel.itemMedicineListRoute - .length == - 1 - ? frequency = widget.medicineViewModel.itemMedicineListRoute[0] - : frequency, - elementList: widget.medicineViewModel.itemMedicineList, - keyId: 'parameterCode', - keyName: 'description', - okFunction: (selectedValue) { - setState(() { - frequency = selectedValue; - frequency['isDefault'] = true; - if (_selectedMedication != null && duration != null && frequency != null && strengthController.text != null) { - widget.medicineViewModel.getBoxQuantity( - freq: frequency['parameterCode'], - duration: duration['id'], - itemCode: _selectedMedication.itemId, - strength: double.parse(strengthController.text) - ); - - return; - } - }); - }), - SizedBox( - height: spaceBetweenTextFields), - PrescriptionTextFiled( - hintText: - TranslationBase.of(context) - .doseTime, - elementError: doseTimeError, - element: doseTime, - elementList: - widget.medicineViewModel.medicationDoseTimeList, - keyId: 'id', - keyName: 'nameEn', - okFunction: (selectedValue) { - setState(() { - doseTime = selectedValue; - }); - }), - SizedBox( - height: spaceBetweenTextFields), - if (widget.medicineViewModel - .patientAssessmentList.isNotEmpty) - Container( - height: screenSize.height * 0.070, - width: double.infinity, - color: Colors.white, - child: Row( - children: [ - Container( - width: - MediaQuery.of(context) - .size - .width * - 0.29, - child: AppTextFieldCustom( - hintText: - widget.medicineViewModel - .patientAssessmentList[ - 0] - .icdCode10ID - .toString(), - // indication != null - // ? indication[ - // 'name'] - // : null, - - enabled: true, - ), + inputType: TextInputType.numberWithOptions( + decimal: true, ), - Container( - width: - MediaQuery.of(context) - .size - .width * - 0.57, - color: Colors.white, - child: AppTextFieldCustom( - maxLines: 5, - hintText: - widget.medicineViewModel - .patientAssessmentList[ - 0] - .asciiDesc - .toString(), - // indication != null - // ? indication[ - // 'name'] - // : null, - enabled: true, - ), - ), - ], - ), - ), - SizedBox( - height: spaceBetweenTextFields), - Container( - color: Colors.transparent, - child: InkWell( - onTap: () => selectDate( - context, widget.prescriptionViewModel), - child: AppTextFieldCustom( - validationError: - strengthError, - hintText: 'Date', - isTextFieldHasSuffix: true, - suffixIcon: IconButton( - icon: Icon( - Icons.calendar_today, - color: Colors.black,), ), - dropDownText: selectedDate != null - ? "${AppDateUtils.convertStringToDateFormat(selectedDate.toString(), "yyyy-MM-dd")}" - : null, - enabled: false, - controller: strengthController, ), - - // TextField( - // decoration: - // textFieldSelectorDecoration( + 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) - // .date, - // selectedDate != null - // ? "${AppDateUtils.convertStringToDateFormat(selectedDate.toString(), "yyyy-MM-dd")}" - // : null, - // true, - // suffixIcon: Icon( - // Icons.calendar_today, - // color: Colors.black, - // )), - // enabled: false, + // 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( - element: duration, - elementError: durationError, - hintText: - TranslationBase.of(context) - .duration, - elementList: - widget.medicineViewModel.medicationDurationList, - keyName: 'nameEn', - keyId: 'id', + ), + SizedBox(height: spaceBetweenTextFields), + PrescriptionTextFiled( + elementList: widget.medicineViewModel.itemMedicineListRoute, + element: widget.medicineViewModel.itemMedicineListRoute.length == 1 + ? route = widget.medicineViewModel.itemMedicineListRoute[0] + : route, + elementError: routeError, + keyId: 'parameterCode', + keyName: 'description', + okFunction: (selectedValue) { + setState(() { + route = selectedValue; + route['isDefault'] = true; + }); + }, + hintText: TranslationBase.of(context).route, + ), + SizedBox(height: spaceBetweenTextFields), + PrescriptionTextFiled( + hintText: TranslationBase.of(context).frequency, + elementError: frequencyError, + // element: frequency, + element: widget.medicineViewModel.itemMedicineListRoute.length == 1 + ? frequency = widget.medicineViewModel.itemMedicineListRoute[0] + : frequency, + elementList: widget.medicineViewModel.itemMedicineList, + keyId: 'parameterCode', + keyName: 'description', okFunction: (selectedValue) { setState(() { - duration = selectedValue; - if (_selectedMedication != - null && + frequency = selectedValue; + frequency['isDefault'] = true; + if (widget.selectedMedication != null && duration != null && frequency != null && - strengthController.text != - null) { + strengthController.text != null) { widget.medicineViewModel.getBoxQuantity( - freq: frequency[ - 'parameterCode'], - duration: duration['id'], - itemCode: - _selectedMedication - .itemId, - strength: double.parse( - strengthController - .text), - ); - box = widget.medicineViewModel.boxQuintity; + freq: frequency['parameterCode'], + duration: duration['id'], + itemCode: widget.selectedMedication.itemId, + strength: double.parse(strengthController.text)); return; } }); - }, - ), - SizedBox( - height: spaceBetweenTextFields), + }), + SizedBox(height: spaceBetweenTextFields), + PrescriptionTextFiled( + hintText: TranslationBase.of(context).doseTime, + elementError: doseTimeError, + element: doseTime, + elementList: widget.medicineViewModel.medicationDoseTimeList, + keyId: 'id', + keyName: 'nameEn', + okFunction: (selectedValue) { + setState(() { + doseTime = selectedValue; + }); + }), + SizedBox(height: spaceBetweenTextFields), + if (widget.medicineViewModel.patientAssessmentList.isNotEmpty) Container( + height: screenSize.height * 0.070, + width: double.infinity, color: Colors.white, - child: AppTextFieldCustom( - hintText: "UOM", - isTextFieldHasSuffix: false, - dropDownText: - uom != null ? uom : null, - enabled: false, + child: Row( + children: [ + Container( + width: MediaQuery.of(context).size.width * 0.29, + child: AppTextFieldCustom( + hintText: widget + .medicineViewModel.patientAssessmentList[0].icdCode10ID + .toString(), + // indication != null + // ? indication[ + // 'name'] + // : null, + + enabled: true, + ), + ), + Container( + width: MediaQuery.of(context).size.width * 0.57, + color: Colors.white, + child: AppTextFieldCustom( + maxLines: 5, + hintText: widget + .medicineViewModel.patientAssessmentList[0].asciiDesc + .toString(), + // indication != null + // ? indication[ + // 'name'] + // : null, + enabled: true, + ), + ), + ], ), ), - SizedBox( - height: spaceBetweenTextFields), - Container( - color: Colors.white, + SizedBox(height: spaceBetweenTextFields), + Container( + color: Colors.transparent, + child: InkWell( + onTap: () => selectDate(context, widget.prescriptionViewModel), child: AppTextFieldCustom( - hintText: - TranslationBase.of(context) - .boxQuantity, - isTextFieldHasSuffix: false, - dropDownText: box != null - ? widget.medicineViewModel.boxQuintity.toString() + validationError: strengthError, + hintText: 'Date', + isTextFieldHasSuffix: true, + suffixIcon: IconButton( + icon: Icon( + Icons.calendar_today, + color: Colors.black, + ), + ), + dropDownText: selectedDate != null + ? "${AppDateUtils.convertStringToDateFormat(selectedDate.toString(), "yyyy-MM-dd")}" : null, enabled: false, + controller: strengthController, ), + + // TextField( + // decoration: + // textFieldSelectorDecoration( + // TranslationBase.of( + // context) + // .date, + // selectedDate != null + // ? "${AppDateUtils.convertStringToDateFormat(selectedDate.toString(), "yyyy-MM-dd")}" + // : null, + // true, + // suffixIcon: Icon( + // Icons.calendar_today, + // color: Colors.black, + // )), + // enabled: false, + // ), ), - SizedBox( - height: spaceBetweenTextFields + ), + SizedBox(height: spaceBetweenTextFields), + PrescriptionTextFiled( + element: duration, + elementError: durationError, + hintText: TranslationBase.of(context).duration, + elementList: widget.medicineViewModel.medicationDurationList, + keyName: 'nameEn', + keyId: 'id', + okFunction: (selectedValue) { + setState(() { + duration = selectedValue; + if (widget.selectedMedication != null && + duration != null && + frequency != null && + strengthController.text != null) { + widget.medicineViewModel.getBoxQuantity( + freq: frequency['parameterCode'], + duration: duration['id'], + itemCode: widget.selectedMedication.itemId, + strength: double.parse(strengthController.text), + ); + box = widget.medicineViewModel.boxQuintity; + + return; + } + }); + }, + ), + SizedBox(height: spaceBetweenTextFields), + Container( + color: Colors.white, + child: AppTextFieldCustom( + hintText: "UOM", + isTextFieldHasSuffix: false, + dropDownText: uom != null ? uom : null, + enabled: false, ), - Container( - decoration: BoxDecoration( - borderRadius: BorderRadius.all( - Radius.circular(6.0)), - border: Border.all( - width: 1.0, - color: - HexColor("#CCCCCC"))), - child: Stack( - children: [ - TextFields( - maxLines: 6, - minLines: 4, - hintText: TranslationBase.of( - context) - .instruction, - controller: - instructionController, - //keyboardType: TextInputType.number, - ), - Positioned( - top: 0, - right: 15, - child: IconButton( - icon: Icon( - DoctorApp.speechtotext, - color: Colors.black, - size: 35, - ), - onPressed: () { - initSpeechState().then( - (value) => - {onVoiceText()}); - }, - ), - ), - ], - ), + ), + SizedBox(height: spaceBetweenTextFields), + Container( + color: Colors.white, + child: AppTextFieldCustom( + hintText: TranslationBase.of(context).boxQuantity, + isTextFieldHasSuffix: false, + dropDownText: box != null + ? widget.medicineViewModel.boxQuintity.toString() + : null, + enabled: false, ), - SizedBox( - height: spaceBetweenTextFields), - Container( - margin: EdgeInsets.all( - SizeConfig.widthMultiplier * 5), - child: Wrap( - alignment: WrapAlignment.center, - children: [ - AppButton( - color: Color(0xff359846), - title: TranslationBase.of( - context) - .addMedication, - fontWeight: FontWeight.w600, - onPressed: () async { - addMedicationButton( widget.medicineViewModel); + ), + SizedBox(height: spaceBetweenTextFields), + Container( + decoration: BoxDecoration( + borderRadius: BorderRadius.all(Radius.circular(6.0)), + border: Border.all(width: 1.0, color: HexColor("#CCCCCC"))), + child: Stack( + children: [ + TextFields( + maxLines: 6, + minLines: 4, + hintText: TranslationBase.of(context).instruction, + controller: instructionController, + //keyboardType: TextInputType.number, + ), + Positioned( + top: 0, + right: 15, + child: IconButton( + icon: Icon( + DoctorApp.speechtotext, + color: Colors.black, + size: 35, + ), + onPressed: () { + initSpeechState().then((value) => {onVoiceText()}); }, ), - ], - ), + ), + ], + ), + ), + SizedBox(height: spaceBetweenTextFields), + Container( + margin: EdgeInsets.all(SizeConfig.widthMultiplier * 5), + child: Wrap( + alignment: WrapAlignment.center, + children: [ + AppButton( + color: Color(0xff359846), + title: TranslationBase.of(context).addMedication, + fontWeight: FontWeight.w600, + onPressed: () async { + addMedicationButton(widget.medicineViewModel); + }, + ), + ], ), - ], - ), + ), + ], ); } @@ -613,7 +536,8 @@ class _PrescriptionFormWidgetState extends State { } } - openDrugToDrug(MedicineViewModel model, PrescriptionViewModel modelPrescription) { + openDrugToDrug( + MedicineViewModel model, PrescriptionViewModel modelPrescription) { showModalBottomSheet( context: context, builder: (context) { @@ -626,107 +550,65 @@ class _PrescriptionFormWidgetState extends State { }); } - addMedicationButton(MedicineViewModel model) async { - await locator< - AnalyticsService>() - .logEvent( - eventCategory: - "Add Prescription Form", - eventAction: - "Add Prescription", + await locator().logEvent( + eventCategory: "Add Prescription Form", + eventAction: "Add Prescription", ); if (duration != null && doseTime != null && frequency != null && selectedDate != null && - strengthController - .text != - "") { - if (_selectedMedication - .isNarcotic == - true) { - DrAppToastMsg.showErrorToast( - TranslationBase.of( - context) - .narcoticMedicineCanOnlyBePrescribedFromVida); + strengthController.text != "") { + if (widget.selectedMedication.isNarcotic == true) { + DrAppToastMsg.showErrorToast(TranslationBase.of(context) + .narcoticMedicineCanOnlyBePrescribedFromVida); Navigator.pop(context); return; } - if (double.parse( - strengthController - .text) > - 1000.0) { - DrAppToastMsg - .showErrorToast( - "1000 is the MAX for the strength"); + if (double.parse(strengthController.text) > 1000.0) { + DrAppToastMsg.showErrorToast("1000 is the MAX for the strength"); return; } - if (double.parse( - strengthController - .text) < - 0.0) { - DrAppToastMsg - .showErrorToast( - "strength can't be zero"); + if (double.parse(strengthController.text) < 0.0) { + DrAppToastMsg.showErrorToast("strength can't be zero"); return; } - if (formKey.currentState - .validate()) { + if (formKey.currentState.validate()) { Navigator.pop(context); - openDrugToDrug(model, widget.prescriptionViewModel); + openDrugToDrug(model, widget.prescriptionViewModel); } } else { setState(() { if (duration == null) { - durationError = - TranslationBase.of( - context) - .fieldRequired; + durationError = TranslationBase.of(context).fieldRequired; } else { durationError = null; } if (doseTime == null) { - doseTimeError = - TranslationBase.of( - context) - .fieldRequired; + doseTimeError = TranslationBase.of(context).fieldRequired; } else { doseTimeError = null; } if (route == null) { - routeError = - TranslationBase.of( - context) - .fieldRequired; + routeError = TranslationBase.of(context).fieldRequired; } else { routeError = null; } if (frequency == null) { - frequencyError = - TranslationBase.of( - context) - .fieldRequired; + frequencyError = TranslationBase.of(context).fieldRequired; } else { frequencyError = null; } if (units == null) { - unitError = - TranslationBase.of( - context) - .fieldRequired; + unitError = TranslationBase.of(context).fieldRequired; } else { unitError = null; } - if (strengthController - .text == - "") { - strengthError = - TranslationBase.of( - context) - .fieldRequired; + if (strengthController.text == "") { + strengthError = TranslationBase.of(context).fieldRequired; } else { strengthError = null; } @@ -735,5 +617,3 @@ class _PrescriptionFormWidgetState extends State { formKey.currentState.save(); } } - - diff --git a/lib/screens/prescription/add_prescription/search_preescription_widget.dart b/lib/screens/prescription/add_prescription/search_preescription_widget.dart index 167c3fb7..4e6cd449 100644 --- a/lib/screens/prescription/add_prescription/search_preescription_widget.dart +++ b/lib/screens/prescription/add_prescription/search_preescription_widget.dart @@ -1,6 +1,7 @@ import 'package:flutter/cupertino.dart'; import 'package:flutter/material.dart'; import 'package:hexcolor/hexcolor.dart'; + import '../../../config/config.dart'; import '../../../core/model/search_drug/get_medication_response_model.dart'; import '../../../core/viewModel/medicine_view_model.dart'; @@ -15,127 +16,114 @@ import '../../../widgets/shared/text_fields/app_text_form_field.dart'; import '../../base/base_view.dart'; final myController = TextEditingController(); + class SearchPrescriptionWidget extends StatelessWidget { final double spaceBetweenTextFields; final MedicineViewModel medicineViewModel; final PrescriptionViewModel prescriptionViewModel; + final Function(GetMedicationResponseModel) onItemSelected; - - - - const SearchPrescriptionWidget({Key key, this.spaceBetweenTextFields, this.medicineViewModel, - this.prescriptionViewModel}) : super(key: key); + const SearchPrescriptionWidget( + {Key key, + this.spaceBetweenTextFields, + this.medicineViewModel, + this.prescriptionViewModel, + this.onItemSelected}) + : super(key: key); @override Widget build(BuildContext context) { - bool visibilityPrescriptionForm = false; - bool visibilitySearch = true; - GetMedicationResponseModel _selectedMedication; - return BaseView( onModelReady: (model) async {}, - builder: ( - BuildContext context, - MedicineViewModel model, - Widget child,) => - NetworkBaseView( - baseViewModel: model, - child: Visibility( - visible: visibilityPrescriptionForm, - child: Column( - children: [ - FractionallySizedBox( - widthFactor: 0.9, - child: Container( - decoration: BoxDecoration( - borderRadius: BorderRadius.all(Radius.circular(6.0)), - border: Border.all(width: 1.0, color: HexColor("#CCCCCC"))), - padding: EdgeInsets.all(10), - child: AppTextFormField( - onTap: () { - visibilityPrescriptionForm = false; - visibilitySearch = true; - }, - borderColor: Colors.white, - hintText: TranslationBase.of(context).searchMedicineNameHere, - controller: myController, - onSaved: (value) {}, - onFieldSubmitted: (value) { - searchMedicine(context, model); - }, - inputFormatter: ONLY_LETTERS, - ), - ), - ), - SizedBox( - height: 15.0, + builder: ( + BuildContext context, + MedicineViewModel model, + Widget child, + ) => + NetworkBaseView( + baseViewModel: model, + child: Column( + children: [ + FractionallySizedBox( + widthFactor: 0.9, + child: Container( + decoration: BoxDecoration( + borderRadius: BorderRadius.all(Radius.circular(6.0)), + border: Border.all(width: 1.0, color: HexColor("#CCCCCC"))), + padding: EdgeInsets.all(10), + child: AppTextFormField( + borderColor: Colors.white, + hintText: TranslationBase.of(context).searchMedicineNameHere, + controller: myController, + onSaved: (value) {}, + onFieldSubmitted: (value) { + searchMedicine(context, model); + }, + inputFormatter: ONLY_LETTERS, ), - Visibility( - visible: visibilitySearch, - child: Container( - child: Column( - children: [ - FractionallySizedBox( - widthFactor: 0.8, - child: Container( - child: Wrap( - alignment: WrapAlignment.center, - children: [ - AppButton( - title: TranslationBase.of(context).search, - onPressed: () async { - await searchMedicine( - context, - model, - ); - }, - ), - ], - ), - ), - ), - if (myController.text != '') - Container( - height: MediaQuery.of(context).size.height * 0.5, - child: ListView.builder( - padding: const EdgeInsets.only(top: 20), - scrollDirection: Axis.vertical, - itemCount: model.allMedicationList == null - ? 0 - : model.allMedicationList.length, - itemBuilder: (BuildContext context, int index) { - return InkWell( - child: MedicineItemWidget( - label: - model.allMedicationList[index].description), - onTap: () { - model.getItem( - itemID: model.allMedicationList[index].itemId); - visibilityPrescriptionForm = true; - visibilitySearch = false; - - _selectedMedication = - model.allMedicationList[index]; - // uom = _selectedMedication.uom; - }, - ); - }, - ), + ), + ), + SizedBox( + height: 15.0, + ), + Container( + child: Column( + children: [ + FractionallySizedBox( + widthFactor: 0.8, + child: Container( + child: Wrap( + alignment: WrapAlignment.center, + children: [ + AppButton( + title: TranslationBase.of(context).search, + onPressed: () async { + await searchMedicine( + context, + model, + ); + }, ), - ], + ], + ), ), ), - ), - SizedBox( - height: spaceBetweenTextFields, - ), - ], + if (myController.text != '') + Container( + height: MediaQuery.of(context).size.height * 0.5, + child: ListView.builder( + padding: const EdgeInsets.only(top: 20), + scrollDirection: Axis.vertical, + itemCount: model.allMedicationList == null + ? 0 + : model.allMedicationList.length, + itemBuilder: (BuildContext context, int index) { + return InkWell( + child: MedicineItemWidget( + label: + model.allMedicationList[index].description), + onTap: () { + model.getItem( + itemID: + model.allMedicationList[index].itemId); + onItemSelected(model.allMedicationList[index]); + // uom = _selectedMedication.uom; + }, + ); + }, + ), + ), + ], + ), ), - ), - + SizedBox( + height: spaceBetweenTextFields, + ), + ], ), - - );} + ), + ); + } searchMedicine(context, MedicineViewModel model) async { FocusScope.of(context).unfocus(); @@ -144,10 +132,7 @@ class SearchPrescriptionWidget extends StatelessWidget { return; } GifLoaderDialogUtils.showMyDialog(context); - await model.getMedicationList(drug: myController.text,isLocalBusy: true); + await model.getMedicationList(drug: myController.text, isLocalBusy: true); GifLoaderDialogUtils.hideDialog(context); } - } - -