src/Entity/ChronologyRequest.php line 28

Open in your IDE?
  1. <?php
  2. namespace MedBrief\MSR\Entity;
  3. use DateTime;
  4. use DH\Auditor\Provider\Doctrine\Auditing\Annotation as Audit;
  5. use Doctrine\Common\Collections\ArrayCollection;
  6. use Doctrine\Common\Collections\Collection;
  7. use Doctrine\ORM\Mapping as ORM;
  8. use Gedmo\Mapping\Annotation as Gedmo;
  9. use MedBrief\MSR\Entity\Serviceable\ServiceableInterface;
  10. use MedBrief\MSR\Entity\Serviceable\ServiceableTrait;
  11. use MedBrief\MSR\Traits\FilterableClassConstantsTrait;
  12. /**
  13. * @ORM\Table(name="ChronologyRequest")
  14. *
  15. * @ORM\Entity
  16. *
  17. * @ORM\HasLifecycleCallbacks
  18. *
  19. * @Gedmo\SoftDeleteable(fieldName="deletedAt", timeAware=false)
  20. *
  21. * @Audit\Auditable
  22. *
  23. * @Audit\Security(view={"ROLE_ALLOWED_TO_AUDIT"})
  24. */
  25. class ChronologyRequest implements ServiceableInterface
  26. {
  27. use ServiceableTrait;
  28. use FilterableClassConstantsTrait;
  29. // chronologyType constants
  30. public const CHRONOLOGY_TYPE_DETAILED = 1;
  31. public const CHRONOLOGY_TYPE_SUMMARY = 2;
  32. // extensionRequestStatus constants
  33. public const EXTENSION_REQUEST_STATUS_REQUESTED = 'requested';
  34. public const EXTENSION_REQUEST_STATUS_REQUESTED__LABEL = 'Requested';
  35. public const EXTENSION_REQUEST_STATUS_APPROVED = 'approved';
  36. public const EXTENSION_REQUEST_STATUS_APPROVED__LABEL = 'Approved';
  37. public const EXTENSION_REQUEST_STATUS_DECLINED = 'declined';
  38. public const EXTENSION_REQUEST_STATUS_DECLINED__LABEL = 'Declined';
  39. /**
  40. * @var ServiceRequest
  41. *
  42. * @ORM\OneToOne(targetEntity="MedBrief\MSR\Entity\ServiceRequest", mappedBy="chronologyRequest", cascade={"persist"})
  43. */
  44. protected $serviceRequest;
  45. /**
  46. * @var int
  47. *
  48. * @ORM\Column(name="id", type="integer")
  49. *
  50. * @ORM\Id
  51. *
  52. * @ORM\GeneratedValue(strategy="IDENTITY")
  53. */
  54. protected $id;
  55. /**
  56. * @deprecated 2023.12.01
  57. *
  58. * @var int|null
  59. *
  60. * @ORM\Column(name="chronologyType", type="integer", nullable=true)
  61. */
  62. protected $chronologyType;
  63. /**
  64. * @var bool|null
  65. *
  66. * @ORM\Column(name="isUpdate", type="boolean", nullable=true)
  67. */
  68. protected $isUpdate;
  69. /**
  70. * @var DateTime|null
  71. *
  72. * @ORM\Column(name="dateUploaded", type="date", nullable=true)
  73. */
  74. protected $dateUploaded;
  75. /**
  76. * @var DateTime|null
  77. *
  78. * @ORM\Column(name="dateSupplierInstructed", type="date", nullable=true)
  79. */
  80. protected $dateSupplierInstructed;
  81. /**
  82. * @var DateTime|null
  83. *
  84. * @ORM\Column(name="dateSupplierAccepted", type="date", nullable=true)
  85. */
  86. protected $dateSupplierAccepted;
  87. /**
  88. * @var DateTime|null
  89. *
  90. * @ORM\Column(name="dateStarted", type="date", nullable=true)
  91. */
  92. protected $dateStarted;
  93. /**
  94. * @var DateTime|null
  95. *
  96. * @ORM\Column(name="dateDue", type="date", nullable=true)
  97. */
  98. protected $dateDue;
  99. /**
  100. * @var string|null
  101. *
  102. * @ORM\Column(name="timeAllowed", type="decimal", precision=7, scale=2, nullable=true)
  103. */
  104. protected $timeAllowed;
  105. // Not sure how to represent this figure
  106. /**
  107. * @var string|null
  108. *
  109. * @ORM\Column(name="timeToComplete", type="decimal", precision=7, scale=2, nullable=true)
  110. */
  111. protected $timeToComplete;
  112. /**
  113. * @var string|null
  114. *
  115. * @ORM\Column(name="extensionLength", type="decimal", precision=7, scale=2, nullable=true)
  116. */
  117. protected $extensionLength;
  118. /**
  119. * @var DateTime
  120. *
  121. * @ORM\Column(name="created", type="datetime")
  122. *
  123. * @Gedmo\Timestampable(on="create")
  124. */
  125. protected $created;
  126. /**
  127. * @var User|null
  128. *
  129. * @ORM\ManyToOne(targetEntity="MedBrief\MSR\Entity\User")
  130. *
  131. * @ORM\JoinColumns({
  132. *
  133. * @ORM\JoinColumn(name="releasedBy_id", referencedColumnName="id", nullable=true)
  134. * })
  135. */
  136. protected $releasedBy;
  137. /**
  138. * @var DateTime|null
  139. *
  140. * @ORM\Column(name="releasedDate", type="datetime", nullable=true)
  141. */
  142. protected $releasedDate;
  143. /**
  144. * @var DateTime
  145. *
  146. * @ORM\Column(name="updated", type="datetime")
  147. *
  148. * @Gedmo\Timestampable(on="update")
  149. */
  150. protected $updated;
  151. /**
  152. * @var DateTime|null
  153. *
  154. * @ORM\Column(name="deletedAt", type="datetime", nullable=true)
  155. */
  156. protected $deletedAt;
  157. /**
  158. * @var Project
  159. *
  160. * @ORM\ManyToOne(targetEntity="MedBrief\MSR\Entity\Project", inversedBy="chronologyRequests")
  161. *
  162. * @ORM\JoinColumns({
  163. *
  164. * @ORM\JoinColumn(name="project_id", referencedColumnName="id")
  165. * })
  166. */
  167. protected $project;
  168. /**
  169. * @var ArrayCollection
  170. *
  171. * @ORM\OneToMany(targetEntity="MedBrief\MSR\Entity\BatchRequest", mappedBy="chronologyRequest", cascade={"persist"})
  172. */
  173. protected $batches;
  174. /**
  175. * @var HumanResource
  176. *
  177. * @ORM\ManyToOne(targetEntity="MedBrief\MSR\Entity\HumanResource")
  178. *
  179. * @ORM\JoinColumns({
  180. *
  181. * @ORM\JoinColumn(name="supplierResourceInstructed_id", referencedColumnName="id")
  182. * })
  183. */
  184. protected $supplierResourceInstructed;
  185. /**
  186. * @var HumanResource
  187. *
  188. * @ORM\ManyToOne(targetEntity="MedBrief\MSR\Entity\HumanResource")
  189. *
  190. * @ORM\JoinColumns({
  191. *
  192. * @ORM\JoinColumn(name="supplier_id", referencedColumnName="id")
  193. * })
  194. */
  195. protected $supplier;
  196. /**
  197. * @var HumanResource
  198. *
  199. * @ORM\ManyToOne(targetEntity="MedBrief\MSR\Entity\HumanResource")
  200. *
  201. * @ORM\JoinColumns({
  202. *
  203. * @ORM\JoinColumn(name="templateBy_id", referencedColumnName="id")
  204. * })
  205. */
  206. protected $templateBy;
  207. /**
  208. * @var int|null
  209. *
  210. * @ORM\Column(name="claimCategory", type="integer", nullable=true)
  211. */
  212. protected $claimCategory;
  213. /**
  214. * @var string|null
  215. *
  216. * @ORM\Column(name="claimCategoryOther", type="string", length=255, nullable=true)
  217. */
  218. protected $claimCategoryOther;
  219. /**
  220. * @var string|null
  221. *
  222. * @ORM\Column(name="extensionRequestStatus", type="string", length=24, nullable=true)
  223. */
  224. protected $extensionRequestStatus;
  225. /**
  226. * @var bool
  227. *
  228. * @ORM\Column(name="scheduleOfRadiologyCompleted", type="boolean", options={"default"=false})
  229. */
  230. protected $scheduleOfRadiologyCompleted = false;
  231. /**
  232. * @var string|null
  233. *
  234. * @ORM\Column(name="scheduleOfRadiologyTime", type="decimal", precision=7, scale=2, nullable=true)
  235. */
  236. protected $scheduleOfRadiologyTime;
  237. /**
  238. * @var string|null
  239. *
  240. * @ORM\Column(name="qaTime", type="decimal", precision=7, scale=2, nullable=true)
  241. */
  242. protected $qaTime;
  243. /**
  244. * @var ArrayCollection
  245. *
  246. * @ORM\OneToMany(targetEntity="MedBrief\MSR\Entity\ChronologyRequestDetail", mappedBy="chronologyRequest")
  247. */
  248. protected $details;
  249. /**
  250. * @var bool
  251. *
  252. * @ORM\Column(name="isUrgent", type="boolean", options={"default": false})
  253. */
  254. protected bool $isUrgent = false;
  255. /**
  256. * Constructor
  257. */
  258. public function __construct()
  259. {
  260. $this->batches = new ArrayCollection();
  261. $this->details = new ArrayCollection();
  262. }
  263. /**
  264. * __toString
  265. *
  266. * @return string
  267. */
  268. public function __toString()
  269. {
  270. return (string) $this->getId();
  271. }
  272. /**
  273. * Get id
  274. *
  275. * @return int
  276. */
  277. public function getId(): ?int
  278. {
  279. return $this->id;
  280. }
  281. /**
  282. * Set chronologyType
  283. *
  284. * @param int|null $chronologyType
  285. *
  286. * @return ChronologyRequest
  287. */
  288. public function setChronologyType(?int $chronologyType = null): self
  289. {
  290. $this->chronologyType = $chronologyType;
  291. return $this;
  292. }
  293. /**
  294. * Get chronologyType
  295. *
  296. * @return int|null
  297. */
  298. public function getChronologyType(): ?int
  299. {
  300. return $this->chronologyType;
  301. }
  302. /**
  303. * Get reasonForCancellationOptions
  304. *
  305. * @return array
  306. */
  307. public static function getChronologyTypeOptions()
  308. {
  309. return [
  310. self::CHRONOLOGY_TYPE_DETAILED => 'Detailed',
  311. self::CHRONOLOGY_TYPE_SUMMARY => 'Summary',
  312. ];
  313. }
  314. /**
  315. * Get reasonForCancellationLabel
  316. *
  317. * @return int
  318. */
  319. public function getChronologyTypeLabel()
  320. {
  321. $options = self::getChronologyTypeOptions();
  322. return $options[$this->getChronologyType()] ?? '';
  323. }
  324. /**
  325. * Set isUpdate
  326. *
  327. * @param bool $isUpdate
  328. *
  329. * @return ChronologyRequest
  330. */
  331. public function setIsUpdate($isUpdate)
  332. {
  333. $this->isUpdate = $isUpdate;
  334. return $this;
  335. }
  336. /**
  337. * Get isUpdate
  338. *
  339. * @return bool
  340. */
  341. public function getIsUpdate()
  342. {
  343. return $this->isUpdate;
  344. }
  345. /**
  346. * Set isUrgent
  347. *
  348. * @param bool $isUrgent
  349. *
  350. * @return self
  351. */
  352. public function setIsUrgent(bool $isUrgent): self
  353. {
  354. $this->isUrgent = $isUrgent;
  355. return $this;
  356. }
  357. /**
  358. * Get isUrgent
  359. *
  360. * @return bool
  361. */
  362. public function getIsUrgent(): bool
  363. {
  364. return $this->isUrgent;
  365. }
  366. /**
  367. * Get isUrgentLabel
  368. *
  369. * @return string
  370. */
  371. public function getIsUrgentLabel(): string
  372. {
  373. return $this->isUrgent ? 'Yes' : 'No';
  374. }
  375. /**
  376. * Get isUpdateLabel
  377. *
  378. * @return string
  379. */
  380. public function getIsUpdateLabel(): string
  381. {
  382. return $this->isUpdate ? 'Update' : 'New';
  383. }
  384. /**
  385. * Get isUpdateOptions
  386. *
  387. * @return array
  388. */
  389. public static function getIsUpdateOptions()
  390. {
  391. return [
  392. 'New' => false,
  393. 'Update' => true,
  394. ];
  395. }
  396. /**
  397. * Set dateUploaded
  398. *
  399. * @param DateTime $dateUploaded
  400. *
  401. * @return ChronologyRequest
  402. */
  403. public function setDateUploaded($dateUploaded)
  404. {
  405. $this->dateUploaded = $dateUploaded;
  406. return $this;
  407. }
  408. /**
  409. * Get dateUploaded
  410. *
  411. * @return DateTime
  412. */
  413. public function getDateUploaded()
  414. {
  415. return $this->dateUploaded;
  416. }
  417. /**
  418. * Calculates the dateUploaded as the current date.
  419. * Keep in separate function in case more calculation needs to be applied.
  420. *
  421. * @return DateTime
  422. */
  423. public function calculateDateUploaded(): DateTime
  424. {
  425. return new DateTime();
  426. }
  427. /**
  428. * Set dateSupplierInstructed
  429. *
  430. * @param DateTime $dateSupplierInstructed
  431. *
  432. * @return ChronologyRequest
  433. */
  434. public function setDateSupplierInstructed($dateSupplierInstructed)
  435. {
  436. $this->dateSupplierInstructed = $dateSupplierInstructed;
  437. return $this;
  438. }
  439. /**
  440. * Get dateSupplierInstructed
  441. *
  442. * @return DateTime
  443. */
  444. public function getDateSupplierInstructed()
  445. {
  446. return $this->dateSupplierInstructed;
  447. }
  448. /**
  449. * Calculates the dateSupplierInstructed as the current date.
  450. * Keep in separate function in case more calculation needs to be applied.
  451. *
  452. * @return DateTime
  453. */
  454. public function calculateDateSupplierInstructed(): DateTime
  455. {
  456. return new DateTime();
  457. }
  458. /**
  459. * Set dateSupplierAccepted
  460. *
  461. * @param DateTime $dateSupplierAccepted
  462. *
  463. * @return ChronologyRequest
  464. */
  465. public function setDateSupplierAccepted($dateSupplierAccepted)
  466. {
  467. $this->dateSupplierAccepted = $dateSupplierAccepted;
  468. return $this;
  469. }
  470. /**
  471. * Get dateSupplierAccepted
  472. *
  473. * @return DateTime
  474. */
  475. public function getDateSupplierAccepted()
  476. {
  477. return $this->dateSupplierAccepted;
  478. }
  479. /**
  480. * Set dateStarted
  481. *
  482. * @param DateTime $dateStarted
  483. *
  484. * @return ChronologyRequest
  485. */
  486. public function setDateStarted($dateStarted)
  487. {
  488. $this->dateStarted = $dateStarted;
  489. return $this;
  490. }
  491. /**
  492. * Get dateStarted
  493. *
  494. * @return DateTime
  495. */
  496. public function getDateStarted()
  497. {
  498. return $this->dateStarted;
  499. }
  500. /**
  501. * Calculates the dateStarted as the current date.
  502. * Keep in separate function in case more calculation needs to be applied.
  503. *
  504. * @return DateTime
  505. */
  506. public function calculateDateStarted(): DateTime
  507. {
  508. return new DateTime();
  509. }
  510. /**
  511. * Set dateDue
  512. *
  513. * @param DateTime $dateDue
  514. *
  515. * @return ChronologyRequest
  516. */
  517. public function setDateDue($dateDue)
  518. {
  519. $this->dateDue = $dateDue;
  520. return $this;
  521. }
  522. /**
  523. * Get dateDue
  524. *
  525. * @return DateTime
  526. */
  527. public function getDateDue()
  528. {
  529. return $this->dateDue;
  530. }
  531. /**
  532. * Calculates the dateDue based on the ServiceOption selected.
  533. *
  534. * @return DateTime
  535. */
  536. public function calculateDateDue(): DateTime
  537. {
  538. $serviceOption = $this->getServiceOption();
  539. $dayOffset = 10;
  540. if ($serviceOption) {
  541. switch ($serviceOption->getAppliesToSubCategory()) {
  542. case ServiceOption::APPLIES_TO_SUB_CATEGORY_CHRON:
  543. case ServiceOption::APPLIES_TO_SUB_CATEGORY_CHRON_SOR:
  544. $dayOffset = 15;
  545. break;
  546. case ServiceOption::APPLIES_TO_SUB_CATEGORY_CLINICAL_SUMMARY:
  547. $dayOffset = 10;
  548. break;
  549. // Even thought the default is 10 days, still noting this explicitly for this sub category.
  550. case ServiceOption::APPLIES_TO_SUB_CATEGORY_SOR:
  551. $dayOffset = 10;
  552. break;
  553. default:
  554. $dayOffset = 10;
  555. break;
  556. }
  557. }
  558. return new DateTime(sprintf('+%1$s weekdays', $dayOffset));
  559. }
  560. /**
  561. * Set timeAllowed
  562. *
  563. * @param int $timeAllowed
  564. *
  565. * @return ChronologyRequest
  566. */
  567. public function setTimeAllowed($timeAllowed)
  568. {
  569. $this->timeAllowed = $timeAllowed;
  570. return $this;
  571. }
  572. /**
  573. * Get timeAllowed
  574. *
  575. * @return int
  576. */
  577. public function getTimeAllowed()
  578. {
  579. return $this->timeAllowed;
  580. }
  581. /**
  582. * Returns the time allowed in hours as a formatted string.
  583. *
  584. * @return string|null
  585. */
  586. public function getTimeAllowedFormatted(): ?string
  587. {
  588. if (!$this->getTimeAllowed()) {
  589. return null;
  590. }
  591. $extensionLengthStr = '';
  592. if ($this->getExtensionRequestStatus() === self::EXTENSION_REQUEST_STATUS_APPROVED) {
  593. $extensionLengthStr = $this->getExtensionLength() ? '+ ' . $this->getExtensionLength() : '';
  594. }
  595. return sprintf('%1$s %3$s Hour%2$s', $this->getTimeAllowed(), $this->getTimeAllowed() > 1 ? 's' : '', $extensionLengthStr);
  596. }
  597. /**
  598. * Set timeToComplete
  599. *
  600. * @param int $timeToComplete
  601. *
  602. * @return ChronologyRequest
  603. */
  604. public function setTimeToComplete($timeToComplete)
  605. {
  606. $this->timeToComplete = $timeToComplete;
  607. return $this;
  608. }
  609. /**
  610. * Get timeToComplete
  611. *
  612. * @return int
  613. */
  614. public function getTimeToComplete()
  615. {
  616. return $this->timeToComplete;
  617. }
  618. /**
  619. * Set extensionLength
  620. *
  621. * @param int $extensionLength
  622. *
  623. * @return ChronologyRequest
  624. */
  625. public function setExtensionLength($extensionLength)
  626. {
  627. $this->extensionLength = $extensionLength;
  628. return $this;
  629. }
  630. /**
  631. * Get extensionLength
  632. *
  633. * @return int
  634. */
  635. public function getExtensionLength()
  636. {
  637. return $this->extensionLength;
  638. }
  639. /**
  640. * Set created
  641. *
  642. * @param DateTime $created
  643. *
  644. * @return ChronologyRequest
  645. */
  646. public function setCreated($created)
  647. {
  648. $this->created = $created;
  649. return $this;
  650. }
  651. /**
  652. * Get created
  653. *
  654. * @return DateTime
  655. */
  656. public function getCreated()
  657. {
  658. return $this->created;
  659. }
  660. /**
  661. * Set releasedBy
  662. *
  663. * @param User|null $releasedBy
  664. *
  665. * @return ChronologyRequest
  666. */
  667. public function setReleasedBy(?User $releasedBy = null)
  668. {
  669. $this->releasedBy = $releasedBy;
  670. return $this;
  671. }
  672. /**
  673. * Get releasedBy
  674. *
  675. * @return User|null
  676. */
  677. public function getReleasedBy(): ?User
  678. {
  679. return $this->releasedBy;
  680. }
  681. /**
  682. * Set releasedDate
  683. *
  684. * @param DateTime|null $releasedDate
  685. *
  686. * @return ChronologyRequest
  687. */
  688. public function setReleasedDate(?DateTime $releasedDate = null)
  689. {
  690. $this->releasedDate = $releasedDate;
  691. return $this;
  692. }
  693. /**
  694. * Get releasedDate
  695. *
  696. * @return DateTime|null
  697. */
  698. public function getReleasedDate(): ?DateTime
  699. {
  700. return $this->releasedDate;
  701. }
  702. /**
  703. * Set updated
  704. *
  705. * @param DateTime $updated
  706. *
  707. * @return ChronologyRequest
  708. */
  709. public function setUpdated($updated)
  710. {
  711. $this->updated = $updated;
  712. return $this;
  713. }
  714. /**
  715. * Get updated
  716. *
  717. * @return DateTime
  718. */
  719. public function getUpdated()
  720. {
  721. return $this->updated;
  722. }
  723. /**
  724. * Set deletedAt
  725. *
  726. * @param DateTime $deletedAt
  727. *
  728. * @return ChronologyRequest
  729. */
  730. public function setDeletedAt($deletedAt)
  731. {
  732. $this->deletedAt = $deletedAt;
  733. return $this;
  734. }
  735. /**
  736. * Get deletedAt
  737. *
  738. * @return DateTime
  739. */
  740. public function getDeletedAt()
  741. {
  742. return $this->deletedAt;
  743. }
  744. /**
  745. * Set project
  746. *
  747. * @param Project $project
  748. *
  749. * @return ChronologyRequest
  750. */
  751. public function setProject(?Project $project = null)
  752. {
  753. $this->project = $project;
  754. // Pre-populate the claim category from the project
  755. if ($this->getProject()) {
  756. $this->setClaimCategory($this->getProject()->getClaimCategory());
  757. } else {
  758. $this->setClaimCategory(null);
  759. }
  760. return $this;
  761. }
  762. /**
  763. * Get project
  764. *
  765. * @return Project
  766. */
  767. public function getProject()
  768. {
  769. return $this->project;
  770. }
  771. /**
  772. * Add batch
  773. *
  774. * @param BatchRequest $batch
  775. *
  776. * @return ChronologyRequest
  777. */
  778. public function addBatch(BatchRequest $batch)
  779. {
  780. $this->batches[] = $batch;
  781. return $this;
  782. }
  783. /**
  784. * Remove batch
  785. *
  786. * @param BatchRequest $batch
  787. */
  788. public function removeBatch(BatchRequest $batch)
  789. {
  790. $this->batches->removeElement($batch);
  791. }
  792. /**
  793. * Get batches
  794. *
  795. * @return Collection
  796. */
  797. public function getBatches()
  798. {
  799. return $this->batches;
  800. }
  801. /**
  802. * Removes all batches linked to this ChronologyRequest.
  803. * Used as a preRemove lifecycle event, to avoid broken relationships when
  804. * soft deleting a ChronologyRequest. Takes the place of a onDelete=NULL database
  805. * call.
  806. *
  807. * @ORM\PreRemove
  808. *
  809. * @return void
  810. */
  811. public function clearBatches()
  812. {
  813. foreach ($this->getBatches() as $batch) {
  814. $batch->setChronologyRequest(null);
  815. }
  816. }
  817. /**
  818. * Set supplierResourceInstructed
  819. *
  820. * @param HumanResource $supplierResourceInstructed
  821. *
  822. * @return ChronologyRequest
  823. */
  824. public function setSupplierResourceInstructed(?HumanResource $supplierResourceInstructed = null)
  825. {
  826. $this->supplierResourceInstructed = $supplierResourceInstructed;
  827. return $this;
  828. }
  829. /**
  830. * Get supplierResourceInstructed
  831. *
  832. * @return HumanResource
  833. */
  834. public function getSupplierResourceInstructed()
  835. {
  836. return $this->supplierResourceInstructed;
  837. }
  838. /**
  839. * Set supplier
  840. *
  841. * @param HumanResource $supplier
  842. *
  843. * @return ChronologyRequest
  844. */
  845. public function setSupplier(?HumanResource $supplier = null)
  846. {
  847. $this->supplier = $supplier;
  848. return $this;
  849. }
  850. /**
  851. * Get supplier
  852. *
  853. * @return HumanResource
  854. */
  855. public function getSupplier()
  856. {
  857. return $this->supplier;
  858. }
  859. /**
  860. * Set templateBy
  861. *
  862. * @param HumanResource $templateBy
  863. *
  864. * @return ChronologyRequest
  865. */
  866. public function setTemplateBy(?HumanResource $templateBy = null)
  867. {
  868. $this->templateBy = $templateBy;
  869. return $this;
  870. }
  871. /**
  872. * Get templateBy
  873. *
  874. * @return HumanResource
  875. */
  876. public function getTemplateBy()
  877. {
  878. return $this->templateBy;
  879. }
  880. /**
  881. * @return int|null
  882. */
  883. public function getClaimCategory(): ?int
  884. {
  885. return $this->claimCategory;
  886. }
  887. /**
  888. * @param int|null $claimCategory
  889. *
  890. * @return self
  891. */
  892. public function setClaimCategory(?int $claimCategory): self
  893. {
  894. $this->claimCategory = $claimCategory;
  895. return $this;
  896. }
  897. /**
  898. * @return string|null
  899. */
  900. public function getClaimCategoryLabel(): ?string
  901. {
  902. if ($this->getClaimCategory() === null) {
  903. return '';
  904. }
  905. $options = Project::getClaimCategoryOptions();
  906. return $options[$this->getClaimCategory()] ?? 'Other';
  907. }
  908. /**
  909. * @return string|null
  910. */
  911. public function getClaimCategoryOther(): ?string
  912. {
  913. return $this->claimCategoryOther;
  914. }
  915. /**
  916. * @param string|null $claimCategoryOther
  917. *
  918. * @return self
  919. */
  920. public function setClaimCategoryOther(?string $claimCategoryOther): self
  921. {
  922. $this->claimCategoryOther = $claimCategoryOther;
  923. return $this;
  924. }
  925. /**
  926. * @return string|null
  927. */
  928. public function getExtensionRequestStatus(): ?string
  929. {
  930. return $this->extensionRequestStatus;
  931. }
  932. /**
  933. * @param string|null $extensionRequestStatus
  934. *
  935. * @return self
  936. */
  937. public function setExtensionRequestStatus(?string $extensionRequestStatus = null): self
  938. {
  939. $this->extensionRequestStatus = $extensionRequestStatus;
  940. return $this;
  941. }
  942. /**
  943. * @return array
  944. */
  945. public static function getExtensionRequestStatusOptions(): array
  946. {
  947. return self::getConstantsWithLabelsAsChoices('EXTENSION_REQUEST_STATUS');
  948. }
  949. /**
  950. * Returns an array of Labels to be readable by humans.
  951. *
  952. * @return string|null
  953. */
  954. public function getExtensionRequestStatusLabel(): ?string
  955. {
  956. if ($this->getExtensionRequestStatus() === null) {
  957. return '';
  958. }
  959. $options = array_flip(self::getExtensionRequestStatusOptions());
  960. return $options[$this->getExtensionRequestStatus()] ?? '';
  961. }
  962. /**
  963. * @return bool|null
  964. */
  965. public function getScheduleOfRadiologyCompleted(): ?bool
  966. {
  967. return $this->scheduleOfRadiologyCompleted;
  968. }
  969. /**
  970. * @param bool $scheduleOfRadiologyCompleted
  971. *
  972. * @return self
  973. */
  974. public function setScheduleOfRadiologyCompleted(bool $scheduleOfRadiologyCompleted): self
  975. {
  976. $this->scheduleOfRadiologyCompleted = $scheduleOfRadiologyCompleted;
  977. return $this;
  978. }
  979. /**
  980. * @return float|null
  981. */
  982. public function getScheduleOfRadiologyTime(): ?float
  983. {
  984. return $this->scheduleOfRadiologyTime;
  985. }
  986. /**
  987. * @param float|null $scheduleOfRadiologyTime
  988. *
  989. * @return self
  990. */
  991. public function setScheduleOfRadiologyTime(?float $scheduleOfRadiologyTime): self
  992. {
  993. $this->scheduleOfRadiologyTime = $scheduleOfRadiologyTime;
  994. return $this;
  995. }
  996. /**
  997. * @return float|null
  998. */
  999. public function getQaTime(): ?float
  1000. {
  1001. return $this->qaTime;
  1002. }
  1003. /**
  1004. * @param float|null $qaTime
  1005. *
  1006. * @return self
  1007. */
  1008. public function setQaTime(?float $qaTime): self
  1009. {
  1010. $this->qaTime = $qaTime;
  1011. return $this;
  1012. }
  1013. /**
  1014. * @return Collection|ChronologyRequestDetail[]
  1015. */
  1016. public function getDetails(): Collection
  1017. {
  1018. return $this->details;
  1019. }
  1020. /**
  1021. * @param ChronologyRequestDetail $detail
  1022. *
  1023. * @return self
  1024. */
  1025. public function addDetail(ChronologyRequestDetail $detail): self
  1026. {
  1027. if (!$this->details->contains($detail)) {
  1028. $this->details[] = $detail;
  1029. $detail->setChronologyRequest($this);
  1030. }
  1031. return $this;
  1032. }
  1033. /**
  1034. * @param ChronologyRequestDetail $detail
  1035. *
  1036. * @return self
  1037. */
  1038. public function removeDetail(ChronologyRequestDetail $detail): self
  1039. {
  1040. if ($this->details->removeElement($detail)) {
  1041. // set the owning side to null (unless already changed)
  1042. if ($detail->getChronologyRequest() === $this) {
  1043. $detail->setChronologyRequest(null);
  1044. }
  1045. }
  1046. return $this;
  1047. }
  1048. /**
  1049. * @return float
  1050. */
  1051. public function getTotalTime(): float
  1052. {
  1053. $serviceOption = $this->getServiceOption();
  1054. if (!$serviceOption) {
  1055. return 0;
  1056. }
  1057. $timeToComplete = $this->getTimeToComplete() ?? 0;
  1058. $scheduleOfRadiologyTime = $this->getScheduleOfRadiologyTime() ?? 0;
  1059. $qaTime = $this->getQaTime() ?? 0;
  1060. switch ($serviceOption->getAppliesToSubCategory()) {
  1061. case ServiceOption::APPLIES_TO_SUB_CATEGORY_CHRON:
  1062. case ServiceOption::APPLIES_TO_SUB_CATEGORY_CLINICAL_SUMMARY:
  1063. return $timeToComplete + $qaTime;
  1064. case ServiceOption::APPLIES_TO_SUB_CATEGORY_CHRON_SOR:
  1065. return $timeToComplete + $scheduleOfRadiologyTime + $qaTime;
  1066. case ServiceOption::APPLIES_TO_SUB_CATEGORY_SOR:
  1067. return $scheduleOfRadiologyTime + $qaTime;
  1068. default:
  1069. return 0;
  1070. }
  1071. }
  1072. /**
  1073. * @return null|string
  1074. */
  1075. public function getLatestNoteContent(): ?string
  1076. {
  1077. /** @var ChronologyRequestDetail $latestNote */
  1078. $latestNote = $this->getDetails()->last();
  1079. return $latestNote ? $latestNote->getContent() : null;
  1080. }
  1081. /**
  1082. *
  1083. * @return null|DateTime
  1084. */
  1085. public function getLatestNoteDate(): ?DateTime
  1086. {
  1087. /** @var ChronologyRequestDetail $latestNote */
  1088. $latestNote = $this->getDetails()->last();
  1089. return $latestNote ? $latestNote->getDisplayDate() : null;
  1090. }
  1091. /**
  1092. * @return bool
  1093. */
  1094. public function hasImportantNotes(): bool
  1095. {
  1096. return $this->getDetails()->filter(function (ChronologyRequestDetail $detail) {
  1097. return $detail->getIsImportant();
  1098. })->count();
  1099. }
  1100. /**
  1101. * @return bool
  1102. */
  1103. public function isClaimCategoryOther(): bool
  1104. {
  1105. return $this->getClaimCategory() === Project::CLAIM_CATEGORY_OTHER;
  1106. }
  1107. /**
  1108. * Returns true if the project the chronology is linked to requires firm records review before commencing with the chronology.
  1109. *
  1110. * @return bool
  1111. */
  1112. public function isFirmRecordsReviewRequired(): bool
  1113. {
  1114. return $this->getProject()
  1115. && $this->getProject()->getMatterRequest()
  1116. && $this->getProject()->getMatterRequest()->getServiceSelectionDetails()
  1117. && $this->getProject()->getMatterRequest()->getServiceSelectionDetails()->isFirmReviewChoiceYes();
  1118. }
  1119. /**
  1120. * Returns true if the project the chronology is linked to requires clinical summary unsorted before commencing with the chronology.
  1121. *
  1122. * @return bool
  1123. */
  1124. public function isClinicalSummaryConclusionRequired(): bool
  1125. {
  1126. return $this->getProject()
  1127. && $this->getProject()->getMatterRequest()
  1128. && $this->getProject()->getMatterRequest()->getServiceSelectionDetails()
  1129. && $this->getProject()->getMatterRequest()->getServiceSelectionDetails()->isReviewChoiceMedBrief();
  1130. }
  1131. /**
  1132. * @return bool
  1133. */
  1134. public function canAutoCancel(): bool
  1135. {
  1136. return $this->getServiceRequest() && $this->getServiceRequest()->getStatus() === ServiceRequest::STATUS_AWAITING_RECORDS;
  1137. }
  1138. }