src/Entity/BatchRequest.php line 35

Open in your IDE?
  1. <?php
  2. namespace MedBrief\MSR\Entity;
  3. use DH\Auditor\Provider\Doctrine\Auditing\Annotation as Audit;
  4. use Doctrine\Common\Collections\ArrayCollection;
  5. use Doctrine\Common\Collections\Collection;
  6. use Doctrine\ORM\Mapping as ORM;
  7. use Gedmo\Mapping\Annotation as Gedmo;
  8. use MedBrief\MSR\Entity\Embeddable\RecordsReceived;
  9. use MedBrief\MSR\Entity\Preprocessing\PreprocessDocument;
  10. use MedBrief\MSR\Entity\RequestType\RequestTypeAwareInterface;
  11. use MedBrief\MSR\Entity\RequestType\RequestTypeAwareTrait;
  12. use MedBrief\MSR\Entity\Serviceable\ServiceableInterface;
  13. use MedBrief\MSR\Entity\Serviceable\ServiceableTrait;
  14. use MedBrief\MSR\Repository\BatchRequestRepository;
  15. use MedBrief\MSR\Service\Preprocessing\PreprocessItemInterface;
  16. use MedBrief\MSR\Service\RecordsRequestCentreTypeAwareInterface;
  17. use MedBrief\MSR\Service\SortingSession\Preprocessing\PreprocessingCriteriaAwareInterface;
  18. use MedBrief\MSR\Traits\FilterableClassConstantsTrait;
  19. /**
  20. * @ORM\Table(name="BatchRequest")
  21. *
  22. * @ORM\Entity(repositoryClass=BatchRequestRepository::class)
  23. *
  24. * @ORM\HasLifecycleCallbacks
  25. *
  26. * @Gedmo\SoftDeleteable(fieldName="deletedAt", timeAware=false)
  27. *
  28. * @Audit\Auditable
  29. *
  30. * @Audit\Security(view={"ROLE_ALLOWED_TO_AUDIT"})
  31. */
  32. class BatchRequest implements ServiceableInterface, RequestTypeAwareInterface, PreprocessItemInterface, RecordsRequestCentreTypeAwareInterface, PreprocessingCriteriaAwareInterface
  33. {
  34. use ServiceableTrait;
  35. use RequestTypeAwareTrait;
  36. use FilterableClassConstantsTrait;
  37. public const BATCH_STANDARD_SHELF_LOCATIONS = [
  38. 'Records With Issues' => 'RWI',
  39. 'Returns Shelf' => 'Returns Shelf',
  40. ];
  41. public const PAGINATION_INDENT_LEVEL_1 = 1;
  42. public const PAGINATION_INDENT_LEVEL_1__LABEL = 1;
  43. public const PAGINATION_INDENT_LEVEL_2 = 2;
  44. public const PAGINATION_INDENT_LEVEL_2__LABEL = 2;
  45. public const PAGINATION_INDENT_LEVEL_3 = 3;
  46. public const PAGINATION_INDENT_LEVEL_3__LABEL = 3;
  47. public const PAGINATION_INDENT_LEVEL_4 = 4;
  48. public const PAGINATION_INDENT_LEVEL_4__LABEL = 4;
  49. public const PAGINATION_INDENT_LEVEL_5 = 5;
  50. public const PAGINATION_INDENT_LEVEL_5__LABEL = 5;
  51. /**
  52. * paginationType constants
  53. */
  54. public const PAGINATION_TYPE_NORMAL = 1;
  55. public const PAGINATION_TYPE_INSERTION = 2;
  56. public const PAGINATION_TYPE_UPDATE = 3;
  57. // dataCategory constant values
  58. public const DATA_CATEGORY_RADIOLOGY = 1;
  59. public const DATA_CATEGORY_VIDEO = 2;
  60. public const DATA_CATEGORY_AUDIO = 3;
  61. public const DATA_CATEGORY_HARD_COPY_INDEXED = 4;
  62. public const DATA_CATEGORY_MEDICAL_RECORDS = 5;
  63. public const DATA_CATEGORY_ELECTRONIC_INDEXED = 6;
  64. // destroyOrReturn constant values
  65. // This is not a simple boolean value, to allow for more future values (such as both)
  66. // and to force a value selection.
  67. public const RECORDS_DESTROY = 1;
  68. public const RECORDS_RETURN = 2;
  69. // Constants used for auto date calculation
  70. public const AUTO_DATE_SORT_DEADLINE = '+6weekday';
  71. public const AUTO_DATE_ESTIMATED_DEADLINE = '+10weekday';
  72. public const AUTO_DATE_DESTRUCTION = '+30day';
  73. // Constants for quoteStatus
  74. public const QUOTE_STATUS_PENDING = 1;
  75. public const QUOTE_STATUS_ACCEPTED = 2;
  76. public const QUOTE_STATUS_DECLINED = 3;
  77. public const COMPUTERIZED_RECORDS_BILLING_THRESHOLD = 1000;
  78. public const EXCLUDE_FROM_PREPROCESSIN_LABEL = '(Excl. from pre-processing)';
  79. public const INCLUDE_FOR_PREPROCESSIN_LABEL = '(Incl. for pre-processing)';
  80. public const CENTRE_TYPE_OTHER_PRE_PROCESSING = 1000;
  81. public const CENTRE_TYPE_OTHER_PRE_PROCESSING__LABEL = 'Other - Pre-processing';
  82. /**
  83. * @var ServiceRequest
  84. *
  85. * @ORM\OneToOne(targetEntity="MedBrief\MSR\Entity\ServiceRequest", mappedBy="batchRequest", cascade={"persist"})
  86. */
  87. protected $serviceRequest;
  88. /**
  89. * @var int
  90. *
  91. * @ORM\Column(name="id", type="integer")
  92. *
  93. * @ORM\Id
  94. *
  95. * @ORM\GeneratedValue(strategy="IDENTITY")
  96. */
  97. protected $id;
  98. /**
  99. * @var string|null
  100. *
  101. * @ORM\Column(name="receivedFrom", type="text", nullable=true)
  102. */
  103. protected $receivedFrom;
  104. /**
  105. * @var string|null
  106. *
  107. * @ORM\Column(name="centreName", type="text", nullable=true)
  108. */
  109. protected $centreName;
  110. /**
  111. * @var int|null
  112. *
  113. * @ORM\Column(name="dataCategory", type="integer", nullable=true)
  114. */
  115. protected $dataCategory;
  116. /**
  117. * @var bool|null
  118. *
  119. * @ORM\Column(name="isCopy", type="boolean", options={"default"=true} , nullable=true)
  120. */
  121. protected $isCopy;
  122. /**
  123. * @var \DateTime|null
  124. *
  125. * @ORM\Column(name="dateReceived", type="date", nullable=true)
  126. */
  127. protected $dateReceived;
  128. /**
  129. * @var \DateTime|null
  130. *
  131. * @ORM\Column(name="sortDeadlineDate", type="date", nullable=true)
  132. */
  133. protected $sortDeadlineDate;
  134. /**
  135. * @var \DateTime|null
  136. *
  137. * @ORM\Column(name="estimatedDeadlineDate", type="date", nullable=true)
  138. */
  139. protected $estimatedDeadlineDate;
  140. /**
  141. * @var \DateTime|null
  142. *
  143. * @ORM\Column(name="dateCompleted", type="date", nullable=true)
  144. */
  145. protected $dateCompleted;
  146. /**
  147. * @var string|null
  148. *
  149. * @ORM\Column(name="passwords", type="string", nullable=true)
  150. */
  151. protected $passwords;
  152. /**
  153. * @var bool
  154. *
  155. * @ORM\Column(name="chronologyRequired", type="boolean", options={"default"=false})
  156. */
  157. protected $chronologyRequired;
  158. /**
  159. * @var int|null
  160. *
  161. * @ORM\Column(name="destroyOrReturn", type="integer", nullable=true)
  162. */
  163. protected $destroyOrReturn;
  164. /**
  165. * @var \DateTime|null
  166. *
  167. * @ORM\Column(name="destructionDate", type="date", nullable=true)
  168. */
  169. protected $destructionDate;
  170. /**
  171. * @var \DateTime|null
  172. *
  173. * @ORM\Column(name="dateDestroyedOrReturned", type="date", nullable=true)
  174. */
  175. protected $dateDestroyedOrReturned;
  176. /**
  177. * @var int|null
  178. *
  179. * @ORM\Column(name="archiveBoxNumber", type="integer", nullable=true)
  180. */
  181. protected $archiveBoxNumber;
  182. /**
  183. * The physical location where Records are to be/have been stored
  184. *
  185. * @var string
  186. *
  187. * @ORM\Column(name="shelfLocation", type="string", length=255, nullable=true)
  188. */
  189. protected $shelfLocation;
  190. /**
  191. * @var \DateTime|null
  192. *
  193. * @ORM\Column(name="qaDate", type="date", nullable=true)
  194. */
  195. protected $qaDate;
  196. /**
  197. * @var string|null
  198. *
  199. * @ORM\Column(name="qaDuration", type="decimal", precision=7, scale=2, nullable=true)
  200. */
  201. protected $qaDuration;
  202. /**
  203. * @var \DateTime|null
  204. *
  205. * @ORM\Column(name="uploadedDate", type="date", nullable=true)
  206. */
  207. protected $uploadedDate;
  208. /**
  209. * @var \DateTime|null
  210. *
  211. * @ORM\Column(name="sortedDate", type="date", nullable=true)
  212. */
  213. protected $sortedDate;
  214. /**
  215. * @var \DateTime|null
  216. *
  217. * @ORM\Column(name="scannedDate", type="date", nullable=true)
  218. */
  219. protected $scannedDate;
  220. /**
  221. * @var int|null
  222. *
  223. * @ORM\Column(name="pageCount", type="integer", nullable=true)
  224. */
  225. protected $pageCount;
  226. /**
  227. * @var int|null
  228. *
  229. * @ORM\Column(name="blankAndDupesCount", type="integer", nullable=true)
  230. */
  231. protected $blankAndDupesCount;
  232. /**
  233. * @var int|null
  234. *
  235. * @ORM\Column(name="computerizedRecordsCount", type="integer", nullable=true)
  236. */
  237. protected $computerizedRecordsCount;
  238. /**
  239. * @var string|null
  240. *
  241. * @ORM\Column(name="scanDuration", type="decimal", precision=7, scale=2, nullable=true)
  242. */
  243. protected $scanDuration;
  244. /**
  245. * @var string|null
  246. *
  247. * @ORM\Column(name="sectionSortDuration", type="decimal", precision=7, scale=2, nullable=true)
  248. */
  249. protected $sectionSortDuration;
  250. /**
  251. * @var string|null
  252. *
  253. * @ORM\Column(name="dateSortDuration", type="decimal", precision=7, scale=2, nullable=true)
  254. */
  255. protected $dateSortDuration;
  256. /**
  257. * @var string|null
  258. *
  259. * @ORM\Column(name="admissionSortDuration", type="decimal", precision=7, scale=2, nullable=true)
  260. */
  261. protected $admissionSortDuration;
  262. /**
  263. * @var Project
  264. *
  265. * @ORM\ManyToOne(targetEntity="MedBrief\MSR\Entity\Project", inversedBy="batchRequests")
  266. *
  267. * @ORM\JoinColumns({
  268. *
  269. * @ORM\JoinColumn(name="project_id", referencedColumnName="id")
  270. * })
  271. */
  272. protected $project;
  273. /**
  274. * @var \DateTime|null
  275. *
  276. * @ORM\Column(name="deletedAt", type="datetime", nullable=true)
  277. */
  278. protected $deletedAt;
  279. /**
  280. * @var \DateTime
  281. *
  282. * @ORM\Column(name="created", type="datetime")
  283. *
  284. * @Gedmo\Timestampable(on="create")
  285. */
  286. protected $created;
  287. /**
  288. * @var User|null
  289. *
  290. * @ORM\ManyToOne(targetEntity="MedBrief\MSR\Entity\User")
  291. *
  292. * @ORM\JoinColumns({
  293. *
  294. * @ORM\JoinColumn(name="createdBy_id", referencedColumnName="id", nullable=true)
  295. * })
  296. */
  297. protected $createdBy;
  298. /**
  299. * @var \DateTime
  300. *
  301. * @ORM\Column(name="updated", type="datetime")
  302. *
  303. * @Gedmo\Timestampable(on="update")
  304. */
  305. protected $updated;
  306. /**
  307. * @var HumanResource
  308. *
  309. * @ORM\ManyToOne(targetEntity="MedBrief\MSR\Entity\HumanResource")
  310. *
  311. * @ORM\JoinColumns({
  312. *
  313. * @ORM\JoinColumn(name="sortedBy_id", referencedColumnName="id")
  314. * })
  315. */
  316. protected $sortedBy;
  317. /**
  318. * @var HumanResource
  319. *
  320. * @ORM\ManyToOne(targetEntity="MedBrief\MSR\Entity\HumanResource")
  321. *
  322. * @ORM\JoinColumns({
  323. *
  324. * @ORM\JoinColumn(name="dateSortedBy_id", referencedColumnName="id")
  325. * })
  326. */
  327. protected $dateSortedBy;
  328. /**
  329. * @var HumanResource
  330. *
  331. * @ORM\ManyToOne(targetEntity="MedBrief\MSR\Entity\HumanResource")
  332. *
  333. * @ORM\JoinColumns({
  334. *
  335. * @ORM\JoinColumn(name="admissionSortedBy_id", referencedColumnName="id")
  336. * })
  337. */
  338. protected $admissionSortedBy;
  339. /**
  340. * @var HumanResource
  341. *
  342. * @ORM\ManyToOne(targetEntity="MedBrief\MSR\Entity\HumanResource")
  343. *
  344. * @ORM\JoinColumns({
  345. *
  346. * @ORM\JoinColumn(name="scanCompletedBy_id", referencedColumnName="id")
  347. * })
  348. */
  349. protected $scanCompletedBy;
  350. /**
  351. * @var HumanResource
  352. *
  353. * @ORM\ManyToOne(targetEntity="MedBrief\MSR\Entity\HumanResource")
  354. *
  355. * @ORM\JoinColumns({
  356. *
  357. * @ORM\JoinColumn(name="qaBy_id", referencedColumnName="id")
  358. * })
  359. */
  360. protected $qaBy;
  361. /**
  362. * @var HumanResource
  363. *
  364. * @ORM\ManyToOne(targetEntity="MedBrief\MSR\Entity\HumanResource")
  365. *
  366. * @ORM\JoinColumns({
  367. *
  368. * @ORM\JoinColumn(name="uploadedBy_id", referencedColumnName="id")
  369. * })
  370. */
  371. protected $uploadedBy;
  372. /**
  373. * @var Collection
  374. *
  375. * @ORM\OneToMany(targetEntity="MedBrief\MSR\Entity\BatchRequestDetail", mappedBy="batchRequest", cascade={"persist","remove"}, orphanRemoval=true)
  376. */
  377. protected $details;
  378. /**
  379. * @var ChronologyRequest
  380. *
  381. * @ORM\ManyToOne(targetEntity="MedBrief\MSR\Entity\ChronologyRequest", inversedBy="batches")
  382. *
  383. * @ORM\JoinColumns({
  384. *
  385. * @ORM\JoinColumn(name="chronologyRequest_id", referencedColumnName="id")
  386. * })
  387. */
  388. protected $chronologyRequest;
  389. /**
  390. * @var RecordsReceived
  391. *
  392. * @ORM\Embedded(class="MedBrief\MSR\Entity\Embeddable\RecordsReceived", columnPrefix="recordsReceived_")
  393. */
  394. protected $recordsReceived;
  395. /**
  396. * @var int|null
  397. *
  398. * @ORM\Column(name="radiologyDiscCount", type="integer", nullable=true)
  399. */
  400. protected $radiologyDiscCount;
  401. /**
  402. * @var string|null
  403. *
  404. * @ORM\Column(name="hoursQuoted", type="decimal", precision=7, scale=2, nullable=true)
  405. */
  406. protected $hoursQuoted;
  407. /**
  408. * @var int|null
  409. *
  410. * @ORM\Column(name="quoteStatus", type="integer", nullable=true)
  411. */
  412. protected $quoteStatus;
  413. /**
  414. * @var Collection
  415. *
  416. * @ORM\OneToMany(targetEntity="MedBrief\MSR\Entity\Disc", mappedBy="batchRequest", cascade={"persist"})
  417. */
  418. protected $discs;
  419. /**
  420. * @var SortingSession
  421. *
  422. * @ORM\ManyToOne(targetEntity="MedBrief\MSR\Entity\SortingSession", inversedBy="batchRequests")
  423. *
  424. * @ORM\JoinColumns({
  425. *
  426. * @ORM\JoinColumn(name="sortingSession_id", referencedColumnName="id")
  427. * })
  428. */
  429. protected $sortingSession;
  430. /**
  431. * @var Collection
  432. *
  433. * @ORM\OneToMany(targetEntity="MedBrief\MSR\Entity\BatchDocument", mappedBy="batchRequest", cascade={"persist"})
  434. *
  435. * @ORM\OrderBy({
  436. * "sortOrder"="ASC"
  437. * })
  438. */
  439. protected $batchDocuments;
  440. /**
  441. * @var Collection
  442. *
  443. * @ORM\OneToMany(targetEntity="MedBrief\MSR\Entity\Page", mappedBy="batchRequest", cascade={"persist"})
  444. */
  445. protected $pages;
  446. /**
  447. * @var bool
  448. *
  449. * @ORM\Column(name="locked", type="boolean", nullable=true, options={"default"=false})
  450. */
  451. protected $locked;
  452. /**
  453. * @var string
  454. *
  455. * @ORM\Column(name="paginationPrefix", type="string", nullable=true)
  456. */
  457. protected $paginationPrefix;
  458. /**
  459. * @var string
  460. *
  461. * @ORM\Column(name="paginationIndentLevel", type="integer", nullable=true)
  462. */
  463. protected $paginationIndentLevel;
  464. /**
  465. * @var int
  466. *
  467. * @ORM\Column(name="paginationType", type="integer", nullable=true, options={"default"="1"})
  468. */
  469. protected $paginationType;
  470. /**
  471. * @var int|null
  472. *
  473. * @ORM\Column(name="clonedPageCount", type="integer", nullable=true)
  474. */
  475. protected $clonedPageCount;
  476. /**
  477. * @var string|null
  478. *
  479. * @ORM\Column(name="centreNameHistory", type="string", nullable=true)
  480. */
  481. protected $centreNameHistory;
  482. /**
  483. * @var Collection
  484. *
  485. * @ORM\OneToMany(targetEntity="MedBrief\MSR\Entity\Preprocessing\PreprocessDocument", mappedBy="batchRequest")
  486. */
  487. private $preprocessDocuments;
  488. /**
  489. * @var int|null
  490. *
  491. * @ORM\Column(name="centreType", type="integer", nullable=true)
  492. */
  493. private $centreType;
  494. /**
  495. * @var int|null
  496. *
  497. * @ORM\Column(name="scannedPageCount", type="integer", nullable=true)
  498. *
  499. */
  500. private ?int $scannedPageCount;
  501. /**
  502. * Constructor
  503. */
  504. public function __construct()
  505. {
  506. $this->isCopy = true;
  507. $this->chronologyRequired = false;
  508. $this->details = new ArrayCollection();
  509. $this->discs = new ArrayCollection();
  510. $this->recordsReceived = new RecordsReceived();
  511. $this->pages = new ArrayCollection();
  512. $this->batchDocuments = new ArrayCollection();
  513. $this->preprocessDocuments = new ArrayCollection();
  514. }
  515. /**
  516. * __toString
  517. *
  518. * @return string
  519. */
  520. public function __toString()
  521. {
  522. return (string) $this->getId();
  523. }
  524. /**
  525. * Get id
  526. *
  527. * @return int
  528. */
  529. public function getId()
  530. {
  531. return $this->id;
  532. }
  533. /**
  534. * Set isCopy
  535. *
  536. * @param bool $isCopy
  537. *
  538. * @return BatchRequest
  539. */
  540. public function setIsCopy($isCopy)
  541. {
  542. $this->isCopy = $isCopy;
  543. return $this;
  544. }
  545. /**
  546. * Get isCopy
  547. *
  548. * @return bool
  549. */
  550. public function getIsCopy()
  551. {
  552. return $this->isCopy;
  553. }
  554. /**
  555. * Get isCopyLabel
  556. *
  557. * @return bool
  558. */
  559. public function getIsCopyLabel()
  560. {
  561. return $this->isCopy ? 'Copy' : 'Original Records';
  562. }
  563. /**
  564. * Get isCopyOptions
  565. *
  566. * @return array
  567. */
  568. public static function getIsCopyOptions()
  569. {
  570. return [
  571. 'Copy' => true,
  572. 'Original Records' => false,
  573. ];
  574. }
  575. /**
  576. * Set dateReceived
  577. *
  578. * @param \DateTime $dateReceived
  579. *
  580. * @return BatchRequest
  581. */
  582. public function setDateReceived($dateReceived)
  583. {
  584. $this->dateReceived = $dateReceived;
  585. return $this;
  586. }
  587. /**
  588. * Get dateReceived
  589. *
  590. * @return \DateTime
  591. */
  592. public function getDateReceived()
  593. {
  594. return $this->dateReceived;
  595. }
  596. /**
  597. * Set estimatedDeadlineDate
  598. *
  599. * @param \DateTime $estimatedDeadlineDate
  600. *
  601. * @return BatchRequest
  602. */
  603. public function setEstimatedDeadlineDate($estimatedDeadlineDate)
  604. {
  605. $this->estimatedDeadlineDate = $estimatedDeadlineDate;
  606. return $this;
  607. }
  608. /**
  609. * Get estimatedDeadlineDate
  610. *
  611. * @return \DateTime
  612. */
  613. public function getEstimatedDeadlineDate()
  614. {
  615. return $this->estimatedDeadlineDate;
  616. }
  617. /**
  618. * Get generateEstimatedDeadlineDate
  619. *
  620. * @return BatchRequest
  621. */
  622. public function generateEstimatedDeadlineDate()
  623. {
  624. if (!$this->estimatedDeadlineDate && $this->getDateReceived()) {
  625. $estimatedDeadlineDate = clone $this->getDateReceived();
  626. $estimatedDeadlineDate->modify(self::AUTO_DATE_ESTIMATED_DEADLINE);
  627. $this->setEstimatedDeadlineDate($estimatedDeadlineDate);
  628. }
  629. return $this;
  630. }
  631. /**
  632. * Set dateCompleted
  633. *
  634. * @param \DateTime $dateCompleted
  635. *
  636. * @return BatchRequest
  637. */
  638. public function setDateCompleted($dateCompleted)
  639. {
  640. $this->dateCompleted = $dateCompleted;
  641. return $this;
  642. }
  643. /**
  644. * Get dateCompleted
  645. *
  646. * @return \DateTime
  647. */
  648. public function getDateCompleted()
  649. {
  650. return $this->dateCompleted;
  651. }
  652. /**
  653. * Set destructionDate
  654. *
  655. * @param \DateTime $destructionDate
  656. *
  657. * @return BatchRequest
  658. */
  659. public function setDestructionDate($destructionDate)
  660. {
  661. $this->destructionDate = $destructionDate;
  662. return $this;
  663. }
  664. /**
  665. * Get destructionDate
  666. *
  667. * @return \DateTime
  668. */
  669. public function getDestructionDate()
  670. {
  671. return $this->destructionDate;
  672. }
  673. /**
  674. * Updates the destruction date based on if the destroyOrReturned field
  675. * is set to RECORDS_DESTROY, and a dateCompleted is set.
  676. *
  677. * Used as a lifecycleCallback.
  678. *
  679. * @ORM\PrePersist
  680. *
  681. * @ORM\PreUpdate
  682. */
  683. public function updateDestructionDate()
  684. {
  685. // If the records are set to be destroyed, calculate and set the destruction date.
  686. if ($this->getDestroyOrReturn() === self::RECORDS_DESTROY && $this->getDateCompleted()) {
  687. $destructionDate = clone $this->getDateCompleted();
  688. $destructionDate->modify(self::AUTO_DATE_DESTRUCTION);
  689. $this->setDestructionDate($destructionDate);
  690. } else {
  691. $this->setDestructionDate(null);
  692. }
  693. return $this;
  694. }
  695. /**
  696. * Returns true if the batch has been destroyed.
  697. *
  698. * Functions by checking if the destroyOrReturn value was set to destroy,
  699. * and if a dateDestroyedOrReturned is set.
  700. *
  701. * @return bool
  702. */
  703. public function isDestroyed()
  704. {
  705. return $this->getDestroyOrReturn() === self::RECORDS_DESTROY && $this->getDateDestroyedOrReturned();
  706. }
  707. /**
  708. * Set dateDestroyedOrReturned
  709. *
  710. * @param \DateTime $dateDestroyedOrReturned
  711. *
  712. * @return BatchRequest
  713. */
  714. public function setDateDestroyedOrReturned($dateDestroyedOrReturned)
  715. {
  716. $this->dateDestroyedOrReturned = $dateDestroyedOrReturned;
  717. return $this;
  718. }
  719. /**
  720. * Get dateDestroyedOrReturned
  721. *
  722. * @return \DateTime
  723. */
  724. public function getDateDestroyedOrReturned()
  725. {
  726. return $this->dateDestroyedOrReturned;
  727. }
  728. /**
  729. * Set archiveBoxNumber
  730. *
  731. * @param string $archiveBoxNumber
  732. *
  733. * @return BatchRequest
  734. */
  735. public function setArchiveBoxNumber($archiveBoxNumber)
  736. {
  737. $this->archiveBoxNumber = $archiveBoxNumber;
  738. return $this;
  739. }
  740. /**
  741. * Get archiveBoxNumber
  742. *
  743. * @return string
  744. */
  745. public function getArchiveBoxNumber()
  746. {
  747. return $this->archiveBoxNumber;
  748. }
  749. /**
  750. * Get archiveBoxNumber
  751. *
  752. * @return string
  753. */
  754. public function getArchiveBoxNumberInclPrefix()
  755. {
  756. $prefix = '';
  757. if ($this->getProject() && $this->getProject()->getAccount()) {
  758. $prefix = $this->getProject()->getAccount()->getPrefix();
  759. }
  760. return ($prefix ? $prefix . '-' : '') . $this->archiveBoxNumber;
  761. }
  762. /**
  763. * Set qaDate
  764. *
  765. * @param \DateTime $qaDate
  766. *
  767. * @return BatchRequest
  768. */
  769. public function setQaDate($qaDate)
  770. {
  771. $this->qaDate = $qaDate;
  772. return $this;
  773. }
  774. /**
  775. * Get qaDate
  776. *
  777. * @return \DateTime
  778. */
  779. public function getQaDate()
  780. {
  781. return $this->qaDate;
  782. }
  783. /**
  784. * Set qaDuration
  785. *
  786. * @param int $qaDuration
  787. *
  788. * @return BatchRequest
  789. */
  790. public function setQaDuration($qaDuration)
  791. {
  792. $this->qaDuration = $qaDuration;
  793. return $this;
  794. }
  795. /**
  796. * Get qaDuration
  797. *
  798. * @return int
  799. */
  800. public function getQaDuration()
  801. {
  802. return $this->qaDuration;
  803. }
  804. /**
  805. * Set uploadedDate
  806. *
  807. * @param \DateTime $uploadedDate
  808. *
  809. * @return BatchRequest
  810. */
  811. public function setUploadedDate($uploadedDate)
  812. {
  813. $this->uploadedDate = $uploadedDate;
  814. return $this;
  815. }
  816. /**
  817. * Get uploadedDate
  818. *
  819. * @return \DateTime
  820. */
  821. public function getUploadedDate()
  822. {
  823. return $this->uploadedDate;
  824. }
  825. /**
  826. * Set deletedAt
  827. *
  828. * @param \DateTime $deletedAt
  829. *
  830. * @return BatchRequest
  831. */
  832. public function setDeletedAt($deletedAt)
  833. {
  834. $this->deletedAt = $deletedAt;
  835. return $this;
  836. }
  837. /**
  838. * Get deletedAt
  839. *
  840. * @return \DateTime
  841. */
  842. public function getDeletedAt()
  843. {
  844. return $this->deletedAt;
  845. }
  846. /**
  847. * Set dataCategory
  848. *
  849. * @param int $dataCategory
  850. *
  851. * @return BatchRequest
  852. */
  853. public function setDataCategory($dataCategory)
  854. {
  855. $this->dataCategory = $dataCategory;
  856. return $this;
  857. }
  858. /**
  859. * Get dataCategory
  860. *
  861. * @return int
  862. */
  863. public function getDataCategory()
  864. {
  865. return $this->dataCategory;
  866. }
  867. /**
  868. * Convenience function for checking if this BatchRequest is
  869. * dataCategory DATA_CATEGORY_RADIOLOGY.
  870. *
  871. * @return bool
  872. */
  873. public function isRadiologyDataCategory()
  874. {
  875. return $this->getDataCategory() === self::DATA_CATEGORY_RADIOLOGY;
  876. }
  877. /**
  878. * Convenience function for checking if this BatchRequest is
  879. * of type media - which includes certain dataCategories.
  880. *
  881. * @return bool
  882. */
  883. public function isDataCategoryTypeMedia()
  884. {
  885. $mediaTypeDataCategories = [
  886. self::DATA_CATEGORY_RADIOLOGY,
  887. self::DATA_CATEGORY_AUDIO,
  888. self::DATA_CATEGORY_VIDEO,
  889. ];
  890. return in_array($this->getDataCategory(), $mediaTypeDataCategories);
  891. }
  892. /**
  893. * Get dataCategoryOptions
  894. *
  895. * @return array
  896. */
  897. public static function getDataCategoryOptions()
  898. {
  899. return [
  900. self::DATA_CATEGORY_RADIOLOGY => 'Radiology',
  901. self::DATA_CATEGORY_VIDEO => 'Video',
  902. self::DATA_CATEGORY_AUDIO => 'Audio',
  903. self::DATA_CATEGORY_HARD_COPY_INDEXED => 'Hard copy indexed',
  904. self::DATA_CATEGORY_MEDICAL_RECORDS => 'Medical records',
  905. self::DATA_CATEGORY_ELECTRONIC_INDEXED => 'Electronic indexed',
  906. ];
  907. }
  908. /**
  909. * Get dataCategoryLabel
  910. *
  911. * @return int
  912. */
  913. public function getDataCategoryLabel()
  914. {
  915. $options = self::getDataCategoryOptions();
  916. return $options[$this->getDataCategory()] ?? '';
  917. }
  918. /**
  919. * Set sortedDate
  920. *
  921. * @param \DateTime $sortedDate
  922. *
  923. * @return BatchRequest
  924. */
  925. public function setSortedDate($sortedDate)
  926. {
  927. $this->sortedDate = $sortedDate;
  928. return $this;
  929. }
  930. /**
  931. * Get sortedDate
  932. *
  933. * @return \DateTime
  934. */
  935. public function getSortedDate()
  936. {
  937. return $this->sortedDate;
  938. }
  939. /**
  940. * Set scannedDate
  941. *
  942. * @param \DateTime $scannedDate
  943. *
  944. * @return BatchRequest
  945. */
  946. public function setScannedDate($scannedDate)
  947. {
  948. $this->scannedDate = $scannedDate;
  949. return $this;
  950. }
  951. /**
  952. * Get scannedDate
  953. *
  954. * @return \DateTime
  955. */
  956. public function getScannedDate()
  957. {
  958. return $this->scannedDate;
  959. }
  960. /**
  961. * Set pageCount
  962. *
  963. * @param int $pageCount
  964. *
  965. * @return BatchRequest
  966. */
  967. public function setPageCount($pageCount)
  968. {
  969. $this->pageCount = $pageCount;
  970. return $this;
  971. }
  972. /**
  973. * Get pageCount
  974. *
  975. * @return int
  976. */
  977. public function getPageCount()
  978. {
  979. return $this->pageCount;
  980. }
  981. /**
  982. * Set blankAndDupesCount
  983. *
  984. * @param int $blankAndDupesCount
  985. *
  986. * @return BatchRequest
  987. */
  988. public function setBlankAndDupesCount($blankAndDupesCount)
  989. {
  990. $this->blankAndDupesCount = $blankAndDupesCount;
  991. return $this;
  992. }
  993. /**
  994. * Get blankAndDupesCount
  995. *
  996. * @return int
  997. */
  998. public function getBlankAndDupesCount()
  999. {
  1000. return $this->blankAndDupesCount;
  1001. }
  1002. /**
  1003. * Set scanDuration
  1004. *
  1005. * @param int $scanDuration
  1006. *
  1007. * @return BatchRequest
  1008. */
  1009. public function setScanDuration($scanDuration)
  1010. {
  1011. $this->scanDuration = $scanDuration;
  1012. return $this;
  1013. }
  1014. /**
  1015. * Get scanDuration
  1016. *
  1017. * @return int
  1018. */
  1019. public function getScanDuration()
  1020. {
  1021. return $this->scanDuration;
  1022. }
  1023. /**
  1024. * Set sectionSortDuration
  1025. *
  1026. * @param int $sectionSortDuration
  1027. *
  1028. * @return BatchRequest
  1029. */
  1030. public function setSectionSortDuration($sectionSortDuration)
  1031. {
  1032. $this->sectionSortDuration = $sectionSortDuration;
  1033. return $this;
  1034. }
  1035. /**
  1036. * Get sectionSortDuration
  1037. *
  1038. * @return int
  1039. */
  1040. public function getSectionSortDuration()
  1041. {
  1042. return $this->sectionSortDuration;
  1043. }
  1044. /**
  1045. * Set dateSortDuration
  1046. *
  1047. * @param int $dateSortDuration
  1048. *
  1049. * @return BatchRequest
  1050. */
  1051. public function setDateSortDuration($dateSortDuration)
  1052. {
  1053. $this->dateSortDuration = $dateSortDuration;
  1054. return $this;
  1055. }
  1056. /**
  1057. * Get dateSortDuration
  1058. *
  1059. * @return int
  1060. */
  1061. public function getDateSortDuration()
  1062. {
  1063. return $this->dateSortDuration;
  1064. }
  1065. /**
  1066. * Set project
  1067. *
  1068. * @param Project $project
  1069. *
  1070. * @return BatchRequest
  1071. */
  1072. public function setProject(?Project $project = null)
  1073. {
  1074. $this->project = $project;
  1075. return $this;
  1076. }
  1077. /**
  1078. * Get project
  1079. *
  1080. * @return Project
  1081. */
  1082. public function getProject()
  1083. {
  1084. return $this->project;
  1085. }
  1086. /**
  1087. * Set sortDeadlineDate
  1088. *
  1089. * @param \DateTime $sortDeadlineDate
  1090. *
  1091. * @return BatchRequest
  1092. */
  1093. public function setSortDeadlineDate($sortDeadlineDate)
  1094. {
  1095. $this->sortDeadlineDate = $sortDeadlineDate;
  1096. return $this;
  1097. }
  1098. /**
  1099. * Get sortDeadlineDate
  1100. *
  1101. * @return \DateTime
  1102. */
  1103. public function getSortDeadlineDate()
  1104. {
  1105. if (!$this->sortDeadlineDate && $this->getDateReceived()) {
  1106. $sortDeadlineDate = clone $this->getDateReceived();
  1107. $sortDeadlineDate->modify(self::AUTO_DATE_SORT_DEADLINE);
  1108. return $sortDeadlineDate;
  1109. }
  1110. return $this->sortDeadlineDate;
  1111. }
  1112. /**
  1113. * Set created
  1114. *
  1115. * @param \DateTime $created
  1116. *
  1117. * @return BatchRequest
  1118. */
  1119. public function setCreated($created)
  1120. {
  1121. $this->created = $created;
  1122. return $this;
  1123. }
  1124. /**
  1125. * Get created
  1126. *
  1127. * @return \DateTime
  1128. */
  1129. public function getCreated()
  1130. {
  1131. return $this->created;
  1132. }
  1133. /**
  1134. * Set createdBy
  1135. *
  1136. * @param User|null $createdBy
  1137. *
  1138. * @return BatchRequest
  1139. */
  1140. public function setCreatedBy(?User $createdBy = null)
  1141. {
  1142. $this->createdBy = $createdBy;
  1143. return $this;
  1144. }
  1145. /**
  1146. * Get createdBy
  1147. *
  1148. * @return User|null
  1149. */
  1150. public function getCreatedBy(): ?User
  1151. {
  1152. return $this->createdBy;
  1153. }
  1154. /**
  1155. * Set updated
  1156. *
  1157. * @param \DateTime $updated
  1158. *
  1159. * @return BatchRequest
  1160. */
  1161. public function setUpdated($updated)
  1162. {
  1163. $this->updated = $updated;
  1164. return $this;
  1165. }
  1166. /**
  1167. * Get updated
  1168. *
  1169. * @return \DateTime
  1170. */
  1171. public function getUpdated()
  1172. {
  1173. return $this->updated;
  1174. }
  1175. /**
  1176. * Set sortedBy
  1177. *
  1178. * @param HumanResource $sortedBy
  1179. *
  1180. * @return BatchRequest
  1181. */
  1182. public function setSortedBy(?HumanResource $sortedBy = null)
  1183. {
  1184. $this->sortedBy = $sortedBy;
  1185. return $this;
  1186. }
  1187. /**
  1188. * Get sortedBy
  1189. *
  1190. * @return HumanResource
  1191. */
  1192. public function getSortedBy()
  1193. {
  1194. return $this->sortedBy;
  1195. }
  1196. /**
  1197. * Set scanCompletedBy
  1198. *
  1199. * @param HumanResource $scanCompletedBy
  1200. *
  1201. * @return BatchRequest
  1202. */
  1203. public function setScanCompletedBy(?HumanResource $scanCompletedBy = null)
  1204. {
  1205. $this->scanCompletedBy = $scanCompletedBy;
  1206. return $this;
  1207. }
  1208. /**
  1209. * Get scanCompletedBy
  1210. *
  1211. * @return HumanResource
  1212. */
  1213. public function getScanCompletedBy()
  1214. {
  1215. return $this->scanCompletedBy;
  1216. }
  1217. /**
  1218. * Set qaBy
  1219. *
  1220. * @param HumanResource $qaBy
  1221. *
  1222. * @return BatchRequest
  1223. */
  1224. public function setQaBy(?HumanResource $qaBy = null)
  1225. {
  1226. $this->qaBy = $qaBy;
  1227. return $this;
  1228. }
  1229. /**
  1230. * Get qaBy
  1231. *
  1232. * @return HumanResource
  1233. */
  1234. public function getQaBy()
  1235. {
  1236. return $this->qaBy;
  1237. }
  1238. /**
  1239. * Set uploadedBy
  1240. *
  1241. * @param HumanResource $uploadedBy
  1242. *
  1243. * @return BatchRequest
  1244. */
  1245. public function setUploadedBy(?HumanResource $uploadedBy = null)
  1246. {
  1247. $this->uploadedBy = $uploadedBy;
  1248. return $this;
  1249. }
  1250. /**
  1251. * Get uploadedBy
  1252. *
  1253. * @return HumanResource
  1254. */
  1255. public function getUploadedBy()
  1256. {
  1257. return $this->uploadedBy;
  1258. }
  1259. /**
  1260. * Set destroyOrReturn
  1261. *
  1262. * @param int $destroyOrReturn
  1263. *
  1264. * @return BatchRequest
  1265. */
  1266. public function setDestroyOrReturn($destroyOrReturn)
  1267. {
  1268. $this->destroyOrReturn = $destroyOrReturn;
  1269. return $this;
  1270. }
  1271. /**
  1272. * Get destroyOrReturn
  1273. *
  1274. * @return int
  1275. */
  1276. public function getDestroyOrReturn()
  1277. {
  1278. return $this->destroyOrReturn;
  1279. }
  1280. /**
  1281. * Get reasonForCancellationOptions
  1282. *
  1283. * @return array
  1284. */
  1285. public static function getDestroyOrReturnOptions()
  1286. {
  1287. return [
  1288. self::RECORDS_RETURN => 'Return',
  1289. self::RECORDS_DESTROY => 'Destroy',
  1290. ];
  1291. }
  1292. /**
  1293. * Get reasonForCancellationLabel
  1294. *
  1295. * @return string
  1296. */
  1297. public function getDestroyOrReturnLabel()
  1298. {
  1299. $options = self::getDestroyOrReturnOptions();
  1300. return $options[$this->getDestroyOrReturn()] ?? '';
  1301. }
  1302. /**
  1303. * Set chronologyRequired
  1304. *
  1305. * @param bool $chronologyRequired
  1306. *
  1307. * @return BatchRequest
  1308. */
  1309. public function setChronologyRequired($chronologyRequired)
  1310. {
  1311. $this->chronologyRequired = $chronologyRequired;
  1312. // Remove the linked ChronologyRequest if we indicate the BatchRequest does not require Chronology
  1313. if (!$chronologyRequired) {
  1314. $this->setChronologyRequest(null);
  1315. }
  1316. return $this;
  1317. }
  1318. /**
  1319. * Get chronologyRequired
  1320. *
  1321. * @return bool
  1322. */
  1323. public function getChronologyRequired()
  1324. {
  1325. return $this->chronologyRequired;
  1326. }
  1327. /**
  1328. * Get chronologyRequired
  1329. *
  1330. * @return bool
  1331. */
  1332. public function getChronologyRequiredLabel()
  1333. {
  1334. return $this->chronologyRequired ? 'Yes' : 'No';
  1335. }
  1336. /**
  1337. * Add detail
  1338. *
  1339. * @param BatchRequestDetail $detail
  1340. *
  1341. * @return BatchRequest
  1342. */
  1343. public function addDetail(BatchRequestDetail $detail)
  1344. {
  1345. $this->details[] = $detail;
  1346. return $this;
  1347. }
  1348. /**
  1349. * Remove detail
  1350. *
  1351. * @param BatchRequestDetail $detail
  1352. */
  1353. public function removeDetail(BatchRequestDetail $detail)
  1354. {
  1355. $this->details->removeElement($detail);
  1356. }
  1357. /**
  1358. * Get details
  1359. *
  1360. * @return Collection
  1361. */
  1362. public function getDetails()
  1363. {
  1364. return $this->details;
  1365. }
  1366. /**
  1367. * Set chronologyRequest
  1368. *
  1369. * @param ChronologyRequest $chronologyRequest
  1370. *
  1371. * @return BatchRequest
  1372. */
  1373. public function setChronologyRequest(?ChronologyRequest $chronologyRequest = null)
  1374. {
  1375. $this->chronologyRequest = $chronologyRequest;
  1376. return $this;
  1377. }
  1378. /**
  1379. * Get chronologyRequest
  1380. *
  1381. * @return ChronologyRequest
  1382. */
  1383. public function getChronologyRequest()
  1384. {
  1385. return $this->chronologyRequest;
  1386. }
  1387. /**
  1388. * Set receivedFrom
  1389. *
  1390. * @param string $receivedFrom
  1391. *
  1392. * @return BatchRequest
  1393. */
  1394. public function setReceivedFrom($receivedFrom)
  1395. {
  1396. $this->receivedFrom = $receivedFrom;
  1397. return $this;
  1398. }
  1399. /**
  1400. * Get receivedFrom
  1401. *
  1402. * @return string
  1403. */
  1404. public function getReceivedFrom()
  1405. {
  1406. return $this->receivedFrom;
  1407. }
  1408. /**
  1409. * Set recordsReceived
  1410. *
  1411. * @param RecordsReceived $recordsReceived
  1412. *
  1413. * @return BatchRequest
  1414. */
  1415. public function setRecordsReceived(RecordsReceived $recordsReceived)
  1416. {
  1417. $this->recordsReceived = $recordsReceived;
  1418. return $this;
  1419. }
  1420. /**
  1421. * Get recordsReceived
  1422. *
  1423. * @return RecordsReceived
  1424. */
  1425. public function getRecordsReceived()
  1426. {
  1427. return $this->recordsReceived;
  1428. }
  1429. /**
  1430. * Set passwords
  1431. *
  1432. * @param string $passwords
  1433. *
  1434. * @return BatchRequest
  1435. */
  1436. public function setPasswords($passwords)
  1437. {
  1438. $this->passwords = $passwords;
  1439. return $this;
  1440. }
  1441. /**
  1442. * Get passwords
  1443. *
  1444. * @return string
  1445. */
  1446. public function getPasswords()
  1447. {
  1448. return $this->passwords;
  1449. }
  1450. /**
  1451. * Add disc
  1452. *
  1453. * @param Disc $disc
  1454. *
  1455. * @return BatchRequest
  1456. */
  1457. public function addDisc(Disc $disc)
  1458. {
  1459. $this->discs[] = $disc;
  1460. return $this;
  1461. }
  1462. /**
  1463. * Remove disc
  1464. *
  1465. * @param Disc $disc
  1466. */
  1467. public function removeDisc(Disc $disc)
  1468. {
  1469. $this->discs->removeElement($disc);
  1470. }
  1471. /**
  1472. * Get discs
  1473. *
  1474. * @return Collection
  1475. */
  1476. public function getDiscs()
  1477. {
  1478. return $this->discs;
  1479. }
  1480. /**
  1481. * Unsets the association between this BatchRequest and Discs.
  1482. * Used as a preRemove lifecycle event, to avoid broken relationships when
  1483. * soft deleting a BatchRequest. Takes the place of a onDelete=NULL database
  1484. * call.
  1485. *
  1486. * @ORM\PreRemove
  1487. *
  1488. * @return void
  1489. */
  1490. public function clearDiscs()
  1491. {
  1492. foreach ($this->getDiscs() as $disc) {
  1493. // Only set the owning side relation to null.
  1494. $disc->setBatchRequest(null);
  1495. }
  1496. }
  1497. /**
  1498. * Set radiologyDiscCount
  1499. *
  1500. * @param int $radiologyDiscCount
  1501. *
  1502. * @return BatchRequest
  1503. */
  1504. public function setRadiologyDiscCount($radiologyDiscCount)
  1505. {
  1506. $this->radiologyDiscCount = $radiologyDiscCount;
  1507. return $this;
  1508. }
  1509. /**
  1510. * Get radiologyDiscCount
  1511. *
  1512. * @return int
  1513. */
  1514. public function getRadiologyDiscCount()
  1515. {
  1516. return $this->radiologyDiscCount;
  1517. }
  1518. /**
  1519. * Returns the number of Discs that still need to be created for this BatchRequest.
  1520. *
  1521. * @return int
  1522. */
  1523. public function getOutstandingRadiologyDiscCount()
  1524. {
  1525. return (int) $this->getRadiologyDiscCount() - $this->getDiscs()->count();
  1526. }
  1527. /**
  1528. * Gets all BatchRequests related to this BatchRequest, i.e.
  1529. * those that belong to the same ServiceRequestGroup
  1530. *
  1531. * @param $inclCurrent - Optionally include the current BatchRequest
  1532. *
  1533. * @return array
  1534. */
  1535. public function getRelatedBatchRequests($inclCurrent = false)
  1536. {
  1537. // If the BatchRequest does not belong to a ServiceRequest group,
  1538. // it has no related batches.
  1539. if (!$this->getServiceRequestGroup()) {
  1540. return [];
  1541. }
  1542. // Assign the calling class to a more readable variable
  1543. $currentBatchRequest = $this;
  1544. // Filter through the ServiceRequests on the ServiceRequestGroup and return the BatchRequests only.
  1545. $relatedBatchRequests = $this->getServiceRequestGroup()->getServiceRequests()->filter(function ($serviceRequest) use ($inclCurrent, $currentBatchRequest) {
  1546. // If the serviceRequest belongs to the currentBatchRequest...
  1547. if ($serviceRequest->getId() === $currentBatchRequest->getServiceRequest()->getId()) {
  1548. // include it if we want to include the current batchRequest
  1549. return $inclCurrent;
  1550. }
  1551. // If the serviceRequest is attached to a batchRequest, include it.
  1552. if ($serviceRequest->isBatchRequest()) {
  1553. return true;
  1554. }
  1555. // Don't include any others
  1556. return false;
  1557. });
  1558. // Extract the Serviceable from the ServiceRequest, which should be a BatchRequest.
  1559. return array_map(function ($serviceRequest) {
  1560. return $serviceRequest->getServiceable();
  1561. }, $relatedBatchRequests->toArray());
  1562. }
  1563. /**
  1564. * Set hoursQuoted
  1565. *
  1566. * @param int $hoursQuoted
  1567. *
  1568. * @return BatchRequest
  1569. */
  1570. public function setHoursQuoted($hoursQuoted)
  1571. {
  1572. $this->hoursQuoted = $hoursQuoted;
  1573. return $this;
  1574. }
  1575. /**
  1576. * Get hoursQuoted
  1577. *
  1578. * @return int
  1579. */
  1580. public function getHoursQuoted()
  1581. {
  1582. return $this->hoursQuoted;
  1583. }
  1584. /**
  1585. * Set quoteStatus
  1586. *
  1587. * @param int $quoteStatus
  1588. *
  1589. * @return BatchRequest
  1590. */
  1591. public function setQuoteStatus($quoteStatus)
  1592. {
  1593. $this->quoteStatus = $quoteStatus;
  1594. return $this;
  1595. }
  1596. /**
  1597. * Get quoteStatus
  1598. *
  1599. * @return int
  1600. */
  1601. public function getQuoteStatus()
  1602. {
  1603. return $this->quoteStatus;
  1604. }
  1605. /**
  1606. * Get quoteStatusLabel
  1607. *
  1608. * @return bool
  1609. */
  1610. public function getQuoteStatusLabel()
  1611. {
  1612. $options = self::getQuoteStatusOptions();
  1613. return $options[$this->getQuoteStatus()] ?? '';
  1614. }
  1615. /**
  1616. * Get quoteStatusOptions
  1617. *
  1618. * @return array
  1619. */
  1620. public static function getQuoteStatusOptions()
  1621. {
  1622. return [
  1623. self::QUOTE_STATUS_PENDING => 'Pending',
  1624. self::QUOTE_STATUS_ACCEPTED => 'Accepted',
  1625. self::QUOTE_STATUS_DECLINED => 'Declined',
  1626. ];
  1627. }
  1628. /**
  1629. * Set shelfLocation
  1630. *
  1631. * @param string $shelfLocation
  1632. *
  1633. * @return BatchRequest
  1634. */
  1635. public function setShelfLocation($shelfLocation)
  1636. {
  1637. $this->shelfLocation = $shelfLocation;
  1638. return $this;
  1639. }
  1640. /**
  1641. * Get shelfLocation
  1642. *
  1643. * @return string
  1644. */
  1645. public function getShelfLocation()
  1646. {
  1647. return $this->shelfLocation;
  1648. }
  1649. /**
  1650. * Set sortingSession
  1651. *
  1652. * @param SortingSession $sortingSession
  1653. *
  1654. * @return BatchRequest
  1655. */
  1656. public function setSortingSession(?SortingSession $sortingSession = null)
  1657. {
  1658. $this->sortingSession = $sortingSession;
  1659. return $this;
  1660. }
  1661. /**
  1662. * Get sortingSession
  1663. *
  1664. * @return SortingSession
  1665. */
  1666. public function getSortingSession()
  1667. {
  1668. return $this->sortingSession;
  1669. }
  1670. /**
  1671. * Add page
  1672. *
  1673. * @param Page $page
  1674. *
  1675. * @return BatchRequest
  1676. */
  1677. public function addPage(Page $page)
  1678. {
  1679. $this->pages[] = $page;
  1680. return $this;
  1681. }
  1682. /**
  1683. * Remove page
  1684. *
  1685. * @param Page $page
  1686. */
  1687. public function removePage(Page $page)
  1688. {
  1689. $this->pages->removeElement($page);
  1690. }
  1691. /**
  1692. * Get pages
  1693. *
  1694. * @return Collection
  1695. */
  1696. public function getPages()
  1697. {
  1698. return $this->pages;
  1699. }
  1700. /**
  1701. * Add batchDocument
  1702. *
  1703. * @param BatchDocument $batchDocument
  1704. *
  1705. * @return BatchRequest
  1706. */
  1707. public function addBatchDocument(BatchDocument $batchDocument)
  1708. {
  1709. $this->batchDocuments[] = $batchDocument;
  1710. return $this;
  1711. }
  1712. /**
  1713. * Remove batchDocument
  1714. *
  1715. * @param BatchDocument $batchDocument
  1716. */
  1717. public function removeBatchDocument(BatchDocument $batchDocument)
  1718. {
  1719. $this->batchDocuments->removeElement($batchDocument);
  1720. }
  1721. /**
  1722. * Get batchDocuments
  1723. *
  1724. * @return Collection|BatchDocument[]
  1725. */
  1726. public function getBatchDocuments()
  1727. {
  1728. return $this->batchDocuments;
  1729. }
  1730. /**
  1731. * Get batchDocuments that are PDF only.
  1732. *
  1733. * @return Collection|BatchDocument[]
  1734. */
  1735. public function getBatchDocumentsPdfOnly()
  1736. {
  1737. return $this->batchDocuments->filter(function (BatchDocument $item) {
  1738. return $item->getDocument()->getFileFamilyType() === Document::FILE_TYPE_PDF;
  1739. });
  1740. }
  1741. /**
  1742. * Get batchDocuments that are PDFs, plus any non-PDF documents left in a failed
  1743. * state (including encrypted PDFs) so they remain visible in the review list.
  1744. *
  1745. * @return Collection|BatchDocument[]
  1746. */
  1747. public function getBatchDocumentsPdfOrFailed()
  1748. {
  1749. return $this->batchDocuments->filter(function (BatchDocument $item) {
  1750. return $item->getDocument()->getFileFamilyType() === Document::FILE_TYPE_PDF
  1751. || $item->isFailed()
  1752. || $item->getStatus() === BatchDocument::STATUS_FAILED_ENCRYPTED;
  1753. });
  1754. }
  1755. /**
  1756. * Set locked
  1757. *
  1758. * @param bool $locked
  1759. *
  1760. * @return BatchRequest
  1761. */
  1762. public function setLocked($locked)
  1763. {
  1764. $this->locked = $locked;
  1765. return $this;
  1766. }
  1767. /**
  1768. * Get locked
  1769. *
  1770. * @return bool
  1771. */
  1772. public function isLocked()
  1773. {
  1774. return $this->locked;
  1775. }
  1776. /**
  1777. * Checks to see if this BatchRequest has pending BatchDocuments
  1778. *
  1779. * @return bool
  1780. */
  1781. public function hasPendingBatchDocuments()
  1782. {
  1783. /** @var BatchDocument $batchDocument */
  1784. foreach ($this->getBatchDocuments() as $batchDocument) {
  1785. if ($batchDocument->getStatus() === BatchDocument::STATUS_PENDING) {
  1786. return true;
  1787. }
  1788. }
  1789. return false;
  1790. }
  1791. /**
  1792. * Checks to see if this BatchRequest has in progress BatchDocuments
  1793. *
  1794. * @return bool
  1795. */
  1796. public function hasInProgressBatchDocuments()
  1797. {
  1798. /** @var BatchDocument $batchDocument */
  1799. foreach ($this->getBatchDocuments() as $batchDocument) {
  1800. if ($batchDocument->getStatus() === BatchDocument::STATUS_IN_PROGRESS) {
  1801. return true;
  1802. }
  1803. }
  1804. return false;
  1805. }
  1806. /**
  1807. * Set centreName
  1808. *
  1809. * @param string $centreName
  1810. *
  1811. * @return BatchRequest
  1812. */
  1813. public function setCentreName($centreName)
  1814. {
  1815. $centreName = trim($centreName);
  1816. if ($this->getReceivedFrom() === null) {
  1817. $this->setReceivedFrom($centreName);
  1818. }
  1819. $this->centreName = $centreName;
  1820. return $this;
  1821. }
  1822. /**
  1823. * Set paginationType
  1824. *
  1825. * @param int $paginationType
  1826. *
  1827. * @return BatchRequest
  1828. */
  1829. public function setPaginationType($paginationType)
  1830. {
  1831. $this->paginationType = $paginationType;
  1832. return $this;
  1833. }
  1834. /**
  1835. * Get centreName
  1836. *
  1837. * @return string
  1838. */
  1839. public function getCentreName()
  1840. {
  1841. return $this->centreName;
  1842. }
  1843. /**
  1844. * Get paginationType
  1845. *
  1846. * @return int
  1847. */
  1848. public function getPaginationType()
  1849. {
  1850. return $this->paginationType;
  1851. }
  1852. /**
  1853. * Get paginationTypeOptions
  1854. *
  1855. * @return array
  1856. */
  1857. public static function getPaginationTypeOptions()
  1858. {
  1859. return [
  1860. self::PAGINATION_TYPE_NORMAL => 'Normal',
  1861. self::PAGINATION_TYPE_INSERTION => 'Insertion',
  1862. self::PAGINATION_TYPE_UPDATE => 'Update',
  1863. ];
  1864. }
  1865. /**
  1866. * Get paginationTypeLabel
  1867. *
  1868. * @return int
  1869. */
  1870. public function getPaginationTypeLabel()
  1871. {
  1872. $options = self::getPaginationTypeOptions();
  1873. return $options[$this->getPaginationType()] ?? '';
  1874. }
  1875. /**
  1876. * Returns true if the pagination type insertion.
  1877. *
  1878. * @return bool
  1879. */
  1880. public function isInsertionPaginationType()
  1881. {
  1882. return $this->getPaginationType() === self::PAGINATION_TYPE_INSERTION;
  1883. }
  1884. /**
  1885. * Returns true if the pagination type is update.
  1886. *
  1887. * @return bool
  1888. */
  1889. public function isUpdatePaginationType()
  1890. {
  1891. return $this->getPaginationType() === self::PAGINATION_TYPE_UPDATE;
  1892. }
  1893. /**
  1894. * Gets the label to use in the choice drop downs.
  1895. *
  1896. * @return string
  1897. */
  1898. public function getChoiceLabel()
  1899. {
  1900. return sprintf('%1$s (%2$s Pag.)', $this->getServiceRequestGroupId(), $this->getPaginationTypeLabel());
  1901. }
  1902. /**
  1903. * Set admissionSortDuration.
  1904. *
  1905. * @param string|null $admissionSortDuration
  1906. *
  1907. * @return BatchRequest
  1908. */
  1909. public function setAdmissionSortDuration($admissionSortDuration = null)
  1910. {
  1911. $this->admissionSortDuration = $admissionSortDuration;
  1912. return $this;
  1913. }
  1914. /**
  1915. * Get admissionSortDuration.
  1916. *
  1917. * @return string|null
  1918. */
  1919. public function getAdmissionSortDuration()
  1920. {
  1921. return $this->admissionSortDuration;
  1922. }
  1923. /**
  1924. * Get locked.
  1925. *
  1926. * @return bool|null
  1927. */
  1928. public function getLocked()
  1929. {
  1930. return $this->locked;
  1931. }
  1932. /**
  1933. * Set dateSortedBy.
  1934. *
  1935. * @param HumanResource|null $dateSortedBy
  1936. *
  1937. * @return BatchRequest
  1938. */
  1939. public function setDateSortedBy(?HumanResource $dateSortedBy = null)
  1940. {
  1941. $this->dateSortedBy = $dateSortedBy;
  1942. return $this;
  1943. }
  1944. /**
  1945. * Get dateSortedBy.
  1946. *
  1947. * @return HumanResource|null
  1948. */
  1949. public function getDateSortedBy()
  1950. {
  1951. return $this->dateSortedBy;
  1952. }
  1953. /**
  1954. * Set admissionSortedBy.
  1955. *
  1956. * @param HumanResource|null $admissionSortedBy
  1957. *
  1958. * @return BatchRequest
  1959. */
  1960. public function setAdmissionSortedBy(?HumanResource $admissionSortedBy = null)
  1961. {
  1962. $this->admissionSortedBy = $admissionSortedBy;
  1963. return $this;
  1964. }
  1965. /**
  1966. * Get admissionSortedBy.
  1967. *
  1968. * @return HumanResource|null
  1969. */
  1970. public function getAdmissionSortedBy()
  1971. {
  1972. return $this->admissionSortedBy;
  1973. }
  1974. /**
  1975. * Set paginationPrefix.
  1976. *
  1977. * @param string|null $paginationPrefix
  1978. *
  1979. * @return BatchRequest
  1980. */
  1981. public function setPaginationPrefix($paginationPrefix = null)
  1982. {
  1983. $this->paginationPrefix = $paginationPrefix;
  1984. return $this;
  1985. }
  1986. /**
  1987. * Get paginationPrefix.
  1988. *
  1989. * @return string|null
  1990. */
  1991. public function getPaginationPrefix()
  1992. {
  1993. return $this->paginationPrefix;
  1994. }
  1995. /**
  1996. * Set paginationIndentLevel.
  1997. *
  1998. * @param int|null $paginationIndentLevel
  1999. *
  2000. * @return BatchRequest
  2001. */
  2002. public function setPaginationIndentLevel($paginationIndentLevel = null)
  2003. {
  2004. $this->paginationIndentLevel = $paginationIndentLevel;
  2005. return $this;
  2006. }
  2007. /**
  2008. * Get paginationIndentLevel.
  2009. *
  2010. * @return int|null
  2011. */
  2012. public function getPaginationIndentLevel()
  2013. {
  2014. return $this->paginationIndentLevel ?: self::PAGINATION_INDENT_LEVEL_1;
  2015. }
  2016. /**
  2017. * Set clonedPageCount.
  2018. *
  2019. * @param int|null $clonedPageCount
  2020. *
  2021. * @return BatchRequest
  2022. */
  2023. public function setClonedPageCount($clonedPageCount = null)
  2024. {
  2025. $this->clonedPageCount = $clonedPageCount;
  2026. return $this;
  2027. }
  2028. /**
  2029. * Get clonedPageCount.
  2030. *
  2031. * @return int|null
  2032. */
  2033. public function getClonedPageCount(): ?int
  2034. {
  2035. return $this->clonedPageCount;
  2036. }
  2037. /**
  2038. * Get the value of centreNameHistory
  2039. *
  2040. * @return string|null
  2041. */
  2042. public function getCentreNameHistory()
  2043. {
  2044. return $this->centreNameHistory;
  2045. }
  2046. /**
  2047. * Set the value of centreNameHistory
  2048. *
  2049. * @param string|null $centreNameHistory
  2050. *
  2051. * @return BatchRequest
  2052. */
  2053. public function setCentreNameHistory($centreNameHistory = null)
  2054. {
  2055. $this->centreNameHistory = $centreNameHistory;
  2056. return $this;
  2057. }
  2058. /**
  2059. * @return Collection|PreprocessDocument[]
  2060. */
  2061. public function getPreprocessDocuments(): Collection
  2062. {
  2063. return $this->preprocessDocuments;
  2064. }
  2065. /**
  2066. * @return PreprocessDocument[]
  2067. */
  2068. public function getPreprocessDocumentsArray(): array
  2069. {
  2070. return $this->preprocessDocuments->toArray();
  2071. }
  2072. /**
  2073. * @param PreprocessDocument $preprocessDocument
  2074. *
  2075. * @return self
  2076. */
  2077. public function addPreprocessDocument(PreprocessDocument $preprocessDocument): self
  2078. {
  2079. if (!$this->preprocessDocuments->contains($preprocessDocument)) {
  2080. $this->preprocessDocuments[] = $preprocessDocument;
  2081. $preprocessDocument->setBatchRequest($this);
  2082. }
  2083. return $this;
  2084. }
  2085. /**
  2086. * @param PreprocessDocument $preprocessDocument
  2087. *
  2088. * @return self
  2089. */
  2090. public function removePreprocessDocument(PreprocessDocument $preprocessDocument): self
  2091. {
  2092. if ($this->preprocessDocuments->removeElement($preprocessDocument)) {
  2093. // set the owning side to null (unless already changed)
  2094. if ($preprocessDocument->getBatchRequest() === $this) {
  2095. $preprocessDocument->setBatchRequest(null);
  2096. }
  2097. }
  2098. return $this;
  2099. }
  2100. /**
  2101. * @return int|null
  2102. */
  2103. public function getCentreType(): ?int
  2104. {
  2105. return $this->centreType;
  2106. }
  2107. /**
  2108. * @param int|null $centreType
  2109. *
  2110. * @return self
  2111. */
  2112. public function setCentreType(?int $centreType): self
  2113. {
  2114. $this->centreType = $centreType;
  2115. return $this;
  2116. }
  2117. /**
  2118. * @return array
  2119. */
  2120. public static function getCentreTypeOptions(): array
  2121. {
  2122. $options = self::getConstantsWithLabelsAsChoices('CENTRE_TYPE');
  2123. $includeOptions = [
  2124. self::CENTRE_TYPE_TRUST,
  2125. self::CENTRE_TYPE_GP,
  2126. self::CENTRE_TYPE_AMBULANCE_SERVICE,
  2127. self::CENTRE_TYPE_CARE_HOME,
  2128. self::CENTRE_TYPE_MARIE_STOPES,
  2129. self::CENTRE_TYPE_PHARMACY,
  2130. self::CENTRE_TYPE_CONSULTANT,
  2131. self::CENTRE_TYPE_HOSPITAL,
  2132. self::CENTRE_TYPE_PSYCHOLOGY,
  2133. self::CENTRE_TYPE_PHYSIO,
  2134. self::CENTRE_TYPE_PODIATRIST,
  2135. self::CENTRE_TYPE_URGENT_CARE_CENTRE,
  2136. self::CENTRE_TYPE_WALKIN_CENTRE,
  2137. self::CENTRE_TYPE_OTHER_PRE_PROCESSING,
  2138. ];
  2139. // Only return certain options for batch requests
  2140. $options = array_intersect($options, $includeOptions);
  2141. ksort($options);
  2142. $reLabeledOptions = [];
  2143. // Append the incl or excl label. Currently, we show the include label as so few centre types are included for pre-processing.
  2144. $preprocessingCentreTypes = static::getAllowedPreprocessingCentreTypes();
  2145. foreach ($options as $label => $value) {
  2146. if (in_array($value, $preprocessingCentreTypes) === true) {
  2147. $reLabeledOptions[sprintf('%1$s %2$s', $label, self::INCLUDE_FOR_PREPROCESSIN_LABEL)] = $value;
  2148. } else {
  2149. $reLabeledOptions[$label] = $value;
  2150. }
  2151. }
  2152. // Add other at the back
  2153. $reLabeledOptions[self::CENTRE_TYPE_OTHER__LABEL] = self::CENTRE_TYPE_OTHER;
  2154. return $reLabeledOptions;
  2155. }
  2156. /**
  2157. * Returns an array of allowed centre types for preprocessing.
  2158. *
  2159. * @return array
  2160. */
  2161. public static function getAllowedPreprocessingCentreTypes(): array
  2162. {
  2163. return [
  2164. // self::CENTRE_TYPE_TRUST,
  2165. self::CENTRE_TYPE_GP,
  2166. // self::CENTRE_TYPE_AMBULANCE_SERVICE,
  2167. // self::CENTRE_TYPE_CARE_HOME,
  2168. // self::CENTRE_TYPE_MARIE_STOPES,
  2169. // self::CENTRE_TYPE_PHARMACY,
  2170. // self::CENTRE_TYPE_CONSULTANT,
  2171. // self::CENTRE_TYPE_HOSPITAL,
  2172. // self::CENTRE_TYPE_PSYCHOLOGY,
  2173. // self::CENTRE_TYPE_PHYSIO,
  2174. // self::CENTRE_TYPE_PODIATRIST,
  2175. // self::CENTRE_TYPE_URGENT_CARE_CENTRE,
  2176. // self::CENTRE_TYPE_WALKIN_CENTRE,
  2177. // self::CENTRE_TYPE_OTHER_PRE_PROCESSING,
  2178. ];
  2179. }
  2180. /**
  2181. * Returns true if the batch request is for GP Records.
  2182. *
  2183. * @return bool
  2184. */
  2185. public function isGpRecords(): bool
  2186. {
  2187. return $this->getCentreType() === self::CENTRE_TYPE_GP;
  2188. }
  2189. /**
  2190. * Returns true of the batch request should be included for pre-processing.
  2191. *
  2192. * @return bool
  2193. */
  2194. public function allowPreprocessing(): bool
  2195. {
  2196. $isServiceRequestComplete = $this->getServiceRequest()->isComplete();
  2197. $isAllowedCentreType = in_array($this->getCentreType(), static::getAllowedPreprocessingCentreTypes());
  2198. // If the type of records is not a GP records set, we only want to allow certain centre names
  2199. // to go for pre-processing.
  2200. $isCentreNameMatch = true;
  2201. // If not a GP records set...
  2202. if ($this->isGpRecords() === false) {
  2203. // Check if the centre wildcards appear in the name
  2204. $pattern = '/' . implode('|', array_map('preg_quote', self::TRUST_NAME_WILDCARDS)) . '/i';
  2205. // Use preg_match to check if any of the wildcards are found
  2206. if (preg_match($pattern, $this->getCentreName()) === 0) {
  2207. $isCentreNameMatch = false;
  2208. }
  2209. }
  2210. return $isServiceRequestComplete === false && $isAllowedCentreType === true && $isCentreNameMatch === true;
  2211. }
  2212. /**
  2213. * @return string
  2214. */
  2215. public function getCentreTypeLabel(): string
  2216. {
  2217. $options = array_flip(self::getCentreTypeOptions());
  2218. return $options[$this->getCentreType()] ?? '';
  2219. }
  2220. /**
  2221. * Returns true if the batch is to be included for preprocessing.
  2222. *
  2223. * @return bool
  2224. */
  2225. public function includedForPreProcessing(): bool
  2226. {
  2227. if (!$this->getSortingSession() || $this->getSortingSession()->getRequiresPreProcessing() === false) {
  2228. return false;
  2229. }
  2230. return !empty(array_filter($this->getSortingSession()->getPreprocessItems(), function (BatchRequest $batchRequest) {
  2231. return $batchRequest->getId() === $this->getId();
  2232. }));
  2233. }
  2234. /**
  2235. * @return bool
  2236. */
  2237. public function isSubmittedForPreprocessing(): bool
  2238. {
  2239. $preprocessDocument = $this->getPreprocessDocuments()->last();
  2240. return $preprocessDocument instanceof PreprocessDocument && !$preprocessDocument->isIgnore();
  2241. }
  2242. /**
  2243. * @return int|null
  2244. */
  2245. public function getComputerizedRecordsCount(): ?int
  2246. {
  2247. return $this->computerizedRecordsCount;
  2248. }
  2249. /**
  2250. * @param int|null $computerizedRecordsCount
  2251. *
  2252. * @return self
  2253. */
  2254. public function setComputerizedRecordsCount(?int $computerizedRecordsCount = null): self
  2255. {
  2256. $this->computerizedRecordsCount = $computerizedRecordsCount;
  2257. return $this;
  2258. }
  2259. /**
  2260. * Returns the pages that should be billed at the standard rate, based on this logic:
  2261. * Total @ Standard Rate (new) = SUM of the following page counts:
  2262. * - Sorted Page Count
  2263. * - Blanks and Dupes Count
  2264. * - Computerised Records, but only if count is < 1000. @see COMPUTERIZED_RECORDS_BILLING_THRESHOLD
  2265. *
  2266. * @return int
  2267. */
  2268. public function getPageCountBilledAtStandardRate(): int
  2269. {
  2270. return $this->getPageCount() + $this->getBlankAndDupesCount() + ($this->getComputerizedRecordsCount() < self::COMPUTERIZED_RECORDS_BILLING_THRESHOLD ? $this->getComputerizedRecordsCount() : 0);
  2271. }
  2272. /**
  2273. * @return bool
  2274. */
  2275. public function hasImportantNotes(): bool
  2276. {
  2277. return $this->getDetails()->filter(function (BatchRequestDetail $batchRequestDetail) {
  2278. return $batchRequestDetail->getIsImportant();
  2279. })->count();
  2280. }
  2281. /**
  2282. * @return bool
  2283. */
  2284. public function canAutoCancel(): bool
  2285. {
  2286. if ($this->getServiceRequest() && ($this->getServiceRequest()->getStatus() === ServiceRequest::STATUS_AWAITING_RECORDS_ARRIVAL || $this->getServiceRequest()->getStatus() === ServiceRequest::STATUS_AWAITING_QUOTE_APPROVAL)) {
  2287. return true;
  2288. }
  2289. return false;
  2290. }
  2291. /**
  2292. * Gets the number of pages scanned
  2293. *
  2294. * @return int|null
  2295. */
  2296. public function getScannedPageCount(): ?int
  2297. {
  2298. return $this->scannedPageCount;
  2299. }
  2300. /**
  2301. * Sets the number of pages scanned
  2302. *
  2303. * @param int|null $scannedPageCount
  2304. *
  2305. * @return self
  2306. */
  2307. public function setScannedPageCount(?int $scannedPageCount): self
  2308. {
  2309. $this->scannedPageCount = $scannedPageCount;
  2310. return $this;
  2311. }
  2312. }