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.
RSGDoctorApp/lib/screens/patient-sick-leave/add_patient_sick_leave_scre...

313 lines
14 KiB
Dart

6 years ago
import 'package:doctor_app_flutter/config/config.dart';
import 'package:doctor_app_flutter/config/size_config.dart';
4 years ago
import 'package:doctor_app_flutter/core/enum/view_state.dart';
import 'package:doctor_app_flutter/core/model/patient/patiant_info_model.dart';
import 'package:doctor_app_flutter/core/model/sickleave/add_sickleave_request.dart';
3 years ago
import 'package:doctor_app_flutter/core/viewModel/sick_leave_view_model.dart';
import 'package:doctor_app_flutter/icons_app/doctor_app_icons.dart';
6 years ago
import 'package:doctor_app_flutter/screens/base/base_view.dart';
import 'package:doctor_app_flutter/screens/patients/profile/soap_update/shared_soap_widgets/bottom_sheet_title.dart';
4 years ago
import 'package:doctor_app_flutter/utils/date-utils.dart';
import 'package:doctor_app_flutter/utils/dr_app_shared_pref.dart';
import 'package:doctor_app_flutter/utils/dr_app_toast_msg.dart';
4 years ago
import 'package:doctor_app_flutter/utils/translations_delegate_base_utils.dart';
3 years ago
import 'package:doctor_app_flutter/utils/utils.dart';
5 years ago
import 'package:doctor_app_flutter/widgets/shared/app_scaffold_widget.dart';
import 'package:doctor_app_flutter/widgets/shared/app_texts_widget.dart';
import 'package:doctor_app_flutter/widgets/shared/buttons/app_buttons_widget.dart';
import 'package:doctor_app_flutter/widgets/shared/loader/gif_loader_dialog_utils.dart';
import 'package:doctor_app_flutter/widgets/shared/text_fields/app-textfield-custom.dart';
6 years ago
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
6 years ago
import 'package:hexcolor/hexcolor.dart';
import 'package:intl/intl.dart';
4 years ago
Utils helpers = Utils();
6 years ago
5 years ago
class AddPatientSickLeaveScreen extends StatefulWidget {
final appointmentNo;
final patientMRN;
final PatiantInformtion? patient;
final SickLeaveViewModel? previousModel;
AddPatientSickLeaveScreen({this.appointmentNo, this.patientMRN, this.patient, this.previousModel});
6 years ago
@override
_AddPatientSickLeaveScreenState createState() => _AddPatientSickLeaveScreenState();
6 years ago
}
5 years ago
class _AddPatientSickLeaveScreenState extends State<AddPatientSickLeaveScreen> {
6 years ago
DrAppSharedPreferances sharedPref = new DrAppSharedPreferances();
TextEditingController _toDateController = new TextEditingController();
TextEditingController _numberOfDayController = new TextEditingController();
TextEditingController _clinicController = new TextEditingController();
TextEditingController _doctorController = new TextEditingController();
TextEditingController _remarkController = new TextEditingController();
DateTime? currentDate;
6 years ago
AddSickLeaveRequest addSickLeave = AddSickLeaveRequest();
bool isFormSubmitted = false;
5 years ago
5 years ago
void _presentDatePicker() {
6 years ago
showDatePicker(
context: context,
initialDate: currentDate ?? DateTime.now(),
firstDate: AppDateUtils.convertStringToDate(
widget!.patient!.arrivedOn!,
),
lastDate: DateTime(DateTime.now().year + 1),
6 years ago
).then((pickedDate) {
if (pickedDate == null) {
return;
}
setState(() {
6 years ago
final df = new DateFormat('yyyy-MM-dd');
addSickLeave.startDate = df.format(pickedDate);
currentDate = pickedDate;
_toDateController.text = AppDateUtils.getDayMonthYearDateFormatted(pickedDate, isMonthShort: true);
6 years ago
});
});
}
@override
void initState() {
super.initState();
}
@override
Widget build(BuildContext context) {
5 years ago
return BaseView<SickLeaveViewModel>(
onModelReady: (model) async {
5 years ago
await model.getDoctorProfile();
_clinicController.text = model.doctorProfile!.clinicDescription!;
_doctorController.text = model.doctorProfile!.doctorName!;
await model.preSickLeaveStatistics(widget.appointmentNo, widget.patientMRN);
},
5 years ago
builder: (_, model, w) => GestureDetector(
onTap: () {
FocusScope.of(context).requestFocus(new FocusNode());
},
child: AppScaffold(
baseViewModel: model,
appBar: BottomSheetTitle(
title: TranslationBase.of(context).addSickLeave,
),
isShowAppBar: true,
body: Center(
child: Container(
margin: EdgeInsets.only(top: 10),
child: FractionallySizedBox(
widthFactor: 0.9,
child: ListView(
5 years ago
children: [
SizedBox(
height: 30,
5 years ago
),
AppTextFieldCustom(
4 years ago
height: Utils.getTextFieldHeight(),
hintText: TranslationBase.of(context).sickLeave + ' ' + TranslationBase.of(context).days,
maxLines: 1,
minLines: 1,
dropDownColor: Colors.white,
isTextFieldHasSuffix: true,
inputFormatters: [FilteringTextInputFormatter.allow(RegExp(ONLY_NUMBERS))],
inputType: TextInputType.number,
controller: _numberOfDayController,
onChanged: (value) {
3 years ago
if (value != null)
setState(() {
addSickLeave.noOfDays = value;
});
},
6 months ago
validationError: isFormSubmitted && (addSickLeave.noOfDays == null) ? TranslationBase.of(context).pleaseEnterNoOfDays : null,
3 years ago
onClick: () {},
onFieldSubmitted: () {},
),
5 years ago
SizedBox(
height: 10,
5 years ago
),
AppTextFieldCustom(
4 years ago
height: Utils.getTextFieldHeight(),
onClick: () {
4 years ago
Utils.hideKeyboard(context);
_presentDatePicker();
},
hintText: TranslationBase.of(context).sickLeaveDate,
enabled: false,
maxLines: 1,
minLines: 1,
isTextFieldHasSuffix: true,
suffixIcon: IconButton(
icon: Icon(Icons.calendar_today),
onPressed: () {},
),
inputFormatters: [FilteringTextInputFormatter.allow(RegExp(ONLY_NUMBERS))],
controller: _toDateController,
onChanged: (value) {
setState(() {
addSickLeave.startDate = value;
});
},
6 months ago
validationError: isFormSubmitted && (addSickLeave.startDate == null) ? TranslationBase.of(context).pleaseEnterDate : null,
3 years ago
onFieldSubmitted: () {},
),
SizedBox(
height: 5,
),
AppTextFieldCustom(
4 years ago
height: Utils.getTextFieldHeight(),
hintText: TranslationBase.of(context).clinic,
enabled: false,
maxLines: 1,
minLines: 1,
dropDownColor: Colors.white,
isTextFieldHasSuffix: true,
inputFormatters: [FilteringTextInputFormatter.allow(RegExp(ONLY_NUMBERS))],
controller: _clinicController,
onChanged: (value) {},
3 years ago
onClick: () {},
onFieldSubmitted: () {},
),
SizedBox(
height: 10,
),
model.sickLeaveStatistics.recommendedSickLeaveDays != null
? Row(
crossAxisAlignment: CrossAxisAlignment.center,
children: [
SizedBox(
width: 10,
),
Icon(
DoctorApp.warning,
size: 20,
5 years ago
color: AppGlobal.inProgressColor,
),
SizedBox(
width: 10,
),
Expanded(
child: AppText(
model.sickLeaveStatistics.recommendedSickLeaveDays!,
textAlign: TextAlign.start,
fontSize: 12,
5 years ago
color: AppGlobal.inProgressColor,
),
),
],
)
: SizedBox(
height: 10,
),
SizedBox(
height: 10,
),
AppTextFieldCustom(
4 years ago
height: Utils.getTextFieldHeight(),
hintText: TranslationBase.of(context).doctor,
enabled: false,
maxLines: 1,
minLines: 1,
dropDownColor: Colors.white,
isTextFieldHasSuffix: true,
inputFormatters: [FilteringTextInputFormatter.allow(RegExp(ONLY_NUMBERS))],
controller: _doctorController,
onChanged: (value) {},
3 years ago
onClick: () {},
onFieldSubmitted: () {},
),
SizedBox(
height: 10,
),
AppTextFieldCustom(
4 years ago
height: Utils.getTextFieldHeight(),
hintText: TranslationBase.of(context).remarks,
maxLines: 30,
minLines: 5,
dropDownColor: Colors.white,
isTextFieldHasSuffix: true,
controller: _remarkController,
onChanged: (value) {
setState(() {
addSickLeave.remarks = value;
});
},
3 years ago
onClick: () {},
onFieldSubmitted: () {},
),
SizedBox(
height: SizeConfig.heightMultiplier! * (SizeConfig.isHeightVeryShort ? 12 : 10) + 20,
5 years ago
),
],
),
),
5 years ago
),
),
bottomSheet: model.state == ViewState.Busy || model.state == ViewState.Busy
? Container(
height: 0,
)
: Container(
decoration: BoxDecoration(
color: Colors.white,
borderRadius: BorderRadius.all(
Radius.circular(0.0),
),
border: Border.all(color: HexColor('#707070'), width: 0),
),
height: SizeConfig.heightMultiplier! * (SizeConfig.isHeightVeryShort ? 12 : 10),
width: double.infinity,
child: Column(
children: [
SizedBox(
height: 10,
),
FractionallySizedBox(
widthFactor: 0.9,
child: AppButton(
title: TranslationBase.of(context).addSickLeaverequest,
color: AppGlobal.appGreenColor,
onPressed: () async {
submitForm(model);
}),
),
SizedBox(
height: 5,
),
],
),
)),
));
6 years ago
}
5 years ago
submitForm(SickLeaveViewModel model) async {
{
try {
setState(() {
isFormSubmitted = true;
});
if (addSickLeave.noOfDays == null || addSickLeave.startDate == null) {
return;
} else {
GifLoaderDialogUtils.showMyDialog(context);
addSickLeave.patientMRN = widget.patient!.patientMRN.toString();
addSickLeave.appointmentNo = widget.patient!.appointmentNo.toString();
await model.addSickLeave(addSickLeave);
6 months ago
print("the state is ${model.state}");
if (model.state == ViewState.ErrorLocal) {
4 years ago
Utils.showErrorToast(model.error);
} else {
await widget.previousModel!.getSickLeaveForPatient(widget.patient!, isLocalBusy: true);
DrAppToastMsg.showSuccesToast(TranslationBase.of(context).replySuccessfully);
Navigator.of(context).pop();
}
6 years ago
GifLoaderDialogUtils.hideDialog(context);
}
} catch (err) {
print(err);
}
5 years ago
}
6 years ago
}
}