prescription reminders added

merge-update-with-lab-changes
haroon amjad 4 years ago
parent ff0e878bf2
commit 68294690a1

@ -171,6 +171,7 @@ const Map localizedValues = {
"minute": {"en": "Minutes", "ar": "دقيقة"}, "minute": {"en": "Minutes", "ar": "دقيقة"},
"hour": {"en": "Hour", "ar": "ساعة"}, "hour": {"en": "Hour", "ar": "ساعة"},
"reminderSuccess": {"en": "The reminder has been added successfully", "ar": "تمت إضافة التذكير بنجاح"}, "reminderSuccess": {"en": "The reminder has been added successfully", "ar": "تمت إضافة التذكير بنجاح"},
"reminderCancelSuccess": {"en": "The reminder has been cancelled successfully", "ar": "تم إلغاء التذكير بنجاح"},
"patientShareToDo": {"en": "Amount before tax: ", "ar": "المبلغ قبل الضريبة:"}, "patientShareToDo": {"en": "Amount before tax: ", "ar": "المبلغ قبل الضريبة:"},
"patientTaxToDo": {"en": "Tax amount: ", "ar": "قيمة الضريبة:"}, "patientTaxToDo": {"en": "Tax amount: ", "ar": "قيمة الضريبة:"},
"patientShareTotalToDo": {"en": "Total amount Due: ", "ar": "المبلغ الإجمالي المستحق:"}, "patientShareTotalToDo": {"en": "Total amount Due: ", "ar": "المبلغ الإجمالي المستحق:"},
@ -449,6 +450,7 @@ const Map localizedValues = {
"Frequency": {"en": "Frequency", "ar": "المعدل"}, "Frequency": {"en": "Frequency", "ar": "المعدل"},
"DailyQuantity": {"en": "Daily Quantity :", "ar": "جرعات يومية"}, "DailyQuantity": {"en": "Daily Quantity :", "ar": "جرعات يومية"},
"AddReminder": {"en": "Add Reminder", "ar": "إضافة تذكير"}, "AddReminder": {"en": "Add Reminder", "ar": "إضافة تذكير"},
"CancelReminder": {"en": "Cancel Reminder", "ar": "إلغاء تذكير"},
"reminderDes": { "reminderDes": {
"en": "Please select treatment start day and time to be notified when it\'s time to take the medicine", "en": "Please select treatment start day and time to be notified when it\'s time to take the medicine",
"ar": "يرجى تحديد يوم بدء العلاج والوقت ليتم ارسال تنبيه عندما يحين الوقت لتناول الدواء" "ar": "يرجى تحديد يوم بدء العلاج والوقت ليتم ارسال تنبيه عندما يحين الوقت لتناول الدواء"

@ -122,10 +122,10 @@ class BaseAppClient {
} }
} }
// body['IdentificationNo'] = 1009199553; body['IdentificationNo'] = 1009199553;
// body['MobileNo'] = "966545156035"; body['MobileNo'] = "966545156035";
// body['PatientID'] = 1018977; //3844083 body['PatientID'] = 1018977; //3844083
// body['TokenID'] = "@dm!n"; body['TokenID'] = "@dm!n";
body.removeWhere((key, value) => key == null || value == null); body.removeWhere((key, value) => key == null || value == null);

@ -1,15 +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/Prescriptions.dart';
import 'package:diplomaticquarterapp/core/model/prescriptions/prescription_report.dart'; import 'package:diplomaticquarterapp/core/model/prescriptions/prescription_report.dart';
import 'package:diplomaticquarterapp/core/viewModels/project_view_model.dart'; import 'package:diplomaticquarterapp/core/viewModels/project_view_model.dart';
import 'package:diplomaticquarterapp/extensions/string_extensions.dart'; import 'package:diplomaticquarterapp/extensions/string_extensions.dart';
import 'package:diplomaticquarterapp/models/header_model.dart'; 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/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/CalendarUtils.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';
import 'package:diplomaticquarterapp/uitl/gif_loader_dialog_utils.dart';
import 'package:diplomaticquarterapp/uitl/translations_delegate_base.dart'; import 'package:diplomaticquarterapp/uitl/translations_delegate_base.dart';
import 'package:diplomaticquarterapp/uitl/utils.dart'; import 'package:diplomaticquarterapp/uitl/utils.dart';
import 'package:diplomaticquarterapp/uitl/utils_new.dart'; import 'package:diplomaticquarterapp/uitl/utils_new.dart';
@ -23,12 +25,25 @@ import 'package:flutter/material.dart';
import 'package:jiffy/jiffy.dart'; import 'package:jiffy/jiffy.dart';
import 'package:provider/provider.dart'; import 'package:provider/provider.dart';
class PrescriptionDetailsPage extends StatelessWidget { class PrescriptionDetailsPage extends StatefulWidget {
final PrescriptionReport prescriptionReport; final PrescriptionReport prescriptionReport;
final Prescriptions prescriptions; final Prescriptions prescriptions;
PrescriptionDetailsPage({Key key, this.prescriptionReport, this.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 @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
ProjectViewModel projectViewModel = Provider.of(context); ProjectViewModel projectViewModel = Provider.of(context);
@ -42,18 +57,18 @@ class PrescriptionDetailsPage extends StatelessWidget {
children: <Widget>[ children: <Widget>[
DoctorHeader( DoctorHeader(
headerModel: HeaderModel( headerModel: HeaderModel(
prescriptions.doctorName, widget.prescriptions.doctorName,
prescriptions.doctorID, widget.prescriptions.doctorID,
prescriptions.doctorImageURL, widget.prescriptions.doctorImageURL,
prescriptions.speciality, widget.prescriptions.speciality,
"", "",
prescriptions.name, widget.prescriptions.name,
DateUtil.convertStringToDate(prescriptions.appointmentDate), DateUtil.convertStringToDate(widget.prescriptions.appointmentDate),
DateUtil.formatDateToTime(DateUtil.convertStringToDate(prescriptions.appointmentDate)), DateUtil.formatDateToTime(DateUtil.convertStringToDate(widget.prescriptions.appointmentDate)),
prescriptions.nationalityFlagURL, widget.prescriptions.nationalityFlagURL,
prescriptions.doctorRate, widget.prescriptions.doctorRate,
prescriptions.actualDoctorRate, widget.prescriptions.actualDoctorRate,
prescriptions.noOfPatientsRate, widget.prescriptions.noOfPatientsRate,
"", "",
), ),
isNeedToShowButton: false, isNeedToShowButton: false,
@ -104,7 +119,7 @@ class PrescriptionDetailsPage extends StatelessWidget {
children: [ children: [
Container( Container(
child: Image.network( child: Image.network(
prescriptionReport.imageSRCUrl, widget.prescriptionReport.imageSRCUrl,
fit: BoxFit.cover, fit: BoxFit.cover,
width: 48, width: 48,
height: 49, height: 49,
@ -125,13 +140,15 @@ class PrescriptionDetailsPage extends StatelessWidget {
], ],
), ),
onTap: () { onTap: () {
showZoomImageDialog(context, prescriptionReport.imageSRCUrl); showZoomImageDialog(context, widget.prescriptionReport.imageSRCUrl);
}, },
), ),
SizedBox(width: 12), SizedBox(width: 12),
Expanded( Expanded(
child: Text( 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), style: TextStyle(fontSize: 16, fontWeight: FontWeight.w600, color: Color(0xff2E303A), letterSpacing: -0.64),
), ),
) )
@ -149,10 +166,10 @@ class PrescriptionDetailsPage extends StatelessWidget {
), ),
TableRow( TableRow(
children: [ children: [
Utils.tableColumnValue(prescriptionReport?.routeN ?? '', isLast: true, mProjectViewModel: projectViewModel), Utils.tableColumnValue(widget.prescriptionReport?.routeN ?? '', isLast: true, mProjectViewModel: projectViewModel),
Utils.tableColumnValue(prescriptionReport?.frequencyN ?? '', isLast: true, mProjectViewModel: projectViewModel), Utils.tableColumnValue(widget.prescriptionReport?.frequencyN ?? '', isLast: true, mProjectViewModel: projectViewModel),
Utils.tableColumnValue(prescriptionReport?.doseDailyQuantity.toString() ?? '', isLast: true, mProjectViewModel: projectViewModel), Utils.tableColumnValue(widget.prescriptionReport?.doseDailyQuantity.toString() ?? '', isLast: true, mProjectViewModel: projectViewModel),
Utils.tableColumnValue(prescriptionReport?.days.toString() ?? '', isLast: true, mProjectViewModel: projectViewModel), Utils.tableColumnValue(widget.prescriptionReport?.days.toString() ?? '', isLast: true, mProjectViewModel: projectViewModel),
], ],
), ),
]), ]),
@ -161,7 +178,7 @@ class PrescriptionDetailsPage extends StatelessWidget {
style: TextStyle(fontSize: 12, fontWeight: FontWeight.w600, color: Color(0xff2E303A), letterSpacing: -0.48), style: TextStyle(fontSize: 12, fontWeight: FontWeight.w600, color: Color(0xff2E303A), letterSpacing: -0.48),
), ),
Text( Text(
prescriptionReport.remarks, widget.prescriptionReport.remarks,
style: TextStyle(fontSize: 12, fontWeight: FontWeight.w600, color: Color(0xff575757), letterSpacing: -0.4, height: 16 / 10), style: TextStyle(fontSize: 12, fontWeight: FontWeight.w600, color: Color(0xff575757), letterSpacing: -0.4, height: 16 / 10),
), ),
], ],
@ -184,8 +201,8 @@ class PrescriptionDetailsPage extends StatelessWidget {
context, context,
FadePage( FadePage(
page: PharmacyForPrescriptionsPage( page: PharmacyForPrescriptionsPage(
itemID: prescriptionReport.itemID, itemID: widget.prescriptionReport.itemID,
prescriptionReport: prescriptionReport, prescriptionReport: widget.prescriptionReport,
), ),
), ),
); );
@ -197,31 +214,35 @@ class PrescriptionDetailsPage extends StatelessWidget {
SizedBox(width: 10), SizedBox(width: 10),
Expanded( Expanded(
child: DefaultButton( child: DefaultButton(
TranslationBase.of(context).addReminder, hasReminder ? TranslationBase.of(context).cancelReminder : TranslationBase.of(context).addReminder,
() { () {
DateTime startDate = DateTime.now(); if (hasReminder) {
DateTime endDate = DateTime(startDate.year, startDate.month, startDate.day + prescriptionReport.days); cancelReminders();
} else {
showReminderDialog( DateTime startDate = DateTime.now();
context, DateTime endDate = DateTime(startDate.year, startDate.month, startDate.day + widget.prescriptionReport.days);
endDate, showReminderDialog(
"", context,
prescriptionReport.itemID.toString(), endDate,
"", "",
"", widget.prescriptionReport.itemID.toString(),
title: "${prescriptionReport.itemDescriptionN} Prescription Reminder", "",
description: "${prescriptionReport.itemDescriptionN} ${prescriptionReport.frequencyN} ${prescriptionReport.routeN} ", "",
onSuccess: () { title: "${widget.prescriptionReport.itemDescriptionN} Prescription Reminder",
AppToast.showSuccessToast(message: TranslationBase.of(context).reminderSuccess); description: "${widget.prescriptionReport.itemDescriptionN} ${widget.prescriptionReport.frequencyN} ${widget.prescriptionReport.routeN} ",
}, onSuccess: () {
onMultiDateSuccess: (int selectedIndex) { AppToast.showSuccessToast(message: TranslationBase.of(context).reminderSuccess);
setCalender(context, prescriptionReport.itemID.toString(), selectedIndex); },
}, onMultiDateSuccess: (int selectedIndex) {
); setCalender(context, widget.prescriptionReport.itemID.toString(), selectedIndex);
return; },
);
return;
}
}, },
iconData: Icons.notifications_active, iconData: Icons.notifications_active,
color: Color(0xffD02127), color: Color(0xffD02127),
fontSize: 13.0,
//textColor: Color(0xff2B353E), //textColor: Color(0xff2B353E),
), ),
), ),
@ -233,16 +254,58 @@ 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 { setCalender(BuildContext context, String eventId, int reminderIndex) async {
CalendarUtils calendarUtils = await CalendarUtils.getInstance(); CalendarUtils calendarUtils = await CalendarUtils.getInstance();
DateTime startDate = DateUtil.convertStringToDate(prescriptionReport.startDate); 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 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 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 < prescriptionReport.days; i++) { for (int i = 0; i < widget.prescriptionReport.days; i++) {
//event for number of days. //event for number of days.
for (int j = 0; j < prescriptionReport.frequencyNumber ?? 2; j++) { for (int j = 0; j < widget.prescriptionReport.frequencyNumber ?? 1; j++) {
// event for number of times per day. // event for number of times per day.
if (j != 0) { if (j != 0) {
@ -269,38 +332,21 @@ class PrescriptionDetailsPage extends StatelessWidget {
} }
calendarUtils calendarUtils
.createOrUpdateEvent( .createOrUpdateEvent(
title: "${prescriptionReport.itemDescriptionN} Prescription Reminder", title: "${widget.prescriptionReport.itemDescriptionN} Prescription Reminder",
description: "${prescriptionReport.itemDescriptionN} ${prescriptionReport.frequencyN} ${prescriptionReport.routeN} ", description: "${widget.prescriptionReport.itemDescriptionN} ${widget.prescriptionReport.frequencyN} ${widget.prescriptionReport.routeN} ",
scheduleDateTime: actualDate, scheduleDateTime: actualDate,
eventId: eventId + (i.toString() + j.toString()), //event id with varitions eventId: eventId + (i.toString() + j.toString()), //event id with varitions
) )
.then( .then((value) {});
(value) {}, actualDate = DateTime(actualDate.year, actualDate.month, actualDate.day, 8, 0);
);
} }
actualDate.add(new Duration(days: i + 1)); actualDate = Jiffy(actualDate).add(days: 1);
print(actualDate);
} }
AppToast.showSuccessToast(message: TranslationBase.of(context).reminderSuccess); AppToast.showSuccessToast(message: TranslationBase.of(context).reminderSuccess);
GifLoaderDialogUtils.hideDialog(context);
setState(() {
hasReminder = true;
});
} }
//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);
// }
} }

@ -2789,8 +2789,9 @@ class TranslationBase {
String get gr => localizedValues["gr"][locale.languageCode]; String get gr => localizedValues["gr"][locale.languageCode];
String get gramsPerMeal => localizedValues["gramsPerMeal"][locale.languageCode]; String get gramsPerMeal => localizedValues["gramsPerMeal"][locale.languageCode];
String get cancelReminder => localizedValues["CancelReminder"][locale.languageCode];
String get reminderCancelSuccess => localizedValues["reminderCancelSuccess"][locale.languageCode];
} }
class TranslationBaseDelegate extends LocalizationsDelegate<TranslationBase> { class TranslationBaseDelegate extends LocalizationsDelegate<TranslationBase> {

Loading…
Cancel
Save