Claculate Box Quantity while adding prescrption

merge-requests/337/head
hussam al-habibeh 5 years ago
parent 780599a8b2
commit c239dbc620

@ -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;

@ -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<String, dynamic> json) {
itemCode = json['ItemCode'];
strength = json['Strength'];
frequency = json['Frequency'];
duration = json['Duration'];
vidaAuthTokenID = json['VidaAuthTokenID'];
}
Map<String, dynamic> toJson() {
final Map<String, dynamic> data = new Map<String, dynamic>();
data['ItemCode'] = this.itemCode;
data['Strength'] = this.strength;
data['Frequency'] = this.frequency;
data['Duration'] = this.duration;
data['VidaAuthTokenID'] = this.vidaAuthTokenID;
return data;
}
}

@ -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<String, dynamic> json) {
description = json['Description'];
@ -24,6 +25,7 @@ class GetMedicationResponseModel {
price = json['Price'];
quantity = json['Quantity'];
isNarcotic = json['isNarcotic'];
uom = json['uom'];
}
Map<String, dynamic> 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;
}
}

@ -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<dynamic> itemMedicineList = [];
List<dynamic> itemMedicineListRoute = [];
List<dynamic> 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());
}
}

@ -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);

@ -128,6 +128,8 @@ class _PrescriptionFormWidgetState extends State<PrescriptionFormWidget> {
dynamic doseTime;
dynamic indication;
dynamic units;
dynamic uom;
dynamic box;
dynamic x;
List<dynamic> indicationList;
@ -222,7 +224,7 @@ class _PrescriptionFormWidgetState extends State<PrescriptionFormWidget> {
(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<PrescriptionFormWidget> {
? 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<PrescriptionFormWidget> {
"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<PrescriptionFormWidget> {
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<PrescriptionFormWidget> {
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<PrescriptionFormWidget> {
),
),
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(

@ -585,6 +585,18 @@ class _NewPrescriptionScreenState extends State<NewPrescriptionScreen> {
.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<NewPrescriptionScreen> {
.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<NewPrescriptionScreen> {
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,

@ -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<UpdatePrescriptionForm> {
(BuildContext context, StateSetter setState /*You can rename this!*/) {
return BaseView<MedicineViewModel>(
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<UpdatePrescriptionForm> {
(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<UpdatePrescriptionForm> {
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,

@ -388,14 +388,14 @@ class _ProcedureScreenState extends State<ProcedureScreen> {
Row(
children: [
AppText(
TranslationBase.of(context)
.price +
" : ",
fontWeight:
FontWeight
.w700,
),
// AppText(
// TranslationBase.of(context)
// .price +
// " : ",
// fontWeight:
// FontWeight
// .w700,
// ),
// Expanded(
// child: AppText(
// model

Loading…
Cancel
Save