<?php
namespace App\Entity;
use App\Repository\LabTestRepository;
use Doctrine\Common\Collections\{ ArrayCollection, Collection };
use Doctrine\ORM\Mapping as ORM;
use Gedmo\Mapping\Annotation as Gedmo;
use Symfony\Component\Validator\Constraints as Assert;
#[ORM\Entity(repositoryClass: LabTestRepository::class), ORM\Table(name: 'lab_tests')]
class LabTest implements \Stringable
{
#[ORM\Id, ORM\GeneratedValue, ORM\Column(type: 'integer')]
private $id;
#[ORM\Column(type: 'string', length: 255), Assert\NotBlank]
#[Assert\Length(
min: 2,
max: 20,
minMessage: 'Lab test name must be at least {{ limit }} characters long',
maxMessage: 'Lab test name cannot be longer than {{ limit }} characters'
)]
#[Assert\Regex(
pattern: '/\d/',
match: false,
message: 'Lab test name cannot contain a number'
)]
private $name;
#[ORM\Column(type: 'boolean')]
private bool $isActive = true;
#[ORM\Column(type: 'string', length: 255, nullable: true)]
private $resultUnit;
#[ORM\Column(type: 'string', length: 255, nullable: true)]
private $normalRange;
#[ORM\OneToMany(targetEntity: LabTestMethod::class, mappedBy: 'method', orphanRemoval: true)]
private $methods;
#[ORM\Column(type: 'boolean')]
private bool $isGeneral = false;
#[ORM\Column(type: 'boolean')]
private bool $isUserDefined = false;
#[ORM\Column(type: 'string', nullable: false, columnDefinition: "enum('Biochemistry', 'Pathology', 'Microbiology', 'Radiology')")]
#[Assert\NotBlank]
private $labType;
#[Gedmo\Blameable(on: 'create'), ORM\ManyToOne(targetEntity: User::class), ORM\JoinColumn(name: 'created_by')]
private $createdBy;
#[Gedmo\Timestampable(on: 'create'), ORM\Column(type: 'datetime')]
private $createdAt;
#[Gedmo\Timestampable(on: 'update'), ORM\Column(type: 'datetime')]
private $updatedAt;
public function __construct()
{
$this->methods = new ArrayCollection();
}
public function getId(): ?int
{
return $this->id;
}
public function getName(): ?string
{
return $this->name;
}
public function setName(string $name): self
{
$this->name = $name;
return $this;
}
public function getIsActive(): ?bool
{
return $this->isActive;
}
public function setIsActive(bool $isActive): self
{
$this->isActive = $isActive;
return $this;
}
public function getResultUnit(): ?string
{
return $this->resultUnit;
}
public function setResultUnit(string $resultUnit): self
{
$this->resultUnit = $resultUnit;
return $this;
}
public function getNormalRange(): ?string
{
return $this->normalRange;
}
public function setNormalRange(string $normalRange): self
{
$this->normalRange = $normalRange;
return $this;
}
public function getMethods(): Collection
{
return $this->methods;
}
public function getIsGeneral(): ?bool
{
return $this->isGeneral;
}
public function setIsGeneral(bool $isGeneral): self
{
$this->isGeneral = $isGeneral;
return $this;
}
public function getIsUserDefined(): ?bool
{
return $this->isUserDefined;
}
public function setIsUserDefined(bool $isUserDefined): self
{
$this->isUserDefined = $isUserDefined;
return $this;
}
public function getLabType(): ?string
{
return $this->labType;
}
public function setLabType(string $labType): self
{
$this->labType = $labType;
return $this;
}
public function getCreatedBy(): ?User
{
return $this->createdBy;
}
public function getCreatedAt(): ?\DateTimeInterface
{
return $this->createdAt;
}
public function getUpdatedAt(): ?\DateTimeInterface
{
return $this->updatedAt;
}
public function addMethod(LabTestMethod $method): self
{
if (!$this->methods->contains($method)) {
$this->methods[] = $method;
$method->setTest($this);
}
return $this;
}
public function removeMethod(LabTestMethod $method): self
{
if ($this->methods->removeElement($method)) {
if ($method->getTest() === $this) {
$method->setMethod(null);
}
}
return $this;
}
public function __toString(): string
{
return $this->getName();
}
}