From 0147481c2795a82b178953f04fdd53d1dec23ed8 Mon Sep 17 00:00:00 2001 From: RoaaGhali98 Date: Sun, 6 Feb 2022 16:52:08 +0200 Subject: [PATCH] Fix the drug to drug page --- .../prescription/prescription_service.dart | 50 ------- lib/core/viewModel/medicine_view_model.dart | 27 ++-- .../viewModel/prescription_view_model.dart | 2 +- .../add_prescription/add_drug_widget.dart | 132 +++++++++++------- .../add_prescription/drugtodrug.dart | 39 +++--- .../prescription_form_widget.dart | 28 +++- 6 files changed, 143 insertions(+), 135 deletions(-) diff --git a/lib/core/service/patient_medical_file/prescription/prescription_service.dart b/lib/core/service/patient_medical_file/prescription/prescription_service.dart index 93048656..1d310c6c 100644 --- a/lib/core/service/patient_medical_file/prescription/prescription_service.dart +++ b/lib/core/service/patient_medical_file/prescription/prescription_service.dart @@ -167,56 +167,6 @@ class PrescriptionService extends LookupService { List allergy, PatiantInformtion patient, List prescription) async { - // Map request = { - // "Prescription": { - // "objPatientInfo": {"Gender": "Male", "Age": "21/06/1967"}, - // "objVitalSign": {"Height": "180", "Weight": "37"}, - // "objPrescriptionItems": [ - // { - // "DrugId": "83-20-00-30-20-03-03", - // "DrugName": "WARFARIN 1 MG TAB 28'S (N)", - // "Dose": "1", - // "DoseType": "04", - // "Unit": "actuation(s)", - // "FrequencyType": "1/3/Day", - // "Duration": "3/Day", - // "IsScreen": "true" - // }, - // { - // "DrugId": "64-20-00-10-00-03-15", - // "DrugName": "PANADOL 500 MG TAB 24'S(DIS)", - // "Dose": "1", - // "DoseType": "04", - // "Unit": "MG", - // "FrequencyType": "3/1/Day", - // "Duration": "4/Day", - // "RouteID": "24", - // "IsScreen": "true" - // } - // ], - // "objAllergies": { - // "Allergy": { - // "objProperties": {"Id": "26", "Name": "phenoxymethylpenicillin"} - // } - // }, - // "objDiagnosis": { - // "Diagnosis": { - // "objProperties": {"Id": "A01.1", "Name": "Paratyphoid fever A"} - // } - // }, - // "IsDoctor": "false", - // "IsPharmacist": "false" - // }, - // "IPAdress": "10.10.10.10", - // "Channel": 9, - // "LanguageID": 2, - // "VersionID": 5.3, - // "SessionID": "BlUSkYymTt", - // "IsLoginForDoctorApp": true, - // "PatientOutSA": 0, - // "TokenID": "@dm!n", - // "OutSA": true - // }; Map request = { "Prescription": { "objPatientInfo": { diff --git a/lib/core/viewModel/medicine_view_model.dart b/lib/core/viewModel/medicine_view_model.dart index 1c5da88d..7cf96a3e 100644 --- a/lib/core/viewModel/medicine_view_model.dart +++ b/lib/core/viewModel/medicine_view_model.dart @@ -9,6 +9,7 @@ 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:doctor_app_flutter/widgets/shared/loader/gif_loader_container.dart'; import 'package:flutter/cupertino.dart'; import '../../locator.dart'; import '../../util/dr_app_toast_msg.dart'; @@ -158,7 +159,14 @@ class MedicineViewModel extends BaseViewModel { String doseUnit, String icdCode, PatiantInformtion patient, - String patientType}) async { + String patientType, + bool isLocalBusy = false, + BuildContext context, PrescriptionRequestModel prescriptionRequestModel}) async { + if (isLocalBusy) { + setState(ViewState.BusyLocal); + } else { + setState(ViewState.Busy); + } PostPrescriptionReqModel postProcedureReqModel = new PostPrescriptionReqModel(); List prescriptionList = List(); @@ -182,13 +190,16 @@ class MedicineViewModel extends BaseViewModel { 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'); + await _prescriptionService.postPrescription(postProcedureReqModel); + if (_prescriptionService.hasError) { + error = _prescriptionService.error; + if (isLocalBusy) { + setState(ViewState.ErrorLocal); + } else { + setState(ViewState.Error); + } + } else { + setState(ViewState.Idle); } } diff --git a/lib/core/viewModel/prescription_view_model.dart b/lib/core/viewModel/prescription_view_model.dart index 0fc34e1e..d79c9f95 100644 --- a/lib/core/viewModel/prescription_view_model.dart +++ b/lib/core/viewModel/prescription_view_model.dart @@ -118,7 +118,7 @@ class PrescriptionViewModel extends BaseViewModel { setState(ViewState.Idle); } - Future getPrescription({int mrn}) async { + Future getPrescription({int mrn, BuildContext context}) async { hasError = false; //_insuranceCardService.clearInsuranceCard(); setState(ViewState.BusyLocal); diff --git a/lib/screens/prescription/add_prescription/add_drug_widget.dart b/lib/screens/prescription/add_prescription/add_drug_widget.dart index f3d9bedd..67970691 100644 --- a/lib/screens/prescription/add_prescription/add_drug_widget.dart +++ b/lib/screens/prescription/add_prescription/add_drug_widget.dart @@ -1,13 +1,20 @@ import 'package:doctor_app_flutter/config/size_config.dart'; import 'package:doctor_app_flutter/core/viewModel/medicine_view_model.dart'; +import 'package:doctor_app_flutter/screens/patients/profile/soap_update/shared_soap_widgets/bottom_sheet_title.dart'; import 'package:doctor_app_flutter/util/translations_delegate_base.dart'; +import 'package:doctor_app_flutter/widgets/shared/app_scaffold_widget.dart'; +import 'package:doctor_app_flutter/widgets/shared/loader/gif_loader_dialog_utils.dart'; import 'package:flutter/cupertino.dart'; import 'package:flutter/material.dart'; +import '../../../core/enum/viewstate.dart'; import '../../../core/model/Prescriptions/prescription_model.dart'; import '../../../core/model/patient/patiant_info_model.dart'; import '../../../core/model/search_drug/get_medication_response_model.dart'; import '../../../core/viewModel/prescription_view_model.dart'; +import '../../../util/dr_app_toast_msg.dart'; +import '../../../util/helpers.dart'; import '../../../widgets/shared/buttons/app_buttons_widget.dart'; +import '../../patients/profile/soap_update/shared_soap_widgets/bottom_sheet_dialog_button.dart'; import 'drugtodrug.dart'; class AddDrugWidget extends StatefulWidget { @@ -39,60 +46,77 @@ class AddDrugWidget extends StatefulWidget { class _AddDrugWidgetState extends State { @override Widget build(BuildContext context) { - return Container( - height: SizeConfig.realScreenHeight * .8, - width: SizeConfig.realScreenWidth, - child: SingleChildScrollView( - child: Column( - // mainAxisAlignment: MainAxisAlignment.spaceBetween, - children: [ - DrugToDrug( - widget.patient, - widget.medicineModel.getPrescriptionForDrug( - widget.prescriptionList, widget.medicineModel - ), - widget.medicineModel.patientAssessmentList), - Container( - margin: EdgeInsets.all(SizeConfig.widthMultiplier * 3), - child: AppButton( - title: TranslationBase.of(context).addMedication, - onPressed: () { - Navigator.pop(context); - widget.medicineModel.postPrescription( - icdCode: widget.medicineModel.patientAssessmentList.isNotEmpty - ? widget.medicineModel.patientAssessmentList[0].icdCode10ID - .isEmpty - ? "test" - : widget.medicineModel.patientAssessmentList[0].icdCode10ID - .toString() - : "test", - dose: widget.strength, - doseUnit: widget.medicineModel.itemMedicineListUnit.length == 1 - ? widget.medicineModel.itemMedicineListUnit[0]['parameterCode'] - .toString() - : widget.units['parameterCode'].toString(), - patient: widget.patient, - doseTimeIn: widget.doseTime['id'].toString(), - model: widget.modelPrescription, - duration: widget.duration['id'].toString(), - frequency: widget.medicineModel.itemMedicineList.length == 1 - ? widget.medicineModel.itemMedicineList[0]['parameterCode'] - .toString() - : widget.frequency['parameterCode'].toString(), - route: widget.medicineModel.itemMedicineListRoute.length == 1 - ? widget.medicineModel.itemMedicineListRoute[0]['parameterCode'] - .toString() - : widget.route['parameterCode'].toString(), - drugId: widget.selectedMedication.itemId.toString(), - strength: widget.strength, - indication: widget.indication, - instruction: widget.instruction, - doseTime: widget.selectedDate, - ); - }, - )) - ], - )), + return AppScaffold( + baseViewModel: widget.medicineModel, + appBar: BottomSheetTitle(title: "Add Medication",), + body: Container( + height: SizeConfig.realScreenHeight * .8, + width: SizeConfig.realScreenWidth, + child: SingleChildScrollView( + child: Column( + // mainAxisAlignment: MainAxisAlignment.spaceBetween, + children: [ + DrugToDrug( + widget.patient, + widget.medicineModel.getPrescriptionForDrug( + widget.prescriptionList, widget.medicineModel + ), + widget.medicineModel.patientAssessmentList), + ], + )), + ), + bottomSheet: widget.medicineModel.state == ViewState.BusyLocal || widget.medicineModel.state == ViewState.Busy + ? Container( + height: 0, + ) + : BottomSheetDialogButton( + label: TranslationBase.of(context).addMedication, + onTap: () async { + GifLoaderDialogUtils.showMyDialog(context); + await widget.medicineModel.postPrescription( + isLocalBusy: true, + icdCode: widget.medicineModel.patientAssessmentList.isNotEmpty + ? widget.medicineModel.patientAssessmentList[0].icdCode10ID + .isEmpty + ? "test" + : widget.medicineModel.patientAssessmentList[0].icdCode10ID + .toString() + : "test", + dose: widget.strength, + doseUnit: widget.medicineModel.itemMedicineListUnit.length == 1 + ? widget.medicineModel.itemMedicineListUnit[0]['parameterCode'] + .toString() + : widget.units['parameterCode'].toString(), + patient: widget.patient, + doseTimeIn: widget.doseTime['id'].toString(), + model: widget.modelPrescription, + duration: widget.duration['id'].toString(), + frequency: widget.medicineModel.itemMedicineList.length == 1 + ? widget.medicineModel.itemMedicineList[0]['parameterCode'] + .toString() + : widget.frequency['parameterCode'].toString(), + route: widget.medicineModel.itemMedicineListRoute.length == 1 + ? widget.medicineModel.itemMedicineListRoute[0]['parameterCode'] + .toString() + : widget.route['parameterCode'].toString(), + drugId: widget.selectedMedication.itemId.toString(), + strength: widget.strength, + indication: widget.indication, + instruction: widget.instruction, + doseTime: widget.selectedDate, + ); + if (widget.medicineModel.state == ViewState.ErrorLocal) { + GifLoaderDialogUtils.hideDialog(context); + Helpers.showErrorToast(widget.medicineModel.error); + } else if (widget.modelPrescription.state == ViewState.Idle) { + widget.modelPrescription.getPrescriptions(widget.patient); + GifLoaderDialogUtils.hideDialog(context); + DrAppToastMsg.showSuccesToast('Medication has been added'); + Navigator.of(context).pop(); + Navigator.of(context).pop(); + } + }, + ), ); } } diff --git a/lib/screens/prescription/add_prescription/drugtodrug.dart b/lib/screens/prescription/add_prescription/drugtodrug.dart index 70075a6a..b008fda0 100644 --- a/lib/screens/prescription/add_prescription/drugtodrug.dart +++ b/lib/screens/prescription/add_prescription/drugtodrug.dart @@ -11,6 +11,7 @@ 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/medicine/medicine_search_screen.dart'; import 'package:doctor_app_flutter/widgets/shared/app_texts_widget.dart'; +import 'package:doctor_app_flutter/widgets/shared/loader/gif_loader_container.dart'; import 'package:doctor_app_flutter/widgets/shared/network_base_view.dart'; import 'package:flutter/material.dart'; @@ -38,8 +39,8 @@ class _DrugToDrug extends State { ]; - VitalSignsViewModel model = new VitalSignsViewModel(); - SOAPViewModel model2 = new SOAPViewModel(); + VitalSignsViewModel vitalSignsViewModel = new VitalSignsViewModel(); + SOAPViewModel soapViewModel = new SOAPViewModel(); @override void initState() { @@ -52,18 +53,18 @@ class _DrugToDrug extends State { Widget build(BuildContext context) { return isLoaded == true ? BaseView( - onModelReady: (model3) => model3.getDrugToDrug( - model.patientVitalSigns, + onModelReady: (prescriptionViewModel) => prescriptionViewModel.getDrugToDrug( + vitalSignsViewModel.patientVitalSigns, widget.listAssessment, - model2.patientAllergiesList, + soapViewModel.patientAllergiesList, widget.patient, widget.prescription), - builder: (BuildContext context, PrescriptionViewModel model3, + builder: (BuildContext context, PrescriptionViewModel prescriptionViewModel, Widget child) => NetworkBaseView( - baseViewModel: model3, + baseViewModel: prescriptionViewModel, child: Container( - height: SizeConfig.realScreenHeight * .4, + height: SizeConfig.realScreenHeight * .9, child: new ListView.builder( itemCount: expandableList.length, itemBuilder: (context, i) { @@ -73,7 +74,7 @@ class _DrugToDrug extends State { ' ' + '(' + getDrugInfo(expandableList[i]['level'], - model3) + prescriptionViewModel) .length .toString() + ')', @@ -81,7 +82,7 @@ class _DrugToDrug extends State { fontWeight: FontWeight.bold, ), children: getDrugInfo( - expandableList[i]['level'], model3) + expandableList[i]['level'], prescriptionViewModel) .map((item) { return Container( padding: EdgeInsets.all(10), @@ -93,10 +94,8 @@ class _DrugToDrug extends State { })))) : Container( height: SizeConfig.realScreenHeight * .45, - child: Center( - child: CircularProgressIndicator( - valueColor: AlwaysStoppedAnimation(Colors.black), - ))); + child: GifLoaderContainer() + ); } getTypeID() async { @@ -119,17 +118,17 @@ class _DrugToDrug extends State { editedBy: ''); /// TODO Elham* rename model to meaning full not just modle with number - await model.getPatientVitalSign(widget.patient); - await model2.getPatientAllergy(generalGetReqForSOAP); - await model2.getMasterLookup(MasterKeysService.DiagnosisType); - if (model.state == ViewState.Idle && model2.state == ViewState.Idle) { + await vitalSignsViewModel.getPatientVitalSign(widget.patient); + await soapViewModel.getPatientAllergy(generalGetReqForSOAP); + await soapViewModel.getMasterLookup(MasterKeysService.DiagnosisType); + if (vitalSignsViewModel.state == ViewState.Idle && soapViewModel.state == ViewState.Idle) { setState(() { isLoaded = true; }); } } - List getDrugInfo(level, model3) { - return model3.drugToDrug.where((i) => i['Severity'] == level).toList(); + List getDrugInfo(level, prescriptionViewModel) { + return prescriptionViewModel.drugToDrug.where((i) => i['Severity'] == level).toList(); } } diff --git a/lib/screens/prescription/add_prescription/prescription_form_widget.dart b/lib/screens/prescription/add_prescription/prescription_form_widget.dart index 30f97e85..1e68c388 100644 --- a/lib/screens/prescription/add_prescription/prescription_form_widget.dart +++ b/lib/screens/prescription/add_prescription/prescription_form_widget.dart @@ -26,6 +26,7 @@ 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 '../../../widgets/transitions/slide_up_page.dart'; import 'add_drug_widget.dart'; class PrescriptionFormWidget extends StatefulWidget { @@ -590,8 +591,31 @@ class _PrescriptionFormWidgetState extends State { } if (formKey.currentState.validate()) { - Navigator.pop(context); - openDrugToDrug(model, prescriptionViewModel); + Navigator.push( + context, + SlideUpPageRoute( + widget: 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, + ), + ), + ); + // Navigator.pop(context); + // openDrugToDrug(model, prescriptionViewModel); } } else { setState(() {