<?php
namespace MedBrief\MSR\Entity;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
use Doctrine\Common\Collections\Criteria;
use Doctrine\ORM\Mapping as ORM;
use Gedmo\Mapping\Annotation as Gedmo;
use MedBrief\MSR\Entity\MatterRequest\Details\Sort;
use MedBrief\MSR\Entity\MatterRequest\MatterRequest;
use MedBrief\MSR\Repository\SortingSessionRepository;
use MedBrief\MSR\Service\Preprocessing\PreprocessableInterface;
use MedBrief\MSR\Service\Preprocessing\PreprocessItemInterface;
use MedBrief\MSR\Service\ProjectClosure\RemoveRecords\RemovableRecordInterface;
use MedBrief\MSR\Service\SortingSession\SortStatusAwareInterface;
use MedBrief\MSR\Traits\FilterableClassConstantsTrait;
/**
* SortingSession
*
* @ORM\Table(name="SortingSession")
*
* @ORM\Entity(repositoryClass=SortingSessionRepository::class)
*
* @Gedmo\SoftDeleteable(fieldName="deletedAt", timeAware=false)
*
*/
class SortingSession implements RemovableRecordInterface, PreprocessableInterface, SortStatusAwareInterface
{
use FilterableClassConstantsTrait;
/**
* Constant values for Session Status
*/
public const SESSION_STATUS_PENDING = 11; // Allow adding/removing of batches
public const SESSION_STATUS_READY_FOR_SORTER = 12; // Allow adding/removing of batches (Revert to ::STATUS_PENDING on addition ONLY)
public const SESSION_STATUS_IN_PROGRESS = 13; // SS is cast in stone!!
public const SESSION_STATUS_PAUSED = 14; // SS may be deleted, batches to be released
public const SESSION_STATUS_PAGES_MISSING = 15; // Allow adding of batches ONLY (Revert to ::STATUS_PENDING) -> Delete SS to release batches
public const SESSION_STATUS_COMPLETED = 16; // Allow adding of batches ONLY (Revert to ::STATUS_PENDING) -> Delete SS to release batches
// Preparation related statuses
public const SESSION_STATUS_PREPARE_PENDING = 21; // SS is cast in stone!!
public const SESSION_STATUS_PREPARE_IN_PROGRESS = 22; // SS is cast in stone!!
public const SESSION_STATUS_PREPARE_FAILED = 23; // Allow adding/removing of batches (Revert to ::STATUS_PENDING)
// Export related statuses
public const SESSION_STATUS_EXPORT_PENDING = 31;
public const SESSION_STATUS_EXPORT_IN_PROGRESS = 32;
public const SESSION_STATUS_EXPORT_COMPLETED = 33;
public const SESSION_STATUS_EXPORT_FAILED = 34;
// Processing related statuses - these in practice relate to AI processing of the documents prior to sorting
public const SESSION_STATUS_PREPROCESSING_PENDING = 41;
public const SESSION_STATUS_PREPROCESSING_IN_PROGRESS = 42;
public const SESSION_STATUS_PREPROCESSING_FAILED = 43;
// Export Push related statuses
public const EXPORT_PUSH_STATUS_PENDING = 'export_push.pending';
public const EXPORT_PUSH_STATUS_IN_PROGRESS = 'export_push.in_progress';
public const EXPORT_PUSH_STATUS_COMPLETED = 'export_push.completed';
public const EXPORT_PUSH_STATUS_FAILED = 'export_push.failed';
/** Pagination Strategies */
public const PAGINATION_STRATEGY_ABSOLUTE = 1;
public const PAGINATION_STRATEGY_RELATIVE = 2;
public const PAGINATION_STRATEGY_PREFIXED_ABSOLUTE = 3;
public const PAGINATION_STRATEGY_PREFIXED_RELATIVE = 4;
public const PAGINATION_STRATEGY_NONE = 5;
public const PAGINATION_STRATEGY_SECTION = 6;
public const PAGINATION_STRATEGY_PREFIXED_SECTION = 7;
/** Centre Prefixes */
public const CENTRE_PREFIX_ALPHA = 1;
public const CENTRE_PREFIX_NUMERIC = 2;
public const VERSION_OLD = 'old';
// memoStatus constants
public const MEMO_STATUS_READY_TO_SYNC = 'ready_to_sync';
public const MEMO_STATUS_PENDING = 'pending';
public const MEMO_READY_FOR_UPLOAD = 'ready_for_upload';
public const MEMO_STATUS_UPLOADED = 'uploaded';
// Export Unsorted Push related statuses
public const EXPORT_UNSORTED_PUSH_STATUS_PENDING = 'export_unsorted_push.pending';
public const EXPORT_UNSORTED_PUSH_STATUS_IN_PROGRESS = 'export_unsorted_push.in_progress';
public const EXPORT_UNSORTED_PUSH_STATUS_COMPLETED = 'export_unsorted_push.completed';
public const EXPORT_UNSORTED_PUSH_STATUS_FAILED = 'export_unsorted_push.failed';
// Sort Session Type Options
public const SORT_SESSION_TYPE_CLIENT = 'type_client';
public const SORT_SESSION_TYPE_CLIENT__LABEL = 'Client Session';
public const SORT_SESSION_TYPE_MEDBRIEF = 'type_medbrief';
public const SORT_SESSION_TYPE_MEDBRIEF__LABEL = 'Medbrief Session';
/**
* Unmapped field used to indicate if a notification should be sent
*
* @var bool
*/
public $sendNotification = false;
/**
* @var int
*
* @ORM\Column(name="id", type="integer")
*
* @ORM\Id
*
* @ORM\GeneratedValue(strategy="IDENTITY")
*/
protected $id;
/**
* @var \DateTime|null
*
* @ORM\Column(name="deletedAt", type="datetime", nullable=true)
*/
protected $deletedAt;
/**
* @var \DateTime
*
* @ORM\Column(name="created", type="datetime")
*
* @Gedmo\Timestampable(on="create")
*/
protected $created;
/**
* @var \DateTime
*
* @ORM\Column(name="updated", type="datetime")
*
* @Gedmo\Timestampable(on="update")
*/
protected $updated;
/**
* @var string|null
*
* @ORM\Column(name="storeData", type="text", nullable=true)
*/
protected $storeData;
/**
* @var string|null
*
* @ORM\Column(name="exportStoreJson", type="text", nullable=true)
*/
protected $exportStoreJson;
/**
* @var int|null
*
* @ORM\Column(name="sessionStatus", type="integer", nullable=true)
*/
protected $sessionStatus = self::SESSION_STATUS_PENDING;
/**
* @var int|null
*
* @ORM\Column(name="sortStatus", type="integer", nullable=true)
*/
protected $sortStatus = self::SORT_STATUS_CLASSIFY;
/**
* @var string|null
*
* @ORM\Column(name="archiveFilename", type="string", nullable=true)
*/
protected $archiveFilename;
/**
* @var int|null
*
* @ORM\Column(name="paginationStrategy", type="integer", nullable=true)
*/
protected $paginationStrategy;
/**
* @var string|null
*
* @ORM\Column(name="paginationPrefix", type="string", nullable=true)
*/
protected $paginationPrefix;
/**
* @var int|null
*
* @ORM\Column(name="centrePrefix", type="integer", nullable=true)
*/
protected $centrePrefix;
/**
* @var int
*
* @ORM\Column(name="centrePrefixPadding", type="integer", options={"default"="3"})
*/
protected $centrePrefixPadding = 3;
/**
* @var int
*
* @ORM\Column(name="pageNumberPadding", type="integer", options={"default"="4"})
*/
protected $pageNumberPadding = 4;
/**
* @var int
*
* @ORM\Column(name="pageNumberPositionHorizontal", type="integer", options={"default"="3"})
*/
protected $pageNumberPositionHorizontal = Sort::PAGE_NUMBER_POSITION_HORIZONTAL_RIGHT;
/**
* @var int
*
* @ORM\Column(name="pageNumberPositionVertical", type="integer", options={"default"="2"})
*/
protected $pageNumberPositionVertical = Sort::PAGE_NUMBER_POSITION_VERTICAL_BOTTOM;
/**
* @var int
*
* @ORM\Column(name="pageNumberSize", type="integer", options={"default"="20"})
*/
protected $pageNumberSize = Sort::PAGE_NUMBER_SIZE_20;
/**
* @var bool
*
* @ORM\Column(name="pageNumberBackground", type="boolean", options={"default"=false})
*/
protected $pageNumberBackground = Sort::PAGE_NUMBER_BACKGROUND_NO;
/**
* @var int
*
* @ORM\Column(name="timeSpentClassify", type="integer", options={"default"="0"})
*/
protected $timeSpentClassify = 0;
/**
* @var int
*
* @ORM\Column(name="timeSpentDating", type="integer", options={"default"="0"})
*/
protected $timeSpentDating = 0;
/**
* @var int
*
* @ORM\Column(name="timeSpentAdmission", type="integer", options={"default"="0"})
*/
protected $timeSpentAdmission = 0;
/**
* @var int
*
* @ORM\Column(name="timeSpentMemo", type="integer", options={"default"="0"})
*/
protected $timeSpentMemo = 0;
/**
* @var int
*
* @ORM\Column(name="timeSpentQa", type="integer", options={"default"="0"})
*/
protected $timeSpentQa = 0;
/**
* @var \DateTime|null
*
* @ORM\Column(name="dateSentToSorter", type="datetime", nullable=true)
*/
protected $dateSentToSorter;
/**
* @var \DateTime|null
*
* @ORM\Column(name="dueDate", type="datetime", nullable=true)
*/
protected $dueDate;
/**
* @var \DateTime|null
*
* @ORM\Column(name="estCompletionDate", type="datetime", nullable=true)
*/
protected $estCompletionDate;
/**
* @var \DateTime|null
*
* @ORM\Column(name="dateDownloaded", type="datetime", nullable=true)
*/
protected $dateDownloaded;
/**
* @var string|null
*
* @ORM\Column(name="mrsFormFilename", type="string", length=255, nullable=true)
*/
protected $mrsFormFilename;
/**
* @var int
*
* @ORM\Column(name="startPageNumber", type="integer", options={"default"="1"})
*/
protected $startPageNumber = 1;
/**
* @var int|null
*
* @ORM\Column(name="classifyCompletePerc", type="integer", nullable=true)
*/
protected $classifyCompletePerc;
/**
* @var int|null
*
* @ORM\Column(name="dateCompletePerc", type="integer", nullable=true)
*/
protected $dateCompletePerc;
/**
* @var string|null
*
* @ORM\Column(name="exportError", type="text", nullable=true)
*/
protected $exportError;
/**
* @var string|null
*
* @ORM\Column(name="version", type="string", nullable=true)
*/
protected $version;
/**
* @var string|null
*
* @ORM\Column(name="exportPushStatus", type="string", nullable=true)
*/
protected $exportPushStatus;
/**
* @var string|null
*
* @ORM\Column(name="memoStatus", type="string", nullable=true)
*/
protected $memoStatus;
/**
* @var string|null
*
* @ORM\Column(name="qaFailNote", type="text", nullable=true)
*/
protected $qaFailNote;
/**
* @var string|null
*
* @ORM\Column(name="exportPushUnsortedStatus", type="string", nullable=true)
*/
protected $exportPushUnsortedStatus;
/**
* @var string|null
*
* @ORM\Column(name="sortSessionType", type="string", nullable=true)
*/
protected $sortSessionType;
/**
* @var bool
*
* @ORM\Column(name="isUrgent", type="boolean", options={"default"=false})
*/
protected $isUrgent = false;
/**
* Indicates if the SortingSession should be sent for pre-processing (AI processing).
*
* @var bool
*
* @ORM\Column(type="boolean", options={"default"=false})
*/
protected $requiresPreProcessing = false;
/**
* @var Collection
*
* @ORM\OneToMany(targetEntity="MedBrief\MSR\Entity\BatchRequest", mappedBy="sortingSession", cascade={"persist"})
*/
protected $batchRequests;
/**
* @var Collection
*
* @ORM\OneToMany(targetEntity="MedBrief\MSR\Entity\SortingSessionDetail", mappedBy="sortingSession", cascade={"persist","remove"}, orphanRemoval=true)
*/
protected $details;
/**
* @var Collection
*
* @ORM\OneToMany(targetEntity="MedBrief\MSR\Entity\SortingSessionMemo", mappedBy="sortingSession", cascade={"persist","remove"}, orphanRemoval=true)
*/
protected $sortingSessionMemos;
/**
* @var Project
*
* @ORM\ManyToOne(targetEntity="MedBrief\MSR\Entity\Project", inversedBy="sortingSessions")
*
* @ORM\JoinColumns({
*
* @ORM\JoinColumn(name="project_id", referencedColumnName="id")
* })
*/
protected $project;
/**
* @ORM\ManyToOne(targetEntity="MedBrief\MSR\Entity\User")
*
* @var User
*/
protected $validatedBy;
/**
* @var User
*
* @ORM\ManyToOne(targetEntity="MedBrief\MSR\Entity\User")
*
* @ORM\JoinColumns({
*
* @ORM\JoinColumn(name="sortedBy_id", referencedColumnName="id")
* })
*/
protected $sortedBy;
/**
* @var User
*
* @ORM\ManyToOne(targetEntity="MedBrief\MSR\Entity\User")
*
* @ORM\JoinColumns({
*
* @ORM\JoinColumn(name="datedBy_id", referencedColumnName="id")
* })
*/
protected $datedBy;
/**
* @var User
*
* @ORM\ManyToOne(targetEntity="MedBrief\MSR\Entity\User")
*
* @ORM\JoinColumns({
*
* @ORM\JoinColumn(name="admissionBy_id", referencedColumnName="id")
* })
*/
protected $admissionBy;
/**
* @var User
*
* @ORM\ManyToOne(targetEntity="MedBrief\MSR\Entity\User")
*
* @ORM\JoinColumns({
*
* @ORM\JoinColumn(name="memoBy_id", referencedColumnName="id")
* })
*/
protected $memoBy;
/**
* @var User
*
* @ORM\ManyToOne(targetEntity="MedBrief\MSR\Entity\User")
*
* @ORM\JoinColumns({
*
* @ORM\JoinColumn(name="qaBy_id", referencedColumnName="id")
* })
*/
protected $qaBy;
/**
* @var User
*
* @ORM\ManyToOne(targetEntity="MedBrief\MSR\Entity\User")
*
* @ORM\JoinColumns({
*
* @ORM\JoinColumn(name="downloadedBy_id", referencedColumnName="id")
* })
*/
protected $downloadedBy;
/**
* @var User
*
* @ORM\ManyToOne(targetEntity="MedBrief\MSR\Entity\User")
*
* @ORM\JoinColumns({
*
* @ORM\JoinColumn(name="exportPushBy_id", referencedColumnName="id")
* })
*/
protected $exportPushBy;
/**
* @var User
*
* @ORM\ManyToOne(targetEntity="MedBrief\MSR\Entity\User")
*
* @ORM\JoinColumns({
*
* @ORM\JoinColumn(name="exportPushUnsortedBy_id", referencedColumnName="id")
* })
*/
protected $exportPushUnsortedBy;
/**
* @var User
*
* @ORM\ManyToOne(targetEntity="MedBrief\MSR\Entity\User")
*
* @ORM\JoinColumns({
*
* @ORM\JoinColumn(name="activeSortingUser_id", referencedColumnName="id")
* })
*/
protected $activeSortingUser;
/**
* @var string
*/
protected $mrsFormFile;
/**
* @var string
*/
protected $chronologyRequired;
/**
* Constructor
*
* @param null|MatterRequest $matterRequest
*/
public function __construct(?MatterRequest $matterRequest = null)
{
$this->batchRequests = new ArrayCollection();
$this->details = new ArrayCollection();
$this->sortingSessionMemos = new ArrayCollection();
// If there was a sort requested on the matter request
if ($matterRequest && $matterRequest->getServiceSelectionDetails() && $matterRequest->getServiceSelectionDetails()->isSortChoiceYes() && $matterRequest->getSortDetails()) {
$this->mapPaginationOptions($matterRequest->getSortDetails());
}
}
/**
* __toString
*
* @return string
*/
public function __toString()
{
return (string) $this->getId();
}
/**
* Get id
*
* @return int
*/
public function getId(): ?int
{
return $this->id;
}
/**
* Set created
*
* @param \DateTime $created
*
* @return SortingSession
*/
public function setCreated($created)
{
$this->created = $created;
return $this;
}
/**
* Get created
*
* @return \DateTime
*/
public function getCreated()
{
return $this->created;
}
/**
* Set updated
*
* @param \DateTime $updated
*
* @return SortingSession
*/
public function setUpdated($updated)
{
$this->updated = $updated;
return $this;
}
/**
* Get updated
*
* @return \DateTime
*/
public function getUpdated()
{
return $this->updated;
}
/**
* Set storeData
*
* @param string $storeData
*
* @return SortingSession
*/
public function setStoreData($storeData)
{
$this->storeData = $storeData;
return $this;
}
/**
* Get storeData
*
* @return string
*/
public function getStoreData()
{
return $this->storeData;
}
/**
* Get storeDataArray
*
* @return array
*/
public function getStoreDataArray()
{
if (!$this->getStoreData()) {
return [];
}
return json_decode($this->getStoreData(), true);
}
/**
* Set sessionStatus
*
* @param int $sessionStatus
*
* @return SortingSession
*/
public function setSessionStatus($sessionStatus)
{
// Clear the export error when we do a new export. Clear the push status when we do a new export.
if ($sessionStatus === self::SESSION_STATUS_EXPORT_PENDING) {
$this->setExportError('');
$this->setExportPushStatus(null);
}
$this->sessionStatus = $sessionStatus;
return $this;
}
/**
* Get sessionStatus
*
* @return int
*/
public function getSessionStatus()
{
return $this->sessionStatus;
}
/**
* Return true if SortingSession is paused
*
* @return bool
*/
public function isPaused()
{
return $this->sessionStatus === self::SESSION_STATUS_PAUSED;
}
/**
* Return true if SortingSession is in progress
*
* @return bool
*/
public function isInProgress()
{
return $this->sessionStatus === self::SESSION_STATUS_IN_PROGRESS || $this->getActiveSortingUser() !== null;
}
/**
* Return true if SortingSession is busy preparing for the sorter
*
* @return bool
*/
public function isPreparing()
{
return $this->sessionStatus === self::SESSION_STATUS_PREPARE_PENDING || $this->sessionStatus === self::SESSION_STATUS_PREPARE_IN_PROGRESS;
}
/**
* Return true if SortingSession is pending
*
* @return bool
*/
public function isPending()
{
return $this->sessionStatus === self::SESSION_STATUS_PENDING;
}
/**
* Return true if SortingSession is prepare failed
*
* @return bool
*/
public function isPrepareFailed()
{
return $this->sessionStatus === self::SESSION_STATUS_PREPARE_FAILED;
}
/**
* Return true if SortingSession is ready for sorter
*
* @return bool
*/
public function isReadyForSorter()
{
return $this->sessionStatus === self::SESSION_STATUS_READY_FOR_SORTER;
}
/**
* Return true if SortingSession is missing pages
*
* @return bool
*/
public function isMissingPages()
{
return $this->sessionStatus === self::SESSION_STATUS_PAGES_MISSING;
}
/**
* Return true if SortingSession export is pending
*
* @return bool
*/
public function isExportPending()
{
return $this->sessionStatus === self::SESSION_STATUS_EXPORT_PENDING;
}
/**
* Return true if SortingSession export is in progress
*
* @return bool
*/
public function isExportInProgress()
{
return $this->sessionStatus === self::SESSION_STATUS_EXPORT_IN_PROGRESS;
}
/**
* Return true if SortingSession export completed
*
* @return bool
*/
public function isExportCompleted()
{
return $this->sessionStatus === self::SESSION_STATUS_EXPORT_COMPLETED;
}
/**
* Return true if SortingSession export failed
*
* @return bool
*/
public function isExportFailed()
{
return $this->sessionStatus === self::SESSION_STATUS_EXPORT_FAILED;
}
/**
* @return bool
*/
public function isPreprocessingPending()
{
return $this->sessionStatus === self::SESSION_STATUS_PREPROCESSING_PENDING;
}
/**
* @return bool
*/
public function isPreprocessingFailed()
{
return $this->sessionStatus === self::SESSION_STATUS_PREPROCESSING_FAILED;
}
/**
* @return bool
*/
public function isPreprocessingInProgress()
{
return $this->sessionStatus === self::SESSION_STATUS_PREPROCESSING_IN_PROGRESS;
}
/**
* @return bool
*/
public function isPreprocessing(): bool
{
return in_array($this->getSessionStatus(), [
self::SESSION_STATUS_PREPROCESSING_PENDING,
self::SESSION_STATUS_PREPROCESSING_FAILED,
self::SESSION_STATUS_PREPROCESSING_IN_PROGRESS,
]);
}
/**
* Get sessionStatusOptions
*
* @param array $inclOnly
*
* @return array
*/
public static function getSessionStatusOptions(array $inclOnly = [])
{
$options = [
self::SESSION_STATUS_PENDING => 'Pending',
self::SESSION_STATUS_READY_FOR_SORTER => 'Ready for Sorter',
self::SESSION_STATUS_IN_PROGRESS => 'In Progress',
self::SESSION_STATUS_PAUSED => 'Paused',
self::SESSION_STATUS_PAGES_MISSING => 'Pages Missing',
self::SESSION_STATUS_COMPLETED => 'Completed',
self::SESSION_STATUS_PREPARE_PENDING => 'Send to Sorter',
self::SESSION_STATUS_PREPARE_IN_PROGRESS => 'Preparing for Sorter',
self::SESSION_STATUS_PREPARE_FAILED => 'Failed Preparing for Sorter',
self::SESSION_STATUS_EXPORT_PENDING => 'Pending Export',
self::SESSION_STATUS_EXPORT_IN_PROGRESS => 'Export In Progress',
self::SESSION_STATUS_EXPORT_COMPLETED => 'Available To Download',
self::SESSION_STATUS_EXPORT_FAILED => 'Failed Creating Archive',
self::SESSION_STATUS_PREPROCESSING_PENDING => 'Pre-Processing - Pending',
self::SESSION_STATUS_PREPROCESSING_IN_PROGRESS => 'Pre-Processing - In Progress',
self::SESSION_STATUS_PREPROCESSING_FAILED => 'Pre-Processing - Failed',
];
if ($inclOnly) {
$options = array_filter($options, function ($key) use ($inclOnly) {
return in_array($key, $inclOnly);
}, \ARRAY_FILTER_USE_KEY);
}
return $options;
}
/**
* Get sessionStatusLabel
*
* @return string
*/
public function getSessionStatusLabel()
{
$options = self::getSessionStatusOptions();
return $options[$this->getSessionStatus()] ?? '';
}
/**
* Add batchRequest
*
* @param BatchRequest $batchRequest
*
* @return SortingSession
*/
public function addBatchRequest(BatchRequest $batchRequest)
{
$batchRequest->setSortingSession($this);
$this->batchRequests[] = $batchRequest;
return $this;
}
/**
* Remove batchRequest
*
* @param BatchRequest $batchRequest
*/
public function removeBatchRequest(BatchRequest $batchRequest)
{
$batchRequest->setSortingSession(null);
$this->batchRequests->removeElement($batchRequest);
}
/**
* Get batchRequests
*
* @return BatchRequest[] | ArrayCollection
*/
public function getBatchRequests()
{
return $this->batchRequests;
}
/**
* Gets the total page count for the SortingSession.
*
* @return int
*/
public function getPageCount()
{
return array_reduce($this->getBatchRequests()->toArray(), function ($pageCount, BatchRequest $batchRequest) {
return $batchRequest->getPages()->count() + $pageCount;
}, 0);
}
/**
* Get batchRequests as a list of request IDs
*
* @return string
*/
public function getBatchRequestsCsv()
{
return implode(', ', array_map(function (BatchRequest $batchRequest) {
return $batchRequest->getServiceRequestGroupId();
}, $this->getBatchRequests()->toArray()));
}
/**
* @return string
*/
public function getPreprocessDocumentsCsv()
{
$preprocessDocumentsCsv = '';
foreach ($this->getPreprocessItems() as $preprocessItem) {
foreach ($preprocessItem->getPreprocessDocumentsArray() as $preprocessDocument) {
if ($preprocessDocument->isIgnore() === false) {
$preprocessDocumentsCsv .= sprintf('%1$s(%2$s), ', $preprocessDocument->getId(), $preprocessDocument->getStatusLabel());
}
}
}
return trim($preprocessDocumentsCsv, ', ');
}
/**
* Set project
*
* @param Project $project
*
* @return SortingSession
*/
public function setProject(?Project $project = null)
{
$this->project = $project;
return $this;
}
/**
* Get project
*
* @return Project
*/
public function getProject()
{
return $this->project;
}
/**
* @param User $validatedBy
*
* @return self
*/
public function setValidatedBy(?User $validatedBy = null): self
{
$this->validatedBy = $validatedBy;
return $this;
}
/**
* Get validatedBy
*
* @return User|null
*/
public function getValidatedBy(): ?User
{
return $this->validatedBy;
}
/**
* Set sortedBy
*
* @param User $sortedBy
*
* @return SortingSession
*/
public function setSortedBy(?User $sortedBy = null)
{
$this->sortedBy = $sortedBy;
return $this;
}
/**
* Get sortedBy
*
* @return User
*/
public function getSortedBy()
{
return $this->sortedBy;
}
/**
* Set datedBy
*
* @param User $datedBy
*
* @return SortingSession
*/
public function setDatedBy(?User $datedBy = null)
{
$this->datedBy = $datedBy;
return $this;
}
/**
* Get datedBy
*
* @return User
*/
public function getDatedBy()
{
return $this->datedBy;
}
/**
* Set qaBy
*
* @param User $qaBy
*
* @return SortingSession
*/
public function setQaBy(?User $qaBy = null)
{
$this->qaBy = $qaBy;
return $this;
}
/**
* Get qaBy
*
* @return User
*/
public function getQaBy()
{
return $this->qaBy;
}
/**
* Get all the statuses that a SortingSession may be in in order for it to be deleted
*
* @return array
*/
public static function getDeletableStatuses()
{
return [
self::SESSION_STATUS_PENDING,
self::SESSION_STATUS_COMPLETED,
self::SESSION_STATUS_PAUSED,
self::SESSION_STATUS_PAGES_MISSING,
self::SESSION_STATUS_PREPARE_FAILED,
];
}
/**
* Get all the statuses that a SortingSession may be in in order to accept additional BatchRequests
*
* @return array
*/
public static function getBatchAddableStatuses()
{
return [
self::SESSION_STATUS_PENDING,
self::SESSION_STATUS_READY_FOR_SORTER,
self::SESSION_STATUS_PAUSED,
self::SESSION_STATUS_PAGES_MISSING,
self::SESSION_STATUS_COMPLETED,
self::SESSION_STATUS_PREPARE_FAILED,
self::SESSION_STATUS_EXPORT_COMPLETED,
];
}
/**
* Get all the statuses that a SortingSession may be in in order to delete associated BatchRequests
*
* @return array
*/
public static function getBatchDeletableStatuses()
{
return [
self::SESSION_STATUS_PENDING,
self::SESSION_STATUS_READY_FOR_SORTER,
self::SESSION_STATUS_PREPARE_FAILED,
self::SESSION_STATUS_PAUSED,
];
}
/**
* Get all the statuses that a SortingSession would show in the doc sorter for.
*
* @return array
*/
public static function getActiveStatuses()
{
return [
self::SESSION_STATUS_IN_PROGRESS,
self::SESSION_STATUS_READY_FOR_SORTER,
self::SESSION_STATUS_PAUSED,
];
}
/**
* Returns true if the SortingSession is in a status that would render it visible in the
* document sorter.
*
* @return bool
*/
public function hasActiveStatus()
{
return in_array($this->getSessionStatus(), self::getActiveStatuses());
}
/**
* Set archiveFilename
*
* @param string $archiveFilename
*
* @return SortingSession
*/
public function setArchiveFilename($archiveFilename)
{
$this->archiveFilename = $archiveFilename;
return $this;
}
/**
* Get archiveFilename
*
* @return string
*/
public function getArchiveFilename()
{
return $this->archiveFilename;
}
/**
* Set paginationStrategy
*
* @param int $paginationStrategy
*
* @return SortingSession
*/
public function setPaginationStrategy($paginationStrategy)
{
$this->paginationStrategy = $paginationStrategy;
return $this;
}
/**
* Get paginationStrategy
*
* @return int
*/
public function getPaginationStrategy()
{
return $this->paginationStrategy;
}
/**
* Set paginationPrefix
*
* @param string $paginationPrefix
*
* @return SortingSession
*/
public function setPaginationPrefix($paginationPrefix)
{
$this->paginationPrefix = $paginationPrefix;
return $this;
}
/**
* Get paginationPrefix
*
* @return string
*/
public function getPaginationPrefix()
{
return $this->paginationPrefix;
}
/**
* Returns an array of pagination strategies that are relative
*
* @return array
*/
public static function getRelativePaginationStrategies()
{
return [
self::PAGINATION_STRATEGY_RELATIVE,
self::PAGINATION_STRATEGY_PREFIXED_RELATIVE,
];
}
/**
* Returns an array of pagination strategies that are relative
*
* @return array
*/
public static function getAbsolutePaginationStrategies()
{
return [
self::PAGINATION_STRATEGY_ABSOLUTE,
self::PAGINATION_STRATEGY_PREFIXED_ABSOLUTE,
];
}
/**
* Returns an array of pagination strategies that are section based
*
* @return array
*/
public static function getSectionPaginationStrategies()
{
return [
self::PAGINATION_STRATEGY_SECTION,
self::PAGINATION_STRATEGY_PREFIXED_SECTION,
];
}
/**
* Returns an array of pagination strategies that are prefixed
*
* @return array
*/
public static function getPrefixedPaginationStrategies()
{
return [
self::PAGINATION_STRATEGY_PREFIXED_ABSOLUTE,
self::PAGINATION_STRATEGY_PREFIXED_RELATIVE,
self::PAGINATION_STRATEGY_PREFIXED_SECTION,
];
}
/**
* Get Pagination options
*
* @param array $inclOnly
*
* @return array
*/
public static function getPaginationOptions(array $inclOnly = [])
{
$options = [
self::PAGINATION_STRATEGY_ABSOLUTE => 'Absolute Numbering',
self::PAGINATION_STRATEGY_RELATIVE => 'Relative Numbering',
self::PAGINATION_STRATEGY_SECTION => 'Section Numbering',
self::PAGINATION_STRATEGY_PREFIXED_ABSOLUTE => 'Absolute Numbering With Prefix',
self::PAGINATION_STRATEGY_PREFIXED_RELATIVE => 'Relative Numbering With Prefix',
self::PAGINATION_STRATEGY_PREFIXED_SECTION => 'Section Numbering With Prefix',
];
if ($inclOnly) {
$options = array_filter($options, function ($key) use ($inclOnly) {
return in_array($key, $inclOnly);
}, \ARRAY_FILTER_USE_KEY);
}
return $options;
}
/**
* Checks to see if this Sorting Session has been completed
*
* @return bool
*/
public function hasBeenCompleted()
{
return in_array($this->getSessionStatus(), [
self::SESSION_STATUS_COMPLETED,
self::SESSION_STATUS_EXPORT_PENDING,
self::SESSION_STATUS_EXPORT_IN_PROGRESS,
self::SESSION_STATUS_EXPORT_COMPLETED,
self::SESSION_STATUS_EXPORT_FAILED,
]);
}
/**
* Checks to see if this Sorting Session has completed exporting.
*
* @return bool
*/
public function hasBeenExported()
{
return in_array($this->getSessionStatus(), [
self::SESSION_STATUS_EXPORT_COMPLETED,
]);
}
/**
* @return mixed
*/
public function getCentrePrefix()
{
return $this->centrePrefix;
}
/**
* getActualCentrePrefix
*
* @return mixed
*/
public function getActualCentrePrefix()
{
switch ($this->centrePrefix) {
case self::CENTRE_PREFIX_ALPHA:
return 'A';
break;
case self::CENTRE_PREFIX_NUMERIC:
return 1;
break;
default:
return 'A';
}
}
/**
* @param int $centrePrefix
*
* @return SortingSession
*/
public function setCentrePrefix(?int $centrePrefix = null)
{
$this->centrePrefix = $centrePrefix;
return $this;
}
/**
* Get Centre Prefix options
*
* @param array $inclOnly
*
* @return array
*/
public static function getCentrePrefixOptions(array $inclOnly = [])
{
$options = [
self::CENTRE_PREFIX_ALPHA => 'Alphabetical',
self::CENTRE_PREFIX_NUMERIC => 'Numerical',
];
if ($inclOnly) {
$options = array_filter($options, function ($key) use ($inclOnly) {
return in_array($key, $inclOnly);
}, \ARRAY_FILTER_USE_KEY);
}
return $options;
}
/**
* Set sortStatus
*
* @param int $sortStatus
*
* @return SortingSession
*/
public function setSortStatus($sortStatus)
{
$this->sortStatus = $sortStatus;
return $this;
}
/**
* Get sortStatus
*
* @return int
*/
public function getSortStatus()
{
return $this->sortStatus;
}
/**
* Get sortStatusOptions
*
* @param mixed $showAdmission
* @param mixed $showMemo
*
* @return array
*/
public static function getSortStatusOptions($showAdmission = true, $showMemo = true)
{
$options = [];
$options[self::SORT_STATUS_CLASSIFY] = 'Classify';
$options[self::SORT_STATUS_DATE] = 'Date';
if ($showAdmission) {
$options[self::SORT_STATUS_ADMISSION] = 'Admission';
}
if ($showMemo) {
$options[self::SORT_STATUS_MEMO] = 'File Note';
}
$options[self::SORT_STATUS_QA] = 'QA';
$options[self::SORT_STATUS_COMPLETE] = 'Complete';
$options[self::SORT_STATUS_DOWNLOADED] = 'Downloaded';
return $options;
}
/**
* Get sortStatusLabel
*
* @return string
*/
public function getSortStatusLabel()
{
$options = self::getSortStatusOptions();
return $options[$this->getSortStatus()] ?? '';
}
/**
* Returns true if the SortingSession's sort status is self::SORT_STATUS_CLASSIFY
*
* @return bool
*/
public function isSortStatusClassify()
{
return $this->getSortStatus() === self::SORT_STATUS_CLASSIFY;
}
/**
* Returns true if the SortingSession's sort status is self::SORT_STATUS_DATE
*
* @return bool
*/
public function isSortStatusDate()
{
return $this->getSortStatus() === self::SORT_STATUS_DATE;
}
/**
* Returns true if the SortingSession's sort status is self::SORT_STATUS_ADMISSION
*
* @return bool
*/
public function isSortStatusAdmission()
{
return $this->getSortStatus() === self::SORT_STATUS_ADMISSION;
}
/**
* Returns true if the SortingSession's sort status is self::SORT_STATUS_MEMO
*
* @return bool
*/
public function isSortStatusMemo()
{
return $this->getSortStatus() === self::SORT_STATUS_MEMO;
}
/**
* Returns true if the SortingSession's sort status is self::SORT_STATUS_QA
*
* @return bool
*/
public function isSortStatusQa()
{
return $this->getSortStatus() === self::SORT_STATUS_QA;
}
/**
* Returns true if the SortingSession's sort status is self::SORT_STATUS_COMPLETE
*
* @return bool
*/
public function isSortStatusComplete()
{
return $this->getSortStatus() === self::SORT_STATUS_COMPLETE;
}
/**
* Returns true if the SortingSession's sort status is self::SORT_STATUS_COMPLETE
*
* @return bool
*/
public function isSortStatusDownloaded()
{
return $this->getSortStatus() === self::SORT_STATUS_DOWNLOADED;
}
/**
* Returns true if the SortingSession has the relevant user assigned to it,
* based on it's current sortStatus.
*
* @return bool
*/
public function hasRelevantUserAssigned()
{
return $this->getRelevantUserAssigned() !== null ? true : false;
}
/**
* Gets the relevant user responsible for this sorting session based on the
* SortStatus the SortingSession is in.
*
* @return User
*/
public function getRelevantUserAssigned()
{
switch ($this->getSortStatus()) {
case self::SORT_STATUS_CLASSIFY:
return $this->getSortedBy();
break;
case self::SORT_STATUS_DATE:
return $this->getDatedBy();
break;
case self::SORT_STATUS_ADMISSION:
return $this->getAdmissionBy();
break;
case self::SORT_STATUS_MEMO:
return $this->getMemoBy();
break;
case self::SORT_STATUS_QA:
return $this->getQaBy();
break;
}
return null;
}
/**
* Gets an array of all the assigned Users to this SortingSession
*
* @return array
*/
public function getAllAssignedUsers(): array
{
return [
'Sort' => $this->getSortedBy(),
'Date' => $this->getDatedBy(),
'Admission' => $this->getAdmissionBy(),
'File Note' => $this->getMemoBy(),
'QA' => $this->getQaBy(),
];
}
/**
* Set timeSpentClassify
*
* @param int $timeSpentClassify
*
* @return SortingSession
*/
public function setTimeSpentClassify($timeSpentClassify)
{
$this->timeSpentClassify = $timeSpentClassify;
return $this;
}
/**
* Get timeSpentClassify
*
* @return int
*/
public function getTimeSpentClassify()
{
return $this->timeSpentClassify;
}
/**
* Get timeSpentClassify
*
* @return int
*/
public function getTimeSpentClassifyMinutes()
{
return round($this->getTimeSpentClassify() / 60, 2);
}
/**
* Set timeSpentDating
*
* @param int $timeSpentDating
*
* @return SortingSession
*/
public function setTimeSpentDating($timeSpentDating)
{
$this->timeSpentDating = $timeSpentDating;
return $this;
}
/**
* Get timeSpentDating
*
* @return int
*/
public function getTimeSpentDating()
{
return $this->timeSpentDating;
}
/**
* Get timeSpentDatingMinutes
*
* @return int
*/
public function getTimeSpentDatingMinutes()
{
return round($this->getTimeSpentDating() / 60, 2);
}
/**
* Set timeSpentQa
*
* @param int $timeSpentQa
*
* @return SortingSession
*/
public function setTimeSpentQa($timeSpentQa)
{
$this->timeSpentQa = $timeSpentQa;
return $this;
}
/**
* Get timeSpentQa
*
* @return int
*/
public function getTimeSpentQa()
{
return $this->timeSpentQa;
}
/**
* Get timeSpentQaMinutes
*
* @return int
*/
public function getTimeSpentQaMinutes()
{
return round($this->getTimeSpentQa() / 60, 2);
}
/**
* Add timeSpentClassify
*
* @param int $timeSpentClassify
*
* @return SortingSession
*/
public function addTimeSpentClassify($timeSpentClassify)
{
$this->timeSpentClassify += $timeSpentClassify;
return $this;
}
/**
* Add timeSpentDating
*
* @param int $timeSpentDating
*
* @return SortingSession
*/
public function addTimeSpentDating($timeSpentDating)
{
$this->timeSpentDating += $timeSpentDating;
return $this;
}
/**
* Add timeSpentAdmission
*
* @param int $timeSpentAdmission
*
* @return SortingSession
*/
public function addTimeSpentAdmission($timeSpentAdmission)
{
$this->timeSpentAdmission += $timeSpentAdmission;
return $this;
}
/**
* Add timeSpentMemo
*
* @param int $timeSpentMemo
*
* @return SortingSession
*/
public function addTimeSpentMemo($timeSpentMemo)
{
$this->timeSpentMemo += $timeSpentMemo;
return $this;
}
/**
* Add timeSpentQa
*
* @param int $timeSpentQa
*
* @return SortingSession
*/
public function addTimeSpentQa($timeSpentQa)
{
$this->timeSpentQa += $timeSpentQa;
return $this;
}
/**
* Set deletedAt
*
* @param \DateTime $deletedAt
*
* @return SortingSession
*/
public function setDeletedAt($deletedAt)
{
$this->deletedAt = $deletedAt;
return $this;
}
/**
* Get deletedAt
*
* @return \DateTime
*/
public function getDeletedAt()
{
return $this->deletedAt;
}
/**
* Set dateSentToSorter
*
* @param \DateTime $dateSentToSorter
*
* @return SortingSession
*/
public function setDateSentToSorter($dateSentToSorter = null)
{
$this->dateSentToSorter = $dateSentToSorter;
return $this;
}
/**
* Get dateSentToSorter
*
* @return \DateTime
*/
public function getDateSentToSorter()
{
return $this->dateSentToSorter;
}
/**
* Set dateDownloaded
*
* @param \DateTime $dateDownloaded
*
* @return SortingSession
*/
public function setDateDownloaded($dateDownloaded)
{
$this->dateDownloaded = $dateDownloaded;
return $this;
}
/**
* Get dateDownloaded
*
* @return \DateTime
*/
public function getDateDownloaded()
{
return $this->dateDownloaded;
}
/**
* Set downloadedBy
*
* @param User $downloadedBy
*
* @return SortingSession
*/
public function setDownloadedBy(?User $downloadedBy = null)
{
$this->downloadedBy = $downloadedBy;
return $this;
}
/**
* Get downloadedBy
*
* @return User
*/
public function getDownloadedBy()
{
return $this->downloadedBy;
}
/**
* Get dueDate based on BatchRequest
*
* @return void
*/
public function getBatchesMaxDueDate()
{
$criteria = Criteria::create()
->orderBy(['estimatedDeadlineDate' => Criteria::DESC])
;
return $this->getBatchRequests()->count() > 0 && $this->getBatchRequests()->matching($criteria)->first() ? $this->getBatchRequests()->matching($criteria)->first()->getEstimatedDeadlineDate() : null;
}
/**
* Get mrsFormFilename
*
* @return string
*/
public function getMrsFormFilename()
{
return $this->mrsFormFilename;
}
/**
* Set mrsFormFile
*
* @param string $mrsFormFile
*
* @return SortingSession
*/
public function setMrsFormFile($mrsFormFile)
{
$this->mrsFormFile = $mrsFormFile;
if (null !== $mrsFormFile) {
// It is required that at least one field changes if you are using doctrine
// otherwise the event listeners won't be called and the file is lost
$this->updated = new \DateTimeImmutable();
}
return $this;
}
/**
* Set mrsFormFilename
*
* @param string $mrsFormFilename
*
* @return SortingSession
*/
public function setMrsFormFilename($mrsFormFilename)
{
$this->mrsFormFilename = $mrsFormFilename;
return $this;
}
/**
* Get mrsFormFile
*
* @return string
*/
public function getMrsFormFile()
{
return $this->mrsFormFile;
}
/**
* Set dueDate
*
* @param \DateTime $dueDate
*
* @return SortingSession
*/
public function setDueDate($dueDate)
{
$this->dueDate = $dueDate;
return $this;
}
/**
* Get dueDate
*
* @return \DateTime
*/
public function getDueDate()
{
return $this->dueDate;
}
/**
* Set estCompletionDate
*
* @param \DateTime $estCompletionDate
*
* @return SortingSession
*/
public function setEstCompletionDate($estCompletionDate)
{
$this->estCompletionDate = $estCompletionDate;
return $this;
}
/**
* Get estCompletionDate
*
* @return \DateTime
*/
public function getEstCompletionDate()
{
return $this->estCompletionDate;
}
/**
* Set startPageNumber
*
* @param int $startPageNumber
*
* @return SortingSession
*/
public function setStartPageNumber($startPageNumber)
{
$this->startPageNumber = $startPageNumber;
return $this;
}
/**
* Get startPageNumber
*
* @return int
*/
public function getStartPageNumber()
{
return $this->startPageNumber;
}
/**
* Add detail
*
* @param SortingSessionDetail $detail
*
* @return SortingSession
*/
public function addDetail(SortingSessionDetail $detail)
{
$this->details[] = $detail;
return $this;
}
/**
* Set classifyCompletePerc
*
* @param int $classifyCompletePerc
*
* @return SortingSession
*/
public function setClassifyCompletePerc($classifyCompletePerc)
{
$this->classifyCompletePerc = $classifyCompletePerc;
return $this;
}
/**
* Remove detail
*
* @param SortingSessionDetail $detail
*/
public function removeDetail(SortingSessionDetail $detail)
{
$this->details->removeElement($detail);
}
/**
* Get details
*
* @return Collection
*/
public function getDetails()
{
return $this->details;
}
/**
* Get classifyCompletePerc
*
* @return int
*/
public function getClassifyCompletePerc()
{
return $this->classifyCompletePerc;
}
/**
* Set dateCompletePerc
*
* @param int $dateCompletePerc
*
* @return SortingSession
*/
public function setDateCompletePerc($dateCompletePerc)
{
$this->dateCompletePerc = $dateCompletePerc;
return $this;
}
/**
* Get dateCompletePerc
*
* @return int
*/
public function getDateCompletePerc()
{
return $this->dateCompletePerc;
}
/**
* Set centrePrefixPadding
*
* @param int $centrePrefixPadding
*
* @return SortingSession
*/
public function setCentrePrefixPadding($centrePrefixPadding)
{
$this->centrePrefixPadding = $centrePrefixPadding;
return $this;
}
/**
* Get centrePrefixPadding
*
* @return int
*/
public function getCentrePrefixPadding()
{
return $this->centrePrefixPadding;
}
/**
* Set pageNumberPadding
*
* @param int $pageNumberPadding
*
* @return SortingSession
*/
public function setPageNumberPadding($pageNumberPadding)
{
$this->pageNumberPadding = $pageNumberPadding;
return $this;
}
/**
* Get pageNumberPadding
*
* @return int
*/
public function getPageNumberPadding()
{
return $this->pageNumberPadding;
}
/**
* Set exportError
*
* @param string $exportError
*
* @return SortingSession
*/
public function setExportError($exportError)
{
$this->exportError = $exportError;
return $this;
}
/**
* Get exportError
*
* @return string
*/
public function getExportError()
{
return $this->exportError;
}
/**
* Set admissionBy.
*
* @param User|null $admissionBy
*
* @return SortingSession
*/
public function setAdmissionBy(?User $admissionBy = null)
{
$this->admissionBy = $admissionBy;
return $this;
}
/**
* Get admissionBy.
*
* @return User|null
*/
public function getAdmissionBy()
{
return $this->admissionBy;
}
/**
* Set timeSpentAdmission.
*
* @param int $timeSpentAdmission
*
* @return SortingSession
*/
public function setTimeSpentAdmission($timeSpentAdmission)
{
$this->timeSpentAdmission = $timeSpentAdmission;
return $this;
}
/**
* Get timeSpentAdmission.
*
* @return int
*/
public function getTimeSpentAdmission()
{
return $this->timeSpentAdmission;
}
/**
* Get timeSpentAdmissionMinutes
*
* @return int
*/
public function getTimeSpentAdmissionMinutes()
{
return round($this->getTimeSpentAdmission() / 60, 2);
}
/**
* Set exportStoreJson.
*
* @param string|null $exportStoreJson
*
* @return SortingSession
*/
public function setExportStoreJson($exportStoreJson = null)
{
$this->exportStoreJson = $exportStoreJson;
return $this;
}
/**
* Get exportStoreJson.
*
* @return string|null
*/
public function getExportStoreJson()
{
return $this->exportStoreJson;
}
/**
* Get getExportStoreArray
*
* @return array
*/
public function getExportStoreArray()
{
if (!$this->getExportStoreJson()) {
return [];
}
return json_decode($this->getExportStoreJson(), true);
}
/**
* Set version.
*
* @param string|null $version
*
* @return SortingSession
*/
public function setVersion($version = null)
{
$this->version = $version;
return $this;
}
/**
* Get version.
*
* @return string|null
*/
public function getVersion()
{
return $this->version;
}
/**
* Returns true if the SortingSession was done in the old DocSorter version.
*
* @return bool
*/
public function isOldVersion()
{
return $this->getVersion() === self::VERSION_OLD;
}
/**
* Set exportPushStatus.
*
* @param string|null $exportPushStatus
*
* @return SortingSession
*/
public function setExportPushStatus($exportPushStatus = null)
{
// Clear the push error when we do a new push.
if ($exportPushStatus === self::EXPORT_PUSH_STATUS_PENDING) {
$this->setExportError('');
}
$this->exportPushStatus = $exportPushStatus;
return $this;
}
/**
* Get exportPushStatus.
*
* @return string|null
*/
public function getExportPushStatus()
{
return $this->exportPushStatus;
}
/**
* Returns true if the SortingSession is pending export push to medical records.
*
* @return bool
*/
public function isExportPushPending()
{
return $this->getExportPushStatus() === self::EXPORT_PUSH_STATUS_PENDING;
}
/**
* Returns true if the SortingSession is in progress export push to medical records.
*
* @return bool
*/
public function isExportPushInProgress()
{
return $this->getExportPushStatus() === self::EXPORT_PUSH_STATUS_IN_PROGRESS;
}
/**
* Returns true if the SortingSession is completed export push to medical records.
*
* @return bool
*/
public function isExportPushCompleted()
{
return $this->getExportPushStatus() === self::EXPORT_PUSH_STATUS_COMPLETED;
}
/**
* Returns true if the SortingSession is failed export push to medical records.
*
* @return bool
*/
public function isExportPushFailed()
{
return $this->getExportPushStatus() === self::EXPORT_PUSH_STATUS_FAILED;
}
/**
* Set exportPushBy.
*
* @param User|null $exportPushBy
*
* @return SortingSession
*/
public function setExportPushBy(?User $exportPushBy = null)
{
$this->exportPushBy = $exportPushBy;
return $this;
}
/**
* Get exportPushBy.
*
* @return User|null
*/
public function getExportPushBy()
{
return $this->exportPushBy;
}
/**
* Set memoStatus.
*
* @param string|null $memoStatus
*
* @return SortingSession
*/
public function setMemoStatus($memoStatus = null)
{
$this->memoStatus = $memoStatus;
return $this;
}
/**
* Get memoStatus.
*
* @return string|null
*/
public function getMemoStatus()
{
return $this->memoStatus;
}
/**
* Get MemoStatusOptions
*
* @param bool $selectableOnly - only return options that can be selected by a user.
*
* @return array
*/
public static function getMemoStatusOptions(bool $selectableOnly = false)
{
// Leave this in place, as previously Ready to Sync was part not selectable - but we had to change this,
$options = [
];
$selectableOptions = [
self::MEMO_STATUS_READY_TO_SYNC => 'Ready to Sync',
self::MEMO_STATUS_PENDING => 'Pending',
self::MEMO_READY_FOR_UPLOAD => 'Ready for Upload',
self::MEMO_STATUS_UPLOADED => 'Uploaded',
];
return array_merge($selectableOnly ? [] : $options, $selectableOptions);
}
/**
* Get MemoStatusLabel
*
* @return string
*/
public function getMemoStatusLabel()
{
$options = self::getMemoStatusOptions();
return $options[$this->getMemoStatus()] ?? '';
}
/**
* Returns true if the memo status is ready to sync.
*
* @return string
*/
public function isMemoReadyToSync()
{
return $this->getMemoStatus() === self::MEMO_STATUS_READY_TO_SYNC;
}
/**
* Set timeSpentMemo.
*
* @param int $timeSpentMemo
*
* @return SortingSession
*/
public function setTimeSpentMemo($timeSpentMemo)
{
$this->timeSpentMemo = $timeSpentMemo;
return $this;
}
/**
* Get timeSpentMemo.
*
* @return int
*/
public function getTimeSpentMemo()
{
return $this->timeSpentMemo;
}
/**
* Get timeSpentMemoMinutes
*
* @return int
*/
public function getTimeSpentMemoMinutes()
{
return round($this->getTimeSpentMemo() / 60, 2);
}
/**
* Set qaFailNote.
*
* @param string|null $qaFailNote
*
* @return SortingSession
*/
public function setQaFailNote($qaFailNote = null)
{
$this->qaFailNote = $qaFailNote;
return $this;
}
/**
* Get qaFailNote.
*
* @return string|null
*/
public function getQaFailNote()
{
return $this->qaFailNote;
}
/**
* Set memoBy.
*
* @param User|null $memoBy
*
* @return SortingSession
*/
public function setMemoBy(?User $memoBy = null)
{
$this->memoBy = $memoBy;
return $this;
}
/**
* Get memoBy.
*
* @return User|null
*/
public function getMemoBy()
{
return $this->memoBy;
}
public static function getChronologyRequiredOptions()
{
$options = [];
$options[0] = 'No';
$options[1] = 'Yes';
return $options;
}
/**
* Determines whether a chronology is requested.
*
* @return string 'Yes'/'No'
*/
public function getChronologyRequired()
{
$chronologies = $this->getProject()->getChronologyRequests();
/** @var ChronologyRequest $latestChronology */
$latestChronology = $chronologies->last();
if ($latestChronology
&& !$latestChronology->getServiceRequest()->isComplete()
&& !$latestChronology->getServiceRequest()->isCancelled()
&& ($latestChronology->getServiceOption()->appliesToSubCategoryChronAndSor() || $latestChronology->getServiceOption()->appliesToSubCategoryChronOnly())) {
return 'Yes';
}
return 'No';
}
/**
* Returns all batch documents associated with the sorting session that are in status failed.
*
* @return array
*/
public function getFailedBatchDocuments()
{
$failedBatchDocuments = [];
/** @var BatchRequest $batchRequest */
foreach ($this->getBatchRequests() as $batchRequest) {
/** @var BatchDocument $batchDocument */
foreach ($batchRequest->getBatchDocuments() as $batchDocument) {
if ($batchDocument->isFailed()) {
$failedBatchDocuments[] = $batchDocument;
}
}
}
return $failedBatchDocuments;
}
/**
* Returns all batch request IDs as a string associated with the sorting session,
* that have a batch document in status failed.
*
* @return string
*/
public function getFailedBatchDocumentsBatchRequestIdsStr()
{
return
implode(
array_unique(
array_map(
function (BatchDocument $batchDocument) {
return $batchDocument->getBatchRequest()->getServiceRequestGroupId();
},
$this->getFailedBatchDocuments()
)
)
);
}
/**
* Set exportPushUnsortedStatus.
*
* @param string|null $exportPushUnsortedStatus
*
* @return SortingSession
*/
public function setExportPushUnsortedStatus($exportPushUnsortedStatus = null)
{
$this->exportPushUnsortedStatus = $exportPushUnsortedStatus;
return $this;
}
/**
* Get exportPushUnsortedStatus.
*
* @return string|null
*/
public function getExportPushUnsortedStatus()
{
return $this->exportPushUnsortedStatus;
}
/**
* Returns true if exportPushUnsortedStatus is pending.
*
* @return bool
*/
public function isExportPushUnsortedStatusPending(): bool
{
return $this->exportPushUnsortedStatus === self::EXPORT_UNSORTED_PUSH_STATUS_PENDING;
}
/**
* Returns true if exportPushUnsortedStatus is in progress.
*
* @return bool
*/
public function isExportPushUnsortedStatusInProgress(): bool
{
return $this->exportPushUnsortedStatus === self::EXPORT_UNSORTED_PUSH_STATUS_IN_PROGRESS;
}
/**
* Returns true if exportPushUnsortedStatus is completed.
*
* @return bool
*/
public function isExportPushUnsortedStatusCompleted(): bool
{
return $this->exportPushUnsortedStatus === self::EXPORT_UNSORTED_PUSH_STATUS_COMPLETED;
}
/**
* Returns true if exportPushUnsortedStatus is failed.
*
* @return bool
*/
public function isExportPushUnsortedStatusFailed(): bool
{
return $this->exportPushUnsortedStatus === self::EXPORT_UNSORTED_PUSH_STATUS_FAILED;
}
/**
* Set exportPushUnsortedBy.
*
* @param User|null $exportPushUnsortedBy
*
* @return SortingSession
*/
public function setExportPushUnsortedBy(?User $exportPushUnsortedBy = null)
{
$this->exportPushUnsortedBy = $exportPushUnsortedBy;
return $this;
}
/**
* Get exportPushUnsortedBy.
*
* @return User|null
*/
public function getExportPushUnsortedBy()
{
return $this->exportPushUnsortedBy;
}
/**
* Set activeSortingUser.
*
* @param User|null $activeSortingUser
*
* @return SortingSession
*/
public function setActiveSortingUser(?User $activeSortingUser = null)
{
$this->activeSortingUser = $activeSortingUser;
return $this;
}
/**
* Get activeSortingUser.
*
* @return User|null
*/
public function getActiveSortingUser(): ?User
{
return $this->activeSortingUser;
}
/**
* Returns a description of who the current active sorting user is.
*
* @return string
*/
public function getActiveSortingUserDescription(): string
{
if ($this->getActiveSortingUser()) {
return sprintf('%1$s (%2$s)', $this->getActiveSortingUser()->getFullName(), $this->getActiveSortingUser()->getEmail());
}
return '';
}
/**
* Returns true if external editing is allowed for the sorting session for the specified user.
*
* @param User $user
*
* @return bool
*/
public function allowExternalEditing(User $user): bool
{
// Allow external editing for these sort statuses
$allowSortStatus = $this->isSortStatusComplete() || $this->isSortStatusDownloaded();
// Allow external editing if no active sorter on sorting session
$allowUnassignedSortingSession = $this->getActiveSortingUser() === null || $user === $this->getActiveSortingUser();
return $allowSortStatus && $allowUnassignedSortingSession;
}
/**
* Set sortSessionType
*
* @param string $sortSessionType
*
* @return SortingSession
*/
public function setSortSessionType($sortSessionType)
{
$this->sortSessionType = $sortSessionType;
return $this;
}
/**
* Get sortSessionType
*
* @return string
*/
public function getSortSessionType()
{
return $this->sortSessionType;
}
/**
* Return array of ClientSortSessionTypeOptions
*
* @return array
*/
public static function getClientSortSessionTypeOptions()
{
$options = [
self::SORT_SESSION_TYPE_CLIENT => 'Client Session',
];
return $options;
}
/**
* Returns an array of permitted values for the Labels field.
*
* @return array
*/
public static function getSortSessionTypeOptions()
{
$typeOptions = self::getConstantsWithLabelsAsChoices('SORT_SESSION_TYPE');
return $typeOptions;
}
/**
* Returns an array of Labels to be readable by humans.
*
* @return array
*/
public function getSortSessionTypeLabels()
{
$labelOptions = array_flip(self::getClientSortSessionTypeOptions());
return array_map(function ($label) use ($labelOptions) {
return $labelOptions[$label] ?: 'Unknown';
}, $this->labels);
}
/**
* Returns a human readable version of the type isSentEmailLabel
*
* @return string
*/
public function getSortSessionTypeLabel()
{
$options = array_flip(self::getSortSessionTypeOptions());
return $options[$this->getSortSessionType()] ?? '';
}
/**
* Returns true if all the sorting session stages are the same
*
* @return bool
*/
public function hasSameSorters()
{
$isSame = true;
$sortedBy = $this->getSortedBy();
$arr = [
$this->getDatedBy(),
$this->getAdmissionBy(),
$this->getMemoBy(),
$this->getQaBy(),
];
foreach ($arr as $value) {
if ($value !== $sortedBy) {
$isSame = false;
break;
}
}
return $isSame;
}
/**
* Method to check if session is a Client session. Returns true if it's a client session
*
* @return bool
*/
public function isClientSortingSession(): bool
{
return $this->getSortSessionType() === self::SORT_SESSION_TYPE_CLIENT;
}
/**
* Method to check if session is a Medbrief session. Returns true if it's a Medbrief session
*
* @return bool
*/
public function isMedbriefSortingSession(): bool
{
return $this->getSortSessionType() === self::SORT_SESSION_TYPE_MEDBRIEF;
}
/**
* Get the value of pageNumberPositionHorizontal
*
* @return int
*/
public function getPageNumberPositionHorizontal()
{
return $this->pageNumberPositionHorizontal;
}
/**
* Set the value of pageNumberPositionHorizontal
*
* @param int|null $pageNumberPositionHorizontal|null
*
* @return self
*/
public function setPageNumberPositionHorizontal(?int $pageNumberPositionHorizontal = null)
{
if ($pageNumberPositionHorizontal !== null) {
$this->pageNumberPositionHorizontal = $pageNumberPositionHorizontal;
}
return $this;
}
/**
* Get the value of pageNumberPositionVertical
*
* @return int
*/
public function getPageNumberPositionVertical()
{
return $this->pageNumberPositionVertical;
}
/**
* Set the value of pageNumberPositionVertical
*
* @param int|null $pageNumberPositionVertical
*
* @return self
*/
public function setPageNumberPositionVertical(?int $pageNumberPositionVertical = null)
{
if ($pageNumberPositionVertical !== null) {
$this->pageNumberPositionVertical = $pageNumberPositionVertical;
}
return $this;
}
/**
* Get the value of pageNumberSize
*
* @return int
*/
public function getPageNumberSize()
{
return $this->pageNumberSize;
}
/**
* Set the value of pageNumberSize
*
* @param int|null $pageNumberSize
*
* @return self
*/
public function setPageNumberSize(?int $pageNumberSize = null)
{
if ($pageNumberSize !== null) {
$this->pageNumberSize = $pageNumberSize;
}
return $this;
}
/**
* Get the value of pageNumberBackground
*
* @return bool
*/
public function getPageNumberBackground()
{
return $this->pageNumberBackground;
}
/**
* Set the value of pageNumberBackground
*
* @param bool|null $pageNumberBackground
*
* @return self
*/
public function setPageNumberBackground(?bool $pageNumberBackground = null)
{
if ($pageNumberBackground !== null) {
$this->pageNumberBackground = $pageNumberBackground;
}
return $this;
}
/**
* Get the value of isUrgent
*
* @return bool
*/
public function getIsUrgent()
{
return $this->isUrgent;
}
/**
* @return string
*/
public function getIsUrgentLabel(): string
{
return $this->isUrgent ? 'Yes' : 'No';
}
/**
* Set the value of isUrgent
*
* @param bool $isUrgent
*
* @return self
*/
public function setIsUrgent(bool $isUrgent)
{
$this->isUrgent = $isUrgent;
return $this;
}
/**
* @return Collection|SortingSessionMemo[]
*/
public function getSortingSessionMemos(): Collection
{
return $this->sortingSessionMemos;
}
/**
* @param SortingSessionMemo $sortingSessionMemo
*
* @return self
*/
public function addSortingSessionMemo(SortingSessionMemo $sortingSessionMemo): self
{
if (!$this->sortingSessionMemos->contains($sortingSessionMemo)) {
$this->sortingSessionMemos[] = $sortingSessionMemo;
$sortingSessionMemo->setSortingSession($this);
}
return $this;
}
/**
* @param SortingSessionMemo $sortingSessionMemo
*
* @return self
*/
public function removeSortingSessionMemo(SortingSessionMemo $sortingSessionMemo): self
{
if ($this->sortingSessionMemos->removeElement($sortingSessionMemo)) {
// set the owning side to null (unless already changed)
if ($sortingSessionMemo->getSortingSession() === $this) {
$sortingSessionMemo->setSortingSession(null);
}
}
return $this;
}
/**
* @return bool
*/
public function getRequiresPreProcessing(): bool
{
return $this->requiresPreProcessing;
}
/**
* @param bool $requiresPreProcessing
*
* @return self
*/
public function setRequiresPreProcessing(bool $requiresPreProcessing): self
{
$this->requiresPreProcessing = $requiresPreProcessing;
return $this;
}
/**
* @inheritDoc
*/
public function setPreprocessStatusComplete(): PreprocessableInterface
{
$this->setSessionStatus(self::SESSION_STATUS_READY_FOR_SORTER);
return $this;
}
/**
* @inheritDoc
*/
public function setPreprocessStatusFailed(): PreprocessableInterface
{
$this->setSessionStatus(self::SESSION_STATUS_PREPROCESSING_FAILED);
return $this;
}
/**
* @inheritDoc
*/
public function setPreprocessStatusInProgress(): PreprocessableInterface
{
$this->setSessionStatus(self::SESSION_STATUS_PREPROCESSING_IN_PROGRESS);
return $this;
}
/**
* @return PreprocessItemInterface[]
*/
public function getPreprocessItems(): array
{
return $this->getBatchRequests()->filter(function (BatchRequest $batchRequest) {
// Exclude complete and 'Other' centre type batch requests from pre-processing
return $batchRequest->allowPreprocessing();
})->toArray();
}
/**
* Gets a CSV of all pre-processing items for this sorting session.
* A '*' indicates the item has not been submitted for pre-processing yet,
* and will submitted on the next 'Send to Sorter' run.
*
* @return string
*/
public function getPreprocessItemsCsv(): string
{
return implode(', ', array_map(function (BatchRequest $batchRequest) {
return $batchRequest->getServiceRequestGroupId() . ($batchRequest->isSubmittedForPreprocessing() === false ? '*' : '');
}, $this->getPreprocessItems()));
}
/**
* @inheritDoc
*/
public function hasIncompletePreprocessItems(): bool
{
foreach ($this->getPreprocessItems() as $preprocessItem) {
$preprocessDocuments = $preprocessItem->getPreprocessDocumentsArray();
foreach ($preprocessDocuments as $preprocessDocument) {
if ($preprocessDocument->isIncomplete()) {
return true;
}
}
}
return false;
}
/**
* Convenience method to check session status of a SortingSession is pending.
*
* @return bool
*/
public function isSessionStatusPending(): bool
{
return $this->getSessionStatus() === self::SESSION_STATUS_PENDING
|| $this->getSessionStatus() === self::SESSION_STATUS_EXPORT_PENDING
|| $this->getSessionStatus() === self::SESSION_STATUS_PREPROCESSING_PENDING;
}
/**
* Convenience method to check session status of a SortingSession is in the export phase.
*
* @return bool
*/
public function isSessionStatusExport(): bool
{
return $this->getSessionStatus() === self::SESSION_STATUS_EXPORT_IN_PROGRESS
|| $this->getSessionStatus() === self::SESSION_STATUS_EXPORT_PENDING;
}
/**
* Convenience method to check session status of a SortingSession when it is ready for sorter.
*
* @return bool
*/
public function isSessionStatusReadyForSorter(): bool
{
return $this->getSessionStatus() === self::SESSION_STATUS_READY_FOR_SORTER;
}
/**
* Convenience method to check session status of a SortingSession is in progress.
*
* @return bool
*/
public function isSessionStatusInProgress(): bool
{
return $this->getSessionStatus() === self::SESSION_STATUS_IN_PROGRESS
|| $this->getSessionStatus() === self::SESSION_STATUS_PREPROCESSING_IN_PROGRESS;
}
/**
* Convenience method to check session status of a SortingSession that is paused.
*
* @return bool
*/
public function isSessionStatusPaused(): bool
{
return $this->getSessionStatus() === self::SESSION_STATUS_PAUSED;
}
/**
* Convenience method to check session status of a SortingSession that has missing pages.
*
* @return bool
*/
public function isSessionStatusPagesMissing(): bool
{
return $this->getSessionStatus() === self::SESSION_STATUS_PAGES_MISSING;
}
/**
* Convenience method to check session status of a SortingSession is completed.
*
* @return bool
*/
public function isSessionStatusCompleted(): bool
{
return $this->getSessionStatus() === self::SESSION_STATUS_COMPLETED
|| $this->getSessionStatus() === self::SESSION_STATUS_EXPORT_COMPLETED;
}
/**
* Convenience method to check session status of a SortingSession has failed in 3 preparing,exporting and preprocessing.
*
* @return bool
*/
public function hasSessionStatusFailed(): bool
{
return $this->getSessionStatus() === self::SESSION_STATUS_PREPARE_FAILED
|| $this->getSessionStatus() === self::SESSION_STATUS_EXPORT_FAILED
|| $this->getSessionStatus() === self::SESSION_STATUS_PREPROCESSING_FAILED;
}
/**
* Maps the sort options from the Sort entity on the associated MatterRequest,
* with the pagination options on the SortingSession.
*
* @param Sort $sort
*
* @return void
*/
protected function mapPaginationOptions(Sort $sort)
{
// centrePrefix
if ($sort->isCentrePrefixAlpha()) {
$this->setCentrePrefix(self::CENTRE_PREFIX_ALPHA);
} elseif ($sort->isCentrePrefixNumeric()) {
$this->setCentrePrefix(self::CENTRE_PREFIX_NUMERIC);
}
// Pagination Strategy
if ($sort->isPagePrefixNone()) {
if ($sort->isPaginationRunCentre()) {
$this->setPaginationStrategy(self::PAGINATION_STRATEGY_RELATIVE);
} elseif ($sort->isPaginationRunContinuous()) {
$this->setPaginationStrategy(self::PAGINATION_STRATEGY_ABSOLUTE);
}
} else {
if ($sort->isPaginationRunCentre()) {
$this->setPaginationStrategy(self::PAGINATION_STRATEGY_PREFIXED_RELATIVE);
} elseif ($sort->isPaginationRunContinuous()) {
$this->setPaginationStrategy(self::PAGINATION_STRATEGY_PREFIXED_ABSOLUTE);
}
if ($sort->isPagePrefixLetter()) {
$this->setPaginationPrefix('A');
} elseif ($sort->isPagePrefixNumeric()) {
$this->setPaginationPrefix('1.');
}
}
$this->setPageNumberPadding($sort->getPageNumberPaddingInteger());
$this->setPageNumberPositionHorizontal($sort->getPageNumberPositionHorizontal());
$this->setPageNumberPositionVertical($sort->getPageNumberPositionVertical());
$this->setPageNumberSize($sort->getPageNumberSize());
$this->setPageNumberBackground($sort->getPageNumberBackground());
}
}