From 1a6df221a50c334cf7de742e9afde461e0995748 Mon Sep 17 00:00:00 2001 From: yaso Date: Wed, 9 Oct 2024 10:49:44 +0200 Subject: [PATCH] Cancell appointment enhancement. --- .../mih_warning_message.dart | 142 ++++++++++++ .../builder/build_access_request_list.dart | 16 +- .../access_review/patient_access_review.dart | 3 +- .../builder/build_patient_queue_list.dart | 205 ++++++++++++++++-- 4 files changed, 347 insertions(+), 19 deletions(-) diff --git a/Frontend/patient_manager/lib/mih_components/mih_pop_up_messages/mih_warning_message.dart b/Frontend/patient_manager/lib/mih_components/mih_pop_up_messages/mih_warning_message.dart index 4d60cf0b..77bde7f8 100644 --- a/Frontend/patient_manager/lib/mih_components/mih_pop_up_messages/mih_warning_message.dart +++ b/Frontend/patient_manager/lib/mih_components/mih_pop_up_messages/mih_warning_message.dart @@ -118,6 +118,146 @@ class _MIHDeleteMessageState extends State { ); } + void setAppointmentCanelled() { + messageTypes["Appointment Canelled"] = Stack( + children: [ + Container( + padding: EdgeInsets.all(popUpPaddingSize), + width: popUpWidth, + height: popUpheight, + decoration: BoxDecoration( + color: MzanziInnovationHub.of(context)!.theme.primaryColor(), + borderRadius: BorderRadius.circular(25.0), + border: Border.all( + color: MzanziInnovationHub.of(context)!.theme.secondaryColor(), + width: 5.0), + ), + child: SingleChildScrollView( + child: Column( + mainAxisSize: MainAxisSize.min, + children: [ + Icon( + Icons.warning_amber_rounded, + size: popUpIconSize, + color: + MzanziInnovationHub.of(context)!.theme.secondaryColor(), + ), + //const SizedBox(height: 15), + Text( + "Appointment Cancelled", + textAlign: TextAlign.center, + style: TextStyle( + color: + MzanziInnovationHub.of(context)!.theme.secondaryColor(), + fontSize: popUpTitleSize, + fontWeight: FontWeight.bold, + ), + ), + const SizedBox(height: 15), + Text( + "This appointment has been canceled. As a result, you no longer have access to the patient's profile. If you would like to view the patient's profile again, please book a new appointment.", + style: TextStyle( + color: + MzanziInnovationHub.of(context)!.theme.secondaryColor(), + fontSize: popUpBodySize, + fontWeight: FontWeight.bold, + ), + ), + const SizedBox(height: 15), + ], + ), + ), + ), + Positioned( + top: 5, + right: 5, + width: 50, + height: 50, + child: IconButton( + onPressed: () { + Navigator.pop(context); + }, + icon: Icon( + Icons.close, + color: MzanziInnovationHub.of(context)!.theme.errorColor(), + size: 35, + ), + ), + ), + ], + ); + } + + void setAccessCanelled() { + messageTypes["Access Cancelled"] = Stack( + children: [ + Container( + padding: EdgeInsets.all(popUpPaddingSize), + width: popUpWidth, + height: popUpheight, + decoration: BoxDecoration( + color: MzanziInnovationHub.of(context)!.theme.primaryColor(), + borderRadius: BorderRadius.circular(25.0), + border: Border.all( + color: MzanziInnovationHub.of(context)!.theme.secondaryColor(), + width: 5.0), + ), + child: SingleChildScrollView( + child: Column( + mainAxisSize: MainAxisSize.min, + children: [ + Icon( + Icons.warning_amber_rounded, + size: popUpIconSize, + color: + MzanziInnovationHub.of(context)!.theme.secondaryColor(), + ), + //const SizedBox(height: 15), + Text( + "Access Cancelled", + textAlign: TextAlign.center, + style: TextStyle( + color: + MzanziInnovationHub.of(context)!.theme.secondaryColor(), + fontSize: popUpTitleSize, + fontWeight: FontWeight.bold, + ), + ), + const SizedBox(height: 15), + Text( + "This appointment has been canceled. As a result, access has been cancelled and the doctor no longer have access to the patient's profile. If you would like them to view the patient's profile again, please book a new appointment through them.", + style: TextStyle( + color: + MzanziInnovationHub.of(context)!.theme.secondaryColor(), + fontSize: popUpBodySize, + fontWeight: FontWeight.bold, + ), + ), + const SizedBox(height: 15), + ], + ), + ), + ), + Positioned( + top: 5, + right: 5, + width: 50, + height: 50, + child: IconButton( + onPressed: () { + Navigator.pop(context); + }, + icon: Icon( + Icons.close, + color: MzanziInnovationHub.of(context)!.theme.errorColor(), + size: 35, + ), + ), + ), + ], + ); + } + void setAccessDeclined() { messageTypes["Access Declined"] = Stack( children: [ @@ -278,6 +418,8 @@ class _MIHDeleteMessageState extends State { setNoAccess(); setExpiredAccess(); setAccessDeclined(); + setAppointmentCanelled(); + setAccessCanelled(); //print(size); // setState(() { // width = size.width; diff --git a/Frontend/patient_manager/lib/mih_packages/access_review/builder/build_access_request_list.dart b/Frontend/patient_manager/lib/mih_packages/access_review/builder/build_access_request_list.dart index 482142a7..cd70647b 100644 --- a/Frontend/patient_manager/lib/mih_packages/access_review/builder/build_access_request_list.dart +++ b/Frontend/patient_manager/lib/mih_packages/access_review/builder/build_access_request_list.dart @@ -5,6 +5,7 @@ import 'package:patient_manager/mih_components/mih_inputs_and_buttons/mih_button import 'package:patient_manager/mih_components/mih_layout/mih_window.dart'; import 'package:patient_manager/mih_components/mih_pop_up_messages/mih_error_message.dart'; import 'package:patient_manager/mih_components/mih_pop_up_messages/mih_success_message.dart'; +import 'package:patient_manager/mih_components/mih_pop_up_messages/mih_warning_message.dart'; import 'package:patient_manager/mih_env/env.dart'; import 'package:patient_manager/main.dart'; import 'package:patient_manager/mih_objects/access_request.dart'; @@ -94,6 +95,15 @@ class _BuildPatientsListState extends State { ); } + void accessCancelledWarning() { + showDialog( + context: context, + builder: (context) { + return const MIHWarningMessage(warningType: "Access Cancelled"); + }, + ); + } + Widget displayQueue(int index) { String line1 = "Appointment: ${widget.accessRequests[index].date_time.substring(0, 16).replaceAll("T", " ")}"; @@ -160,7 +170,11 @@ class _BuildPatientsListState extends State { // ), // ), onTap: () { - viewApprovalPopUp(index); + if (access == "CANCELLED") { + accessCancelledWarning(); + } else { + viewApprovalPopUp(index); + } }, // trailing: Icon( // Icons.arrow_forward, diff --git a/Frontend/patient_manager/lib/mih_packages/access_review/patient_access_review.dart b/Frontend/patient_manager/lib/mih_packages/access_review/patient_access_review.dart index 01b02286..e9b5a54a 100644 --- a/Frontend/patient_manager/lib/mih_packages/access_review/patient_access_review.dart +++ b/Frontend/patient_manager/lib/mih_packages/access_review/patient_access_review.dart @@ -262,7 +262,8 @@ class _PatientAccessRequestState extends State { "All", "Approved", "Pending", - "Declined" + "Declined", + "Cancelled" ], required: true, editable: true, 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 02a6db22..afbb922d 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 @@ -1,6 +1,10 @@ import 'dart:convert'; import 'package:flutter/material.dart'; +import 'package:patient_manager/mih_components/mih_inputs_and_buttons/mih_button.dart'; +import 'package:patient_manager/mih_components/mih_layout/mih_window.dart'; +import 'package:patient_manager/mih_components/mih_pop_up_messages/mih_error_message.dart'; +import 'package:patient_manager/mih_components/mih_pop_up_messages/mih_success_message.dart'; import 'package:patient_manager/mih_components/mih_pop_up_messages/mih_warning_message.dart'; import 'package:patient_manager/mih_env/env.dart'; import 'package:patient_manager/main.dart'; @@ -33,6 +37,45 @@ class BuildPatientQueueList extends StatefulWidget { class _BuildPatientsListState extends State { String baseAPI = AppEnviroment.baseApiUrl; + Future updateAccessAPICall(int index, String accessType) async { + var response = await http.put( + Uri.parse("$baseAPI/access-requests/update/"), + headers: { + "Content-Type": "application/json; charset=UTF-8" + }, + body: jsonEncode({ + "business_id": widget.business!.business_id, + "app_id": widget.patientQueue[index].app_id, + "date_time": widget.patientQueue[index].date_time, + "access": accessType, + }), + ); + 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, + ), + ); + // Navigator.of(context).pushNamed( + // '/patient-access-review', + // arguments: widget.signedInUser, + // ); + 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 fetchPatients(String app_id) async { //print("pat man drawer: " + endpointUserData + widget.userEmail); @@ -55,6 +98,121 @@ class _BuildPatientsListState extends State { } } + void internetConnectionPopUp() { + showDialog( + context: context, + builder: (context) { + return const MIHErrorMessage(errorType: "Internet Connection"); + }, + ); + } + + void successPopUp(String message) { + showDialog( + context: context, + builder: (context) { + return MIHSuccessMessage( + successType: "Success", + successMessage: message, + ); + }, + ); + } + + void viewConfirmationPopUp(int index) { + String subtitle = + "Appointment: ${widget.patientQueue[index].date_time.substring(0, 16).replaceAll("T", " ")}\n"; + subtitle += + "Patient: ${widget.patientQueue[index].first_name} ${widget.patientQueue[index].last_name}\n\n"; + //subtitle += "Business Type: ${widget.patientQueue[index].last_name}\n\n"; + subtitle += + "Would you like to view the patient's profile before the appointment or cancel the appointment now?\n"; + //"You are about to approve an access request to your patient profile.\nPlease be aware that once approved, ${widget.accessRequests[index].Name} will have access to your profile information until ${widget.accessRequests[index].revoke_date.substring(0, 16).replaceAll("T", " ")}.\nIf you are unsure about an upcoming appointment with ${widget.accessRequests[index].Name}, please contact ${widget.accessRequests[index].contact_no} for clarification before approving this request.\n"; + showDialog( + context: context, + barrierDismissible: false, + builder: (context) => MIHWindow( + fullscreen: false, + windowTitle: "Appointment Confirmation", + windowBody: [ + const SizedBox( + height: 10, + ), + Padding( + padding: const EdgeInsets.symmetric(horizontal: 10.0), + child: Text( + subtitle, + textAlign: TextAlign.left, + style: TextStyle( + color: + MzanziInnovationHub.of(context)!.theme.secondaryColor(), + fontSize: 15, + //fontWeight: FontWeight.bold, + ), + ), + ), + Wrap( + runSpacing: 10, + spacing: 10, + children: [ + SizedBox( + width: 300, + height: 50, + child: MIHButton( + onTap: () { + updateAccessAPICall(index, "cancelled"); + }, + buttonText: "Cancel Appointment", + buttonColor: + MzanziInnovationHub.of(context)!.theme.errorColor(), + textColor: + MzanziInnovationHub.of(context)!.theme.primaryColor(), + ), + ), + SizedBox( + width: 300, + height: 50, + child: MIHButton( + onTap: () { + //updateAccessAPICall(index, "approved"); + Patient selectedPatient; + fetchPatients(widget.patientQueue[index].app_id).then( + (result) { + setState(() { + selectedPatient = result; + Navigator.of(context) + .pushNamed('/patient-manager/patient', + arguments: PatientViewArguments( + widget.signedInUser, + selectedPatient, + widget.businessUser, + widget.business, + "business", + )); + }); + }, + ); + }, + buttonText: "View Patient Profile", + buttonColor: + MzanziInnovationHub.of(context)!.theme.successColor(), + textColor: + MzanziInnovationHub.of(context)!.theme.primaryColor(), + ), + ), + ], + ), + const SizedBox( + height: 10, + ), + ], + windowTools: const [], + onWindowTapClose: () { + Navigator.pop(context); + }), + ); + } + Widget displayQueue(int index) { String fname = widget.patientQueue[index].first_name[0] + "********"; String lname = widget.patientQueue[index].last_name[0] + "********"; @@ -83,7 +241,8 @@ class _BuildPatientsListState extends State { } String line5 = "\nAccess Request: "; String access = ""; - if (expireyDate.isBefore(nowDate)) { + if (expireyDate.isBefore(nowDate) && + widget.patientQueue[index].access != "cacelled") { access += "EXPIRED"; } else { access += widget.patientQueue[index].access.toUpperCase(); @@ -140,24 +299,27 @@ class _BuildPatientsListState extends State { if (revokeDate.isBefore(todayDate)) { expiredAccessWarning(); } else if (widget.patientQueue[index].access == "approved") { - Patient selectedPatient; - fetchPatients(widget.patientQueue[index].app_id).then( - (result) { - setState(() { - selectedPatient = result; - Navigator.of(context).pushNamed('/patient-manager/patient', - arguments: PatientViewArguments( - widget.signedInUser, - selectedPatient, - widget.businessUser, - widget.business, - "business", - )); - }); - }, - ); + viewConfirmationPopUp(index); + // Patient selectedPatient; + // fetchPatients(widget.patientQueue[index].app_id).then( + // (result) { + // setState(() { + // selectedPatient = result; + // Navigator.of(context).pushNamed('/patient-manager/patient', + // arguments: PatientViewArguments( + // widget.signedInUser, + // selectedPatient, + // widget.businessUser, + // widget.business, + // "business", + // )); + // }); + // }, + // ); } else if (widget.patientQueue[index].access == "declined") { accessDeclinedWarning(); + } else if (widget.patientQueue[index].access == "cancelled") { + appointmentCancelledWarning(); } else { noAccessWarning(); } @@ -187,6 +349,15 @@ class _BuildPatientsListState extends State { ); } + void appointmentCancelledWarning() { + showDialog( + context: context, + builder: (context) { + return const MIHWarningMessage(warningType: "Appointment Canelled"); + }, + ); + } + void expiredAccessWarning() { showDialog( context: context,