<?php
namespace App\Entity;
use App\Repository\PatientRepository;
use Boab\CmsBundle\Entity\User;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
use Doctrine\ORM\Mapping as ORM;
#[ORM\Entity(repositoryClass: PatientRepository::class)]
class Patient extends User implements PatientInterface
{
const ROLE_DEFAULT = 'ROLE_PATIENT';
const USER_TYPE = "patient";
#[ORM\OneToMany(mappedBy: 'client', targetEntity: Appointment::class)]
private Collection $appointments;
#[ORM\OneToMany(mappedBy: 'createdBy', targetEntity: Review::class)]
private Collection $reviews;
public function __construct()
{
parent::__construct();
$this->appointments = new ArrayCollection();
$this->reviews = new ArrayCollection();
}
use UserTrait;
/**
* Get role
*
* @return array
*/
public function getRoles():array
{
return array_unique(array_merge(parent::getRoles(), [self::ROLE_DEFAULT]));
}
/**
* @return Collection<int, Appointment>
*/
public function getAppointments(): Collection
{
return $this->appointments;
}
public function addAppointment(Appointment $appointment): self
{
if (!$this->appointments->contains($appointment)) {
$this->appointments->add($appointment);
$appointment->setClient($this);
}
return $this;
}
public function removeAppointment(Appointment $appointment): self
{
if ($this->appointments->removeElement($appointment)) {
// set the owning side to null (unless already changed)
if ($appointment->getClient() === $this) {
$appointment->setClient(null);
}
}
return $this;
}
/**
* @return Collection<int, Review>
*/
public function getReviews(): Collection
{
return $this->reviews;
}
public function addReview(Review $review): static
{
if (!$this->reviews->contains($review)) {
$this->reviews->add($review);
$review->setCreatedBy($this);
}
return $this;
}
public function removeReview(Review $review): static
{
if ($this->reviews->removeElement($review)) {
// set the owning side to null (unless already changed)
if ($review->getCreatedBy() === $this) {
$review->setCreatedBy(null);
}
}
return $this;
}
public function getUserType(): string
{
return 'Client';
}
public function getWhatsappFormatNumber(): ?string
{
$phone_number = ltrim($this->whatsappNumber, '0');
// Prepend '233' if not already present
if (strpos($phone_number, '233') !== 0) {
$phone_number = '233' . $phone_number;
}
return $phone_number;
}
}