Medical Reminder 1.0

merge-update-with-lab-changes
devmirza121 4 years ago
parent f3b7a5c318
commit 7f8a0320a7

@ -14,13 +14,15 @@ Future<Map<Permission, PermissionStatus>> requestPermissions() async {
} }
showReminderDialog(BuildContext context, DateTime dateTime, String doctorName, String eventId, String appoDateFormatted, String appoTimeFormatted, showReminderDialog(BuildContext context, DateTime dateTime, String doctorName, String eventId, String appoDateFormatted, String appoTimeFormatted,
{Function onSuccess, String title, String description}) async { {Function onSuccess, String title, String description, Function(int) onMultiDateSuccess}) async {
if (await Permission.calendar.request().isGranted) { if (await Permission.calendar.request().isGranted) {
_showReminderDialog(context, dateTime, doctorName, eventId, appoDateFormatted, appoTimeFormatted, onSuccess: onSuccess, title: title, description: description); _showReminderDialog(context, dateTime, doctorName, eventId, appoDateFormatted, appoTimeFormatted,
onSuccess: onSuccess, title: title, description: description, onMultiDateSuccess: onMultiDateSuccess);
} else { } else {
requestPermissions().then((results) { requestPermissions().then((results) {
if (results[Permission.calendar].isGranted) { if (results[Permission.calendar].isGranted) {
_showReminderDialog(context, dateTime, doctorName, eventId, appoDateFormatted, appoTimeFormatted, onSuccess: onSuccess, title: title, description: description); _showReminderDialog(context, dateTime, doctorName, eventId, appoDateFormatted, appoTimeFormatted,
onSuccess: onSuccess, title: title, description: description, onMultiDateSuccess: onMultiDateSuccess);
} }
}); });
} }
@ -29,7 +31,7 @@ showReminderDialog(BuildContext context, DateTime dateTime, String doctorName, S
final CalendarPlugin _myPlugin = CalendarPlugin(); final CalendarPlugin _myPlugin = CalendarPlugin();
Future<void> _showReminderDialog(BuildContext context, DateTime dateTime, String doctorName, String eventId, String appoDateFormatted, String appoTimeFormatted, Future<void> _showReminderDialog(BuildContext context, DateTime dateTime, String doctorName, String eventId, String appoDateFormatted, String appoTimeFormatted,
{Function onSuccess, String title, String description}) async { {Function onSuccess, String title, String description, Function(int) onMultiDateSuccess}) async {
return showDialog<void>( return showDialog<void>(
context: context, context: context,
barrierDismissible: true, // user must tap button! barrierDismissible: true, // user must tap button!
@ -56,6 +58,7 @@ Future<void> _showReminderDialog(BuildContext context, DateTime dateTime, String
// dateTime.add(new Duration(minutes: -120)); // dateTime.add(new Duration(minutes: -120));
dateTime = Jiffy(dateTime).subtract(hours: 2); dateTime = Jiffy(dateTime).subtract(hours: 2);
} }
if (onMultiDateSuccess == null) {
CalendarUtils calendarUtils = await CalendarUtils.getInstance(); CalendarUtils calendarUtils = await CalendarUtils.getInstance();
calendarUtils calendarUtils
.createOrUpdateEvent( .createOrUpdateEvent(
@ -66,6 +69,9 @@ Future<void> _showReminderDialog(BuildContext context, DateTime dateTime, String
.then((value) {}); .then((value) {});
onSuccess(); onSuccess();
} else {
onMultiDateSuccess(i);
}
}, },
), ),
); );
@ -144,12 +150,14 @@ class _ReminderDialogState extends State<ReminderDialog> {
}); });
}, },
), ),
Text(TranslationBase.of(context).appoReminder30, Text(
TranslationBase.of(context).appoReminder30,
style: TextStyle( style: TextStyle(
fontSize: 12, fontSize: 12,
fontWeight: FontWeight.w600, fontWeight: FontWeight.w600,
letterSpacing: -0.48, letterSpacing: -0.48,
),), ),
),
], ],
), ),
Row( Row(
@ -163,12 +171,14 @@ class _ReminderDialogState extends State<ReminderDialog> {
}); });
}, },
), ),
Text(TranslationBase.of(context).appoReminder60, Text(
TranslationBase.of(context).appoReminder60,
style: TextStyle( style: TextStyle(
fontSize: 12, fontSize: 12,
fontWeight: FontWeight.w600, fontWeight: FontWeight.w600,
letterSpacing: -0.48, letterSpacing: -0.48,
),), ),
),
], ],
), ),
Row( Row(
@ -182,12 +192,14 @@ class _ReminderDialogState extends State<ReminderDialog> {
}); });
}, },
), ),
Text(TranslationBase.of(context).appoReminder90, Text(
TranslationBase.of(context).appoReminder90,
style: TextStyle( style: TextStyle(
fontSize: 12, fontSize: 12,
fontWeight: FontWeight.w600, fontWeight: FontWeight.w600,
letterSpacing: -0.48, letterSpacing: -0.48,
),), ),
),
], ],
), ),
Row( Row(

@ -6,6 +6,7 @@ import 'package:diplomaticquarterapp/models/header_model.dart';
import 'package:diplomaticquarterapp/pages/BookAppointment/widgets/reminder_dialog.dart'; import 'package:diplomaticquarterapp/pages/BookAppointment/widgets/reminder_dialog.dart';
import 'package:diplomaticquarterapp/pages/MyAppointments/widgets/reminder_dialog_prescription.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/pages/medical/prescriptions/pharmacy_for_prescriptions_page.dart';
import 'package:diplomaticquarterapp/uitl/CalendarUtils.dart';
import 'package:diplomaticquarterapp/uitl/LocalNotification.dart'; import 'package:diplomaticquarterapp/uitl/LocalNotification.dart';
import 'package:diplomaticquarterapp/uitl/app_toast.dart'; import 'package:diplomaticquarterapp/uitl/app_toast.dart';
import 'package:diplomaticquarterapp/uitl/date_uitl.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:diplomaticquarterapp/widgets/transitions/fade_page.dart';
import 'package:flutter/cupertino.dart'; import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'package:jiffy/jiffy.dart';
import 'package:provider/provider.dart'; import 'package:provider/provider.dart';
class PrescriptionDetailsPage extends StatelessWidget { class PrescriptionDetailsPage extends StatelessWidget {
@ -197,24 +199,26 @@ class PrescriptionDetailsPage extends StatelessWidget {
child: DefaultButton( child: DefaultButton(
TranslationBase.of(context).addReminder, TranslationBase.of(context).addReminder,
() { () {
setTheNotificatoin(context); DateTime startDate = DateTime.now();
// DateTime startDate = DateTime.now(); DateTime endDate = DateTime(startDate.year, startDate.month, startDate.day + prescriptionReport.days);
// DateTime endDate = DateTime(startDate.year, startDate.month, startDate.day + prescriptionReport.days);
// showReminderDialog(
// showReminderDialog( context,
// context, endDate,
// endDate, "",
// "", prescriptionReport.itemID.toString(),
// prescriptionReport.itemID.toString(), "",
// "", "",
// "", title: "${prescriptionReport.itemDescriptionN} Prescription Reminder",
// title: "${prescriptionReport.itemDescriptionN} Prescription Reminder", description: "${prescriptionReport.itemDescriptionN} ${prescriptionReport.frequencyN} ${prescriptionReport.routeN} ",
// description: "${prescriptionReport.itemDescriptionN} ${prescriptionReport.frequencyN} ${prescriptionReport.routeN} ", onSuccess: () {
// onSuccess: () { AppToast.showSuccessToast(message: TranslationBase.of(context).reminderSuccess);
// AppToast.showSuccessToast(message: TranslationBase.of(context).reminderSuccess); },
// }, onMultiDateSuccess: (int selectedIndex) {
// ); setCalender(context, prescriptionReport.itemID.toString(), selectedIndex);
// return; },
);
return;
}, },
iconData: Icons.notifications_active, iconData: Icons.notifications_active,
color: Color(0xffD02127), 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 startDate = DateUtil.convertStringToDate(prescriptionReport.startDate);
DateTime actualDate = DateTime(startDate.year, startDate.month, startDate.day, 8, 0); 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) if (prescriptionReport?.frequencyNumber == null) prescriptionReport.frequencyNumber = 2; //Some time frequency number is null so by default will be 2
prescriptionReport.frequencyNumber=2;
for (int i = 0; i < prescriptionReport.days; i++) { 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) { if (j != 0) {
actualDate.add(new Duration(hours: 8)); actualDate.add(new Duration(hours: 8)); // 8 hours addition for daily dose.
} }
LocalNotification.getInstance().scheduleNotification(
scheduledNotificationDateTime: actualDate, //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: "${prescriptionReport.itemDescriptionN} Prescription Reminder", title: "${prescriptionReport.itemDescriptionN} Prescription Reminder",
description: "${prescriptionReport.itemDescriptionN} ${prescriptionReport.frequencyN} ${prescriptionReport.routeN} "); 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)); actualDate.add(new Duration(days: i + 1));
} }
AppToast.showSuccessToast(message: TranslationBase.of(context).reminderSuccess); 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);
// }
} }

Loading…
Cancel
Save