src/Entity/RecordsRequest.php line 33

Open in your IDE?
  1. <?php
  2. namespace MedBrief\MSR\Entity;
  3. use DateTime;
  4. use DH\Auditor\Provider\Doctrine\Auditing\Annotation as Audit;
  5. use Doctrine\ORM\Mapping as ORM;
  6. use Gedmo\Mapping\Annotation as Gedmo;
  7. use MedBrief\MSR\Entity\Embeddable\RecordsReceived;
  8. use MedBrief\MSR\Entity\MatterRequest\TrustCentre as MatterRequestTrustCentre;
  9. use MedBrief\MSR\Entity\RequestType\RequestTypeAwareInterface;
  10. use MedBrief\MSR\Entity\RequestType\RequestTypeAwareTrait;
  11. use MedBrief\MSR\Entity\Serviceable\ServiceableInterface;
  12. use MedBrief\MSR\Entity\Serviceable\ServiceableTrait;
  13. use MedBrief\MSR\Service\LetterGenerator\Letter\LetterInterface;
  14. /**
  15. * Uses the ServiceableInterface to indicate this entity represents a service rendered to an Account,
  16. * and can be associated with a ServiceRequest.
  17. *
  18. * @ORM\Table(name="RecordsRequest", indexes={@ORM\Index(name="status_idx", columns={"status"})})
  19. *
  20. * @ORM\Entity
  21. *
  22. * @ORM\HasLifecycleCallbacks
  23. *
  24. * @Gedmo\SoftDeleteable(fieldName="deletedAt", timeAware=false)
  25. *
  26. * @Audit\Auditable
  27. *
  28. * @Audit\Security(view={"ROLE_ALLOWED_TO_AUDIT"})
  29. */
  30. class RecordsRequest implements ServiceableInterface, RequestTypeAwareInterface, LetterInterface
  31. {
  32. use ServiceableTrait;
  33. use RequestTypeAwareTrait;
  34. // These are the old status constants.
  35. // The new constants live on the \MedBrief\MSR\Entity\Timeline\AbstractTimelineType
  36. // object associated with the ServiceRequest::serviceOption for the RecordsRequest.
  37. public const STATUS_INSTRUCTED = 1;
  38. public const STATUS_REQUESTED = 2;
  39. public const STATUS_CHASED = 3;
  40. public const STATUS_RECEIVED = 4;
  41. public const STATUS_SORTED = 5;
  42. public const STATUS_UPLOADED = 6;
  43. public const STATUS_CHRONOLOGY = 7;
  44. // request_method constants
  45. public const REQUEST_METHOD_EMAIL = 0;
  46. public const REQUEST_METHOD_FAX = 1;
  47. public const REQUEST_METHOD_POST = 2;
  48. public const REQUEST_METHOD_PORTAL = 3;
  49. // The prefix we use to identify a RecordsRequests's reference ID.
  50. public const REFERENCE_ID_PREFIX = 'RR-';
  51. // Constants used for auto date calculation
  52. public const AUTO_DUE_DATE = '+30day';
  53. /**
  54. * @var ServiceRequest
  55. *
  56. * @ORM\OneToOne(targetEntity="MedBrief\MSR\Entity\ServiceRequest", mappedBy="recordsRequest", cascade={"persist"})
  57. */
  58. protected $serviceRequest;
  59. /**
  60. * @var int
  61. *
  62. * @ORM\Column(name="id", type="integer")
  63. *
  64. * @ORM\Id
  65. *
  66. * @ORM\GeneratedValue(strategy="IDENTITY")
  67. */
  68. private $id;
  69. /**
  70. * @var DateTime|null
  71. *
  72. * @ORM\Column(name="deletedAt", type="datetime", nullable=true)
  73. */
  74. private $deletedAt;
  75. /**
  76. * @var string|null
  77. *
  78. * @ORM\Column(name="records_requested_from_other", type="string", nullable=true)
  79. */
  80. private $records_requested_from_other;
  81. /**
  82. * @var int|null
  83. *
  84. * @ORM\Column(name="archiveBoxNumber", type="integer", nullable=true)
  85. */
  86. private $archiveBoxNumber;
  87. /**
  88. * @var DateTime|null
  89. *
  90. * @ORM\Column(name="dateDestroyedOrReturned", type="date", nullable=true)
  91. */
  92. private $dateDestroyedOrReturned;
  93. /**
  94. * @var DateTime|null
  95. *
  96. * @ORM\Column(name="date_records_requested", type="date", nullable=true)
  97. */
  98. private $date_records_requested;
  99. /**
  100. * @var string|null
  101. *
  102. * @ORM\Column(name="records_sent_by", type="string", nullable=true)
  103. */
  104. private $records_sent_by;
  105. /**
  106. * @var DateTime|null
  107. *
  108. * @ORM\Column(name="date_records_received", type="date", nullable=true)
  109. */
  110. private $date_records_received;
  111. /**
  112. * @var int|null
  113. *
  114. * @ORM\Column(name="status", type="integer", nullable=true)
  115. */
  116. private $status;
  117. /**
  118. * @var DateTime|null
  119. *
  120. * @ORM\Column(name="date_acknowledged", type="date", nullable=true)
  121. */
  122. private $date_acknowledged;
  123. /**
  124. * @var DateTime|null
  125. *
  126. * @ORM\Column(name="date_password_provided", type="date", nullable=true)
  127. */
  128. private $date_password_provided;
  129. /**
  130. * @var int|null
  131. *
  132. * @ORM\Column(name="request_method", type="integer", nullable=true)
  133. */
  134. private $request_method;
  135. /**
  136. * @var string|null
  137. *
  138. * @ORM\Column(name="internal_document_password", type="string", nullable=true)
  139. */
  140. private $internal_document_password;
  141. /**
  142. * @var string|null
  143. *
  144. * @ORM\Column(name="centre_password", type="string", nullable=true)
  145. */
  146. private $centre_password;
  147. /**
  148. * @var bool
  149. *
  150. * @ORM\Column(name="postage_paid", type="boolean", options={"default"=false})
  151. */
  152. private $postage_paid = false;
  153. /**
  154. * @var string|null
  155. *
  156. * @ORM\Column(name="postage_amount", type="decimal", precision=7, scale=2, nullable=true)
  157. */
  158. private $postage_amount;
  159. /**
  160. * @var int|null
  161. *
  162. * @ORM\Column(name="radiology_disc_count", type="integer", nullable=true)
  163. */
  164. private $radiology_disc_count;
  165. /**
  166. * The date that an update is due on this records request.
  167. *
  168. * @var DateTime|null
  169. *
  170. * @ORM\Column(name="update_due_date", type="date", nullable=true)
  171. */
  172. private $update_due_date;
  173. /**
  174. * The date that the records request is due.
  175. *
  176. * @var DateTime|null
  177. *
  178. * @ORM\Column(name="due_date", type="date", nullable=true)
  179. */
  180. private $due_date;
  181. /**
  182. * @var string|null
  183. *
  184. * @ORM\Column(name="trust_reference", type="string", nullable=true)
  185. */
  186. private $trust_reference;
  187. /**
  188. * @var bool
  189. *
  190. * @ORM\Column(name="collate_before_processing", type="boolean", options={"default"=false})
  191. */
  192. private $collate_before_processing = false;
  193. /**
  194. * @var string|null
  195. *
  196. * @ORM\Column(name="patientName", type="string", nullable=true)
  197. */
  198. private $patientName;
  199. /**
  200. * @var DateTime|null
  201. *
  202. * @ORM\Column(name="patientDateOfBirth", type="date", nullable=true)
  203. */
  204. private $patientDateOfBirth;
  205. /**
  206. * @var bool
  207. *
  208. * @ORM\Column(name="patientDeceased", type="boolean", options={"default"=false})
  209. */
  210. private $patientDeceased = false;
  211. /**
  212. * @var DateTime
  213. *
  214. * @ORM\Column(name="created", type="datetime")
  215. *
  216. * @Gedmo\Timestampable(on="create")
  217. */
  218. private $created;
  219. /**
  220. * @var DateTime
  221. *
  222. * @ORM\Column(name="updated", type="datetime")
  223. *
  224. * @Gedmo\Timestampable(on="update")
  225. */
  226. private $updated;
  227. /**
  228. * @var RecordsReceived
  229. *
  230. * @ORM\Embedded(class="MedBrief\MSR\Entity\Embeddable\RecordsReceived", columnPrefix="recordsReceived_")
  231. */
  232. private $recordsReceived;
  233. /**
  234. * @var RecordsRequestLetter
  235. *
  236. * @ORM\OneToOne(targetEntity="MedBrief\MSR\Entity\RecordsRequestLetter", inversedBy="recordsRequest", cascade={"all"})
  237. *
  238. * @ORM\JoinColumns({
  239. *
  240. * @ORM\JoinColumn(name="recordsRequestLetter_id", referencedColumnName="id", unique=true, nullable=true)
  241. * })
  242. */
  243. private $recordsRequestLetter;
  244. /**
  245. * @var \Doctrine\Common\Collections\Collection
  246. *
  247. * @ORM\OneToMany(targetEntity="MedBrief\MSR\Entity\RecordsRequestDetail", mappedBy="recordsRequest")
  248. *
  249. * @ORM\OrderBy({
  250. * "displayDate"="ASC"
  251. * })
  252. */
  253. private $recordsRequestDetails;
  254. /**
  255. * @var Project
  256. *
  257. * @ORM\ManyToOne(targetEntity="MedBrief\MSR\Entity\Project", inversedBy="recordsRequests")
  258. *
  259. * @ORM\JoinColumns({
  260. *
  261. * @ORM\JoinColumn(name="project_id", referencedColumnName="id", nullable=false)
  262. * })
  263. */
  264. private $project;
  265. /**
  266. * @var RecordsRequestCentre
  267. *
  268. * @ORM\ManyToOne(targetEntity="MedBrief\MSR\Entity\RecordsRequestCentre")
  269. *
  270. * @ORM\JoinColumns({
  271. *
  272. * @ORM\JoinColumn(name="recordsRequestedFromExisting_id", referencedColumnName="id", nullable=true)
  273. * })
  274. */
  275. private $recordsRequestedFromExisting;
  276. /**
  277. * @var RecordsRequestCentreParent
  278. *
  279. * @ORM\ManyToOne(targetEntity="MedBrief\MSR\Entity\RecordsRequestCentreParent")
  280. *
  281. * @ORM\JoinColumns({
  282. *
  283. * @ORM\JoinColumn(name="recordsRequestedFromExistingParent_id", referencedColumnName="id", nullable=true)
  284. * })
  285. */
  286. private $recordsRequestedFromExistingParent;
  287. /**
  288. * @var MatterRequestTrustCentre
  289. *
  290. * @ORM\ManyToOne(targetEntity="MedBrief\MSR\Entity\MatterRequest\TrustCentre", inversedBy="recordsRequests")
  291. *
  292. * @ORM\JoinColumns({
  293. *
  294. * @ORM\JoinColumn(name="matterRequestTrustCentre_id", referencedColumnName="id", nullable=true)
  295. * })
  296. */
  297. private $matterRequestTrustCentre;
  298. /**
  299. * @var User
  300. *
  301. * @ORM\ManyToOne(targetEntity="MedBrief\MSR\Entity\User")
  302. *
  303. * @ORM\JoinColumns({
  304. *
  305. * @ORM\JoinColumn(name="assignedTo_id", referencedColumnName="id")
  306. * })
  307. */
  308. private $assignedTo;
  309. /**
  310. * @var User|null
  311. *
  312. * @ORM\ManyToOne(targetEntity="MedBrief\MSR\Entity\User")
  313. *
  314. * @ORM\JoinColumns({
  315. *
  316. * @ORM\JoinColumn(name="requestedBy_id", referencedColumnName="id")
  317. * })
  318. */
  319. private ?User $requestedBy = null;
  320. /**
  321. * @var DateTime|null
  322. *
  323. * @ORM\Column(name="requestedDate", type="datetime", nullable=true)
  324. */
  325. private ?DateTime $requestedDate = null;
  326. /**
  327. * @var User|null
  328. *
  329. * @ORM\ManyToOne(targetEntity="MedBrief\MSR\Entity\User")
  330. *
  331. * @ORM\JoinColumns({
  332. *
  333. * @ORM\JoinColumn(name="completedBy_id", referencedColumnName="id")
  334. * })
  335. */
  336. private ?User $completedBy = null;
  337. /**
  338. * @var DateTime|null
  339. *
  340. * @ORM\Column(name="completedDate", type="datetime", nullable=true)
  341. */
  342. private ?DateTime $completedDate = null;
  343. /**
  344. * Constructor
  345. */
  346. public function __construct()
  347. {
  348. $this->recordsRequestDetails = new \Doctrine\Common\Collections\ArrayCollection();
  349. $this->recordsReceived = new RecordsReceived();
  350. }
  351. public function __toString()
  352. {
  353. return (string) $this->getId();
  354. }
  355. /**
  356. * Get id
  357. *
  358. * @return int
  359. */
  360. public function getId()
  361. {
  362. return $this->id;
  363. }
  364. /**
  365. * Set records_requested_from_other
  366. *
  367. * @param string $recordsRequestedFromOther
  368. *
  369. * @return RecordsRequest
  370. */
  371. public function setRecordsRequestedFromOther($recordsRequestedFromOther)
  372. {
  373. $this->records_requested_from_other = $recordsRequestedFromOther;
  374. return $this;
  375. }
  376. /**
  377. * Get records_requested_from_other
  378. *
  379. * @return string
  380. */
  381. public function getRecordsRequestedFromOther()
  382. {
  383. return $this->records_requested_from_other;
  384. }
  385. /**
  386. * Set records_sent_by
  387. *
  388. * @param string $recordsSentBy
  389. *
  390. * @return RecordsRequest
  391. */
  392. public function setRecordsSentBy($recordsSentBy)
  393. {
  394. $this->records_sent_by = $recordsSentBy;
  395. return $this;
  396. }
  397. /**
  398. * Get records_sent_by
  399. *
  400. * @return string
  401. */
  402. public function getRecordsSentBy()
  403. {
  404. return $this->records_sent_by;
  405. }
  406. /**
  407. * Set created
  408. *
  409. * @param DateTime $created
  410. *
  411. * @return RecordsRequest
  412. */
  413. public function setCreated($created)
  414. {
  415. $this->created = $created;
  416. return $this;
  417. }
  418. /**
  419. * Get created
  420. *
  421. * @return DateTime
  422. */
  423. public function getCreated()
  424. {
  425. return $this->created;
  426. }
  427. /**
  428. * Set updated
  429. *
  430. * @param DateTime $updated
  431. *
  432. * @return RecordsRequest
  433. */
  434. public function setUpdated($updated)
  435. {
  436. $this->updated = $updated;
  437. return $this;
  438. }
  439. /**
  440. * Get updated
  441. *
  442. * @return DateTime
  443. */
  444. public function getUpdated()
  445. {
  446. return $this->updated;
  447. }
  448. /**
  449. * Set project
  450. *
  451. * @param Project $project
  452. *
  453. * @return RecordsRequest
  454. */
  455. public function setProject(Project $project)
  456. {
  457. $this->project = $project;
  458. return $this;
  459. }
  460. /**
  461. * Get project
  462. *
  463. * @return Project
  464. */
  465. public function getProject()
  466. {
  467. return $this->project;
  468. }
  469. /**
  470. * Set deletedAt
  471. *
  472. * @param DateTime $deletedAt
  473. *
  474. * @return RecordsRequest
  475. */
  476. public function setDeletedAt($deletedAt)
  477. {
  478. $this->deletedAt = $deletedAt;
  479. return $this;
  480. }
  481. /**
  482. * Get deletedAt
  483. *
  484. * @return DateTime
  485. */
  486. public function getDeletedAt()
  487. {
  488. return $this->deletedAt;
  489. }
  490. /**
  491. * Set dateRecordsRequested
  492. *
  493. * @param DateTime $dateRecordsRequested
  494. *
  495. * @return RecordsRequest
  496. */
  497. public function setDateRecordsRequested($dateRecordsRequested)
  498. {
  499. $this->date_records_requested = $dateRecordsRequested;
  500. return $this;
  501. }
  502. /**
  503. * Get dateRecordsRequested
  504. *
  505. * @return DateTime
  506. */
  507. public function getDateRecordsRequested()
  508. {
  509. return $this->date_records_requested;
  510. }
  511. /**
  512. * Set dateRecordsReceived
  513. *
  514. * @param DateTime $dateRecordsReceived
  515. *
  516. * @return RecordsRequest
  517. */
  518. public function setDateRecordsReceived($dateRecordsReceived)
  519. {
  520. $this->date_records_received = $dateRecordsReceived;
  521. return $this;
  522. }
  523. /**
  524. * Get dateRecordsReceived
  525. *
  526. * @return DateTime
  527. */
  528. public function getDateRecordsReceived()
  529. {
  530. return $this->date_records_received;
  531. }
  532. /**
  533. * Set status
  534. *
  535. * @param int $status
  536. *
  537. * @return RecordsRequest
  538. */
  539. public function setStatus($status)
  540. {
  541. $this->status = $status;
  542. return $this;
  543. }
  544. /**
  545. * Get status
  546. *
  547. * @return int
  548. */
  549. public function getStatus()
  550. {
  551. return $this->status;
  552. }
  553. /**
  554. * Get status
  555. *
  556. * @return string
  557. */
  558. public function getStatusName()
  559. {
  560. $statuses = self::getStatusOptions();
  561. // if the status is not set, or does not exist in our array we return an appropriate value
  562. if (!array_key_exists($this->getStatus(), $statuses)) {
  563. return 'Status Not Set';
  564. }
  565. return $statuses[$this->getStatus()];
  566. }
  567. /**
  568. * Get statuses
  569. *
  570. * My recommendation is that we leave this with string keys pointing to
  571. * string values: it just makes the data much more readable.
  572. *
  573. * @return array
  574. */
  575. public static function getStatusOptions()
  576. {
  577. return [
  578. self::STATUS_INSTRUCTED => 'Instructed',
  579. self::STATUS_REQUESTED => 'Requested',
  580. self::STATUS_CHASED => 'Chased',
  581. self::STATUS_RECEIVED => 'Received',
  582. self::STATUS_SORTED => 'Sorted',
  583. self::STATUS_UPLOADED => 'Uploaded',
  584. self::STATUS_CHRONOLOGY => 'Chronology',
  585. ];
  586. }
  587. /**
  588. * Add recordsRequestDetail
  589. *
  590. * @param RecordsRequestDetail $recordsRequestDetail
  591. *
  592. * @return RecordsRequest
  593. */
  594. public function addRecordsRequestDetail(RecordsRequestDetail $recordsRequestDetail)
  595. {
  596. $this->recordsRequestDetails[] = $recordsRequestDetail;
  597. return $this;
  598. }
  599. /**
  600. * Remove recordsRequestDetail
  601. *
  602. * @param RecordsRequestDetail $recordsRequestDetail
  603. */
  604. public function removeRecordsRequestDetail(RecordsRequestDetail $recordsRequestDetail)
  605. {
  606. $this->recordsRequestDetails->removeElement($recordsRequestDetail);
  607. }
  608. /**
  609. * Get recordsRequestDetails
  610. *
  611. * @return \Doctrine\Common\Collections\Collection|RecordsRequestDetail[]
  612. */
  613. public function getRecordsRequestDetails()
  614. {
  615. return $this->recordsRequestDetails;
  616. }
  617. /**
  618. * @return array
  619. */
  620. public function getNoteCounts(): array
  621. {
  622. $noteCounts = [];
  623. foreach ($this->getRecordsRequestDetails() as $note) {
  624. if (!isset($noteCounts[$note->getType()])) {
  625. $noteCounts[$note->getType()] = 0;
  626. }
  627. $noteCounts[$note->getType()]++;
  628. }
  629. return $noteCounts;
  630. }
  631. /**
  632. * Get recordsRequestDetailsByType.
  633. *
  634. * Filters out RecordsRequestDetails by type.
  635. *
  636. * @param mixed $type
  637. *
  638. * @return \Doctrine\Common\Collections\Collection
  639. */
  640. public function getRecordsRequestDetailsByType($type)
  641. {
  642. return $this->getRecordsRequestDetails()->filter(function ($detail) use ($type) {
  643. return $detail->getType() === $type;
  644. });
  645. }
  646. /**
  647. * Get getChaseCount
  648. *
  649. * The number of RecordsRequestDetails that have type Chase.
  650. *
  651. * @return int
  652. */
  653. public function getChaseCount()
  654. {
  655. return $this->getRecordsRequestDetailsByType(RecordsRequestDetail::TYPE_CHASE)->count();
  656. }
  657. /**
  658. * Set updateDueDate
  659. *
  660. * @param DateTime $updateDueDate
  661. *
  662. * @return RecordsRequest
  663. */
  664. public function setUpdateDueDate($updateDueDate)
  665. {
  666. $this->update_due_date = $updateDueDate;
  667. return $this;
  668. }
  669. /**
  670. * Get updateDueDate
  671. *
  672. * @return DateTime
  673. */
  674. public function getUpdateDueDate()
  675. {
  676. return $this->update_due_date;
  677. }
  678. /**
  679. * Returns the number of days until a RecordsRequest's update is due,
  680. * as a SIGNED integer.
  681. *
  682. *
  683. * @return int|null
  684. */
  685. public function getDaysToUpdateDue()
  686. {
  687. if ($this->update_due_date) {
  688. // %r = signed
  689. // %d = days
  690. $days = (new DateTime('midnight'))->diff($this->update_due_date)->format('%r%a');
  691. return $days;
  692. }
  693. return null;
  694. }
  695. /**
  696. * Returns whether the RecordsRequest has an update due,
  697. * by checking if the updateDueDate has passed, and if the updateDueDate
  698. * is more recent than the updated date.
  699. *
  700. * @return bool
  701. */
  702. public function hasUpdateDue()
  703. {
  704. return
  705. $this->getServiceRequest()
  706. && $this->getServiceRequest()->isInprogress()
  707. && $this->getDaysToUpdateDue() != null
  708. && $this->getDaysToUpdateDue() <= 0
  709. && $this->getUpdated() && $this->getUpdated() < $this->getUpdateDueDate();
  710. }
  711. /**
  712. * Set dateAcknowledged
  713. *
  714. * @param DateTime $dateAcknowledged
  715. *
  716. * @return RecordsRequest
  717. */
  718. public function setDateAcknowledged($dateAcknowledged)
  719. {
  720. $this->date_acknowledged = $dateAcknowledged;
  721. return $this;
  722. }
  723. /**
  724. * Get dateAcknowledged
  725. *
  726. * @return DateTime
  727. */
  728. public function getDateAcknowledged()
  729. {
  730. return $this->date_acknowledged;
  731. }
  732. /**
  733. * Set datePasswordProvided
  734. *
  735. * @param DateTime $datePasswordProvided
  736. *
  737. * @return RecordsRequest
  738. */
  739. public function setDatePasswordProvided($datePasswordProvided)
  740. {
  741. $this->date_password_provided = $datePasswordProvided;
  742. return $this;
  743. }
  744. /**
  745. * Get datePasswordProvided
  746. *
  747. * @return DateTime
  748. */
  749. public function getDatePasswordProvided()
  750. {
  751. return $this->date_password_provided;
  752. }
  753. /**
  754. * Set requestMethod
  755. *
  756. * @param int $requestMethod
  757. *
  758. * @return RecordsRequest
  759. */
  760. public function setRequestMethod($requestMethod)
  761. {
  762. $this->request_method = $requestMethod;
  763. return $this;
  764. }
  765. /**
  766. * Get requestMethod
  767. *
  768. * @return int
  769. */
  770. public function getRequestMethod()
  771. {
  772. return $this->request_method;
  773. }
  774. /**
  775. * Get requestMethodOptions
  776. *
  777. * @return array
  778. */
  779. public static function getRequestMethodOptions()
  780. {
  781. return [
  782. self::REQUEST_METHOD_EMAIL => 'Email',
  783. self::REQUEST_METHOD_FAX => 'Fax',
  784. self::REQUEST_METHOD_POST => 'Post',
  785. self::REQUEST_METHOD_PORTAL => 'Portal',
  786. ];
  787. }
  788. /**
  789. * Get requestMethodLabel
  790. *
  791. * @return int
  792. */
  793. public function getRequestMethodLabel()
  794. {
  795. $options = self::getRequestMethodOptions();
  796. return $options[$this->getRequestMethod()] ?? '';
  797. }
  798. /**
  799. * Set internalDocumentPassword
  800. *
  801. * @param string $internalDocumentPassword
  802. *
  803. * @return RecordsRequest
  804. */
  805. public function setInternalDocumentPassword($internalDocumentPassword)
  806. {
  807. $this->internal_document_password = $internalDocumentPassword;
  808. return $this;
  809. }
  810. /**
  811. * Get internalDocumentPassword
  812. *
  813. * @return string
  814. */
  815. public function getInternalDocumentPassword()
  816. {
  817. return $this->internal_document_password;
  818. }
  819. /**
  820. * Set recordsRequestedFromExisting
  821. *
  822. * @param RecordsRequestCentre $recordsRequestedFromExisting
  823. *
  824. * @return RecordsRequest
  825. */
  826. public function setRecordsRequestedFromExisting(?RecordsRequestCentre $recordsRequestedFromExisting = null)
  827. {
  828. $this->recordsRequestedFromExisting = $recordsRequestedFromExisting;
  829. return $this;
  830. }
  831. /**
  832. * Get recordsRequestedFromExisting
  833. *
  834. * @return RecordsRequestCentre
  835. */
  836. public function getRecordsRequestedFromExisting()
  837. {
  838. return $this->recordsRequestedFromExisting;
  839. }
  840. /**
  841. * Set recordsRequestedFromExistingParent.
  842. *
  843. * @param RecordsRequestCentreParent|null $recordsRequestedFromExistingParent
  844. *
  845. * @return RecordsRequest
  846. */
  847. public function setRecordsRequestedFromExistingParent(?RecordsRequestCentreParent $recordsRequestedFromExistingParent = null)
  848. {
  849. $this->recordsRequestedFromExistingParent = $recordsRequestedFromExistingParent;
  850. return $this;
  851. }
  852. /**
  853. * Get recordsRequestedFromExistingParent.
  854. *
  855. * @return RecordsRequestCentreParent|null
  856. */
  857. public function getRecordsRequestedFromExistingParent()
  858. {
  859. return $this->recordsRequestedFromExistingParent;
  860. }
  861. /**
  862. * Helper function for displaying where the records are being
  863. * requested from.
  864. *
  865. * Correctly displays based on if the RecordsRequest has an existing
  866. * RecordsRequestCentre linked to it, or a string RecordsRequestedFromOther
  867. * field.
  868. *
  869. * @return string
  870. */
  871. public function getRecordsRequestedFrom()
  872. {
  873. // Return the name of the RecordsRequestedFromExistingParent if set.
  874. if ($this->getRecordsRequestedFromExistingParent()) {
  875. return $this->getRecordsRequestedFromExistingParent()->getName();
  876. }
  877. // Else return the string value assigned to RecordsRequestedFromOther.
  878. return $this->getRecordsRequestedFromOther();
  879. }
  880. /**
  881. * Set postagePaid
  882. *
  883. * @param bool $postagePaid
  884. *
  885. * @return RecordsRequest
  886. */
  887. public function setPostagePaid($postagePaid)
  888. {
  889. $this->postage_paid = $postagePaid;
  890. return $this;
  891. }
  892. /**
  893. * Get postagePaid
  894. *
  895. * @return bool
  896. */
  897. public function getPostagePaid()
  898. {
  899. return $this->postage_paid;
  900. }
  901. /**
  902. * Get postagePaidLabel
  903. *
  904. * @return string
  905. */
  906. public function getPostagePaidLabel()
  907. {
  908. return $this->postage_paid ? 'Yes' : 'No';
  909. }
  910. /**
  911. * Set postageAmount
  912. *
  913. * @param string $postageAmount
  914. *
  915. * @return RecordsRequest
  916. */
  917. public function setPostageAmount($postageAmount)
  918. {
  919. $this->postage_amount = $postageAmount;
  920. return $this;
  921. }
  922. /**
  923. * Get postageAmount
  924. *
  925. * @return string
  926. */
  927. public function getPostageAmount()
  928. {
  929. return $this->postage_amount;
  930. }
  931. /**
  932. * Get postageAmountFormatted
  933. *
  934. * @return string
  935. */
  936. public function getPostageAmountFormatted()
  937. {
  938. return number_format($this->postage_amount, 2, '.', ' ');
  939. }
  940. /**
  941. * Set radiologyDiscCount
  942. *
  943. * @param int $radiologyDiscCount
  944. *
  945. * @return RecordsRequest
  946. */
  947. public function setRadiologyDiscCount($radiologyDiscCount)
  948. {
  949. $this->radiology_disc_count = $radiologyDiscCount;
  950. return $this;
  951. }
  952. /**
  953. * Get radiologyDiscCount
  954. *
  955. * @return int
  956. */
  957. public function getRadiologyDiscCount()
  958. {
  959. return $this->radiology_disc_count;
  960. }
  961. /**
  962. * Set assignedTo
  963. *
  964. * @param User $assignedTo
  965. *
  966. * @return RecordsRequest
  967. */
  968. public function setAssignedTo(?User $assignedTo = null)
  969. {
  970. $this->assignedTo = $assignedTo;
  971. return $this;
  972. }
  973. /**
  974. * Get assignedTo
  975. *
  976. * @return User
  977. */
  978. public function getAssignedTo()
  979. {
  980. return $this->assignedTo;
  981. }
  982. /**
  983. * Set requestedBy
  984. *
  985. * @param User|null $requestedBy
  986. *
  987. * @return RecordsRequest
  988. */
  989. public function setRequestedBy(?User $requestedBy = null)
  990. {
  991. $this->requestedBy = $requestedBy;
  992. return $this;
  993. }
  994. /**
  995. * Get requestedBy
  996. *
  997. * @return User|null
  998. */
  999. public function getRequestedBy(): ?User
  1000. {
  1001. return $this->requestedBy;
  1002. }
  1003. /**
  1004. * Set requestedDate
  1005. *
  1006. * @param DateTime|null $requestedDate
  1007. *
  1008. * @return RecordsRequest
  1009. */
  1010. public function setRequestedDate(?DateTime $requestedDate = null)
  1011. {
  1012. $this->requestedDate = $requestedDate;
  1013. return $this;
  1014. }
  1015. /**
  1016. * Get requestedDate
  1017. *
  1018. * @return DateTime|null
  1019. */
  1020. public function getRequestedDate(): ?DateTime
  1021. {
  1022. return $this->requestedDate;
  1023. }
  1024. /**
  1025. * Set completedBy
  1026. *
  1027. * @param User|null $completedBy
  1028. *
  1029. * @return RecordsRequest
  1030. */
  1031. public function setCompletedBy(?User $completedBy = null)
  1032. {
  1033. $this->completedBy = $completedBy;
  1034. return $this;
  1035. }
  1036. /**
  1037. * Get completedBy
  1038. *
  1039. * @return User|null
  1040. */
  1041. public function getCompletedBy(): ?User
  1042. {
  1043. return $this->completedBy;
  1044. }
  1045. /**
  1046. * Set completedDate
  1047. *
  1048. * @param DateTime|null $completedDate
  1049. *
  1050. * @return RecordsRequest
  1051. */
  1052. public function setCompletedDate(?DateTime $completedDate = null)
  1053. {
  1054. $this->completedDate = $completedDate;
  1055. return $this;
  1056. }
  1057. /**
  1058. * Get completedDate
  1059. *
  1060. * @return DateTime|null
  1061. */
  1062. public function getCompletedDate(): ?DateTime
  1063. {
  1064. return $this->completedDate;
  1065. }
  1066. /**
  1067. * Set recordsReceived
  1068. *
  1069. * @param RecordsReceived $recordsReceived
  1070. *
  1071. * @return RecordsRequest
  1072. */
  1073. public function setRecordsReceived(RecordsReceived $recordsReceived)
  1074. {
  1075. $this->recordsReceived = $recordsReceived;
  1076. return $this;
  1077. }
  1078. /**
  1079. * Get recordsReceived
  1080. *
  1081. * @return RecordsReceived
  1082. */
  1083. public function getRecordsReceived()
  1084. {
  1085. return $this->recordsReceived;
  1086. }
  1087. /**
  1088. * Set trustReference
  1089. *
  1090. * @param string $trustReference
  1091. *
  1092. * @return RecordsRequest
  1093. */
  1094. public function setTrustReference($trustReference)
  1095. {
  1096. $this->trust_reference = $trustReference;
  1097. return $this;
  1098. }
  1099. /**
  1100. * Get trustReference
  1101. *
  1102. * @return string
  1103. */
  1104. public function getTrustReference()
  1105. {
  1106. return $this->trust_reference;
  1107. }
  1108. /**
  1109. * Set collateBeforeProcessing
  1110. *
  1111. * @param bool $collateBeforeProcessing
  1112. *
  1113. * @return RecordsRequest
  1114. */
  1115. public function setCollateBeforeProcessing($collateBeforeProcessing)
  1116. {
  1117. $this->collate_before_processing = $collateBeforeProcessing;
  1118. return $this;
  1119. }
  1120. /**
  1121. * Get collateBeforeProcessing
  1122. *
  1123. * @return bool
  1124. */
  1125. public function getCollateBeforeProcessing()
  1126. {
  1127. return $this->collate_before_processing;
  1128. }
  1129. /**
  1130. * Get collateBeforeProcessingLabel
  1131. *
  1132. * @return string
  1133. */
  1134. public function getCollateBeforeProcessingLabel()
  1135. {
  1136. return $this->collate_before_processing ? 'Yes' : 'No';
  1137. }
  1138. /**
  1139. * Set centrePassword
  1140. *
  1141. * @param string $centrePassword
  1142. *
  1143. * @return RecordsRequest
  1144. */
  1145. public function setCentrePassword($centrePassword)
  1146. {
  1147. $this->centre_password = $centrePassword;
  1148. return $this;
  1149. }
  1150. /**
  1151. * Get centrePassword
  1152. *
  1153. * @return string
  1154. */
  1155. public function getCentrePassword()
  1156. {
  1157. return $this->centre_password;
  1158. }
  1159. /**
  1160. * Set dueDate
  1161. *
  1162. * @param DateTime $dueDate
  1163. *
  1164. * @return RecordsRequest
  1165. */
  1166. public function setDueDate($dueDate)
  1167. {
  1168. $this->due_date = $dueDate;
  1169. return $this;
  1170. }
  1171. /**
  1172. * Get dueDate
  1173. *
  1174. * @return DateTime
  1175. */
  1176. public function getDueDate()
  1177. {
  1178. return $this->due_date;
  1179. }
  1180. /**
  1181. * Updates the due date based on if the date_records_requested field is set.
  1182. *
  1183. * Used as a lifecycleCallback.
  1184. *
  1185. * @ORM\PrePersist
  1186. *
  1187. * @ORM\PreUpdate
  1188. *
  1189. * @return RecordsRequest
  1190. */
  1191. public function generateDueDate()
  1192. {
  1193. if (!$this->getDueDate() && $this->getDateRecordsRequested()) {
  1194. $dueDate = clone $this->getDateRecordsRequested();
  1195. $dueDate->modify(self::AUTO_DUE_DATE);
  1196. $this->setDueDate($dueDate);
  1197. } elseif (!$this->getDueDate()) {
  1198. $this->setDueDate(null);
  1199. }
  1200. return $this;
  1201. }
  1202. /**
  1203. * Set archiveBoxNumber
  1204. *
  1205. * @param int $archiveBoxNumber
  1206. *
  1207. * @return RecordsRequest
  1208. */
  1209. public function setArchiveBoxNumber($archiveBoxNumber)
  1210. {
  1211. $this->archiveBoxNumber = $archiveBoxNumber;
  1212. return $this;
  1213. }
  1214. /**
  1215. * Get archiveBoxNumber
  1216. *
  1217. * @return int
  1218. */
  1219. public function getArchiveBoxNumber()
  1220. {
  1221. return $this->archiveBoxNumber;
  1222. }
  1223. /**
  1224. * Set dateDestroyedOrReturned
  1225. *
  1226. * @param DateTime $dateDestroyedOrReturned
  1227. *
  1228. * @return RecordsRequest
  1229. */
  1230. public function setDateDestroyedOrReturned($dateDestroyedOrReturned)
  1231. {
  1232. $this->dateDestroyedOrReturned = $dateDestroyedOrReturned;
  1233. return $this;
  1234. }
  1235. /**
  1236. * Get dateDestroyedOrReturned
  1237. *
  1238. * @return DateTime
  1239. */
  1240. public function getDateDestroyedOrReturned()
  1241. {
  1242. return $this->dateDestroyedOrReturned;
  1243. }
  1244. /**
  1245. * Set matterRequestTrustCentre.
  1246. *
  1247. * @param MatterRequestTrustCentre|null $matterRequestTrustCentre
  1248. *
  1249. * @return RecordsRequest
  1250. */
  1251. public function setMatterRequestTrustCentre(?MatterRequestTrustCentre $matterRequestTrustCentre = null)
  1252. {
  1253. $this->matterRequestTrustCentre = $matterRequestTrustCentre;
  1254. return $this;
  1255. }
  1256. /**
  1257. * Get matterRequestTrustCentre.
  1258. *
  1259. * @return MatterRequestTrustCentre|null
  1260. */
  1261. public function getMatterRequestTrustCentre()
  1262. {
  1263. return $this->matterRequestTrustCentre;
  1264. }
  1265. /**
  1266. * Set recordsRequestLetter.
  1267. *
  1268. * @param RecordsRequestLetter|null $recordsRequestLetter
  1269. *
  1270. * @return RecordsRequest
  1271. */
  1272. public function setRecordsRequestLetter(?RecordsRequestLetter $recordsRequestLetter = null)
  1273. {
  1274. $this->recordsRequestLetter = $recordsRequestLetter;
  1275. return $this;
  1276. }
  1277. /**
  1278. * Get recordsRequestLetter.
  1279. *
  1280. * @return RecordsRequestLetter|null
  1281. */
  1282. public function getRecordsRequestLetter()
  1283. {
  1284. return $this->recordsRequestLetter;
  1285. }
  1286. /**
  1287. * Set patientName
  1288. *
  1289. * @param string $patientName
  1290. *
  1291. * @return RecordsRequest
  1292. */
  1293. public function setPatientName($patientName)
  1294. {
  1295. $this->patientName = $patientName;
  1296. return $this;
  1297. }
  1298. /**
  1299. * Get patientName
  1300. *
  1301. * @return string
  1302. */
  1303. public function getPatientName()
  1304. {
  1305. return $this->patientName;
  1306. }
  1307. /**
  1308. * Set patientDateOfBirth
  1309. *
  1310. * @param DateTime $patientDateOfBirth
  1311. *
  1312. * @return RecordsRequest
  1313. */
  1314. public function setPatientDateOfBirth($patientDateOfBirth)
  1315. {
  1316. $this->patientDateOfBirth = $patientDateOfBirth;
  1317. return $this;
  1318. }
  1319. /**
  1320. * Get patientDateOfBirth
  1321. *
  1322. * @return DateTime
  1323. */
  1324. public function getPatientDateOfBirth()
  1325. {
  1326. return $this->patientDateOfBirth;
  1327. }
  1328. /**
  1329. * Set patientDeceased
  1330. *
  1331. * @param bool $patientDeceased
  1332. *
  1333. * @return RecordsRequest
  1334. */
  1335. public function setPatientDeceased($patientDeceased)
  1336. {
  1337. $this->patientDeceased = $patientDeceased;
  1338. return $this;
  1339. }
  1340. /**
  1341. * Get patientDeceased
  1342. *
  1343. * @return bool
  1344. */
  1345. public function getPatientDeceased()
  1346. {
  1347. return $this->patientDeceased;
  1348. }
  1349. /**
  1350. * @inheritDoc
  1351. */
  1352. public function getLetterContent(): ?string
  1353. {
  1354. if ($this->getRecordsRequestLetter() instanceof RecordsRequestLetter) {
  1355. return $this->getRecordsRequestLetter()->getContent();
  1356. }
  1357. return null;
  1358. }
  1359. /**
  1360. * @inheritDoc
  1361. */
  1362. public function getLetterSubject()
  1363. {
  1364. return $this;
  1365. }
  1366. /**
  1367. * @return bool
  1368. */
  1369. public function hasImportantNotes(): bool
  1370. {
  1371. return $this->getRecordsRequestDetails()->filter(function (RecordsRequestDetail $detail) {
  1372. return $detail->getIsImportant();
  1373. })->count();
  1374. }
  1375. /**
  1376. * @return bool
  1377. */
  1378. public function canAutoCancel(): bool
  1379. {
  1380. return $this->getServiceRequest() && $this->getServiceRequest()->getStatus() === ServiceRequest::STATUS_BACK_TO_CLIENT;
  1381. }
  1382. }