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.
PatientApp-KKUMC/lib/pages/MyAppointments/AppointmentDetails.dart

658 lines
28 KiB
Dart

3 years ago
import 'dart:collection';
import 'package:device_calendar/device_calendar.dart';
import 'package:diplomaticquarterapp/config/shared_pref_kay.dart';
5 years ago
import 'package:diplomaticquarterapp/core/viewModels/project_view_model.dart';
import 'package:diplomaticquarterapp/models/Appointments/AppoimentAllHistoryResultList.dart';
import 'package:diplomaticquarterapp/models/Appointments/DoctorListResponse.dart';
import 'package:diplomaticquarterapp/models/Appointments/DoctorRateDetails.dart';
import 'package:diplomaticquarterapp/models/Appointments/toDoCountProviderModel.dart';
import 'package:diplomaticquarterapp/models/header_model.dart';
import 'package:diplomaticquarterapp/pages/BookAppointment/BookConfirm.dart';
import 'package:diplomaticquarterapp/pages/BookAppointment/components/DocAvailableAppointments.dart';
4 years ago
import 'package:diplomaticquarterapp/pages/MyAppointments/SchedulePage.dart';
2 years ago
import 'package:diplomaticquarterapp/pages/MyAppointments/models/AppointmentType.dart';
import 'package:diplomaticquarterapp/services/appointment_services/GetDoctorsList.dart';
import 'package:diplomaticquarterapp/services/clinic_services/get_clinic_service.dart';
4 years ago
import 'package:diplomaticquarterapp/theme/colors.dart';
3 years ago
import 'package:diplomaticquarterapp/uitl/CalendarUtils.dart';
import 'package:diplomaticquarterapp/uitl/app_shared_preferences.dart';
import 'package:diplomaticquarterapp/uitl/app_toast.dart';
5 years ago
import 'package:diplomaticquarterapp/uitl/date_uitl.dart';
import 'package:diplomaticquarterapp/uitl/gif_loader_dialog_utils.dart';
import 'package:diplomaticquarterapp/uitl/translations_delegate_base.dart';
import 'package:diplomaticquarterapp/widgets/buttons/custom_text_button.dart';
import 'package:diplomaticquarterapp/widgets/buttons/defaultButton.dart';
import 'package:diplomaticquarterapp/widgets/dialogs/confirm_dialog.dart';
import 'package:diplomaticquarterapp/widgets/new_design/doctor_header.dart';
import 'package:diplomaticquarterapp/widgets/others/app_scaffold_widget.dart';
import 'package:diplomaticquarterapp/widgets/transitions/fade_page.dart';
import 'package:flutter/material.dart';
5 years ago
import 'package:provider/provider.dart';
import 'package:rating_bar/rating_bar.dart';
import 'widgets/AppointmentActions.dart';
class AppointmentDetails extends StatefulWidget {
AppoitmentAllHistoryResultList appo;
static bool isLoading = false;
4 years ago
dynamic doctorSchedule;
static bool showFooterButton = false;
final int parentIndex;
4 years ago
AppointmentDetails({@required this.appo, this.parentIndex, this.doctorSchedule});
@override
_AppointmentDetailsState createState() => _AppointmentDetailsState();
}
class _AppointmentDetailsState extends State<AppointmentDetails> with SingleTickerProviderStateMixin {
static TabController _tabController;
4 years ago
AppSharedPreferences sharedPref = AppSharedPreferences();
List<DoctorRateDetails> doctorDetailsList = List();
ToDoCountProviderModel toDoProvider;
ProjectViewModel projectViewModel;
4 years ago
DoctorList doctorList = new DoctorList();
@override
void initState() {
5 years ago
AppointmentDetails.showFooterButton = false;
4 years ago
if (widget.doctorSchedule != null) {
4 years ago
_tabController = new TabController(length: 2, vsync: this, initialIndex: 1);
4 years ago
widget.appo.appointmentDate = widget.doctorSchedule['Date'];
} else {
_tabController = new TabController(length: 2, vsync: this);
}
4 years ago
doctorList.doctorID = widget.appo.doctorID;
doctorList.clinicID = widget.appo.clinicID;
doctorList.projectID = widget.appo.projectID;
4 years ago
setTab();
super.initState();
}
@override
void dispose() {
super.dispose();
_tabController.dispose();
5 years ago
AppointmentDetails.showFooterButton = false;
}
@override
Widget build(BuildContext context) {
projectViewModel = Provider.of(context);
toDoProvider = Provider.of<ToDoCountProviderModel>(context);
return AppScaffold(
appBarTitle: widget.appo.doctorNameObj,
isShowAppBar: true,
showNewAppBar: true,
backgroundColor: Colors.white,
showNewAppBarTitle: true,
bottomSheet: _bottomButtons(),
body: SingleChildScrollView(
physics: BouncingScrollPhysics(),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: <Widget>[
4 years ago
DoctorHeader(
headerModel: HeaderModel(
3 years ago
widget.appo.doctorTitle + " " + widget.appo.doctorNameObj,
widget.appo.doctorID,
widget.appo.doctorImageURL,
widget.appo.doctorSpeciality,
"",
widget.appo.projectName,
DateUtil.convertStringToDate(widget.appo.appointmentDate),
widget.appo.isLiveCareAppointment ? DateUtil.convertStringToDate(widget.appo.appointmentDate).toString().split(" ")[1].substring(0, 5) : widget.appo.startTime.substring(0, 5),
3 years ago
null,
widget.appo.doctorRate,
widget.appo.actualDoctorRate,
widget.appo.noOfPatientsRate,
"",
decimalDoctorRate: widget.appo.decimalDoctorRate.toString()
//model.user.emailAddress,
),
isNeedToShowButton: (widget.appo.clinicID == 17 ||
widget.appo.clinicID == 47 ||
widget.appo.clinicID == 23 ||
widget.appo.clinicID == 265 ||
widget.appo.clinicID == 134 ||
3 years ago
widget.appo.isExecludeDoctor ||
widget.appo.isLiveCareAppointment)
? false
: true,
4 years ago
buttonTitle: TranslationBase.of(context).schedule,
buttonIcon: 'assets/images/new/Boo_ Appointment.svg',
showConfirmMessageDialog: false,
onRatingAndReviewTap: getDoctorRatingsDetails,
onTap: () {
Navigator.push(
context,
FadePage(
page: SchedulePage(doctorList: doctorList, appo: widget.appo),
),
4 years ago
).then((value) {
setState(() {
4 years ago
if (_tabController.index == 0) {
_tabController.animateTo((_tabController.index + 1) % 2);
this.enableFooterButton();
}
4 years ago
widget.doctorSchedule = value;
});
});
},
),
SizedBox(height: 10),
Material(
color: Color(0xffF8F8F8),
child: TabBar(
onTap: (index) {
setState(() {
if (index == 1) {
3 years ago
if (widget.appo.clinicID == 17 ||
widget.appo.clinicID == 47 ||
widget.appo.clinicID == 23 ||
3 years ago
widget.appo.clinicID == 253 ||
3 years ago
widget.appo.clinicID == 265 ||
widget.appo.clinicID == 134 ||
3 years ago
widget.appo.isExecludeDoctor ||
widget.appo.isLiveCareAppointment) {
4 years ago
_tabController.index = _tabController.previousIndex;
AppointmentDetails.showFooterButton = false;
} else {
AppointmentDetails.showFooterButton = true;
}
}
});
},
tabs: [
Tab(child: Text(TranslationBase.of(context).appoActions, style: TextStyle(color: Colors.black))),
3 years ago
widget.appo.clinicID == 17 ||
widget.appo.clinicID == 23 ||
widget.appo.clinicID == 47 ||
widget.appo.clinicID == 265 ||
3 years ago
widget.appo.clinicID == 253 ||
3 years ago
widget.appo.isExecludeDoctor ||
widget.appo.isLiveCareAppointment
4 years ago
? Tab(
child: Text(TranslationBase.of(context).availableAppo, style: TextStyle(color: Colors.grey)),
)
: Tab(
child: Text(TranslationBase.of(context).availableAppo, style: TextStyle(color: Colors.black)),
)
],
4 years ago
controller: _tabController,
),
),
Container(
height: MediaQuery.of(context).size.height * 0.87,
color: Color(0xffF8F8F8),
child: TabBarView(
physics: NeverScrollableScrollPhysics(),
children: [
AppointmentActions(appo: widget.appo, tabController: _tabController, enableFooterButton: enableFooterButton, projectViewModel: projectViewModel),
4 years ago
DocAvailableAppointments(doctor: getDoctorObject(), doctorSchedule: widget.doctorSchedule, isLiveCareAppointment: widget.appo.isLiveCareAppointment)
],
controller: _tabController,
),
),
],
),
),
);
}
Widget _bottomButtons() {
if (widget.parentIndex == null) {
return null;
} else {
List<Widget> list = [];
if (widget.parentIndex == 0 && _tabController.index == 0) {
list.add(
Expanded(
child: DefaultButton(
4 years ago
TranslationBase.of(context).cancelAppointment,
() {
ConfirmDialog dialog = new ConfirmDialog(
context: context,
confirmMessage: TranslationBase.of(context).cancelAppoMsg,
okText: TranslationBase.of(context).confirm,
cancelText: TranslationBase.of(context).cancel_nocaps,
okFunction: cancelAppointment,
cancelFunction: () => {});
dialog.showAlertDialog(context);
},
4 years ago
color: CustomColors.accentColor,
textColor: CustomColors.white,
),
),
);
list.add(
SizedBox(width: 8),
);
list.add(
Expanded(
child: DefaultButton(
TranslationBase.of(context).confirm,
confirmAppointment,
color: Color(0xff359846),
),
),
);
} else if (widget.parentIndex == 1 && _tabController.index == 0) {
list.add(
Expanded(
child: DefaultButton(
4 years ago
TranslationBase.of(context).cancelAppointment,
4 years ago
() {
ConfirmDialog dialog = new ConfirmDialog(
context: context,
confirmMessage: TranslationBase.of(context).cancelAppoMsg,
okText: TranslationBase.of(context).confirm,
cancelText: TranslationBase.of(context).cancel_nocaps,
okFunction: cancelAppointment,
cancelFunction: () => {});
dialog.showAlertDialog(context);
},
4 years ago
color: CustomColors.accentColor,
4 years ago
// textColor: Color(0xff000000),
),
),
);
2 years ago
list.add(
SizedBox(width: 8),
);
if (AppointmentType.isBooked(widget.appo))
list.add(
Expanded(
child: DefaultButton(
TranslationBase.of(context).confirm,
confirmAppointment,
color: Color(0xff359846),
),
),
);
} else if (_tabController.index == 1) {
list.add(
Expanded(
child: DefaultButton(
TranslationBase.of(context).reviewAppointment,
4 years ago
goToBookConfirm,
// DocAvailableAppointments.areSlotsAvailable ? goToBookConfirm : null,
color: Color(0xFFD02127),
disabledColor: Color(0xff28323A).withOpacity(0.3),
),
),
);
}
if (list.isEmpty) {
return null;
} else
return Container(
color: Colors.white,
padding: EdgeInsets.only(top: 16, bottom: 16, right: 21, left: 21),
child: Row(
mainAxisSize: MainAxisSize.min,
children: list,
),
);
}
}
void enableFooterButton() {
setState(() {
AppointmentDetails.showFooterButton = true;
});
}
void goToBookConfirm() {
if (DocAvailableAppointments.areSlotsAvailable)
navigateToBookConfirm(context);
else
AppToast.showErrorToast(message: TranslationBase.of(context).selectSlot);
}
Future navigateToBookConfirm(context) async {
Navigator.push(
context,
FadePage(
page: BookConfirm(
doctor: getDoctorObject(),
5 years ago
isLiveCareAppointment: widget.appo.isLiveCareAppointment,
selectedDate: DocAvailableAppointments.selectedDate,
selectedTime: DocAvailableAppointments.selectedTime)));
}
void getDoctorRatingsDetails() {
GifLoaderDialogUtils.showMyDialog(context);
DoctorsListService service = new DoctorsListService();
2 years ago
service.getDoctorsRatingDetails(widget.appo.doctorID, projectViewModel.isArabic ? 1 : 2, context).then((res) {
GifLoaderDialogUtils.hideDialog(context);
if (res['MessageStatus'] == 1) {
doctorDetailsList.clear();
res['DoctorRatingDetailsList'].forEach((v) {
doctorDetailsList.add(new DoctorRateDetails.fromJson(v));
});
showRatingDialog(doctorDetailsList);
} else {
AppToast.showErrorToast(message: res['ErrorEndUserMessage']);
}
}).catchError((err) {
GifLoaderDialogUtils.hideDialog(context);
AppToast.showErrorToast(message: err);
print(err);
});
}
void showRatingDialog(List<DoctorRateDetails> doctorDetailsList) {
showGeneralDialog(
barrierColor: Colors.black.withOpacity(0.5),
transitionBuilder: (context, a1, a2, widget) {
final curvedValue = Curves.easeInOutBack.transform(a1.value) - 1.0;
return Transform(
transform: Matrix4.translationValues(0.0, curvedValue * 200, 0.0),
child: Opacity(
opacity: a1.value,
child: Dialog(
child: Column(
mainAxisSize: MainAxisSize.min,
children: [
Container(
// height: 400.0,
width: MediaQuery.of(context).size.width * 0.8,
color: Colors.white,
child: Column(
children: [
Container(
width: MediaQuery.of(context).size.width,
margin: EdgeInsets.only(bottom: 5.0),
padding: EdgeInsets.all(10.0),
child: Text(TranslationBase.of(context).doctorRating, style: TextStyle(fontSize: 22.0, color: Colors.black))),
Container(margin: EdgeInsets.only(top: 0.0), child: Text(this.widget.appo.actualDoctorRate.ceilToDouble().toString(), style: TextStyle(fontSize: 32.0, color: Colors.black))),
Container(
margin: EdgeInsets.only(top: 5.0),
alignment: Alignment.center,
child: RatingBar.readOnly(
initialRating: this.widget.appo.actualDoctorRate.toDouble(),
size: 35.0,
filledColor: Colors.yellow[700],
emptyColor: Colors.grey[500],
isHalfAllowed: true,
halfFilledIcon: Icons.star_half,
filledIcon: Icons.star,
emptyIcon: Icons.star,
),
),
Container(
margin: EdgeInsets.only(top: 10.0),
child: Text(this.widget.appo.noOfPatientsRate.toString() + " " + TranslationBase.of(context).reviews, style: TextStyle(fontSize: 14.0, color: Colors.black))),
Container(
margin: EdgeInsets.only(top: 10.0),
child: Row(
children: [
Container(
width: 100.0,
margin: EdgeInsets.only(top: 10.0, left: 15.0, right: 15.0),
child: Text(TranslationBase.of(context).excellent, style: TextStyle(fontSize: 13.0, color: Colors.black))),
Expanded(
child: Container(
margin: EdgeInsets.only(top: 10.0),
child: SizedBox(
width: getRatingWidth(doctorDetailsList[0].patientNumber),
height: 6.0,
child: Container(
color: Colors.green[700],
),
),
),
),
],
),
),
Container(
child: Row(
children: [
Container(
width: 100.0,
margin: EdgeInsets.only(top: 10.0, left: 15.0, right: 15.0),
child: Text(TranslationBase.of(context).v_good, style: TextStyle(fontSize: 13.0, color: Colors.black))),
Container(
margin: EdgeInsets.only(top: 10.0),
child: SizedBox(
width: getRatingWidth(doctorDetailsList[1].patientNumber),
height: 6.0,
child: Container(
color: Color(0xffB7B723),
),
),
),
],
),
),
Container(
child: Row(
children: [
Container(
width: 100.0,
margin: EdgeInsets.only(top: 10.0, left: 15.0, right: 15.0),
child: Text(TranslationBase.of(context).good, style: TextStyle(fontSize: 13.0, color: Colors.black))),
Container(
margin: EdgeInsets.only(top: 10.0),
child: SizedBox(
width: getRatingWidth(doctorDetailsList[2].patientNumber),
height: 6.0,
child: Container(
color: Color(0xffEBA727),
),
),
),
],
),
),
Container(
child: Row(
children: [
Container(
width: 100.0,
margin: EdgeInsets.only(top: 10.0, left: 15.0, right: 15.0),
child: Text(TranslationBase.of(context).average, style: TextStyle(fontSize: 13.0, color: Colors.black))),
Container(
margin: EdgeInsets.only(top: 10.0),
child: SizedBox(
width: getRatingWidth(doctorDetailsList[3].patientNumber),
height: 6.0,
child: Container(
color: Color(0xffEB7227),
),
),
),
],
),
),
Container(
child: Row(
children: [
Container(
width: 100.0,
margin: EdgeInsets.only(top: 10.0, left: 15.0, right: 15.0),
child: Text(TranslationBase.of(context).below_average, style: TextStyle(fontSize: 13.0, color: Colors.black))),
Container(
margin: EdgeInsets.only(top: 10.0),
child: SizedBox(
width: getRatingWidth(doctorDetailsList[4].patientNumber),
height: 6.0,
child: Container(
color: Color(0xffE20C0C),
),
),
),
],
),
),
Container(margin: EdgeInsets.only(top: 40.0), child: Divider()),
Container(
margin: EdgeInsets.only(top: 0.0),
child: Align(
alignment: FractionalOffset.bottomCenter,
child: ButtonTheme(
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(10.0),
),
minWidth: MediaQuery.of(context).size.width,
height: 40.0,
child: CustomTextButton(
2 years ago
elevation: 0.0,
backgroundColor: Colors.white,
disabledForegroundColor: new Color(0xFFbcc2c4).withOpacity(0.38),
disabledBackgroundColor: new Color(0xFFbcc2c4).withOpacity(0.12),
onPressed: () {
Navigator.of(context).pop();
},
child: Text(TranslationBase.of(context).cancel, style: TextStyle(fontSize: 18.0, color: Colors.red)),
),
),
),
),
],
),
),
],
),
),
),
);
},
transitionDuration: Duration(milliseconds: 500),
barrierDismissible: true,
barrierLabel: '',
context: context,
pageBuilder: (context, animation1, animation2) {});
}
double getRatingWidth(int patientNumber) {
var width = (patientNumber / this.widget.appo.noOfPatientsRate) * 100;
return width;
}
5 years ago
String getDate(String date) {
DateTime dateObj = DateUtil.convertStringToDate(date);
return DateUtil.getWeekDay(dateObj.weekday) + ", " + dateObj.day.toString() + " " + DateUtil.getMonth(dateObj.month) + " " + dateObj.year.toString();
5 years ago
}
String getDoctorSpeciality(List<String> docSpecial) {
String docSpeciality = "";
docSpecial.forEach((v) {
docSpeciality = docSpeciality + v + " ";
});
return docSpeciality;
}
DoctorList getDoctorObject() {
DoctorList docObj = new DoctorList();
docObj.doctorID = widget.appo.doctorID;
docObj.clinicID = widget.appo.clinicID;
docObj.projectID = widget.appo.projectID;
docObj.doctorTitle = widget.appo.doctorTitle;
docObj.name = widget.appo.doctorNameObj;
docObj.clinicName = widget.appo.clinicName;
docObj.speciality = widget.appo.doctorSpeciality;
docObj.actualDoctorRate = widget.appo.actualDoctorRate;
docObj.projectName = widget.appo.projectName;
docObj.originalClinicID = widget.appo.originalClinicID;
docObj.doctorImageURL = widget.appo.doctorImageURL;
return docObj;
}
4 years ago
void openSchedule() {
4 years ago
Navigator.push(
context,
FadePage(
page: SchedulePage(
doctorList: getDoctorObject(),
appo: widget.appo,
)));
4 years ago
}
4 years ago
setTab() async {
var scheduleDoctor = await sharedPref.getObject(DOCTOR_SCHEDULE_DATE_SEL);
4 years ago
if (scheduleDoctor != null) widget.appo.appointmentDate = scheduleDoctor['Date'];
4 years ago
}
confirmAppointment() {
GifLoaderDialogUtils.showMyDialog(context);
DoctorsListService service = new DoctorsListService();
service.confirmAppointment(widget.appo.appointmentNo, widget.appo.clinicID, widget.appo.projectID, widget.appo.isLiveCareAppointment, context).then((res) {
GifLoaderDialogUtils.hideDialog(context);
if (res['MessageStatus'] == 1) {
AppToast.showSuccessToast(message: res['ErrorEndUserMessage']);
Navigator.of(context).pop();
projectViewModel.analytics.appointment.appointment_details_confirm(appointment: widget.appo);
} else {
AppToast.showErrorToast(message: res['ErrorEndUserMessage']);
}
}).catchError((err) {
GifLoaderDialogUtils.hideDialog(context);
print(err);
});
}
3 years ago
checkIfHasReminder() async {
CalendarUtils calendarUtils = await CalendarUtils.getInstance();
DateTime startEventsDate = DateUtil.convertStringToDate(widget.appo.appointmentDate);
DateTime endEventsDate = DateUtil.convertStringToDate(widget.appo.appointmentDate);
RetrieveEventsParams params = new RetrieveEventsParams(startDate: startEventsDate, endDate: endEventsDate);
try {
await calendarUtils.retrieveEvents(calendarUtils.calendars[0].id, params).then((value) {
Result<UnmodifiableListView<Event>> events = value;
events.data.forEach((element) {
if (element.title.contains(widget.appo.doctorNameObj)) calendarUtils.deleteEvent(calendarUtils.calendars[0], element);
});
3 years ago
});
} catch (ex) {
print(ex);
}
3 years ago
}
cancelAppointment() {
ConfirmDialog.closeAlertDialog(context);
GifLoaderDialogUtils.showMyDialog(context);
DoctorsListService service = new DoctorsListService();
service.cancelAppointment(widget.appo, context).then((res) {
GifLoaderDialogUtils.hideDialog(context);
if (res['MessageStatus'] == 1) {
3 years ago
checkIfHasReminder();
getToDoCount();
AppToast.showSuccessToast(message: res['ErrorEndUserMessage']);
Navigator.of(context).pop();
3 years ago
projectViewModel.analytics.appointment.appointment_details_cancel(appointment: widget.appo);
} else {
AppToast.showErrorToast(message: res['ErrorEndUserMessage']);
}
3 years ago
projectViewModel.analytics.appointment.appointment_details_cancel(appointment: widget.appo, appointment_type: widget.appo.isLiveCareAppointment ? "livecare" : "regular");
}).catchError((err) {
GifLoaderDialogUtils.hideDialog(context);
print(err);
});
}
getToDoCount() {
2 years ago
toDoProvider.setState(0, 0, true, toDoProvider.notificationsCount);
ClinicListService service = new ClinicListService();
service.getActiveAppointmentNo(context).then((res) {
if (res['MessageStatus'] == 1) {
2 years ago
// toDoProvider.setState(res['AppointmentActiveNumber'], true, toDoProvider.notificationsCount);
toDoProvider.setState(res['AppointmentActiveNumber'], res['AncillaryOrderListCount'], true, toDoProvider.notificationsCount);
} else {}
}).catchError((err) {
print(err);
});
}
}