diff --git a/src/Appointment/Repository/AppointmentRepository.php b/src/Appointment/Repository/AppointmentRepository.php index 7b12012d..13ca2f0d 100644 --- a/src/Appointment/Repository/AppointmentRepository.php +++ b/src/Appointment/Repository/AppointmentRepository.php @@ -27,11 +27,15 @@ class AppointmentRepository extends ServiceEntityRepository $qb = $this->createQueryBuilder('a') ->select('COUNT(a.id)') ->where('a.doctor = :doctor') - ->andWhere('a.status IN (:activeStatuses)') ->andWhere('a.slotStart < :slotEnd') ->andWhere('a.slotEnd > :slotStart') + ->andWhere( + 'a.status = :confirmed OR (a.status = :pending AND (a.expiresAt IS NULL OR a.expiresAt > :now))' + ) ->setParameter('doctor', $doctor) - ->setParameter('activeStatuses', [Appointment::STATUS_PENDING, Appointment::STATUS_CONFIRMED]) + ->setParameter('confirmed', Appointment::STATUS_CONFIRMED) + ->setParameter('pending', Appointment::STATUS_PENDING) + ->setParameter('now', time()) ->setParameter('slotStart', $slotStart) ->setParameter('slotEnd', $slotEnd);