feat(clinic): enhance clinic listing with additional details and address information

- Updated the clinic API response to include new fields: title, phone, logo, images_clinic, doctors_count, city, state, 24_7, and field_working_days.
- Modified the ClinicController to fetch and include city and state information based on the clinic's address.
- Refactored the toListArray method in the Clinic entity to accept city and state parameters.
- Added a new method in the ClinicRepository to retrieve city and province names for each clinic based on their address.
This commit is contained in:
hamed
2026-06-18 15:03:36 +03:30
parent eb576b7d98
commit 4bb65c7502
5 changed files with 359 additions and 273 deletions
+7 -1
View File
@@ -252,8 +252,14 @@ class ClinicController extends BaseController
$filters = $request->query->all();
$result = $this->clinicRepo->findWithFilters($filters);
$clinicIds = array_map(fn(Clinic $c) => $c->getId(), $result['items']);
$locations = $this->clinicRepo->findAddressLocations($clinicIds);
return $this->paginated(
array_map(fn(Clinic $c) => $c->toListArray(), $result['items']),
array_map(function (Clinic $c) use ($locations) {
$loc = $locations[$c->getId()] ?? ['city' => null, 'state' => null];
return $c->toListArray($loc['city'], $loc['state']);
}, $result['items']),
$result['total'],
$result['page'],
$result['limit']
+5 -2
View File
@@ -211,7 +211,7 @@ class Clinic
];
}
public function toListArray(): array
public function toListArray(?string $city = null, ?string $state = null): array
{
return [
'id' => (string) $this->id,
@@ -226,10 +226,13 @@ class Clinic
'doctors_count' => $this->doctors->count(),
'is_active' => $this->isActive,
'created_at' => $this->createdAt,
'city' => $city,
'state' => $state,
'specialties' => array_map(fn(Specialty $s) => [
'uuid' => $s->getUuid(), 'id' => (string) $s->getId(), 'name' => $s->getName(),
], $this->specialties->toArray()),
'24_7' => $this->is247,
'24_7' => $this->is247,
'field_working_days' => $this->workingDays,
];
}
}
@@ -83,6 +83,40 @@ class ClinicRepository extends ServiceEntityRepository
];
}
/**
* City/province names for each clinic, taken from the clinic's address
* (DoctorAddress.clinicId). Returns [clinicId => ['city' => ?string, 'state' => ?string]].
*
* @param int[] $clinicIds
* @return array<int, array{city: ?string, state: ?string}>
*/
public function findAddressLocations(array $clinicIds): array
{
if ($clinicIds === []) {
return [];
}
$rows = $this->getEntityManager()->createQueryBuilder()
->select('addr.clinicId AS clinic_id', 'cityCat.name AS city', 'provinceCat.name AS state')
->from(DoctorAddress::class, 'addr')
->leftJoin('addr.city', 'cityCat')
->leftJoin('addr.province', 'provinceCat')
->where('addr.clinicId IN (:ids)')
->setParameter('ids', $clinicIds)
->getQuery()
->getResult();
$map = [];
foreach ($rows as $row) {
$id = (int) $row['clinic_id'];
if (!isset($map[$id])) {
$map[$id] = ['city' => $row['city'], 'state' => $row['state']];
}
}
return $map;
}
public function save(Clinic $clinic, bool $flush = true): void
{
$this->getEntityManager()->persist($clinic);