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