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/update-procedure.dart

386 lines
17 KiB
Dart

import 'package:doctor_app_flutter/client/base_app_client.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/update_procedure_request_model.dart';
import 'package:doctor_app_flutter/core/viewModel/procedure_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/procedures/entity_list_checkbox_search_widget.dart';
import 'package:doctor_app_flutter/util/dr_app_toast_msg.dart';
import 'package:doctor_app_flutter/util/translations_delegate_base.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_texts_widget.dart';
import 'package:doctor_app_flutter/widgets/shared/dialogs/dailog-list-select.dart';
import 'package:doctor_app_flutter/widgets/shared/loader/gif_loader_dialog_utils.dart';
import 'package:doctor_app_flutter/widgets/shared/network_base_view.dart';
import 'package:flutter/material.dart';
import 'package:hexcolor/hexcolor.dart';
void updateProcedureForm(context,
{String procedureName,
int orderNo,
PatiantInformtion patient,
String orderType,
String procedureId,
String remarks,
ProcedureViewModel model,
String categoreId}) {
//ProcedureViewModel model2 = ProcedureViewModel();
TextEditingController remarksController = TextEditingController();
TextEditingController orderController = TextEditingController();
showModalBottomSheet(
context: context,
isScrollControlled: true,
builder: (BuildContext bc) {
return UpdateProcedureWidget(
procedureName: procedureName,
remarks: remarks,
remarksController: remarksController,
patient: patient,
model: model,
procedureId: procedureId,
categoryId: categoreId,
orderNo: orderNo,
);
});
}
class UpdateProcedureWidget extends StatefulWidget {
final PatiantInformtion patient;
final ProcedureViewModel model;
final String procedureName;
final String remarks;
final TextEditingController remarksController;
final String procedureId;
final String categoryId;
final int orderNo;
UpdateProcedureWidget(
{this.model,
this.procedureName,
this.remarks,
this.remarksController,
this.patient,
this.procedureId,
this.categoryId,
this.orderNo});
@override
_UpdateProcedureWidgetState createState() => _UpdateProcedureWidgetState();
}
class _UpdateProcedureWidgetState extends State<UpdateProcedureWidget> {
int selectedType = 0;
setSelectedType(int val) {
setState(() {
selectedType = val;
});
}
List<EntityList> entityList = List();
dynamic selectedCategory;
@override
Widget build(BuildContext context) {
final screenSize = MediaQuery.of(context).size;
return StatefulBuilder(builder:
(BuildContext context, StateSetter setState /*You can rename this!*/) {
return BaseView<ProcedureViewModel>(
onModelReady: (model) => model.getCategory(),
builder:
(BuildContext context, ProcedureViewModel model, Widget child) =>
NetworkBaseView(
baseViewModel: widget.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: Form(
child: Padding(
padding: EdgeInsets.symmetric(
horizontal: 20.0, vertical: 10.0),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
AppText(
widget.procedureName.toUpperCase(),
fontWeight: FontWeight.w700,
),
SizedBox(
height: 30.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'],
categoryID: selectedCategory[
'categoryId'] <=
9
? "0" +
selectedCategory[
'categoryId']
.toString()
: selectedCategory[
'categoryId']
.toString());
});
},
);
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),
),
),
// 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).urgent),
// Radio(
// activeColor: Color(0xFFB9382C),
// groupValue: selectedType,
// value: 1,
// onChanged: (value) {
// setSelectedType(value);
// },
// ),
// Text('routine'),
// ],
// ),
// ),
// 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: widget.remarks,
// fontSize: 15.0,
// controller: widget.remarksController,
// maxLines: 3,
// minLines: 2,
// onChanged: (value) {},
// ),
// ),
SizedBox(
height: 50.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(
orderNo: widget.orderNo,
orderType: selectedType.toString(),
categorieId: widget.categoryId,
procedureId: widget.procedureId,
entityList: entityList,
patient: widget.patient,
model: widget.model,
remarks:
widget.remarksController.text);
// authorizationForm(context);
},
),
],
),
),
],
),
),
)),
);
}),
),
);
});
}
updateProcedure(
{ProcedureViewModel model,
String remarks,
int orderNo,
String newProcedureId,
String newCategorieId,
List<EntityList> entityList,
String orderType,
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 = orderNo;
controls.add(
Controls(code: "remarks", controlValue: remarks.isEmpty ? '' : remarks),
);
controls.add(
Controls(code: "ordertype", controlValue: "1"),
);
entityList.isNotEmpty
? entityList.forEach((element) {
controlsProcedure.procedure = element.procedureId;
controlsProcedure.category = element.categoryID;
controlsProcedure.controls = controls;
})
: 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');
}
}
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,
),
);
}
}