You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
doctor_app_flutter/lib/screens/procedures/procedure_screen.dart

1005 lines
52 KiB
Dart

import 'package:doctor_app_flutter/client/base_app_client.dart';
import 'package:doctor_app_flutter/config/config.dart';
import 'package:doctor_app_flutter/config/size_config.dart';
import 'package:doctor_app_flutter/core/enum/viewstate.dart';
import 'package:doctor_app_flutter/core/model/procedure/ControlsModel.dart';
import 'package:doctor_app_flutter/core/model/procedure/categories_procedure.dart';
import 'package:doctor_app_flutter/core/model/procedure/post_procedure_req_model.dart';
import 'package:doctor_app_flutter/core/model/procedure/update_procedure_request_model.dart';
import 'package:doctor_app_flutter/core/viewModel/prescription_view_model.dart';
import 'package:doctor_app_flutter/core/viewModel/procedure_View_model.dart';
import 'package:doctor_app_flutter/icons_app/doctor_app_icons.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/procedures/entity_list_checkbox_search_widget.dart';
import 'package:doctor_app_flutter/util/dr_app_toast_msg.dart';
import 'package:doctor_app_flutter/util/helpers.dart';
import 'package:doctor_app_flutter/util/translations_delegate_base.dart';
import 'package:doctor_app_flutter/widgets/patients/profile/patient_profile_widget.dart';
import 'package:doctor_app_flutter/widgets/shared/Text.dart';
import 'package:doctor_app_flutter/widgets/shared/TextFields.dart';
import 'package:doctor_app_flutter/widgets/shared/app_buttons_widget.dart';
import 'package:doctor_app_flutter/widgets/shared/app_scaffold_widget.dart';
import 'package:doctor_app_flutter/widgets/shared/app_text_form_field.dart';
import 'package:doctor_app_flutter/widgets/shared/app_texts_widget.dart';
import 'package:doctor_app_flutter/widgets/shared/dialogs/dailog-list-select.dart';
import 'package:doctor_app_flutter/widgets/shared/divider_with_spaces_around.dart';
import 'package:doctor_app_flutter/widgets/shared/master_key_checkbox_search_widget.dart';
import 'package:doctor_app_flutter/widgets/shared/network_base_view.dart';
import 'package:eva_icons_flutter/eva_icons_flutter.dart';
import 'package:flutter/material.dart';
import 'package:hexcolor/hexcolor.dart';
class ProcedureScreen extends StatefulWidget {
@override
_ProcedureScreenState createState() => _ProcedureScreenState();
}
class _ProcedureScreenState extends State<ProcedureScreen> {
int selectedType = 0;
int testNum = 1;
PatiantInformtion patient;
setSelectedType(int val) {
setState(() {
selectedType = val;
});
}
TextEditingController procedureController = TextEditingController();
@override
Widget build(BuildContext context) {
final routeArgs = ModalRoute.of(context).settings.arguments as Map;
patient = routeArgs['patient'];
return BaseView<ProcedureViewModel>(
onModelReady: (model) => model.getProcedure(mrn: patient.patientMRN),
builder: (BuildContext context, ProcedureViewModel model, Widget child) =>
AppScaffold(
isShowAppBar: true,
appBarTitle: TranslationBase.of(context).orderProcedure,
body: NetworkBaseView(
baseViewModel: model,
child: SingleChildScrollView(
child: Container(
child: Column(
children: [
Padding(
padding: EdgeInsets.all(12.0),
child: Row(
children: <Widget>[
AvatarWidget(
Icon(
patient.genderDescription == "Male"
? DoctorApp.male
: DoctorApp.female_icon,
size: 70,
color: Colors.white,
),
),
SizedBox(
width: 20,
),
Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
AppText(
patient.firstName + ' ' + patient.lastName,
color: Colors.black,
fontWeight: FontWeight.bold,
),
Row(
children: [
AppText(
TranslationBase.of(context).age2,
color: Colors.black,
fontWeight: FontWeight.bold,
),
SizedBox(
width: 5.0,
),
AppText(
patient.age.toString(),
color: Colors.black,
fontWeight: FontWeight.normal,
),
],
),
AppText(
"ALLERGIC TO: FOOD, ASPIRIN",
color: Color(0xFFB9382C),
fontWeight: FontWeight.bold,
),
],
)
],
),
),
Divider(
height: 1.0,
thickness: 1.0,
color: Colors.grey,
),
(model.procedureList.length != 0)
? SizedBox(
height: model.procedureList[0].rowcount == 0
? 200.0
: 10.0)
: SizedBox(height: 200.0),
//model.prescriptionList == null
(model.procedureList.length != 0)
? model.procedureList[0].rowcount == 0
? Column(
mainAxisAlignment: MainAxisAlignment.center,
crossAxisAlignment:
CrossAxisAlignment.stretch,
children: [
InkWell(
onTap: () {
model
.getProcedureCategory()
.then((value) {
addSelectedProcedure(
context, model, patient);
});
//model.postPrescription();
},
child: CircleAvatar(
radius: 65,
backgroundColor: Color(0XFFB8382C),
child: CircleAvatar(
radius: 60,
backgroundColor: Colors.white,
child: Icon(
Icons.add,
color: Colors.black,
size: 45.0,
),
),
),
),
SizedBox(
height: 15.0,
),
Row(
mainAxisAlignment:
MainAxisAlignment.center,
children: [
AppText(
'NO ORDER FOR PROCEDURE LISTED',
color: Colors.black,
fontWeight: FontWeight.w900,
),
],
),
Row(
mainAxisAlignment:
MainAxisAlignment.center,
children: [
AppText(
TranslationBase.of(context).addNow,
color: Color(0XFFB8382C),
fontWeight: FontWeight.w700,
),
],
),
],
)
: Padding(
padding: EdgeInsets.all(16.0),
child: NetworkBaseView(
baseViewModel: model,
child: Column(
mainAxisAlignment:
MainAxisAlignment.start,
children: [
InkWell(
child: Container(
height: 50.0,
width: 450.0,
decoration: BoxDecoration(
border: Border.all(
color: Colors.grey),
borderRadius:
BorderRadius.circular(10.0),
),
child: Padding(
padding: EdgeInsets.all(8.0),
child: Row(
mainAxisAlignment:
MainAxisAlignment
.spaceBetween,
children: [
AppText(
TranslationBase.of(
context)
.addMoreProcedure,
fontWeight:
FontWeight.w100,
fontSize: 12.5,
),
Icon(
Icons.add,
color: Color(0XFFB8382C),
)
],
),
),
),
onTap: () {
model
.getProcedureCategory()
.then((value) {
addSelectedProcedure(
context, model, patient);
});
//model.postPrescription();
},
),
// Container(
// decoration: BoxDecoration(
// borderRadius: BorderRadius.all(
// Radius.circular(6.0)),
// border: Border.all(
// width: 1.0,
// color: HexColor("#CCCCCC"))),
// child: AppTextFormField(
// labelText: 'Add more procedure',
// borderColor: Colors.white,
// //suffixIcon: Icons.search,
//
// //textInputType: TextInputType.number,
// inputFormatter: ONLY_NUMBERS,
// onTap: () {
// addSelectedProcedure(context);
// },
// ),
// ),
SizedBox(
height: 35.0,
),
...List.generate(
model.procedureList[0].rowcount,
(index) => Container(
child: Column(
children: [
Row(
mainAxisAlignment:
MainAxisAlignment
.spaceBetween,
children: [
Container(
height: 120.0,
width: 45.0,
child: Column(
children: [
AppText(
DateTime.parse(model
.procedureList[
0]
.entityList[
index]
.orderDate)
.day
.toString(),
color:
Colors.green,
),
AppText(
Helpers.getMonth(model
.procedureList[
0]
.entityList[
index]
.orderDate !=
null
? (DateTime.parse(model
.procedureList[
0]
.entityList[
index]
.orderDate)
.month)
: DateTime
.now()
.month)
.toUpperCase(),
color:
Colors.green,
)
],
),
),
Expanded(
child: Container(
height: 120,
width: 325.0,
child: Column(
children: [
Row(
children: [
AppText(
TranslationBase.of(context)
.codeNo +
" : ",
fontWeight:
FontWeight
.w700,
fontSize:
15.0,
),
AppText(
model
.procedureList[
0]
.entityList[
index]
.procedureId
.toString(),
fontSize:
13.0,
),
SizedBox(
width: 12.0,
),
AppText(
TranslationBase.of(context)
.orderType +
" : ",
fontWeight:
FontWeight
.w700,
fontSize:
15.0,
),
AppText(
model.procedureList[0].entityList[index].orderType ==
1
? 'Regular'
: 'Urgent',
fontSize:
13.0,
color: Color(
0xFFB9382C),
),
],
),
Row(
children: [
Container(
child:
Expanded(
child:
AppText(
model
.procedureList[0]
.entityList[index]
.procedureName,
fontWeight:
FontWeight.w800,
),
),
)
],
),
Row(
children: [
AppText(
TranslationBase.of(context)
.price +
" : ",
fontWeight:
FontWeight
.w700,
),
// Expanded(
// child: AppText(
// model
// .procedureList[
// 0]
// .entityList[
// index]
// .price
// .toString(),
// fontSize:
// 13.0),
// )
],
),
SizedBox(
height: 10.0,
),
Row(
children: [
Expanded(
child:
AppText(
model
.procedureList[
0]
.entityList[
index]
.remarks
.toString(),
fontSize:
13.5,
),
),
],
),
SizedBox(
height: 10.0,
),
Divider(
height: 5.0,
thickness: 1.0,
color:
Colors.grey,
)
// SizedBox(
// height: 40,
// ),
],
),
),
),
Container(
child: Column(
children: [
InkWell(
child: Icon(
Icons.edit),
onTap: () {
// model
// .updateProcedure();
updateProcedureForm(
context,
remarks: model
.procedureList[
0]
.entityList[
index]
.remarks,
procedureName: model
.procedureList[
0]
.entityList[
index]
.procedureName,
patient:
patient,
procedureId: model
.procedureList[
0]
.entityList[
index]
.procedureId,
categoreId: model
.procedureList[
0]
.entityList[
index]
.categoryID
.toString());
},
)
],
),
)
],
),
],
),
),
),
],
),
),
)
: Column(
mainAxisAlignment: MainAxisAlignment.center,
crossAxisAlignment: CrossAxisAlignment.stretch,
children: [
InkWell(
onTap: () {
model
.getProcedureCategory()
.then((value) {
addSelectedProcedure(
context, model, patient);
});
//model.postPrescription();
},
child: CircleAvatar(
radius: 65,
backgroundColor: Color(0XFFB8382C),
child: CircleAvatar(
radius: 60,
backgroundColor: Colors.white,
child: Icon(
Icons.add,
color: Colors.black,
size: 45.0,
),
),
),
),
SizedBox(
height: 15.0,
),
Row(
mainAxisAlignment: MainAxisAlignment.center,
children: [
AppText(
'NO ORDER FOR PROCEDURE LISTED',
color: Colors.black,
fontWeight: FontWeight.w900,
),
],
),
Row(
mainAxisAlignment: MainAxisAlignment.center,
children: [
AppText(
TranslationBase.of(context).addNow,
color: Color(0XFFB8382C),
fontWeight: FontWeight.w700,
),
],
),
],
)
],
),
),
),
)),
);
}
void updateProcedureForm(context,
{String procedureName,
PatiantInformtion patient,
String procedureId,
String remarks,
String categoreId}) {
ProcedureViewModel model = ProcedureViewModel();
TextEditingController remarksController = TextEditingController();
TextEditingController orderController = TextEditingController();
showModalBottomSheet(
context: context,
isScrollControlled: true,
builder: (BuildContext bc) {
return Container(
height: MediaQuery.of(context).size.height * 0.55,
child: Form(
child: Padding(
padding:
EdgeInsets.symmetric(horizontal: 20.0, vertical: 10.0),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
AppText(
procedureName.toUpperCase(),
fontWeight: FontWeight.w700,
),
SizedBox(
height: 30.0,
),
Container(
child: Row(
children: [
AppText(TranslationBase.of(context).orderType),
Radio(
activeColor: Color(0xFFB9382C),
value: 0,
groupValue: selectedType,
onChanged: (value) {
setSelectedType(value);
},
),
Text(TranslationBase.of(context).regular),
Radio(
activeColor: Color(0xFFB9382C),
groupValue: selectedType,
value: 1,
onChanged: (value) {
setSelectedType(value);
},
),
Text(TranslationBase.of(context).urgent),
],
),
),
SizedBox(
height: 12.0,
),
Container(
decoration: BoxDecoration(
borderRadius:
BorderRadius.all(Radius.circular(6.0)),
border: Border.all(
width: 1.0, color: HexColor("#CCCCCC"))),
child: TextFields(
hintText: remarks,
controller: remarksController,
maxLines: 5,
minLines: 3,
),
),
SizedBox(
height: 100.0,
),
Container(
margin: EdgeInsets.all(SizeConfig.widthMultiplier * 2),
child: Wrap(
alignment: WrapAlignment.center,
children: <Widget>[
AppButton(
title: TranslationBase.of(context)
.updateProcedure
.toUpperCase(),
onPressed: () {
Navigator.pop(context);
updateProcedure(
categorieId: categoreId,
procedureId: procedureId,
patient: patient,
model: model,
remarks: remarksController.text);
// authorizationForm(context);
},
),
],
),
),
],
),
),
));
});
}
}
postProcedure(
{ProcedureViewModel model,
String remarks,
PatiantInformtion patient,
List<EntityList> entityList}) async {
PostProcedureReqModel postProcedureReqModel = new PostProcedureReqModel();
List<Controls> controls = List();
List<Procedures> controlsProcedure = List();
postProcedureReqModel.appointmentNo = patient.appointmentNo;
postProcedureReqModel.episodeID = patient.episodeNo;
postProcedureReqModel.patientMRN = patient.patientMRN;
entityList.forEach((element) {
controls.add(
Controls(code: "remarks", controlValue: remarks.isEmpty ? '' : remarks),
);
});
entityList.forEach((element) {
controlsProcedure.add(Procedures(
category: element.categoryID,
procedure: element.procedureId,
controls: controls));
});
postProcedureReqModel.procedures = controlsProcedure;
await model.postProcedure(postProcedureReqModel, patient.patientMRN);
if (model.state == ViewState.ErrorLocal) {
helpers.showErrorToast(model.error);
model.getProcedure(mrn: patient.patientMRN);
} else if (model.state == ViewState.Idle) {
DrAppToastMsg.showSuccesToast('procedure has been added');
}
}
updateProcedure(
{ProcedureViewModel model,
String remarks,
String procedureId,
PatiantInformtion patient,
String categorieId}) async {
UpdateProcedureRequestModel updateProcedureReqModel =
new UpdateProcedureRequestModel();
List<Controls> controls = List();
ProcedureDetail controlsProcedure = new ProcedureDetail();
updateProcedureReqModel.appointmentNo = patient.appointmentNo;
updateProcedureReqModel.episodeID = patient.episodeNo;
updateProcedureReqModel.patientMRN = patient.patientMRN;
updateProcedureReqModel.lineItemNo = 1;
updateProcedureReqModel.orderNo = 0;
controls.add(
Controls(code: "02", controlValue: remarks.isEmpty ? '' : remarks),
);
controlsProcedure.procedure = procedureId;
controlsProcedure.category = categorieId;
controlsProcedure.controls = controls;
// controlsProcedure.add(ProcedureDetail(
// category: categorieId, procedure: procedureId, controls: controls));
updateProcedureReqModel.procedureDetail = controlsProcedure;
await model.updateProcedure(
updateProcedureRequestModel: updateProcedureReqModel,
mrn: patient.patientMRN);
if (model.state == ViewState.ErrorLocal) {
helpers.showErrorToast(model.error);
model.getProcedure(mrn: patient.patientMRN);
} else if (model.state == ViewState.Idle) {
DrAppToastMsg.showSuccesToast('procedure has been updated');
}
}
void addSelectedProcedure(
context, ProcedureViewModel model, PatiantInformtion patient) {
showModalBottomSheet(
context: context,
isScrollControlled: true,
builder: (BuildContext bc) {
return AddSelectedProcedure(
model: model,
patient: patient,
);
});
}
class AddSelectedProcedure extends StatefulWidget {
final ProcedureViewModel model;
final PatiantInformtion patient;
const AddSelectedProcedure({Key key, this.model, this.patient})
: super(key: key);
@override
_AddSelectedProcedureState createState() =>
_AddSelectedProcedureState(patient: patient, model: model);
}
class _AddSelectedProcedureState extends State<AddSelectedProcedure> {
int selectedType;
ProcedureViewModel model;
PatiantInformtion patient;
_AddSelectedProcedureState({this.patient, this.model});
TextEditingController procedureController = TextEditingController();
TextEditingController remarksController = TextEditingController();
List<EntityList> entityList = List();
dynamic selectedCategory;
setSelectedType(int val) {
setState(() {
selectedType = val;
});
}
@override
Widget build(BuildContext context) {
final screenSize = MediaQuery.of(context).size;
return BaseView<ProcedureViewModel>(
onModelReady: (model) => model.getCategory(),
builder: (BuildContext context, ProcedureViewModel model, Widget child) =>
NetworkBaseView(
baseViewModel: model,
child: DraggableScrollableSheet(
minChildSize: 0.90,
initialChildSize: 0.95,
maxChildSize: 1.0,
builder: (BuildContext context, ScrollController scrollController) {
return SingleChildScrollView(
child: Container(
height: MediaQuery.of(context).size.height * 1.20,
child: Padding(
padding: EdgeInsets.all(12.0),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
AppText(
TranslationBase.of(context)
.selectProcedures
.toUpperCase(),
fontWeight: FontWeight.w900,
),
SizedBox(
height: 10.0,
),
Container(
height: screenSize.height * 0.070,
child: InkWell(
onTap: model.categoryList != null &&
model.categoryList.length > 0
? () {
ListSelectDialog dialog = ListSelectDialog(
list: model.categoryList,
attributeName: 'categoryName',
attributeValueId: 'categoryId',
okText: TranslationBase.of(context).ok,
okFunction: (selectedValue) {
setState(() {
selectedCategory = selectedValue;
model.getProcedureCategory(
categoryName: selectedCategory[
'categoryName']);
});
},
);
showDialog(
barrierDismissible: false,
context: context,
builder: (BuildContext context) {
return dialog;
},
);
//model.getProcedureCategory();
}
: null,
child: TextField(
decoration: textFieldSelectorDecoration(
TranslationBase.of(context)
.procedureCategorise,
selectedCategory != null
? selectedCategory['categoryName']
: null,
true,
suffixIcon: Icon(
Icons.search,
color: Colors.black,
)),
enabled: false,
),
),
),
if (widget.model.categoriesList.length != 0)
NetworkBaseView(
baseViewModel: model,
child: EntityListCheckboxSearchWidget(
model: widget.model,
masterList:
widget.model.categoriesList[0].entityList,
removeHistory: (item) {
setState(() {
entityList.remove(item);
});
},
addHistory: (history) {
setState(() {
entityList.add(history);
});
},
addSelectedHistories: () {
//TODO build your fun herr
// widget.addSelectedHistories();
},
isEntityListSelected: (master) =>
isEntityListSelected(master),
),
),
SizedBox(
height: 15.0,
),
Column(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
Container(
child: Row(
children: [
AppText(
TranslationBase.of(context).orderType),
Radio(
activeColor: Color(0xFFB9382C),
value: 0,
groupValue: selectedType,
onChanged: (value) {
setSelectedType(value);
},
),
Text(TranslationBase.of(context).regular),
Radio(
activeColor: Color(0xFFB9382C),
groupValue: selectedType,
value: 1,
onChanged: (value) {
setSelectedType(value);
},
),
Text(TranslationBase.of(context).urgent),
],
),
),
SizedBox(
height: 15.0,
),
TextFields(
hintText: TranslationBase.of(context).remarks,
controller: remarksController,
minLines: 3,
maxLines: 5,
),
SizedBox(
height: 50.0,
),
Container(
margin: EdgeInsets.all(
SizeConfig.widthMultiplier * 5),
child: Wrap(
alignment: WrapAlignment.center,
children: <Widget>[
AppButton(
title: TranslationBase.of(context)
.addSelectedProcedures,
onPressed: () {
Navigator.pop(context);
postProcedure(
entityList: entityList,
patient: patient,
model: widget.model,
remarks: remarksController.text);
},
),
],
),
),
],
)
],
),
),
),
);
}),
),
);
}
bool isEntityListSelected(EntityList masterKey) {
Iterable<EntityList> history = entityList
.where((element) => masterKey.procedureId == element.procedureId);
if (history.length > 0) {
return true;
}
return false;
}
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(0xFFCCCCCC), width: 2.0),
borderRadius: BorderRadius.circular(8),
),
disabledBorder: OutlineInputBorder(
borderSide: BorderSide(color: Color(0xFFCCCCCC), width: 2.0),
borderRadius: BorderRadius.circular(8),
),
hintText: selectedText != null ? selectedText : hintText,
suffixIcon: isDropDown
? suffixIcon != null
? suffixIcon
: Icon(
Icons.arrow_drop_down,
color: Colors.black,
)
: null,
hintStyle: TextStyle(
fontSize: 14,
color: Colors.grey.shade600,
),
);
}
}