feat(clinic): update filtering logic to use clinic address for city/state
This commit is contained in:
@@ -5,7 +5,9 @@ namespace App\Clinic\Repository;
|
||||
use App\Auth\Entity\User;
|
||||
use App\Clinic\Entity\Clinic;
|
||||
use App\Doctor\Entity\Doctor;
|
||||
use App\Doctor\Entity\DoctorAddress;
|
||||
use Doctrine\Bundle\DoctrineBundle\Repository\ServiceEntityRepository;
|
||||
use Doctrine\ORM\Query\Expr\Join;
|
||||
use Doctrine\ORM\Tools\Pagination\Paginator;
|
||||
use Doctrine\Persistence\ManagerRegistry;
|
||||
|
||||
@@ -47,11 +49,18 @@ class ClinicRepository extends ServiceEntityRepository
|
||||
->leftJoin('c.specialties', 's')
|
||||
->distinct();
|
||||
|
||||
if (!empty($filters['state'])) {
|
||||
$qb->andWhere('c.stateId = :state')->setParameter('state', (int) $filters['state']);
|
||||
}
|
||||
if (!empty($filters['city'])) {
|
||||
$qb->andWhere('c.cityId = :city')->setParameter('city', (int) $filters['city']);
|
||||
// City/province live on the clinic's address (DoctorAddress.clinicId),
|
||||
// not on the clinic itself. DoctorAddress has no Doctrine relation to
|
||||
// Clinic, so join on the scalar clinicId with a WITH condition.
|
||||
if (!empty($filters['city']) || !empty($filters['state'])) {
|
||||
$qb->join(DoctorAddress::class, 'addr', Join::WITH, 'addr.clinicId = c.id');
|
||||
|
||||
if (!empty($filters['city'])) {
|
||||
$qb->andWhere('IDENTITY(addr.city) = :city')->setParameter('city', (int) $filters['city']);
|
||||
}
|
||||
if (!empty($filters['state'])) {
|
||||
$qb->andWhere('IDENTITY(addr.province) = :state')->setParameter('state', (int) $filters['state']);
|
||||
}
|
||||
}
|
||||
if (!empty($filters['specialty'])) {
|
||||
$qb->andWhere('s.id = :specialty')->setParameter('specialty', (int) $filters['specialty']);
|
||||
|
||||
Reference in New Issue
Block a user