fix(doctors): correct city/state filters in doctor listing API
This commit is contained in:
@@ -45,32 +45,35 @@ class DoctorRepository extends ServiceEntityRepository
|
||||
$limit = min(50, max(1, (int) ($filters['limit'] ?? 10)));
|
||||
$sort = strtoupper($filters['sort'] ?? 'DESC') === 'ASC' ? 'ASC' : 'DESC';
|
||||
|
||||
// Location comes from the doctor's own address (doctor_addresses), plus a
|
||||
// fallback to the clinic address for doctors listed under a clinic.
|
||||
$qb = $this->createQueryBuilder('d')
|
||||
->leftJoin('d.specialties', 's')
|
||||
->leftJoin('d.provinces', 'pr')
|
||||
->leftJoin('d.cities', 'ci')
|
||||
->leftJoin(DoctorAddress::class, 'da', Join::WITH, 'da.doctor = d')
|
||||
->distinct();
|
||||
|
||||
if (!empty($filters['state'])) {
|
||||
$stateId = (int) $filters['state'];
|
||||
if (!empty($filters['state_id'])) {
|
||||
$stateId = (int) $filters['state_id'];
|
||||
$clinicIds = $this->doctorIdsViaClinicLocation('province', $stateId);
|
||||
$qb->andWhere('pr.id = :state' . ($clinicIds ? ' OR d.id IN (:stateClinicDoctorIds)' : ''))
|
||||
->setParameter('state', $stateId);
|
||||
$orX = $qb->expr()->orX('IDENTITY(da.province) = :state');
|
||||
if ($clinicIds) {
|
||||
$orX->add('d.id IN (:stateClinicDoctorIds)');
|
||||
$qb->setParameter('stateClinicDoctorIds', $clinicIds);
|
||||
}
|
||||
$qb->andWhere($orX)->setParameter('state', $stateId);
|
||||
}
|
||||
if (!empty($filters['city'])) {
|
||||
$cityId = (int) $filters['city'];
|
||||
if (!empty($filters['city_id'])) {
|
||||
$cityId = (int) $filters['city_id'];
|
||||
$clinicIds = $this->doctorIdsViaClinicLocation('city', $cityId);
|
||||
$qb->andWhere('ci.id = :city' . ($clinicIds ? ' OR d.id IN (:cityClinicDoctorIds)' : ''))
|
||||
->setParameter('city', $cityId);
|
||||
$orX = $qb->expr()->orX('IDENTITY(da.city) = :city');
|
||||
if ($clinicIds) {
|
||||
$orX->add('d.id IN (:cityClinicDoctorIds)');
|
||||
$qb->setParameter('cityClinicDoctorIds', $clinicIds);
|
||||
}
|
||||
$qb->andWhere($orX)->setParameter('city', $cityId);
|
||||
}
|
||||
if (!empty($filters['specialty'])) {
|
||||
$qb->andWhere('s.id = :specialty')->setParameter('specialty', (int) $filters['specialty']);
|
||||
if (!empty($filters['specialty_id'])) {
|
||||
$qb->andWhere('s.id = :specialty')->setParameter('specialty', (int) $filters['specialty_id']);
|
||||
}
|
||||
if (!empty($filters['gender'])) {
|
||||
$qb->andWhere('d.gender = :gender')->setParameter('gender', $filters['gender']);
|
||||
|
||||
Reference in New Issue
Block a user