|
|
|
|
@ -222,6 +222,7 @@ class _PrescriptionDetailsPageState extends State<PrescriptionDetailsPage> {
|
|
|
|
|
onSuccess: () {
|
|
|
|
|
AppToast.showSuccessToast(message: TranslationBase.of(context).reminderSuccess);
|
|
|
|
|
},
|
|
|
|
|
isMultiAllowed: true,
|
|
|
|
|
onMultiDateSuccess: (int selectedIndex) {
|
|
|
|
|
setCalender(context, widget.prescriptionReport!.itemID.toString(), selectedIndex);
|
|
|
|
|
},
|
|
|
|
|
@ -245,21 +246,27 @@ class _PrescriptionDetailsPageState extends State<PrescriptionDetailsPage> {
|
|
|
|
|
|
|
|
|
|
checkIfHasReminder() async {
|
|
|
|
|
CalendarUtils calendarUtils = await CalendarUtils.getInstance();
|
|
|
|
|
|
|
|
|
|
print("If Has Reminder");
|
|
|
|
|
DateTime startEventsDate = Jiffy.parseFromDateTime(DateTime.now()).subtract(days: 30).dateTime;
|
|
|
|
|
DateTime endEventsDate = Jiffy.parseFromDateTime(DateTime.now()).add(days: 120).dateTime;
|
|
|
|
|
|
|
|
|
|
RetrieveEventsParams params = new RetrieveEventsParams(startDate: startEventsDate, endDate: endEventsDate);
|
|
|
|
|
|
|
|
|
|
if (calendarUtils.calendars != null) {
|
|
|
|
|
await calendarUtils.retrieveEvents(calendarUtils.calendars[0].id!, params).then((value) {
|
|
|
|
|
print(calendarUtils.calendars);
|
|
|
|
|
Future.forEach(
|
|
|
|
|
calendarUtils.calendars,
|
|
|
|
|
(Calendar calender) => {
|
|
|
|
|
calendarUtils.retrieveEvents(calender.id!, params).then((value) {
|
|
|
|
|
Result<UnmodifiableListView<Event>> events = value;
|
|
|
|
|
events.data!.forEach((element) {
|
|
|
|
|
print(widget.prescriptionReport!.itemDescriptionN!);
|
|
|
|
|
if (element.title!.contains(widget.prescriptionReport!.itemDescriptionN!))
|
|
|
|
|
setState(() {
|
|
|
|
|
hasReminder = true;
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
}),
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
@ -269,15 +276,25 @@ class _PrescriptionDetailsPageState extends State<PrescriptionDetailsPage> {
|
|
|
|
|
|
|
|
|
|
DateTime startEventsDate = Jiffy.parseFromDateTime(DateTime.now()).subtract(days: 30).dateTime;
|
|
|
|
|
DateTime endEventsDate = Jiffy.parseFromDateTime(DateTime.now()).add(days: 120).dateTime;
|
|
|
|
|
RetrieveEventsParams params = RetrieveEventsParams(startDate: startEventsDate, endDate: endEventsDate);
|
|
|
|
|
|
|
|
|
|
RetrieveEventsParams params = new RetrieveEventsParams(startDate: startEventsDate, endDate: endEventsDate);
|
|
|
|
|
|
|
|
|
|
await calendarUtils.retrieveEvents(calendarUtils.calendars[0].id!, params).then((value) {
|
|
|
|
|
Future.forEach(
|
|
|
|
|
calendarUtils.calendars,
|
|
|
|
|
(Calendar calender) => {
|
|
|
|
|
calendarUtils.retrieveEvents(calender.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);
|
|
|
|
|
print(widget.prescriptionReport!.itemDescriptionN!);
|
|
|
|
|
if (element.title!.contains(widget.prescriptionReport!.itemDescriptionN!)) calendarUtils.deleteEvent(calender, element);
|
|
|
|
|
|
|
|
|
|
});
|
|
|
|
|
}),
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
AppToast.showSuccessToast(message: TranslationBase.of(context).reminderCancelSuccess);
|
|
|
|
|
setState(() {
|
|
|
|
|
hasReminder = false;
|
|
|
|
|
@ -285,16 +302,21 @@ class _PrescriptionDetailsPageState extends State<PrescriptionDetailsPage> {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
setCalender(BuildContext context, String eventId, int reminderIndex) async {
|
|
|
|
|
CalendarUtils calendarUtils = await CalendarUtils.getInstance();
|
|
|
|
|
|
|
|
|
|
DateTime actualDate = DateTime(DateTime.now().year, DateTime.now().month, DateTime.now().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
|
|
|
|
|
|
|
|
|
|
int remainingDays = widget.prescriptionReport!.days! -
|
|
|
|
|
(Jiffy.parseFromDateTime(DateTime.now()).diff(Jiffy.parseFromDateTime(DateUtil.convertStringToDate(widget.prescriptionReport!.orderDate!)), unit: Unit.day) as int);
|
|
|
|
|
DateTime actualDate = DateTime(DateTime.now().year, DateTime.now().month, DateTime.now().day, 8, 0);
|
|
|
|
|
print("Frequency ${widget.prescriptionReport?.frequencyNumber}"); //Time will start at 8:00 AM from starting date
|
|
|
|
|
if (widget.prescriptionReport?.frequencyNumber == null) widget.prescriptionReport!.frequencyNumber = 2; //Some time frequency number is null so by default will be 2
|
|
|
|
|
|
|
|
|
|
int remainingDays = widget.prescriptionReport!.days!;
|
|
|
|
|
// -
|
|
|
|
|
// (Jiffy.parseFromDateTime(DateTime.now()).diff(Jiffy.parseFromDateTime(DateUtil.convertStringToDate(widget.prescriptionReport!.orderDate!)), unit: Unit.day) as int);
|
|
|
|
|
if (remainingDays.isNegative) {
|
|
|
|
|
Utils.showErrorToast("Prescription date has been already passed you can not add a reminder for this prescription.");
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
CalendarUtils calendarUtils = await CalendarUtils.getInstance();
|
|
|
|
|
GifLoaderDialogUtils.showMyDialog(context);
|
|
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
for (int i = 0; i < remainingDays; i++) {
|
|
|
|
|
//event for number of days.
|
|
|
|
|
for (int j = 0; j < widget.prescriptionReport!.frequencyNumber!; j++) {
|
|
|
|
|
@ -320,21 +342,27 @@ class _PrescriptionDetailsPageState extends State<PrescriptionDetailsPage> {
|
|
|
|
|
// dateTime.add(new Duration(minutes: -120));
|
|
|
|
|
actualDate = Jiffy.parseFromDateTime(actualDate).subtract(hours: 2).dateTime;
|
|
|
|
|
}
|
|
|
|
|
calendarUtils
|
|
|
|
|
.createOrUpdateEvent(
|
|
|
|
|
|
|
|
|
|
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.parseFromDateTime(actualDate).add(days: 1).dateTime;
|
|
|
|
|
print(actualDate);
|
|
|
|
|
}
|
|
|
|
|
} catch (ex) {
|
|
|
|
|
print("catch:$ex");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
AppToast.showSuccessToast(message: TranslationBase.of(context).reminderSuccess);
|
|
|
|
|
Future.delayed(Duration(seconds: 2), () {
|
|
|
|
|
GifLoaderDialogUtils.hideDialog(context);
|
|
|
|
|
});
|
|
|
|
|
setState(() {
|
|
|
|
|
hasReminder = true;
|
|
|
|
|
});
|
|
|
|
|
|