diff --git a/lib/config/config.dart b/lib/config/config.dart index 704dc7da..35c35ef3 100644 --- a/lib/config/config.dart +++ b/lib/config/config.dart @@ -209,6 +209,8 @@ const GET_ITEM_BY_MEDICINE = const GET_PROCEDURE_VALIDATION = 'Services/DoctorApplication.svc/REST/ValidateProcedures'; +const GET_BOX_QUANTITY = + 'Services/DoctorApplication.svc/REST/CalculateBoxQuantity'; var selectedPatientType = 1; diff --git a/lib/core/model/calculate_box_request_model.dart b/lib/core/model/calculate_box_request_model.dart new file mode 100644 index 00000000..80281854 --- /dev/null +++ b/lib/core/model/calculate_box_request_model.dart @@ -0,0 +1,32 @@ +class CalculateBoxQuantityRequestModel { + int itemCode; + double strength; + int frequency; + int duration; + String vidaAuthTokenID; + + CalculateBoxQuantityRequestModel( + {this.itemCode, + this.strength, + this.frequency, + this.duration, + this.vidaAuthTokenID}); + + CalculateBoxQuantityRequestModel.fromJson(Map json) { + itemCode = json['ItemCode']; + strength = json['Strength']; + frequency = json['Frequency']; + duration = json['Duration']; + vidaAuthTokenID = json['VidaAuthTokenID']; + } + + Map toJson() { + final Map data = new Map(); + data['ItemCode'] = this.itemCode; + data['Strength'] = this.strength; + data['Frequency'] = this.frequency; + data['Duration'] = this.duration; + data['VidaAuthTokenID'] = this.vidaAuthTokenID; + return data; + } +} diff --git a/lib/core/model/get_medication_response_model.dart b/lib/core/model/get_medication_response_model.dart index 1f9597f5..d0173ed9 100644 --- a/lib/core/model/get_medication_response_model.dart +++ b/lib/core/model/get_medication_response_model.dart @@ -6,7 +6,7 @@ class GetMedicationResponseModel { dynamic price; dynamic quantity; bool isNarcotic; - + String uom; GetMedicationResponseModel( {this.description, this.genericName, @@ -14,7 +14,8 @@ class GetMedicationResponseModel { this.keywords, this.price, this.quantity, - this.isNarcotic}); + this.isNarcotic, + this.uom}); GetMedicationResponseModel.fromJson(Map json) { description = json['Description']; @@ -24,6 +25,7 @@ class GetMedicationResponseModel { price = json['Price']; quantity = json['Quantity']; isNarcotic = json['isNarcotic']; + uom = json['uom']; } Map toJson() { @@ -35,6 +37,7 @@ class GetMedicationResponseModel { data['Price'] = this.price; data['Quantity'] = this.quantity; data['isNarcotic'] = this.isNarcotic; + data['uom'] = this.uom; return data; } } diff --git a/lib/core/service/prescription_service.dart b/lib/core/service/prescription_service.dart index 54640fcc..12ae96f2 100644 --- a/lib/core/service/prescription_service.dart +++ b/lib/core/service/prescription_service.dart @@ -1,5 +1,6 @@ import 'package:doctor_app_flutter/config/config.dart'; import 'package:doctor_app_flutter/core/model/Prescription_model.dart'; +import 'package:doctor_app_flutter/core/model/calculate_box_request_model.dart'; import 'package:doctor_app_flutter/core/model/get_medication_response_model.dart'; import 'package:doctor_app_flutter/core/model/item_by_medicine_request_model.dart'; import 'package:doctor_app_flutter/core/model/prescription_req_model.dart'; @@ -27,6 +28,7 @@ class PrescriptionService extends LookupService { List itemMedicineList = []; List itemMedicineListRoute = []; List itemMedicineListUnit = []; + dynamic boxQuantity; PrescriptionReqModel _prescriptionReqModel = PrescriptionReqModel(); ItemByMedicineRequestModel _itemByMedicineRequestModel = @@ -36,6 +38,9 @@ class PrescriptionService extends LookupService { search: ["Amoxicillin"], ); + CalculateBoxQuantityRequestModel _boxQuantityRequestModel = + CalculateBoxQuantityRequestModel(); + PostPrescriptionReqModel _postPrescriptionReqModel = PostPrescriptionReqModel(); @@ -232,4 +237,23 @@ class PrescriptionService extends LookupService { super.error = error; }, body: request); } + + Future calculateBoxQuantity( + {int freq, int duration, int itemCode, double strength}) async { + _boxQuantityRequestModel = CalculateBoxQuantityRequestModel( + frequency: freq, + duration: duration, + itemCode: itemCode, + strength: strength); + + hasError = false; + + await baseAppClient.post(GET_BOX_QUANTITY, + onSuccess: (dynamic response, int statusCode) { + boxQuantity = response['BoxQuantity']; + }, onFailure: (String error, int statusCode) { + hasError = true; + super.error = error; + }, body: _boxQuantityRequestModel.toJson()); + } } diff --git a/lib/core/viewModel/medicine_view_model.dart b/lib/core/viewModel/medicine_view_model.dart index 9f446f46..a029b519 100644 --- a/lib/core/viewModel/medicine_view_model.dart +++ b/lib/core/viewModel/medicine_view_model.dart @@ -25,6 +25,7 @@ class MedicineViewModel extends BaseViewModel { get medicationRouteList => _prescriptionService.medicationRouteList; get medicationFrequencyList => _prescriptionService.medicationFrequencyList; + get boxQuintity => _prescriptionService.boxQuantity; get medicationIndicationsList => _prescriptionService.medicationIndicationsList; @@ -149,6 +150,18 @@ class MedicineViewModel extends BaseViewModel { setState(ViewState.Idle); } + Future getBoxQuantity( + {int itemCode, int duration, double strength, int freq}) async { + setState(ViewState.Busy); + await _prescriptionService.calculateBoxQuantity( + strength: strength, itemCode: itemCode, duration: duration, freq: freq); + if (_prescriptionService.hasError) { + error = _prescriptionService.error; + setState(ViewState.Error); + } else + setState(ViewState.Idle); + } + Future getPharmaciesList(int itemId) async { setState(ViewState.Busy); await _medicineService.getPharmaciesList(itemId); diff --git a/lib/screens/prescription/add_prescription_form.dart b/lib/screens/prescription/add_prescription_form.dart index 81e85dfa..0153ebd5 100644 --- a/lib/screens/prescription/add_prescription_form.dart +++ b/lib/screens/prescription/add_prescription_form.dart @@ -128,6 +128,8 @@ class _PrescriptionFormWidgetState extends State { dynamic doseTime; dynamic indication; dynamic units; + dynamic uom; + dynamic box; dynamic x; List indicationList; @@ -222,7 +224,7 @@ class _PrescriptionFormWidgetState extends State { (BuildContext context, ScrollController scrollController) { return SingleChildScrollView( child: Container( - height: 1010, + height: MediaQuery.of(context).size.height * 1.45, child: Padding( padding: EdgeInsets.symmetric( horizontal: 12.0, vertical: 10.0), @@ -262,12 +264,35 @@ class _PrescriptionFormWidgetState extends State { ? AutoCompleteTextField< GetMedicationResponseModel>( onFocusChanged: (__) { - _selectedMedication != null - ? model.getItem( - itemID: - _selectedMedication - .itemId) - : null; + if (_selectedMedication != + null) { + model.getItem( + itemID: + _selectedMedication + .itemId); + uom = _selectedMedication.uom; + } else { + null; + } + 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; + } }, decoration: textFieldSelectorDecoration( @@ -383,6 +408,26 @@ class _PrescriptionFormWidgetState extends State { "Only 5 Digits allowed for strength"); } }, + onSubmit: (_) { + 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; + } + }, // validator: (value) { // if (value.isEmpty && // strengthController.text.length > @@ -524,6 +569,27 @@ class _PrescriptionFormWidgetState extends State { 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; + } }); }, ); @@ -706,6 +772,29 @@ class _PrescriptionFormWidgetState extends State { 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; + } }); }, ); @@ -732,6 +821,90 @@ class _PrescriptionFormWidgetState extends State { ), ), SizedBox(height: spaceBetweenTextFileds), + Container( + height: screenSize.height * 0.070, + child: InkWell( + onTap: model.allMedicationList != null + ? () { + Helpers.hideKeyboard(context); + ListSelectDialog dialog = + ListSelectDialog( + list: model.allMedicationList, + attributeName: 'nameEn', + attributeValueId: 'id', + okText: + TranslationBase.of(context) + .ok, + okFunction: (selectedValue) { + setState(() { + duration = selectedValue; + }); + }, + ); + showDialog( + barrierDismissible: false, + context: context, + builder: + (BuildContext context) { + return dialog; + }, + ); + } + : null, + child: TextField( + decoration: textFieldSelectorDecoration( + "UOM", + uom != null ? uom : null, + true), + //enabled: false, + readOnly: true, + ), + ), + ), + Container( + height: screenSize.height * 0.070, + child: InkWell( + onTap: model.allMedicationList != null + ? () { + Helpers.hideKeyboard(context); + ListSelectDialog dialog = + ListSelectDialog( + list: model.allMedicationList, + attributeName: 'nameEn', + attributeValueId: 'id', + okText: + TranslationBase.of(context) + .ok, + okFunction: (selectedValue) { + setState(() { + duration = selectedValue; + }); + }, + ); + showDialog( + barrierDismissible: false, + context: context, + builder: + (BuildContext context) { + return dialog; + }, + ); + } + : null, + child: TextField( + decoration: textFieldSelectorDecoration( + "Box Quantity", + box != null + ? "Box Quantity: " + + model.boxQuintity.toString() + : null, + true), + //enabled: false, + readOnly: true, + ), + ), + ), + SizedBox(height: spaceBetweenTextFileds), Container( decoration: BoxDecoration( borderRadius: BorderRadius.all( diff --git a/lib/screens/prescription/prescription_screen.dart b/lib/screens/prescription/prescription_screen.dart index ab152bf1..6e9f0676 100644 --- a/lib/screens/prescription/prescription_screen.dart +++ b/lib/screens/prescription/prescription_screen.dart @@ -585,6 +585,18 @@ class _NewPrescriptionScreenState extends State { .edit), onTap: () { updatePrescriptionForm( + box: model + .prescriptionList[ + 0] + .entityList[ + index] + .quantity, + uom: model + .prescriptionList[ + 0] + .entityList[ + index] + .uom, drugNameGeneric: model .prescriptionList[ 0] @@ -595,8 +607,9 @@ class _NewPrescriptionScreenState extends State { .toString(), doseStreangth: model.prescriptionList[0].entityList[index].doseDailyQuantity .toString(), - duration: model.prescriptionList[0].entityList[index].doseDurationDays - .toString(), + duration: + model.prescriptionList[0].entityList[index].doseDurationDays + .toString(), startDate: model.prescriptionList[0].entityList[index].startDate .toString(), @@ -611,18 +624,12 @@ class _NewPrescriptionScreenState extends State { model.prescriptionList[0].entityList[index].frequencyID .toString(), rouat: model - .prescriptionList[ - 0] - .entityList[ - index] - .routeID - .toString(), - patient: - patient, - drugId: model .prescriptionList[0] .entityList[index] - .medicineCode, + .routeID + .toString(), + patient: patient, + drugId: model.prescriptionList[0].entityList[index].medicineCode, drugName: model.prescriptionList[0].entityList[index].doseDetail, remarks: model.prescriptionList[0].entityList[index].remarks, model: model, diff --git a/lib/screens/prescription/update_prescription_form.dart b/lib/screens/prescription/update_prescription_form.dart index 7892a1cd..998b28f2 100644 --- a/lib/screens/prescription/update_prescription_form.dart +++ b/lib/screens/prescription/update_prescription_form.dart @@ -37,6 +37,8 @@ class UpdatePrescriptionForm extends StatefulWidget { final String startDate; final String frequency; final String drugNameGeneric; + final String uom; + final int box; final PrescriptionViewModel model; @@ -54,7 +56,9 @@ class UpdatePrescriptionForm extends StatefulWidget { this.enteredRemarks, this.frequency, this.model, - this.drugNameGeneric}); + this.drugNameGeneric, + this.uom, + this.box}); @override _UpdatePrescriptionFormState createState() => _UpdatePrescriptionFormState(); } @@ -116,7 +120,7 @@ class _UpdatePrescriptionFormState extends State { (BuildContext context, StateSetter setState /*You can rename this!*/) { return BaseView( onModelReady: (model) async { - //await model.getMedicationList(); + await model.getMedicationList(); await model.getMedicationStrength(); await model.getMedicationDuration(); await model.getMedicationRoute(); @@ -151,7 +155,7 @@ class _UpdatePrescriptionFormState extends State { (BuildContext context, ScrollController scrollController) { return SingleChildScrollView( child: Container( - height: MediaQuery.of(context).size.height * 2.0, + height: MediaQuery.of(context).size.height * 1.5, child: Form( child: Padding( padding: EdgeInsets.symmetric( @@ -678,6 +682,96 @@ class _UpdatePrescriptionFormState extends State { SizedBox( height: 12.0, ), + Container( + height: screenSize.height * 0.070, + child: InkWell( + onTap: model.allMedicationList != null + ? () { + Helpers.hideKeyboard(context); + ListSelectDialog dialog = + ListSelectDialog( + list: model.allMedicationList, + attributeName: 'nameEn', + attributeValueId: 'id', + okText: TranslationBase.of( + context) + .ok, + okFunction: (selectedValue) { + setState(() { + // duration = selectedValue; + }); + }, + ); + showDialog( + barrierDismissible: false, + context: context, + builder: + (BuildContext context) { + return dialog; + }, + ); + } + : null, + child: TextField( + decoration: + textFieldSelectorDecoration( + "UOM", + widget.uom != null + ? widget.uom + : null, + true), + // enabled: false, + readOnly: true, + ), + ), + ), + Container( + height: screenSize.height * 0.070, + child: InkWell( + onTap: model.allMedicationList != null + ? () { + Helpers.hideKeyboard(context); + ListSelectDialog dialog = + ListSelectDialog( + list: model.allMedicationList, + attributeName: 'nameEn', + attributeValueId: 'id', + okText: TranslationBase.of( + context) + .ok, + okFunction: (selectedValue) { + setState(() { + // duration = selectedValue; + }); + }, + ); + showDialog( + barrierDismissible: false, + context: context, + builder: + (BuildContext context) { + return dialog; + }, + ); + } + : null, + child: TextField( + decoration: + textFieldSelectorDecoration( + 'Box Quantity', + widget.box != null + ? "Box Quantity: " + + widget.box.toString() + : null, + true), + // enabled: false, + readOnly: true, + ), + ), + ), + SizedBox( + height: 12.0, + ), Container( decoration: BoxDecoration( borderRadius: BorderRadius.all( @@ -931,6 +1025,8 @@ void updatePrescriptionForm( String doseStreangth, String doseUnit, String enteredRemarks, + String uom, + int box, String startDate}) { TextEditingController remarksController = TextEditingController(); TextEditingController doseController = TextEditingController(); @@ -941,6 +1037,8 @@ void updatePrescriptionForm( isScrollControlled: true, builder: (BuildContext context) { return UpdatePrescriptionForm( + box: box, + uom: uom, drugName: drugName, patient: patient, doseStreangth: doseStreangth, diff --git a/lib/screens/procedures/procedure_screen.dart b/lib/screens/procedures/procedure_screen.dart index c66b66a9..c7da891e 100644 --- a/lib/screens/procedures/procedure_screen.dart +++ b/lib/screens/procedures/procedure_screen.dart @@ -388,14 +388,14 @@ class _ProcedureScreenState extends State { Row( children: [ - AppText( - TranslationBase.of(context) - .price + - " : ", - fontWeight: - FontWeight - .w700, - ), + // AppText( + // TranslationBase.of(context) + // .price + + // " : ", + // fontWeight: + // FontWeight + // .w700, + // ), // Expanded( // child: AppText( // model