refactor some files in prescription screen

merge-requests/967/head
RoaaGhali98 4 years ago
parent 3f25acda8f
commit 113fb42d68

@ -8,20 +8,16 @@ import 'package:doctor_app_flutter/core/service/patient_medical_file/prescriptio
import 'package:doctor_app_flutter/core/service/patient_medical_file/procedure/procedure_service.dart';
import 'package:doctor_app_flutter/core/model/SOAP/GetAssessmentReqModel.dart';
import 'package:doctor_app_flutter/core/model/SOAP/GetAssessmentResModel.dart';
import 'package:flutter/cupertino.dart';
import 'package:doctor_app_flutter/core/viewModel/prescription_view_model.dart';
import '../../locator.dart';
import '../../util/dr_app_toast_msg.dart';
import '../../util/helpers.dart';
import '../model/Prescriptions/post_prescrition_req_model.dart';
import '../model/Prescriptions/prescription_model.dart';
import 'base_view_model.dart';
class MedicineViewModel extends BaseViewModel {
bool hasError = false;
// dynamic route;
// dynamic frequency;
// dynamic duration;
// dynamic units;
MedicineService _medicineService = locator<MedicineService>();
ProcedureService _procedureService = locator<ProcedureService>();
PrescriptionService _prescriptionService = locator<PrescriptionService>();
@ -30,8 +26,6 @@ class MedicineViewModel extends BaseViewModel {
_procedureService.templateList;
List<ProcedureTempleteDetailsModelList> templateList = List();
GetMedicationResponseModel _selectedMedication;
get pharmacyItemsList => _medicineService.pharmacyItemsList;
get searchText => _medicineService.searchText;
@ -72,8 +66,6 @@ class MedicineViewModel extends BaseViewModel {
Future getItem({int itemID}) async {
//hasError = false;
//_insuranceCardService.clearInsuranceCard();
setState(ViewState.Busy);
await _prescriptionService.getItem(itemID: itemID);
if (_prescriptionService.hasError) {
@ -155,6 +147,56 @@ class MedicineViewModel extends BaseViewModel {
}
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<PrescriptionRequestModel> 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');
}
}
Future getAssessmentList ({
PatiantInformtion patientInfo,
@ -216,7 +258,8 @@ class MedicineViewModel extends BaseViewModel {
setState(ViewState.Idle);
}
Future getMedicationList({String drug}) async {
Future getMedicationList({String drug, bool isLocalBusy = true})
async {
setState(ViewState.Busy);
await _prescriptionService.getMedicationList(drug: drug);
if (_prescriptionService.hasError) {
@ -226,6 +269,27 @@ class MedicineViewModel extends BaseViewModel {
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);

@ -96,7 +96,7 @@ class PrescriptionViewModel extends BaseViewModel {
Future getPrescription({int mrn}) async {
hasError = false;
//_insuranceCardService.clearInsuranceCard();
setState(ViewState.Busy);
setState(ViewState.BusyLocal);
await _prescriptionService.getPrescription(mrn: mrn);
if (_prescriptionService.hasError) {
error = _prescriptionService.error;
@ -109,7 +109,7 @@ class PrescriptionViewModel extends BaseViewModel {
PostPrescriptionReqModel postProcedureReqModel, int mrn) async {
hasError = false;
//_insuranceCardService.clearInsuranceCard();
setState(ViewState.Busy);
setState(ViewState.BusyLocal);
await _prescriptionService.postPrescription(postProcedureReqModel);
if (_prescriptionService.hasError) {
error = _prescriptionService.error;
@ -121,7 +121,7 @@ class PrescriptionViewModel extends BaseViewModel {
}
Future getMedicationList({String drug}) async {
setState(ViewState.Busy);
setState(ViewState.BusyLocal);
await _prescriptionService.getMedicationList(drug: drug);
if (_prescriptionService.hasError) {
error = _prescriptionService.error;
@ -134,7 +134,7 @@ class PrescriptionViewModel extends BaseViewModel {
PostPrescriptionReqModel updatePrescriptionReqModel, int mrn) async {
hasError = false;
//_insuranceCardService.clearInsuranceCard();
setState(ViewState.Busy);
setState(ViewState.BusyLocal);
await _prescriptionService.updatePrescription(updatePrescriptionReqModel);
if (_prescriptionService.hasError) {
error = _prescriptionService.error;
@ -164,7 +164,7 @@ class PrescriptionViewModel extends BaseViewModel {
PatiantInformtion patient,
List<dynamic> prescription) async {
hasError = false;
setState(ViewState.Busy);
setState(ViewState.BusyLocal);
await _prescriptionService.getDrugToDrug(
vital, lstAssessments, allergy, patient, prescription);
if (_prescriptionService.hasError) {
@ -182,7 +182,7 @@ class PrescriptionViewModel extends BaseViewModel {
getPrescriptionReport(
{Prescriptions prescriptions,
@required PatiantInformtion patient}) async {
setState(ViewState.Busy);
setState(ViewState.BusyLocal);
await _prescriptionsService.getPrescriptionReport(
prescriptions: prescriptions, patient: patient);
if (_prescriptionsService.hasError) {
@ -195,7 +195,7 @@ class PrescriptionViewModel extends BaseViewModel {
getListPharmacyForPrescriptions(
{int itemId, @required PatiantInformtion patient}) async {
setState(ViewState.Busy);
setState(ViewState.BusyLocal);
await _prescriptionsService.getListPharmacyForPrescriptions(
itemId: itemId, patient: patient);
if (_prescriptionsService.hasError) {
@ -270,7 +270,7 @@ class PrescriptionViewModel extends BaseViewModel {
}
getPrescriptions(PatiantInformtion patient, {String patientType}) async {
setState(ViewState.Busy);
setState(ViewState.BusyLocal);
await _prescriptionsService.getPrescriptions(patient);
if (_prescriptionsService.hasError) {
error = _prescriptionsService.error;
@ -287,7 +287,7 @@ class PrescriptionViewModel extends BaseViewModel {
}
getMedicationForInPatient(PatiantInformtion patient) async {
setState(ViewState.Busy);
setState(ViewState.BusyLocal);
await _prescriptionsService.getMedicationForInPatient(patient);
if (_prescriptionsService.hasError) {
error = _prescriptionsService.error;

@ -14,10 +14,13 @@ import 'drugtodrug.dart';
class AddDrugWidget extends StatefulWidget {
final PatiantInformtion patient;
final List<PrescriptionModel> prescriptionList;
final PrescriptionViewModel model;
final MedicineViewModel medicineModel;
final PrescriptionViewModel modelPrescription;
const AddDrugWidget({Key key, this.patient, this.prescriptionList, this.model}) : super(key: key);
const AddDrugWidget({Key key, this.patient, this.prescriptionList, this.medicineModel, this.modelPrescription}) : super(key: key);
@override
_AddDrugWidgetState createState() => _AddDrugWidgetState();
@ -38,12 +41,12 @@ class _AddDrugWidgetState extends State<AddDrugWidget> {
@override
Widget build(BuildContext context) {
MedicineViewModel model;
GetMedicationResponseModel _selectedMedication;
TextEditingController indicationController = TextEditingController();
TextEditingController instructionController = TextEditingController();
DateTime selectedDate;
return Container(
height: SizeConfig.realScreenHeight * .8,
width: SizeConfig.realScreenWidth,
@ -53,10 +56,10 @@ class _AddDrugWidgetState extends State<AddDrugWidget> {
children: [
DrugToDrug(
widget.patient,
model.getPrescriptionForDrug(
widget.prescriptionList, model
widget.medicineModel.getPrescriptionForDrug(
widget.prescriptionList, widget.medicineModel
),
model.patientAssessmentList),
widget.medicineModel.patientAssessmentList),
Container(
margin: EdgeInsets.all(SizeConfig.widthMultiplier * 3),
child: AppButton(
@ -64,29 +67,29 @@ class _AddDrugWidgetState extends State<AddDrugWidget> {
onPressed: () {
Navigator.pop(context);
postPrescription(
icdCode: model.patientAssessmentList.isNotEmpty
? model.patientAssessmentList[0].icdCode10ID
widget.medicineModel.postPrescription(
icdCode: widget.medicineModel.patientAssessmentList.isNotEmpty
? widget.medicineModel.patientAssessmentList[0].icdCode10ID
.isEmpty
? "test"
: model.patientAssessmentList[0].icdCode10ID
: widget.medicineModel.patientAssessmentList[0].icdCode10ID
.toString()
: "test",
dose: strengthController.text,
doseUnit: model.itemMedicineListUnit.length == 1
? model.itemMedicineListUnit[0]['parameterCode']
doseUnit: widget.medicineModel.itemMedicineListUnit.length == 1
? widget.medicineModel.itemMedicineListUnit[0]['parameterCode']
.toString()
: units['parameterCode'].toString(),
patient: widget.patient,
doseTimeIn: doseTime['id'].toString(),
model: widget.model,
model: widget.modelPrescription,
duration: duration['id'].toString(),
frequency: model.itemMedicineList.length == 1
? model.itemMedicineList[0]['parameterCode']
frequency: widget.medicineModel.itemMedicineList.length == 1
? widget.medicineModel.itemMedicineList[0]['parameterCode']
.toString()
: frequency['parameterCode'].toString(),
route: model.itemMedicineListRoute.length == 1
? model.itemMedicineListRoute[0]['parameterCode']
route: widget.medicineModel.itemMedicineListRoute.length == 1
? widget.medicineModel.itemMedicineListRoute[0]['parameterCode']
.toString()
: route['parameterCode'].toString(),
drugId: _selectedMedication.itemId.toString(),
@ -99,12 +102,6 @@ class _AddDrugWidgetState extends State<AddDrugWidget> {
))
],
)),
//],
//)
);
}
}

@ -37,64 +37,58 @@ import 'package:provider/provider.dart';
import 'package:speech_to_text/speech_recognition_error.dart';
import 'package:speech_to_text/speech_to_text.dart' as stt;
addPrescriptionForm(context, PrescriptionViewModel model,
PatiantInformtion patient, prescription) {
showModalBottomSheet(
isScrollControlled: true,
context: context,
builder: (BuildContext bc) {
return PrescriptionFormWidget(model, patient, prescription);
});
}
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<PrescriptionRequestModel> 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');
}
}
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<PrescriptionRequestModel> 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;
@ -196,6 +190,7 @@ class _PrescriptionFormWidgetState extends State<PrescriptionFormWidget> {
recognizedWord = status == 'listening' ? 'Listening...' : 'Sorry....';
}
// void requestPermissions() async {
// void requestPermissions() async {
// Map<Permission, PermissionStatus> statuses = await [
// Permission.microphone,
@ -234,6 +229,7 @@ class _PrescriptionFormWidgetState extends State<PrescriptionFormWidget> {
builder: (
BuildContext context,
MedicineViewModel model,
Widget child,) =>
NetworkBaseView(
baseViewModel: model,
@ -858,89 +854,7 @@ class _PrescriptionFormWidgetState extends State<PrescriptionFormWidget> {
if (formKey.currentState
.validate()) {
Navigator.pop(context);
openDrugToDrug(model);
{
// postProcedure(
// icdCode: model
// .patientAssessmentList
// .isNotEmpty
// ? model
// .patientAssessmentList[
// 0]
// .icdCode10ID
// .isEmpty
// ? "test"
// : model
// .patientAssessmentList[
// 0]
// .icdCode10ID
// .toString()
// : "test",
// // icdCode: model
// // .patientAssessmentList
// // .map((value) => value
// // .icdCode10ID
// // .trim())
// // .toList()
// // .join(' '),
// dose: strengthController
// .text,
// doseUnit: model
// .itemMedicineListUnit
// .length ==
// 1
// ? model
// .itemMedicineListUnit[
// 0][
// 'parameterCode']
// .toString()
// : units['parameterCode']
// .toString(),
// patient: widget.patient,
// doseTimeIn:
// doseTime['id']
// .toString(),
// model: widget.model,
// duration: duration['id']
// .toString(),
// frequency: model
// .itemMedicineList
// .length ==
// 1
// ? model
// .itemMedicineList[
// 0][
// 'parameterCode']
// .toString()
// : frequency[
// 'parameterCode']
// .toString(),
// route: model.itemMedicineListRoute
// .length ==
// 1
// ? model
// .itemMedicineListRoute[
// 0][
// 'parameterCode']
// .toString()
// : route['parameterCode']
// .toString(),
// drugId:
// _selectedMedication
// .itemId
// .toString(),
// strength:
// strengthController
// .text,
// indication:
// indicationController
// .text,
// instruction:
// instructionController
// .text,
// doseTime: selectedDate,
// );
}
openDrugToDrug(model, widget.model);
}
} else {
setState(() {
@ -996,7 +910,6 @@ class _PrescriptionFormWidgetState extends State<PrescriptionFormWidget> {
}
});
}
formKey.currentState.save();
},
),
@ -1039,154 +952,20 @@ class _PrescriptionFormWidgetState extends State<PrescriptionFormWidget> {
});
}
}
// InputDecoration textFieldSelectorDecoration(
// String hintText, String selectedText, bool isDropDown,
// {Icon suffixIcon}) {
// return InputDecoration(
// focusedBorder: OutlineInputBorder(
// borderSide: BorderSide(color: Color(0xFFCCCCCC), width: 2.0),
// borderRadius: BorderRadius.circular(8),
// ),
// enabledBorder: OutlineInputBorder(
// borderSide: BorderSide(color: Color(0xFFEFEFEF), width: 2.0),
// borderRadius: BorderRadius.circular(8),
// ),
// disabledBorder: OutlineInputBorder(
// borderSide: BorderSide(color: Color(0xFFEFEFEF), width: 2.0),
// borderRadius: BorderRadius.circular(8),
// ),
// hintText: selectedText != null ? selectedText : hintText,
// suffixIcon: isDropDown
// ? suffixIcon != null
// ? suffixIcon
// : Icon(
// Icons.keyboard_arrow_down_sharp,
// color: Color(0xff2E303A),
// )
// : null,
// hintStyle: TextStyle(
// fontSize: 13,
// color: Color(0xff2E303A),
// fontFamily: 'Poppins',
// fontWeight: FontWeight.w600,
// ),
// labelText: selectedText != null ? '$hintText\n$selectedText' : null,
// labelStyle: TextStyle(
// fontSize: 13,
// color: Color(0xff2E303A),
// fontFamily: 'Poppins',
// fontWeight: FontWeight.w600,
// ),
// );
// }
openDrugToDrug(MedicineViewModel model) {
openDrugToDrug(MedicineViewModel model, PrescriptionViewModel modelPrescription) {
showModalBottomSheet(
context: context,
builder: (context) {
/// TODO Elham* Move this to widget
return Container(
height: SizeConfig.realScreenHeight * .8,
width: SizeConfig.realScreenWidth,
child: SingleChildScrollView(
child: Column(
// mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
DrugToDrug(
widget.patient,
model.getPrescriptionForDrug(
widget.prescriptionList, model
),
model.patientAssessmentList),
Container(
margin: EdgeInsets.all(SizeConfig.widthMultiplier * 3),
child: AppButton(
title: TranslationBase.of(context).addMedication,
onPressed: () {
Navigator.pop(context);
postPrescription(
icdCode: model.patientAssessmentList.isNotEmpty
? model.patientAssessmentList[0].icdCode10ID
.isEmpty
? "test"
: model.patientAssessmentList[0].icdCode10ID
.toString()
: "test",
dose: strengthController.text,
doseUnit: model.itemMedicineListUnit.length == 1
? model.itemMedicineListUnit[0]['parameterCode']
.toString()
: units['parameterCode'].toString(),
patient: widget.patient,
doseTimeIn: doseTime['id'].toString(),
model: widget.model,
duration: duration['id'].toString(),
frequency: model.itemMedicineList.length == 1
? model.itemMedicineList[0]['parameterCode']
.toString()
: frequency['parameterCode'].toString(),
route: model.itemMedicineListRoute.length == 1
? model.itemMedicineListRoute[0]['parameterCode']
.toString()
: route['parameterCode'].toString(),
drugId: _selectedMedication.itemId.toString(),
strength: strengthController.text,
indication: indicationController.text,
instruction: instructionController.text,
doseTime: selectedDate,
);
},
))
],
)),
return AddDrugWidget(
patient: widget.patient,
medicineModel: model,
modelPrescription: modelPrescription,
prescriptionList: widget.prescriptionList,
);
});
}
// getPrescriptionForDrug(
// List<PrescriptionModel> prescriptionList, MedicineViewModel model) {
// var prescriptionDetails = [];
// if (prescriptionList.length > 0) {
// prescriptionList[0].entityList.forEach((element) {
// if (element.mediSpanGPICode != null) {
// prescriptionDetails.add({
// 'DrugId': element.mediSpanGPICode,
// 'DrugName': element.medicationName,
// 'Dose': element.doseDailyQuantity,
// 'DoseType': element.doseDailyUnitID,
// 'Unit': element.uom,
// 'FrequencyType': element.frequencyID,
// 'Duration': element.doseDurationDays,
// 'RouteID': element.routeID,
// 'IsScreen': element.isSIG
// });
// }
// });
// }
// 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;
// }
searchMedicine(context, MedicineViewModel model) async {
FocusScope.of(context).unfocus();

Loading…
Cancel
Save