From c1199b1f50ae7da133a84cf8a5d47e651e135bf9 Mon Sep 17 00:00:00 2001 From: yaso Date: Tue, 15 Oct 2024 11:20:28 +0200 Subject: [PATCH] Add notification on Cancelation and rescheduled appointments --- .../builder/build_patient_queue_list.dart | 128 +++++++++++++----- 1 file changed, 97 insertions(+), 31 deletions(-) diff --git a/Frontend/patient_manager/lib/mih_packages/patient_profile/builder/build_patient_queue_list.dart b/Frontend/patient_manager/lib/mih_packages/patient_profile/builder/build_patient_queue_list.dart index 8bdfd50f..2f328115 100644 --- a/Frontend/patient_manager/lib/mih_packages/patient_profile/builder/build_patient_queue_list.dart +++ b/Frontend/patient_manager/lib/mih_packages/patient_profile/builder/build_patient_queue_list.dart @@ -61,24 +61,21 @@ class _BuildPatientsListState extends State { ); if (response.statusCode == 200) { //Navigator.of(context).pushNamed('/home'); - Navigator.of(context).pop(); - Navigator.of(context).pop(); - Navigator.of(context).pushNamed( - '/patient-manager', - arguments: BusinessArguments( - widget.signedInUser, - widget.businessUser, - widget.business, - ), - ); + addCancelledAppointmentNotificationAPICall(index); + // Navigator.of(context).pop(); + // Navigator.of(context).pop(); // Navigator.of(context).pushNamed( - // '/patient-access-review', - // arguments: widget.signedInUser, + // '/patient-manager', + // arguments: BusinessArguments( + // widget.signedInUser, + // widget.businessUser, + // widget.business, + // ), // ); - String message = - "The appointment for ${widget.patientQueue[index].first_name} ${widget.patientQueue[index].last_name} at ${widget.patientQueue[index].date_time} has been successfully canceled."; + // String message = + // "The appointment for ${widget.patientQueue[index].first_name} ${widget.patientQueue[index].last_name} at ${widget.patientQueue[index].date_time} has been successfully canceled."; - successPopUp(message); + // successPopUp(message); } else { internetConnectionPopUp(); } @@ -98,25 +95,23 @@ class _BuildPatientsListState extends State { ); if (response.statusCode == 200) { //Navigator.of(context).pushNamed('/home'); - Navigator.of(context).pop(); - Navigator.of(context).pop(); - Navigator.of(context).pop(); - Navigator.of(context).pushNamed( - '/patient-manager', - arguments: BusinessArguments( - widget.signedInUser, - widget.businessUser, - widget.business, - ), - ); + addRescheduledAppointmentNotificationAPICall(index); + // Navigator.of(context).pop(); + // Navigator.of(context).pop(); + // Navigator.of(context).pop(); // Navigator.of(context).pushNamed( - // '/patient-access-review', - // arguments: widget.signedInUser, + // '/patient-manager', + // arguments: BusinessArguments( + // widget.signedInUser, + // widget.businessUser, + // widget.business, + // ), // ); - String message = - "The appointment has been rescheduled for ${dateController.text} ${timeController.text}.\n\nJust a heads up: We've reset your access to the patient's profile and it will have to be approved again."; - successPopUp(message); + // String message = + // "The appointment has been rescheduled for ${dateController.text} ${timeController.text}.\n\nJust a heads up: We've reset your access to the patient's profile and it will have to be approved again."; + + // successPopUp(message); } else { internetConnectionPopUp(); } @@ -307,6 +302,77 @@ class _BuildPatientsListState extends State { ); } + Future addCancelledAppointmentNotificationAPICall(int index) async { + var response = await http.post( + Uri.parse("$baseAPI/notifications/insert/"), + headers: { + "Content-Type": "application/json; charset=UTF-8" + }, + body: jsonEncode({ + "app_id": widget.patientQueue[index].app_id, + "notification_type": "Appointment Cancelled", + "notification_message": + "Your appointment with ${widget.business!.Name} for the ${widget.patientQueue[index].date_time.replaceAll("T", " ")} has been cancelled.", + "action_path": "/access-review", + }), + ); + if (response.statusCode == 201) { + // Navigator.pushNamed(context, '/patient-manager/patient', + // arguments: widget.signedInUser); + Navigator.of(context).pop(); + Navigator.of(context).pop(); + Navigator.of(context).pushNamed( + '/patient-manager', + arguments: BusinessArguments( + widget.signedInUser, + widget.businessUser, + widget.business, + ), + ); + String message = + "The appointment for ${widget.patientQueue[index].first_name} ${widget.patientQueue[index].last_name} at ${widget.patientQueue[index].date_time} has been successfully canceled."; + + successPopUp(message); + } else { + internetConnectionPopUp(); + } + } + + Future addRescheduledAppointmentNotificationAPICall(int index) async { + var response = await http.post( + Uri.parse("$baseAPI/notifications/insert/"), + headers: { + "Content-Type": "application/json; charset=UTF-8" + }, + body: jsonEncode({ + "app_id": widget.patientQueue[index].app_id, + "notification_type": "Rescheduled Appointment", + "notification_message": + "Your appointment with ${widget.business!.Name} for the ${widget.patientQueue[index].date_time.replaceAll("T", " ").substring(0, widget.patientQueue[index].date_time.length - 3)} has been rescheduled to the ${dateController.text} ${timeController.text}.", + "action_path": "/access-review", + }), + ); + if (response.statusCode == 201) { + Navigator.of(context).pop(); + Navigator.of(context).pop(); + Navigator.of(context).pop(); + Navigator.of(context).pushNamed( + '/patient-manager', + arguments: BusinessArguments( + widget.signedInUser, + widget.businessUser, + widget.business, + ), + ); + String message = + "The appointment for ${widget.patientQueue[index].first_name} ${widget.patientQueue[index].last_name} at ${widget.patientQueue[index].date_time} has been successfully canceled."; + + successPopUp(message); + } else { + internetConnectionPopUp(); + } + } + void manageAppointmentPopUp(int index) { showDialog( context: context,