src/Entity/SortingSession.php line 29

Open in your IDE?
  1. <?php
  2. namespace MedBrief\MSR\Entity;
  3. use Doctrine\Common\Collections\ArrayCollection;
  4. use Doctrine\Common\Collections\Collection;
  5. use Doctrine\Common\Collections\Criteria;
  6. use Doctrine\ORM\Mapping as ORM;
  7. use Gedmo\Mapping\Annotation as Gedmo;
  8. use MedBrief\MSR\Entity\MatterRequest\Details\Sort;
  9. use MedBrief\MSR\Entity\MatterRequest\MatterRequest;
  10. use MedBrief\MSR\Repository\SortingSessionRepository;
  11. use MedBrief\MSR\Service\Preprocessing\PreprocessableInterface;
  12. use MedBrief\MSR\Service\Preprocessing\PreprocessItemInterface;
  13. use MedBrief\MSR\Service\ProjectClosure\RemoveRecords\RemovableRecordInterface;
  14. use MedBrief\MSR\Service\SortingSession\SortStatusAwareInterface;
  15. use MedBrief\MSR\Traits\FilterableClassConstantsTrait;
  16. /**
  17. * SortingSession
  18. *
  19. * @ORM\Table(name="SortingSession")
  20. *
  21. * @ORM\Entity(repositoryClass=SortingSessionRepository::class)
  22. *
  23. * @Gedmo\SoftDeleteable(fieldName="deletedAt", timeAware=false)
  24. *
  25. */
  26. class SortingSession implements RemovableRecordInterface, PreprocessableInterface, SortStatusAwareInterface
  27. {
  28. use FilterableClassConstantsTrait;
  29. /**
  30. * Constant values for Session Status
  31. */
  32. public const SESSION_STATUS_PENDING = 11; // Allow adding/removing of batches
  33. public const SESSION_STATUS_READY_FOR_SORTER = 12; // Allow adding/removing of batches (Revert to ::STATUS_PENDING on addition ONLY)
  34. public const SESSION_STATUS_IN_PROGRESS = 13; // SS is cast in stone!!
  35. public const SESSION_STATUS_PAUSED = 14; // SS may be deleted, batches to be released
  36. public const SESSION_STATUS_PAGES_MISSING = 15; // Allow adding of batches ONLY (Revert to ::STATUS_PENDING) -> Delete SS to release batches
  37. public const SESSION_STATUS_COMPLETED = 16; // Allow adding of batches ONLY (Revert to ::STATUS_PENDING) -> Delete SS to release batches
  38. // Preparation related statuses
  39. public const SESSION_STATUS_PREPARE_PENDING = 21; // SS is cast in stone!!
  40. public const SESSION_STATUS_PREPARE_IN_PROGRESS = 22; // SS is cast in stone!!
  41. public const SESSION_STATUS_PREPARE_FAILED = 23; // Allow adding/removing of batches (Revert to ::STATUS_PENDING)
  42. // Export related statuses
  43. public const SESSION_STATUS_EXPORT_PENDING = 31;
  44. public const SESSION_STATUS_EXPORT_IN_PROGRESS = 32;
  45. public const SESSION_STATUS_EXPORT_COMPLETED = 33;
  46. public const SESSION_STATUS_EXPORT_FAILED = 34;
  47. // Processing related statuses - these in practice relate to AI processing of the documents prior to sorting
  48. public const SESSION_STATUS_PREPROCESSING_PENDING = 41;
  49. public const SESSION_STATUS_PREPROCESSING_IN_PROGRESS = 42;
  50. public const SESSION_STATUS_PREPROCESSING_FAILED = 43;
  51. // Export Push related statuses
  52. public const EXPORT_PUSH_STATUS_PENDING = 'export_push.pending';
  53. public const EXPORT_PUSH_STATUS_IN_PROGRESS = 'export_push.in_progress';
  54. public const EXPORT_PUSH_STATUS_COMPLETED = 'export_push.completed';
  55. public const EXPORT_PUSH_STATUS_FAILED = 'export_push.failed';
  56. /** Pagination Strategies */
  57. public const PAGINATION_STRATEGY_ABSOLUTE = 1;
  58. public const PAGINATION_STRATEGY_RELATIVE = 2;
  59. public const PAGINATION_STRATEGY_PREFIXED_ABSOLUTE = 3;
  60. public const PAGINATION_STRATEGY_PREFIXED_RELATIVE = 4;
  61. public const PAGINATION_STRATEGY_NONE = 5;
  62. public const PAGINATION_STRATEGY_SECTION = 6;
  63. public const PAGINATION_STRATEGY_PREFIXED_SECTION = 7;
  64. /** Centre Prefixes */
  65. public const CENTRE_PREFIX_ALPHA = 1;
  66. public const CENTRE_PREFIX_NUMERIC = 2;
  67. public const VERSION_OLD = 'old';
  68. // memoStatus constants
  69. public const MEMO_STATUS_READY_TO_SYNC = 'ready_to_sync';
  70. public const MEMO_STATUS_PENDING = 'pending';
  71. public const MEMO_READY_FOR_UPLOAD = 'ready_for_upload';
  72. public const MEMO_STATUS_UPLOADED = 'uploaded';
  73. // Export Unsorted Push related statuses
  74. public const EXPORT_UNSORTED_PUSH_STATUS_PENDING = 'export_unsorted_push.pending';
  75. public const EXPORT_UNSORTED_PUSH_STATUS_IN_PROGRESS = 'export_unsorted_push.in_progress';
  76. public const EXPORT_UNSORTED_PUSH_STATUS_COMPLETED = 'export_unsorted_push.completed';
  77. public const EXPORT_UNSORTED_PUSH_STATUS_FAILED = 'export_unsorted_push.failed';
  78. // Sort Session Type Options
  79. public const SORT_SESSION_TYPE_CLIENT = 'type_client';
  80. public const SORT_SESSION_TYPE_CLIENT__LABEL = 'Client Session';
  81. public const SORT_SESSION_TYPE_MEDBRIEF = 'type_medbrief';
  82. public const SORT_SESSION_TYPE_MEDBRIEF__LABEL = 'Medbrief Session';
  83. /**
  84. * Unmapped field used to indicate if a notification should be sent
  85. *
  86. * @var bool
  87. */
  88. public $sendNotification = false;
  89. /**
  90. * @var int
  91. *
  92. * @ORM\Column(name="id", type="integer")
  93. *
  94. * @ORM\Id
  95. *
  96. * @ORM\GeneratedValue(strategy="IDENTITY")
  97. */
  98. protected $id;
  99. /**
  100. * @var \DateTime|null
  101. *
  102. * @ORM\Column(name="deletedAt", type="datetime", nullable=true)
  103. */
  104. protected $deletedAt;
  105. /**
  106. * @var \DateTime
  107. *
  108. * @ORM\Column(name="created", type="datetime")
  109. *
  110. * @Gedmo\Timestampable(on="create")
  111. */
  112. protected $created;
  113. /**
  114. * @var \DateTime
  115. *
  116. * @ORM\Column(name="updated", type="datetime")
  117. *
  118. * @Gedmo\Timestampable(on="update")
  119. */
  120. protected $updated;
  121. /**
  122. * @var string|null
  123. *
  124. * @ORM\Column(name="storeData", type="text", nullable=true)
  125. */
  126. protected $storeData;
  127. /**
  128. * @var string|null
  129. *
  130. * @ORM\Column(name="exportStoreJson", type="text", nullable=true)
  131. */
  132. protected $exportStoreJson;
  133. /**
  134. * @var int|null
  135. *
  136. * @ORM\Column(name="sessionStatus", type="integer", nullable=true)
  137. */
  138. protected $sessionStatus = self::SESSION_STATUS_PENDING;
  139. /**
  140. * @var int|null
  141. *
  142. * @ORM\Column(name="sortStatus", type="integer", nullable=true)
  143. */
  144. protected $sortStatus = self::SORT_STATUS_CLASSIFY;
  145. /**
  146. * @var string|null
  147. *
  148. * @ORM\Column(name="archiveFilename", type="string", nullable=true)
  149. */
  150. protected $archiveFilename;
  151. /**
  152. * @var int|null
  153. *
  154. * @ORM\Column(name="paginationStrategy", type="integer", nullable=true)
  155. */
  156. protected $paginationStrategy;
  157. /**
  158. * @var string|null
  159. *
  160. * @ORM\Column(name="paginationPrefix", type="string", nullable=true)
  161. */
  162. protected $paginationPrefix;
  163. /**
  164. * @var int|null
  165. *
  166. * @ORM\Column(name="centrePrefix", type="integer", nullable=true)
  167. */
  168. protected $centrePrefix;
  169. /**
  170. * @var int
  171. *
  172. * @ORM\Column(name="centrePrefixPadding", type="integer", options={"default"="3"})
  173. */
  174. protected $centrePrefixPadding = 3;
  175. /**
  176. * @var int
  177. *
  178. * @ORM\Column(name="pageNumberPadding", type="integer", options={"default"="4"})
  179. */
  180. protected $pageNumberPadding = 4;
  181. /**
  182. * @var int
  183. *
  184. * @ORM\Column(name="pageNumberPositionHorizontal", type="integer", options={"default"="3"})
  185. */
  186. protected $pageNumberPositionHorizontal = Sort::PAGE_NUMBER_POSITION_HORIZONTAL_RIGHT;
  187. /**
  188. * @var int
  189. *
  190. * @ORM\Column(name="pageNumberPositionVertical", type="integer", options={"default"="2"})
  191. */
  192. protected $pageNumberPositionVertical = Sort::PAGE_NUMBER_POSITION_VERTICAL_BOTTOM;
  193. /**
  194. * @var int
  195. *
  196. * @ORM\Column(name="pageNumberSize", type="integer", options={"default"="20"})
  197. */
  198. protected $pageNumberSize = Sort::PAGE_NUMBER_SIZE_20;
  199. /**
  200. * @var bool
  201. *
  202. * @ORM\Column(name="pageNumberBackground", type="boolean", options={"default"=false})
  203. */
  204. protected $pageNumberBackground = Sort::PAGE_NUMBER_BACKGROUND_NO;
  205. /**
  206. * @var int
  207. *
  208. * @ORM\Column(name="timeSpentClassify", type="integer", options={"default"="0"})
  209. */
  210. protected $timeSpentClassify = 0;
  211. /**
  212. * @var int
  213. *
  214. * @ORM\Column(name="timeSpentDating", type="integer", options={"default"="0"})
  215. */
  216. protected $timeSpentDating = 0;
  217. /**
  218. * @var int
  219. *
  220. * @ORM\Column(name="timeSpentAdmission", type="integer", options={"default"="0"})
  221. */
  222. protected $timeSpentAdmission = 0;
  223. /**
  224. * @var int
  225. *
  226. * @ORM\Column(name="timeSpentMemo", type="integer", options={"default"="0"})
  227. */
  228. protected $timeSpentMemo = 0;
  229. /**
  230. * @var int
  231. *
  232. * @ORM\Column(name="timeSpentQa", type="integer", options={"default"="0"})
  233. */
  234. protected $timeSpentQa = 0;
  235. /**
  236. * @var \DateTime|null
  237. *
  238. * @ORM\Column(name="dateSentToSorter", type="datetime", nullable=true)
  239. */
  240. protected $dateSentToSorter;
  241. /**
  242. * @var \DateTime|null
  243. *
  244. * @ORM\Column(name="dueDate", type="datetime", nullable=true)
  245. */
  246. protected $dueDate;
  247. /**
  248. * @var \DateTime|null
  249. *
  250. * @ORM\Column(name="estCompletionDate", type="datetime", nullable=true)
  251. */
  252. protected $estCompletionDate;
  253. /**
  254. * @var \DateTime|null
  255. *
  256. * @ORM\Column(name="dateDownloaded", type="datetime", nullable=true)
  257. */
  258. protected $dateDownloaded;
  259. /**
  260. * @var string|null
  261. *
  262. * @ORM\Column(name="mrsFormFilename", type="string", length=255, nullable=true)
  263. */
  264. protected $mrsFormFilename;
  265. /**
  266. * @var int
  267. *
  268. * @ORM\Column(name="startPageNumber", type="integer", options={"default"="1"})
  269. */
  270. protected $startPageNumber = 1;
  271. /**
  272. * @var int|null
  273. *
  274. * @ORM\Column(name="classifyCompletePerc", type="integer", nullable=true)
  275. */
  276. protected $classifyCompletePerc;
  277. /**
  278. * @var int|null
  279. *
  280. * @ORM\Column(name="dateCompletePerc", type="integer", nullable=true)
  281. */
  282. protected $dateCompletePerc;
  283. /**
  284. * @var string|null
  285. *
  286. * @ORM\Column(name="exportError", type="text", nullable=true)
  287. */
  288. protected $exportError;
  289. /**
  290. * @var string|null
  291. *
  292. * @ORM\Column(name="version", type="string", nullable=true)
  293. */
  294. protected $version;
  295. /**
  296. * @var string|null
  297. *
  298. * @ORM\Column(name="exportPushStatus", type="string", nullable=true)
  299. */
  300. protected $exportPushStatus;
  301. /**
  302. * @var string|null
  303. *
  304. * @ORM\Column(name="memoStatus", type="string", nullable=true)
  305. */
  306. protected $memoStatus;
  307. /**
  308. * @var string|null
  309. *
  310. * @ORM\Column(name="qaFailNote", type="text", nullable=true)
  311. */
  312. protected $qaFailNote;
  313. /**
  314. * @var string|null
  315. *
  316. * @ORM\Column(name="exportPushUnsortedStatus", type="string", nullable=true)
  317. */
  318. protected $exportPushUnsortedStatus;
  319. /**
  320. * @var string|null
  321. *
  322. * @ORM\Column(name="sortSessionType", type="string", nullable=true)
  323. */
  324. protected $sortSessionType;
  325. /**
  326. * @var bool
  327. *
  328. * @ORM\Column(name="isUrgent", type="boolean", options={"default"=false})
  329. */
  330. protected $isUrgent = false;
  331. /**
  332. * Indicates if the SortingSession should be sent for pre-processing (AI processing).
  333. *
  334. * @var bool
  335. *
  336. * @ORM\Column(type="boolean", options={"default"=false})
  337. */
  338. protected $requiresPreProcessing = false;
  339. /**
  340. * @var Collection
  341. *
  342. * @ORM\OneToMany(targetEntity="MedBrief\MSR\Entity\BatchRequest", mappedBy="sortingSession", cascade={"persist"})
  343. */
  344. protected $batchRequests;
  345. /**
  346. * @var Collection
  347. *
  348. * @ORM\OneToMany(targetEntity="MedBrief\MSR\Entity\SortingSessionDetail", mappedBy="sortingSession", cascade={"persist","remove"}, orphanRemoval=true)
  349. */
  350. protected $details;
  351. /**
  352. * @var Collection
  353. *
  354. * @ORM\OneToMany(targetEntity="MedBrief\MSR\Entity\SortingSessionMemo", mappedBy="sortingSession", cascade={"persist","remove"}, orphanRemoval=true)
  355. */
  356. protected $sortingSessionMemos;
  357. /**
  358. * @var Project
  359. *
  360. * @ORM\ManyToOne(targetEntity="MedBrief\MSR\Entity\Project", inversedBy="sortingSessions")
  361. *
  362. * @ORM\JoinColumns({
  363. *
  364. * @ORM\JoinColumn(name="project_id", referencedColumnName="id")
  365. * })
  366. */
  367. protected $project;
  368. /**
  369. * @ORM\ManyToOne(targetEntity="MedBrief\MSR\Entity\User")
  370. *
  371. * @var User
  372. */
  373. protected $validatedBy;
  374. /**
  375. * @var User
  376. *
  377. * @ORM\ManyToOne(targetEntity="MedBrief\MSR\Entity\User")
  378. *
  379. * @ORM\JoinColumns({
  380. *
  381. * @ORM\JoinColumn(name="sortedBy_id", referencedColumnName="id")
  382. * })
  383. */
  384. protected $sortedBy;
  385. /**
  386. * @var User
  387. *
  388. * @ORM\ManyToOne(targetEntity="MedBrief\MSR\Entity\User")
  389. *
  390. * @ORM\JoinColumns({
  391. *
  392. * @ORM\JoinColumn(name="datedBy_id", referencedColumnName="id")
  393. * })
  394. */
  395. protected $datedBy;
  396. /**
  397. * @var User
  398. *
  399. * @ORM\ManyToOne(targetEntity="MedBrief\MSR\Entity\User")
  400. *
  401. * @ORM\JoinColumns({
  402. *
  403. * @ORM\JoinColumn(name="admissionBy_id", referencedColumnName="id")
  404. * })
  405. */
  406. protected $admissionBy;
  407. /**
  408. * @var User
  409. *
  410. * @ORM\ManyToOne(targetEntity="MedBrief\MSR\Entity\User")
  411. *
  412. * @ORM\JoinColumns({
  413. *
  414. * @ORM\JoinColumn(name="memoBy_id", referencedColumnName="id")
  415. * })
  416. */
  417. protected $memoBy;
  418. /**
  419. * @var User
  420. *
  421. * @ORM\ManyToOne(targetEntity="MedBrief\MSR\Entity\User")
  422. *
  423. * @ORM\JoinColumns({
  424. *
  425. * @ORM\JoinColumn(name="qaBy_id", referencedColumnName="id")
  426. * })
  427. */
  428. protected $qaBy;
  429. /**
  430. * @var User
  431. *
  432. * @ORM\ManyToOne(targetEntity="MedBrief\MSR\Entity\User")
  433. *
  434. * @ORM\JoinColumns({
  435. *
  436. * @ORM\JoinColumn(name="downloadedBy_id", referencedColumnName="id")
  437. * })
  438. */
  439. protected $downloadedBy;
  440. /**
  441. * @var User
  442. *
  443. * @ORM\ManyToOne(targetEntity="MedBrief\MSR\Entity\User")
  444. *
  445. * @ORM\JoinColumns({
  446. *
  447. * @ORM\JoinColumn(name="exportPushBy_id", referencedColumnName="id")
  448. * })
  449. */
  450. protected $exportPushBy;
  451. /**
  452. * @var User
  453. *
  454. * @ORM\ManyToOne(targetEntity="MedBrief\MSR\Entity\User")
  455. *
  456. * @ORM\JoinColumns({
  457. *
  458. * @ORM\JoinColumn(name="exportPushUnsortedBy_id", referencedColumnName="id")
  459. * })
  460. */
  461. protected $exportPushUnsortedBy;
  462. /**
  463. * @var User
  464. *
  465. * @ORM\ManyToOne(targetEntity="MedBrief\MSR\Entity\User")
  466. *
  467. * @ORM\JoinColumns({
  468. *
  469. * @ORM\JoinColumn(name="activeSortingUser_id", referencedColumnName="id")
  470. * })
  471. */
  472. protected $activeSortingUser;
  473. /**
  474. * @var string
  475. */
  476. protected $mrsFormFile;
  477. /**
  478. * @var string
  479. */
  480. protected $chronologyRequired;
  481. /**
  482. * Constructor
  483. *
  484. * @param null|MatterRequest $matterRequest
  485. */
  486. public function __construct(?MatterRequest $matterRequest = null)
  487. {
  488. $this->batchRequests = new ArrayCollection();
  489. $this->details = new ArrayCollection();
  490. $this->sortingSessionMemos = new ArrayCollection();
  491. // If there was a sort requested on the matter request
  492. if ($matterRequest && $matterRequest->getServiceSelectionDetails() && $matterRequest->getServiceSelectionDetails()->isSortChoiceYes() && $matterRequest->getSortDetails()) {
  493. $this->mapPaginationOptions($matterRequest->getSortDetails());
  494. }
  495. }
  496. /**
  497. * __toString
  498. *
  499. * @return string
  500. */
  501. public function __toString()
  502. {
  503. return (string) $this->getId();
  504. }
  505. /**
  506. * Get id
  507. *
  508. * @return int
  509. */
  510. public function getId(): ?int
  511. {
  512. return $this->id;
  513. }
  514. /**
  515. * Set created
  516. *
  517. * @param \DateTime $created
  518. *
  519. * @return SortingSession
  520. */
  521. public function setCreated($created)
  522. {
  523. $this->created = $created;
  524. return $this;
  525. }
  526. /**
  527. * Get created
  528. *
  529. * @return \DateTime
  530. */
  531. public function getCreated()
  532. {
  533. return $this->created;
  534. }
  535. /**
  536. * Set updated
  537. *
  538. * @param \DateTime $updated
  539. *
  540. * @return SortingSession
  541. */
  542. public function setUpdated($updated)
  543. {
  544. $this->updated = $updated;
  545. return $this;
  546. }
  547. /**
  548. * Get updated
  549. *
  550. * @return \DateTime
  551. */
  552. public function getUpdated()
  553. {
  554. return $this->updated;
  555. }
  556. /**
  557. * Set storeData
  558. *
  559. * @param string $storeData
  560. *
  561. * @return SortingSession
  562. */
  563. public function setStoreData($storeData)
  564. {
  565. $this->storeData = $storeData;
  566. return $this;
  567. }
  568. /**
  569. * Get storeData
  570. *
  571. * @return string
  572. */
  573. public function getStoreData()
  574. {
  575. return $this->storeData;
  576. }
  577. /**
  578. * Get storeDataArray
  579. *
  580. * @return array
  581. */
  582. public function getStoreDataArray()
  583. {
  584. if (!$this->getStoreData()) {
  585. return [];
  586. }
  587. return json_decode($this->getStoreData(), true);
  588. }
  589. /**
  590. * Set sessionStatus
  591. *
  592. * @param int $sessionStatus
  593. *
  594. * @return SortingSession
  595. */
  596. public function setSessionStatus($sessionStatus)
  597. {
  598. // Clear the export error when we do a new export. Clear the push status when we do a new export.
  599. if ($sessionStatus === self::SESSION_STATUS_EXPORT_PENDING) {
  600. $this->setExportError('');
  601. $this->setExportPushStatus(null);
  602. }
  603. $this->sessionStatus = $sessionStatus;
  604. return $this;
  605. }
  606. /**
  607. * Get sessionStatus
  608. *
  609. * @return int
  610. */
  611. public function getSessionStatus()
  612. {
  613. return $this->sessionStatus;
  614. }
  615. /**
  616. * Return true if SortingSession is paused
  617. *
  618. * @return bool
  619. */
  620. public function isPaused()
  621. {
  622. return $this->sessionStatus === self::SESSION_STATUS_PAUSED;
  623. }
  624. /**
  625. * Return true if SortingSession is in progress
  626. *
  627. * @return bool
  628. */
  629. public function isInProgress()
  630. {
  631. return $this->sessionStatus === self::SESSION_STATUS_IN_PROGRESS || $this->getActiveSortingUser() !== null;
  632. }
  633. /**
  634. * Return true if SortingSession is busy preparing for the sorter
  635. *
  636. * @return bool
  637. */
  638. public function isPreparing()
  639. {
  640. return $this->sessionStatus === self::SESSION_STATUS_PREPARE_PENDING || $this->sessionStatus === self::SESSION_STATUS_PREPARE_IN_PROGRESS;
  641. }
  642. /**
  643. * Return true if SortingSession is pending
  644. *
  645. * @return bool
  646. */
  647. public function isPending()
  648. {
  649. return $this->sessionStatus === self::SESSION_STATUS_PENDING;
  650. }
  651. /**
  652. * Return true if SortingSession is prepare failed
  653. *
  654. * @return bool
  655. */
  656. public function isPrepareFailed()
  657. {
  658. return $this->sessionStatus === self::SESSION_STATUS_PREPARE_FAILED;
  659. }
  660. /**
  661. * Return true if SortingSession is ready for sorter
  662. *
  663. * @return bool
  664. */
  665. public function isReadyForSorter()
  666. {
  667. return $this->sessionStatus === self::SESSION_STATUS_READY_FOR_SORTER;
  668. }
  669. /**
  670. * Return true if SortingSession is missing pages
  671. *
  672. * @return bool
  673. */
  674. public function isMissingPages()
  675. {
  676. return $this->sessionStatus === self::SESSION_STATUS_PAGES_MISSING;
  677. }
  678. /**
  679. * Return true if SortingSession export is pending
  680. *
  681. * @return bool
  682. */
  683. public function isExportPending()
  684. {
  685. return $this->sessionStatus === self::SESSION_STATUS_EXPORT_PENDING;
  686. }
  687. /**
  688. * Return true if SortingSession export is in progress
  689. *
  690. * @return bool
  691. */
  692. public function isExportInProgress()
  693. {
  694. return $this->sessionStatus === self::SESSION_STATUS_EXPORT_IN_PROGRESS;
  695. }
  696. /**
  697. * Return true if SortingSession export completed
  698. *
  699. * @return bool
  700. */
  701. public function isExportCompleted()
  702. {
  703. return $this->sessionStatus === self::SESSION_STATUS_EXPORT_COMPLETED;
  704. }
  705. /**
  706. * Return true if SortingSession export failed
  707. *
  708. * @return bool
  709. */
  710. public function isExportFailed()
  711. {
  712. return $this->sessionStatus === self::SESSION_STATUS_EXPORT_FAILED;
  713. }
  714. /**
  715. * @return bool
  716. */
  717. public function isPreprocessingPending()
  718. {
  719. return $this->sessionStatus === self::SESSION_STATUS_PREPROCESSING_PENDING;
  720. }
  721. /**
  722. * @return bool
  723. */
  724. public function isPreprocessingFailed()
  725. {
  726. return $this->sessionStatus === self::SESSION_STATUS_PREPROCESSING_FAILED;
  727. }
  728. /**
  729. * @return bool
  730. */
  731. public function isPreprocessingInProgress()
  732. {
  733. return $this->sessionStatus === self::SESSION_STATUS_PREPROCESSING_IN_PROGRESS;
  734. }
  735. /**
  736. * @return bool
  737. */
  738. public function isPreprocessing(): bool
  739. {
  740. return in_array($this->getSessionStatus(), [
  741. self::SESSION_STATUS_PREPROCESSING_PENDING,
  742. self::SESSION_STATUS_PREPROCESSING_FAILED,
  743. self::SESSION_STATUS_PREPROCESSING_IN_PROGRESS,
  744. ]);
  745. }
  746. /**
  747. * Get sessionStatusOptions
  748. *
  749. * @param array $inclOnly
  750. *
  751. * @return array
  752. */
  753. public static function getSessionStatusOptions(array $inclOnly = [])
  754. {
  755. $options = [
  756. self::SESSION_STATUS_PENDING => 'Pending',
  757. self::SESSION_STATUS_READY_FOR_SORTER => 'Ready for Sorter',
  758. self::SESSION_STATUS_IN_PROGRESS => 'In Progress',
  759. self::SESSION_STATUS_PAUSED => 'Paused',
  760. self::SESSION_STATUS_PAGES_MISSING => 'Pages Missing',
  761. self::SESSION_STATUS_COMPLETED => 'Completed',
  762. self::SESSION_STATUS_PREPARE_PENDING => 'Send to Sorter',
  763. self::SESSION_STATUS_PREPARE_IN_PROGRESS => 'Preparing for Sorter',
  764. self::SESSION_STATUS_PREPARE_FAILED => 'Failed Preparing for Sorter',
  765. self::SESSION_STATUS_EXPORT_PENDING => 'Pending Export',
  766. self::SESSION_STATUS_EXPORT_IN_PROGRESS => 'Export In Progress',
  767. self::SESSION_STATUS_EXPORT_COMPLETED => 'Available To Download',
  768. self::SESSION_STATUS_EXPORT_FAILED => 'Failed Creating Archive',
  769. self::SESSION_STATUS_PREPROCESSING_PENDING => 'Pre-Processing - Pending',
  770. self::SESSION_STATUS_PREPROCESSING_IN_PROGRESS => 'Pre-Processing - In Progress',
  771. self::SESSION_STATUS_PREPROCESSING_FAILED => 'Pre-Processing - Failed',
  772. ];
  773. if ($inclOnly) {
  774. $options = array_filter($options, function ($key) use ($inclOnly) {
  775. return in_array($key, $inclOnly);
  776. }, \ARRAY_FILTER_USE_KEY);
  777. }
  778. return $options;
  779. }
  780. /**
  781. * Get sessionStatusLabel
  782. *
  783. * @return string
  784. */
  785. public function getSessionStatusLabel()
  786. {
  787. $options = self::getSessionStatusOptions();
  788. return $options[$this->getSessionStatus()] ?? '';
  789. }
  790. /**
  791. * Add batchRequest
  792. *
  793. * @param BatchRequest $batchRequest
  794. *
  795. * @return SortingSession
  796. */
  797. public function addBatchRequest(BatchRequest $batchRequest)
  798. {
  799. $batchRequest->setSortingSession($this);
  800. $this->batchRequests[] = $batchRequest;
  801. return $this;
  802. }
  803. /**
  804. * Remove batchRequest
  805. *
  806. * @param BatchRequest $batchRequest
  807. */
  808. public function removeBatchRequest(BatchRequest $batchRequest)
  809. {
  810. $batchRequest->setSortingSession(null);
  811. $this->batchRequests->removeElement($batchRequest);
  812. }
  813. /**
  814. * Get batchRequests
  815. *
  816. * @return BatchRequest[] | ArrayCollection
  817. */
  818. public function getBatchRequests()
  819. {
  820. return $this->batchRequests;
  821. }
  822. /**
  823. * Gets the total page count for the SortingSession.
  824. *
  825. * @return int
  826. */
  827. public function getPageCount()
  828. {
  829. return array_reduce($this->getBatchRequests()->toArray(), function ($pageCount, BatchRequest $batchRequest) {
  830. return $batchRequest->getPages()->count() + $pageCount;
  831. }, 0);
  832. }
  833. /**
  834. * Get batchRequests as a list of request IDs
  835. *
  836. * @return string
  837. */
  838. public function getBatchRequestsCsv()
  839. {
  840. return implode(', ', array_map(function (BatchRequest $batchRequest) {
  841. return $batchRequest->getServiceRequestGroupId();
  842. }, $this->getBatchRequests()->toArray()));
  843. }
  844. /**
  845. * @return string
  846. */
  847. public function getPreprocessDocumentsCsv()
  848. {
  849. $preprocessDocumentsCsv = '';
  850. foreach ($this->getPreprocessItems() as $preprocessItem) {
  851. foreach ($preprocessItem->getPreprocessDocumentsArray() as $preprocessDocument) {
  852. if ($preprocessDocument->isIgnore() === false) {
  853. $preprocessDocumentsCsv .= sprintf('%1$s(%2$s), ', $preprocessDocument->getId(), $preprocessDocument->getStatusLabel());
  854. }
  855. }
  856. }
  857. return trim($preprocessDocumentsCsv, ', ');
  858. }
  859. /**
  860. * Set project
  861. *
  862. * @param Project $project
  863. *
  864. * @return SortingSession
  865. */
  866. public function setProject(?Project $project = null)
  867. {
  868. $this->project = $project;
  869. return $this;
  870. }
  871. /**
  872. * Get project
  873. *
  874. * @return Project
  875. */
  876. public function getProject()
  877. {
  878. return $this->project;
  879. }
  880. /**
  881. * @param User $validatedBy
  882. *
  883. * @return self
  884. */
  885. public function setValidatedBy(?User $validatedBy = null): self
  886. {
  887. $this->validatedBy = $validatedBy;
  888. return $this;
  889. }
  890. /**
  891. * Get validatedBy
  892. *
  893. * @return User|null
  894. */
  895. public function getValidatedBy(): ?User
  896. {
  897. return $this->validatedBy;
  898. }
  899. /**
  900. * Set sortedBy
  901. *
  902. * @param User $sortedBy
  903. *
  904. * @return SortingSession
  905. */
  906. public function setSortedBy(?User $sortedBy = null)
  907. {
  908. $this->sortedBy = $sortedBy;
  909. return $this;
  910. }
  911. /**
  912. * Get sortedBy
  913. *
  914. * @return User
  915. */
  916. public function getSortedBy()
  917. {
  918. return $this->sortedBy;
  919. }
  920. /**
  921. * Set datedBy
  922. *
  923. * @param User $datedBy
  924. *
  925. * @return SortingSession
  926. */
  927. public function setDatedBy(?User $datedBy = null)
  928. {
  929. $this->datedBy = $datedBy;
  930. return $this;
  931. }
  932. /**
  933. * Get datedBy
  934. *
  935. * @return User
  936. */
  937. public function getDatedBy()
  938. {
  939. return $this->datedBy;
  940. }
  941. /**
  942. * Set qaBy
  943. *
  944. * @param User $qaBy
  945. *
  946. * @return SortingSession
  947. */
  948. public function setQaBy(?User $qaBy = null)
  949. {
  950. $this->qaBy = $qaBy;
  951. return $this;
  952. }
  953. /**
  954. * Get qaBy
  955. *
  956. * @return User
  957. */
  958. public function getQaBy()
  959. {
  960. return $this->qaBy;
  961. }
  962. /**
  963. * Get all the statuses that a SortingSession may be in in order for it to be deleted
  964. *
  965. * @return array
  966. */
  967. public static function getDeletableStatuses()
  968. {
  969. return [
  970. self::SESSION_STATUS_PENDING,
  971. self::SESSION_STATUS_COMPLETED,
  972. self::SESSION_STATUS_PAUSED,
  973. self::SESSION_STATUS_PAGES_MISSING,
  974. self::SESSION_STATUS_PREPARE_FAILED,
  975. ];
  976. }
  977. /**
  978. * Get all the statuses that a SortingSession may be in in order to accept additional BatchRequests
  979. *
  980. * @return array
  981. */
  982. public static function getBatchAddableStatuses()
  983. {
  984. return [
  985. self::SESSION_STATUS_PENDING,
  986. self::SESSION_STATUS_READY_FOR_SORTER,
  987. self::SESSION_STATUS_PAUSED,
  988. self::SESSION_STATUS_PAGES_MISSING,
  989. self::SESSION_STATUS_COMPLETED,
  990. self::SESSION_STATUS_PREPARE_FAILED,
  991. self::SESSION_STATUS_EXPORT_COMPLETED,
  992. ];
  993. }
  994. /**
  995. * Get all the statuses that a SortingSession may be in in order to delete associated BatchRequests
  996. *
  997. * @return array
  998. */
  999. public static function getBatchDeletableStatuses()
  1000. {
  1001. return [
  1002. self::SESSION_STATUS_PENDING,
  1003. self::SESSION_STATUS_READY_FOR_SORTER,
  1004. self::SESSION_STATUS_PREPARE_FAILED,
  1005. self::SESSION_STATUS_PAUSED,
  1006. ];
  1007. }
  1008. /**
  1009. * Get all the statuses that a SortingSession would show in the doc sorter for.
  1010. *
  1011. * @return array
  1012. */
  1013. public static function getActiveStatuses()
  1014. {
  1015. return [
  1016. self::SESSION_STATUS_IN_PROGRESS,
  1017. self::SESSION_STATUS_READY_FOR_SORTER,
  1018. self::SESSION_STATUS_PAUSED,
  1019. ];
  1020. }
  1021. /**
  1022. * Returns true if the SortingSession is in a status that would render it visible in the
  1023. * document sorter.
  1024. *
  1025. * @return bool
  1026. */
  1027. public function hasActiveStatus()
  1028. {
  1029. return in_array($this->getSessionStatus(), self::getActiveStatuses());
  1030. }
  1031. /**
  1032. * Set archiveFilename
  1033. *
  1034. * @param string $archiveFilename
  1035. *
  1036. * @return SortingSession
  1037. */
  1038. public function setArchiveFilename($archiveFilename)
  1039. {
  1040. $this->archiveFilename = $archiveFilename;
  1041. return $this;
  1042. }
  1043. /**
  1044. * Get archiveFilename
  1045. *
  1046. * @return string
  1047. */
  1048. public function getArchiveFilename()
  1049. {
  1050. return $this->archiveFilename;
  1051. }
  1052. /**
  1053. * Set paginationStrategy
  1054. *
  1055. * @param int $paginationStrategy
  1056. *
  1057. * @return SortingSession
  1058. */
  1059. public function setPaginationStrategy($paginationStrategy)
  1060. {
  1061. $this->paginationStrategy = $paginationStrategy;
  1062. return $this;
  1063. }
  1064. /**
  1065. * Get paginationStrategy
  1066. *
  1067. * @return int
  1068. */
  1069. public function getPaginationStrategy()
  1070. {
  1071. return $this->paginationStrategy;
  1072. }
  1073. /**
  1074. * Set paginationPrefix
  1075. *
  1076. * @param string $paginationPrefix
  1077. *
  1078. * @return SortingSession
  1079. */
  1080. public function setPaginationPrefix($paginationPrefix)
  1081. {
  1082. $this->paginationPrefix = $paginationPrefix;
  1083. return $this;
  1084. }
  1085. /**
  1086. * Get paginationPrefix
  1087. *
  1088. * @return string
  1089. */
  1090. public function getPaginationPrefix()
  1091. {
  1092. return $this->paginationPrefix;
  1093. }
  1094. /**
  1095. * Returns an array of pagination strategies that are relative
  1096. *
  1097. * @return array
  1098. */
  1099. public static function getRelativePaginationStrategies()
  1100. {
  1101. return [
  1102. self::PAGINATION_STRATEGY_RELATIVE,
  1103. self::PAGINATION_STRATEGY_PREFIXED_RELATIVE,
  1104. ];
  1105. }
  1106. /**
  1107. * Returns an array of pagination strategies that are relative
  1108. *
  1109. * @return array
  1110. */
  1111. public static function getAbsolutePaginationStrategies()
  1112. {
  1113. return [
  1114. self::PAGINATION_STRATEGY_ABSOLUTE,
  1115. self::PAGINATION_STRATEGY_PREFIXED_ABSOLUTE,
  1116. ];
  1117. }
  1118. /**
  1119. * Returns an array of pagination strategies that are section based
  1120. *
  1121. * @return array
  1122. */
  1123. public static function getSectionPaginationStrategies()
  1124. {
  1125. return [
  1126. self::PAGINATION_STRATEGY_SECTION,
  1127. self::PAGINATION_STRATEGY_PREFIXED_SECTION,
  1128. ];
  1129. }
  1130. /**
  1131. * Returns an array of pagination strategies that are prefixed
  1132. *
  1133. * @return array
  1134. */
  1135. public static function getPrefixedPaginationStrategies()
  1136. {
  1137. return [
  1138. self::PAGINATION_STRATEGY_PREFIXED_ABSOLUTE,
  1139. self::PAGINATION_STRATEGY_PREFIXED_RELATIVE,
  1140. self::PAGINATION_STRATEGY_PREFIXED_SECTION,
  1141. ];
  1142. }
  1143. /**
  1144. * Get Pagination options
  1145. *
  1146. * @param array $inclOnly
  1147. *
  1148. * @return array
  1149. */
  1150. public static function getPaginationOptions(array $inclOnly = [])
  1151. {
  1152. $options = [
  1153. self::PAGINATION_STRATEGY_ABSOLUTE => 'Absolute Numbering',
  1154. self::PAGINATION_STRATEGY_RELATIVE => 'Relative Numbering',
  1155. self::PAGINATION_STRATEGY_SECTION => 'Section Numbering',
  1156. self::PAGINATION_STRATEGY_PREFIXED_ABSOLUTE => 'Absolute Numbering With Prefix',
  1157. self::PAGINATION_STRATEGY_PREFIXED_RELATIVE => 'Relative Numbering With Prefix',
  1158. self::PAGINATION_STRATEGY_PREFIXED_SECTION => 'Section Numbering With Prefix',
  1159. ];
  1160. if ($inclOnly) {
  1161. $options = array_filter($options, function ($key) use ($inclOnly) {
  1162. return in_array($key, $inclOnly);
  1163. }, \ARRAY_FILTER_USE_KEY);
  1164. }
  1165. return $options;
  1166. }
  1167. /**
  1168. * Checks to see if this Sorting Session has been completed
  1169. *
  1170. * @return bool
  1171. */
  1172. public function hasBeenCompleted()
  1173. {
  1174. return in_array($this->getSessionStatus(), [
  1175. self::SESSION_STATUS_COMPLETED,
  1176. self::SESSION_STATUS_EXPORT_PENDING,
  1177. self::SESSION_STATUS_EXPORT_IN_PROGRESS,
  1178. self::SESSION_STATUS_EXPORT_COMPLETED,
  1179. self::SESSION_STATUS_EXPORT_FAILED,
  1180. ]);
  1181. }
  1182. /**
  1183. * Checks to see if this Sorting Session has completed exporting.
  1184. *
  1185. * @return bool
  1186. */
  1187. public function hasBeenExported()
  1188. {
  1189. return in_array($this->getSessionStatus(), [
  1190. self::SESSION_STATUS_EXPORT_COMPLETED,
  1191. ]);
  1192. }
  1193. /**
  1194. * @return mixed
  1195. */
  1196. public function getCentrePrefix()
  1197. {
  1198. return $this->centrePrefix;
  1199. }
  1200. /**
  1201. * getActualCentrePrefix
  1202. *
  1203. * @return mixed
  1204. */
  1205. public function getActualCentrePrefix()
  1206. {
  1207. switch ($this->centrePrefix) {
  1208. case self::CENTRE_PREFIX_ALPHA:
  1209. return 'A';
  1210. break;
  1211. case self::CENTRE_PREFIX_NUMERIC:
  1212. return 1;
  1213. break;
  1214. default:
  1215. return 'A';
  1216. }
  1217. }
  1218. /**
  1219. * @param int $centrePrefix
  1220. *
  1221. * @return SortingSession
  1222. */
  1223. public function setCentrePrefix(?int $centrePrefix = null)
  1224. {
  1225. $this->centrePrefix = $centrePrefix;
  1226. return $this;
  1227. }
  1228. /**
  1229. * Get Centre Prefix options
  1230. *
  1231. * @param array $inclOnly
  1232. *
  1233. * @return array
  1234. */
  1235. public static function getCentrePrefixOptions(array $inclOnly = [])
  1236. {
  1237. $options = [
  1238. self::CENTRE_PREFIX_ALPHA => 'Alphabetical',
  1239. self::CENTRE_PREFIX_NUMERIC => 'Numerical',
  1240. ];
  1241. if ($inclOnly) {
  1242. $options = array_filter($options, function ($key) use ($inclOnly) {
  1243. return in_array($key, $inclOnly);
  1244. }, \ARRAY_FILTER_USE_KEY);
  1245. }
  1246. return $options;
  1247. }
  1248. /**
  1249. * Set sortStatus
  1250. *
  1251. * @param int $sortStatus
  1252. *
  1253. * @return SortingSession
  1254. */
  1255. public function setSortStatus($sortStatus)
  1256. {
  1257. $this->sortStatus = $sortStatus;
  1258. return $this;
  1259. }
  1260. /**
  1261. * Get sortStatus
  1262. *
  1263. * @return int
  1264. */
  1265. public function getSortStatus()
  1266. {
  1267. return $this->sortStatus;
  1268. }
  1269. /**
  1270. * Get sortStatusOptions
  1271. *
  1272. * @param mixed $showAdmission
  1273. * @param mixed $showMemo
  1274. *
  1275. * @return array
  1276. */
  1277. public static function getSortStatusOptions($showAdmission = true, $showMemo = true)
  1278. {
  1279. $options = [];
  1280. $options[self::SORT_STATUS_CLASSIFY] = 'Classify';
  1281. $options[self::SORT_STATUS_DATE] = 'Date';
  1282. if ($showAdmission) {
  1283. $options[self::SORT_STATUS_ADMISSION] = 'Admission';
  1284. }
  1285. if ($showMemo) {
  1286. $options[self::SORT_STATUS_MEMO] = 'File Note';
  1287. }
  1288. $options[self::SORT_STATUS_QA] = 'QA';
  1289. $options[self::SORT_STATUS_COMPLETE] = 'Complete';
  1290. $options[self::SORT_STATUS_DOWNLOADED] = 'Downloaded';
  1291. return $options;
  1292. }
  1293. /**
  1294. * Get sortStatusLabel
  1295. *
  1296. * @return string
  1297. */
  1298. public function getSortStatusLabel()
  1299. {
  1300. $options = self::getSortStatusOptions();
  1301. return $options[$this->getSortStatus()] ?? '';
  1302. }
  1303. /**
  1304. * Returns true if the SortingSession's sort status is self::SORT_STATUS_CLASSIFY
  1305. *
  1306. * @return bool
  1307. */
  1308. public function isSortStatusClassify()
  1309. {
  1310. return $this->getSortStatus() === self::SORT_STATUS_CLASSIFY;
  1311. }
  1312. /**
  1313. * Returns true if the SortingSession's sort status is self::SORT_STATUS_DATE
  1314. *
  1315. * @return bool
  1316. */
  1317. public function isSortStatusDate()
  1318. {
  1319. return $this->getSortStatus() === self::SORT_STATUS_DATE;
  1320. }
  1321. /**
  1322. * Returns true if the SortingSession's sort status is self::SORT_STATUS_ADMISSION
  1323. *
  1324. * @return bool
  1325. */
  1326. public function isSortStatusAdmission()
  1327. {
  1328. return $this->getSortStatus() === self::SORT_STATUS_ADMISSION;
  1329. }
  1330. /**
  1331. * Returns true if the SortingSession's sort status is self::SORT_STATUS_MEMO
  1332. *
  1333. * @return bool
  1334. */
  1335. public function isSortStatusMemo()
  1336. {
  1337. return $this->getSortStatus() === self::SORT_STATUS_MEMO;
  1338. }
  1339. /**
  1340. * Returns true if the SortingSession's sort status is self::SORT_STATUS_QA
  1341. *
  1342. * @return bool
  1343. */
  1344. public function isSortStatusQa()
  1345. {
  1346. return $this->getSortStatus() === self::SORT_STATUS_QA;
  1347. }
  1348. /**
  1349. * Returns true if the SortingSession's sort status is self::SORT_STATUS_COMPLETE
  1350. *
  1351. * @return bool
  1352. */
  1353. public function isSortStatusComplete()
  1354. {
  1355. return $this->getSortStatus() === self::SORT_STATUS_COMPLETE;
  1356. }
  1357. /**
  1358. * Returns true if the SortingSession's sort status is self::SORT_STATUS_COMPLETE
  1359. *
  1360. * @return bool
  1361. */
  1362. public function isSortStatusDownloaded()
  1363. {
  1364. return $this->getSortStatus() === self::SORT_STATUS_DOWNLOADED;
  1365. }
  1366. /**
  1367. * Returns true if the SortingSession has the relevant user assigned to it,
  1368. * based on it's current sortStatus.
  1369. *
  1370. * @return bool
  1371. */
  1372. public function hasRelevantUserAssigned()
  1373. {
  1374. return $this->getRelevantUserAssigned() !== null ? true : false;
  1375. }
  1376. /**
  1377. * Gets the relevant user responsible for this sorting session based on the
  1378. * SortStatus the SortingSession is in.
  1379. *
  1380. * @return User
  1381. */
  1382. public function getRelevantUserAssigned()
  1383. {
  1384. switch ($this->getSortStatus()) {
  1385. case self::SORT_STATUS_CLASSIFY:
  1386. return $this->getSortedBy();
  1387. break;
  1388. case self::SORT_STATUS_DATE:
  1389. return $this->getDatedBy();
  1390. break;
  1391. case self::SORT_STATUS_ADMISSION:
  1392. return $this->getAdmissionBy();
  1393. break;
  1394. case self::SORT_STATUS_MEMO:
  1395. return $this->getMemoBy();
  1396. break;
  1397. case self::SORT_STATUS_QA:
  1398. return $this->getQaBy();
  1399. break;
  1400. }
  1401. return null;
  1402. }
  1403. /**
  1404. * Gets an array of all the assigned Users to this SortingSession
  1405. *
  1406. * @return array
  1407. */
  1408. public function getAllAssignedUsers(): array
  1409. {
  1410. return [
  1411. 'Sort' => $this->getSortedBy(),
  1412. 'Date' => $this->getDatedBy(),
  1413. 'Admission' => $this->getAdmissionBy(),
  1414. 'File Note' => $this->getMemoBy(),
  1415. 'QA' => $this->getQaBy(),
  1416. ];
  1417. }
  1418. /**
  1419. * Set timeSpentClassify
  1420. *
  1421. * @param int $timeSpentClassify
  1422. *
  1423. * @return SortingSession
  1424. */
  1425. public function setTimeSpentClassify($timeSpentClassify)
  1426. {
  1427. $this->timeSpentClassify = $timeSpentClassify;
  1428. return $this;
  1429. }
  1430. /**
  1431. * Get timeSpentClassify
  1432. *
  1433. * @return int
  1434. */
  1435. public function getTimeSpentClassify()
  1436. {
  1437. return $this->timeSpentClassify;
  1438. }
  1439. /**
  1440. * Get timeSpentClassify
  1441. *
  1442. * @return int
  1443. */
  1444. public function getTimeSpentClassifyMinutes()
  1445. {
  1446. return round($this->getTimeSpentClassify() / 60, 2);
  1447. }
  1448. /**
  1449. * Set timeSpentDating
  1450. *
  1451. * @param int $timeSpentDating
  1452. *
  1453. * @return SortingSession
  1454. */
  1455. public function setTimeSpentDating($timeSpentDating)
  1456. {
  1457. $this->timeSpentDating = $timeSpentDating;
  1458. return $this;
  1459. }
  1460. /**
  1461. * Get timeSpentDating
  1462. *
  1463. * @return int
  1464. */
  1465. public function getTimeSpentDating()
  1466. {
  1467. return $this->timeSpentDating;
  1468. }
  1469. /**
  1470. * Get timeSpentDatingMinutes
  1471. *
  1472. * @return int
  1473. */
  1474. public function getTimeSpentDatingMinutes()
  1475. {
  1476. return round($this->getTimeSpentDating() / 60, 2);
  1477. }
  1478. /**
  1479. * Set timeSpentQa
  1480. *
  1481. * @param int $timeSpentQa
  1482. *
  1483. * @return SortingSession
  1484. */
  1485. public function setTimeSpentQa($timeSpentQa)
  1486. {
  1487. $this->timeSpentQa = $timeSpentQa;
  1488. return $this;
  1489. }
  1490. /**
  1491. * Get timeSpentQa
  1492. *
  1493. * @return int
  1494. */
  1495. public function getTimeSpentQa()
  1496. {
  1497. return $this->timeSpentQa;
  1498. }
  1499. /**
  1500. * Get timeSpentQaMinutes
  1501. *
  1502. * @return int
  1503. */
  1504. public function getTimeSpentQaMinutes()
  1505. {
  1506. return round($this->getTimeSpentQa() / 60, 2);
  1507. }
  1508. /**
  1509. * Add timeSpentClassify
  1510. *
  1511. * @param int $timeSpentClassify
  1512. *
  1513. * @return SortingSession
  1514. */
  1515. public function addTimeSpentClassify($timeSpentClassify)
  1516. {
  1517. $this->timeSpentClassify += $timeSpentClassify;
  1518. return $this;
  1519. }
  1520. /**
  1521. * Add timeSpentDating
  1522. *
  1523. * @param int $timeSpentDating
  1524. *
  1525. * @return SortingSession
  1526. */
  1527. public function addTimeSpentDating($timeSpentDating)
  1528. {
  1529. $this->timeSpentDating += $timeSpentDating;
  1530. return $this;
  1531. }
  1532. /**
  1533. * Add timeSpentAdmission
  1534. *
  1535. * @param int $timeSpentAdmission
  1536. *
  1537. * @return SortingSession
  1538. */
  1539. public function addTimeSpentAdmission($timeSpentAdmission)
  1540. {
  1541. $this->timeSpentAdmission += $timeSpentAdmission;
  1542. return $this;
  1543. }
  1544. /**
  1545. * Add timeSpentMemo
  1546. *
  1547. * @param int $timeSpentMemo
  1548. *
  1549. * @return SortingSession
  1550. */
  1551. public function addTimeSpentMemo($timeSpentMemo)
  1552. {
  1553. $this->timeSpentMemo += $timeSpentMemo;
  1554. return $this;
  1555. }
  1556. /**
  1557. * Add timeSpentQa
  1558. *
  1559. * @param int $timeSpentQa
  1560. *
  1561. * @return SortingSession
  1562. */
  1563. public function addTimeSpentQa($timeSpentQa)
  1564. {
  1565. $this->timeSpentQa += $timeSpentQa;
  1566. return $this;
  1567. }
  1568. /**
  1569. * Set deletedAt
  1570. *
  1571. * @param \DateTime $deletedAt
  1572. *
  1573. * @return SortingSession
  1574. */
  1575. public function setDeletedAt($deletedAt)
  1576. {
  1577. $this->deletedAt = $deletedAt;
  1578. return $this;
  1579. }
  1580. /**
  1581. * Get deletedAt
  1582. *
  1583. * @return \DateTime
  1584. */
  1585. public function getDeletedAt()
  1586. {
  1587. return $this->deletedAt;
  1588. }
  1589. /**
  1590. * Set dateSentToSorter
  1591. *
  1592. * @param \DateTime $dateSentToSorter
  1593. *
  1594. * @return SortingSession
  1595. */
  1596. public function setDateSentToSorter($dateSentToSorter = null)
  1597. {
  1598. $this->dateSentToSorter = $dateSentToSorter;
  1599. return $this;
  1600. }
  1601. /**
  1602. * Get dateSentToSorter
  1603. *
  1604. * @return \DateTime
  1605. */
  1606. public function getDateSentToSorter()
  1607. {
  1608. return $this->dateSentToSorter;
  1609. }
  1610. /**
  1611. * Set dateDownloaded
  1612. *
  1613. * @param \DateTime $dateDownloaded
  1614. *
  1615. * @return SortingSession
  1616. */
  1617. public function setDateDownloaded($dateDownloaded)
  1618. {
  1619. $this->dateDownloaded = $dateDownloaded;
  1620. return $this;
  1621. }
  1622. /**
  1623. * Get dateDownloaded
  1624. *
  1625. * @return \DateTime
  1626. */
  1627. public function getDateDownloaded()
  1628. {
  1629. return $this->dateDownloaded;
  1630. }
  1631. /**
  1632. * Set downloadedBy
  1633. *
  1634. * @param User $downloadedBy
  1635. *
  1636. * @return SortingSession
  1637. */
  1638. public function setDownloadedBy(?User $downloadedBy = null)
  1639. {
  1640. $this->downloadedBy = $downloadedBy;
  1641. return $this;
  1642. }
  1643. /**
  1644. * Get downloadedBy
  1645. *
  1646. * @return User
  1647. */
  1648. public function getDownloadedBy()
  1649. {
  1650. return $this->downloadedBy;
  1651. }
  1652. /**
  1653. * Get dueDate based on BatchRequest
  1654. *
  1655. * @return void
  1656. */
  1657. public function getBatchesMaxDueDate()
  1658. {
  1659. $criteria = Criteria::create()
  1660. ->orderBy(['estimatedDeadlineDate' => Criteria::DESC])
  1661. ;
  1662. return $this->getBatchRequests()->count() > 0 && $this->getBatchRequests()->matching($criteria)->first() ? $this->getBatchRequests()->matching($criteria)->first()->getEstimatedDeadlineDate() : null;
  1663. }
  1664. /**
  1665. * Get mrsFormFilename
  1666. *
  1667. * @return string
  1668. */
  1669. public function getMrsFormFilename()
  1670. {
  1671. return $this->mrsFormFilename;
  1672. }
  1673. /**
  1674. * Set mrsFormFile
  1675. *
  1676. * @param string $mrsFormFile
  1677. *
  1678. * @return SortingSession
  1679. */
  1680. public function setMrsFormFile($mrsFormFile)
  1681. {
  1682. $this->mrsFormFile = $mrsFormFile;
  1683. if (null !== $mrsFormFile) {
  1684. // It is required that at least one field changes if you are using doctrine
  1685. // otherwise the event listeners won't be called and the file is lost
  1686. $this->updated = new \DateTimeImmutable();
  1687. }
  1688. return $this;
  1689. }
  1690. /**
  1691. * Set mrsFormFilename
  1692. *
  1693. * @param string $mrsFormFilename
  1694. *
  1695. * @return SortingSession
  1696. */
  1697. public function setMrsFormFilename($mrsFormFilename)
  1698. {
  1699. $this->mrsFormFilename = $mrsFormFilename;
  1700. return $this;
  1701. }
  1702. /**
  1703. * Get mrsFormFile
  1704. *
  1705. * @return string
  1706. */
  1707. public function getMrsFormFile()
  1708. {
  1709. return $this->mrsFormFile;
  1710. }
  1711. /**
  1712. * Set dueDate
  1713. *
  1714. * @param \DateTime $dueDate
  1715. *
  1716. * @return SortingSession
  1717. */
  1718. public function setDueDate($dueDate)
  1719. {
  1720. $this->dueDate = $dueDate;
  1721. return $this;
  1722. }
  1723. /**
  1724. * Get dueDate
  1725. *
  1726. * @return \DateTime
  1727. */
  1728. public function getDueDate()
  1729. {
  1730. return $this->dueDate;
  1731. }
  1732. /**
  1733. * Set estCompletionDate
  1734. *
  1735. * @param \DateTime $estCompletionDate
  1736. *
  1737. * @return SortingSession
  1738. */
  1739. public function setEstCompletionDate($estCompletionDate)
  1740. {
  1741. $this->estCompletionDate = $estCompletionDate;
  1742. return $this;
  1743. }
  1744. /**
  1745. * Get estCompletionDate
  1746. *
  1747. * @return \DateTime
  1748. */
  1749. public function getEstCompletionDate()
  1750. {
  1751. return $this->estCompletionDate;
  1752. }
  1753. /**
  1754. * Set startPageNumber
  1755. *
  1756. * @param int $startPageNumber
  1757. *
  1758. * @return SortingSession
  1759. */
  1760. public function setStartPageNumber($startPageNumber)
  1761. {
  1762. $this->startPageNumber = $startPageNumber;
  1763. return $this;
  1764. }
  1765. /**
  1766. * Get startPageNumber
  1767. *
  1768. * @return int
  1769. */
  1770. public function getStartPageNumber()
  1771. {
  1772. return $this->startPageNumber;
  1773. }
  1774. /**
  1775. * Add detail
  1776. *
  1777. * @param SortingSessionDetail $detail
  1778. *
  1779. * @return SortingSession
  1780. */
  1781. public function addDetail(SortingSessionDetail $detail)
  1782. {
  1783. $this->details[] = $detail;
  1784. return $this;
  1785. }
  1786. /**
  1787. * Set classifyCompletePerc
  1788. *
  1789. * @param int $classifyCompletePerc
  1790. *
  1791. * @return SortingSession
  1792. */
  1793. public function setClassifyCompletePerc($classifyCompletePerc)
  1794. {
  1795. $this->classifyCompletePerc = $classifyCompletePerc;
  1796. return $this;
  1797. }
  1798. /**
  1799. * Remove detail
  1800. *
  1801. * @param SortingSessionDetail $detail
  1802. */
  1803. public function removeDetail(SortingSessionDetail $detail)
  1804. {
  1805. $this->details->removeElement($detail);
  1806. }
  1807. /**
  1808. * Get details
  1809. *
  1810. * @return Collection
  1811. */
  1812. public function getDetails()
  1813. {
  1814. return $this->details;
  1815. }
  1816. /**
  1817. * Get classifyCompletePerc
  1818. *
  1819. * @return int
  1820. */
  1821. public function getClassifyCompletePerc()
  1822. {
  1823. return $this->classifyCompletePerc;
  1824. }
  1825. /**
  1826. * Set dateCompletePerc
  1827. *
  1828. * @param int $dateCompletePerc
  1829. *
  1830. * @return SortingSession
  1831. */
  1832. public function setDateCompletePerc($dateCompletePerc)
  1833. {
  1834. $this->dateCompletePerc = $dateCompletePerc;
  1835. return $this;
  1836. }
  1837. /**
  1838. * Get dateCompletePerc
  1839. *
  1840. * @return int
  1841. */
  1842. public function getDateCompletePerc()
  1843. {
  1844. return $this->dateCompletePerc;
  1845. }
  1846. /**
  1847. * Set centrePrefixPadding
  1848. *
  1849. * @param int $centrePrefixPadding
  1850. *
  1851. * @return SortingSession
  1852. */
  1853. public function setCentrePrefixPadding($centrePrefixPadding)
  1854. {
  1855. $this->centrePrefixPadding = $centrePrefixPadding;
  1856. return $this;
  1857. }
  1858. /**
  1859. * Get centrePrefixPadding
  1860. *
  1861. * @return int
  1862. */
  1863. public function getCentrePrefixPadding()
  1864. {
  1865. return $this->centrePrefixPadding;
  1866. }
  1867. /**
  1868. * Set pageNumberPadding
  1869. *
  1870. * @param int $pageNumberPadding
  1871. *
  1872. * @return SortingSession
  1873. */
  1874. public function setPageNumberPadding($pageNumberPadding)
  1875. {
  1876. $this->pageNumberPadding = $pageNumberPadding;
  1877. return $this;
  1878. }
  1879. /**
  1880. * Get pageNumberPadding
  1881. *
  1882. * @return int
  1883. */
  1884. public function getPageNumberPadding()
  1885. {
  1886. return $this->pageNumberPadding;
  1887. }
  1888. /**
  1889. * Set exportError
  1890. *
  1891. * @param string $exportError
  1892. *
  1893. * @return SortingSession
  1894. */
  1895. public function setExportError($exportError)
  1896. {
  1897. $this->exportError = $exportError;
  1898. return $this;
  1899. }
  1900. /**
  1901. * Get exportError
  1902. *
  1903. * @return string
  1904. */
  1905. public function getExportError()
  1906. {
  1907. return $this->exportError;
  1908. }
  1909. /**
  1910. * Set admissionBy.
  1911. *
  1912. * @param User|null $admissionBy
  1913. *
  1914. * @return SortingSession
  1915. */
  1916. public function setAdmissionBy(?User $admissionBy = null)
  1917. {
  1918. $this->admissionBy = $admissionBy;
  1919. return $this;
  1920. }
  1921. /**
  1922. * Get admissionBy.
  1923. *
  1924. * @return User|null
  1925. */
  1926. public function getAdmissionBy()
  1927. {
  1928. return $this->admissionBy;
  1929. }
  1930. /**
  1931. * Set timeSpentAdmission.
  1932. *
  1933. * @param int $timeSpentAdmission
  1934. *
  1935. * @return SortingSession
  1936. */
  1937. public function setTimeSpentAdmission($timeSpentAdmission)
  1938. {
  1939. $this->timeSpentAdmission = $timeSpentAdmission;
  1940. return $this;
  1941. }
  1942. /**
  1943. * Get timeSpentAdmission.
  1944. *
  1945. * @return int
  1946. */
  1947. public function getTimeSpentAdmission()
  1948. {
  1949. return $this->timeSpentAdmission;
  1950. }
  1951. /**
  1952. * Get timeSpentAdmissionMinutes
  1953. *
  1954. * @return int
  1955. */
  1956. public function getTimeSpentAdmissionMinutes()
  1957. {
  1958. return round($this->getTimeSpentAdmission() / 60, 2);
  1959. }
  1960. /**
  1961. * Set exportStoreJson.
  1962. *
  1963. * @param string|null $exportStoreJson
  1964. *
  1965. * @return SortingSession
  1966. */
  1967. public function setExportStoreJson($exportStoreJson = null)
  1968. {
  1969. $this->exportStoreJson = $exportStoreJson;
  1970. return $this;
  1971. }
  1972. /**
  1973. * Get exportStoreJson.
  1974. *
  1975. * @return string|null
  1976. */
  1977. public function getExportStoreJson()
  1978. {
  1979. return $this->exportStoreJson;
  1980. }
  1981. /**
  1982. * Get getExportStoreArray
  1983. *
  1984. * @return array
  1985. */
  1986. public function getExportStoreArray()
  1987. {
  1988. if (!$this->getExportStoreJson()) {
  1989. return [];
  1990. }
  1991. return json_decode($this->getExportStoreJson(), true);
  1992. }
  1993. /**
  1994. * Set version.
  1995. *
  1996. * @param string|null $version
  1997. *
  1998. * @return SortingSession
  1999. */
  2000. public function setVersion($version = null)
  2001. {
  2002. $this->version = $version;
  2003. return $this;
  2004. }
  2005. /**
  2006. * Get version.
  2007. *
  2008. * @return string|null
  2009. */
  2010. public function getVersion()
  2011. {
  2012. return $this->version;
  2013. }
  2014. /**
  2015. * Returns true if the SortingSession was done in the old DocSorter version.
  2016. *
  2017. * @return bool
  2018. */
  2019. public function isOldVersion()
  2020. {
  2021. return $this->getVersion() === self::VERSION_OLD;
  2022. }
  2023. /**
  2024. * Set exportPushStatus.
  2025. *
  2026. * @param string|null $exportPushStatus
  2027. *
  2028. * @return SortingSession
  2029. */
  2030. public function setExportPushStatus($exportPushStatus = null)
  2031. {
  2032. // Clear the push error when we do a new push.
  2033. if ($exportPushStatus === self::EXPORT_PUSH_STATUS_PENDING) {
  2034. $this->setExportError('');
  2035. }
  2036. $this->exportPushStatus = $exportPushStatus;
  2037. return $this;
  2038. }
  2039. /**
  2040. * Get exportPushStatus.
  2041. *
  2042. * @return string|null
  2043. */
  2044. public function getExportPushStatus()
  2045. {
  2046. return $this->exportPushStatus;
  2047. }
  2048. /**
  2049. * Returns true if the SortingSession is pending export push to medical records.
  2050. *
  2051. * @return bool
  2052. */
  2053. public function isExportPushPending()
  2054. {
  2055. return $this->getExportPushStatus() === self::EXPORT_PUSH_STATUS_PENDING;
  2056. }
  2057. /**
  2058. * Returns true if the SortingSession is in progress export push to medical records.
  2059. *
  2060. * @return bool
  2061. */
  2062. public function isExportPushInProgress()
  2063. {
  2064. return $this->getExportPushStatus() === self::EXPORT_PUSH_STATUS_IN_PROGRESS;
  2065. }
  2066. /**
  2067. * Returns true if the SortingSession is completed export push to medical records.
  2068. *
  2069. * @return bool
  2070. */
  2071. public function isExportPushCompleted()
  2072. {
  2073. return $this->getExportPushStatus() === self::EXPORT_PUSH_STATUS_COMPLETED;
  2074. }
  2075. /**
  2076. * Returns true if the SortingSession is failed export push to medical records.
  2077. *
  2078. * @return bool
  2079. */
  2080. public function isExportPushFailed()
  2081. {
  2082. return $this->getExportPushStatus() === self::EXPORT_PUSH_STATUS_FAILED;
  2083. }
  2084. /**
  2085. * Set exportPushBy.
  2086. *
  2087. * @param User|null $exportPushBy
  2088. *
  2089. * @return SortingSession
  2090. */
  2091. public function setExportPushBy(?User $exportPushBy = null)
  2092. {
  2093. $this->exportPushBy = $exportPushBy;
  2094. return $this;
  2095. }
  2096. /**
  2097. * Get exportPushBy.
  2098. *
  2099. * @return User|null
  2100. */
  2101. public function getExportPushBy()
  2102. {
  2103. return $this->exportPushBy;
  2104. }
  2105. /**
  2106. * Set memoStatus.
  2107. *
  2108. * @param string|null $memoStatus
  2109. *
  2110. * @return SortingSession
  2111. */
  2112. public function setMemoStatus($memoStatus = null)
  2113. {
  2114. $this->memoStatus = $memoStatus;
  2115. return $this;
  2116. }
  2117. /**
  2118. * Get memoStatus.
  2119. *
  2120. * @return string|null
  2121. */
  2122. public function getMemoStatus()
  2123. {
  2124. return $this->memoStatus;
  2125. }
  2126. /**
  2127. * Get MemoStatusOptions
  2128. *
  2129. * @param bool $selectableOnly - only return options that can be selected by a user.
  2130. *
  2131. * @return array
  2132. */
  2133. public static function getMemoStatusOptions(bool $selectableOnly = false)
  2134. {
  2135. // Leave this in place, as previously Ready to Sync was part not selectable - but we had to change this,
  2136. $options = [
  2137. ];
  2138. $selectableOptions = [
  2139. self::MEMO_STATUS_READY_TO_SYNC => 'Ready to Sync',
  2140. self::MEMO_STATUS_PENDING => 'Pending',
  2141. self::MEMO_READY_FOR_UPLOAD => 'Ready for Upload',
  2142. self::MEMO_STATUS_UPLOADED => 'Uploaded',
  2143. ];
  2144. return array_merge($selectableOnly ? [] : $options, $selectableOptions);
  2145. }
  2146. /**
  2147. * Get MemoStatusLabel
  2148. *
  2149. * @return string
  2150. */
  2151. public function getMemoStatusLabel()
  2152. {
  2153. $options = self::getMemoStatusOptions();
  2154. return $options[$this->getMemoStatus()] ?? '';
  2155. }
  2156. /**
  2157. * Returns true if the memo status is ready to sync.
  2158. *
  2159. * @return string
  2160. */
  2161. public function isMemoReadyToSync()
  2162. {
  2163. return $this->getMemoStatus() === self::MEMO_STATUS_READY_TO_SYNC;
  2164. }
  2165. /**
  2166. * Set timeSpentMemo.
  2167. *
  2168. * @param int $timeSpentMemo
  2169. *
  2170. * @return SortingSession
  2171. */
  2172. public function setTimeSpentMemo($timeSpentMemo)
  2173. {
  2174. $this->timeSpentMemo = $timeSpentMemo;
  2175. return $this;
  2176. }
  2177. /**
  2178. * Get timeSpentMemo.
  2179. *
  2180. * @return int
  2181. */
  2182. public function getTimeSpentMemo()
  2183. {
  2184. return $this->timeSpentMemo;
  2185. }
  2186. /**
  2187. * Get timeSpentMemoMinutes
  2188. *
  2189. * @return int
  2190. */
  2191. public function getTimeSpentMemoMinutes()
  2192. {
  2193. return round($this->getTimeSpentMemo() / 60, 2);
  2194. }
  2195. /**
  2196. * Set qaFailNote.
  2197. *
  2198. * @param string|null $qaFailNote
  2199. *
  2200. * @return SortingSession
  2201. */
  2202. public function setQaFailNote($qaFailNote = null)
  2203. {
  2204. $this->qaFailNote = $qaFailNote;
  2205. return $this;
  2206. }
  2207. /**
  2208. * Get qaFailNote.
  2209. *
  2210. * @return string|null
  2211. */
  2212. public function getQaFailNote()
  2213. {
  2214. return $this->qaFailNote;
  2215. }
  2216. /**
  2217. * Set memoBy.
  2218. *
  2219. * @param User|null $memoBy
  2220. *
  2221. * @return SortingSession
  2222. */
  2223. public function setMemoBy(?User $memoBy = null)
  2224. {
  2225. $this->memoBy = $memoBy;
  2226. return $this;
  2227. }
  2228. /**
  2229. * Get memoBy.
  2230. *
  2231. * @return User|null
  2232. */
  2233. public function getMemoBy()
  2234. {
  2235. return $this->memoBy;
  2236. }
  2237. public static function getChronologyRequiredOptions()
  2238. {
  2239. $options = [];
  2240. $options[0] = 'No';
  2241. $options[1] = 'Yes';
  2242. return $options;
  2243. }
  2244. /**
  2245. * Determines whether a chronology is requested.
  2246. *
  2247. * @return string 'Yes'/'No'
  2248. */
  2249. public function getChronologyRequired()
  2250. {
  2251. $chronologies = $this->getProject()->getChronologyRequests();
  2252. /** @var ChronologyRequest $latestChronology */
  2253. $latestChronology = $chronologies->last();
  2254. if ($latestChronology
  2255. && !$latestChronology->getServiceRequest()->isComplete()
  2256. && !$latestChronology->getServiceRequest()->isCancelled()
  2257. && ($latestChronology->getServiceOption()->appliesToSubCategoryChronAndSor() || $latestChronology->getServiceOption()->appliesToSubCategoryChronOnly())) {
  2258. return 'Yes';
  2259. }
  2260. return 'No';
  2261. }
  2262. /**
  2263. * Returns all batch documents associated with the sorting session that are in status failed.
  2264. *
  2265. * @return array
  2266. */
  2267. public function getFailedBatchDocuments()
  2268. {
  2269. $failedBatchDocuments = [];
  2270. /** @var BatchRequest $batchRequest */
  2271. foreach ($this->getBatchRequests() as $batchRequest) {
  2272. /** @var BatchDocument $batchDocument */
  2273. foreach ($batchRequest->getBatchDocuments() as $batchDocument) {
  2274. if ($batchDocument->isFailed()) {
  2275. $failedBatchDocuments[] = $batchDocument;
  2276. }
  2277. }
  2278. }
  2279. return $failedBatchDocuments;
  2280. }
  2281. /**
  2282. * Returns all batch request IDs as a string associated with the sorting session,
  2283. * that have a batch document in status failed.
  2284. *
  2285. * @return string
  2286. */
  2287. public function getFailedBatchDocumentsBatchRequestIdsStr()
  2288. {
  2289. return
  2290. implode(
  2291. array_unique(
  2292. array_map(
  2293. function (BatchDocument $batchDocument) {
  2294. return $batchDocument->getBatchRequest()->getServiceRequestGroupId();
  2295. },
  2296. $this->getFailedBatchDocuments()
  2297. )
  2298. )
  2299. );
  2300. }
  2301. /**
  2302. * Set exportPushUnsortedStatus.
  2303. *
  2304. * @param string|null $exportPushUnsortedStatus
  2305. *
  2306. * @return SortingSession
  2307. */
  2308. public function setExportPushUnsortedStatus($exportPushUnsortedStatus = null)
  2309. {
  2310. $this->exportPushUnsortedStatus = $exportPushUnsortedStatus;
  2311. return $this;
  2312. }
  2313. /**
  2314. * Get exportPushUnsortedStatus.
  2315. *
  2316. * @return string|null
  2317. */
  2318. public function getExportPushUnsortedStatus()
  2319. {
  2320. return $this->exportPushUnsortedStatus;
  2321. }
  2322. /**
  2323. * Returns true if exportPushUnsortedStatus is pending.
  2324. *
  2325. * @return bool
  2326. */
  2327. public function isExportPushUnsortedStatusPending(): bool
  2328. {
  2329. return $this->exportPushUnsortedStatus === self::EXPORT_UNSORTED_PUSH_STATUS_PENDING;
  2330. }
  2331. /**
  2332. * Returns true if exportPushUnsortedStatus is in progress.
  2333. *
  2334. * @return bool
  2335. */
  2336. public function isExportPushUnsortedStatusInProgress(): bool
  2337. {
  2338. return $this->exportPushUnsortedStatus === self::EXPORT_UNSORTED_PUSH_STATUS_IN_PROGRESS;
  2339. }
  2340. /**
  2341. * Returns true if exportPushUnsortedStatus is completed.
  2342. *
  2343. * @return bool
  2344. */
  2345. public function isExportPushUnsortedStatusCompleted(): bool
  2346. {
  2347. return $this->exportPushUnsortedStatus === self::EXPORT_UNSORTED_PUSH_STATUS_COMPLETED;
  2348. }
  2349. /**
  2350. * Returns true if exportPushUnsortedStatus is failed.
  2351. *
  2352. * @return bool
  2353. */
  2354. public function isExportPushUnsortedStatusFailed(): bool
  2355. {
  2356. return $this->exportPushUnsortedStatus === self::EXPORT_UNSORTED_PUSH_STATUS_FAILED;
  2357. }
  2358. /**
  2359. * Set exportPushUnsortedBy.
  2360. *
  2361. * @param User|null $exportPushUnsortedBy
  2362. *
  2363. * @return SortingSession
  2364. */
  2365. public function setExportPushUnsortedBy(?User $exportPushUnsortedBy = null)
  2366. {
  2367. $this->exportPushUnsortedBy = $exportPushUnsortedBy;
  2368. return $this;
  2369. }
  2370. /**
  2371. * Get exportPushUnsortedBy.
  2372. *
  2373. * @return User|null
  2374. */
  2375. public function getExportPushUnsortedBy()
  2376. {
  2377. return $this->exportPushUnsortedBy;
  2378. }
  2379. /**
  2380. * Set activeSortingUser.
  2381. *
  2382. * @param User|null $activeSortingUser
  2383. *
  2384. * @return SortingSession
  2385. */
  2386. public function setActiveSortingUser(?User $activeSortingUser = null)
  2387. {
  2388. $this->activeSortingUser = $activeSortingUser;
  2389. return $this;
  2390. }
  2391. /**
  2392. * Get activeSortingUser.
  2393. *
  2394. * @return User|null
  2395. */
  2396. public function getActiveSortingUser(): ?User
  2397. {
  2398. return $this->activeSortingUser;
  2399. }
  2400. /**
  2401. * Returns a description of who the current active sorting user is.
  2402. *
  2403. * @return string
  2404. */
  2405. public function getActiveSortingUserDescription(): string
  2406. {
  2407. if ($this->getActiveSortingUser()) {
  2408. return sprintf('%1$s (%2$s)', $this->getActiveSortingUser()->getFullName(), $this->getActiveSortingUser()->getEmail());
  2409. }
  2410. return '';
  2411. }
  2412. /**
  2413. * Returns true if external editing is allowed for the sorting session for the specified user.
  2414. *
  2415. * @param User $user
  2416. *
  2417. * @return bool
  2418. */
  2419. public function allowExternalEditing(User $user): bool
  2420. {
  2421. // Allow external editing for these sort statuses
  2422. $allowSortStatus = $this->isSortStatusComplete() || $this->isSortStatusDownloaded();
  2423. // Allow external editing if no active sorter on sorting session
  2424. $allowUnassignedSortingSession = $this->getActiveSortingUser() === null || $user === $this->getActiveSortingUser();
  2425. return $allowSortStatus && $allowUnassignedSortingSession;
  2426. }
  2427. /**
  2428. * Set sortSessionType
  2429. *
  2430. * @param string $sortSessionType
  2431. *
  2432. * @return SortingSession
  2433. */
  2434. public function setSortSessionType($sortSessionType)
  2435. {
  2436. $this->sortSessionType = $sortSessionType;
  2437. return $this;
  2438. }
  2439. /**
  2440. * Get sortSessionType
  2441. *
  2442. * @return string
  2443. */
  2444. public function getSortSessionType()
  2445. {
  2446. return $this->sortSessionType;
  2447. }
  2448. /**
  2449. * Return array of ClientSortSessionTypeOptions
  2450. *
  2451. * @return array
  2452. */
  2453. public static function getClientSortSessionTypeOptions()
  2454. {
  2455. $options = [
  2456. self::SORT_SESSION_TYPE_CLIENT => 'Client Session',
  2457. ];
  2458. return $options;
  2459. }
  2460. /**
  2461. * Returns an array of permitted values for the Labels field.
  2462. *
  2463. * @return array
  2464. */
  2465. public static function getSortSessionTypeOptions()
  2466. {
  2467. $typeOptions = self::getConstantsWithLabelsAsChoices('SORT_SESSION_TYPE');
  2468. return $typeOptions;
  2469. }
  2470. /**
  2471. * Returns an array of Labels to be readable by humans.
  2472. *
  2473. * @return array
  2474. */
  2475. public function getSortSessionTypeLabels()
  2476. {
  2477. $labelOptions = array_flip(self::getClientSortSessionTypeOptions());
  2478. return array_map(function ($label) use ($labelOptions) {
  2479. return $labelOptions[$label] ?: 'Unknown';
  2480. }, $this->labels);
  2481. }
  2482. /**
  2483. * Returns a human readable version of the type isSentEmailLabel
  2484. *
  2485. * @return string
  2486. */
  2487. public function getSortSessionTypeLabel()
  2488. {
  2489. $options = array_flip(self::getSortSessionTypeOptions());
  2490. return $options[$this->getSortSessionType()] ?? '';
  2491. }
  2492. /**
  2493. * Returns true if all the sorting session stages are the same
  2494. *
  2495. * @return bool
  2496. */
  2497. public function hasSameSorters()
  2498. {
  2499. $isSame = true;
  2500. $sortedBy = $this->getSortedBy();
  2501. $arr = [
  2502. $this->getDatedBy(),
  2503. $this->getAdmissionBy(),
  2504. $this->getMemoBy(),
  2505. $this->getQaBy(),
  2506. ];
  2507. foreach ($arr as $value) {
  2508. if ($value !== $sortedBy) {
  2509. $isSame = false;
  2510. break;
  2511. }
  2512. }
  2513. return $isSame;
  2514. }
  2515. /**
  2516. * Method to check if session is a Client session. Returns true if it's a client session
  2517. *
  2518. * @return bool
  2519. */
  2520. public function isClientSortingSession(): bool
  2521. {
  2522. return $this->getSortSessionType() === self::SORT_SESSION_TYPE_CLIENT;
  2523. }
  2524. /**
  2525. * Method to check if session is a Medbrief session. Returns true if it's a Medbrief session
  2526. *
  2527. * @return bool
  2528. */
  2529. public function isMedbriefSortingSession(): bool
  2530. {
  2531. return $this->getSortSessionType() === self::SORT_SESSION_TYPE_MEDBRIEF;
  2532. }
  2533. /**
  2534. * Get the value of pageNumberPositionHorizontal
  2535. *
  2536. * @return int
  2537. */
  2538. public function getPageNumberPositionHorizontal()
  2539. {
  2540. return $this->pageNumberPositionHorizontal;
  2541. }
  2542. /**
  2543. * Set the value of pageNumberPositionHorizontal
  2544. *
  2545. * @param int|null $pageNumberPositionHorizontal|null
  2546. *
  2547. * @return self
  2548. */
  2549. public function setPageNumberPositionHorizontal(?int $pageNumberPositionHorizontal = null)
  2550. {
  2551. if ($pageNumberPositionHorizontal !== null) {
  2552. $this->pageNumberPositionHorizontal = $pageNumberPositionHorizontal;
  2553. }
  2554. return $this;
  2555. }
  2556. /**
  2557. * Get the value of pageNumberPositionVertical
  2558. *
  2559. * @return int
  2560. */
  2561. public function getPageNumberPositionVertical()
  2562. {
  2563. return $this->pageNumberPositionVertical;
  2564. }
  2565. /**
  2566. * Set the value of pageNumberPositionVertical
  2567. *
  2568. * @param int|null $pageNumberPositionVertical
  2569. *
  2570. * @return self
  2571. */
  2572. public function setPageNumberPositionVertical(?int $pageNumberPositionVertical = null)
  2573. {
  2574. if ($pageNumberPositionVertical !== null) {
  2575. $this->pageNumberPositionVertical = $pageNumberPositionVertical;
  2576. }
  2577. return $this;
  2578. }
  2579. /**
  2580. * Get the value of pageNumberSize
  2581. *
  2582. * @return int
  2583. */
  2584. public function getPageNumberSize()
  2585. {
  2586. return $this->pageNumberSize;
  2587. }
  2588. /**
  2589. * Set the value of pageNumberSize
  2590. *
  2591. * @param int|null $pageNumberSize
  2592. *
  2593. * @return self
  2594. */
  2595. public function setPageNumberSize(?int $pageNumberSize = null)
  2596. {
  2597. if ($pageNumberSize !== null) {
  2598. $this->pageNumberSize = $pageNumberSize;
  2599. }
  2600. return $this;
  2601. }
  2602. /**
  2603. * Get the value of pageNumberBackground
  2604. *
  2605. * @return bool
  2606. */
  2607. public function getPageNumberBackground()
  2608. {
  2609. return $this->pageNumberBackground;
  2610. }
  2611. /**
  2612. * Set the value of pageNumberBackground
  2613. *
  2614. * @param bool|null $pageNumberBackground
  2615. *
  2616. * @return self
  2617. */
  2618. public function setPageNumberBackground(?bool $pageNumberBackground = null)
  2619. {
  2620. if ($pageNumberBackground !== null) {
  2621. $this->pageNumberBackground = $pageNumberBackground;
  2622. }
  2623. return $this;
  2624. }
  2625. /**
  2626. * Get the value of isUrgent
  2627. *
  2628. * @return bool
  2629. */
  2630. public function getIsUrgent()
  2631. {
  2632. return $this->isUrgent;
  2633. }
  2634. /**
  2635. * @return string
  2636. */
  2637. public function getIsUrgentLabel(): string
  2638. {
  2639. return $this->isUrgent ? 'Yes' : 'No';
  2640. }
  2641. /**
  2642. * Set the value of isUrgent
  2643. *
  2644. * @param bool $isUrgent
  2645. *
  2646. * @return self
  2647. */
  2648. public function setIsUrgent(bool $isUrgent)
  2649. {
  2650. $this->isUrgent = $isUrgent;
  2651. return $this;
  2652. }
  2653. /**
  2654. * @return Collection|SortingSessionMemo[]
  2655. */
  2656. public function getSortingSessionMemos(): Collection
  2657. {
  2658. return $this->sortingSessionMemos;
  2659. }
  2660. /**
  2661. * @param SortingSessionMemo $sortingSessionMemo
  2662. *
  2663. * @return self
  2664. */
  2665. public function addSortingSessionMemo(SortingSessionMemo $sortingSessionMemo): self
  2666. {
  2667. if (!$this->sortingSessionMemos->contains($sortingSessionMemo)) {
  2668. $this->sortingSessionMemos[] = $sortingSessionMemo;
  2669. $sortingSessionMemo->setSortingSession($this);
  2670. }
  2671. return $this;
  2672. }
  2673. /**
  2674. * @param SortingSessionMemo $sortingSessionMemo
  2675. *
  2676. * @return self
  2677. */
  2678. public function removeSortingSessionMemo(SortingSessionMemo $sortingSessionMemo): self
  2679. {
  2680. if ($this->sortingSessionMemos->removeElement($sortingSessionMemo)) {
  2681. // set the owning side to null (unless already changed)
  2682. if ($sortingSessionMemo->getSortingSession() === $this) {
  2683. $sortingSessionMemo->setSortingSession(null);
  2684. }
  2685. }
  2686. return $this;
  2687. }
  2688. /**
  2689. * @return bool
  2690. */
  2691. public function getRequiresPreProcessing(): bool
  2692. {
  2693. return $this->requiresPreProcessing;
  2694. }
  2695. /**
  2696. * @param bool $requiresPreProcessing
  2697. *
  2698. * @return self
  2699. */
  2700. public function setRequiresPreProcessing(bool $requiresPreProcessing): self
  2701. {
  2702. $this->requiresPreProcessing = $requiresPreProcessing;
  2703. return $this;
  2704. }
  2705. /**
  2706. * @inheritDoc
  2707. */
  2708. public function setPreprocessStatusComplete(): PreprocessableInterface
  2709. {
  2710. $this->setSessionStatus(self::SESSION_STATUS_READY_FOR_SORTER);
  2711. return $this;
  2712. }
  2713. /**
  2714. * @inheritDoc
  2715. */
  2716. public function setPreprocessStatusFailed(): PreprocessableInterface
  2717. {
  2718. $this->setSessionStatus(self::SESSION_STATUS_PREPROCESSING_FAILED);
  2719. return $this;
  2720. }
  2721. /**
  2722. * @inheritDoc
  2723. */
  2724. public function setPreprocessStatusInProgress(): PreprocessableInterface
  2725. {
  2726. $this->setSessionStatus(self::SESSION_STATUS_PREPROCESSING_IN_PROGRESS);
  2727. return $this;
  2728. }
  2729. /**
  2730. * @return PreprocessItemInterface[]
  2731. */
  2732. public function getPreprocessItems(): array
  2733. {
  2734. return $this->getBatchRequests()->filter(function (BatchRequest $batchRequest) {
  2735. // Exclude complete and 'Other' centre type batch requests from pre-processing
  2736. return $batchRequest->allowPreprocessing();
  2737. })->toArray();
  2738. }
  2739. /**
  2740. * Gets a CSV of all pre-processing items for this sorting session.
  2741. * A '*' indicates the item has not been submitted for pre-processing yet,
  2742. * and will submitted on the next 'Send to Sorter' run.
  2743. *
  2744. * @return string
  2745. */
  2746. public function getPreprocessItemsCsv(): string
  2747. {
  2748. return implode(', ', array_map(function (BatchRequest $batchRequest) {
  2749. return $batchRequest->getServiceRequestGroupId() . ($batchRequest->isSubmittedForPreprocessing() === false ? '*' : '');
  2750. }, $this->getPreprocessItems()));
  2751. }
  2752. /**
  2753. * @inheritDoc
  2754. */
  2755. public function hasIncompletePreprocessItems(): bool
  2756. {
  2757. foreach ($this->getPreprocessItems() as $preprocessItem) {
  2758. $preprocessDocuments = $preprocessItem->getPreprocessDocumentsArray();
  2759. foreach ($preprocessDocuments as $preprocessDocument) {
  2760. if ($preprocessDocument->isIncomplete()) {
  2761. return true;
  2762. }
  2763. }
  2764. }
  2765. return false;
  2766. }
  2767. /**
  2768. * Convenience method to check session status of a SortingSession is pending.
  2769. *
  2770. * @return bool
  2771. */
  2772. public function isSessionStatusPending(): bool
  2773. {
  2774. return $this->getSessionStatus() === self::SESSION_STATUS_PENDING
  2775. || $this->getSessionStatus() === self::SESSION_STATUS_EXPORT_PENDING
  2776. || $this->getSessionStatus() === self::SESSION_STATUS_PREPROCESSING_PENDING;
  2777. }
  2778. /**
  2779. * Convenience method to check session status of a SortingSession is in the export phase.
  2780. *
  2781. * @return bool
  2782. */
  2783. public function isSessionStatusExport(): bool
  2784. {
  2785. return $this->getSessionStatus() === self::SESSION_STATUS_EXPORT_IN_PROGRESS
  2786. || $this->getSessionStatus() === self::SESSION_STATUS_EXPORT_PENDING;
  2787. }
  2788. /**
  2789. * Convenience method to check session status of a SortingSession when it is ready for sorter.
  2790. *
  2791. * @return bool
  2792. */
  2793. public function isSessionStatusReadyForSorter(): bool
  2794. {
  2795. return $this->getSessionStatus() === self::SESSION_STATUS_READY_FOR_SORTER;
  2796. }
  2797. /**
  2798. * Convenience method to check session status of a SortingSession is in progress.
  2799. *
  2800. * @return bool
  2801. */
  2802. public function isSessionStatusInProgress(): bool
  2803. {
  2804. return $this->getSessionStatus() === self::SESSION_STATUS_IN_PROGRESS
  2805. || $this->getSessionStatus() === self::SESSION_STATUS_PREPROCESSING_IN_PROGRESS;
  2806. }
  2807. /**
  2808. * Convenience method to check session status of a SortingSession that is paused.
  2809. *
  2810. * @return bool
  2811. */
  2812. public function isSessionStatusPaused(): bool
  2813. {
  2814. return $this->getSessionStatus() === self::SESSION_STATUS_PAUSED;
  2815. }
  2816. /**
  2817. * Convenience method to check session status of a SortingSession that has missing pages.
  2818. *
  2819. * @return bool
  2820. */
  2821. public function isSessionStatusPagesMissing(): bool
  2822. {
  2823. return $this->getSessionStatus() === self::SESSION_STATUS_PAGES_MISSING;
  2824. }
  2825. /**
  2826. * Convenience method to check session status of a SortingSession is completed.
  2827. *
  2828. * @return bool
  2829. */
  2830. public function isSessionStatusCompleted(): bool
  2831. {
  2832. return $this->getSessionStatus() === self::SESSION_STATUS_COMPLETED
  2833. || $this->getSessionStatus() === self::SESSION_STATUS_EXPORT_COMPLETED;
  2834. }
  2835. /**
  2836. * Convenience method to check session status of a SortingSession has failed in 3 preparing,exporting and preprocessing.
  2837. *
  2838. * @return bool
  2839. */
  2840. public function hasSessionStatusFailed(): bool
  2841. {
  2842. return $this->getSessionStatus() === self::SESSION_STATUS_PREPARE_FAILED
  2843. || $this->getSessionStatus() === self::SESSION_STATUS_EXPORT_FAILED
  2844. || $this->getSessionStatus() === self::SESSION_STATUS_PREPROCESSING_FAILED;
  2845. }
  2846. /**
  2847. * Maps the sort options from the Sort entity on the associated MatterRequest,
  2848. * with the pagination options on the SortingSession.
  2849. *
  2850. * @param Sort $sort
  2851. *
  2852. * @return void
  2853. */
  2854. protected function mapPaginationOptions(Sort $sort)
  2855. {
  2856. // centrePrefix
  2857. if ($sort->isCentrePrefixAlpha()) {
  2858. $this->setCentrePrefix(self::CENTRE_PREFIX_ALPHA);
  2859. } elseif ($sort->isCentrePrefixNumeric()) {
  2860. $this->setCentrePrefix(self::CENTRE_PREFIX_NUMERIC);
  2861. }
  2862. // Pagination Strategy
  2863. if ($sort->isPagePrefixNone()) {
  2864. if ($sort->isPaginationRunCentre()) {
  2865. $this->setPaginationStrategy(self::PAGINATION_STRATEGY_RELATIVE);
  2866. } elseif ($sort->isPaginationRunContinuous()) {
  2867. $this->setPaginationStrategy(self::PAGINATION_STRATEGY_ABSOLUTE);
  2868. }
  2869. } else {
  2870. if ($sort->isPaginationRunCentre()) {
  2871. $this->setPaginationStrategy(self::PAGINATION_STRATEGY_PREFIXED_RELATIVE);
  2872. } elseif ($sort->isPaginationRunContinuous()) {
  2873. $this->setPaginationStrategy(self::PAGINATION_STRATEGY_PREFIXED_ABSOLUTE);
  2874. }
  2875. if ($sort->isPagePrefixLetter()) {
  2876. $this->setPaginationPrefix('A');
  2877. } elseif ($sort->isPagePrefixNumeric()) {
  2878. $this->setPaginationPrefix('1.');
  2879. }
  2880. }
  2881. $this->setPageNumberPadding($sort->getPageNumberPaddingInteger());
  2882. $this->setPageNumberPositionHorizontal($sort->getPageNumberPositionHorizontal());
  2883. $this->setPageNumberPositionVertical($sort->getPageNumberPositionVertical());
  2884. $this->setPageNumberSize($sort->getPageNumberSize());
  2885. $this->setPageNumberBackground($sort->getPageNumberBackground());
  2886. }
  2887. }