From 661c9b006a2e984e89faadfba57e653360e2cc1a Mon Sep 17 00:00:00 2001 From: Harkamal Randhawa Date: Mon, 6 Apr 2026 00:39:37 -0600 Subject: [PATCH] Add Missed status --- .../backend/repository/AppointmentRepository.java | 4 ++-- .../db/migration/V18__past_appointments_missed.sql | 10 ++++++++++ .../dialogcontrollers/AppointmentDialogController.java | 2 +- 3 files changed, 13 insertions(+), 3 deletions(-) create mode 100644 backend/src/main/resources/db/migration/V18__past_appointments_missed.sql diff --git a/backend/src/main/java/com/petshop/backend/repository/AppointmentRepository.java b/backend/src/main/java/com/petshop/backend/repository/AppointmentRepository.java index 2a78244b..940f7cf2 100644 --- a/backend/src/main/java/com/petshop/backend/repository/AppointmentRepository.java +++ b/backend/src/main/java/com/petshop/backend/repository/AppointmentRepository.java @@ -18,7 +18,7 @@ public interface AppointmentRepository extends JpaRepository @Query("SELECT a FROM Appointment a WHERE a.appointmentDate = :date AND a.appointmentTime = :time") List findByDateAndTime(@Param("date") LocalDate date, @Param("time") LocalTime time); - @Query("SELECT a FROM Appointment a JOIN FETCH a.service WHERE a.store.storeId = :storeId AND a.appointmentDate = :date AND LOWER(a.appointmentStatus) <> 'cancelled'") + @Query("SELECT a FROM Appointment a JOIN FETCH a.service WHERE a.store.storeId = :storeId AND a.appointmentDate = :date AND LOWER(a.appointmentStatus) NOT IN ('cancelled', 'missed')") List findByStoreAndDate(@Param("storeId") Long storeId, @Param("date") LocalDate date); @Query("SELECT DISTINCT a FROM Appointment a LEFT JOIN a.pets p WHERE " + @@ -37,6 +37,6 @@ public interface AppointmentRepository extends JpaRepository "LOWER(p.petName) LIKE LOWER(CONCAT('%', :q, '%')))") Page searchAppointmentsByCustomer(@Param("customerId") Long customerId, @Param("q") String query, Pageable pageable); - @Query("SELECT a FROM Appointment a JOIN FETCH a.service WHERE a.employee.employeeId = :employeeId AND a.appointmentDate = :date AND LOWER(a.appointmentStatus) <> 'cancelled'") + @Query("SELECT a FROM Appointment a JOIN FETCH a.service WHERE a.employee.employeeId = :employeeId AND a.appointmentDate = :date AND LOWER(a.appointmentStatus) NOT IN ('cancelled', 'missed')") List findByEmployeeEmployeeIdAndAppointmentDate(@Param("employeeId") Long employeeId, @Param("date") LocalDate date); } diff --git a/backend/src/main/resources/db/migration/V18__past_appointments_missed.sql b/backend/src/main/resources/db/migration/V18__past_appointments_missed.sql new file mode 100644 index 00000000..1f3a6707 --- /dev/null +++ b/backend/src/main/resources/db/migration/V18__past_appointments_missed.sql @@ -0,0 +1,10 @@ +-- V18: Normalize past appointments. +-- Any appointment that is still 'Booked' but the date/time has passed should be marked as 'Missed'. + +UPDATE appointment +SET appointmentStatus = 'Missed' +WHERE LOWER(appointmentStatus) = 'booked' + AND ( + appointmentDate < CURRENT_DATE + OR (appointmentDate = CURRENT_DATE AND appointmentTime < CURRENT_TIME) + ); diff --git a/desktop/src/main/java/org/example/petshopdesktop/controllers/dialogcontrollers/AppointmentDialogController.java b/desktop/src/main/java/org/example/petshopdesktop/controllers/dialogcontrollers/AppointmentDialogController.java index 69cfd412..cac4f47e 100644 --- a/desktop/src/main/java/org/example/petshopdesktop/controllers/dialogcontrollers/AppointmentDialogController.java +++ b/desktop/src/main/java/org/example/petshopdesktop/controllers/dialogcontrollers/AppointmentDialogController.java @@ -57,7 +57,7 @@ public class AppointmentDialogController { private ObservableList statusList = FXCollections.observableArrayList( - "Booked", "Completed", "Cancelled" + "Booked", "Completed", "Cancelled", "Missed" ); //