feat: enhance DoctorAddress entity to support clinic addresses and types
- Added `clinic_id` and `type` fields to `DoctorAddress` entity to differentiate between personal and clinic addresses. - Updated constructor to support creation of addresses for both doctors and clinics. - Modified repository methods to handle new address types and added methods for counting and finding addresses by clinic. - Implemented migration to update the database schema accordingly. - Removed deprecated endpoint for creating addresses from clinics and updated related controller methods. - Added new endpoints for managing clinic addresses, including CRUD operations. - Updated frontend components to handle new address types and display accordingly.
This commit is contained in:
@@ -10,8 +10,12 @@ use Symfony\Component\Uid\Uuid;
|
||||
#[ORM\Entity]
|
||||
#[ORM\Table(name: 'doctor_addresses')]
|
||||
#[ORM\Index(columns: ['doctor_id'], name: 'idx_doctor_addresses_doctor')]
|
||||
#[ORM\Index(columns: ['clinic_id'], name: 'idx_doctor_addr_clinic')]
|
||||
class DoctorAddress
|
||||
{
|
||||
public const TYPE_PERSONAL = 'personal';
|
||||
public const TYPE_CLINIC = 'clinic';
|
||||
|
||||
#[ORM\Id]
|
||||
#[ORM\GeneratedValue]
|
||||
#[ORM\Column(type: 'integer')]
|
||||
@@ -21,8 +25,14 @@ class DoctorAddress
|
||||
private string $uuid;
|
||||
|
||||
#[ORM\ManyToOne(targetEntity: Doctor::class, inversedBy: 'addresses')]
|
||||
#[ORM\JoinColumn(name: 'doctor_id', referencedColumnName: 'id', nullable: false, onDelete: 'CASCADE')]
|
||||
private Doctor $doctor;
|
||||
#[ORM\JoinColumn(name: 'doctor_id', referencedColumnName: 'id', nullable: true, onDelete: 'CASCADE')]
|
||||
private ?Doctor $doctor = null;
|
||||
|
||||
#[ORM\Column(name: 'clinic_id', type: 'integer', nullable: true)]
|
||||
private ?int $clinicId = null;
|
||||
|
||||
#[ORM\Column(type: 'string', length: 10)]
|
||||
private string $type = self::TYPE_PERSONAL;
|
||||
|
||||
#[ORM\Column(type: 'string', length: 255, nullable: true)]
|
||||
private ?string $name = null;
|
||||
@@ -53,23 +63,40 @@ class DoctorAddress
|
||||
#[ORM\Column(name: 'updated_at', type: 'integer')]
|
||||
private int $updatedAt;
|
||||
|
||||
public function __construct(Doctor $doctor)
|
||||
private function __construct()
|
||||
{
|
||||
$this->uuid = Uuid::v4()->toRfc4122();
|
||||
$this->doctor = $doctor;
|
||||
$this->createdAt = time();
|
||||
$this->updatedAt = time();
|
||||
}
|
||||
|
||||
public function getId(): ?int { return $this->id; }
|
||||
public function getUuid(): string { return $this->uuid; }
|
||||
public function getDoctor(): Doctor { return $this->doctor; }
|
||||
public function getName(): ?string { return $this->name; }
|
||||
public function getAddress(): ?string { return $this->address; }
|
||||
public static function forDoctor(Doctor $doctor): self
|
||||
{
|
||||
$a = new self();
|
||||
$a->type = self::TYPE_PERSONAL;
|
||||
$a->doctor = $doctor;
|
||||
return $a;
|
||||
}
|
||||
|
||||
public static function forClinic(int $clinicId): self
|
||||
{
|
||||
$a = new self();
|
||||
$a->type = self::TYPE_CLINIC;
|
||||
$a->clinicId = $clinicId;
|
||||
return $a;
|
||||
}
|
||||
|
||||
public function getId(): ?int { return $this->id; }
|
||||
public function getUuid(): string { return $this->uuid; }
|
||||
public function getDoctor(): ?Doctor { return $this->doctor; }
|
||||
public function getClinicId(): ?int { return $this->clinicId; }
|
||||
public function getType(): string { return $this->type; }
|
||||
public function getName(): ?string { return $this->name; }
|
||||
public function getAddress(): ?string { return $this->address; }
|
||||
public function getTelephone(): ?string { return $this->telephone; }
|
||||
public function getLatitude(): ?float { return $this->latitude; }
|
||||
public function getLongitude(): ?float { return $this->longitude; }
|
||||
public function getCity(): ?City { return $this->city; }
|
||||
public function getLatitude(): ?float { return $this->latitude; }
|
||||
public function getLongitude(): ?float { return $this->longitude; }
|
||||
public function getCity(): ?City { return $this->city; }
|
||||
public function getProvince(): ?Province { return $this->province; }
|
||||
|
||||
public function setName(?string $v): self { $this->name = $v; return $this; }
|
||||
@@ -85,20 +112,22 @@ class DoctorAddress
|
||||
public function toArray(): array
|
||||
{
|
||||
return [
|
||||
'id' => (string) $this->id,
|
||||
'uuid' => $this->uuid,
|
||||
'name' => $this->name,
|
||||
'map' => [
|
||||
'id' => (string) $this->id,
|
||||
'uuid' => $this->uuid,
|
||||
'type' => $this->type,
|
||||
'clinic_id' => $this->clinicId,
|
||||
'name' => $this->name,
|
||||
'map' => [
|
||||
'latitude' => $this->latitude !== null ? (string) $this->latitude : null,
|
||||
'longitude' => $this->longitude !== null ? (string) $this->longitude : null,
|
||||
],
|
||||
'address' => $this->address,
|
||||
'telephone' => $this->telephone,
|
||||
'city' => $this->city !== null ? [
|
||||
'address' => $this->address,
|
||||
'telephone' => $this->telephone,
|
||||
'city' => $this->city !== null ? [
|
||||
'id' => (string) $this->city->getId(),
|
||||
'name' => $this->city->getName(),
|
||||
] : null,
|
||||
'province' => $this->province !== null ? [
|
||||
'province' => $this->province !== null ? [
|
||||
'id' => (string) $this->province->getId(),
|
||||
'name' => $this->province->getName(),
|
||||
] : null,
|
||||
|
||||
Reference in New Issue
Block a user