feat: enhance clinic API to resolve contact fields from address record and add tests for contact field resolution

This commit is contained in:
hamed
2026-07-19 16:43:57 +03:30
parent cb399ac653
commit 21b67ec075
5 changed files with 146 additions and 18 deletions
+34 -8
View File
@@ -187,20 +187,33 @@ class Clinic
private function touch(): void { $this->updatedAt = time(); }
public function toDetailArray(array $provinceData = [], array $cityData = [], ?array $map = null): array
{
/**
* $street/$telephone come from the clinic's DoctorAddress record. The columns
* on this entity are the deprecated legacy source and are only a fallback:
* mixing the two makes a single response describe two different places.
*/
public function toDetailArray(
array $provinceData = [],
array $cityData = [],
?array $map = null,
?string $street = null,
?string $telephone = null
): array {
$phone = $this->firstFilled($telephone, $this->telephone);
$address = $this->firstFilled($street, $this->address);
return [
'id' => (string) $this->id,
'uuid' => $this->uuid,
'name' => $this->name,
'title' => $this->name,
'is_active' => $this->isActive,
'phone' => $this->telephone,
'phone' => $phone,
'logo' => $this->clinicLogo,
'images_clinic' => $this->imagesClinic ?? [],
'social_media' => $this->socialMedia,
'clinic_logo' => $this->clinicLogo,
'phone_number' => $this->telephone,
'phone_number' => $phone,
'caption' => $this->info,
'list_bime' => array_map(fn(Insurance $i) => [
'uuid' => $i->getUuid(), 'id' => (string) $i->getId(), 'name' => $i->getName(),
@@ -220,7 +233,7 @@ class Clinic
'doctor_list' => null,
'city' => $cityData ? [$cityData] : [],
'state' => $provinceData ? [$provinceData] : [],
'location' => $this->address,
'location' => $address,
'map' => $map ?? [
'latitude' => $this->latitude !== null ? (string) $this->latitude : null,
'longitude' => $this->longitude !== null ? (string) $this->longitude : null,
@@ -230,15 +243,28 @@ class Clinic
];
}
public function toListArray(?string $city = null, ?string $state = null): array
private function firstFilled(?string ...$values): ?string
{
foreach ($values as $value) {
if ($value !== null && trim($value) !== '') {
return $value;
}
}
return null;
}
public function toListArray(?string $city = null, ?string $state = null, ?string $telephone = null): array
{
$phone = $this->firstFilled($telephone, $this->telephone);
return [
'id' => (string) $this->id,
'uuid' => $this->uuid,
'name' => $this->name,
'title' => $this->name,
'phone' => $this->telephone,
'phone_number' => $this->telephone,
'phone' => $phone,
'phone_number' => $phone,
'logo' => $this->clinicLogo,
'clinic_logo' => $this->clinicLogo,
'images_clinic' => $this->imagesClinic ?? [],