diff --git a/lib/core/viewModel/medicine_view_model.dart b/lib/core/viewModel/medicine_view_model.dart index 2482a30d..2ec86367 100644 --- a/lib/core/viewModel/medicine_view_model.dart +++ b/lib/core/viewModel/medicine_view_model.dart @@ -9,9 +9,11 @@ import 'package:doctor_app_flutter/core/service/patient_medical_file/procedure/p import 'package:doctor_app_flutter/core/model/SOAP/GetAssessmentReqModel.dart'; import 'package:doctor_app_flutter/core/model/SOAP/GetAssessmentResModel.dart'; import 'package:doctor_app_flutter/core/viewModel/prescription_view_model.dart'; +import 'package:flutter/cupertino.dart'; import '../../locator.dart'; import '../../util/dr_app_toast_msg.dart'; import '../../util/helpers.dart'; +import '../../widgets/shared/loader/gif_loader_dialog_utils.dart'; import '../model/Prescriptions/post_prescrition_req_model.dart'; import '../model/Prescriptions/prescription_model.dart'; import 'base_view_model.dart'; @@ -22,6 +24,7 @@ class MedicineViewModel extends BaseViewModel { ProcedureService _procedureService = locator(); PrescriptionService _prescriptionService = locator(); + List get procedureTemplate => _procedureService.templateList; List templateList = List(); @@ -122,27 +125,6 @@ class MedicineViewModel extends BaseViewModel { } }); } - // if (_selectedMedication.mediSpanGPICode != null) { - // prescriptionDetails.add({ - // 'DrugId': _selectedMedication.mediSpanGPICode, - // 'DrugName': _selectedMedication.description, - // // 'Dose': strengthController.text, - // 'DoseType': model.itemMedicineListUnit.length == 1 - // ? model.itemMedicineListUnit[0]['parameterCode'].toString() - // : units['parameterCode'].toString(), - // 'Unit': model.itemMedicineListUnit.length == 1 - // ? model.itemMedicineListUnit[0]['description'] - // : units['description'], - // 'FrequencyType': model.itemMedicineList.length == 1 - // ? model.itemMedicineList[0]['parameterCode'].toString() - // : frequency['parameterCode'].toString(), - // 'Duration': duration['id'].toString(), - // 'RouteID': model.itemMedicineListRoute.length == 1 - // ? model.itemMedicineListRoute[0]['parameterCode'].toString() - // : route['parameterCode'].toString(), - // 'IsScreen': true - // }); - // } return prescriptionDetails; } @@ -200,11 +182,13 @@ class MedicineViewModel extends BaseViewModel { Future getAssessmentList ({ PatiantInformtion patientInfo, - bool isBusyLocal = false + bool isLocalBusy = false }) async { - patientAssessmentList.map((element) { - return element.icdCode10ID; - }); + if (isLocalBusy) { + setState(ViewState.BusyLocal); + } else { + setState(ViewState.Busy); + } GetAssessmentReqModel getAssessmentReqModel = GetAssessmentReqModel( patientMRN: patientInfo.patientMRN, episodeID: patientInfo.episodeNo.toString(), @@ -220,7 +204,17 @@ class MedicineViewModel extends BaseViewModel { if (medicationDoseTimeList.length == 0) { await getMedicationDoseTime(); } - await getPatientAssessment(getAssessmentReqModel); + await getPatientAssessment(getAssessmentReqModel, isLocalBusy: true); + if (_prescriptionService.hasError) { + error = _prescriptionService.error; + if (isLocalBusy) { + setState(ViewState.ErrorLocal); + } else { + setState(ViewState.Error); + } + } else { + setState(ViewState.Idle); + } } Future getProcedureTemplate({String categoryID}) async { @@ -258,56 +252,92 @@ class MedicineViewModel extends BaseViewModel { setState(ViewState.Idle); } - Future getMedicationList({String drug, bool isLocalBusy = true}) - async { - setState(ViewState.Busy); + + getMedicationList( + {String drug, bool isLocalBusy = false}) async { + if (isLocalBusy) { + setState(ViewState.BusyLocal); + } else { + setState(ViewState.Busy); + } + await getDoctorProfile(isGetProfile: true); await _prescriptionService.getMedicationList(drug: drug); if (_prescriptionService.hasError) { error = _prescriptionService.error; - setState(ViewState.Error); - } else + if (isLocalBusy) { + setState(ViewState.ErrorLocal); + } else { + setState(ViewState.Error); + } + } else { setState(ViewState.Idle); + } } - // async { - // if (isLocalBusy) { - // setState(ViewState.Busy); - // } else { - // setState(ViewState.BusyLocal); - // } - // - // await _prescriptionService.getMedicationList(drug: drug); - // if (_prescriptionService.hasError) { - // error = _prescriptionService.error; - // if (isLocalBusy) { - // setState(ViewState.ErrorLocal); - // } else { - // setState(ViewState.Error); - // } - // } else { - // //filterData = _prescriptionService.patientList; - // setState(ViewState.Idle); - // } - // } - Future getPatientAssessment( - GetAssessmentReqModel getAssessmentReqModel) async { - setState(ViewState.Busy); + GetAssessmentReqModel getAssessmentReqModel ,{bool isLocalBusy = false}) async { + if (isLocalBusy) { + setState(ViewState.BusyLocal); + } else { + setState(ViewState.Busy); + } await _prescriptionService.getPatientAssessment(getAssessmentReqModel); if (_prescriptionService.hasError) { error = _prescriptionService.error; - setState(ViewState.Error); + setState(ViewState.ErrorLocal); } else setState(ViewState.Idle); } - Future getMedicationStrength() async { - setState(ViewState.Busy); + Future onInitiateAllPrescription({ + PrescriptionViewModel model, + PatiantInformtion patient, + ProcedureTempleteDetailsModel groupProcedures, + BuildContext context, + bool isLocalBusy = true + } + ) async { + if (isLocalBusy) { + setState(ViewState.BusyLocal); + } else { + setState(ViewState.Busy); + } + model.getItem( + itemID: int.parse( + groupProcedures.aliasN.replaceAll("item code ;", ""))); + + GetAssessmentReqModel getAssessmentReqModel = GetAssessmentReqModel( + patientMRN: patient.patientMRN, + episodeID: patient.episodeNo.toString(), + editedBy: '', + doctorID: '', + appointmentNo: patient.appointmentNo); + if (medicationStrengthList.length == 0) { + await getMedicationStrength(); + } + if (medicationDurationList.length == 0) { + await getMedicationDuration(); + } + if (medicationDoseTimeList.length == 0) { + await getMedicationDoseTime(); + } + // await model.getPatientAssessment(getAssessmentReqModel); + // GifLoaderDialogUtils.showMyDialog(context); + await getPatientAssessment(getAssessmentReqModel); + // GifLoaderDialogUtils.hideDialog(context); + } + + Future getMedicationStrength({bool isLocalBusy = false}) async { + if (isLocalBusy) { + setState(ViewState.BusyLocal); + } else { + setState(ViewState.Busy); + } await _prescriptionService .getMasterLookup(MasterKeysService.MedicationStrength); if (_prescriptionService.hasError) { error = _prescriptionService.error; - setState(ViewState.Error); + setState(ViewState.ErrorLocal); } else setState(ViewState.Idle); } @@ -334,9 +364,12 @@ class MedicineViewModel extends BaseViewModel { setState(ViewState.Idle); } - Future getMedicationDoseTime() async { - setState(ViewState.Busy); - await _prescriptionService + Future getMedicationDoseTime({bool isLocalBusy = false}) async { + if (isLocalBusy) { + setState(ViewState.BusyLocal); + } else { + setState(ViewState.Busy); + } await _prescriptionService .getMasterLookup(MasterKeysService.MedicationDoseTime); if (_prescriptionService.hasError) { error = _prescriptionService.error; @@ -356,13 +389,17 @@ class MedicineViewModel extends BaseViewModel { setState(ViewState.Idle); } - Future getMedicationDuration() async { - setState(ViewState.Busy); + Future getMedicationDuration({bool isLocalBusy = false}) async { + if (isLocalBusy) { + setState(ViewState.BusyLocal); + } else { + setState(ViewState.Busy); + } await _prescriptionService .getMasterLookup(MasterKeysService.MedicationDuration); if (_prescriptionService.hasError) { error = _prescriptionService.error; - setState(ViewState.Error); + setState(ViewState.ErrorLocal); } else setState(ViewState.Idle); } diff --git a/lib/screens/prescription/add_prescription/add_prescription_form.dart b/lib/screens/prescription/add_prescription/add_prescription_form.dart index f3c95e57..3201a6ed 100644 --- a/lib/screens/prescription/add_prescription/add_prescription_form.dart +++ b/lib/screens/prescription/add_prescription/add_prescription_form.dart @@ -16,6 +16,8 @@ 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'; @@ -25,6 +27,7 @@ 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'; @@ -39,69 +42,19 @@ import 'package:speech_to_text/speech_to_text.dart' as stt; import 'add_drug_widget.dart'; - -// -// postPrescription( -// {String duration, -// String doseTimeIn, -// String dose, -// String drugId, -// String strength, -// String route, -// String frequency, -// String indication, -// String instruction, -// PrescriptionViewModel model, -// DateTime doseTime, -// String doseUnit, -// String icdCode, -// PatiantInformtion patient, -// String patientType}) async { -// PostPrescriptionReqModel postProcedureReqModel = -// new PostPrescriptionReqModel(); -// List prescriptionList = List(); -// -// postProcedureReqModel.appointmentNo = patient.appointmentNo; -// postProcedureReqModel.clinicID = patient.clinicId; -// postProcedureReqModel.episodeID = patient.episodeNo; -// postProcedureReqModel.patientMRN = patient.patientMRN; -// -// prescriptionList.add(PrescriptionRequestModel( -// covered: true, -// dose: double.parse(dose), -// itemId: drugId.isEmpty ? 1 : int.parse(drugId), -// doseUnitId: int.parse(doseUnit), -// route: route.isEmpty ? 1 : int.parse(route), -// frequency: frequency.isEmpty ? 1 : int.parse(frequency), -// remarks: instruction, -// approvalRequired: true, -// icdcode10Id: icdCode.toString(), -// doseTime: doseTimeIn.isEmpty ? 1 : int.parse(doseTimeIn), -// duration: duration.isEmpty ? 1 : int.parse(duration), -// doseStartDate: doseTime.toIso8601String())); -// postProcedureReqModel.prescriptionRequestModel = prescriptionList; -// await model.postPrescription(postProcedureReqModel, patient.patientMRN); -// -// if (model.state == ViewState.ErrorLocal) { -// Helpers.showErrorToast(model.error); -// } else if (model.state == ViewState.Idle) { -// model.getPrescriptions(patient); -// DrAppToastMsg.showSuccesToast('Medication has been added'); -// } -// } - -class PrescriptionFormWidget extends StatefulWidget { - final PrescriptionViewModel model; +class AddPrescriptionForm extends StatefulWidget { + final PrescriptionViewModel prescriptionViewModel; final PatiantInformtion patient; final List prescriptionList; - PrescriptionFormWidget(this.model, this.patient, this.prescriptionList); + + AddPrescriptionForm(this.prescriptionViewModel, this.patient, this.prescriptionList, ); @override - _PrescriptionFormWidgetState createState() => _PrescriptionFormWidgetState(); + _AddPrescriptionFormState createState() => _AddPrescriptionFormState(); } -class _PrescriptionFormWidgetState extends State { +class _AddPrescriptionFormState extends State { String routeError; String frequencyError; String doseTimeError; @@ -117,12 +70,13 @@ class _PrescriptionFormWidgetState extends State { TextEditingController instructionController = TextEditingController(); bool visibilityPrescriptionForm = false; - bool visibilitySearch = true; final myController = TextEditingController(); DateTime selectedDate; int strengthChar; GetMedicationResponseModel _selectedMedication; + MedicineViewModel medicineViewModel; + GlobalKey key = new GlobalKey>(); @@ -145,91 +99,21 @@ class _PrescriptionFormWidgetState extends State { dynamic box; dynamic x; - // @override - // void initState() { - // requestPermissions(); - // event.controller.stream.listen((p) { - // if (p['startPopUp'] == 'true') { - // if (this.mounted) { - // initSpeechState().then((value) => {onVoiceText()}); - // } - // } - // }); - // selectedType = 1; - // super.initState(); - // } - - setSelectedType(int val) { - setState(() { - selectedType = val; - }); - } - - onVoiceText() async { - new SpeechToText(context: context).showAlertDialog(context); - var lang = TranslationBase.of(AppGlobal.CONTEX).locale.languageCode; - bool available = await speech.initialize( - onStatus: statusListener, onError: errorListener); - if (available) { - speech.listen( - onResult: resultListener, - listenMode: stt.ListenMode.confirmation, - localeId: lang == 'en' ? 'en-US' : 'ar-SA', - ); - } else { - print("The user has denied the use of speech recognition."); - } - } - - void errorListener(SpeechRecognitionError error) { - event.setValue({"searchText": 'null'}); - print(error); - } - - void statusListener(String status) { - recognizedWord = status == 'listening' ? 'Listening...' : 'Sorry....'; - } - - // void requestPermissions() async { - // void requestPermissions() async { - // Map statuses = await [ - // Permission.microphone, - // ].request(); - // } - - void resultListener(result) { - recognizedWord = result.recognizedWords; - event.setValue({"searchText": recognizedWord}); - - if (result.finalResult == true) { - setState(() { - SpeechToText.closeAlertDialog(context); - speech.stop(); - instructionController.text += recognizedWord + '\n'; - }); - } else { - print(result.finalResult); - } - } - - Future initSpeechState() async { - bool hasSpeech = await speech.initialize( - onError: errorListener, onStatus: statusListener); - print(hasSpeech); - if (!mounted) return; - } + PatiantInformtion patient; @override Widget build(BuildContext context) { - final screenSize = MediaQuery.of(context).size; return BaseView( - onModelReady: (model) => model.getAssessmentList( - patientInfo: widget.patient - ), + onModelReady: (model) async { + // // await getPatientAssessment(getAssessmentReqModel); + // model.onInitiateAllPrescription(groupProcedures: widget.groupProcedures, patient: widget.patient); + await model.getAssessmentList(patientInfo: widget.patient,isLocalBusy: true); + + + }, builder: ( BuildContext context, MedicineViewModel model, - Widget child,) => NetworkBaseView( baseViewModel: model, @@ -267,659 +151,24 @@ class _PrescriptionFormWidgetState extends State { key: formKey, 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, - ), - 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; - }, - ); - }, - ), - ), - ], - ), - ), + SearchPrescriptionWidget( + spaceBetweenTextFields: spaceBetweenTextFields, + medicineViewModel: model, + prescriptionViewModel: widget.prescriptionViewModel, ), - SizedBox( - height: spaceBetweenTextFields, - ), - Visibility( - visible: visibilityPrescriptionForm, - child: Container( + + Container( 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), - ], - ), - ), - 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: model - .itemMedicineListUnit - .length == - 1 - ? model - .itemMedicineListUnit[0] - : units, - elementError: unitError, - keyName: 'description', - keyId: 'parameterCode', - hintText: 'Unit', - elementList: model - .itemMedicineListUnit, - okFunction: (selectedValue) { - setState(() { - units = selectedValue; - units['isDefault'] = true; - }); - }, - ), - ], - ), - ), - SizedBox( - height: spaceBetweenTextFields), - PrescriptionTextFiled( - elementList: - model.itemMedicineListRoute, - element: model.itemMedicineListRoute - .length == - 1 - ? route = model.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: model.itemMedicineListRoute - .length == - 1 - ? frequency = model.itemMedicineListRoute[0] - : frequency, - elementList: model.itemMedicineList, - keyId: 'parameterCode', - keyName: 'description', - okFunction: (selectedValue) { - setState(() { - frequency = selectedValue; - frequency['isDefault'] = true; - if (_selectedMedication != null && duration != null && frequency != null && strengthController.text != null) { - model.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: - model.medicationDoseTimeList, - keyId: 'id', - keyName: 'nameEn', - okFunction: (selectedValue) { - setState(() { - doseTime = selectedValue; - }); - }), - SizedBox( - height: spaceBetweenTextFields), - if (model - .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: - model - .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: - model - .patientAssessmentList[ - 0] - .asciiDesc - .toString(), - // indication != null - // ? indication[ - // 'name'] - // : null, - enabled: true, - ), - ), - ], - ), - ), - SizedBox( - height: spaceBetweenTextFields), - Container( - color: Colors.transparent, - child: InkWell( - onTap: () => selectDate( - context, widget.model), - 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( - // 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), - PrescriptionTextFiled( - element: duration, - elementError: durationError, - hintText: - TranslationBase.of(context) - .duration, - elementList: - model.medicationDurationList, - keyName: 'nameEn', - keyId: 'id', - okFunction: (selectedValue) { - setState(() { - duration = selectedValue; - if (_selectedMedication != - null && - duration != null && - frequency != null && - strengthController.text != - null) { - model.getBoxQuantity( - freq: frequency[ - 'parameterCode'], - duration: duration['id'], - itemCode: - _selectedMedication - .itemId, - strength: double.parse( - strengthController - .text), - ); - box = model.boxQuintity; - - return; - } - }); - }, - ), - SizedBox( - height: spaceBetweenTextFields), - Container( - color: Colors.white, - child: AppTextFieldCustom( - hintText: "UOM", - isTextFieldHasSuffix: false, - dropDownText: - uom != null ? uom : null, - enabled: false, - ), - ), - SizedBox( - height: spaceBetweenTextFields), - Container( - color: Colors.white, - child: AppTextFieldCustom( - hintText: - TranslationBase.of(context) - .boxQuantity, - isTextFieldHasSuffix: false, - dropDownText: box != null - ? model.boxQuintity.toString() - : null, - enabled: false, - ), - ), - 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 { - /// TODO Elham* Use it to separate function - await locator< - AnalyticsService>() - .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); - Navigator.pop(context); - return; - } - - 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"); - return; - } - - if (formKey.currentState - .validate()) { - Navigator.pop(context); - openDrugToDrug(model, widget.model); - } - } else { - setState(() { - if (duration == null) { - durationError = - TranslationBase.of( - context) - .fieldRequired; - } else { - durationError = null; - } - if (doseTime == null) { - doseTimeError = - TranslationBase.of( - context) - .fieldRequired; - } else { - doseTimeError = null; - } - if (route == null) { - routeError = - TranslationBase.of( - context) - .fieldRequired; - } else { - routeError = null; - } - if (frequency == null) { - frequencyError = - TranslationBase.of( - context) - .fieldRequired; - } else { - frequencyError = null; - } - if (units == null) { - unitError = - TranslationBase.of( - context) - .fieldRequired; - } else { - unitError = null; - } - if (strengthController - .text == - "") { - strengthError = - TranslationBase.of( - context) - .fieldRequired; - } else { - strengthError = null; - } - }); - } - formKey.currentState.save(); - }, - ), - ], - ), + PrescriptionFormWidget( + patient: widget.patient, + prescriptionViewModel: widget.prescriptionViewModel, + medicineViewModel: model, + prescriptionList: widget.prescriptionList, ), ], ), ), - ), ], ), ), @@ -934,45 +183,4 @@ class _PrescriptionFormWidgetState extends State { ), ); } - - selectDate(BuildContext context, PrescriptionViewModel model) async { - Helpers.hideKeyboard(context); - DateTime selectedDate; - selectedDate = DateTime.now(); - final DateTime picked = await showDatePicker( - context: context, - initialDate: selectedDate, - firstDate: DateTime.now(), - lastDate: DateTime(2040), - initialEntryMode: DatePickerEntryMode.calendar, - ); - if (picked != null && picked != selectedDate) { - setState(() { - this.selectedDate = picked; - }); - } - } - - openDrugToDrug(MedicineViewModel model, PrescriptionViewModel modelPrescription) { - showModalBottomSheet( - context: context, - builder: (context) { - return AddDrugWidget( - patient: widget.patient, - medicineModel: model, - modelPrescription: modelPrescription, - prescriptionList: widget.prescriptionList, - ); - }); - } - - - searchMedicine(context, MedicineViewModel model) async { - FocusScope.of(context).unfocus(); - if (myController.text.length < 3) { - Helpers.showErrorToast(TranslationBase.of(context).moreThan3Letter); - return; - } - await model.getMedicationList(drug: myController.text); - } } diff --git a/lib/screens/prescription/add_prescription/prescription_form_widget.dart b/lib/screens/prescription/add_prescription/prescription_form_widget.dart new file mode 100644 index 00000000..b75aa52b --- /dev/null +++ b/lib/screens/prescription/add_prescription/prescription_form_widget.dart @@ -0,0 +1,739 @@ +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/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/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'; +import 'package:doctor_app_flutter/util/helpers.dart'; +import 'package:doctor_app_flutter/util/translations_delegate_base.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/speech-text-popup.dart'; +import 'package:doctor_app_flutter/widgets/shared/text_fields/app-textfield-custom.dart'; +import 'package:flutter/material.dart'; +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'; + + + +class PrescriptionFormWidget extends StatefulWidget { + final PatiantInformtion patient; + final List prescriptionList; + final PrescriptionViewModel prescriptionViewModel; + final MedicineViewModel medicineViewModel; + + + const PrescriptionFormWidget({Key key, this.patient, this.prescriptionList, + this.prescriptionViewModel, this.medicineViewModel,}); + + @override + _PrescriptionFormWidgetState createState() => _PrescriptionFormWidgetState(); +} + +class _PrescriptionFormWidgetState extends State { + String routeError; + String frequencyError; + String doseTimeError; + String durationError; + String unitError; + String strengthError; + + int selectedType; + + TextEditingController strengthController = TextEditingController(); + TextEditingController unitController = TextEditingController(); + TextEditingController indicationController = TextEditingController(); + TextEditingController instructionController = TextEditingController(); + + bool visibilityPrescriptionForm = false; + bool visibilitySearch = true; + + final myController = TextEditingController(); + DateTime selectedDate; + int strengthChar; + GetMedicationResponseModel _selectedMedication; + PrescriptionViewModel prescriptionViewModel; + + GlobalKey key = + new GlobalKey>(); + + TextEditingController drugIdController = TextEditingController(); + TextEditingController doseController = TextEditingController(); + final searchController = TextEditingController(); + stt.SpeechToText speech = stt.SpeechToText(); + var event = RobotProvider(); + var recognizedWord; + + final GlobalKey formKey = GlobalKey(); + final double spaceBetweenTextFields = 12; + dynamic route; + dynamic frequency; + dynamic duration; + dynamic doseTime; + dynamic indication; + dynamic units; + dynamic uom; + dynamic box; + dynamic x; + + + setSelectedType(int val) { + setState(() { + selectedType = val; + }); + } + + onVoiceText() async { + new SpeechToText(context: context).showAlertDialog(context); + var lang = TranslationBase.of(AppGlobal.CONTEX).locale.languageCode; + bool available = await speech.initialize( + onStatus: statusListener, onError: errorListener); + if (available) { + speech.listen( + onResult: resultListener, + listenMode: stt.ListenMode.confirmation, + localeId: lang == 'en' ? 'en-US' : 'ar-SA', + ); + } else { + print("The user has denied the use of speech recognition."); + } + } + + void errorListener(SpeechRecognitionError error) { + event.setValue({"searchText": 'null'}); + print(error); + } + + void statusListener(String status) { + recognizedWord = status == 'listening' ? 'Listening...' : 'Sorry....'; + } + + // void requestPermissions() async { + // void requestPermissions() async { + // Map statuses = await [ + // Permission.microphone, + // ].request(); + // } + + void resultListener(result) { + recognizedWord = result.recognizedWords; + event.setValue({"searchText": recognizedWord}); + + if (result.finalResult == true) { + setState(() { + SpeechToText.closeAlertDialog(context); + speech.stop(); + instructionController.text += recognizedWord + '\n'; + }); + } else { + print(result.finalResult); + } + } + + Future initSpeechState() async { + bool hasSpeech = await speech.initialize( + onError: errorListener, onStatus: statusListener); + print(hasSpeech); + if (!mounted) return; + } + + @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), + ], + ), + ), + 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) { + setState(() { + units = selectedValue; + units['isDefault'] = true; + }); + }, + ), + ], + ), + ), + 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, + ), + ), + 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( + // 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), + PrescriptionTextFiled( + element: duration, + elementError: durationError, + hintText: + TranslationBase.of(context) + .duration, + elementList: + widget.medicineViewModel.medicationDurationList, + keyName: 'nameEn', + keyId: 'id', + okFunction: (selectedValue) { + setState(() { + duration = selectedValue; + 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), + ); + 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, + ), + ), + 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( + 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); + }, + ), + ], + ), + ), + ], + ), + ); + } + + selectDate(BuildContext context, PrescriptionViewModel model) async { + Helpers.hideKeyboard(context); + DateTime selectedDate; + selectedDate = DateTime.now(); + final DateTime picked = await showDatePicker( + context: context, + initialDate: selectedDate, + firstDate: DateTime.now(), + lastDate: DateTime(2040), + initialEntryMode: DatePickerEntryMode.calendar, + ); + if (picked != null && picked != selectedDate) { + setState(() { + this.selectedDate = picked; + }); + } + } + + openDrugToDrug(MedicineViewModel model, PrescriptionViewModel modelPrescription) { + showModalBottomSheet( + context: context, + builder: (context) { + return AddDrugWidget( + patient: widget.patient, + medicineModel: model, + modelPrescription: modelPrescription, + prescriptionList: widget.prescriptionList, + ); + }); + } + + + addMedicationButton(MedicineViewModel model) async { + await locator< + AnalyticsService>() + .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); + Navigator.pop(context); + return; + } + + 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"); + return; + } + + if (formKey.currentState + .validate()) { + Navigator.pop(context); + openDrugToDrug(model, widget.prescriptionViewModel); + } + } else { + setState(() { + if (duration == null) { + durationError = + TranslationBase.of( + context) + .fieldRequired; + } else { + durationError = null; + } + if (doseTime == null) { + doseTimeError = + TranslationBase.of( + context) + .fieldRequired; + } else { + doseTimeError = null; + } + if (route == null) { + routeError = + TranslationBase.of( + context) + .fieldRequired; + } else { + routeError = null; + } + if (frequency == null) { + frequencyError = + TranslationBase.of( + context) + .fieldRequired; + } else { + frequencyError = null; + } + if (units == null) { + unitError = + TranslationBase.of( + context) + .fieldRequired; + } else { + unitError = null; + } + if (strengthController + .text == + "") { + strengthError = + TranslationBase.of( + context) + .fieldRequired; + } else { + strengthError = null; + } + }); + } + 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 new file mode 100644 index 00000000..167c3fb7 --- /dev/null +++ b/lib/screens/prescription/add_prescription/search_preescription_widget.dart @@ -0,0 +1,153 @@ +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'; +import '../../../core/viewModel/prescription_view_model.dart'; +import '../../../util/helpers.dart'; +import '../../../util/translations_delegate_base.dart'; +import '../../../widgets/medicine/medicine_item_widget.dart'; +import '../../../widgets/shared/buttons/app_buttons_widget.dart'; +import '../../../widgets/shared/loader/gif_loader_dialog_utils.dart'; +import '../../../widgets/shared/network_base_view.dart'; +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; + + + + + const SearchPrescriptionWidget({Key key, this.spaceBetweenTextFields, this.medicineViewModel, + this.prescriptionViewModel}) : 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, + ), + 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: spaceBetweenTextFields, + ), + ], + ), + ), + + ), + + );} + + searchMedicine(context, MedicineViewModel model) async { + FocusScope.of(context).unfocus(); + if (myController.text.length < 3) { + Helpers.showErrorToast(TranslationBase.of(context).moreThan3Letter); + return; + } + GifLoaderDialogUtils.showMyDialog(context); + await model.getMedicationList(drug: myController.text,isLocalBusy: true); + GifLoaderDialogUtils.hideDialog(context); + } + +} + + diff --git a/lib/screens/procedures/base_add_procedure_tab_page.dart b/lib/screens/procedures/base_add_procedure_tab_page.dart index 90ca0e55..7ef3e6e2 100644 --- a/lib/screens/procedures/base_add_procedure_tab_page.dart +++ b/lib/screens/procedures/base_add_procedure_tab_page.dart @@ -167,11 +167,11 @@ class _BaseAddProcedureTabPageState extends State ), if (widget.procedureType == ProcedureType.PRESCRIPTION) - PrescriptionFormWidget( + AddPrescriptionForm( widget.prescriptionModel, widget.patient, - widget.prescriptionModel - .prescriptionList) + widget.prescriptionModel.prescriptionList, + ) else AddProcedurePage( model: this.model,