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 2f328115..4489b18d 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 @@ -45,7 +45,8 @@ class _BuildPatientsListState extends State { TextEditingController idController = TextEditingController(); TextEditingController fnameController = TextEditingController(); TextEditingController lnameController = TextEditingController(); - + TextEditingController daysExtensionController = TextEditingController(); + int counter = 0; Future updateAccessAPICall(int index, String accessType) async { var response = await http.put( Uri.parse("$baseAPI/access-requests/update/"), @@ -81,6 +82,27 @@ class _BuildPatientsListState extends State { } } + Future extendAccessAPICall(int index, String revokeDate) async { + var response = await http.put( + Uri.parse("$baseAPI/access-requests/extension/"), + 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, + "revoke_date": revokeDate, + }), + ); + if (response.statusCode == 200) { + addAccessExtensionNotificationAPICall(index, revokeDate); + //addCancelledAppointmentNotificationAPICall(index); + } else { + internetConnectionPopUp(); + } + } + Future updateApointmentAPICall(int index) async { var response = await http.put( Uri.parse("$baseAPI/queue/update/"), @@ -373,6 +395,41 @@ class _BuildPatientsListState extends State { } } + Future addAccessExtensionNotificationAPICall( + int index, String revokeDate) 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": "Access Extension Request", + "notification_message": + "${widget.business!.Name} - access expiry date extension for appointment: ${widget.patientQueue[index].date_time.split("T")[0]}. Expiry Date: from ${widget.patientQueue[index].revoke_date.split("T")[0]} to ${revokeDate.split(" ")[0]}.", + "action_path": "/access-review", + }), + ); + if (response.statusCode == 201) { + Navigator.of(context).pop(); + Navigator.of(context).pop(); + Navigator.of(context).pushNamed( + '/patient-manager', + arguments: BusinessArguments( + widget.signedInUser, + widget.businessUser, + widget.business, + ), + ); + String message = + "you have successfully requested an extension on the expirey date. The request has been sent tp ${widget.patientQueue[index].first_name} ${widget.patientQueue[index].last_name} to review and approve the request"; + + successPopUp(message); + } else { + internetConnectionPopUp(); + } + } + void manageAppointmentPopUp(int index) { showDialog( context: context, @@ -526,7 +583,7 @@ class _BuildPatientsListState extends State { text: TextSpan( text: line234, style: DefaultTextStyle.of(context).style, - children: [ + children: [ TextSpan(text: line5), accessWithColour, TextSpan(text: line6), @@ -572,9 +629,144 @@ class _BuildPatientsListState extends State { //noAccessWarning(); } }, - trailing: Icon( + //leading: getExtendAccessButton(access), + trailing: getExtendAccessButton(access, index), + // Icon( + // Icons.arrow_forward, + // color: MzanziInnovationHub.of(context)!.theme.secondaryColor(), + // ), + ); + } + + bool isAccessExpired(String accessType) { + if (accessType == "EXPIRED") { + return true; + } else { + return false; + } + } + + Widget getExtendAccessButton(String accessType, int index) { + if (isAccessExpired(accessType)) { + return IconButton( + icon: const Icon(Icons.cached), + onPressed: () { + setState(() { + daysExtensionController.text = counter.toString(); + }); + reapplyForAccess(index); + }, + ); + } else { + return Icon( Icons.arrow_forward, color: MzanziInnovationHub.of(context)!.theme.secondaryColor(), + ); + } + } + + void reapplyForAccess(int index) { + showDialog( + context: context, + barrierDismissible: false, + builder: (context) => MIHWindow( + fullscreen: false, + windowTitle: "Extend Access", + windowTools: const [], + onWindowTapClose: () { + Navigator.pop(context); + }, + windowBody: [ + Text( + "Current Expiration Date : ${widget.patientQueue[index].revoke_date.replaceAll("T", " ")}", + style: TextStyle( + color: MzanziInnovationHub.of(context)!.theme.secondaryColor(), + fontSize: 15, + fontWeight: FontWeight.normal, + ), + ), + const SizedBox(height: 5), + Text( + "Select the number of days you would like to extend the access by.", + style: TextStyle( + color: MzanziInnovationHub.of(context)!.theme.secondaryColor(), + fontSize: 15, + fontWeight: FontWeight.normal, + ), + ), + const SizedBox(height: 5), + Text( + "Once you click \"Apply\", an access review request will be triggered to the patient.", + style: TextStyle( + color: MzanziInnovationHub.of(context)!.theme.secondaryColor(), + fontSize: 15, + fontWeight: FontWeight.normal, + ), + ), + const SizedBox(height: 30), + Row( + mainAxisAlignment: MainAxisAlignment.center, + children: [ + IconButton.filled( + onPressed: () { + if (counter > 0) { + counter--; + setState(() { + daysExtensionController.text = counter.toString(); + }); + } + }, + icon: const Icon(Icons.remove), + ), + const SizedBox(width: 15), + SizedBox( + width: 100, + child: MIHTextField( + controller: daysExtensionController, + hintText: "Days", + editable: false, + required: true, + ), + ), + const SizedBox(width: 15), + IconButton.filled( + onPressed: () { + counter++; + setState(() { + daysExtensionController.text = counter.toString(); + }); + }, + icon: const Icon(Icons.add), + ), + ], + ), + const SizedBox(height: 30), + SizedBox( + width: 300, + height: 50, + child: MIHButton( + onTap: () { + print( + "Revoke Date (String): ${widget.patientQueue[index].revoke_date}"); + var revokeDate = DateTime.parse(widget + .patientQueue[index].revoke_date + .replaceAll("T", " ")); + var newRevokeDate = revokeDate.add( + Duration(days: int.parse(daysExtensionController.text))); + print("Revoke Date (DateTime): $revokeDate"); + print("New Revoke Date (DateTime): $newRevokeDate"); + print( + "${widget.business!.Name} would like to extend the access expirey date for your appointment on the ${widget.patientQueue[index].date_time}.\nNew Expirey Date: $revokeDate", + ); + extendAccessAPICall(index, "$newRevokeDate"); + }, + buttonText: "Apply", + buttonColor: + MzanziInnovationHub.of(context)!.theme.secondaryColor(), + textColor: MzanziInnovationHub.of(context)!.theme.primaryColor(), + ), + ), + ], ), ); } @@ -617,6 +809,7 @@ class _BuildPatientsListState extends State { @override void dispose() { + daysExtensionController.dispose(); dateController.dispose(); timeController.dispose(); super.dispose(); @@ -625,6 +818,7 @@ class _BuildPatientsListState extends State { @override Widget build(BuildContext context) { return ListView.separated( + physics: const NeverScrollableScrollPhysics(), shrinkWrap: true, separatorBuilder: (BuildContext context, index) { return Divider(