src/Entity/RecordsRequest.php line 32

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