BUG: Update Appointment & Clear Coltrollers
This commit is contained in:
@@ -1,4 +1,5 @@
|
|||||||
import 'package:flutter/foundation.dart';
|
import 'package:flutter/foundation.dart';
|
||||||
|
import 'package:ken_logger/ken_logger.dart';
|
||||||
import 'package:mzansi_innovation_hub/mih_components/mih_objects/appointment.dart';
|
import 'package:mzansi_innovation_hub/mih_components/mih_objects/appointment.dart';
|
||||||
|
|
||||||
class MihCalendarProvider extends ChangeNotifier {
|
class MihCalendarProvider extends ChangeNotifier {
|
||||||
@@ -57,6 +58,7 @@ class MihCalendarProvider extends ChangeNotifier {
|
|||||||
int index = personalAppointments?.indexWhere((appointment) =>
|
int index = personalAppointments?.indexWhere((appointment) =>
|
||||||
appointment.idappointments == updatedAppointment.idappointments) ??
|
appointment.idappointments == updatedAppointment.idappointments) ??
|
||||||
-1;
|
-1;
|
||||||
|
KenLogger.success("Edit Patient Index: $index");
|
||||||
if (index != -1) {
|
if (index != -1) {
|
||||||
personalAppointments?[index] = updatedAppointment;
|
personalAppointments?[index] = updatedAppointment;
|
||||||
notifyListeners();
|
notifyListeners();
|
||||||
|
|||||||
@@ -3,7 +3,6 @@ import 'package:go_router/go_router.dart';
|
|||||||
import 'package:ken_logger/ken_logger.dart';
|
import 'package:ken_logger/ken_logger.dart';
|
||||||
import 'package:mzansi_innovation_hub/main.dart';
|
import 'package:mzansi_innovation_hub/main.dart';
|
||||||
import 'package:mzansi_innovation_hub/mih_components/mih_objects/appointment.dart';
|
import 'package:mzansi_innovation_hub/mih_components/mih_objects/appointment.dart';
|
||||||
import 'package:mzansi_innovation_hub/mih_components/mih_objects/arguments.dart';
|
|
||||||
import 'package:mzansi_innovation_hub/mih_components/mih_package_components/mih_package_alert.dart';
|
import 'package:mzansi_innovation_hub/mih_components/mih_package_components/mih_package_alert.dart';
|
||||||
import 'package:mzansi_innovation_hub/mih_components/mih_providers/mih_calendar_provider.dart';
|
import 'package:mzansi_innovation_hub/mih_components/mih_providers/mih_calendar_provider.dart';
|
||||||
import 'package:mzansi_innovation_hub/mih_components/mih_providers/mzansi_profile_provider.dart';
|
import 'package:mzansi_innovation_hub/mih_components/mih_providers/mzansi_profile_provider.dart';
|
||||||
@@ -59,6 +58,13 @@ class _BuildAppointmentListState extends State<BuildAppointmentList> {
|
|||||||
late double width;
|
late double width;
|
||||||
late double height;
|
late double height;
|
||||||
|
|
||||||
|
void clearControllers() {
|
||||||
|
widget.titleController.clear();
|
||||||
|
widget.descriptionIDController.clear();
|
||||||
|
widget.dateController.clear();
|
||||||
|
widget.timeController.clear();
|
||||||
|
}
|
||||||
|
|
||||||
double getPaddingSize() {
|
double getPaddingSize() {
|
||||||
if (MzansiInnovationHub.of(context)!.theme.screenType == "desktop") {
|
if (MzansiInnovationHub.of(context)!.theme.screenType == "desktop") {
|
||||||
return (width / 10);
|
return (width / 10);
|
||||||
@@ -72,37 +78,41 @@ class _BuildAppointmentListState extends State<BuildAppointmentList> {
|
|||||||
List<Appointment> appointmentList = mzansiProfileProvider.personalHome
|
List<Appointment> appointmentList = mzansiProfileProvider.personalHome
|
||||||
? mihCalendarProvider.personalAppointments!
|
? mihCalendarProvider.personalAppointments!
|
||||||
: mihCalendarProvider.businessAppointments!;
|
: mihCalendarProvider.businessAppointments!;
|
||||||
String heading = "";
|
|
||||||
String description = "";
|
// SAFELY EXTRACT DATE AND TIME
|
||||||
DateTime now;
|
String dateTimeString = appointmentList[index].date_time;
|
||||||
int hourNow = 0;
|
String timePart = "";
|
||||||
String date = "";
|
String datePart = "";
|
||||||
int appointHour = 0;
|
|
||||||
String appointDate = "";
|
if (dateTimeString.contains("T")) {
|
||||||
if (appointmentList[index].date_time.contains("T")) {
|
List<String> parts = dateTimeString.split('T');
|
||||||
heading =
|
datePart = parts[0];
|
||||||
"${appointmentList[index].date_time.split('T')[1].substring(0, 5)} - ${appointmentList[index].title.toUpperCase()}";
|
timePart = parts[1].substring(0, 5);
|
||||||
description = appointmentList[index].description;
|
} else if (dateTimeString.contains(" ")) {
|
||||||
now = DateTime.now();
|
List<String> parts = dateTimeString.split(' ');
|
||||||
hourNow = int.parse(now.toString().split(' ')[1].substring(0, 2));
|
datePart = parts[0];
|
||||||
date = DateTime(now.year, now.month, now.day).toString().split(' ')[0];
|
timePart = parts[1].substring(0, 5);
|
||||||
appointDate = appointmentList[index].date_time.split('T')[0];
|
|
||||||
appointHour = int.parse(
|
|
||||||
appointmentList[index].date_time.split('T')[1].substring(0, 2));
|
|
||||||
} else {
|
} else {
|
||||||
heading =
|
// Fallback if format is unexpected
|
||||||
"${appointmentList[index].date_time.split(' ')[1].substring(0, 5)} - ${appointmentList[index].title.toUpperCase()}";
|
datePart = dateTimeString;
|
||||||
description = appointmentList[index].description;
|
timePart = "00:00";
|
||||||
now = DateTime.now();
|
|
||||||
hourNow = int.parse(now.toString().split(' ')[1].substring(0, 2));
|
|
||||||
date = DateTime(now.year, now.month, now.day).toString().split(' ')[0];
|
|
||||||
appointDate = appointmentList[index].date_time.split(' ')[0];
|
|
||||||
appointHour = int.parse(
|
|
||||||
appointmentList[index].date_time.split(' ')[1].substring(0, 2));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
String heading =
|
||||||
|
"$timePart - ${appointmentList[index].title.toUpperCase()}";
|
||||||
|
String description = appointmentList[index].description;
|
||||||
|
|
||||||
|
DateTime now = DateTime.now();
|
||||||
|
int hourNow = int.parse(now.toString().split(' ')[1].substring(0, 2));
|
||||||
|
String currentDate =
|
||||||
|
DateTime(now.year, now.month, now.day).toString().split(' ')[0];
|
||||||
|
|
||||||
|
int appointHour = int.parse(timePart.split(':')[0]);
|
||||||
|
|
||||||
Color appointmentColor = MihColors.getSecondaryColor(
|
Color appointmentColor = MihColors.getSecondaryColor(
|
||||||
MzansiInnovationHub.of(context)!.theme.mode == "Dark");
|
MzansiInnovationHub.of(context)!.theme.mode == "Dark");
|
||||||
if (date == appointDate) {
|
|
||||||
|
if (currentDate == datePart) {
|
||||||
if (appointHour < hourNow) {
|
if (appointHour < hourNow) {
|
||||||
appointmentColor = MihColors.getGreyColor(
|
appointmentColor = MihColors.getGreyColor(
|
||||||
MzansiInnovationHub.of(context)!.theme.mode == "Dark");
|
MzansiInnovationHub.of(context)!.theme.mode == "Dark");
|
||||||
@@ -110,7 +120,7 @@ class _BuildAppointmentListState extends State<BuildAppointmentList> {
|
|||||||
appointmentColor = MihColors.getGreenColor(
|
appointmentColor = MihColors.getGreenColor(
|
||||||
MzansiInnovationHub.of(context)!.theme.mode == "Dark");
|
MzansiInnovationHub.of(context)!.theme.mode == "Dark");
|
||||||
}
|
}
|
||||||
} else if (DateTime.parse(appointDate).isBefore(DateTime.parse(date))) {
|
} else if (DateTime.parse(datePart).isBefore(DateTime.parse(currentDate))) {
|
||||||
appointmentColor = MihColors.getGreyColor(
|
appointmentColor = MihColors.getGreyColor(
|
||||||
MzansiInnovationHub.of(context)!.theme.mode == "Dark");
|
MzansiInnovationHub.of(context)!.theme.mode == "Dark");
|
||||||
}
|
}
|
||||||
@@ -138,15 +148,15 @@ class _BuildAppointmentListState extends State<BuildAppointmentList> {
|
|||||||
),
|
),
|
||||||
),
|
),
|
||||||
onTap: () {
|
onTap: () {
|
||||||
|
// SAFELY SET CONTROLLER VALUES
|
||||||
setState(() {
|
setState(() {
|
||||||
widget.titleController.text = appointmentList[index].title;
|
widget.titleController.text = appointmentList[index].title;
|
||||||
widget.descriptionIDController.text =
|
widget.descriptionIDController.text =
|
||||||
appointmentList[index].description;
|
appointmentList[index].description;
|
||||||
widget.dateController.text =
|
widget.dateController.text = datePart;
|
||||||
appointmentList[index].date_time.split('T')[0];
|
widget.timeController.text = timePart;
|
||||||
widget.timeController.text =
|
|
||||||
appointmentList[index].date_time.split('T')[1].substring(0, 5);
|
|
||||||
});
|
});
|
||||||
|
|
||||||
if (widget.inWaitingRoom == false) {
|
if (widget.inWaitingRoom == false) {
|
||||||
appointmentDetailsWindow(
|
appointmentDetailsWindow(
|
||||||
mzansiProfileProvider, mihCalendarProvider, index, bodyWidth);
|
mzansiProfileProvider, mihCalendarProvider, index, bodyWidth);
|
||||||
@@ -214,10 +224,7 @@ class _BuildAppointmentListState extends State<BuildAppointmentList> {
|
|||||||
],
|
],
|
||||||
onWindowTapClose: () {
|
onWindowTapClose: () {
|
||||||
context.pop();
|
context.pop();
|
||||||
widget.dateController.clear();
|
clearControllers();
|
||||||
widget.timeController.clear();
|
|
||||||
widget.titleController.clear();
|
|
||||||
widget.descriptionIDController.clear();
|
|
||||||
},
|
},
|
||||||
windowBody: Padding(
|
windowBody: Padding(
|
||||||
padding:
|
padding:
|
||||||
@@ -342,10 +349,7 @@ class _BuildAppointmentListState extends State<BuildAppointmentList> {
|
|||||||
],
|
],
|
||||||
onWindowTapClose: () {
|
onWindowTapClose: () {
|
||||||
context.pop();
|
context.pop();
|
||||||
widget.dateController.clear();
|
clearControllers();
|
||||||
widget.timeController.clear();
|
|
||||||
widget.titleController.clear();
|
|
||||||
widget.descriptionIDController.clear();
|
|
||||||
},
|
},
|
||||||
windowBody: Padding(
|
windowBody: Padding(
|
||||||
padding:
|
padding:
|
||||||
@@ -591,6 +595,7 @@ class _BuildAppointmentListState extends State<BuildAppointmentList> {
|
|||||||
List<Appointment> appointmentList = mzansiProfileProvider.personalHome
|
List<Appointment> appointmentList = mzansiProfileProvider.personalHome
|
||||||
? mihCalendarProvider.personalAppointments!
|
? mihCalendarProvider.personalAppointments!
|
||||||
: mihCalendarProvider.businessAppointments!;
|
: mihCalendarProvider.businessAppointments!;
|
||||||
|
KenLogger.success("ersonalHome: ${mzansiProfileProvider.personalHome}");
|
||||||
if (mzansiProfileProvider.personalHome == true) {
|
if (mzansiProfileProvider.personalHome == true) {
|
||||||
statusCode = await MihMzansiCalendarApis.updatePersonalAppointment(
|
statusCode = await MihMzansiCalendarApis.updatePersonalAppointment(
|
||||||
mzansiProfileProvider.user!,
|
mzansiProfileProvider.user!,
|
||||||
@@ -634,28 +639,30 @@ class _BuildAppointmentListState extends State<BuildAppointmentList> {
|
|||||||
if (statusCode == 200) {
|
if (statusCode == 200) {
|
||||||
context.pop();
|
context.pop();
|
||||||
context.pop();
|
context.pop();
|
||||||
if (!widget.inWaitingRoom) {
|
successPopUp("Successfully Updated Appointment",
|
||||||
KenLogger.warning("calendar route");
|
"You appointment has been successfully updated.");
|
||||||
context.goNamed(
|
// if (!widget.inWaitingRoom) {
|
||||||
"mihCalendar",
|
// KenLogger.warning("calendar route");
|
||||||
);
|
// context.goNamed(
|
||||||
} else {
|
// "mihCalendar",
|
||||||
KenLogger.warning("waiting room route");
|
// );
|
||||||
// GoRouter.of(context).refresh();
|
// } else {
|
||||||
context.goNamed(
|
// KenLogger.warning("waiting room route");
|
||||||
'mihHome',
|
// // GoRouter.of(context).refresh();
|
||||||
);
|
// context.goNamed(
|
||||||
context.goNamed(
|
// 'mihHome',
|
||||||
'patientManager',
|
// );
|
||||||
extra: PatManagerArguments(
|
// context.goNamed(
|
||||||
mzansiProfileProvider.user!,
|
// 'patientManager',
|
||||||
false,
|
// extra: PatManagerArguments(
|
||||||
mzansiProfileProvider.business,
|
// mzansiProfileProvider.user!,
|
||||||
mzansiProfileProvider.businessUser,
|
// false,
|
||||||
),
|
// mzansiProfileProvider.business,
|
||||||
);
|
// mzansiProfileProvider.businessUser,
|
||||||
// context.pop();
|
// ),
|
||||||
}
|
// );
|
||||||
|
// // context.pop();
|
||||||
|
// }
|
||||||
} else {
|
} else {
|
||||||
internetConnectionPopUp();
|
internetConnectionPopUp();
|
||||||
}
|
}
|
||||||
@@ -724,6 +731,7 @@ class _BuildAppointmentListState extends State<BuildAppointmentList> {
|
|||||||
child: MihButton(
|
child: MihButton(
|
||||||
onPressed: () {
|
onPressed: () {
|
||||||
context.pop();
|
context.pop();
|
||||||
|
clearControllers();
|
||||||
},
|
},
|
||||||
buttonColor: MihColors.getGreenColor(
|
buttonColor: MihColors.getGreenColor(
|
||||||
MzansiInnovationHub.of(context)!.theme.mode == "Dark"),
|
MzansiInnovationHub.of(context)!.theme.mode == "Dark"),
|
||||||
@@ -805,15 +813,17 @@ class _BuildAppointmentListState extends State<BuildAppointmentList> {
|
|||||||
MzansiProfileProvider mzansiProfileProvider,
|
MzansiProfileProvider mzansiProfileProvider,
|
||||||
MihCalendarProvider mihCalendarProvider,
|
MihCalendarProvider mihCalendarProvider,
|
||||||
Widget? child) {
|
Widget? child) {
|
||||||
List<Appointment> appointmentList = mzansiProfileProvider.personalHome
|
// List<Appointment> appointmentList = mzansiProfileProvider.personalHome
|
||||||
? mihCalendarProvider.personalAppointments!
|
// ? mihCalendarProvider.personalAppointments!
|
||||||
: mihCalendarProvider.businessAppointments!;
|
// : mihCalendarProvider.businessAppointments!;
|
||||||
return Padding(
|
return Padding(
|
||||||
padding: EdgeInsets.symmetric(horizontal: getPaddingSize()),
|
padding: EdgeInsets.symmetric(horizontal: getPaddingSize()),
|
||||||
child: ListView.builder(
|
child: ListView.builder(
|
||||||
physics: const NeverScrollableScrollPhysics(),
|
physics: const NeverScrollableScrollPhysics(),
|
||||||
shrinkWrap: true,
|
shrinkWrap: true,
|
||||||
itemCount: appointmentList.length,
|
itemCount: mzansiProfileProvider.personalHome
|
||||||
|
? mihCalendarProvider.personalAppointments!.length
|
||||||
|
: mihCalendarProvider.businessAppointments!.length,
|
||||||
itemBuilder: (context, index) {
|
itemBuilder: (context, index) {
|
||||||
return displayAppointment(
|
return displayAppointment(
|
||||||
mzansiProfileProvider, mihCalendarProvider, index, width);
|
mzansiProfileProvider, mihCalendarProvider, index, width);
|
||||||
|
|||||||
@@ -139,7 +139,7 @@ class _PatientAccessRequestState extends State<Appointments> {
|
|||||||
fullscreen: false,
|
fullscreen: false,
|
||||||
windowTitle: "Add Appointment",
|
windowTitle: "Add Appointment",
|
||||||
onWindowTapClose: () {
|
onWindowTapClose: () {
|
||||||
Navigator.of(context).pop();
|
context.pop();
|
||||||
_appointmentDateController.clear();
|
_appointmentDateController.clear();
|
||||||
_appointmentTimeController.clear();
|
_appointmentTimeController.clear();
|
||||||
_appointmentTitleController.clear();
|
_appointmentTitleController.clear();
|
||||||
|
|||||||
Reference in New Issue
Block a user