|
|
|
|
@ -6,6 +6,7 @@ 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/LocalNotification.dart';
|
|
|
|
|
import 'package:diplomaticquarterapp/uitl/app_toast.dart';
|
|
|
|
|
import 'package:diplomaticquarterapp/uitl/date_uitl.dart';
|
|
|
|
|
@ -19,6 +20,7 @@ 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 {
|
|
|
|
|
@ -197,24 +199,26 @@ class PrescriptionDetailsPage extends StatelessWidget {
|
|
|
|
|
child: DefaultButton(
|
|
|
|
|
TranslationBase.of(context).addReminder,
|
|
|
|
|
() {
|
|
|
|
|
setTheNotificatoin(context);
|
|
|
|
|
// 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;
|
|
|
|
|
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);
|
|
|
|
|
},
|
|
|
|
|
onMultiDateSuccess: (int selectedIndex) {
|
|
|
|
|
setCalender(context, prescriptionReport.itemID.toString(), selectedIndex);
|
|
|
|
|
},
|
|
|
|
|
);
|
|
|
|
|
return;
|
|
|
|
|
},
|
|
|
|
|
iconData: Icons.notifications_active,
|
|
|
|
|
color: Color(0xffD02127),
|
|
|
|
|
@ -229,24 +233,74 @@ class PrescriptionDetailsPage extends StatelessWidget {
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
setTheNotificatoin(BuildContext context) {
|
|
|
|
|
setCalender(BuildContext context, String eventId, int reminderIndex) async {
|
|
|
|
|
CalendarUtils calendarUtils = await CalendarUtils.getInstance();
|
|
|
|
|
|
|
|
|
|
DateTime startDate = DateUtil.convertStringToDate(prescriptionReport.startDate);
|
|
|
|
|
DateTime actualDate = DateTime(startDate.year, startDate.month, startDate.day, 8, 0);
|
|
|
|
|
if(prescriptionReport?.frequencyNumber==null)
|
|
|
|
|
prescriptionReport.frequencyNumber=2;
|
|
|
|
|
DateTime actualDate = DateTime(startDate.year, startDate.month, startDate.day, 8, 0); //Time will start at 8:00 AM from starting date
|
|
|
|
|
if (prescriptionReport?.frequencyNumber == null) prescriptionReport.frequencyNumber = 2; //Some time frequency number is null so by default will be 2
|
|
|
|
|
|
|
|
|
|
for (int i = 0; i < prescriptionReport.days; i++) {
|
|
|
|
|
for (int j = 0; j < prescriptionReport.frequencyNumber??2; j++) {
|
|
|
|
|
//event for number of days.
|
|
|
|
|
for (int j = 0; j < prescriptionReport.frequencyNumber ?? 2; j++) {
|
|
|
|
|
// event for number of times per day.
|
|
|
|
|
|
|
|
|
|
if (j != 0) {
|
|
|
|
|
actualDate.add(new Duration(hours: 8));
|
|
|
|
|
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);
|
|
|
|
|
}
|
|
|
|
|
LocalNotification.getInstance().scheduleNotification(
|
|
|
|
|
scheduledNotificationDateTime: actualDate,
|
|
|
|
|
title: "${prescriptionReport.itemDescriptionN} Prescription Reminder",
|
|
|
|
|
description: "${prescriptionReport.itemDescriptionN} ${prescriptionReport.frequencyN} ${prescriptionReport.routeN} ");
|
|
|
|
|
calendarUtils
|
|
|
|
|
.createOrUpdateEvent(
|
|
|
|
|
title: "${prescriptionReport.itemDescriptionN} Prescription Reminder",
|
|
|
|
|
description: "${prescriptionReport.itemDescriptionN} ${prescriptionReport.frequencyN} ${prescriptionReport.routeN} ",
|
|
|
|
|
scheduleDateTime: actualDate,
|
|
|
|
|
eventId: eventId + (i.toString() + j.toString()), //event id with varitions
|
|
|
|
|
)
|
|
|
|
|
.then(
|
|
|
|
|
(value) {},
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
actualDate.add(new Duration(days: i + 1));
|
|
|
|
|
}
|
|
|
|
|
AppToast.showSuccessToast(message: TranslationBase.of(context).reminderSuccess);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//schedual local notifications
|
|
|
|
|
// setTheNotificatoin(BuildContext context) {
|
|
|
|
|
// DateTime startDate = DateUtil.convertStringToDate(prescriptionReport.startDate);
|
|
|
|
|
// DateTime actualDate = DateTime(startDate.year, startDate.month, startDate.day, 8, 0);
|
|
|
|
|
// if (prescriptionReport?.frequencyNumber == null) prescriptionReport.frequencyNumber = 2;
|
|
|
|
|
//
|
|
|
|
|
// for (int i = 0; i < prescriptionReport.days; i++) {
|
|
|
|
|
// for (int j = 0; j < prescriptionReport.frequencyNumber ?? 2; j++) {
|
|
|
|
|
// if (j != 0) {
|
|
|
|
|
// actualDate.add(new Duration(hours: 8));
|
|
|
|
|
// }
|
|
|
|
|
// LocalNotification.getInstance().scheduleNotification(
|
|
|
|
|
// scheduledNotificationDateTime: actualDate,
|
|
|
|
|
// title: "${prescriptionReport.itemDescriptionN} Prescription Reminder",
|
|
|
|
|
// description: "${prescriptionReport.itemDescriptionN} ${prescriptionReport.frequencyN} ${prescriptionReport.routeN} ");
|
|
|
|
|
// }
|
|
|
|
|
// actualDate.add(new Duration(days: i + 1));
|
|
|
|
|
// }
|
|
|
|
|
// AppToast.showSuccessToast(message: TranslationBase.of(context).reminderSuccess);
|
|
|
|
|
// }
|
|
|
|
|
}
|
|
|
|
|
|