diff --git a/lib/core/viewModel/prescription_view_model.dart b/lib/core/viewModel/prescription_view_model.dart index a07ae715..548c0a68 100644 --- a/lib/core/viewModel/prescription_view_model.dart +++ b/lib/core/viewModel/prescription_view_model.dart @@ -1,10 +1,17 @@ +import 'package:doctor_app_flutter/core/enum/filter_type.dart'; import 'package:doctor_app_flutter/core/enum/viewstate.dart'; import 'package:doctor_app_flutter/core/model/Prescription_model.dart'; +import 'package:doctor_app_flutter/core/model/Prescriptions/Prescriptions.dart'; +import 'package:doctor_app_flutter/core/model/Prescriptions/perscription_pharmacy.dart'; +import 'package:doctor_app_flutter/core/model/Prescriptions/prescription_report.dart'; +import 'package:doctor_app_flutter/core/model/Prescriptions/prescription_report_enh.dart'; +import 'package:doctor_app_flutter/core/model/Prescriptions/prescriptions_order.dart'; import 'package:doctor_app_flutter/core/model/get_medication_response_model.dart'; import 'package:doctor_app_flutter/core/model/medical_file_model.dart'; import 'package:doctor_app_flutter/core/model/post_prescrition_req_model.dart'; import 'package:doctor_app_flutter/core/model/search_drug_model.dart'; import 'package:doctor_app_flutter/core/service/prescription_service.dart'; +import 'package:doctor_app_flutter/core/service/prescriptions_service.dart'; import 'package:doctor_app_flutter/core/viewModel/base_view_model.dart'; import 'package:doctor_app_flutter/locator.dart'; import 'package:doctor_app_flutter/models/SOAP/GetAllergiesResModel.dart'; @@ -12,8 +19,10 @@ import 'package:doctor_app_flutter/models/SOAP/GetAssessmentResModel.dart'; import 'package:doctor_app_flutter/models/SOAP/master_key_model.dart'; import 'package:doctor_app_flutter/models/patient/patiant_info_model.dart'; import 'package:doctor_app_flutter/models/patient/vital_sign/patient-vital-sign-data.dart'; +import 'package:flutter/cupertino.dart'; class PrescriptionViewModel extends BaseViewModel { + FilterType filterType = FilterType.Clinic; bool hasError = false; PrescriptionService _prescriptionService = locator(); List get allMedicationList => @@ -26,6 +35,26 @@ class PrescriptionViewModel extends BaseViewModel { List get drugToDrug => _prescriptionService.drugToDrugList; List get itemMedicineList => _prescriptionService.itemMedicineList; + PrescriptionsService _prescriptionsService = locator(); + + List _prescriptionsOrderListClinic = List(); + List _prescriptionsOrderListHospital = List(); + + List get prescriptionReportList => + _prescriptionsService.prescriptionReportList; + + List get prescriptionsList => + _prescriptionsService.prescriptionsList; + + List get pharmacyPrescriptionsList => + _prescriptionsService.pharmacyPrescriptionsList; + List get prescriptionReportEnhList => + _prescriptionsService.prescriptionReportEnhList; + + List get prescriptionsOrderList => + filterType == FilterType.Clinic + ? _prescriptionsOrderListClinic + : _prescriptionsOrderListHospital; Future getItem({int itemID}) async { hasError = false; @@ -119,4 +148,113 @@ class PrescriptionViewModel extends BaseViewModel { } else setState(ViewState.Idle); } + + setFilterType(FilterType filterType) { + this.filterType = filterType; + notifyListeners(); + } + + getPrescriptionReport( + {Prescriptions prescriptions, + @required PatiantInformtion patient}) async { + setState(ViewState.Busy); + await _prescriptionsService.getPrescriptionReport( + prescriptions: prescriptions, patient: patient); + if (_prescriptionsService.hasError) { + error = _prescriptionsService.error; + setState(ViewState.ErrorLocal); + } else { + setState(ViewState.Idle); + } + } + + getListPharmacyForPrescriptions( + {int itemId, @required PatiantInformtion patient}) async { + setState(ViewState.Busy); + await _prescriptionsService.getListPharmacyForPrescriptions( + itemId: itemId, patient: patient); + if (_prescriptionsService.hasError) { + error = _prescriptionsService.error; + setState(ViewState.Error); + } else { + setState(ViewState.Idle); + } + } + + void _filterList() { + _prescriptionsService.prescriptionsList.forEach((element) { + /// PrescriptionsList list sort clinic + List prescriptionsByClinic = + _prescriptionsOrderListClinic + .where((elementClinic) => + elementClinic.filterName == element.clinicDescription) + .toList(); + + if (prescriptionsByClinic.length != 0) { + _prescriptionsOrderListClinic[ + _prescriptionsOrderListClinic.indexOf(prescriptionsByClinic[0])] + .prescriptionsList + .add(element); + } else { + _prescriptionsOrderListClinic.add(PrescriptionsList( + filterName: element.clinicDescription, prescriptions: element)); + } + + /// PrescriptionsList list sort via hospital + List prescriptionsByHospital = + _prescriptionsOrderListHospital + .where( + (elementClinic) => elementClinic.filterName == element.name, + ) + .toList(); + + if (prescriptionsByHospital.length != 0) { + _prescriptionsOrderListHospital[_prescriptionsOrderListHospital + .indexOf(prescriptionsByHospital[0])] + .prescriptionsList + .add(element); + } else { + _prescriptionsOrderListHospital.add(PrescriptionsList( + filterName: element.name, prescriptions: element)); + } + }); + } + + getPrescriptionReportEnh( + {PrescriptionsOrder prescriptionsOrder, + @required PatiantInformtion patient}) async { + setState(ViewState.Busy); + await _prescriptionsService.getPrescriptionReportEnh( + prescriptionsOrder: prescriptionsOrder, patient: patient); + if (_prescriptionsService.hasError) { + error = _prescriptionsService.error; + setState(ViewState.Error); + } else { + setState(ViewState.Idle); + } + } + + _getPrescriptionsOrders() async { + await _prescriptionsService.getPrescriptionsOrders(); + if (_prescriptionsService.hasError) { + error = _prescriptionsService.error; + setState(ViewState.ErrorLocal); + } else { + setState(ViewState.Idle); + } + } + + getPrescriptions(PatiantInformtion patient) async { + setState(ViewState.Busy); + await _prescriptionsService.getPrescriptions(patient); + if (_prescriptionsService.hasError) { + error = _prescriptionsService.error; + setState(ViewState.Error); + } else { + _filterList(); + await _getPrescriptionsOrders(); + + setState(ViewState.Idle); + } + } } diff --git a/lib/screens/prescription/add_prescription_form.dart b/lib/screens/prescription/add_prescription_form.dart index a7e10f25..5dc04221 100644 --- a/lib/screens/prescription/add_prescription_form.dart +++ b/lib/screens/prescription/add_prescription_form.dart @@ -80,6 +80,7 @@ postProcedure( if (model.state == ViewState.ErrorLocal) { helpers.showErrorToast(model.error); } else if (model.state == ViewState.Idle) { + model.getPrescriptions(patient); DrAppToastMsg.showSuccesToast('Medication has been added'); } } diff --git a/lib/screens/prescription/prescriptions_page.dart b/lib/screens/prescription/prescriptions_page.dart index ec27f4bc..aca973da 100644 --- a/lib/screens/prescription/prescriptions_page.dart +++ b/lib/screens/prescription/prescriptions_page.dart @@ -1,8 +1,10 @@ import 'package:doctor_app_flutter/core/enum/filter_type.dart'; +import 'package:doctor_app_flutter/core/viewModel/prescription_view_model.dart'; import 'package:doctor_app_flutter/core/viewModel/prescriptions_view_model.dart'; import 'package:doctor_app_flutter/core/viewModel/project_view_model.dart'; import 'package:doctor_app_flutter/models/patient/patiant_info_model.dart'; import 'package:doctor_app_flutter/screens/base/base_view.dart'; +import 'package:doctor_app_flutter/screens/prescription/add_prescription_form.dart'; import 'package:doctor_app_flutter/screens/prescription/prescription_items_page.dart'; import 'package:doctor_app_flutter/util/date-utils.dart'; import 'package:doctor_app_flutter/util/translations_delegate_base.dart'; @@ -17,7 +19,6 @@ import 'package:flutter/material.dart'; import 'package:provider/provider.dart'; class PrescriptionsPage extends StatelessWidget { - @override Widget build(BuildContext context) { final routeArgs = ModalRoute.of(context).settings.arguments as Map; @@ -25,7 +26,7 @@ class PrescriptionsPage extends StatelessWidget { String patientType = routeArgs['patientType']; String arrivalType = routeArgs['arrivalType']; ProjectViewModel projectViewModel = Provider.of(context); - return BaseView( + return BaseView( onModelReady: (model) => model.getPrescriptions(patient), builder: (_, model, w) => AppScaffold( baseViewModel: model, @@ -35,22 +36,35 @@ class PrescriptionsPage extends StatelessWidget { child: ListView( physics: BouncingScrollPhysics(), children: [ - PatientProfileHeaderNewDesign(patient,arrivalType??'0',patientType), - SizedBox(height: 12,), + PatientProfileHeaderNewDesign( + patient, arrivalType ?? '0', patientType), + SizedBox( + height: 12, + ), Padding( padding: const EdgeInsets.all(8.0), child: Column( crossAxisAlignment: CrossAxisAlignment.start, children: [ - Texts('Order',style: "caption2",color: Colors.black,fontSize: 13,), - Texts('Prescriptions',bold: true,fontSize: 22,), + Texts( + 'Order', + style: "caption2", + color: Colors.black, + fontSize: 13, + ), + Texts( + 'Prescriptions', + bold: true, + fontSize: 22, + ), ], ), ), - if(patientType!=null && patientType=='7') + if (patientType != null && patientType == '7') InkWell( - onTap: (){ - //TODO Hussam call the add page here + onTap: () { + addPrescriptionForm( + context, model, patient, model.prescriptionList); }, child: Container( width: double.maxFinite, @@ -73,40 +87,55 @@ class PrescriptionsPage extends StatelessWidget { borderRadius: BorderRadius.circular(10), ), child: Center( - child: Icon(Icons.add,color: Colors.white,), + child: Icon( + Icons.add, + color: Colors.white, + ), ), ), - SizedBox(height: 10,), - Texts('Apply for New Prescriptions Order',color: Colors.grey[600],fontWeight: FontWeight.w600,) + SizedBox( + height: 10, + ), + Texts( + 'Apply for New Prescriptions Order', + color: Colors.grey[600], + fontWeight: FontWeight.w600, + ) ], ), ), ), ), ), - ...List.generate(model.prescriptionsList.length, (index) => InkWell( - onTap: () => Navigator.push( - context, - FadePage( - page: PrescriptionItemsPage( - prescriptions: model.prescriptionsList[index], - patient: patient, - patientType: patientType, - arrivalType: arrivalType, - ), - ), - ), - child: DoctorCard( - doctorName: model.prescriptionsList[index].doctorName, - profileUrl: model.prescriptionsList[index].doctorImageURL, - branch: model.prescriptionsList[index].name, - clinic: model.prescriptionsList[index].clinicDescription, - isPrescriptions: true, - appointmentDate: DateUtils.getDateTimeFromServerFormat(model.prescriptionsList[index].appointmentDate,), - ) - - )) - + ...List.generate( + model.prescriptionsList.length, + (index) => InkWell( + onTap: () => Navigator.push( + context, + FadePage( + page: PrescriptionItemsPage( + prescriptions: + model.prescriptionsList[index], + patient: patient, + patientType: patientType, + arrivalType: arrivalType, + ), + ), + ), + child: DoctorCard( + doctorName: + model.prescriptionsList[index].doctorName, + profileUrl: + model.prescriptionsList[index].doctorImageURL, + branch: model.prescriptionsList[index].name, + clinic: model + .prescriptionsList[index].clinicDescription, + isPrescriptions: true, + appointmentDate: + DateUtils.getDateTimeFromServerFormat( + model.prescriptionsList[index].appointmentDate, + ), + ))) ], ), ), diff --git a/pubspec.lock b/pubspec.lock index 46eca7cf..e15e02c9 100644 --- a/pubspec.lock +++ b/pubspec.lock @@ -608,7 +608,7 @@ packages: name: meta url: "https://pub.dartlang.org" source: hosted - version: "1.3.0-nullsafety.3" + version: "1.3.0-nullsafety.4" mime: dependency: transitive description: @@ -900,7 +900,7 @@ packages: name: stack_trace url: "https://pub.dartlang.org" source: hosted - version: "1.10.0-nullsafety.1" + version: "1.10.0-nullsafety.2" stream_channel: dependency: transitive description: @@ -1084,5 +1084,5 @@ packages: source: hosted version: "2.2.1" sdks: - dart: ">=2.10.0 <2.11.0" + dart: ">=2.10.0 <=2.11.0-213.1.beta" flutter: ">=1.22.0 <2.0.0"