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/sick-leave/sick_leave.dart

413 lines
19 KiB
Dart

import 'package:doctor_app_flutter/config/config.dart';
import 'package:doctor_app_flutter/config/shared_pref_kay.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/viewModel/patient_view_model.dart';
import 'package:doctor_app_flutter/core/viewModel/sick_leave_view_model.dart';
import 'package:doctor_app_flutter/models/sickleave/add_sickleave_request.dart';
import 'package:doctor_app_flutter/models/sickleave/get_all_sickleave_response.dart';
import 'package:doctor_app_flutter/routes.dart';
import 'package:doctor_app_flutter/screens/base/base_view.dart';
import 'package:doctor_app_flutter/screens/sick-leave/add-sickleave.dart';
import 'package:doctor_app_flutter/util/dr_app_shared_pref.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/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';
import 'package:doctor_app_flutter/widgets/shared/text_fields/app_text_form_field.dart';
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:hexcolor/hexcolor.dart';
import 'package:intl/intl.dart';
Helpers helpers = Helpers();
class SickLeaveScreen extends StatefulWidget {
final bool isExtended;
final GetAllSickLeaveResponse extendedData;
final appointmentNo;
final patientMRN;
final patient;
SickLeaveScreen(
{this.appointmentNo,
this.patientMRN,
this.isExtended = false,
this.extendedData,
this.patient});
@override
_SickLeaveScreenState createState() => _SickLeaveScreenState();
}
class _SickLeaveScreenState extends State<SickLeaveScreen> {
DrAppSharedPreferances sharedPref = new DrAppSharedPreferances();
TextEditingController _toDateController = new TextEditingController();
TextEditingController _numberOfController = new TextEditingController();
TextEditingController _clinicController = new TextEditingController();
TextEditingController _doctorController = new TextEditingController();
TextEditingController _remarkController = new TextEditingController();
String _selectedClinic;
Map profile = {};
AddSickLeaveRequest addSickLeave = AddSickLeaveRequest();
void _presentDatePicker(id) {
showDatePicker(
context: context,
initialDate: DateTime.now(),
firstDate: DateTime(2019),
lastDate: DateTime(2050),
).then((pickedDate) {
if (pickedDate == null) {
return;
}
setState(() {
// var selectedDate = DateFormat.yMd().format(pickedDate);
final df = new DateFormat('yyyy-MM-dd');
addSickLeave.startDate = df.format(pickedDate);
_toDateController.text = addSickLeave.startDate;
//addSickLeave.startDate = selectedDate;
});
});
}
@override
void initState() {
getProfile();
super.initState();
}
@override
Widget build(BuildContext context) {
return BaseView<PatientViewModel>(
onModelReady: (model) async {
await model.getClinicsList();
_clinicController.text = getClinicName(model);
_doctorController.text = profile['DoctorName'];
},
builder: (_, model, w) => BaseView<SickLeaveViewModel>(
onModelReady: (model2) => model2.preSickLeaveStatistics(
widget.appointmentNo, widget.patientMRN),
builder: (_, model2, w) => GestureDetector(
onTap: () {
FocusScope.of(context).requestFocus(new FocusNode());
},
child: AppScaffold(
baseViewModel: model2,
appBarTitle: widget.isExtended == true
? TranslationBase.of(context).extendSickLeave
: TranslationBase.of(context).addSickLeave,
isShowAppBar: true,
body: Center(
child: Container(
margin: EdgeInsets.only(top: 10),
child: FractionallySizedBox(
widthFactor: 0.9,
child: ListView(
children: [
SizedBox(
height: 30,
),
AppTextFieldCustom(
height: Helpers.getTextFieldHeight(),
hintText: widget.extendedData != null
? widget.extendedData.noOfDays.toString()
: TranslationBase.of(context).sickLeave +
' ' +
TranslationBase.of(context).days,
maxLines: 1,
minLines: 1,
dropDownColor: Colors.white,
isTextFieldHasSuffix: true,
inputFormatters: [
FilteringTextInputFormatter.allow(
RegExp(ONLY_NUMBERS))
],
controller: _numberOfController,
onChanged: (value) {
addSickLeave.noOfDays = value;
if (widget.extendedData != null) {
widget.extendedData.noOfDays =
int.parse(value);
}
},
// validationError: isFormSubmitted &&
// _selectedMedicationFrequency ==
// null
// ? TranslationBase
// .of(context)
// .emptyMessage
// : null,
),
SizedBox(
height: 10,
),
AppTextFieldCustom(
height: Helpers.getTextFieldHeight(),
onClick: () {
_presentDatePicker('_selectedToDate');
},
hintText: widget.extendedData != null
? widget.extendedData.startDate
: TranslationBase.of(context).sickLeaveDate,
enabled: false,
maxLines: 1,
minLines: 1,
isTextFieldHasSuffix: true,
suffixIcon: IconButton(
icon: Icon(Icons.calendar_today)),
inputFormatters: [
FilteringTextInputFormatter.allow(
RegExp(ONLY_NUMBERS))
],
controller: _toDateController,
onChanged: (value) {
addSickLeave.startDate = value;
if (widget.extendedData != null) {
widget.extendedData.startDate = value;
}
},
),
SizedBox(
height: 5,
),
AppTextFieldCustom(
height: Helpers.getTextFieldHeight(),
hintText:
TranslationBase.of(context).clinicName,
enabled: false,
maxLines: 1,
minLines: 1,
dropDownColor: Colors.white,
isTextFieldHasSuffix: true,
inputFormatters: [
FilteringTextInputFormatter.allow(
RegExp(ONLY_NUMBERS))
],
controller: _clinicController,
onChanged: (value) {},
),
SizedBox(
height: 10,
),
model2.sickLeaveStatistics[
'recommendedSickLeaveDays'] !=
null
? AppText(
model2.sickLeaveStatistics[
'recommendedSickLeaveDays'],
fontWeight: FontWeight.bold,
textAlign: TextAlign.start,
fontSize: 15,
)
: SizedBox(
height: 10,
),
SizedBox(
height: 10,
),
AppTextFieldCustom(
height: Helpers.getTextFieldHeight(),
hintText:
TranslationBase.of(context).doctorName,
enabled: false,
maxLines: 1,
minLines: 1,
dropDownColor: Colors.white,
isTextFieldHasSuffix: true,
inputFormatters: [
FilteringTextInputFormatter.allow(
RegExp(ONLY_NUMBERS))
],
controller: _doctorController,
onChanged: (value) {},
),
SizedBox(
height: 10,
),
AppTextFieldCustom(
height: Helpers.getTextFieldHeight(),
hintText: widget.extendedData != null
? widget.extendedData.remarks
: TranslationBase.of(context).remarks,
maxLines: 30,
minLines: 5,
dropDownColor: Colors.white,
isTextFieldHasSuffix: true,
controller: _remarkController,
onChanged: (value) {
addSickLeave.remarks = value;
if (widget.extendedData != null) {
widget.extendedData.remarks = value;
}
},
),
],
),
),
),
),
bottomSheet: model2.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: widget.isExtended == true
? TranslationBase.of(context).extend
: TranslationBase.of(context)
.addSickLeaverequest,
color: Colors.green,
onPressed: () async {
if (widget.isExtended) {
await model2.extendSickLeave(
widget.extendedData);
DrAppToastMsg.showSuccesToast(
model2.sickleaveResponse[
'ListSickLeavesToExtent']
['success']);
Navigator.of(context)
.popUntil((route) {
return route.settings.name ==
PATIENTS_PROFILE;
});
Navigator.of(context).pushNamed(
ADD_SICKLEAVE,
arguments: {
'patient': widget.patient
});
//print(value);
//});
} else {
try {
if (addSickLeave.noOfDays == null) {
DrAppToastMsg.showErrorToast(
TranslationBase.of(context)
.pleaseEnterNoOfDays);
} else if (addSickLeave.remarks ==
null) {
DrAppToastMsg.showErrorToast(
TranslationBase.of(context)
.pleaseEnterRemarks);
} else if (addSickLeave.startDate ==
null) {
DrAppToastMsg.showErrorToast(
TranslationBase.of(context)
.pleaseEnterDate);
} else {
GifLoaderDialogUtils.showMyDialog(
context);
addSickLeave.patientMRN = widget
.patient.patientMRN
.toString();
addSickLeave.appointmentNo =
widget.patient.appointmentNo
.toString();
await model2
.addSickLeave(addSickLeave);
if (model2.state ==
ViewState.ErrorLocal) {
Helpers.showErrorToast(
model2.error);
} else {
DrAppToastMsg.showSuccesToast(
TranslationBase.of(context)
.replySuccessfully);
}
GifLoaderDialogUtils.hideDialog(
context);
}
} catch (err) {
print(err);
}
}
},
),
),
SizedBox(
height: 5,
),
],
),
)
),
)));
}
void _validateInputs(model2) async {
try {
if (addSickLeave.noOfDays == null) {
DrAppToastMsg.showErrorToast(
TranslationBase.of(context).pleaseEnterNoOfDays);
} else if (addSickLeave.remarks == null) {
DrAppToastMsg.showErrorToast(
TranslationBase.of(context).pleaseEnterRemarks);
} else if (addSickLeave.startDate == null) {
DrAppToastMsg.showErrorToast(
TranslationBase.of(context).pleaseEnterDate);
} else {
addSickLeave.patientMRN = widget.patient.patientMRN.toString();
addSickLeave.appointmentNo = widget.patient.appointmentNo.toString();
await model2.addSickLeave(addSickLeave);
if (model2.state == ViewState.ErrorLocal) {
Helpers.showErrorToast(model2.error);
} else {
DrAppToastMsg.showSuccesToast(
TranslationBase.of(context).replySuccessfully);
}
GifLoaderDialogUtils.hideDialog(context);
Navigator.of(context).popUntil((route) {
return route.settings.name == PATIENTS_PROFILE;
});
Navigator.of(context)
.pushNamed(ADD_SICKLEAVE, arguments: {'patient': widget.patient});
}
} catch (err) {
print(err);
}
}
getProfile() async {
Map p = await sharedPref.getObj(DOCTOR_PROFILE);
setState(() {
this.profile = p;
});
}
getClinicName(model) {
var clinicInfo = model.clinicsList
.where((i) => i['ClinicID'] == this.profile['ClinicID'])
.toList();
return clinicInfo.length > 0 ? clinicInfo[0]['ClinicDescription'] : "";
}
}