|
|
|
|
@ -1,13 +1,17 @@
|
|
|
|
|
import 'dart:collection';
|
|
|
|
|
|
|
|
|
|
import 'package:device_calendar/device_calendar.dart';
|
|
|
|
|
import 'package:diplomaticquarterapp/core/model/prescriptions/Prescriptions.dart';
|
|
|
|
|
import 'package:diplomaticquarterapp/core/model/prescriptions/prescription_report.dart';
|
|
|
|
|
import 'package:diplomaticquarterapp/core/viewModels/project_view_model.dart';
|
|
|
|
|
import 'package:diplomaticquarterapp/extensions/string_extensions.dart';
|
|
|
|
|
import 'package:diplomaticquarterapp/models/header_model.dart';
|
|
|
|
|
import 'package:diplomaticquarterapp/pages/BookAppointment/widgets/reminder_dialog.dart';
|
|
|
|
|
import 'package:diplomaticquarterapp/pages/MyAppointments/widgets/reminder_dialog_prescription.dart';
|
|
|
|
|
import 'package:diplomaticquarterapp/pages/medical/prescriptions/pharmacy_for_prescriptions_page.dart';
|
|
|
|
|
import 'package:diplomaticquarterapp/uitl/CalendarUtils.dart';
|
|
|
|
|
import 'package:diplomaticquarterapp/uitl/app_toast.dart';
|
|
|
|
|
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/uitl/utils.dart';
|
|
|
|
|
import 'package:diplomaticquarterapp/uitl/utils_new.dart';
|
|
|
|
|
@ -18,21 +22,34 @@ import 'package:diplomaticquarterapp/widgets/show_zoom_image_dialog.dart';
|
|
|
|
|
import 'package:diplomaticquarterapp/widgets/transitions/fade_page.dart';
|
|
|
|
|
import 'package:flutter/cupertino.dart';
|
|
|
|
|
import 'package:flutter/material.dart';
|
|
|
|
|
import 'package:jiffy/jiffy.dart';
|
|
|
|
|
import 'package:provider/provider.dart';
|
|
|
|
|
|
|
|
|
|
class PrescriptionDetailsPage extends StatelessWidget {
|
|
|
|
|
class PrescriptionDetailsPage extends StatefulWidget {
|
|
|
|
|
final PrescriptionReport prescriptionReport;
|
|
|
|
|
final Prescriptions prescriptions;
|
|
|
|
|
|
|
|
|
|
PrescriptionDetailsPage({Key key, this.prescriptionReport, this.prescriptions});
|
|
|
|
|
|
|
|
|
|
@override
|
|
|
|
|
_PrescriptionDetailsPageState createState() => _PrescriptionDetailsPageState();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
class _PrescriptionDetailsPageState extends State<PrescriptionDetailsPage> {
|
|
|
|
|
bool hasReminder = false;
|
|
|
|
|
|
|
|
|
|
@override
|
|
|
|
|
void initState() {
|
|
|
|
|
checkIfHasReminder();
|
|
|
|
|
super.initState();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@override
|
|
|
|
|
Widget build(BuildContext context) {
|
|
|
|
|
ProjectViewModel projectViewModel = Provider.of(context);
|
|
|
|
|
return AppScaffold(
|
|
|
|
|
isShowAppBar: true,
|
|
|
|
|
showNewAppBar: true,
|
|
|
|
|
backgroundColor: Color(0xffF8F8F8),
|
|
|
|
|
showNewAppBarTitle: true,
|
|
|
|
|
appBarTitle: TranslationBase.of(context).prescriptions,
|
|
|
|
|
body: Column(
|
|
|
|
|
@ -40,18 +57,18 @@ class PrescriptionDetailsPage extends StatelessWidget {
|
|
|
|
|
children: <Widget>[
|
|
|
|
|
DoctorHeader(
|
|
|
|
|
headerModel: HeaderModel(
|
|
|
|
|
prescriptions.doctorName,
|
|
|
|
|
prescriptions.doctorID,
|
|
|
|
|
prescriptions.doctorImageURL,
|
|
|
|
|
prescriptions.speciality,
|
|
|
|
|
widget.prescriptions.doctorName,
|
|
|
|
|
widget.prescriptions.doctorID,
|
|
|
|
|
widget.prescriptions.doctorImageURL,
|
|
|
|
|
widget.prescriptions.speciality,
|
|
|
|
|
"",
|
|
|
|
|
prescriptions.name,
|
|
|
|
|
DateUtil.convertStringToDate(prescriptions.appointmentDate),
|
|
|
|
|
DateUtil.formatDateToTime(DateUtil.convertStringToDate(prescriptions.appointmentDate)),
|
|
|
|
|
prescriptions.nationalityFlagURL,
|
|
|
|
|
prescriptions.doctorRate,
|
|
|
|
|
prescriptions.actualDoctorRate,
|
|
|
|
|
prescriptions.noOfPatientsRate,
|
|
|
|
|
widget.prescriptions.name,
|
|
|
|
|
DateUtil.convertStringToDate(widget.prescriptions.appointmentDate),
|
|
|
|
|
DateUtil.formatDateToTime(DateUtil.convertStringToDate(widget.prescriptions.appointmentDate)),
|
|
|
|
|
widget.prescriptions.nationalityFlagURL,
|
|
|
|
|
widget.prescriptions.doctorRate,
|
|
|
|
|
widget.prescriptions.actualDoctorRate,
|
|
|
|
|
widget.prescriptions.noOfPatientsRate,
|
|
|
|
|
"",
|
|
|
|
|
),
|
|
|
|
|
isNeedToShowButton: false,
|
|
|
|
|
@ -102,7 +119,7 @@ class PrescriptionDetailsPage extends StatelessWidget {
|
|
|
|
|
children: [
|
|
|
|
|
Container(
|
|
|
|
|
child: Image.network(
|
|
|
|
|
prescriptionReport.imageSRCUrl,
|
|
|
|
|
widget.prescriptionReport.imageSRCUrl,
|
|
|
|
|
fit: BoxFit.cover,
|
|
|
|
|
width: 48,
|
|
|
|
|
height: 49,
|
|
|
|
|
@ -123,13 +140,15 @@ class PrescriptionDetailsPage extends StatelessWidget {
|
|
|
|
|
],
|
|
|
|
|
),
|
|
|
|
|
onTap: () {
|
|
|
|
|
showZoomImageDialog(context, prescriptionReport.imageSRCUrl);
|
|
|
|
|
showZoomImageDialog(context, widget.prescriptionReport.imageSRCUrl);
|
|
|
|
|
},
|
|
|
|
|
),
|
|
|
|
|
SizedBox(width: 12),
|
|
|
|
|
Expanded(
|
|
|
|
|
child: Text(
|
|
|
|
|
(prescriptionReport.itemDescription.isNotEmpty ? prescriptionReport.itemDescription : prescriptionReport.itemDescriptionN ?? '').toLowerCase().capitalizeFirstofEach,
|
|
|
|
|
(widget.prescriptionReport.itemDescription.isNotEmpty ? widget.prescriptionReport.itemDescription : widget.prescriptionReport.itemDescriptionN ?? '')
|
|
|
|
|
.toLowerCase()
|
|
|
|
|
.capitalizeFirstofEach,
|
|
|
|
|
style: TextStyle(fontSize: 16, fontWeight: FontWeight.w600, color: Color(0xff2E303A), letterSpacing: -0.64),
|
|
|
|
|
),
|
|
|
|
|
)
|
|
|
|
|
@ -147,10 +166,10 @@ class PrescriptionDetailsPage extends StatelessWidget {
|
|
|
|
|
),
|
|
|
|
|
TableRow(
|
|
|
|
|
children: [
|
|
|
|
|
Utils.tableColumnValue(prescriptionReport?.routeN ?? '', isLast: true, mProjectViewModel: projectViewModel),
|
|
|
|
|
Utils.tableColumnValue(prescriptionReport?.frequencyN ?? '', isLast: true, mProjectViewModel: projectViewModel),
|
|
|
|
|
Utils.tableColumnValue(prescriptionReport?.doseDailyQuantity.toString() ?? '', isLast: true, mProjectViewModel: projectViewModel),
|
|
|
|
|
Utils.tableColumnValue(prescriptionReport?.days.toString() ?? '', isLast: true, mProjectViewModel: projectViewModel),
|
|
|
|
|
Utils.tableColumnValue(widget.prescriptionReport?.routeN ?? '', isLast: true, mProjectViewModel: projectViewModel),
|
|
|
|
|
Utils.tableColumnValue(widget.prescriptionReport?.frequencyN ?? '', isLast: true, mProjectViewModel: projectViewModel),
|
|
|
|
|
Utils.tableColumnValue(widget.prescriptionReport?.doseDailyQuantity.toString() ?? '', isLast: true, mProjectViewModel: projectViewModel),
|
|
|
|
|
Utils.tableColumnValue(widget.prescriptionReport?.days.toString() ?? '', isLast: true, mProjectViewModel: projectViewModel),
|
|
|
|
|
],
|
|
|
|
|
),
|
|
|
|
|
]),
|
|
|
|
|
@ -159,7 +178,7 @@ class PrescriptionDetailsPage extends StatelessWidget {
|
|
|
|
|
style: TextStyle(fontSize: 12, fontWeight: FontWeight.w600, color: Color(0xff2E303A), letterSpacing: -0.48),
|
|
|
|
|
),
|
|
|
|
|
Text(
|
|
|
|
|
prescriptionReport.remarks,
|
|
|
|
|
widget.prescriptionReport.remarks,
|
|
|
|
|
style: TextStyle(fontSize: 12, fontWeight: FontWeight.w600, color: Color(0xff575757), letterSpacing: -0.4, height: 16 / 10),
|
|
|
|
|
),
|
|
|
|
|
],
|
|
|
|
|
@ -182,8 +201,8 @@ class PrescriptionDetailsPage extends StatelessWidget {
|
|
|
|
|
context,
|
|
|
|
|
FadePage(
|
|
|
|
|
page: PharmacyForPrescriptionsPage(
|
|
|
|
|
itemID: prescriptionReport.itemID,
|
|
|
|
|
prescriptionReport: prescriptionReport,
|
|
|
|
|
itemID: widget.prescriptionReport.itemID,
|
|
|
|
|
prescriptionReport: widget.prescriptionReport,
|
|
|
|
|
),
|
|
|
|
|
),
|
|
|
|
|
);
|
|
|
|
|
@ -195,54 +214,35 @@ class PrescriptionDetailsPage extends StatelessWidget {
|
|
|
|
|
SizedBox(width: 10),
|
|
|
|
|
Expanded(
|
|
|
|
|
child: DefaultButton(
|
|
|
|
|
TranslationBase.of(context).addReminder,
|
|
|
|
|
hasReminder ? TranslationBase.of(context).cancelReminder : TranslationBase.of(context).addReminder,
|
|
|
|
|
() {
|
|
|
|
|
DateTime startDate = DateTime.now();
|
|
|
|
|
DateTime endDate = DateTime(startDate.year, startDate.month, startDate.day + prescriptionReport.days);
|
|
|
|
|
|
|
|
|
|
showReminderDialog(
|
|
|
|
|
context,
|
|
|
|
|
endDate,
|
|
|
|
|
"",
|
|
|
|
|
prescriptionReport.itemID.toString(),
|
|
|
|
|
"",
|
|
|
|
|
"",
|
|
|
|
|
title: "${prescriptionReport.itemDescriptionN} Prescription Reminder",
|
|
|
|
|
description: "${prescriptionReport.itemDescriptionN} ${prescriptionReport.frequencyN} ${prescriptionReport.routeN} ",
|
|
|
|
|
onSuccess: () {
|
|
|
|
|
AppToast.showSuccessToast(message: TranslationBase.of(context).reminderSuccess);
|
|
|
|
|
},
|
|
|
|
|
);
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
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: PrescriptionReminderDialog(
|
|
|
|
|
eventId: prescriptionReport.itemID.toString(),
|
|
|
|
|
title: "${prescriptionReport.itemDescriptionN} Prescription Reminder",
|
|
|
|
|
description: "${prescriptionReport.itemDescriptionN} ${prescriptionReport.frequencyN} ${prescriptionReport.routeN} ",
|
|
|
|
|
startDate: startDate,
|
|
|
|
|
endDate: endDate,
|
|
|
|
|
location: prescriptionReport.remarks,
|
|
|
|
|
days: 1,
|
|
|
|
|
),
|
|
|
|
|
),
|
|
|
|
|
);
|
|
|
|
|
if (hasReminder) {
|
|
|
|
|
cancelReminders();
|
|
|
|
|
} else {
|
|
|
|
|
DateTime startDate = DateTime.now();
|
|
|
|
|
DateTime endDate = DateTime(startDate.year, startDate.month, startDate.day + widget.prescriptionReport.days);
|
|
|
|
|
showReminderDialog(
|
|
|
|
|
context,
|
|
|
|
|
endDate,
|
|
|
|
|
"",
|
|
|
|
|
widget.prescriptionReport.itemID.toString(),
|
|
|
|
|
"",
|
|
|
|
|
"",
|
|
|
|
|
title: "${widget.prescriptionReport.itemDescriptionN} Prescription Reminder",
|
|
|
|
|
description: "${widget.prescriptionReport.itemDescriptionN} ${widget.prescriptionReport.frequencyN} ${widget.prescriptionReport.routeN} ",
|
|
|
|
|
onSuccess: () {
|
|
|
|
|
AppToast.showSuccessToast(message: TranslationBase.of(context).reminderSuccess);
|
|
|
|
|
},
|
|
|
|
|
onMultiDateSuccess: (int selectedIndex) {
|
|
|
|
|
setCalender(context, widget.prescriptionReport.itemID.toString(), selectedIndex);
|
|
|
|
|
},
|
|
|
|
|
transitionDuration: Duration(milliseconds: 500),
|
|
|
|
|
barrierDismissible: true,
|
|
|
|
|
barrierLabel: '',
|
|
|
|
|
context: context,
|
|
|
|
|
pageBuilder: (context, animation1, animation2) {});
|
|
|
|
|
);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
iconData: Icons.notifications_active,
|
|
|
|
|
color: Color(0xffD02127),
|
|
|
|
|
fontSize: 13.0,
|
|
|
|
|
//textColor: Color(0xff2B353E),
|
|
|
|
|
),
|
|
|
|
|
),
|
|
|
|
|
@ -253,4 +253,100 @@ class PrescriptionDetailsPage extends StatelessWidget {
|
|
|
|
|
),
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
checkIfHasReminder() async {
|
|
|
|
|
CalendarUtils calendarUtils = await CalendarUtils.getInstance();
|
|
|
|
|
|
|
|
|
|
DateTime startEventsDate = Jiffy(DateTime.now()).subtract(days: 30);
|
|
|
|
|
DateTime endEventsDate = Jiffy(DateTime.now()).add(days: 120);
|
|
|
|
|
|
|
|
|
|
RetrieveEventsParams params = new RetrieveEventsParams(startDate: startEventsDate, endDate: endEventsDate);
|
|
|
|
|
|
|
|
|
|
await calendarUtils.retrieveEvents(calendarUtils.calendars[0].id, params).then((value) {
|
|
|
|
|
Result<UnmodifiableListView<Event>> events = value;
|
|
|
|
|
events.data.forEach((element) {
|
|
|
|
|
if (element.title.contains(widget.prescriptionReport.itemDescriptionN))
|
|
|
|
|
setState(() {
|
|
|
|
|
hasReminder = true;
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
print("Has Reminder: " + hasReminder.toString());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
cancelReminders() async {
|
|
|
|
|
CalendarUtils calendarUtils = await CalendarUtils.getInstance();
|
|
|
|
|
|
|
|
|
|
DateTime startEventsDate = Jiffy(DateTime.now()).subtract(days: 30);
|
|
|
|
|
DateTime endEventsDate = Jiffy(DateTime.now()).add(days: 120);
|
|
|
|
|
|
|
|
|
|
RetrieveEventsParams params = new RetrieveEventsParams(startDate: startEventsDate, endDate: endEventsDate);
|
|
|
|
|
|
|
|
|
|
await calendarUtils.retrieveEvents(calendarUtils.calendars[0].id, params).then((value) {
|
|
|
|
|
Result<UnmodifiableListView<Event>> events = value;
|
|
|
|
|
events.data.forEach((element) {
|
|
|
|
|
if (element.title.contains(widget.prescriptionReport.itemDescriptionN)) calendarUtils.deleteEvent(calendarUtils.calendars[0], element);
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
AppToast.showSuccessToast(message: TranslationBase.of(context).reminderCancelSuccess);
|
|
|
|
|
setState(() {
|
|
|
|
|
hasReminder = false;
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
setCalender(BuildContext context, String eventId, int reminderIndex) async {
|
|
|
|
|
CalendarUtils calendarUtils = await CalendarUtils.getInstance();
|
|
|
|
|
|
|
|
|
|
DateTime startDate = DateUtil.convertStringToDate(widget.prescriptionReport.startDate);
|
|
|
|
|
DateTime actualDate = DateTime(startDate.year, startDate.month, startDate.day, 8, 0); //Time will start at 8:00 AM from starting date
|
|
|
|
|
if (widget.prescriptionReport?.frequencyNumber == null) widget.prescriptionReport.frequencyNumber = 1; //Some time frequency number is null so by default will be 2
|
|
|
|
|
|
|
|
|
|
GifLoaderDialogUtils.showMyDialog(context);
|
|
|
|
|
|
|
|
|
|
for (int i = 0; i < widget.prescriptionReport.days; i++) {
|
|
|
|
|
//event for number of days.
|
|
|
|
|
for (int j = 0; j < widget.prescriptionReport.frequencyNumber ?? 1; j++) {
|
|
|
|
|
// event for number of times per day.
|
|
|
|
|
|
|
|
|
|
if (j != 0) {
|
|
|
|
|
actualDate.add(new Duration(hours: 8)); // 8 hours addition for daily dose.
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//Time subtraction from actual reminder time. like before 30, or 1 hour.
|
|
|
|
|
if (reminderIndex == 0) {
|
|
|
|
|
// Before 30 mints
|
|
|
|
|
actualDate = Jiffy(actualDate).subtract(minutes: 30);
|
|
|
|
|
// dateTime.add(new Duration(minutes: -30));
|
|
|
|
|
} else if (reminderIndex == 1) {
|
|
|
|
|
// Before 1 hour
|
|
|
|
|
// dateTime.add(new Duration(minutes: -60));
|
|
|
|
|
actualDate = Jiffy(actualDate).subtract(hours: 1);
|
|
|
|
|
} else if (reminderIndex == 2) {
|
|
|
|
|
// Before 1 hour and 30 mints
|
|
|
|
|
// dateTime.add(new Duration(minutes: -90));
|
|
|
|
|
actualDate = Jiffy(actualDate).subtract(hours: 1, minutes: 30);
|
|
|
|
|
} else if (reminderIndex == 3) {
|
|
|
|
|
// Before 2 hours
|
|
|
|
|
// dateTime.add(new Duration(minutes: -120));
|
|
|
|
|
actualDate = Jiffy(actualDate).subtract(hours: 2);
|
|
|
|
|
}
|
|
|
|
|
calendarUtils
|
|
|
|
|
.createOrUpdateEvent(
|
|
|
|
|
title: "${widget.prescriptionReport.itemDescriptionN} Prescription Reminder",
|
|
|
|
|
description: "${widget.prescriptionReport.itemDescriptionN} ${widget.prescriptionReport.frequencyN} ${widget.prescriptionReport.routeN} ",
|
|
|
|
|
scheduleDateTime: actualDate,
|
|
|
|
|
eventId: eventId + (i.toString() + j.toString()), //event id with varitions
|
|
|
|
|
)
|
|
|
|
|
.then((value) {});
|
|
|
|
|
actualDate = DateTime(actualDate.year, actualDate.month, actualDate.day, 8, 0);
|
|
|
|
|
}
|
|
|
|
|
actualDate = Jiffy(actualDate).add(days: 1);
|
|
|
|
|
print(actualDate);
|
|
|
|
|
}
|
|
|
|
|
AppToast.showSuccessToast(message: TranslationBase.of(context).reminderSuccess);
|
|
|
|
|
GifLoaderDialogUtils.hideDialog(context);
|
|
|
|
|
setState(() {
|
|
|
|
|
hasReminder = true;
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|