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