Files
clinicpro/src/Doctor/Entity/Doctor.php
T
hamed de1a78a235 feat: Implement SMS sending functionality with KavehNegar and Rangineh providers
- Add SendSmsMessage class for encapsulating SMS message data.
- Create KavehNegarProvider and RanginehProvider classes implementing SmsProviderInterface for sending SMS.
- Implement SmsLogRepository and SmsTemplateRepository for managing SMS logs and templates.
- Develop SendSmsHandler for handling SMS sending messages.
- Create SmsService to manage SMS dispatching and logging.
- Add UserProfileController for managing user profiles with CRUD operations.
- Implement UserProfile entity and repository for user profile data management.
- Update symfony.lock and bootstrap.php for project dependencies and environment setup.
2026-06-09 22:00:34 +03:30

233 lines
10 KiB
PHP

<?php
namespace App\Doctor\Entity;
use App\Auth\Entity\User;
use App\Category\Entity\Category;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
use Doctrine\ORM\Mapping as ORM;
use Symfony\Component\Uid\Uuid;
#[ORM\Entity]
#[ORM\Table(name: 'doctors')]
#[ORM\UniqueConstraint(name: 'idx_doctors_user', columns: ['user_id'])]
#[ORM\Index(columns: ['active_doctor_appointment'], name: 'idx_doctors_active')]
class Doctor
{
public const DEGREES = ['expert', 'general', 'specialist', 'subspecialistplus'];
public const GENDERS = ['man', 'woman'];
#[ORM\Id]
#[ORM\GeneratedValue]
#[ORM\Column(type: 'integer')]
private ?int $id = null;
#[ORM\Column(type: 'string', length: 36, unique: true)]
private string $uuid;
#[ORM\OneToOne(targetEntity: User::class)]
#[ORM\JoinColumn(name: 'user_id', referencedColumnName: 'id', nullable: false)]
private User $user;
#[ORM\Column(type: 'string', length: 255)]
private string $name;
#[ORM\Column(type: 'string', length: 10, nullable: true)]
private ?string $gender = null;
#[ORM\Column(name: 'medical_system_code', type: 'string', length: 25, nullable: true)]
private ?string $medicalSystemCode = null;
#[ORM\Column(name: 'mobile_number', type: 'string', length: 15, nullable: true)]
private ?string $mobileNumber = null;
#[ORM\Column(name: 'activity_time', type: 'integer', nullable: true)]
private ?int $activityTime = null;
#[ORM\Column(type: 'string', length: 30, nullable: true)]
private ?string $degree = null;
#[ORM\Column(type: 'text', nullable: true)]
private ?string $info = null;
#[ORM\Column(type: 'json', nullable: true)]
private ?array $images = null;
#[ORM\Column(name: 'doctor_rate', type: 'float')]
private float $doctorRate = 3.5;
#[ORM\Column(name: 'doctor_rate_percentage', type: 'float')]
private float $doctorRatePercentage = 60.0;
#[ORM\Column(name: 'active_doctor_appointment', type: 'boolean')]
private bool $activeDoctorAppointment = true;
#[ORM\Column(name: 'representation_id', type: 'integer', nullable: true)]
private ?int $representationId = null;
#[ORM\Column(name: 'created_at', type: 'integer')]
private int $createdAt;
#[ORM\Column(name: 'updated_at', type: 'integer')]
private int $updatedAt;
#[ORM\ManyToMany(targetEntity: Category::class)]
#[ORM\JoinTable(
name: 'doctor_specialties',
joinColumns: [new ORM\JoinColumn(name: 'doctor_id', referencedColumnName: 'id')],
inverseJoinColumns: [new ORM\JoinColumn(name: 'category_id', referencedColumnName: 'id')]
)]
private Collection $specialties;
#[ORM\ManyToMany(targetEntity: Category::class)]
#[ORM\JoinTable(
name: 'doctor_expertise',
joinColumns: [new ORM\JoinColumn(name: 'doctor_id', referencedColumnName: 'id')],
inverseJoinColumns: [new ORM\JoinColumn(name: 'category_id', referencedColumnName: 'id')]
)]
private Collection $expertise;
#[ORM\ManyToMany(targetEntity: Category::class)]
#[ORM\JoinTable(
name: 'doctor_states',
joinColumns: [new ORM\JoinColumn(name: 'doctor_id', referencedColumnName: 'id')],
inverseJoinColumns: [new ORM\JoinColumn(name: 'category_id', referencedColumnName: 'id')]
)]
private Collection $states;
#[ORM\ManyToMany(targetEntity: Category::class)]
#[ORM\JoinTable(
name: 'doctor_cities',
joinColumns: [new ORM\JoinColumn(name: 'doctor_id', referencedColumnName: 'id')],
inverseJoinColumns: [new ORM\JoinColumn(name: 'category_id', referencedColumnName: 'id')]
)]
private Collection $cities;
#[ORM\OneToMany(targetEntity: DoctorAddress::class, mappedBy: 'doctor', cascade: ['remove'])]
private Collection $addresses;
public function __construct(User $user, string $name)
{
$this->uuid = Uuid::v4()->toRfc4122();
$this->user = $user;
$this->name = $name;
$this->createdAt = time();
$this->updatedAt = time();
$this->specialties = new ArrayCollection();
$this->expertise = new ArrayCollection();
$this->states = new ArrayCollection();
$this->cities = new ArrayCollection();
$this->addresses = new ArrayCollection();
}
public function getId(): ?int { return $this->id; }
public function getUuid(): string { return $this->uuid; }
public function getUser(): User { return $this->user; }
public function getName(): string { return $this->name; }
public function getGender(): ?string { return $this->gender; }
public function getMedicalSystemCode(): ?string { return $this->medicalSystemCode; }
public function getMobileNumber(): ?string { return $this->mobileNumber; }
public function getActivityTime(): ?int { return $this->activityTime; }
public function getDegree(): ?string { return $this->degree; }
public function getInfo(): ?string { return $this->info; }
public function getImages(): ?array { return $this->images; }
public function getDoctorRate(): float { return $this->doctorRate; }
public function getDoctorRatePercentage(): float { return $this->doctorRatePercentage; }
public function isActiveDoctorAppointment(): bool { return $this->activeDoctorAppointment; }
public function getRepresentationId(): ?int { return $this->representationId; }
public function getCreatedAt(): int { return $this->createdAt; }
public function getUpdatedAt(): int { return $this->updatedAt; }
public function getSpecialties(): Collection { return $this->specialties; }
public function getExpertise(): Collection { return $this->expertise; }
public function getStates(): Collection { return $this->states; }
public function getCities(): Collection { return $this->cities; }
public function getAddresses(): Collection { return $this->addresses; }
public function setName(string $v): self { $this->name = $v; return $this; }
public function setGender(?string $v): self { $this->gender = $v; $this->touch(); return $this; }
public function setMedicalSystemCode(?string $v): self { $this->medicalSystemCode = $v; $this->touch(); return $this; }
public function setMobileNumber(?string $v): self { $this->mobileNumber = $v; $this->touch(); return $this; }
public function setActivityTime(?int $v): self { $this->activityTime = $v; $this->touch(); return $this; }
public function setDegree(?string $v): self { $this->degree = $v; $this->touch(); return $this; }
public function setInfo(?string $v): self { $this->info = $v; $this->touch(); return $this; }
public function setImages(?array $v): self { $this->images = $v; $this->touch(); return $this; }
public function setDoctorRate(float $v): self { $this->doctorRate = $v; $this->touch(); return $this; }
public function setDoctorRatePercentage(float $v): self { $this->doctorRatePercentage = $v; $this->touch(); return $this; }
public function setActiveDoctorAppointment(bool $v): self { $this->activeDoctorAppointment = $v; $this->touch(); return $this; }
public function setRepresentationId(?int $v): self { $this->representationId = $v; $this->touch(); return $this; }
private function touch(): void { $this->updatedAt = time(); }
public function getExperience(): int
{
if ($this->activityTime === null) {
return 0;
}
return max(0, (int)((time() - $this->activityTime) / (365.25 * 24 * 3600)));
}
public function toListArray(): array
{
return [
'id' => (string) $this->id,
'uuid' => $this->uuid,
'name' => $this->name,
'gender' => $this->gender,
'degree' => $this->degree,
'img' => $this->images ?? [],
'specialties' => $this->formatCategories($this->specialties),
'satisfaction' => (string) $this->doctorRatePercentage,
'point' => (string) $this->doctorRate,
'free_turn' => 'نوبت آزادی موجود نیست',
'hours_of_work' => 'برنامه کاری تنظیم نشده',
'active' => $this->activeDoctorAppointment,
];
}
public function toDetailArray(): array
{
return [
'id' => (string) $this->id,
'uuid' => $this->uuid,
'name' => $this->name,
'gender' => $this->gender,
'experience' => $this->getExperience(),
'activity_time' => $this->activityTime !== null ? (string) $this->activityTime : null,
'medical_system_code' => $this->medicalSystemCode,
'detail' => $this->info,
'degree' => $this->degree,
'specialties' => $this->formatCategories($this->specialties),
'img' => $this->images ?? [],
'expertise' => $this->formatCategories($this->expertise),
'satisfaction' => (string) $this->doctorRatePercentage,
'point' => (string) $this->doctorRate,
'free_turn' => 'نوبت آزادی موجود نیست',
'hours_of_work' => 'برنامه کاری تنظیم نشده',
'address' => array_map(fn(DoctorAddress $a) => $a->toArray(), $this->addresses->toArray()),
'average_rate' => ['total_rates' => null],
'state' => $this->formatCategories($this->states),
'city' => $this->formatCategoriesWithParent($this->cities),
];
}
private function formatCategories(Collection $collection): array
{
return array_map(fn(Category $c) => [
'uuid' => $c->getUuid(),
'id' => (string) $c->getId(),
'name' => $c->getLabel(),
], $collection->toArray());
}
private function formatCategoriesWithParent(Collection $collection): array
{
return array_map(fn(Category $c) => [
'uuid' => $c->getUuid(),
'id' => (string) $c->getId(),
'name' => $c->getLabel(),
'parent' => $c->getParentId() !== null ? (string) $c->getParentId() : null,
], $collection->toArray());
}
}