src/Entity/Project.php line 72

Open in your IDE?
  1. <?php
  2. namespace MedBrief\MSR\Entity;
  3. use ApiPlatform\Core\Annotation\ApiResource;
  4. use DateTime;
  5. use DateTimeInterface;
  6. use DH\Auditor\Provider\Doctrine\Auditing\Annotation as Audit;
  7. use Doctrine\Common\Collections\ArrayCollection;
  8. use Doctrine\Common\Collections\Collection as DoctrineCollection;
  9. use Doctrine\Common\Collections\Criteria;
  10. use Doctrine\ORM\EntityNotFoundException;
  11. use Doctrine\ORM\Mapping as ORM;
  12. use Doctrine\Persistence\Proxy;
  13. use Exception;
  14. use Gedmo\Mapping\Annotation as Gedmo;
  15. use libphonenumber\PhoneNumber;
  16. use MedBrief\MSR\Dto\ClinicalSummaryMatterDto;
  17. use MedBrief\MSR\Entity\MatterRequest\MatterRequest;
  18. use MedBrief\MSR\Entity\MatterRequest\Patient;
  19. use MedBrief\MSR\Entity\Patient as RadiologyPatient;
  20. use MedBrief\MSR\Entity\Serviceable\ServiceableInterface;
  21. use MedBrief\MSR\Repository\ProjectRepository;
  22. use MedBrief\MSR\Service\ClaimCategoryAwareInterface;
  23. use MedBrief\MSR\Service\InterpartyDisclosure\Disclose\DisclosureTargetInterface;
  24. use MedBrief\MSR\Service\MatterTypeAwareInterface;
  25. use MedBrief\MSR\Traits\Disclosure\DisclosureTargetTrait;
  26. use MedBrief\MSR\Traits\FilterableClassConstantsTrait;
  27. use Symfony\Component\Serializer\Annotation\Groups;
  28. use Symfony\Component\Validator\Constraints as Assert;
  29. use Symfony\Component\Validator\Context\ExecutionContextInterface;
  30. use Symfony\Component\Validator\Mapping\ClassMetadata;
  31. use Symfony\Component\Validator\Validation;
  32. /**
  33. * Note: When using ApiResource groups, if the variable you want to get is snake_case you will need to add the group as an annotation to the getter.
  34. *
  35. * @ApiResource(
  36. * collectionOperations={},
  37. * itemOperations={
  38. * "get"={
  39. * "access_control"="is_granted('READ', object)",
  40. * "normalization_context"={"groups"={"project_closure:read"}, "enable_max_depth"=true}
  41. * },
  42. * "get_clinical_summary_matter"={
  43. * "method"="GET",
  44. * "path"="/projects/{id}/clinical_summary_matter",
  45. * "access_control"="is_granted('READ', object)",
  46. * "normalization_context"={"groups"={"clinical_summary_matter:read"}},
  47. * "output"=ClinicalSummaryMatterDto::class,
  48. * "description"="Resource representing matter details relevant to a clinical summary.",
  49. * },
  50. * "put"={"access_control"="is_granted('UPDATE', object)"}
  51. * },
  52. * attributes={
  53. * "normalization_context"={"groups"={"project:read"}},
  54. * }
  55. * )
  56. *
  57. * @ORM\Table(name="Project", uniqueConstraints={@ORM\UniqueConstraint(name="reference_idx", columns={"account_id", "client_reference", "deletedAt"})})
  58. *
  59. * @ORM\Entity(repositoryClass=ProjectRepository::class)
  60. *
  61. * @ORM\HasLifecycleCallbacks
  62. *
  63. * @Gedmo\SoftDeleteable(fieldName="deletedAt", timeAware=false)
  64. *
  65. * @Audit\Auditable
  66. *
  67. * @Audit\Security(view={"ROLE_ALLOWED_TO_AUDIT"})
  68. */
  69. class Project implements ClaimCategoryAwareInterface, MatterTypeAwareInterface, DisclosureTargetInterface
  70. {
  71. use FilterableClassConstantsTrait;
  72. use DisclosureTargetTrait;
  73. public const STATUS_INACTIVE = 1;
  74. public const STATUS_ACTIVE = 2;
  75. public const LICENSE_LEVEL_STANDARD = 1;
  76. public const LICENSE_LEVEL_PROFESSIONAL = 2;
  77. public const LICENSE_LEVEL_PREMIUM = 3;
  78. public const LICENSE_LEVEL_BASIC = 4;
  79. public const ESTIMATED_CLAIM_VALUE_0_25000 = 1;
  80. public const ESTIMATED_CLAIM_VALUE_25001_50000 = 2;
  81. public const ESTIMATED_CLAIM_VALUE_50001_100000 = 3;
  82. public const ESTIMATED_CLAIM_VALUE_100001_250000 = 4;
  83. public const ESTIMATED_CLAIM_VALUE_250001_500000 = 5;
  84. public const ESTIMATED_CLAIM_VALUE_500001_1000000 = 6;
  85. public const ESTIMATED_CLAIM_VALUE_1000001 = 7;
  86. public const ESTIMATED_CLAIM_VALUE_0_25000__LABEL = '£0 - £25,000';
  87. public const ESTIMATED_CLAIM_VALUE_25001_50000__LABEL = '£25,001 - £50,000';
  88. public const ESTIMATED_CLAIM_VALUE_50001_100000__LABEL = '£50,001 - £100,000';
  89. public const ESTIMATED_CLAIM_VALUE_100001_250000__LABEL = '£100,001 - £250,000';
  90. public const ESTIMATED_CLAIM_VALUE_250001_500000__LABEL = '£250,001 - £500,000';
  91. public const ESTIMATED_CLAIM_VALUE_500001_1000000__LABEL = '£500,001 - £1,000,000';
  92. public const ESTIMATED_CLAIM_VALUE_1000001__LABEL = '£1,000,000 +';
  93. // These are the Archive statuses of a Project
  94. public const ARCHIVE_STATUS_PENDING = 1;
  95. public const ARCHIVE_STATUS_PENDING__LABEL = 'Pending';
  96. public const ARCHIVE_STATUS_PROCESSING = 2;
  97. public const ARCHIVE_STATUS_PROCESSING__LABEL = 'Processing';
  98. public const ARCHIVE_STATUS_COMPLETE = 3;
  99. public const ARCHIVE_STATUS_COMPLETE__LABEL = 'Complete';
  100. public const ARCHIVE_STATUS_UNARCHIVE_PROCESSING = 4;
  101. public const ARCHIVE_STATUS_UNARCHIVE_PROCESSING__LABEL = 'Unarchiving processing';
  102. // The delete statuses of a Project
  103. public const DELETE_STATUS_PENDING = 1;
  104. public const DELETE_STATUS_PENDING__LABEL = 'Pending Deletion';
  105. public const DELETE_STATUS_REMINDER_SENT = 6;
  106. public const DELETE_STATUS_REMINDER_SENT__LABEL = 'Reminder Sent';
  107. public const DELETE_STATUS_PROCESSING = 2;
  108. public const DELETE_STATUS_PROCESSING__LABEL = 'Processing';
  109. public const DELETE_STATUS_COMPLETE = 3;
  110. public const DELETE_STATUS_COMPLETE__LABEL = 'Complete';
  111. public const DELETE_STATUS_DELETE_FAILED = 4;
  112. public const DELETE_STATUS_DELETE_FAILED__LABEL = 'Failed';
  113. public const DELETE_STATUS_ANONYMISE_FAILED = 5;
  114. public const DELETE_STATUS_ANONYMISE_FAILED__LABEL = 'Anonymise Failed';
  115. // This status is used to mass set projects to be deleted immediately.
  116. public const DELETE_STATUS_PENDING_IMMEDIATE = 7;
  117. public const DELETE_STATUS_PENDING_IMMEDIATE__LABEL = 'Pending Immediate Deletion';
  118. // The permanent delete status of a Project
  119. public const PERMANENT_DELETE_STATUS_PENDING = 'pending';
  120. public const PERMANENT_DELETE_STATUS_INPROGRESS = 'inprogress';
  121. public const PERMANENT_DELETE_STATUS_COMPLETE = 'complete';
  122. public const PERMANENT_DELETE_STATUS_FAILED = 'failed';
  123. // Default role options
  124. public const DEFAULT_ROLE_EXPERT = 'EXPERT';
  125. public const DEFAULT_ROLE_EXPERTVIEWER = 'EXPERTVIEWER';
  126. public const DEFAULT_ROLE_SCANNER = 'SCANNER';
  127. public const DEFAULT_ROLE_SCANNERDOWNLOAD = 'SCANNERDOWNLOAD';
  128. public const DEFAULT_ROLE_PROJECTMANAGER = 'PROJECTMANAGER';
  129. public const REFERENCE_ID_PREFIX = 'MSR-';
  130. // Case merits analysis options
  131. public const CASE_MERITS_ANALYSIS_SUPPORTIVE = 'supportive';
  132. public const CASE_MERITS_ANALYSIS_UNSUPPORTIVE = 'unsupportive';
  133. public const CASE_MERITS_ANALYSIS_INCONCLUSIVE = 'inconclusive';
  134. // Type of letter options
  135. public const TYPE_OF_LETTER_LETTER_OF_CLAIM = 'letter_of_claim';
  136. public const TYPE_OF_LETTER_LETTER_OF_NOTIFICATION = 'letter_of_notification';
  137. public const TYPE_OF_LETTER_SUBJECT_ACCESS_REQUEST = 'subject_access_request';
  138. public const TYPE_OF_LETTER_DISCLOSURE_APPLICATION = 'disclosure_application';
  139. // Review type options
  140. public const REVIEW_TYPE_CASE_MERITS_ANALYSIS = 'case_merits_analysis';
  141. public const REVIEW_TYPE_CHRONOLOGY = 'chronology';
  142. // The number of hours prior to deletion that a reminder must be sent (currently set to the equivalent of 7 days)
  143. public const DELETION_REMINDER_OFFSET_HOURS = 168;
  144. // Firm Records Review Constants
  145. public const FIRM_RECORDS_REVIEW_STATUS_AWAITING_RECORDS = 'awaiting_records';
  146. public const FIRM_RECORDS_REVIEW_STATUS_AWAITING_RECORDS__LABEL = 'Awaiting records';
  147. public const FIRM_RECORDS_REVIEW_STATUS_UPLOADED = 'uploaded';
  148. public const FIRM_RECORDS_REVIEW_STATUS_UPLOADED__LABEL = 'Uploaded for firm review';
  149. public const FIRM_RECORDS_REVIEW_STATUS_COMPLETE_PROCEED = 'complete_proceed';
  150. public const FIRM_RECORDS_REVIEW_STATUS_COMPLETE_PROCEED__LABEL = 'Complete - proceed with services';
  151. public const FIRM_RECORDS_REVIEW_STATUS_COMPLETE_NO_PROCEED = 'complete_no_proceed';
  152. public const FIRM_RECORDS_REVIEW_STATUS_COMPLETE_NO_PROCEED__LABEL = 'Complete - do not proceed with services';
  153. // Clinical Summary Unsorted Constants
  154. public const CLINICAL_SUMMARY_UNSORTED_STATUS_AWAITING_CONCLUSION = 'awaiting_conclusion';
  155. public const CLINICAL_SUMMARY_UNSORTED_STATUS_AWAITING_CONCLUSION__LABEL = 'Awaiting conclusion';
  156. public const CLINICAL_SUMMARY_UNSORTED_STATUS_SUPPORTIVE = 'supportive';
  157. public const CLINICAL_SUMMARY_UNSORTED_STATUS_SUPPORTIVE__LABEL = 'Supportive - proceed with services';
  158. public const CLINICAL_SUMMARY_UNSORTED_STATUS_UNSUPPORTIVE = 'unsupportive';
  159. public const CLINICAL_SUMMARY_UNSORTED_STATUS_UNSUPPORTIVE__LABEL = 'Unsupportive - do not proceed with services';
  160. public const CLINICAL_SUMMARY_UNSORTED_STATUS_INCONCLUSIVE = 'inconclusive';
  161. public const CLINICAL_SUMMARY_UNSORTED_STATUS_INCONCLUSIVE__LABEL = 'Inconclusive';
  162. // Radiology migration statuses
  163. public const MODERN_RADIOLOGY_MIGRATION_STATUS_PENDING = 'pending';
  164. public const MODERN_RADIOLOGY_MIGRATION_STATUS_IN_PROGRESS = 'in_progress';
  165. public const MODERN_RADIOLOGY_MIGRATION_STATUS_COMPLETE = 'complete';
  166. // Migration is considered failed if a previously active disc is now in a failed state.
  167. public const MODERN_RADIOLOGY_MIGRATION_STATUS_FAILED = 'failed';
  168. // We use the skipped status to indicate projects that had no discs to migrate, or that were newly created and did not need to be migrated.
  169. public const MODERN_RADIOLOGY_MIGRATION_STATUS_SKIPPED = 'skipped';
  170. // Represents a matter accessible to the firm which is our client
  171. public const TYPE_MATTER_FIRM = 'firm';
  172. public const TYPE_MATTER_FIRM__LABEL = 'Matter';
  173. // Represents a matter that is intended to disclosure records to a third-party.
  174. public const TYPE_MATTER_DISCLOSURE = 'disclosure';
  175. public const TYPE_MATTER_DISCLOSURE__LABEL = 'Disclosure';
  176. /**
  177. * @var int
  178. *
  179. * @Groups({"project_closure:read", "clinical_summary_matter:read"})
  180. *
  181. * @ORM\Column(name="id", type="integer")
  182. *
  183. * @ORM\Id
  184. *
  185. * @ORM\GeneratedValue(strategy="IDENTITY")
  186. */
  187. private $id;
  188. /**
  189. * @var DateTime|null
  190. *
  191. * @ORM\Column(name="deletedAt", type="datetime", nullable=true)
  192. */
  193. private $deletedAt;
  194. /**
  195. * @var string
  196. *
  197. * @Groups({"project_closure:read", "clinical_summary_matter:read"})
  198. *
  199. * @ORM\Column(name="name", type="text")
  200. */
  201. private $name;
  202. /**
  203. * @var string|null
  204. *
  205. * @ORM\Column(name="patient_name", type="string", nullable=true)
  206. */
  207. private $patient_name;
  208. /**
  209. * @var string|null
  210. *
  211. * @ORM\Column(name="old_matter_reference", type="string", nullable=true)
  212. */
  213. private $old_matter_reference;
  214. /**
  215. * @var int|null
  216. *
  217. * @ORM\Column(name="pages", type="integer", nullable=true)
  218. */
  219. private $pages;
  220. /**
  221. * @var int
  222. *
  223. * @ORM\Column(name="status", type="integer", nullable=false)
  224. */
  225. private $status;
  226. /**
  227. * @var string|null
  228. *
  229. * @Groups({"project_closure:read", "clinical_summary_matter:read"})
  230. *
  231. * @ORM\Column(name="client_reference", type="string", nullable=true)
  232. */
  233. private $client_reference;
  234. /**
  235. * @var string|null
  236. *
  237. * @ORM\Column(name="billing_code", type="string", nullable=true)
  238. */
  239. private $billing_code;
  240. /**
  241. * @var string|null
  242. *
  243. * @ORM\Column(name="background", type="text", nullable=true)
  244. */
  245. private $background;
  246. /**
  247. * @var string|null
  248. *
  249. * @ORM\Column(name="reference", type="string", nullable=true)
  250. */
  251. private $reference;
  252. /**
  253. * @var string|null
  254. *
  255. * @ORM\Column(name="millnet_id", type="string", nullable=true)
  256. */
  257. private $millnet_id;
  258. /**
  259. * @var int|null
  260. *
  261. * @ORM\Column(name="hold_settled", type="integer", nullable=true)
  262. */
  263. private $hold_settled;
  264. /**
  265. * @var DateTime|null
  266. *
  267. * @ORM\Column(name="date_created", type="datetime", nullable=true)
  268. */
  269. private $date_created;
  270. /**
  271. * @var DateTime|null
  272. *
  273. * @ORM\Column(name="date_closed", type="datetime", nullable=true)
  274. */
  275. private $date_closed;
  276. /**
  277. * @var DateTime|null
  278. *
  279. * @ORM\Column(name="forcedRenewalCreated", type="datetime", nullable=true)
  280. */
  281. private ?DateTime $forcedRenewalCreated;
  282. /**
  283. * @var DateTime|null
  284. *
  285. * @ORM\Column(name="patient_date_of_birth", type="date", nullable=true)
  286. */
  287. private $patient_date_of_birth;
  288. /**
  289. * @var int|null
  290. *
  291. * @ORM\Column(name="archive_status", type="integer", nullable=true)
  292. */
  293. private $archive_status;
  294. /**
  295. * @var DateTime|null
  296. *
  297. * @ORM\Column(name="archive_status_updated", type="datetime", nullable=true)
  298. */
  299. private $archive_status_updated;
  300. /**
  301. * @var int|null
  302. *
  303. * @ORM\Column(name="deleteStatus", type="integer", nullable=true)
  304. */
  305. private $deleteStatus;
  306. /**
  307. * @var DateTime|null
  308. *
  309. * @ORM\Column(name="deleteStatusUpdated", type="datetime", nullable=true)
  310. */
  311. private $deleteStatusUpdated;
  312. /**
  313. * @var DateTime|null
  314. *
  315. * @ORM\Column(name="future_deletion_date", type="datetime", nullable=true)
  316. */
  317. private $future_deletion_date;
  318. /**
  319. * @var string
  320. *
  321. * @ORM\Column(name="slug", type="text")
  322. *
  323. * @Gedmo\Slug(fields={"name"}, updatable=false, separator="_")
  324. */
  325. private $slug;
  326. /**
  327. * @var DateTime
  328. *
  329. * @ORM\Column(name="created", type="datetime")
  330. *
  331. * @Gedmo\Timestampable(on="create")
  332. *
  333. */
  334. private $created;
  335. /**
  336. * @var DateTime
  337. *
  338. * @ORM\Column(name="updated", type="datetime")
  339. *
  340. * @Gedmo\Timestampable(on="update")
  341. */
  342. private $updated;
  343. /**
  344. * @var string
  345. *
  346. * @ORM\Column(name="search_index", type="text", nullable=false)
  347. */
  348. private $search_index;
  349. /**
  350. * @var int
  351. *
  352. * @ORM\Column(name="license_level", type="integer", nullable=false)
  353. */
  354. private $license_level;
  355. /**
  356. * @var string|null
  357. *
  358. * @ORM\Column(name="documents_total_filesize", type="string", nullable=true)
  359. */
  360. private $documents_total_filesize;
  361. /**
  362. * @var string|null
  363. *
  364. * @ORM\Column(name="active_discs_total_archive_filesize", type="string", nullable=true)
  365. */
  366. private $active_discs_total_archive_filesize;
  367. /**
  368. * @var DateTime|null
  369. *
  370. * @ORM\Column(name="limitation_date", type="datetime", nullable=true)
  371. */
  372. private $limitation_date;
  373. /**
  374. * @var int|null
  375. *
  376. * @ORM\Column(name="claim_category", type="integer", nullable=true)
  377. */
  378. private $claim_category;
  379. /**
  380. * @var int|null
  381. *
  382. * @ORM\Column(name="estimated_claim_value", type="integer", nullable=true)
  383. */
  384. private $estimated_claim_value;
  385. /**
  386. * @var string|null
  387. *
  388. * @ORM\Column(name="team", type="string", nullable=true)
  389. */
  390. private $team;
  391. /**
  392. * @var string|null
  393. *
  394. * @ORM\Column(name="default_role", type="string", nullable=true)
  395. */
  396. private $default_role;
  397. /**
  398. * UserNotifications disabled for this Project
  399. *
  400. * @var array|null
  401. *
  402. * @ORM\Column(name="disabled_notifications", type="array", nullable=true)
  403. */
  404. private $disabled_notifications;
  405. /**
  406. * Whether to require the user to enter a password on downloading a document or folder
  407. *
  408. * @var bool
  409. *
  410. * @ORM\Column(name="require_password_on_download", type="boolean", options={"default"=false})
  411. */
  412. private $require_password_on_download = false;
  413. /**
  414. * Whether to require the user to enter a password when accepting an invitation to join a project
  415. *
  416. * @var bool
  417. *
  418. * @ORM\Column(name="inviteUserMustAuthenticate", type="boolean", options={"default"=false})
  419. */
  420. private $inviteUserMustAuthenticate = false;
  421. /**
  422. * @var string|null
  423. *
  424. * @ORM\Column(name="inviteUserPassword", type="string", nullable=true)
  425. */
  426. private $inviteUserPassword;
  427. /**
  428. * @var string|null
  429. *
  430. * @ORM\Column(name="inviteUserContactName", type="string", nullable=true)
  431. */
  432. private $inviteUserContactName;
  433. /**
  434. * @var string|null
  435. *
  436. * @ORM\Column(name="inviteUserContactEmail", type="string", nullable=true)
  437. */
  438. private $inviteUserContactEmail;
  439. /**
  440. * @var PhoneNumber|null
  441. *
  442. * @ORM\Column(name="inviteUserContactPhoneNumber", type="phone_number", nullable=true)
  443. */
  444. private $inviteUserContactPhoneNumber;
  445. /**
  446. * @var DateTime|null
  447. *
  448. * @ORM\Column(name="date_on_letter", type="datetime", nullable=true)
  449. */
  450. private $date_on_letter;
  451. /**
  452. * @var string|null
  453. *
  454. * @ORM\Column(name="case_merits_analysis", type="string", nullable=true)
  455. */
  456. private $case_merits_analysis;
  457. /**
  458. * @var string|null
  459. *
  460. * @ORM\Column(name="claimant_solicitor", type="string", nullable=true)
  461. */
  462. private $claimant_solicitor;
  463. /**
  464. * @var string|null
  465. *
  466. * @ORM\Column(name="type_of_letter", type="string", nullable=true)
  467. */
  468. private $type_of_letter;
  469. /**
  470. * @var string|null
  471. *
  472. * @ORM\Column(name="review_type", type="string", nullable=true)
  473. */
  474. private $review_type;
  475. /**
  476. * @var DateTime|null
  477. *
  478. * @ORM\Column(name="experts_report_date", type="datetime", nullable=true)
  479. */
  480. private $experts_report_date;
  481. /**
  482. * @var DateTime|null
  483. *
  484. * @ORM\Column(name="letter_of_response_and_expert_report_date", type="datetime", nullable=true)
  485. */
  486. private $letter_of_response_and_expert_report_date;
  487. /**
  488. * @var DateTime|null
  489. *
  490. * @ORM\Column(name="letter_of_response_prepared_date", type="datetime", nullable=true)
  491. */
  492. private $letter_of_response_prepared_date;
  493. /**
  494. * @var DateTime|null
  495. *
  496. * @ORM\Column(name="letter_of_response_sent_date", type="datetime", nullable=true)
  497. */
  498. private $letter_of_response_sent_date;
  499. /**
  500. * @var DateTime|null
  501. *
  502. * @ORM\Column(name="dateDeleted", type="datetime", nullable=true)
  503. */
  504. private $dateDeleted;
  505. /**
  506. * Determines if users with role Expert and Expert - View Only on a Project/Matter can see
  507. * the Unsorted records folder on the Medical Records Screen.
  508. *
  509. * @var bool|null
  510. *
  511. * @ORM\Column(name="allowExpertViewUnsortedRecords", type="boolean", nullable=true)
  512. */
  513. private $allowExpertViewUnsortedRecords;
  514. /**
  515. * @var ProjectDeletionReport
  516. *
  517. * @ORM\OneToOne(targetEntity="MedBrief\MSR\Entity\ProjectDeletionReport", inversedBy="project")
  518. *
  519. * @ORM\JoinColumns({
  520. *
  521. * @ORM\JoinColumn(name="projectDeletionReport_id", referencedColumnName="id", unique=true)
  522. * })
  523. */
  524. private $projectDeletionReport;
  525. /**
  526. * @var Collection
  527. *
  528. * @ORM\OneToOne(targetEntity="MedBrief\MSR\Entity\Collection", inversedBy="projectMedicalRecords", cascade={"all"})
  529. *
  530. * @ORM\JoinColumns({
  531. *
  532. * @ORM\JoinColumn(name="medicalRecordsCollection_id", referencedColumnName="id", unique=true)
  533. * })
  534. */
  535. private $medicalRecordsCollection;
  536. /**
  537. * @var Collection
  538. *
  539. * @ORM\OneToOne(targetEntity="MedBrief\MSR\Entity\Collection", inversedBy="projectUnsortedRecords", cascade={"all"})
  540. *
  541. * @ORM\JoinColumns({
  542. *
  543. * @ORM\JoinColumn(name="unsortedRecordsCollection_id", referencedColumnName="id", unique=true)
  544. * })
  545. */
  546. private $unsortedRecordsCollection;
  547. /**
  548. * @var Collection
  549. *
  550. * @ORM\OneToOne(targetEntity="MedBrief\MSR\Entity\Collection", inversedBy="projectPrivate", cascade={"all"})
  551. *
  552. * @ORM\JoinColumns({
  553. *
  554. * @ORM\JoinColumn(name="privateCollection_id", referencedColumnName="id", unique=true)
  555. * })
  556. */
  557. private $privateCollection;
  558. /**
  559. * This collection contains collections specific to a user,
  560. * from which they are free to upload and download Documents.
  561. *
  562. * @var Collection
  563. *
  564. * @ORM\OneToOne(targetEntity="MedBrief\MSR\Entity\Collection", inversedBy="projectPrivateSandbox", cascade={"all"})
  565. *
  566. * @ORM\JoinColumns({
  567. *
  568. * @ORM\JoinColumn(name="privateSandboxCollection_id", referencedColumnName="id", unique=true)
  569. * })
  570. */
  571. private $privateSandboxCollection;
  572. /**
  573. * @var MatterRequest
  574. *
  575. * @ORM\OneToOne(targetEntity="MedBrief\MSR\Entity\MatterRequest\MatterRequest", mappedBy="matter", cascade={"persist", "remove"})
  576. */
  577. private $matterRequest;
  578. /**
  579. * @var ProjectClosure
  580. *
  581. * @ORM\OneToOne(targetEntity="MedBrief\MSR\Entity\ProjectClosure", mappedBy="project", cascade={"persist", "remove"})
  582. */
  583. private $projectClosure;
  584. /**
  585. * @var DoctrineCollection
  586. *
  587. * @ORM\OneToMany(targetEntity="MedBrief\MSR\Entity\Document", mappedBy="project", orphanRemoval=true)
  588. */
  589. private $documents;
  590. /**
  591. * @var DoctrineCollection
  592. *
  593. * @ORM\OneToMany(targetEntity="MedBrief\MSR\Entity\ProjectUser", mappedBy="project", cascade={"all"})
  594. */
  595. private $projectUsers;
  596. /**
  597. * @var DoctrineCollection
  598. *
  599. * @ORM\OneToMany(targetEntity="MedBrief\MSR\Entity\Disc", mappedBy="project", cascade={"all"})
  600. *
  601. * @ORM\OrderBy({
  602. * "created"="ASC"
  603. * })
  604. */
  605. private $discs;
  606. /**
  607. * @var DoctrineCollection
  608. *
  609. * @ORM\OneToMany(targetEntity="MedBrief\MSR\Entity\RecordsRequest", mappedBy="project", cascade={"all"})
  610. */
  611. private $recordsRequests;
  612. /**
  613. * @var DoctrineCollection
  614. *
  615. * @ORM\OneToMany(targetEntity="MedBrief\MSR\Entity\BatchRequest", mappedBy="project", cascade={"all"})
  616. */
  617. private $batchRequests;
  618. /**
  619. * @var DoctrineCollection
  620. *
  621. * @ORM\OneToMany(targetEntity="MedBrief\MSR\Entity\ChronologyRequest", mappedBy="project", cascade={"all"})
  622. */
  623. private $chronologyRequests;
  624. /**
  625. * @var DoctrineCollection
  626. *
  627. * @ORM\OneToMany(targetEntity="MedBrief\MSR\Entity\AdditionalRequest", mappedBy="project", cascade={"all"})
  628. */
  629. private $additionalRequests;
  630. /**
  631. * @var DoctrineCollection
  632. *
  633. * @ORM\OneToMany(targetEntity="MedBrief\MSR\Entity\SortingSession", mappedBy="project", cascade={"all"})
  634. */
  635. private $sortingSessions;
  636. /**
  637. * @var DoctrineCollection
  638. *
  639. * @ORM\OneToMany(targetEntity="MedBrief\MSR\Entity\Patient", mappedBy="project", cascade={"all"})
  640. */
  641. private $patients;
  642. /**
  643. * @var DoctrineCollection
  644. *
  645. * @ORM\OneToMany(targetEntity="MedBrief\MSR\Entity\Study", mappedBy="project", cascade={"all"})
  646. */
  647. private $studies;
  648. /**
  649. * @var DoctrineCollection
  650. *
  651. * @ORM\OneToMany(targetEntity="MedBrief\MSR\Entity\Series", mappedBy="project", cascade={"all"})
  652. */
  653. private $series;
  654. /**
  655. * @var DoctrineCollection
  656. *
  657. * @ORM\OneToMany(targetEntity="MedBrief\MSR\Entity\DiscImportSession", mappedBy="project", cascade={"all"})
  658. */
  659. private $discImportSessions;
  660. /**
  661. * @var DoctrineCollection
  662. *
  663. * @ORM\OneToMany(targetEntity="MedBrief\MSR\Entity\MatterNote", mappedBy="project", cascade={"persist","remove"}, orphanRemoval=true)
  664. */
  665. private $matterNotes;
  666. /**
  667. * @var DoctrineCollection
  668. *
  669. * @ORM\OneToMany(targetEntity="MedBrief\MSR\Entity\MatterCommunication", mappedBy="project", cascade={"all"})
  670. */
  671. private $matterCommunications;
  672. /**
  673. * @var
  674. *
  675. * @Groups({"clinical_summary_matter:read"})
  676. *
  677. * @ORM\ManyToOne(targetEntity="MedBrief\MSR\Entity\Account", inversedBy="projects")
  678. *
  679. * @ORM\JoinColumns({
  680. *
  681. * @ORM\JoinColumn(name="account_id", referencedColumnName="id", nullable=false)
  682. * })
  683. */
  684. private $account;
  685. /**
  686. * @var User
  687. *
  688. * @ORM\ManyToOne(targetEntity="MedBrief\MSR\Entity\User", inversedBy="managedProjects")
  689. *
  690. * @ORM\JoinColumns({
  691. *
  692. * @ORM\JoinColumn(name="manager_id", referencedColumnName="id", nullable=true)
  693. * })
  694. */
  695. private $manager;
  696. /**
  697. * @var DoctrineCollection|null
  698. *
  699. * @ORM\ManyToMany(targetEntity="MedBrief\MSR\Entity\User")
  700. *
  701. * @ORM\JoinTable(
  702. * name="project_additional_contacts",
  703. * joinColumns={@ORM\JoinColumn(name="project_id", referencedColumnName="id", onDelete="CASCADE", nullable=true)},
  704. * inverseJoinColumns={@ORM\JoinColumn(name="user_id", referencedColumnName="id", onDelete="CASCADE", nullable=true)}
  705. * )
  706. */
  707. private $additionalContacts;
  708. /**
  709. * @ORM\OneToMany(targetEntity=Instance::class, mappedBy="project")
  710. */
  711. private $instances;
  712. /**
  713. * @ORM\Column(type="string", nullable=true)
  714. */
  715. private ?string $firmRecordsReviewStatus = null;
  716. /**
  717. * @ORM\Column(type="datetime", nullable=true)
  718. */
  719. private ?DateTime $firmRecordsReviewUpdated = null;
  720. /**
  721. * @ORM\Column(type="string", nullable=true)
  722. */
  723. private ?string $clinicalSummaryUnsortedStatus = null;
  724. /**
  725. * @ORM\Column(type="datetime", nullable=true)
  726. */
  727. private ?DateTime $clinicalSummaryUnsortedUpdated = null;
  728. /**
  729. * @ORM\OneToMany(targetEntity=InterpartyDisclosure::class, mappedBy="project", orphanRemoval=true, cascade={"persist", "remove"})
  730. *
  731. * @ORM\OrderBy({"id"="DESC"})
  732. */
  733. private ?DoctrineCollection $interpartyDisclosures;
  734. /**
  735. * @ORM\Column(name="matterType", type="string", length=64, nullable=true)
  736. *
  737. */
  738. private ?string $matterType = self::MATTER_TYPE_CLINICAL_NEGLIGENCE;
  739. /**
  740. * @ORM\Column(type="string", nullable=true)
  741. */
  742. private ?string $modernRadiologyMigrationStatus;
  743. /**
  744. * @ORM\Column(type="boolean", nullable=false, options={"default"=false})
  745. */
  746. private bool $useModernRadiology = false;
  747. /**
  748. * @ORM\Column(type="string", nullable=false, options={"default"=self::TYPE_MATTER_FIRM})
  749. */
  750. private ?string $type = self::TYPE_MATTER_FIRM;
  751. /**
  752. * @ORM\Column(type="boolean", nullable=false, options={"default"=false})
  753. */
  754. private bool $hideFromInvoicing = false;
  755. /**
  756. * @ORM\Column(type="datetime", nullable=true)
  757. */
  758. private ?DateTime $lastRenewalDate = null;
  759. /**
  760. * @ORM\Column(type="datetime", nullable=true)
  761. */
  762. private ?DateTime $nextRenewalDate;
  763. /**
  764. * @ORM\Column(type="json", nullable=true)
  765. */
  766. private ?array $renewalNotificationSent = [];
  767. /**
  768. * @ORM\OneToMany(targetEntity=MatterLicenceRenewalLog::class, mappedBy="project")
  769. */
  770. private ?DoctrineCollection $matterLicenceRenewalLogs;
  771. /**
  772. * @ORM\Column(type="string", length=255, nullable=true)
  773. */
  774. private ?string $permanentDeleteStatus = null;
  775. /**
  776. * @Groups({"clinical_summary_matter:read"})
  777. *
  778. * @ORM\OneToOne(targetEntity=ClinicalSummary::class, mappedBy="project", cascade={"persist", "remove"})
  779. */
  780. private ?ClinicalSummary $clinicalSummary;
  781. public function __construct()
  782. {
  783. // default status of INACTIVE
  784. $this->setStatus(self::STATUS_INACTIVE);
  785. $this->patients = new ArrayCollection();
  786. $this->studies = new ArrayCollection();
  787. $this->series = new ArrayCollection();
  788. $this->discs = new ArrayCollection();
  789. $this->recordsRequests = new ArrayCollection();
  790. $this->batchRequests = new ArrayCollection();
  791. $this->additionalRequests = new ArrayCollection();
  792. $this->chronologyRequests = new ArrayCollection();
  793. $this->sortingSessions = new ArrayCollection();
  794. $this->matterNotes = new ArrayCollection();
  795. $this->documents = new ArrayCollection();
  796. $this->projectUsers = new ArrayCollection();
  797. $this->discImportSessions = new ArrayCollection();
  798. $this->matterCommunications = new ArrayCollection();
  799. $this->instances = new ArrayCollection();
  800. $this->interpartyDisclosures = new ArrayCollection();
  801. $this->disclosureSources = new ArrayCollection();
  802. $this->matterLicenceRenewalLogs = new ArrayCollection();
  803. $this->medicalRecordsCollection = new Collection();
  804. $this->medicalRecordsCollection
  805. ->setName(Collection::DISPLAY_NAME_MEDICAL_RECORDS)
  806. ->setProjectMedicalRecords($this)
  807. ;
  808. $this->unsortedRecordsCollection = new Collection();
  809. $this->unsortedRecordsCollection
  810. ->setName(Collection::DISPLAY_NAME_UNSORTED_RECORDS)
  811. ->setProjectUnsortedRecords($this)
  812. ;
  813. // default the date created for matters to the current date
  814. $this->setDateCreated(new DateTime());
  815. // All matters default to the standard license
  816. $this->setLicenseLevel(self::LICENSE_LEVEL_STANDARD);
  817. $this->require_password_on_download = false;
  818. $this->setInviteUserMustAuthenticate(false);
  819. // Set this in the constructor so it only applies to new matters
  820. $this->setModernRadiologyMigrationStatus(self::MODERN_RADIOLOGY_MIGRATION_STATUS_SKIPPED);
  821. $this->matterLicenceRenewalLogs = new ArrayCollection();
  822. $this->additionalContacts = new ArrayCollection();
  823. }
  824. public function __toString()
  825. {
  826. return $this->getName();
  827. }
  828. /**
  829. * @return int
  830. */
  831. public function getId()
  832. {
  833. return $this->id;
  834. }
  835. /**
  836. * @param string $name
  837. *
  838. * @return Project
  839. */
  840. public function setName($name)
  841. {
  842. $this->name = $name;
  843. return $this;
  844. }
  845. /**
  846. * @return string
  847. */
  848. public function getName()
  849. {
  850. return $this->name;
  851. }
  852. /**
  853. * @param int $pages
  854. *
  855. * @return Project
  856. */
  857. public function setPages($pages)
  858. {
  859. $this->pages = $pages;
  860. return $this;
  861. }
  862. /**
  863. * @return int
  864. */
  865. public function getPages()
  866. {
  867. return $this->pages;
  868. }
  869. /**
  870. * @param Account|null $account
  871. *
  872. * @return Project
  873. */
  874. public function setAccount(?Account $account = null)
  875. {
  876. $this->account = $account;
  877. return $this;
  878. }
  879. /**
  880. * @return Account
  881. */
  882. public function getAccount()
  883. {
  884. return $this->account;
  885. }
  886. /**
  887. * @param string $slug
  888. *
  889. * @return Project
  890. */
  891. public function setSlug($slug)
  892. {
  893. $this->slug = $slug;
  894. return $this;
  895. }
  896. /**
  897. * @return string
  898. */
  899. public function getSlug()
  900. {
  901. return $this->slug;
  902. }
  903. /**
  904. * @param DateTime $created
  905. *
  906. * @return Project
  907. */
  908. public function setCreated($created)
  909. {
  910. $this->created = $created;
  911. return $this;
  912. }
  913. /**
  914. * @return DateTime
  915. */
  916. public function getCreated()
  917. {
  918. return $this->created;
  919. }
  920. /**
  921. * @param DateTime $updated
  922. *
  923. * @return Project
  924. */
  925. public function setUpdated($updated)
  926. {
  927. $this->updated = $updated;
  928. return $this;
  929. }
  930. /**
  931. * @return DateTime
  932. */
  933. public function getUpdated()
  934. {
  935. return $this->updated;
  936. }
  937. /**
  938. * @param Document $documents
  939. *
  940. * @return Project
  941. */
  942. public function addDocument(Document $documents)
  943. {
  944. $this->documents[] = $documents;
  945. return $this;
  946. }
  947. /**
  948. * @param Document $documents
  949. */
  950. public function removeDocument(Document $documents)
  951. {
  952. $this->documents->removeElement($documents);
  953. }
  954. /**
  955. * @return DoctrineCollection|Document[]
  956. */
  957. public function getDocuments()
  958. {
  959. return $this->documents;
  960. }
  961. /**
  962. * @param Disc $disc
  963. *
  964. * @return Project
  965. */
  966. public function addDisc(Disc $disc)
  967. {
  968. if (!$this->discs->contains($disc)) {
  969. $this->discs[] = $disc;
  970. }
  971. return $this;
  972. }
  973. /**
  974. * @param Disc $discs
  975. *
  976. * @return Project
  977. */
  978. public function removeDisc(Disc $discs)
  979. {
  980. $this->discs->removeElement($discs);
  981. return $this;
  982. }
  983. /**
  984. * @return DoctrineCollection|Disc[]
  985. */
  986. public function getDiscs()
  987. {
  988. return $this->discs;
  989. }
  990. /**
  991. * @return bool
  992. */
  993. public function isAllDiscsPendingUpload(): bool
  994. {
  995. foreach ($this->getDiscs() as $disc) {
  996. if ($disc->getStatus() !== Disc::STATUS_PENDING_UPLOAD) {
  997. return false;
  998. }
  999. }
  1000. return true;
  1001. }
  1002. /**
  1003. * Gets Discs for a project with a specific status.
  1004. *
  1005. * @param mixed $status
  1006. *
  1007. * @return ArrayCollection | null
  1008. */
  1009. public function getDiscsByStatus($status)
  1010. {
  1011. return $this->discs->filter(function (Disc $disc) use ($status) {
  1012. return $disc->getStatus() === $status;
  1013. });
  1014. }
  1015. /**
  1016. * Get all active Discs for a Project
  1017. *
  1018. * @return ArrayCollection|null
  1019. */
  1020. public function getActiveDiscs()
  1021. {
  1022. return $this->getDiscsByStatus(Disc::STATUS_ACTIVE);
  1023. }
  1024. /**
  1025. * Gets all failed Discs for a Project
  1026. *
  1027. * @return ArrayCollection|null
  1028. */
  1029. public function getFailedDiscs()
  1030. {
  1031. return $this->getDiscs()->filter(function (Disc $disc) {
  1032. // return true if disc failed, however exclude discs with status failed virus
  1033. // Normally we don't need to check for deletedAt, as the softdeletable filter filters it out,
  1034. // but in the case of disclosures, we switch this filter off, to avoid a broken relationship issue.
  1035. return $disc->isFailed([Disc::STATUS_FAILED_VIRUS]) && $disc->getDeletedAt() === null;
  1036. });
  1037. }
  1038. /**
  1039. * @param int $status
  1040. *
  1041. * @return Project
  1042. */
  1043. public function setStatus($status)
  1044. {
  1045. $this->status = $status;
  1046. return $this;
  1047. }
  1048. /**
  1049. * @return int
  1050. */
  1051. public function getStatus()
  1052. {
  1053. return $this->status;
  1054. }
  1055. /**
  1056. * Returns true if the Project is inactive.
  1057. *
  1058. * @return bool
  1059. */
  1060. public function isInactive()
  1061. {
  1062. return $this->getStatus() === self::STATUS_INACTIVE;
  1063. }
  1064. /**
  1065. * @param string $clientReference
  1066. *
  1067. * @return Project
  1068. */
  1069. public function setClientReference($clientReference)
  1070. {
  1071. $this->client_reference = $clientReference;
  1072. // Update the associated matter request as well, if it exists, and if the values are different,
  1073. // to avoid a recursive loop.
  1074. if ($this->getMatterRequest() && $this->getMatterRequest()->getMatterReference() != $this->client_reference) {
  1075. $this->getMatterRequest()->setMatterReference($this->client_reference);
  1076. }
  1077. return $this;
  1078. }
  1079. /**
  1080. * @Groups({"project_closure:read"})
  1081. *
  1082. * @return string
  1083. */
  1084. public function getClientReference()
  1085. {
  1086. return $this->client_reference;
  1087. }
  1088. /**
  1089. * @param string $reference
  1090. *
  1091. * @return Project
  1092. */
  1093. public function setReference($reference)
  1094. {
  1095. $this->reference = $reference;
  1096. return $this;
  1097. }
  1098. /**
  1099. * @return string
  1100. */
  1101. public function getReference()
  1102. {
  1103. return $this->reference;
  1104. }
  1105. /**
  1106. * @param Patient $patients
  1107. *
  1108. * @return Project
  1109. */
  1110. public function addPatient(Patient $patients)
  1111. {
  1112. $this->patients[] = $patients;
  1113. return $this;
  1114. }
  1115. /**
  1116. * @param Patient $patients
  1117. */
  1118. public function removePatient(Patient $patients)
  1119. {
  1120. $this->patients->removeElement($patients);
  1121. }
  1122. /**
  1123. * @return DoctrineCollection|RadiologyPatient[]
  1124. */
  1125. public function getPatients()
  1126. {
  1127. return $this->patients;
  1128. }
  1129. /**
  1130. * @param Study $studies
  1131. *
  1132. * @return Project
  1133. */
  1134. public function addStudy(Study $studies)
  1135. {
  1136. $this->studies[] = $studies;
  1137. return $this;
  1138. }
  1139. /**
  1140. * @param Study $studies
  1141. */
  1142. public function removeStudy(Study $studies)
  1143. {
  1144. $this->studies->removeElement($studies);
  1145. }
  1146. /**
  1147. * @return DoctrineCollection|Study[]
  1148. */
  1149. public function getStudies()
  1150. {
  1151. return $this->studies;
  1152. }
  1153. /**
  1154. * Get Studies with active Discs
  1155. *
  1156. * @return ArrayCollection|null
  1157. */
  1158. public function getStudiesWithActiveDiscs()
  1159. {
  1160. return $this->getStudies()->filter(function (Study $study) {
  1161. return $study->getDiscs()->filter(function (Disc $disc) {
  1162. // Normally we don't need to check for deletedAt, as the softdeletable filter filters it out,
  1163. // but in the case of disclosures, we switch this filter off, to avoid a broken relationship issue.
  1164. // Due to the many-to-many relation between Disc and Study, the check for deletedAt isn't ACTUALLY needed,
  1165. // but for data integrity, we do the check anyway.
  1166. return $disc->isActive() && $disc->getDeletedAt() === null;
  1167. })->count();
  1168. });
  1169. }
  1170. /**
  1171. * @param Series $series
  1172. *
  1173. * @return Project
  1174. */
  1175. public function addSeries(Series $series)
  1176. {
  1177. $this->series[] = $series;
  1178. return $this;
  1179. }
  1180. /**
  1181. * @param Series $series
  1182. */
  1183. public function removeSeries(Series $series)
  1184. {
  1185. $this->series->removeElement($series);
  1186. }
  1187. /**
  1188. * @return DoctrineCollection|Series[]
  1189. */
  1190. public function getSeries()
  1191. {
  1192. return $this->series;
  1193. }
  1194. /**
  1195. * Returns the MedBrief Matter reference number which is essentially the ClientReference
  1196. * of the Project padded with zeros to six figures
  1197. *
  1198. * @return string
  1199. */
  1200. public function getReferenceNumber()
  1201. {
  1202. return str_pad($this->getClientReference(), 6, '0', STR_PAD_LEFT);
  1203. }
  1204. /**
  1205. * @param DateTime $dateCreated
  1206. *
  1207. * @return Project
  1208. */
  1209. public function setDateCreated($dateCreated)
  1210. {
  1211. $this->date_created = $dateCreated;
  1212. return $this;
  1213. }
  1214. /**
  1215. * @return DateTime
  1216. */
  1217. public function getDateCreated()
  1218. {
  1219. return $this->date_created;
  1220. }
  1221. /**
  1222. * @param DateTime $patientDateOfBirth
  1223. *
  1224. * @throws Exception
  1225. *
  1226. * @return Project
  1227. */
  1228. public function setPatientDateOfBirth($patientDateOfBirth)
  1229. {
  1230. $this->patient_date_of_birth = $patientDateOfBirth;
  1231. // Update the matter request's first patient's date of birth, if different from matter date of birth.
  1232. if ($this->getMatterRequest() && $this->getMatterRequest()->getPatients()->count() > 0) {
  1233. /** @var Patient $firstPatient */
  1234. $firstPatient = $this->getMatterRequest()->getPatients()->first();
  1235. if ($firstPatient->getDateOfBirth() != $this->patient_date_of_birth) {
  1236. $dateOfBirthImmutable = null;
  1237. if ($this->patient_date_of_birth instanceof DateTime) {
  1238. $dateOfBirthImmutable = new \DateTimeImmutable($this->patient_date_of_birth->format('Y-m-d'));
  1239. }
  1240. $firstPatient->setDateOfBirth($dateOfBirthImmutable);
  1241. }
  1242. }
  1243. return $this;
  1244. }
  1245. /**
  1246. * @return DateTime
  1247. */
  1248. public function getPatientDateOfBirth()
  1249. {
  1250. return $this->patient_date_of_birth;
  1251. }
  1252. /**
  1253. * @param User|null $manager
  1254. *
  1255. * @return Project
  1256. */
  1257. public function setManager(?User $manager = null)
  1258. {
  1259. $this->manager = $manager;
  1260. // Update the associated matter request as well, if it exists, and if the values are different,
  1261. // to avoid a recursive loop.
  1262. if ($manager && $this->getMatterRequest() && $this->getMatterRequest()->getManager() != $this->manager) {
  1263. $this->getMatterRequest()->setManager($this->manager);
  1264. }
  1265. return $this;
  1266. }
  1267. /**
  1268. * @return Project
  1269. */
  1270. public function unsetManager()
  1271. {
  1272. $this->manager = null;
  1273. return $this;
  1274. }
  1275. /**
  1276. * retrieves the manager of the project
  1277. *
  1278. * @return User|null
  1279. */
  1280. public function getManager(): ?User
  1281. {
  1282. try {
  1283. // If the manager is a Proxy, we need to load it to ensure it is fully initialized.
  1284. if ($this->manager instanceof Proxy) {
  1285. $this->manager->__load();
  1286. }
  1287. return $this->manager;
  1288. } catch (EntityNotFoundException) {
  1289. // If the manager is not found (has been soft deleted), return null.
  1290. return null;
  1291. }
  1292. }
  1293. /**
  1294. * Returns additional contacts for a matter
  1295. *
  1296. * @return DoctrineCollection|null
  1297. */
  1298. public function getAdditionalContacts(): ?DoctrineCollection
  1299. {
  1300. return $this->additionalContacts;
  1301. }
  1302. /**
  1303. * Sets additional contacts for a matter
  1304. *
  1305. * @param DoctrineCollection|null $additionalContacts
  1306. *
  1307. * @return self
  1308. */
  1309. public function setAdditionalContacts(?DoctrineCollection $additionalContacts): self
  1310. {
  1311. $this->additionalContacts = $additionalContacts ?: new ArrayCollection();
  1312. return $this;
  1313. }
  1314. /**
  1315. * @param RecordsRequest $recordsRequests
  1316. *
  1317. * @return Project
  1318. */
  1319. public function addRecordsRequest(RecordsRequest $recordsRequests)
  1320. {
  1321. $this->recordsRequests[] = $recordsRequests;
  1322. return $this;
  1323. }
  1324. /**
  1325. * @param RecordsRequest $recordsRequests
  1326. */
  1327. public function removeRecordsRequest(RecordsRequest $recordsRequests)
  1328. {
  1329. $this->recordsRequests->removeElement($recordsRequests);
  1330. }
  1331. /**
  1332. * @return DoctrineCollection|RecordsRequest[]
  1333. */
  1334. public function getRecordsRequests()
  1335. {
  1336. return $this->recordsRequests;
  1337. }
  1338. /**
  1339. * @return array
  1340. */
  1341. public function getRecordsRequestIdsArray(): array
  1342. {
  1343. // Map the collection of records requests to extract each's ID, then convert it to an array
  1344. return $this->recordsRequests->map(function (RecordsRequest $recordsRequest) {
  1345. return $recordsRequest->getId();
  1346. })->toArray();
  1347. }
  1348. /**
  1349. * Retrieves the counts for RecordsRequests grouped by
  1350. * their serviceRequest status.
  1351. *
  1352. * @param mixed $uninvoicedOnly
  1353. *
  1354. * @return array
  1355. */
  1356. public function getRecordsRequestsCountByServiceRequestStatus($uninvoicedOnly = true)
  1357. {
  1358. return $this->getServiceableCountsByStatus($this->getRecordsRequests()->toArray(), $uninvoicedOnly);
  1359. }
  1360. /**
  1361. * @param Collection|null $medicalRecordsCollection
  1362. *
  1363. * @return Project
  1364. */
  1365. public function setMedicalRecordsCollection(?Collection $medicalRecordsCollection = null)
  1366. {
  1367. $this->medicalRecordsCollection = $medicalRecordsCollection;
  1368. return $this;
  1369. }
  1370. /**
  1371. * @return Collection
  1372. */
  1373. public function getMedicalRecordsCollection()
  1374. {
  1375. return $this->medicalRecordsCollection;
  1376. }
  1377. /**
  1378. * @param string $billingCode
  1379. *
  1380. * @return Project
  1381. */
  1382. public function setBillingCode($billingCode)
  1383. {
  1384. $this->billing_code = $billingCode;
  1385. // Update the associated matter request as well, if it exists, and if the values are different,
  1386. // to avoid a recursive loop.
  1387. if ($this->getMatterRequest() && $this->getMatterRequest()->getBillingCode() != $this->billing_code) {
  1388. $this->getMatterRequest()->setBillingCode($this->billing_code);
  1389. }
  1390. return $this;
  1391. }
  1392. /**
  1393. * @return string
  1394. */
  1395. public function getBillingCode()
  1396. {
  1397. return $this->billing_code;
  1398. }
  1399. /**
  1400. * @param DateTime $deletedAt
  1401. *
  1402. * @return Project
  1403. */
  1404. public function setDeletedAt($deletedAt)
  1405. {
  1406. $this->deletedAt = $deletedAt;
  1407. return $this;
  1408. }
  1409. /**
  1410. * @return DateTime
  1411. */
  1412. public function getDeletedAt()
  1413. {
  1414. return $this->deletedAt;
  1415. }
  1416. /**
  1417. * Add discImportSession
  1418. *
  1419. * @param DiscImportSession $discImportSession
  1420. *
  1421. * @return Project
  1422. */
  1423. public function addDiscImportSession(DiscImportSession $discImportSession)
  1424. {
  1425. $this->discImportSessions[] = $discImportSession;
  1426. return $this;
  1427. }
  1428. /**
  1429. * Remove discImportSession
  1430. *
  1431. * @param DiscImportSession $discImportSession
  1432. */
  1433. public function removeDiscImportSession(DiscImportSession $discImportSession)
  1434. {
  1435. $this->discImportSessions->removeElement($discImportSession);
  1436. }
  1437. /**
  1438. * @return DoctrineCollection
  1439. */
  1440. public function getDiscImportSessions()
  1441. {
  1442. return $this->discImportSessions;
  1443. }
  1444. /**
  1445. * @param string $patientName
  1446. *
  1447. * @return Project
  1448. */
  1449. public function setPatientName($patientName)
  1450. {
  1451. $this->patient_name = $patientName;
  1452. return $this;
  1453. }
  1454. /**
  1455. * @return string
  1456. */
  1457. public function getPatientName()
  1458. {
  1459. return $this->patient_name;
  1460. }
  1461. /**
  1462. * @param string $oldMatterReference
  1463. *
  1464. * @return Project
  1465. */
  1466. public function setOldMatterReference($oldMatterReference)
  1467. {
  1468. $this->old_matter_reference = $oldMatterReference;
  1469. return $this;
  1470. }
  1471. /**
  1472. * @return string
  1473. */
  1474. public function getOldMatterReference()
  1475. {
  1476. return $this->old_matter_reference;
  1477. }
  1478. /**
  1479. * @param string $millnetId
  1480. *
  1481. * @return Project
  1482. */
  1483. public function setMillnetId($millnetId)
  1484. {
  1485. $this->millnet_id = $millnetId;
  1486. return $this;
  1487. }
  1488. /**
  1489. * @return string
  1490. */
  1491. public function getMillnetId()
  1492. {
  1493. return $this->millnet_id;
  1494. }
  1495. /**
  1496. * @param int $holdSettled
  1497. *
  1498. * @return Project
  1499. */
  1500. public function setHoldSettled($holdSettled)
  1501. {
  1502. $this->hold_settled = $holdSettled;
  1503. return $this;
  1504. }
  1505. /**
  1506. * @return int
  1507. */
  1508. public function getHoldSettled()
  1509. {
  1510. return $this->hold_settled;
  1511. }
  1512. /**
  1513. * @param DateTime $dateClosed
  1514. *
  1515. * @return Project
  1516. */
  1517. public function setDateClosed($dateClosed)
  1518. {
  1519. $this->date_closed = $dateClosed;
  1520. return $this;
  1521. }
  1522. /**
  1523. * @return DateTime
  1524. */
  1525. public function getDateClosed()
  1526. {
  1527. return $this->date_closed;
  1528. }
  1529. /**
  1530. * @param DateTime|null $forcedRenewalCreated
  1531. *
  1532. * @return Project
  1533. */
  1534. public function setForcedRenewalCreated(?DateTime $forcedRenewalCreated = null)
  1535. {
  1536. $this->forcedRenewalCreated = $forcedRenewalCreated;
  1537. return $this;
  1538. }
  1539. /**
  1540. * @return DateTime|null
  1541. */
  1542. public function getForcedRenewalCreated(): ?DateTime
  1543. {
  1544. return $this->forcedRenewalCreated;
  1545. }
  1546. /**
  1547. * @param string $searchIndex
  1548. *
  1549. * @return Project
  1550. */
  1551. public function setSearchIndex($searchIndex)
  1552. {
  1553. $this->search_index = $searchIndex;
  1554. return $this;
  1555. }
  1556. /**
  1557. * @return string
  1558. */
  1559. public function getSearchIndex()
  1560. {
  1561. return $this->search_index;
  1562. }
  1563. /**
  1564. * Updates the Search Index field with internal data. The Search Index Field
  1565. * provides an easy way to perform a 'like' query for a generalised search.
  1566. *
  1567. * @ORM\PrePersist
  1568. *
  1569. * @ORM\PreUpdate
  1570. */
  1571. public function updateSearchIndex()
  1572. {
  1573. $searchIndex
  1574. = $this->getName()
  1575. . ' '
  1576. . $this->getClientReference();
  1577. $this->setSearchIndex($searchIndex);
  1578. }
  1579. /**
  1580. * Set licenseLevel
  1581. *
  1582. * @param int $licenseLevel
  1583. *
  1584. * @return Project
  1585. */
  1586. public function setLicenseLevel($licenseLevel)
  1587. {
  1588. $this->license_level = $licenseLevel;
  1589. return $this;
  1590. }
  1591. /**
  1592. * Get licenseLevel
  1593. *
  1594. * @return int
  1595. */
  1596. public function getLicenseLevel()
  1597. {
  1598. return $this->license_level;
  1599. }
  1600. /**
  1601. * Returns an array of permitted values for the license level field and their
  1602. * associated labels,
  1603. *
  1604. * @return array
  1605. */
  1606. public static function getILicenseLevelOptions()
  1607. {
  1608. return [
  1609. self::LICENSE_LEVEL_BASIC => 'Basic',
  1610. self::LICENSE_LEVEL_STANDARD => 'Standard',
  1611. self::LICENSE_LEVEL_PROFESSIONAL => 'Professional',
  1612. self::LICENSE_LEVEL_PREMIUM => 'Premium',
  1613. ];
  1614. }
  1615. /**
  1616. * Returns a human-readable version of the licence level
  1617. *
  1618. * @return string
  1619. */
  1620. public function getLicenseLevelName()
  1621. {
  1622. $options = self::getILicenseLevelOptions();
  1623. return
  1624. $options[$this->getLicenseLevel()] ?? $this->getLicenseLevel();
  1625. }
  1626. /**
  1627. * Returns the Medical Records Collection for this project in a JSTree
  1628. * formatted node tree. Notably, this structure will not include Documents
  1629. * under the top most node that also exist in sub nodes.
  1630. *
  1631. * @param string $replacementRootNodeText
  1632. * @param array $additionalLiAttributes Additional attributes for <li> elements
  1633. *
  1634. * @return array
  1635. */
  1636. public function getMedicalRecordsAsJsTreeFormattedTree($replacementRootNodeText = null, $additionalLiAttributes = [])
  1637. {
  1638. $medicalRecordsCollection = $this->getMedicalRecordsCollection();
  1639. if ($medicalRecordsCollection === null) {
  1640. // Not sure why this Project has no MR Collection so let's create a blank one
  1641. $this->medicalRecordsCollection = new Collection();
  1642. $this->medicalRecordsCollection
  1643. ->setName(Collection::DISPLAY_NAME_MEDICAL_RECORDS)
  1644. ->setProjectMedicalRecords($this)
  1645. ;
  1646. }
  1647. // first, grab the node with no children
  1648. $node = $this->getMedicalRecordsCollection()
  1649. ->getJsTreeFormattedNode(
  1650. $replacementRootNodeText,
  1651. false,
  1652. false,
  1653. $additionalLiAttributes
  1654. )
  1655. ;
  1656. // set the children sub array, ready for populating
  1657. $node['children'] = [];
  1658. // order the children alphabetically
  1659. $criteria = Criteria::create()
  1660. ->orderBy(['name' => Criteria::ASC])
  1661. ;
  1662. // add all the sub collections with all their children and document children
  1663. /** @var Collection $childCollection */
  1664. foreach ($this->getMedicalRecordsCollection()->getChildren()->matching($criteria) as $childCollection) {
  1665. $node['children'][] = $childCollection->getJsTreeFormattedNode(null, true, true, $additionalLiAttributes);
  1666. }
  1667. // all document children also get a collection id sent through, so we know what collection
  1668. // the document belongs to
  1669. $additionalLiAttributes['data-collection-id'] = $this->medicalRecordsCollection->getId();
  1670. // loop through all the document children on this main collection
  1671. foreach ($this->getMedicalRecordsCollection()->getDocuments() as $childDocument) {
  1672. // Only if the Document is assigned to one collection inside the MedicalRecords collection (this one)...
  1673. $collectionCount = $childDocument->getCollections()->filter(function (Collection $collection) {
  1674. return $this->getMedicalRecordsCollection()->containsCollectionRecursive($collection);
  1675. })->count();
  1676. // ... do we include it here, else the Document will show twice in Medical Records.
  1677. if ($collectionCount === 1) {
  1678. $node['children'][] = $childDocument->getJsTreeFormattedNode(null, $additionalLiAttributes);
  1679. }
  1680. }
  1681. return $node;
  1682. }
  1683. /**
  1684. * Returns the Unsorted Records Collection for this project in a JSTree
  1685. * formatted node tree. Notably, this structure will not include Documents
  1686. * under the top most node that also exist in sub nodes.
  1687. *
  1688. * @param string $replacementRootNodeText
  1689. * @param array $additionalLiAttributes Additional attributes for <li> elements
  1690. *
  1691. * @return array
  1692. */
  1693. public function getUnsortedRecordsAsJsTreeFormattedTree($replacementRootNodeText = null, $additionalLiAttributes = [])
  1694. {
  1695. // first, grab the node with no children
  1696. $node = $this->getUnsortedRecordsCollection()->getJsTreeFormattedNode(
  1697. $replacementRootNodeText,
  1698. false,
  1699. false,
  1700. $additionalLiAttributes
  1701. );
  1702. // set the children sub array, ready for populating
  1703. $node['children'] = [];
  1704. // order the children alphabetically
  1705. $criteria = Criteria::create()
  1706. ->orderBy(['name' => Criteria::ASC])
  1707. ;
  1708. // add all the sub collections with all their children and document children
  1709. foreach ($this->getUnsortedRecordsCollection()->getChildren()->matching($criteria) as $childCollection) {
  1710. $node['children'][] = $childCollection->getJsTreeFormattedNode(null, true, true, $additionalLiAttributes);
  1711. }
  1712. // all document children also get a collection id sent through, so we know what collection
  1713. // the document belongs to
  1714. $additionalLiAttributes['data-collection-id'] = $this->unsortedRecordsCollection->getId();
  1715. // loop through all the document children on this main collection
  1716. foreach ($this->getUnsortedRecordsCollection()->getDocuments() as $childDocument) {
  1717. // Only if the Document is assigned to one collection inside the MedicalRecords collection (this one)...
  1718. $collectionCount = $childDocument->getCollections()->filter(function (Collection $collection) {
  1719. return $this->getUnsortedRecordsCollection()->containsCollectionRecursive($collection);
  1720. })->count();
  1721. // ... do we include it here, else the Document will show twice in Medical Records.
  1722. if ($collectionCount === 1) {
  1723. $node['children'][] = $childDocument->getJsTreeFormattedNode(null, $additionalLiAttributes);
  1724. }
  1725. }
  1726. return $node;
  1727. }
  1728. /**
  1729. * Returns the Medical Records Collection for this project in a JSTree
  1730. * formatted node tree. Notably, this structure will not include Documents
  1731. * under the top most node that also exist in sub nodes.
  1732. *
  1733. * @param string $replacementRootNodeText
  1734. * @param array $additionalLiAttributes
  1735. *
  1736. * @return array
  1737. */
  1738. public function getPrivateCollectionAsJsTreeFormattedTree($replacementRootNodeText = null, $additionalLiAttributes = [])
  1739. {
  1740. // first, grab the node with no children
  1741. // NB! additional attributes MUST be set so that the outer node in the
  1742. // private tree has the data-group "private" or copy and move rules
  1743. // will not work!
  1744. $node = $this->getPrivateCollection()->getJsTreeFormattedNode($replacementRootNodeText, false, false, $additionalLiAttributes);
  1745. // set the children sub array, ready for populating
  1746. $node['children'] = [];
  1747. // order the children alphabetically
  1748. $criteria = Criteria::create()
  1749. ->orderBy(['name' => Criteria::ASC])
  1750. ;
  1751. // add all the sub collections with all their children and document children
  1752. foreach ($this->getPrivateCollection()->getChildren()->matching($criteria) as $childCollection) {
  1753. $node['children'][] = $childCollection->getJsTreeFormattedNode(null, true, true, $additionalLiAttributes);
  1754. }
  1755. // all document children also get a collection id sent through, so we know what collection
  1756. // the document belongs to
  1757. $additionalLiAttributes['data-collection-id'] = $this->getId();
  1758. // loop through all the document children on this main collection
  1759. foreach ($this->getPrivateCollection()->getDocuments() as $childDocument) {
  1760. // Only if the Document is assigned to one collection inside the Private collection (this one)...
  1761. $collectionCount = $childDocument->getCollections()->filter(function (Collection $collection) {
  1762. return $this->getPrivateCollection()->containsCollectionRecursive($collection);
  1763. })->count();
  1764. // ... do we include it here, else the Document will show twice in Medical Records.
  1765. if ($collectionCount === 1) {
  1766. $node['children'][] = $childDocument->getJsTreeFormattedNode(null, $additionalLiAttributes);
  1767. }
  1768. }
  1769. return $node;
  1770. }
  1771. /**
  1772. * Add projectUser
  1773. *
  1774. * @param ProjectUser $projectUser
  1775. *
  1776. * @return Project
  1777. */
  1778. public function addProjectUser(ProjectUser $projectUser)
  1779. {
  1780. $this->projectUsers[] = $projectUser;
  1781. return $this;
  1782. }
  1783. /**
  1784. * Remove projectUser
  1785. *
  1786. * @param ProjectUser $projectUser
  1787. */
  1788. public function removeProjectUser(ProjectUser $projectUser)
  1789. {
  1790. $this->projectUsers->removeElement($projectUser);
  1791. }
  1792. /**
  1793. * Get projectUsers
  1794. *
  1795. * @return DoctrineCollection|ProjectUser[]
  1796. */
  1797. public function getProjectUsers()
  1798. {
  1799. return $this->projectUsers;
  1800. }
  1801. /**
  1802. * Set privateCollection
  1803. *
  1804. * @param Collection|null $privateCollection
  1805. *
  1806. * @return Project
  1807. */
  1808. public function setPrivateCollection(?Collection $privateCollection = null)
  1809. {
  1810. $this->privateCollection = $privateCollection;
  1811. return $this;
  1812. }
  1813. /**
  1814. * Get privateCollection
  1815. *
  1816. * @return Collection
  1817. */
  1818. public function getPrivateCollection()
  1819. {
  1820. return $this->privateCollection;
  1821. }
  1822. /**
  1823. * Set background
  1824. *
  1825. * @param string $background
  1826. *
  1827. * @return Project
  1828. */
  1829. public function setBackground($background)
  1830. {
  1831. $this->background = $background;
  1832. // Update the associated matter request as well, if it exists, and if the values are different,
  1833. // to avoid a recursive loop.
  1834. if ($background !== null && $this->getMatterRequest() && $this->getMatterRequest()->getBackground() != $this->background) {
  1835. $this->getMatterRequest()->setBackground($this->background);
  1836. }
  1837. return $this;
  1838. }
  1839. /**
  1840. * Get background
  1841. *
  1842. * @return string
  1843. */
  1844. public function getBackground()
  1845. {
  1846. return $this->background;
  1847. }
  1848. /**
  1849. * Increases the total documents file size for this Project.
  1850. *
  1851. * This value should exclude DICOM files.
  1852. *
  1853. * @param mixed $filesize
  1854. *
  1855. * @return Project
  1856. */
  1857. public function increaseDocumentsTotalFilesize($filesize)
  1858. {
  1859. $this->documents_total_filesize += $filesize;
  1860. return $this;
  1861. }
  1862. /**
  1863. * Decreases the total documents file size for this Project.
  1864. *
  1865. * This value should exclude DICOM files.
  1866. *
  1867. * @param mixed $filesize
  1868. *
  1869. * @return Project
  1870. */
  1871. public function decreaseDocumentsTotalFilesize($filesize)
  1872. {
  1873. $this->documents_total_filesize -= $filesize;
  1874. return $this;
  1875. }
  1876. /**
  1877. * Get documentsTotalFilesize
  1878. *
  1879. * @return string
  1880. */
  1881. public function getDocumentsTotalFilesize()
  1882. {
  1883. return $this->documents_total_filesize;
  1884. }
  1885. /**
  1886. * Set documentsTotalFilesize
  1887. *
  1888. * @param mixed $documents_total_filesize
  1889. *
  1890. * @return Project
  1891. */
  1892. public function setDocumentsTotalFilesize($documents_total_filesize)
  1893. {
  1894. $this->documents_total_filesize = $documents_total_filesize;
  1895. return $this;
  1896. }
  1897. /**
  1898. * Increases the total file size in bytes of active disc archives for
  1899. * this project.
  1900. *
  1901. * @param int $filesize
  1902. *
  1903. * @return Project
  1904. */
  1905. public function increaseActiveDiscsTotalArchiveFilesize($filesize)
  1906. {
  1907. $this->active_discs_total_archive_filesize += $filesize;
  1908. return $this;
  1909. }
  1910. /**
  1911. * Decreases the total file size in bytes of active disc archives for
  1912. * this project.
  1913. *
  1914. * @param int $filesize
  1915. *
  1916. * @return Project
  1917. */
  1918. public function decreaseActiveDiscsTotalArchiveFilesize($filesize)
  1919. {
  1920. $this->active_discs_total_archive_filesize -= $filesize;
  1921. return $this;
  1922. }
  1923. /**
  1924. * Get activeDiscsTotalArchiveFilesize
  1925. *
  1926. * @return string
  1927. */
  1928. public function getActiveDiscsTotalArchiveFilesize()
  1929. {
  1930. return $this->active_discs_total_archive_filesize;
  1931. }
  1932. /**
  1933. * Set activeDiscsTotalArchiveFilesize
  1934. *
  1935. * @param mixed $active_discs_total_archive_filesize
  1936. *
  1937. * @return Project
  1938. */
  1939. public function setActiveDiscsTotalArchiveFilesize($active_discs_total_archive_filesize)
  1940. {
  1941. $this->active_discs_total_archive_filesize = $active_discs_total_archive_filesize;
  1942. return $this;
  1943. }
  1944. /**
  1945. * Get limitationDate
  1946. *
  1947. * @return DateTime
  1948. */
  1949. public function getLimitationDate()
  1950. {
  1951. return $this->limitation_date;
  1952. }
  1953. /**
  1954. * Set limitationDate
  1955. *
  1956. * @param DateTime $limitationDate
  1957. *
  1958. * @return Project
  1959. */
  1960. public function setLimitationDate($limitationDate)
  1961. {
  1962. $this->limitation_date = $limitationDate;
  1963. // Update the associated matter request as well, if it exists, and if the values are different,
  1964. // to avoid a recursive loop.
  1965. if ($this->getMatterRequest() && $this->getMatterRequest()->getLimitationDate() != $this->limitation_date) {
  1966. $this->getMatterRequest()->setLimitationDate($this->limitation_date);
  1967. }
  1968. return $this;
  1969. }
  1970. /**
  1971. * Set claimCategory
  1972. *
  1973. * @param int $claimCategory
  1974. *
  1975. * @return Project
  1976. */
  1977. public function setClaimCategory($claimCategory)
  1978. {
  1979. $this->claim_category = $claimCategory;
  1980. // Update the associated matter request as well, if it exists, and if the values are different,
  1981. // to avoid a recursive loop.
  1982. if ($this->getMatterRequest() && $this->getMatterRequest()->getClaimCategory() != $this->claim_category) {
  1983. $this->getMatterRequest()->setClaimCategory($this->claim_category);
  1984. }
  1985. return $this;
  1986. }
  1987. /**
  1988. * Get claimCategory
  1989. *
  1990. * @return int
  1991. */
  1992. public function getClaimCategory()
  1993. {
  1994. return $this->claim_category;
  1995. }
  1996. /**
  1997. * Returns an array of permitted values for the claim category field and their
  1998. * associated labels.
  1999. *
  2000. * @return array
  2001. */
  2002. public static function getClaimCategoryOptions()
  2003. {
  2004. $claimCategoryOptions = self::getConstantsWithLabelsAsChoices('CLAIM_CATEGORY');
  2005. ksort($claimCategoryOptions);
  2006. return array_flip($claimCategoryOptions);
  2007. }
  2008. /**
  2009. * Returns an array of permitted values for the claim category field and their
  2010. * associated labels, in a verbose array structure.
  2011. *
  2012. * @return array
  2013. */
  2014. public static function getClaimCategoryOptionsWithLabels()
  2015. {
  2016. return self::getConstantsWithLabels('CLAIM_CATEGORY');
  2017. }
  2018. /**
  2019. * Returns a human-readable version of the claim_category
  2020. *
  2021. * @return string
  2022. */
  2023. public function getClaimCategoryName()
  2024. {
  2025. $options = self::getClaimCategoryOptions();
  2026. return $options[$this->getClaimCategory()] ?? 'Other';
  2027. }
  2028. /**
  2029. * Returns an array of Claim Categories that are Birth Injury cases.
  2030. *
  2031. * @TODO: We should update how the constants are handled to include this
  2032. * there.
  2033. *
  2034. * @return array|int[]
  2035. */
  2036. public static function getBirthInjuryClaimCategories(): array
  2037. {
  2038. return [
  2039. self::CLAIM_CATEGORY_OBSTETRICS_RELATING_TO_CHILD,
  2040. self::CLAIM_CATEGORY_OBSTETRICS_BRAIN_INJURY_HIE,
  2041. self::CLAIM_CATEGORY_OBSTETRICS_GBS_SEPSIS,
  2042. self::CLAIM_CATEGORY_OBSTETRICS_KERNICTERUS,
  2043. self::CLAIM_CATEGORY_OBSTETRICS_NEONATAL_DEATH,
  2044. self::CLAIM_CATEGORY_OBSTETRICS_OTHER_CHILD_INJURY,
  2045. self::CLAIM_CATEGORY_OBSTETRICS_SHOULDER_DYSTOCIA,
  2046. self::CLAIM_CATEGORY_OBSTETRICS_STILLBIRTH,
  2047. self::CLAIM_CATEGORY_OBSTETRICS_WRONGFUL_BIRTH,
  2048. ];
  2049. }
  2050. /**
  2051. * Set estimatedClaimValue
  2052. *
  2053. * @param int $estimatedClaimValue
  2054. *
  2055. * @return Project
  2056. */
  2057. public function setEstimatedClaimValue($estimatedClaimValue)
  2058. {
  2059. $this->estimated_claim_value = $estimatedClaimValue;
  2060. // Update the associated matter request as well, if it exists, and if the values are different,
  2061. // to avoid a recursive loop.
  2062. if ($this->getMatterRequest() && $this->getMatterRequest()->getClaimValue() != $this->estimated_claim_value) {
  2063. $this->getMatterRequest()->setClaimValue($this->estimated_claim_value);
  2064. }
  2065. return $this;
  2066. }
  2067. /**
  2068. * Get estimatedClaimValue
  2069. *
  2070. * @return int
  2071. */
  2072. public function getEstimatedClaimValue()
  2073. {
  2074. return $this->estimated_claim_value;
  2075. }
  2076. /**
  2077. * Returns an array of permitted values for the estimated claim value field and their
  2078. * associated labels.
  2079. *
  2080. * @return array
  2081. */
  2082. public static function getEstimatedClaimValueOptions()
  2083. {
  2084. return [
  2085. self::ESTIMATED_CLAIM_VALUE_0_25000 => self::ESTIMATED_CLAIM_VALUE_0_25000__LABEL,
  2086. self::ESTIMATED_CLAIM_VALUE_25001_50000 => self::ESTIMATED_CLAIM_VALUE_25001_50000__LABEL,
  2087. self::ESTIMATED_CLAIM_VALUE_50001_100000 => self::ESTIMATED_CLAIM_VALUE_50001_100000__LABEL,
  2088. self::ESTIMATED_CLAIM_VALUE_100001_250000 => self::ESTIMATED_CLAIM_VALUE_100001_250000__LABEL,
  2089. self::ESTIMATED_CLAIM_VALUE_250001_500000 => self::ESTIMATED_CLAIM_VALUE_250001_500000__LABEL,
  2090. self::ESTIMATED_CLAIM_VALUE_500001_1000000 => self::ESTIMATED_CLAIM_VALUE_500001_1000000__LABEL,
  2091. self::ESTIMATED_CLAIM_VALUE_1000001 => self::ESTIMATED_CLAIM_VALUE_1000001__LABEL,
  2092. ];
  2093. }
  2094. /**
  2095. * Returns an array of permitted values for the estimated claim value field and their
  2096. * associated labels, in a verbose array structure.
  2097. *
  2098. * @return array
  2099. */
  2100. public static function getEstimatedClaimValueOptionsWithLabels()
  2101. {
  2102. return self::getConstantsWithLabels('ESTIMATED_CLAIM_VALUE');
  2103. }
  2104. /**
  2105. * Returns a human-readable version of the estimated_claim_value
  2106. *
  2107. * @return string
  2108. */
  2109. public function getEstimatedClaimValueName()
  2110. {
  2111. $options = self::getEstimatedClaimValueOptions();
  2112. return $options[$this->getEstimatedClaimValue()] ?? $this->getEstimatedClaimValue();
  2113. }
  2114. /**
  2115. * Set archiveStatus
  2116. *
  2117. * @param int|null $archiveStatus
  2118. *
  2119. * @return Project
  2120. */
  2121. public function setArchiveStatus(?int $archiveStatus = null)
  2122. {
  2123. $this->archive_status = $archiveStatus;
  2124. // DisclosureProjects are directly associated with their Parent Project
  2125. // As a Project may have multiple DisclosureTargets/Projects, update their archiveStatus as well
  2126. // To ensure they are included in the archive logic
  2127. foreach ($this->getInterpartyDisclosures() as $disclosure) {
  2128. if ($disclosure->getDisclosureTarget() !== null) {
  2129. $disclosure->getDisclosureTarget()->setArchiveStatus($archiveStatus);
  2130. }
  2131. }
  2132. return $this;
  2133. }
  2134. /**
  2135. * Get archiveStatus
  2136. *
  2137. * @return int
  2138. */
  2139. public function getArchiveStatus()
  2140. {
  2141. return $this->archive_status;
  2142. }
  2143. /**
  2144. * Set archiveStatusUpdated
  2145. *
  2146. * @param DateTime|null $archiveStatusUpdated
  2147. *
  2148. * @return Project
  2149. */
  2150. public function setArchiveStatusUpdated(?DateTime $archiveStatusUpdated = null)
  2151. {
  2152. $this->archive_status_updated = $archiveStatusUpdated;
  2153. // DisclosureProjects are directly associated with their Parent Project
  2154. // As a Project may have multiple DisclosureTargets, update their archiveStatusUpdated as well
  2155. // To ensure they are included in the archive logic
  2156. foreach ($this->getInterpartyDisclosures() as $disclosure) {
  2157. if ($disclosure->getDisclosureTarget() !== null) {
  2158. $disclosure->getDisclosureTarget()->setArchiveStatusUpdated($archiveStatusUpdated);
  2159. }
  2160. }
  2161. return $this;
  2162. }
  2163. /**
  2164. * Get archiveStatusUpdated
  2165. *
  2166. * @return DateTime
  2167. */
  2168. public function getArchiveStatusUpdated()
  2169. {
  2170. return $this->archive_status_updated;
  2171. }
  2172. /**
  2173. * Set futureDeletionDate
  2174. *
  2175. * @param DateTime $futureDeletionDate
  2176. *
  2177. * @return Project
  2178. */
  2179. public function setFutureDeletionDate($futureDeletionDate)
  2180. {
  2181. $this->future_deletion_date = $futureDeletionDate;
  2182. return $this;
  2183. }
  2184. /**
  2185. * Get futureDeletionDate
  2186. *
  2187. * @return DateTime
  2188. */
  2189. public function getFutureDeletionDate()
  2190. {
  2191. return $this->future_deletion_date;
  2192. }
  2193. /**
  2194. * Set privateSandboxCollection
  2195. *
  2196. * @param Collection|null $privateSandboxCollection
  2197. *
  2198. * @return Project
  2199. */
  2200. public function setPrivateSandboxCollection(?Collection $privateSandboxCollection = null)
  2201. {
  2202. $this->privateSandboxCollection = $privateSandboxCollection;
  2203. return $this;
  2204. }
  2205. /**
  2206. * Get privateSandboxCollection
  2207. *
  2208. * @return Collection
  2209. */
  2210. public function getPrivateSandboxCollection()
  2211. {
  2212. // If no privateSandboxCollection exists, create a new one.
  2213. // We do this here, instead of the constructor, so we only create a new
  2214. // Collection entity if none already exists.
  2215. if ($this->privateSandboxCollection === null) {
  2216. $privateSandboxCollection = new Collection();
  2217. $privateSandboxCollection->setName('Private Sandbox Folders');
  2218. $this->setPrivateSandboxCollection($privateSandboxCollection);
  2219. }
  2220. return $this->privateSandboxCollection;
  2221. }
  2222. /**
  2223. * Returns the PrivateSandboxCollection for this project in a JSTree
  2224. * formatted node tree. Notably, this structure will not include Documents
  2225. * under the top most node that also exist in sub nodes.
  2226. *
  2227. * @param string $replacementRootNodeText
  2228. * @param array $additionalLiAttributes
  2229. *
  2230. * @return array
  2231. */
  2232. public function getPrivateSandboxCollectionAsJsTreeFormattedTree($replacementRootNodeText = null, $additionalLiAttributes = [])
  2233. {
  2234. $node = $this->getPrivateSandboxCollection()->getJsTreeFormattedNode($replacementRootNodeText, false, false, $additionalLiAttributes);
  2235. // set the children sub array, ready for populating
  2236. $node['children'] = [];
  2237. // order the children alphabetically
  2238. $criteria = Criteria::create()
  2239. ->orderBy(['name' => Criteria::ASC])
  2240. ;
  2241. // add all the sub collections with all their children and document children
  2242. foreach ($this->getPrivateSandboxCollection()->getChildren()->matching($criteria) as $childCollection) {
  2243. $node['children'][] = $childCollection->getJsTreeFormattedNode(null, true, true, $additionalLiAttributes);
  2244. }
  2245. // all document children also get a collection id sent through, so we know what collection
  2246. // the document belongs to
  2247. $additionalLiAttributes['data-collection-id'] = $this->getId();
  2248. // loop through all the document children on this main collection
  2249. foreach ($this->getPrivateSandboxCollection()->getDocuments() as $childDocument) {
  2250. // Only if the Document is assigned to one collection inside the Private Sandbox collection (this one)...
  2251. $collectionCount = $childDocument->getCollections()->filter(function (Collection $collection) {
  2252. return $this->getPrivateSandboxCollection()->containsCollectionRecursive($collection);
  2253. })->count();
  2254. // ... do we include it here, else the Document will show twice in Medical Records.
  2255. if ($collectionCount === 1) {
  2256. $node['children'][] = $childDocument->getJsTreeFormattedNode(null, $additionalLiAttributes);
  2257. }
  2258. }
  2259. return $node;
  2260. }
  2261. /**
  2262. * Add batchRequest
  2263. *
  2264. * @param BatchRequest $batchRequest
  2265. *
  2266. * @return Project
  2267. */
  2268. public function addBatchRequest(BatchRequest $batchRequest)
  2269. {
  2270. $this->batchRequests[] = $batchRequest;
  2271. return $this;
  2272. }
  2273. /**
  2274. * Remove batchRequest
  2275. *
  2276. * @param BatchRequest $batchRequest
  2277. */
  2278. public function removeBatchRequest(BatchRequest $batchRequest)
  2279. {
  2280. $this->batchRequests->removeElement($batchRequest);
  2281. }
  2282. /**
  2283. * Get batchRequests
  2284. *
  2285. * @return DoctrineCollection|BatchRequest[]
  2286. */
  2287. public function getBatchRequests()
  2288. {
  2289. return $this->batchRequests;
  2290. }
  2291. /**
  2292. * Retrieves the counts for BatchRequests grouped by
  2293. * their serviceRequest status.
  2294. *
  2295. * @param mixed $uninvoicedOnly
  2296. *
  2297. * @return array
  2298. */
  2299. public function getBatchRequestsCountByServiceRequestStatus($uninvoicedOnly = true)
  2300. {
  2301. return $this->getServiceableCountsByStatus($this->getBatchRequests()->toArray(), $uninvoicedOnly);
  2302. }
  2303. /**
  2304. * Add additionalRequest
  2305. *
  2306. * @param AdditionalRequest $additionalRequest
  2307. *
  2308. * @return Project
  2309. */
  2310. public function addAdditionalRequest(AdditionalRequest $additionalRequest)
  2311. {
  2312. $this->additionalRequests[] = $additionalRequest;
  2313. return $this;
  2314. }
  2315. /**
  2316. * Remove additionalRequest
  2317. *
  2318. * @param AdditionalRequest $additionalRequest
  2319. */
  2320. public function removeAdditionalRequest(AdditionalRequest $additionalRequest)
  2321. {
  2322. $this->additionalRequests->removeElement($additionalRequest);
  2323. }
  2324. /**
  2325. * Get additionalRequests
  2326. *
  2327. * @return DoctrineCollection|AdditionalRequest[]
  2328. */
  2329. public function getAdditionalRequests()
  2330. {
  2331. return $this->additionalRequests;
  2332. }
  2333. /**
  2334. * Retrieves the counts for AdditionalRequests grouped by
  2335. * their serviceRequest status
  2336. *
  2337. * @param mixed $uninvoicedOnly
  2338. *
  2339. * @return array
  2340. */
  2341. public function getAdditionalRequestsCountByServiceRequestStatus($uninvoicedOnly = true)
  2342. {
  2343. return $this->getServiceableCountsByStatus($this->getAdditionalRequests()->toArray(), $uninvoicedOnly);
  2344. }
  2345. /**
  2346. * Add chronologyRequest
  2347. *
  2348. * @param ChronologyRequest $chronologyRequest
  2349. *
  2350. * @return Project
  2351. */
  2352. public function addChronologyRequest(ChronologyRequest $chronologyRequest)
  2353. {
  2354. $this->chronologyRequests[] = $chronologyRequest;
  2355. return $this;
  2356. }
  2357. /**
  2358. * Remove chronologyRequest
  2359. *
  2360. * @param ChronologyRequest $chronologyRequest
  2361. */
  2362. public function removeChronologyRequest(ChronologyRequest $chronologyRequest)
  2363. {
  2364. $this->chronologyRequests->removeElement($chronologyRequest);
  2365. }
  2366. /**
  2367. * Get chronologyRequests
  2368. *
  2369. * @return ArrayCollection|ChronologyRequest[]
  2370. */
  2371. public function getChronologyRequests()
  2372. {
  2373. return $this->chronologyRequests;
  2374. }
  2375. /**
  2376. * Retrieves the counts for ChronologyRequests grouped by
  2377. * their serviceRequest status
  2378. *
  2379. * @param bool $uninvoicedOnly
  2380. *
  2381. * @return array
  2382. */
  2383. public function getChronologyRequestsCountByServiceRequestStatus($uninvoicedOnly = true)
  2384. {
  2385. return $this->getServiceableCountsByStatus($this->getChronologyRequests()->toArray(), $uninvoicedOnly);
  2386. }
  2387. /**
  2388. * Retrieve a sum of ServiceRequest statuses for all Serviceable entities attached to this Project.
  2389. *
  2390. * @param bool $uninvoicedOnly
  2391. *
  2392. * @return array
  2393. */
  2394. public function getTotalServiceRequestCountsByStatus($uninvoicedOnly = true)
  2395. {
  2396. return $this->getServiceableCountsByStatus($this->getServiceables(), $uninvoicedOnly);
  2397. }
  2398. /**
  2399. * @return array
  2400. */
  2401. public function getServiceables(): array
  2402. {
  2403. $serviceables = [];
  2404. // Combine all Serviceable entities on this Project into a single array.
  2405. $serviceables = array_merge(
  2406. $this->getRecordsRequests()->toArray(),
  2407. $this->getBatchRequests()->toArray(),
  2408. $this->getChronologyRequests()->toArray(),
  2409. $this->getAdditionalRequests()->toArray()
  2410. );
  2411. return $serviceables;
  2412. }
  2413. /**
  2414. * Gets the total number of ServiceRequest that are in status On Hold.
  2415. *
  2416. * @return int
  2417. */
  2418. public function getTotalServiceRequestCountsOnHold()
  2419. {
  2420. $totals = $this->getTotalServiceRequestCountsByStatus();
  2421. return isset($totals[ServiceRequest::STATUS_ON_HOLD]) ? $totals[ServiceRequest::STATUS_ON_HOLD]['count'] : 0;
  2422. }
  2423. /**
  2424. * Gets the total number of ServiceRequest that are in status In Progress.
  2425. *
  2426. * @return int
  2427. */
  2428. public function getTotalServiceRequestCountsInProgress()
  2429. {
  2430. $totals = $this->getTotalServiceRequestCountsByStatus();
  2431. $inProgressCount = $totals[ServiceRequest::STATUS_IN_PROGRESS]['count'] ?? 0;
  2432. $instructedCount = $totals[ServiceRequest::STATUS_INSTRUCTED]['count'] ?? 0;
  2433. return $inProgressCount + $instructedCount;
  2434. }
  2435. /**
  2436. * Gets the total number of ServiceRequest that are in status Complete.
  2437. *
  2438. * @return int
  2439. */
  2440. public function getTotalServiceRequestCountsComplete()
  2441. {
  2442. $totals = $this->getTotalServiceRequestCountsByStatus();
  2443. $completeTotal = 0;
  2444. $completeTotal += $totals[ServiceRequest::STATUS_COMPLETE]['count'] ?? 0;
  2445. $completeTotal += $totals[ServiceRequest::STATUS_BACK_TO_CLIENT]['count'] ?? 0;
  2446. $completeTotal += $totals[ServiceRequest::STATUS_RELEASED_TO_CLIENT]['count'] ?? 0;
  2447. return $completeTotal;
  2448. }
  2449. /**
  2450. * Gets the total number of ServiceRequest that are in status Awaiting Records.
  2451. *
  2452. * @return int
  2453. */
  2454. public function getTotalServiceRequestCountsAwaitingRecords()
  2455. {
  2456. $totals = $this->getTotalServiceRequestCountsByStatus();
  2457. /**
  2458. * Combine awaiting records and awaiting records arrival into one total, as they are similar but have slightly
  2459. * different meanings for different service requests.
  2460. * {@see ServiceRequest::getStatusOptionsBatchRequest} and {@see ServiceRequest::getStatusOptionsChronologyRequest}
  2461. */
  2462. $awaitingRecordsTotal = isset($totals[ServiceRequest::STATUS_AWAITING_RECORDS]) ? $totals[ServiceRequest::STATUS_AWAITING_RECORDS]['count'] : 0;
  2463. $awaitingRecordsArrivalTotal = isset($totals[ServiceRequest::STATUS_AWAITING_RECORDS_ARRIVAL]) ? $totals[ServiceRequest::STATUS_AWAITING_RECORDS_ARRIVAL]['count'] : 0;
  2464. $awaitingQuoteApprovalTotal = isset($totals[ServiceRequest::STATUS_AWAITING_QUOTE_APPROVAL]) ? $totals[ServiceRequest::STATUS_AWAITING_QUOTE_APPROVAL]['count'] : 0;
  2465. return $awaitingRecordsTotal + $awaitingRecordsArrivalTotal + $awaitingQuoteApprovalTotal;
  2466. }
  2467. /**
  2468. * Gets the amount of Records Requests grouped by their respective statuses
  2469. *
  2470. * @return array
  2471. */
  2472. public function getRecordsRequestCountsByStatus()
  2473. {
  2474. $serviceables = $this->getRecordsRequests()->toArray();
  2475. return $this->getServiceableCountsByStatus($serviceables);
  2476. }
  2477. /**
  2478. * Gets the amount of Batch Requests grouped by their respective statuses
  2479. *
  2480. * @return array
  2481. */
  2482. public function getBatchRequestCountsByStatus()
  2483. {
  2484. $serviceables = $this->getBatchRequests()->toArray();
  2485. return $this->getServiceableCountsByStatus($serviceables);
  2486. }
  2487. /**
  2488. * Gets the amount of Chronology Requests grouped by their respective statuses
  2489. *
  2490. * @return array
  2491. */
  2492. public function getChronologyRequestCountsByStatus()
  2493. {
  2494. $serviceables = $this->getChronologyRequests()->toArray();
  2495. return $this->getServiceableCountsByStatus($serviceables);
  2496. }
  2497. /**
  2498. * Gets the amount of Additional Requests grouped by their respective statuses
  2499. *
  2500. * @return array
  2501. */
  2502. public function getAdditionalRequestCountsByStatus()
  2503. {
  2504. $serviceables = $this->getAdditionalRequests()->toArray();
  2505. return $this->getServiceableCountsByStatus($serviceables);
  2506. }
  2507. /**
  2508. * Gets the total of all records request status' with status STATUS_COMPLETE and STATUS_BACK_TO_CLIENT
  2509. *
  2510. * @return int
  2511. */
  2512. public function getRecordsRequestCompleteReturnCount()
  2513. {
  2514. $recordsRequestByStatus = $this->getRecordsRequestCountsByStatus();
  2515. $count = 0;
  2516. $arrayKeys = array_keys($recordsRequestByStatus);
  2517. if (in_array(ServiceRequest::STATUS_BACK_TO_CLIENT, $arrayKeys, true)) {
  2518. $count += $recordsRequestByStatus[ServiceRequest::STATUS_BACK_TO_CLIENT]['count'];
  2519. }
  2520. if (in_array(ServiceRequest::STATUS_COMPLETE, $arrayKeys, true)) {
  2521. $count += $recordsRequestByStatus[ServiceRequest::STATUS_COMPLETE]['count'];
  2522. }
  2523. return $count;
  2524. }
  2525. /**
  2526. * Gets the ServiceRequest counts grouped by their respective statuses and types
  2527. *
  2528. * @return array
  2529. */
  2530. public function getServiceRequestStatusCountsByType()
  2531. {
  2532. return [
  2533. 'Records Requests' => $this->getRecordsRequestCountsByStatus(),
  2534. 'Batch Requests' => $this->getBatchRequestCountsByStatus(),
  2535. 'Chronology Requests' => $this->getChronologyRequestCountsByStatus(),
  2536. 'Additional Requests' => $this->getAdditionalRequestCountsByStatus(),
  2537. ];
  2538. }
  2539. // @todo The below functions could probably all be rolled up in to one easy catchall
  2540. // like ::getServiceRequestCountByTypeAndStatus( $type, $status ) but only
  2541. // thought of it too late ┐('~`;)┌
  2542. /**
  2543. * Gets a count of all completed ServiceRequests given a specific Type
  2544. *
  2545. * @param $service_request_type
  2546. *
  2547. * @throws Exception
  2548. *
  2549. * @return int|mixed
  2550. */
  2551. public function getCompleteServiceRequestCountsByType($service_request_type)
  2552. {
  2553. switch ($service_request_type) {
  2554. case ServiceRequest::TYPE_RECORDS_REQUEST:
  2555. $serviceables = $this->getRecordsRequestsCountByServiceRequestStatus(false);
  2556. break;
  2557. case ServiceRequest::TYPE_BATCH_REQUEST:
  2558. $serviceables = $this->getBatchRequestsCountByServiceRequestStatus(false);
  2559. break;
  2560. case ServiceRequest::TYPE_CHRONOLOGY_REQUEST:
  2561. $serviceables = $this->getChronologyRequestsCountByServiceRequestStatus(false);
  2562. break;
  2563. case ServiceRequest::TYPE_ADDITIONAL_REQUEST:
  2564. $serviceables = $this->getAdditionalRequestsCountByServiceRequestStatus(false);
  2565. break;
  2566. default:
  2567. throw new Exception('Invalid Service Request Type.');
  2568. }
  2569. $complete = isset($serviceables[ServiceRequest::STATUS_COMPLETE]) ? $serviceables[ServiceRequest::STATUS_COMPLETE]['count'] : 0;
  2570. $releasedToClient = isset($serviceables[ServiceRequest::STATUS_RELEASED_TO_CLIENT]) ? $serviceables[ServiceRequest::STATUS_RELEASED_TO_CLIENT]['count'] : 0;
  2571. return $complete + $releasedToClient;
  2572. }
  2573. /**
  2574. * Gets a count of all in progress ServiceRequests given a specific Type
  2575. *
  2576. * @param $service_request_type
  2577. *
  2578. * @throws Exception
  2579. *
  2580. * @return int|mixed
  2581. */
  2582. public function getInProgressServiceRequestCountsByType($service_request_type)
  2583. {
  2584. switch ($service_request_type) {
  2585. case ServiceRequest::TYPE_RECORDS_REQUEST:
  2586. $serviceables = $this->getRecordsRequestsCountByServiceRequestStatus(false);
  2587. break;
  2588. case ServiceRequest::TYPE_BATCH_REQUEST:
  2589. $serviceables = $this->getBatchRequestsCountByServiceRequestStatus(false);
  2590. break;
  2591. case ServiceRequest::TYPE_CHRONOLOGY_REQUEST:
  2592. $serviceables = $this->getChronologyRequestsCountByServiceRequestStatus(false);
  2593. break;
  2594. case ServiceRequest::TYPE_ADDITIONAL_REQUEST:
  2595. $serviceables = $this->getAdditionalRequestsCountByServiceRequestStatus(false);
  2596. break;
  2597. default:
  2598. throw new Exception('Invalid Service Request Type.');
  2599. }
  2600. return isset($serviceables[ServiceRequest::STATUS_IN_PROGRESS]) ? $serviceables[ServiceRequest::STATUS_IN_PROGRESS]['count'] : 0;
  2601. }
  2602. /**
  2603. * Gets a count of all on hold ServiceRequests given a specific Type
  2604. *
  2605. * @param $service_request_type
  2606. *
  2607. * @throws Exception
  2608. *
  2609. * @return int|mixed
  2610. */
  2611. public function getOnHoldServiceRequestCountsByType($service_request_type)
  2612. {
  2613. switch ($service_request_type) {
  2614. case ServiceRequest::TYPE_RECORDS_REQUEST:
  2615. $serviceables = $this->getRecordsRequestsCountByServiceRequestStatus(false);
  2616. break;
  2617. case ServiceRequest::TYPE_BATCH_REQUEST:
  2618. $serviceables = $this->getBatchRequestsCountByServiceRequestStatus(false);
  2619. break;
  2620. case ServiceRequest::TYPE_CHRONOLOGY_REQUEST:
  2621. $serviceables = $this->getChronologyRequestsCountByServiceRequestStatus(false);
  2622. break;
  2623. case ServiceRequest::TYPE_ADDITIONAL_REQUEST:
  2624. $serviceables = $this->getAdditionalRequestsCountByServiceRequestStatus(false);
  2625. break;
  2626. default:
  2627. throw new Exception('Invalid Service Request Type.');
  2628. }
  2629. return isset($serviceables[ServiceRequest::STATUS_ON_HOLD]) ? $serviceables[ServiceRequest::STATUS_ON_HOLD]['count'] : 0;
  2630. }
  2631. /**
  2632. * Gets a count of all ServiceRequests awaiting records given a specific Type
  2633. *
  2634. * @param $service_request_type
  2635. *
  2636. * @throws Exception
  2637. *
  2638. * @return int|mixed
  2639. */
  2640. public function getPendingServiceRequestCountsByType($service_request_type)
  2641. {
  2642. switch ($service_request_type) {
  2643. case ServiceRequest::TYPE_RECORDS_REQUEST:
  2644. $serviceables = $this->getRecordsRequestsCountByServiceRequestStatus(false);
  2645. break;
  2646. case ServiceRequest::TYPE_BATCH_REQUEST:
  2647. $serviceables = $this->getBatchRequestsCountByServiceRequestStatus(false);
  2648. break;
  2649. case ServiceRequest::TYPE_CHRONOLOGY_REQUEST:
  2650. $serviceables = $this->getChronologyRequestsCountByServiceRequestStatus(false);
  2651. break;
  2652. case ServiceRequest::TYPE_ADDITIONAL_REQUEST:
  2653. $serviceables = $this->getAdditionalRequestsCountByServiceRequestStatus(false);
  2654. break;
  2655. default:
  2656. throw new Exception('Invalid Service Request Type.');
  2657. }
  2658. return isset($serviceables[ServiceRequest::STATUS_AWAITING_RECORDS]) ? $serviceables[ServiceRequest::STATUS_AWAITING_RECORDS]['count'] : 0;
  2659. }
  2660. /**
  2661. * Gets a count of all cancelled ServiceRequests given a specific Type
  2662. *
  2663. * @param $service_request_type
  2664. *
  2665. * @throws Exception
  2666. *
  2667. * @return int|mixed
  2668. */
  2669. public function getCancelledServiceRequestCountsByType($service_request_type)
  2670. {
  2671. switch ($service_request_type) {
  2672. case ServiceRequest::TYPE_RECORDS_REQUEST:
  2673. $serviceables = $this->getRecordsRequestsCountByServiceRequestStatus(false);
  2674. break;
  2675. case ServiceRequest::TYPE_BATCH_REQUEST:
  2676. $serviceables = $this->getBatchRequestsCountByServiceRequestStatus(false);
  2677. break;
  2678. case ServiceRequest::TYPE_CHRONOLOGY_REQUEST:
  2679. $serviceables = $this->getChronologyRequestsCountByServiceRequestStatus(false);
  2680. break;
  2681. case ServiceRequest::TYPE_ADDITIONAL_REQUEST:
  2682. $serviceables = $this->getAdditionalRequestsCountByServiceRequestStatus(false);
  2683. break;
  2684. default:
  2685. throw new Exception('Invalid Service Request Type.');
  2686. }
  2687. return isset($serviceables[ServiceRequest::STATUS_CANCELLED]) ? $serviceables[ServiceRequest::STATUS_CANCELLED]['count'] : 0;
  2688. }
  2689. /**
  2690. * Set team
  2691. *
  2692. * @param string $team
  2693. *
  2694. * @return Project
  2695. */
  2696. public function setTeam($team)
  2697. {
  2698. $this->team = $team;
  2699. // Update the associated matter request as well, if it exists, and if the values are different,
  2700. // to avoid a recursive loop.
  2701. if ($this->getMatterRequest() && $this->getMatterRequest()->getTeam() != $this->team) {
  2702. $this->getMatterRequest()->setTeam($this->team);
  2703. }
  2704. return $this;
  2705. }
  2706. /**
  2707. * Get team
  2708. *
  2709. * @return string
  2710. */
  2711. public function getTeam()
  2712. {
  2713. return $this->team;
  2714. }
  2715. /**
  2716. * Set defaultRole
  2717. *
  2718. * @param string $defaultRole
  2719. *
  2720. * @return Project
  2721. */
  2722. public function setDefaultRole($defaultRole)
  2723. {
  2724. $this->default_role = $defaultRole;
  2725. return $this;
  2726. }
  2727. /**
  2728. * Get defaultRole
  2729. *
  2730. * @return string
  2731. */
  2732. public function getDefaultRole()
  2733. {
  2734. return $this->default_role;
  2735. }
  2736. /**
  2737. * Get defaultRoleOptions
  2738. *
  2739. * @return array
  2740. */
  2741. public static function getDefaultRoleOptions()
  2742. {
  2743. return [
  2744. self::DEFAULT_ROLE_EXPERT => 'Expert',
  2745. self::DEFAULT_ROLE_EXPERTVIEWER => 'Expert - View Only',
  2746. self::DEFAULT_ROLE_SCANNER => 'Scanner',
  2747. self::DEFAULT_ROLE_SCANNERDOWNLOAD => 'Scanner - Download Enabled',
  2748. self::DEFAULT_ROLE_PROJECTMANAGER => 'Project Manager',
  2749. ];
  2750. }
  2751. /**
  2752. * Get DefaultRoleLabel
  2753. *
  2754. * @return int
  2755. */
  2756. public function getDefaultRoleLabel()
  2757. {
  2758. $options = self::getDefaultRoleOptions();
  2759. return $options[$this->getDefaultRole()] ?? '';
  2760. }
  2761. /**
  2762. * Get DefaultRoleLabel
  2763. *
  2764. * @return string
  2765. */
  2766. public function getDefaultRoleAsRole()
  2767. {
  2768. if (!$this->getDefaultRole()) {
  2769. return '';
  2770. }
  2771. return 'ROLE_PROJECT_' . $this->getId() . '_' . $this->getDefaultRole();
  2772. }
  2773. /**
  2774. * Get the disabled UserNotification types
  2775. *
  2776. * @return array
  2777. */
  2778. public function getDisabledNotifications()
  2779. {
  2780. return $this->disabled_notifications ?: [];
  2781. }
  2782. /**
  2783. * @param array $disabled_notifications
  2784. *
  2785. * @return Project
  2786. */
  2787. public function setDisabledNotifications($disabled_notifications): Project
  2788. {
  2789. $this->disabled_notifications = $disabled_notifications;
  2790. return $this;
  2791. }
  2792. /**
  2793. * Disable a notification
  2794. *
  2795. * @param $notification_type
  2796. *
  2797. * @return Project
  2798. */
  2799. public function disableNotification($notification_type): Project
  2800. {
  2801. $this->disabled_notifications[] = $notification_type;
  2802. return $this;
  2803. }
  2804. /**
  2805. * Function to determine if the specific UserNotification is disabled for this Entity
  2806. *
  2807. * @param $notification_type
  2808. *
  2809. * @return bool
  2810. */
  2811. public function isNotificationDisabled($notification_type)
  2812. {
  2813. if (!$this->disabled_notifications || count($this->disabled_notifications) == 0) {
  2814. return false;
  2815. }
  2816. return in_array($notification_type, $this->disabled_notifications) ? true : false;
  2817. }
  2818. /**
  2819. * Add sortingSession
  2820. *
  2821. * @param SortingSession $sortingSession
  2822. *
  2823. * @return Project
  2824. */
  2825. public function addSortingSession(SortingSession $sortingSession)
  2826. {
  2827. $this->sortingSessions[] = $sortingSession;
  2828. return $this;
  2829. }
  2830. /**
  2831. * Remove sortingSession
  2832. *
  2833. * @param SortingSession $sortingSession
  2834. */
  2835. public function removeSortingSession(SortingSession $sortingSession)
  2836. {
  2837. $this->sortingSessions->removeElement($sortingSession);
  2838. }
  2839. /**
  2840. * Get sortingSessions
  2841. *
  2842. * @return DoctrineCollection|SortingSession[]
  2843. */
  2844. public function getSortingSessions()
  2845. {
  2846. return $this->sortingSessions;
  2847. }
  2848. /**
  2849. * Get completedSortingSessions
  2850. *
  2851. * @return ArrayCollection|DoctrineCollection|Collection
  2852. */
  2853. public function getCompletedSortingSessions()
  2854. {
  2855. return $this->getSortingSessions()->filter(
  2856. function ($sortingSession) {
  2857. return $sortingSession->hasBeenCompleted();
  2858. }
  2859. );
  2860. }
  2861. /**
  2862. * @return bool
  2863. */
  2864. public function hasIncompleteSortingSessions(): bool
  2865. {
  2866. foreach ($this->getSortingSessions() as $sortingSession) {
  2867. if (!$sortingSession->hasBeenCompleted() && !$sortingSession->isSortStatusDownloaded()) {
  2868. return true;
  2869. }
  2870. }
  2871. return false;
  2872. }
  2873. /**
  2874. * Returns true if there are any incomplete serviceables on the project.
  2875. * This is used to block a project from being archived or deleted when work is still on-going.
  2876. *
  2877. * @return bool
  2878. */
  2879. public function hasIncompleteServiceables(): bool
  2880. {
  2881. foreach ($this->getRecordsRequests() as $recordsRequest) {
  2882. $incompleteStatuses = [
  2883. ServiceRequest::STATUS_IN_PROGRESS,
  2884. ServiceRequest::STATUS_ON_HOLD,
  2885. ];
  2886. if ($recordsRequest->getServiceRequest() && in_array($recordsRequest->getServiceRequest()->getStatus(), $incompleteStatuses)) {
  2887. return true;
  2888. }
  2889. }
  2890. foreach ($this->getBatchRequests() as $batchRequest) {
  2891. $incompleteStatuses = [
  2892. ServiceRequest::STATUS_IN_PROGRESS,
  2893. ServiceRequest::STATUS_AWAITING_RECORDS,
  2894. ServiceRequest::STATUS_ON_HOLD,
  2895. ];
  2896. if ($batchRequest->getServiceRequest() && in_array($batchRequest->getServiceRequest()->getStatus(), $incompleteStatuses)) {
  2897. return true;
  2898. }
  2899. }
  2900. foreach ($this->getChronologyRequests() as $chronologyRequest) {
  2901. $incompleteStatuses = [
  2902. ServiceRequest::STATUS_INSTRUCTED,
  2903. ServiceRequest::STATUS_IN_PROGRESS,
  2904. ServiceRequest::STATUS_ON_HOLD,
  2905. ];
  2906. if ($chronologyRequest->getServiceRequest() && in_array($chronologyRequest->getServiceRequest()->getStatus(), $incompleteStatuses)) {
  2907. return true;
  2908. }
  2909. }
  2910. foreach ($this->getAdditionalRequests() as $additionalRequest) {
  2911. $incompleteStatuses = [
  2912. ServiceRequest::STATUS_IN_PROGRESS,
  2913. ServiceRequest::STATUS_ON_HOLD,
  2914. ];
  2915. if ($additionalRequest->getServiceRequest() && in_array($additionalRequest->getServiceRequest()->getStatus(), $incompleteStatuses)) {
  2916. return true;
  2917. }
  2918. }
  2919. // Finally, we check if there are incomplete sorting sessions.
  2920. return $this->hasIncompleteSortingSessions();
  2921. }
  2922. /**
  2923. * Add matterNote
  2924. *
  2925. * @param MatterNote $matterNote
  2926. *
  2927. * @return Project
  2928. */
  2929. public function addMatterNote(MatterNote $matterNote)
  2930. {
  2931. $this->matterNotes[] = $matterNote;
  2932. $matterNote->setProject($this);
  2933. return $this;
  2934. }
  2935. /**
  2936. * Remove matterNote
  2937. *
  2938. * @param MatterNote $matterNote
  2939. */
  2940. public function removeMatterNote(MatterNote $matterNote)
  2941. {
  2942. $this->matterNotes->removeElement($matterNote);
  2943. }
  2944. /**
  2945. * Get matterNotes
  2946. *
  2947. * @return DoctrineCollection|MatterNote[]
  2948. */
  2949. public function getMatterNotes()
  2950. {
  2951. return $this->matterNotes;
  2952. }
  2953. /**
  2954. * @return array
  2955. */
  2956. public function getNoteCounts(): array
  2957. {
  2958. $noteCounts = [];
  2959. foreach ($this->getMatterNotes() as $note) {
  2960. if (!isset($noteCounts[$note->getType()])) {
  2961. $noteCounts[$note->getType()] = 0;
  2962. }
  2963. $noteCounts[$note->getType()]++;
  2964. }
  2965. return $noteCounts;
  2966. }
  2967. /**
  2968. * Set unsortedRecordsCollection.
  2969. *
  2970. * @param Collection|null $unsortedRecordsCollection
  2971. *
  2972. * @return Project
  2973. */
  2974. public function setUnsortedRecordsCollection(?Collection $unsortedRecordsCollection = null)
  2975. {
  2976. $this->unsortedRecordsCollection = $unsortedRecordsCollection;
  2977. return $this;
  2978. }
  2979. /**
  2980. * Set requirePasswordOnDownload.
  2981. *
  2982. * @param bool $requirePasswordOnDownload
  2983. *
  2984. * @return Project
  2985. */
  2986. public function setRequirePasswordOnDownload($requirePasswordOnDownload)
  2987. {
  2988. $this->require_password_on_download = $requirePasswordOnDownload;
  2989. return $this;
  2990. }
  2991. /**
  2992. * Get unsortedRecordsCollection.
  2993. *
  2994. * @return Collection|null
  2995. */
  2996. public function getUnsortedRecordsCollection()
  2997. {
  2998. return $this->unsortedRecordsCollection;
  2999. }
  3000. /**
  3001. * Get requirePasswordOnDownload.
  3002. *
  3003. * @return bool
  3004. */
  3005. public function getRequirePasswordOnDownload()
  3006. {
  3007. return $this->require_password_on_download;
  3008. }
  3009. /**
  3010. * Set inviteUserMustAuthenticate.
  3011. *
  3012. * @param bool $inviteUserMustAuthenticate
  3013. *
  3014. * @return Project
  3015. */
  3016. public function setInviteUserMustAuthenticate($inviteUserMustAuthenticate)
  3017. {
  3018. $this->inviteUserMustAuthenticate = $inviteUserMustAuthenticate;
  3019. return $this;
  3020. }
  3021. /**
  3022. * Get inviteUserMustAuthenticate.
  3023. *
  3024. * @return bool
  3025. */
  3026. public function getInviteUserMustAuthenticate()
  3027. {
  3028. return $this->inviteUserMustAuthenticate;
  3029. }
  3030. /**
  3031. * Set inviteUserPassword.
  3032. *
  3033. * @param string $inviteUserPassword
  3034. *
  3035. * @return Project
  3036. */
  3037. public function setInviteUserPassword($inviteUserPassword)
  3038. {
  3039. $this->inviteUserPassword = $inviteUserPassword;
  3040. return $this;
  3041. }
  3042. /**
  3043. * Get inviteUserPassword.
  3044. *
  3045. * @return string
  3046. */
  3047. public function getInviteUserPassword()
  3048. {
  3049. return $this->inviteUserPassword;
  3050. }
  3051. /**
  3052. * Set inviteUserContactName.
  3053. *
  3054. * @param string|null $inviteUserContactName
  3055. *
  3056. * @return Project
  3057. */
  3058. public function setInviteUserContactName($inviteUserContactName = null)
  3059. {
  3060. $this->inviteUserContactName = $inviteUserContactName;
  3061. return $this;
  3062. }
  3063. /**
  3064. * Get inviteUserContactName.
  3065. *
  3066. * @return string|null
  3067. */
  3068. public function getInviteUserContactName()
  3069. {
  3070. return $this->inviteUserContactName;
  3071. }
  3072. /**
  3073. * Set inviteUserContactEmail.
  3074. *
  3075. * @param string|null $inviteUserContactEmail
  3076. *
  3077. * @return Project
  3078. */
  3079. public function setInviteUserContactEmail($inviteUserContactEmail = null)
  3080. {
  3081. $this->inviteUserContactEmail = $inviteUserContactEmail;
  3082. return $this;
  3083. }
  3084. /**
  3085. * Get inviteUserContactEmail.
  3086. *
  3087. * @return string|null
  3088. */
  3089. public function getInviteUserContactEmail()
  3090. {
  3091. return $this->inviteUserContactEmail;
  3092. }
  3093. /**
  3094. * Set inviteUserContactPhoneNumber.
  3095. *
  3096. * @param string|null $inviteUserContactPhoneNumber
  3097. *
  3098. * @return Project
  3099. */
  3100. public function setInviteUserContactPhoneNumber($inviteUserContactPhoneNumber = null)
  3101. {
  3102. $this->inviteUserContactPhoneNumber = $inviteUserContactPhoneNumber;
  3103. return $this;
  3104. }
  3105. /**
  3106. * Get inviteUserContactPhoneNumber.
  3107. *
  3108. * @return string|null
  3109. */
  3110. public function getInviteUserContactPhoneNumber()
  3111. {
  3112. return $this->inviteUserContactPhoneNumber;
  3113. }
  3114. /**
  3115. * Tells if the contact type is Email.
  3116. *
  3117. * @return bool
  3118. */
  3119. public function isInviteUserContactTypeEmail()
  3120. {
  3121. return !is_null($this->getInviteUserContactEmail());
  3122. }
  3123. /**
  3124. * Tells if the contact type is Phone.
  3125. *
  3126. * @return bool
  3127. */
  3128. public function isInviteUserContactTypePhone()
  3129. {
  3130. return !is_null($this->getInviteUserContactPhoneNumber());
  3131. }
  3132. /**
  3133. * Set dateOnLetter.
  3134. *
  3135. * @param DateTime|null $dateOnLetter
  3136. *
  3137. * @return Project
  3138. */
  3139. public function setDateOnLetter($dateOnLetter = null)
  3140. {
  3141. $this->date_on_letter = $dateOnLetter;
  3142. return $this;
  3143. }
  3144. /**
  3145. * Get dateOnLetter.
  3146. *
  3147. * @return DateTime|null
  3148. */
  3149. public function getDateOnLetter()
  3150. {
  3151. return $this->date_on_letter;
  3152. }
  3153. /**
  3154. * Set caseMeritsAnalysis.
  3155. *
  3156. * @param string|null $caseMeritsAnalysis
  3157. *
  3158. * @return Project
  3159. */
  3160. public function setCaseMeritsAnalysis($caseMeritsAnalysis = null)
  3161. {
  3162. $this->case_merits_analysis = $caseMeritsAnalysis;
  3163. return $this;
  3164. }
  3165. /**
  3166. * Get caseMeritsAnalysis.
  3167. *
  3168. * @return string|null
  3169. */
  3170. public function getCaseMeritsAnalysis()
  3171. {
  3172. return $this->case_merits_analysis;
  3173. }
  3174. /**
  3175. * Returns an array of permitted values for the case_merits_analysis field and their
  3176. * associated labels.
  3177. *
  3178. * @return array
  3179. */
  3180. public static function getCaseMeritsAnalysisOptions()
  3181. {
  3182. return [
  3183. self::CASE_MERITS_ANALYSIS_SUPPORTIVE => 'Supportive',
  3184. self::CASE_MERITS_ANALYSIS_UNSUPPORTIVE => 'Unsupportive',
  3185. self::CASE_MERITS_ANALYSIS_INCONCLUSIVE => 'Inconclusive',
  3186. ];
  3187. }
  3188. /**
  3189. * Returns a human-readable version of the case_merits_analysis
  3190. *
  3191. * @return string
  3192. */
  3193. public function getCaseMeritsAnalysisName()
  3194. {
  3195. $options = self::getCaseMeritsAnalysisOptions();
  3196. return
  3197. $options[$this->getCaseMeritsAnalysis()] ?? $this->getCaseMeritsAnalysis();
  3198. }
  3199. /**
  3200. * Set claimantSolicitor.
  3201. *
  3202. * @param string|null $claimantSolicitor
  3203. *
  3204. * @return Project
  3205. */
  3206. public function setClaimantSolicitor($claimantSolicitor = null)
  3207. {
  3208. $this->claimant_solicitor = $claimantSolicitor;
  3209. return $this;
  3210. }
  3211. /**
  3212. * Get claimantSolicitor.
  3213. *
  3214. * @return string|null
  3215. */
  3216. public function getClaimantSolicitor()
  3217. {
  3218. return $this->claimant_solicitor;
  3219. }
  3220. /**
  3221. * Set typeOfLetter.
  3222. *
  3223. * @param string|null $typeOfLetter
  3224. *
  3225. * @return Project
  3226. */
  3227. public function setTypeOfLetter($typeOfLetter = null)
  3228. {
  3229. $this->type_of_letter = $typeOfLetter;
  3230. return $this;
  3231. }
  3232. /**
  3233. * Get typeOfLetter.
  3234. *
  3235. * @return string|null
  3236. */
  3237. public function getTypeOfLetter()
  3238. {
  3239. return $this->type_of_letter;
  3240. }
  3241. /**
  3242. * Returns an array of permitted values for the type_of_letter field and their
  3243. * associated labels.
  3244. *
  3245. * @return array
  3246. */
  3247. public static function getTypeOfLetterOptions()
  3248. {
  3249. return [
  3250. self::TYPE_OF_LETTER_LETTER_OF_CLAIM => 'Letter of claim',
  3251. self::TYPE_OF_LETTER_LETTER_OF_NOTIFICATION => 'Letter of notification',
  3252. self::TYPE_OF_LETTER_SUBJECT_ACCESS_REQUEST => 'Subject access request',
  3253. self::TYPE_OF_LETTER_DISCLOSURE_APPLICATION => 'Disclosure application',
  3254. ];
  3255. }
  3256. /**
  3257. * Returns a human-readable version of the type_of_letter
  3258. *
  3259. * @return string
  3260. */
  3261. public function getTypeOfLetterName()
  3262. {
  3263. $options = self::getTypeOfLetterOptions();
  3264. return
  3265. $options[$this->getTypeOfLetter()] ?? $this->getTypeOfLetter();
  3266. }
  3267. /**
  3268. * Set reviewType.
  3269. *
  3270. * @param string|null $reviewType
  3271. *
  3272. * @return Project
  3273. */
  3274. public function setReviewType($reviewType = null)
  3275. {
  3276. $this->review_type = $reviewType;
  3277. return $this;
  3278. }
  3279. /**
  3280. * Get reviewType.
  3281. *
  3282. * @return string|null
  3283. */
  3284. public function getReviewType()
  3285. {
  3286. return $this->review_type;
  3287. }
  3288. /**
  3289. * Returns an array of permitted values for the review_type field and their
  3290. * associated labels.
  3291. *
  3292. * @return array
  3293. */
  3294. public static function getReviewTypeOptions()
  3295. {
  3296. return [
  3297. self::REVIEW_TYPE_CASE_MERITS_ANALYSIS => 'Case merits analysis',
  3298. self::REVIEW_TYPE_CHRONOLOGY => 'Chronology',
  3299. ];
  3300. }
  3301. /**
  3302. * Returns a human-readable version of the review_type
  3303. *
  3304. * @return string
  3305. */
  3306. public function getReviewTypeName()
  3307. {
  3308. $options = self::getReviewTypeOptions();
  3309. return
  3310. $options[$this->getReviewType()] ?? $this->getReviewType();
  3311. }
  3312. /**
  3313. * Set expertsReportDate.
  3314. *
  3315. * @param DateTime|null $expertsReportDate
  3316. *
  3317. * @return Project
  3318. */
  3319. public function setExpertsReportDate($expertsReportDate = null)
  3320. {
  3321. $this->experts_report_date = $expertsReportDate;
  3322. return $this;
  3323. }
  3324. /**
  3325. * Get expertsReportDate.
  3326. *
  3327. * @return DateTime|null
  3328. */
  3329. public function getExpertsReportDate()
  3330. {
  3331. return $this->experts_report_date;
  3332. }
  3333. /**
  3334. * Set letterOfResponseAndExpertReportDate.
  3335. *
  3336. * @param DateTime|null $letterOfResponseAndExpertReportDate
  3337. *
  3338. * @return Project
  3339. */
  3340. public function setLetterOfResponseAndExpertReportDate($letterOfResponseAndExpertReportDate = null)
  3341. {
  3342. $this->letter_of_response_and_expert_report_date = $letterOfResponseAndExpertReportDate;
  3343. return $this;
  3344. }
  3345. /**
  3346. * Get letterOfResponseAndExpertReportDate.
  3347. *
  3348. * @return DateTime|null
  3349. */
  3350. public function getLetterOfResponseAndExpertReportDate()
  3351. {
  3352. return $this->letter_of_response_and_expert_report_date;
  3353. }
  3354. /**
  3355. * Set letterOfResponsePreparedDate.
  3356. *
  3357. * @param DateTime|null $letterOfResponsePreparedDate
  3358. *
  3359. * @return Project
  3360. */
  3361. public function setLetterOfResponsePreparedDate($letterOfResponsePreparedDate = null)
  3362. {
  3363. $this->letter_of_response_prepared_date = $letterOfResponsePreparedDate;
  3364. return $this;
  3365. }
  3366. /**
  3367. * Get letterOfResponsePreparedDate.
  3368. *
  3369. * @return DateTime|null
  3370. */
  3371. public function getLetterOfResponsePreparedDate()
  3372. {
  3373. return $this->letter_of_response_prepared_date;
  3374. }
  3375. /**
  3376. * Set letterOfResponseSentDate.
  3377. *
  3378. * @param DateTime|null $letterOfResponseSentDate
  3379. *
  3380. * @return Project
  3381. */
  3382. public function setLetterOfResponseSentDate($letterOfResponseSentDate = null)
  3383. {
  3384. $this->letter_of_response_sent_date = $letterOfResponseSentDate;
  3385. return $this;
  3386. }
  3387. /**
  3388. * Get letterOfResponseSentDate.
  3389. *
  3390. * @return DateTime|null
  3391. */
  3392. public function getLetterOfResponseSentDate()
  3393. {
  3394. return $this->letter_of_response_sent_date;
  3395. }
  3396. public static function loadValidatorMetadata(ClassMetadata $metadata)
  3397. {
  3398. $metadata->addConstraint(new Assert\Callback('validate'));
  3399. }
  3400. public function validate(ExecutionContextInterface $context, $payload)
  3401. {
  3402. if ($this->getInviteUserMustAuthenticate()) {
  3403. $password = $this->getinviteUserPassword();
  3404. // If the password has not already been set, validate the plainPassword.
  3405. if (is_null($password)) {
  3406. $plainPassword = $this->getinviteUserPlainPassword();
  3407. $constraints = [
  3408. new Assert\Regex([
  3409. 'pattern' => '/(?=.*[A-Z])(?=.*[a-z])(?=.*[0-9])(?=.*[\d])(?=.*[\W]).{8,}/',
  3410. 'message' => 'Please ensure you use a strong password of at least 8 characters, including at least one each of the following: lowercase, uppercase, number, symbol.',
  3411. ]),
  3412. new Assert\NotBlank([]),
  3413. new Assert\Length([
  3414. 'min' => 8,
  3415. 'max' => 255,
  3416. 'minMessage' => 'Your password must have at least {{ limit }} characters.',
  3417. 'maxMessage' => 'The password is too long.',
  3418. ]),
  3419. ];
  3420. $validator = Validation::createValidator();
  3421. foreach ($constraints as $constraint) {
  3422. $errors = $validator->validate(
  3423. $plainPassword,
  3424. $constraint
  3425. );
  3426. if (0 !== count($errors)) {
  3427. $errorMessage = $errors[0]->getMessage();
  3428. $context->buildViolation($errorMessage)
  3429. ->atPath('inviteUserPlainPassword')
  3430. ->addViolation()
  3431. ;
  3432. }
  3433. }
  3434. }
  3435. if (is_null($this->getInviteUserContactName())) {
  3436. $errorMessage = 'Contact name required.';
  3437. $context->buildViolation($errorMessage)
  3438. ->atPath('inviteUserContactName')
  3439. ->addViolation()
  3440. ;
  3441. }
  3442. if (is_null($this->getInviteUserContactEmail())
  3443. && is_null($this->getInviteUserContactPhoneNumber())
  3444. ) {
  3445. $errorMessage = 'Contact email address or phone number required.';
  3446. $context->buildViolation($errorMessage)
  3447. ->atPath('inviteUserContactEmail')
  3448. ->addViolation()
  3449. ;
  3450. $context->buildViolation($errorMessage)
  3451. ->atPath('inviteUserContactPhoneNumber')
  3452. ->addViolation()
  3453. ;
  3454. }
  3455. }
  3456. }
  3457. /**
  3458. * Set matterRequest.
  3459. *
  3460. * @param MatterRequest|null $matterRequest
  3461. *
  3462. * @return Project
  3463. */
  3464. public function setMatterRequest(?MatterRequest $matterRequest = null)
  3465. {
  3466. $this->matterRequest = $matterRequest;
  3467. return $this;
  3468. }
  3469. /**
  3470. * Get matterRequest.
  3471. *
  3472. * @return MatterRequest|null
  3473. */
  3474. public function getMatterRequest()
  3475. {
  3476. return $this->matterRequest;
  3477. }
  3478. /**
  3479. * Returns a radiology schedule array grouped by study of all related radiology on a project.
  3480. *
  3481. * @return array
  3482. */
  3483. public function getRadiologyScheduleArray()
  3484. {
  3485. $data = [];
  3486. $serieses = $this->getSeries();
  3487. /** @var Series $series */
  3488. foreach ($serieses as $series) {
  3489. // Grab the Study this Series is in
  3490. $study = $series->getStudy();
  3491. if ($study) {
  3492. // Having named keys here isn't really necessary but we might want them later for something
  3493. // If we have Discs, we can fill out the `source` and `number` fields
  3494. $data[$study->getId()] = [
  3495. 'id' => $study->getId(),
  3496. 'matter' => $this->getClientReference(),
  3497. 'patient' => $study->getPatient()->getDicomPatientName(),
  3498. 'date' => $study->getStudyDate(),
  3499. 'description' => $study->getStudyDescription(),
  3500. 'centre' => $study->getStudyInstituteName(),
  3501. 'discs' => $study->getDiscs(),
  3502. 'longDescription' => $study->__toString(),
  3503. ];
  3504. }
  3505. }
  3506. usort($data, function ($a, $b) {
  3507. return strcmp($a['longDescription'], $b['longDescription']);
  3508. });
  3509. return $data;
  3510. }
  3511. /**
  3512. * Add matterCommunication.
  3513. *
  3514. * @param MatterCommunication $matterCommunication
  3515. *
  3516. * @return Project
  3517. */
  3518. public function addMatterCommunication(MatterCommunication $matterCommunication)
  3519. {
  3520. $this->matterCommunications[] = $matterCommunication;
  3521. return $this;
  3522. }
  3523. /**
  3524. * Remove matterCommunication.
  3525. *
  3526. * @param MatterCommunication $matterCommunication
  3527. *
  3528. * @return bool TRUE if this collection contained the specified element, FALSE otherwise.
  3529. */
  3530. public function removeMatterCommunication(MatterCommunication $matterCommunication)
  3531. {
  3532. return $this->matterCommunications->removeElement($matterCommunication);
  3533. }
  3534. /**
  3535. * Get matterCommunications.
  3536. *
  3537. * @return DoctrineCollection|MatterCommunication[]
  3538. */
  3539. public function getMatterCommunications()
  3540. {
  3541. return $this->matterCommunications;
  3542. }
  3543. /**
  3544. * Set deleteStatus
  3545. *
  3546. * @param int $deleteStatus
  3547. *
  3548. * @return Project
  3549. */
  3550. public function setDeleteStatus(?int $deleteStatus = null)
  3551. {
  3552. if ($this->deleteStatus !== $deleteStatus) {
  3553. $this->setDeleteStatusUpdated(new DateTime());
  3554. }
  3555. $this->deleteStatus = $deleteStatus;
  3556. return $this;
  3557. }
  3558. /**
  3559. * Get deleteStatus
  3560. *
  3561. * @return int
  3562. */
  3563. public function getDeleteStatus()
  3564. {
  3565. return $this->deleteStatus;
  3566. }
  3567. /**
  3568. * Return true if deletestatus is equal to the constants below
  3569. *
  3570. * @return bool
  3571. */
  3572. public function hasDeleteStatus()
  3573. {
  3574. $statuses = [
  3575. self::DELETE_STATUS_PENDING,
  3576. self::DELETE_STATUS_REMINDER_SENT,
  3577. self::DELETE_STATUS_PROCESSING,
  3578. self::DELETE_STATUS_COMPLETE,
  3579. ];
  3580. return in_array($this->getDeleteStatus(), $statuses);
  3581. }
  3582. /**
  3583. * Set deleteStatusUpdated
  3584. *
  3585. * @param DateTime $deleteStatusUpdated
  3586. *
  3587. * @return Project
  3588. */
  3589. public function setDeleteStatusUpdated(?DateTime $deleteStatusUpdated = null)
  3590. {
  3591. $this->deleteStatusUpdated = $deleteStatusUpdated;
  3592. return $this;
  3593. }
  3594. /**
  3595. * Get deleteStatusUpdated
  3596. *
  3597. * @return DateTime
  3598. */
  3599. public function getDeleteStatusUpdated()
  3600. {
  3601. return $this->deleteStatusUpdated;
  3602. }
  3603. /**
  3604. * Get archiveStatus as Label
  3605. *
  3606. * @return string
  3607. */
  3608. public function getArchiveStatusLabel()
  3609. {
  3610. $archiveStatusOptions = array_flip(static::getConstantsWithLabelsAsChoices('ARCHIVE_STATUS'));
  3611. return $archiveStatusOptions[$this->getArchiveStatus()] ?? '';
  3612. }
  3613. /**
  3614. * @return array
  3615. */
  3616. public static function getArchiveStatusChoices()
  3617. {
  3618. return static::getConstantsWithLabelsAsChoices('ARCHIVE_STATUS');
  3619. }
  3620. /**
  3621. * @return array
  3622. */
  3623. public static function getDeleteStatusChoices()
  3624. {
  3625. return static::getConstantsWithLabelsAsChoices('DELETE_STATUS');
  3626. }
  3627. /**
  3628. * Return true if matter is in the process of being deleted/archived, or is deleted or archived
  3629. *
  3630. * @return bool
  3631. */
  3632. public function isCloseInProgressOrComplete()
  3633. {
  3634. $archiveStatuses = [
  3635. self::ARCHIVE_STATUS_PENDING,
  3636. self::ARCHIVE_STATUS_PROCESSING,
  3637. self::ARCHIVE_STATUS_UNARCHIVE_PROCESSING,
  3638. self::ARCHIVE_STATUS_COMPLETE,
  3639. ];
  3640. $deleteStatuses = [
  3641. self::DELETE_STATUS_PENDING,
  3642. self::DELETE_STATUS_REMINDER_SENT,
  3643. self::DELETE_STATUS_PROCESSING,
  3644. self::DELETE_STATUS_COMPLETE,
  3645. self::DELETE_STATUS_DELETE_FAILED,
  3646. self::DELETE_STATUS_ANONYMISE_FAILED,
  3647. ];
  3648. return in_array($this->getArchiveStatus(), $archiveStatuses, true) || in_array($this->getDeleteStatus(), $deleteStatuses, true);
  3649. }
  3650. /**
  3651. * Return true if project status is active
  3652. *
  3653. * @return bool
  3654. */
  3655. public function isStatusActive()
  3656. {
  3657. return $this->getStatus() === self::STATUS_ACTIVE;
  3658. }
  3659. /**
  3660. * Return true if project archive status is pending
  3661. *
  3662. * @return bool
  3663. */
  3664. public function isArchiveStatusPending()
  3665. {
  3666. return $this->getArchiveStatus() === self::ARCHIVE_STATUS_PENDING;
  3667. }
  3668. /**
  3669. * Return true if project archive status is processing
  3670. *
  3671. * @return bool
  3672. */
  3673. public function isArchiveStatusProcessing()
  3674. {
  3675. return $this->getArchiveStatus() === self::ARCHIVE_STATUS_PROCESSING;
  3676. }
  3677. /**
  3678. * Return true if project archive status is complete
  3679. *
  3680. * @return bool
  3681. */
  3682. public function isArchiveStatusComplete()
  3683. {
  3684. return $this->getArchiveStatus() === self::ARCHIVE_STATUS_COMPLETE;
  3685. }
  3686. /**
  3687. * Return true if project archive status is unarchive in process
  3688. *
  3689. * @return bool
  3690. */
  3691. public function isArchiveStatusUnarchiveProcessing()
  3692. {
  3693. return $this->getArchiveStatus() === self::ARCHIVE_STATUS_UNARCHIVE_PROCESSING;
  3694. }
  3695. /**
  3696. * Return true if matter is in the process of being deleted/archived
  3697. *
  3698. * @return bool
  3699. */
  3700. public function isQueuedForArchiveOrDeletion(): bool
  3701. {
  3702. $archiveStatuses = [
  3703. self::ARCHIVE_STATUS_PENDING,
  3704. self::ARCHIVE_STATUS_PROCESSING,
  3705. self::ARCHIVE_STATUS_UNARCHIVE_PROCESSING,
  3706. ];
  3707. $deleteStatuses = [
  3708. self::DELETE_STATUS_PENDING,
  3709. self::DELETE_STATUS_REMINDER_SENT,
  3710. self::DELETE_STATUS_PROCESSING,
  3711. ];
  3712. return in_array($this->getArchiveStatus(), $archiveStatuses, true) || in_array($this->getDeleteStatus(), $deleteStatuses, true);
  3713. }
  3714. /**
  3715. * Return true if archive status is equal to the constants below
  3716. *
  3717. * @return bool
  3718. */
  3719. public function hasArchiveStatus(): bool
  3720. {
  3721. $statuses = [
  3722. self::ARCHIVE_STATUS_PENDING,
  3723. self::ARCHIVE_STATUS_PROCESSING,
  3724. self::ARCHIVE_STATUS_COMPLETE,
  3725. self::ARCHIVE_STATUS_UNARCHIVE_PROCESSING,
  3726. ];
  3727. return in_array($this->getArchiveStatus(), $statuses);
  3728. }
  3729. /**
  3730. * Get deleteStatus as Label
  3731. *
  3732. * @return string
  3733. */
  3734. public function getDeleteStatusLabel()
  3735. {
  3736. $deleteStatusOptions = array_flip(static::getConstantsWithLabelsAsChoices('DELETE_STATUS'));
  3737. return $deleteStatusOptions[$this->getDeleteStatus()] ?? '';
  3738. }
  3739. /**
  3740. * Return true if project delete status is pending
  3741. *
  3742. * @return bool
  3743. */
  3744. public function isDeleteStatusPending()
  3745. {
  3746. return $this->getDeleteStatus() === self::DELETE_STATUS_PENDING;
  3747. }
  3748. /**
  3749. * Return true if project delete status is pending immediate deletion.
  3750. *
  3751. * @return bool
  3752. */
  3753. public function isDeleteStatusPendingImmediate()
  3754. {
  3755. return $this->getDeleteStatus() === self::DELETE_STATUS_PENDING_IMMEDIATE;
  3756. }
  3757. /**
  3758. * Return true if project delete status is reminder sent
  3759. *
  3760. * @return bool
  3761. */
  3762. public function isDeleteStatusReminderSent()
  3763. {
  3764. return $this->getDeleteStatus() === self::DELETE_STATUS_REMINDER_SENT;
  3765. }
  3766. /**
  3767. * Return true if project delete status is processing
  3768. *
  3769. * @return bool
  3770. */
  3771. public function isDeleteStatusProcessing()
  3772. {
  3773. return $this->getDeleteStatus() === self::DELETE_STATUS_PROCESSING;
  3774. }
  3775. /**
  3776. * Return true if project delete status is complete
  3777. *
  3778. * @return bool
  3779. */
  3780. public function isDeleteStatusComplete()
  3781. {
  3782. return $this->getDeleteStatus() === self::DELETE_STATUS_COMPLETE;
  3783. }
  3784. /**
  3785. * Return true if project delete status is failed
  3786. *
  3787. * @return bool
  3788. */
  3789. public function isDeleteStatusFailed()
  3790. {
  3791. return $this->getDeleteStatus() === self::DELETE_STATUS_DELETE_FAILED;
  3792. }
  3793. /**
  3794. * Return true if the Project can be deleted.
  3795. *
  3796. * @return bool
  3797. */
  3798. public function canBeDeleted(): bool
  3799. {
  3800. return $this->isDeleteStatusReminderSent() || $this->isDeleteStatusProcessing();
  3801. }
  3802. /**
  3803. * Returns true if the project is queued for deletion.
  3804. *
  3805. * @return bool
  3806. */
  3807. public function isQueuedForDeletion(): bool
  3808. {
  3809. return $this->isDeleteStatusPending() || $this->isDeleteStatusReminderSent() || $this->isDeleteStatusPendingImmediate();
  3810. }
  3811. /**
  3812. * Return true if matter is in the process of being deleted/archived, and is not in the queue to be closed
  3813. *
  3814. * @return bool
  3815. */
  3816. public function isCloseInProgress()
  3817. {
  3818. $archiveStatuses = [
  3819. self::ARCHIVE_STATUS_PROCESSING,
  3820. self::ARCHIVE_STATUS_UNARCHIVE_PROCESSING,
  3821. ];
  3822. $deleteStatuses = [
  3823. self::DELETE_STATUS_PROCESSING,
  3824. ];
  3825. return in_array($this->getArchiveStatus(), $archiveStatuses, true) || in_array($this->getDeleteStatus(), $deleteStatuses, true);
  3826. }
  3827. /**
  3828. * Return true if matter deletion is complete
  3829. *
  3830. * @return bool
  3831. */
  3832. public function isDeleteComplete()
  3833. {
  3834. return $this->getDeleteStatus() === self::DELETE_STATUS_COMPLETE;
  3835. }
  3836. /**
  3837. * Returns the User that requested the deletion.
  3838. *
  3839. * @return User
  3840. */
  3841. public function getDeletionRequestedBy(): ?User
  3842. {
  3843. return $this->getProjectClosure() ? $this->getProjectClosure()->getClosedBy() : null;
  3844. }
  3845. /**
  3846. * getAllowExpertViewUnsortedRecords
  3847. *
  3848. * @return bool
  3849. */
  3850. public function getAllowExpertViewUnsortedRecords(): ?bool
  3851. {
  3852. return $this->allowExpertViewUnsortedRecords;
  3853. }
  3854. /**
  3855. * setAllowExpertViewUnsortedRecords
  3856. *
  3857. * @param bool $allowExpertViewUnsortedRecords
  3858. *
  3859. * @return self
  3860. */
  3861. public function setAllowExpertViewUnsortedRecords(?bool $allowExpertViewUnsortedRecords = null): self
  3862. {
  3863. $this->allowExpertViewUnsortedRecords = $allowExpertViewUnsortedRecords;
  3864. return $this;
  3865. }
  3866. /**
  3867. * Get the value of dateDeleted
  3868. *
  3869. * @return DateTime
  3870. */
  3871. public function getDateDeleted()
  3872. {
  3873. return $this->dateDeleted;
  3874. }
  3875. /**
  3876. * Set the value of dateDeleted
  3877. *
  3878. * @param DateTime|null $dateDeleted
  3879. *
  3880. * @return self
  3881. */
  3882. public function setDateDeleted(?DateTime $dateDeleted)
  3883. {
  3884. $this->dateDeleted = $dateDeleted;
  3885. return $this;
  3886. }
  3887. /**
  3888. * Get the value of projectDeletionReport
  3889. */
  3890. public function getProjectDeletionReport()
  3891. {
  3892. return $this->projectDeletionReport;
  3893. }
  3894. /**
  3895. * Set the value of projectDeletionReport
  3896. *
  3897. * @param ProjectDeletionReport|null $projectDeletionReport
  3898. *
  3899. * @return self
  3900. */
  3901. public function setProjectDeletionReport(?ProjectDeletionReport $projectDeletionReport)
  3902. {
  3903. $this->projectDeletionReport = $projectDeletionReport;
  3904. return $this;
  3905. }
  3906. /**
  3907. * Transforms matter Request entity into a usable array structure
  3908. *
  3909. * @return array
  3910. */
  3911. public function getDeletionSummaryArray(): array
  3912. {
  3913. $deletionReport = $this->getProjectDeletionReport();
  3914. if ($deletionReport === null) {
  3915. throw new Exception('Project deletion report has not been stored.');
  3916. }
  3917. return [
  3918. 'project' => $this,
  3919. 'patientDob' => $deletionReport->getPatientDateOfBirth(),
  3920. 'userWhoCompletedClosureWizard' => $this->getDeletionRequestedBy() ? $this->getDeletionRequestedBy()->getFullName() : '',
  3921. 'dateDeletionCompleted' => $deletionReport->getCreated(),
  3922. 'documents' => $deletionReport->getDocuments(),
  3923. ];
  3924. }
  3925. /**
  3926. * Sets the project delete status to failed.
  3927. *
  3928. * @return self
  3929. */
  3930. public function setDeleteStatusFailed(): self
  3931. {
  3932. $this->setDeleteStatus(self::DELETE_STATUS_DELETE_FAILED);
  3933. return $this;
  3934. }
  3935. /**
  3936. * Sets the project delete status to anonymise failed.
  3937. *
  3938. * @return self
  3939. */
  3940. public function setDeleteStatusAnonymiseFailed(): self
  3941. {
  3942. $this->setDeleteStatus(self::DELETE_STATUS_ANONYMISE_FAILED);
  3943. return $this;
  3944. }
  3945. /**
  3946. * Sets the project delete status to complete.
  3947. *
  3948. * @return self
  3949. */
  3950. public function setDeleteStatusComplete(): self
  3951. {
  3952. $this->setDeleteStatus(self::DELETE_STATUS_COMPLETE);
  3953. return $this;
  3954. }
  3955. /**
  3956. * Sets the project delete status to complete.
  3957. *
  3958. * @return self
  3959. */
  3960. public function setDeleteStatusProcessing(): self
  3961. {
  3962. $this->setDeleteStatus(self::DELETE_STATUS_PROCESSING);
  3963. return $this;
  3964. }
  3965. /**
  3966. * @return ProjectClosure|null
  3967. */
  3968. public function getProjectClosure(): ?ProjectClosure
  3969. {
  3970. return $this->projectClosure;
  3971. }
  3972. /**
  3973. * @param ProjectClosure|null $projectClosure
  3974. *
  3975. * @return self
  3976. */
  3977. public function setProjectClosure(?ProjectClosure $projectClosure): self
  3978. {
  3979. // unset the owning side of the relation if necessary
  3980. if ($projectClosure === null && $this->projectClosure !== null) {
  3981. $this->projectClosure->setProject(null);
  3982. }
  3983. // set the owning side of the relation if necessary
  3984. if ($projectClosure !== null && $projectClosure->getProject() !== $this) {
  3985. $projectClosure->setProject($this);
  3986. }
  3987. $this->projectClosure = $projectClosure;
  3988. return $this;
  3989. }
  3990. /**
  3991. * Returns all the root collections for a project. These are the root folders on the MedicalRecords page.
  3992. *
  3993. * @return Collection[]
  3994. */
  3995. public function getRootCollections(): array
  3996. {
  3997. $rootCollections = [];
  3998. if ($this->getMedicalRecordsCollection()) {
  3999. $rootCollections[] = $this->getMedicalRecordsCollection();
  4000. }
  4001. if ($this->getPrivateCollection()) {
  4002. $rootCollections[] = $this->getPrivateCollection();
  4003. }
  4004. if ($this->getPrivateSandboxCollection()) {
  4005. $rootCollections[] = $this->getPrivateSandboxCollection();
  4006. }
  4007. if ($this->getUnsortedRecordsCollection()) {
  4008. $rootCollections[] = $this->getUnsortedRecordsCollection();
  4009. }
  4010. return $rootCollections;
  4011. }
  4012. /**
  4013. * Return true if deleteStatus is PROCESSING or COMPLETE
  4014. *
  4015. * @return bool
  4016. */
  4017. public function isDeleteProcessingOrComplete()
  4018. {
  4019. $statuses = [
  4020. self::DELETE_STATUS_PROCESSING,
  4021. self::DELETE_STATUS_COMPLETE,
  4022. ];
  4023. return in_array($this->getDeleteStatus(), $statuses);
  4024. }
  4025. /**
  4026. * @Groups({"project_closure:read"})
  4027. *
  4028. * @return bool
  4029. */
  4030. public function getClosureQuestionsOptional(): bool
  4031. {
  4032. return $this->getAccount()->getMatterClosureQuestionsOptional();
  4033. }
  4034. /**
  4035. * @return string|null
  4036. */
  4037. public function getClosureStatusLabel(): ?string
  4038. {
  4039. if ($this->getArchiveStatus()) {
  4040. return 'Archived';
  4041. }
  4042. if ($this->getDeleteStatus()) {
  4043. return 'Deleted';
  4044. }
  4045. return null;
  4046. }
  4047. /**
  4048. * @return string|null
  4049. */
  4050. public function getFirmRecordsReviewStatus(): ?string
  4051. {
  4052. return $this->firmRecordsReviewStatus;
  4053. }
  4054. /**
  4055. * @param string|null $firmRecordsReviewStatus
  4056. *
  4057. * @return self
  4058. */
  4059. public function setFirmRecordsReviewStatus(?string $firmRecordsReviewStatus): self
  4060. {
  4061. if ($this->firmRecordsReviewStatus !== $firmRecordsReviewStatus) {
  4062. $this->setFirmRecordsReviewUpdated(new DateTime());
  4063. }
  4064. $this->firmRecordsReviewStatus = $firmRecordsReviewStatus;
  4065. return $this;
  4066. }
  4067. /**
  4068. * @return array
  4069. */
  4070. public static function getFirmRecordsReviewStatusOptions(): array
  4071. {
  4072. return static::getConstantsWithLabelsAsChoices('FIRM_RECORDS_REVIEW_STATUS');
  4073. }
  4074. /**
  4075. * @return string
  4076. */
  4077. public function getFirmRecordsReviewStatusLabel(): string
  4078. {
  4079. $options = array_flip($this->getFirmRecordsReviewStatusOptions());
  4080. return $options[$this->firmRecordsReviewStatus] ?? '';
  4081. }
  4082. /**
  4083. * @return bool
  4084. */
  4085. public function showFirmRecordsReviewAdditionalInstruction(): bool
  4086. {
  4087. $statuses = [
  4088. self::FIRM_RECORDS_REVIEW_STATUS_AWAITING_RECORDS,
  4089. self::FIRM_RECORDS_REVIEW_STATUS_UPLOADED,
  4090. ];
  4091. return in_array($this->getFirmRecordsReviewStatus(), $statuses);
  4092. }
  4093. /**
  4094. * @return DateTimeInterface|null
  4095. */
  4096. public function getFirmRecordsReviewUpdated(): ?DateTimeInterface
  4097. {
  4098. return $this->firmRecordsReviewUpdated;
  4099. }
  4100. /**
  4101. * @param DateTimeInterface|null $firmRecordsReviewUpdated
  4102. *
  4103. * @return self
  4104. */
  4105. public function setFirmRecordsReviewUpdated(?DateTimeInterface $firmRecordsReviewUpdated): self
  4106. {
  4107. $this->firmRecordsReviewUpdated = $firmRecordsReviewUpdated;
  4108. return $this;
  4109. }
  4110. /**
  4111. * @return string|null
  4112. */
  4113. public function getClinicalSummaryUnsortedStatus(): ?string
  4114. {
  4115. return $this->clinicalSummaryUnsortedStatus;
  4116. }
  4117. /**
  4118. * @param string|null $clinicalSummaryUnsortedStatus
  4119. *
  4120. * @return self
  4121. */
  4122. public function setClinicalSummaryUnsortedStatus(?string $clinicalSummaryUnsortedStatus): self
  4123. {
  4124. if ($this->clinicalSummaryUnsortedStatus !== $clinicalSummaryUnsortedStatus) {
  4125. $this->setClinicalSummaryUnsortedUpdated(new DateTime());
  4126. }
  4127. $this->clinicalSummaryUnsortedStatus = $clinicalSummaryUnsortedStatus;
  4128. return $this;
  4129. }
  4130. /**
  4131. * @return array
  4132. */
  4133. public static function getClinicalSummaryUnsortedStatusOptions(): array
  4134. {
  4135. return static::getConstantsWithLabelsAsChoices('CLINICAL_SUMMARY_UNSORTED_STATUS');
  4136. }
  4137. /**
  4138. * @return string
  4139. */
  4140. public function getClinicalSummaryUnsortedStatusLabel(): string
  4141. {
  4142. $options = array_flip($this->getClinicalSummaryUnsortedStatusOptions());
  4143. return $options[$this->clinicalSummaryUnsortedStatus] ?? '';
  4144. }
  4145. /**
  4146. * @return DateTimeInterface|null
  4147. */
  4148. public function getClinicalSummaryUnsortedUpdated(): ?DateTimeInterface
  4149. {
  4150. return $this->clinicalSummaryUnsortedUpdated;
  4151. }
  4152. /**
  4153. * @param DateTimeInterface|null $clinicalSummaryUnsortedUpdated
  4154. *
  4155. * @return self
  4156. */
  4157. public function setClinicalSummaryUnsortedUpdated(?DateTimeInterface $clinicalSummaryUnsortedUpdated): self
  4158. {
  4159. $this->clinicalSummaryUnsortedUpdated = $clinicalSummaryUnsortedUpdated;
  4160. return $this;
  4161. }
  4162. /**
  4163. * @return bool
  4164. */
  4165. public function showClinicalSummaryUnsortedAdditionalInstruction(): bool
  4166. {
  4167. $statuses = [
  4168. self::CLINICAL_SUMMARY_UNSORTED_STATUS_AWAITING_CONCLUSION,
  4169. self::CLINICAL_SUMMARY_UNSORTED_STATUS_INCONCLUSIVE,
  4170. ];
  4171. return in_array($this->getClinicalSummaryUnsortedStatus(), $statuses);
  4172. }
  4173. /**
  4174. * @param Instance $instance
  4175. *
  4176. * @return $this
  4177. */
  4178. public function addInstance(Instance $instance): Project
  4179. {
  4180. if (!$this->instances->contains($instance)) {
  4181. $this->instances[] = $instance;
  4182. }
  4183. return $this;
  4184. }
  4185. /**
  4186. * @param Instance $instance
  4187. *
  4188. * @return $this
  4189. */
  4190. public function removeInstance(Instance $instance): Project
  4191. {
  4192. $this->instances->removeElement($instance);
  4193. return $this;
  4194. }
  4195. /**
  4196. * @return DoctrineCollection<int, InterpartyDisclosure>
  4197. */
  4198. public function getInterpartyDisclosures(): DoctrineCollection
  4199. {
  4200. return $this->interpartyDisclosures;
  4201. }
  4202. /**
  4203. * This function name is no longer very descriptive as we include drafts that
  4204. * were saved intentionally as drafts for review.
  4205. *
  4206. * @return DoctrineCollection<int, InterpartyDisclosure>
  4207. */
  4208. public function getNonDraftInterpartyDisclosures(): DoctrineCollection
  4209. {
  4210. return $this->interpartyDisclosures->filter(function (InterpartyDisclosure $disclosure) {
  4211. return ($disclosure->isStatusDraft() === false || $disclosure->getSavedAsDraft() === true) && $disclosure->isCurrentHeadOfChain() === true;
  4212. });
  4213. }
  4214. /**
  4215. * Returns a unique array of matter numbers that have already been used as recipient firm
  4216. * matter numbers for disclosures on this project.
  4217. *
  4218. * @param ?InterpartyDisclosure $excludeDisclosure - Optionally exclude a specific disclosure from the list.
  4219. * @param bool $excludePreviousVersions
  4220. *
  4221. * @return array
  4222. */
  4223. public function getInterpartyDisclosureRecipientMatterNumbers(?InterpartyDisclosure $excludeDisclosure = null, bool $excludePreviousVersions = false): array
  4224. {
  4225. $matterNumbers = [];
  4226. foreach ($this->getInterpartyDisclosures() as $disclosure) {
  4227. if (
  4228. $excludeDisclosure === $disclosure
  4229. || ($excludePreviousVersions === true && $disclosure->isDisclosurePreviousVersionOf($excludeDisclosure))
  4230. || $disclosure->isStatusDraft()
  4231. || $disclosure->isStatusRevoked()
  4232. || $disclosure->isStatusFailed()
  4233. ) {
  4234. continue;
  4235. }
  4236. foreach ($disclosure->getRecipientFirms() as $recipientFirm) {
  4237. $matterNumbers[] = $recipientFirm->getMatterNumber();
  4238. }
  4239. }
  4240. // Don't call array unique here as it messes with the keys of the array.
  4241. return $matterNumbers;
  4242. }
  4243. /**
  4244. * @return bool
  4245. */
  4246. public function hasActiveInterpartyDisclosures(): bool
  4247. {
  4248. foreach ($this->getInterpartyDisclosures() as $disclosure) {
  4249. if ($disclosure->isStatusActive()) {
  4250. return true;
  4251. }
  4252. }
  4253. return false;
  4254. }
  4255. /**
  4256. * @return bool
  4257. */
  4258. public function hasExpiredInterpartyDisclosures(): bool
  4259. {
  4260. foreach ($this->getInterpartyDisclosures() as $disclosure) {
  4261. if ($disclosure->isStatusExpired()) {
  4262. return true;
  4263. }
  4264. }
  4265. return false;
  4266. }
  4267. /**
  4268. * @param InterpartyDisclosure $interpartyDisclosure
  4269. *
  4270. * @return self
  4271. */
  4272. public function addInterpartyDisclosure(InterpartyDisclosure $interpartyDisclosure): self
  4273. {
  4274. if (!$this->interpartyDisclosures->contains($interpartyDisclosure)) {
  4275. $this->interpartyDisclosures[] = $interpartyDisclosure;
  4276. $interpartyDisclosure->setProject($this);
  4277. }
  4278. return $this;
  4279. }
  4280. /**
  4281. * @param InterpartyDisclosure $interpartyDisclosure
  4282. *
  4283. * @return self
  4284. */
  4285. public function removeInterpartyDisclosure(InterpartyDisclosure $interpartyDisclosure): self
  4286. {
  4287. if ($this->interpartyDisclosures->removeElement($interpartyDisclosure)) {
  4288. // set the owning side to null (unless already changed)
  4289. if ($interpartyDisclosure->getProject() === $this) {
  4290. $interpartyDisclosure->setProject(null);
  4291. }
  4292. }
  4293. return $this;
  4294. }
  4295. /**
  4296. * Return the count of active disclosures relating to the current project.
  4297. *
  4298. * @return int
  4299. */
  4300. public function getActiveDisclosuresCount(): int
  4301. {
  4302. $interpartyDisclosuresArray = $this->getInterpartyDisclosures()->toArray();
  4303. $activeCount = array_reduce(
  4304. $interpartyDisclosuresArray,
  4305. function ($activeTotal, $disclosure) {
  4306. return $activeTotal + $disclosure->isStatusActive();
  4307. },
  4308. 0
  4309. );
  4310. return $activeCount;
  4311. }
  4312. /**
  4313. * @return string|null
  4314. *
  4315. */
  4316. public function getMatterType(): ?string
  4317. {
  4318. return $this->matterType;
  4319. }
  4320. /**
  4321. * @param string|null $matterType
  4322. *
  4323. * @return self
  4324. */
  4325. public function setMatterType(?string $matterType): self
  4326. {
  4327. $this->matterType = $matterType;
  4328. return $this;
  4329. }
  4330. /**
  4331. * @return array
  4332. */
  4333. public static function getMatterTypeOptions(): array
  4334. {
  4335. return self::getConstantsWithLabelsAsChoices('MATTER_TYPE');
  4336. }
  4337. /**
  4338. * @return string
  4339. */
  4340. public function getMatterTypeLabel(): string
  4341. {
  4342. if ($this->getMatterType() === null) {
  4343. return '';
  4344. }
  4345. $options = array_flip(self::getMatterTypeOptions());
  4346. return $options[$this->getMatterType()] ?? '';
  4347. }
  4348. /**
  4349. * @return bool
  4350. */
  4351. public function isClinicalNegligenceMatterType(): bool
  4352. {
  4353. return $this->getMatterType() === self::MATTER_TYPE_CLINICAL_NEGLIGENCE;
  4354. }
  4355. /**
  4356. * Get the value of useModernRadiology
  4357. */
  4358. public function getUseModernRadiology(): ?bool
  4359. {
  4360. return $this->useModernRadiology;
  4361. }
  4362. /**
  4363. * Set the value of useModernRadiology
  4364. *
  4365. * @param bool|null $useModernRadiology
  4366. *
  4367. * @return self
  4368. */
  4369. public function setUseModernRadiology(?bool $useModernRadiology)
  4370. {
  4371. $this->useModernRadiology = $useModernRadiology;
  4372. return $this;
  4373. }
  4374. /**
  4375. * Get the value of modernRadiologyMigrationStatus
  4376. */
  4377. public function getModernRadiologyMigrationStatus(): ?string
  4378. {
  4379. return $this->modernRadiologyMigrationStatus;
  4380. }
  4381. /**
  4382. * Set the value of modernRadiologyMigrationStatus
  4383. *
  4384. * @param mixed $modernRadiologyMigrationStatus
  4385. *
  4386. * @return self
  4387. */
  4388. public function setModernRadiologyMigrationStatus(?string $modernRadiologyMigrationStatus)
  4389. {
  4390. $this->modernRadiologyMigrationStatus = $modernRadiologyMigrationStatus;
  4391. // Once the migration completes, flick the switch that we should now use modern radiology.
  4392. if ($modernRadiologyMigrationStatus === self::MODERN_RADIOLOGY_MIGRATION_STATUS_COMPLETE
  4393. || $modernRadiologyMigrationStatus === self::MODERN_RADIOLOGY_MIGRATION_STATUS_SKIPPED) {
  4394. $this->setUseModernRadiology(true);
  4395. }
  4396. return $this;
  4397. }
  4398. /**
  4399. * @return bool
  4400. */
  4401. public function isModernRadiologyMigrationInProgress(): bool
  4402. {
  4403. return $this->getModernRadiologyMigrationStatus() === self::MODERN_RADIOLOGY_MIGRATION_STATUS_IN_PROGRESS;
  4404. }
  4405. /**
  4406. * @return string|null
  4407. */
  4408. public function getType(): ?string
  4409. {
  4410. return $this->type;
  4411. }
  4412. /**
  4413. * @param string|null $type
  4414. *
  4415. * @return self
  4416. */
  4417. public function setType(?string $type): self
  4418. {
  4419. $this->type = $type;
  4420. return $this;
  4421. }
  4422. /**
  4423. * @return bool
  4424. */
  4425. public function isTypeDisclosure(): bool
  4426. {
  4427. return $this->type === self::TYPE_MATTER_DISCLOSURE;
  4428. }
  4429. /**
  4430. * Returns an array of permitted values for the Matter Type field and their
  4431. * associated labels.
  4432. *
  4433. * @return array
  4434. */
  4435. public static function getTypeOptions()
  4436. {
  4437. $typeOptions = self::getConstantsWithLabelsAsChoices('TYPE_MATTER');
  4438. return $typeOptions;
  4439. }
  4440. /**
  4441. * Returns a human readable version of the type
  4442. *
  4443. * @return string
  4444. */
  4445. public function getTypeLabel()
  4446. {
  4447. return self::getConstantsWithLabels('TYPE_MATTER');
  4448. }
  4449. /**
  4450. * @return bool
  4451. */
  4452. public function hasNoRecordsForDisclosure(): bool
  4453. {
  4454. if ($this->getMedicalRecordsCollection() === null) {
  4455. return false;
  4456. }
  4457. return $this->getMedicalRecordsCollection()->getDocuments()->isEmpty() && $this->getUnsortedRecordsCollection()->getDocuments()->isEmpty();
  4458. }
  4459. /**
  4460. * @return bool
  4461. */
  4462. public function hasNoRadiologyForDisclosure(): bool
  4463. {
  4464. // Get failed discs too for this consideration, as you can disclose failed discs.
  4465. return $this->getFailedDiscs()->isEmpty() && $this->getActiveDiscs()->isEmpty() && $this->getStudies()->isEmpty();
  4466. }
  4467. /**
  4468. * Returns true if the project has no items for disclosure (records and radiology)
  4469. *
  4470. * @return bool
  4471. */
  4472. public function hasNoItemsForDisclosure(): bool
  4473. {
  4474. $hasNoRecords = $this->hasNoRecordsForDisclosure();
  4475. $hasNoRadiology = $this->hasNoRadiologyForDisclosure();
  4476. return $hasNoRecords === true && $hasNoRadiology === true;
  4477. }
  4478. /**
  4479. * Returns true if one of the project's discs does not have the same status as it had pre-migration.
  4480. *
  4481. * @return bool
  4482. */
  4483. public function hasProjectFailedDiscMigration(): bool
  4484. {
  4485. foreach ($this->getDiscs() as $disc) {
  4486. if ($disc->hasDiscFailedMigration()) {
  4487. return true;
  4488. }
  4489. }
  4490. return false;
  4491. }
  4492. /**
  4493. * @return bool|null
  4494. */
  4495. public function getHideFromInvoicing(): ?bool
  4496. {
  4497. return $this->hideFromInvoicing;
  4498. }
  4499. /**
  4500. * @param bool|null $hideFromInvoicing
  4501. *
  4502. * @return self
  4503. */
  4504. public function setHideFromInvoicing(?bool $hideFromInvoicing): self
  4505. {
  4506. $this->hideFromInvoicing = $hideFromInvoicing;
  4507. return $this;
  4508. }
  4509. /**
  4510. * @return DateTimeInterface|null
  4511. */
  4512. public function getLastRenewalDate(): ?DateTimeInterface
  4513. {
  4514. return $this->lastRenewalDate;
  4515. }
  4516. /**
  4517. * @param DateTimeInterface|null $lastRenewalDate
  4518. *
  4519. * @return self
  4520. */
  4521. public function setLastRenewalDate(?DateTimeInterface $lastRenewalDate): self
  4522. {
  4523. $this->lastRenewalDate = $lastRenewalDate;
  4524. return $this;
  4525. }
  4526. /**
  4527. * @return DateTimeInterface|null
  4528. */
  4529. public function getNextRenewalDate(): ?DateTimeInterface
  4530. {
  4531. return $this->nextRenewalDate;
  4532. }
  4533. /**
  4534. * @param DateTimeInterface|null $nextRenewalDate
  4535. *
  4536. * @return self
  4537. */
  4538. public function setNextRenewalDate(?DateTimeInterface $nextRenewalDate): self
  4539. {
  4540. $this->nextRenewalDate = $nextRenewalDate;
  4541. return $this;
  4542. }
  4543. /**
  4544. * @return array|null
  4545. */
  4546. public function getRenewalNotificationSent(): ?array
  4547. {
  4548. return $this->renewalNotificationSent;
  4549. }
  4550. /**
  4551. * @param array|null $renewalNotificationSent
  4552. *
  4553. * @return self
  4554. */
  4555. public function setRenewalNotificationSent(?array $renewalNotificationSent): self
  4556. {
  4557. $this->renewalNotificationSent = $renewalNotificationSent;
  4558. return $this;
  4559. }
  4560. /**
  4561. * @return DoctrineCollection<int, MatterLicenceRenewalLog>
  4562. */
  4563. public function getMatterLicenceRenewalLogs(): DoctrineCollection
  4564. {
  4565. return $this->matterLicenceRenewalLogs;
  4566. }
  4567. /**
  4568. * @param MatterLicenceRenewalLog $matterLicenceRenewalLog
  4569. *
  4570. * @return self
  4571. */
  4572. public function addMatterLicenceRenewalLog(MatterLicenceRenewalLog $matterLicenceRenewalLog): self
  4573. {
  4574. if (!$this->matterLicenceRenewalLogs->contains($matterLicenceRenewalLog)) {
  4575. $this->matterLicenceRenewalLogs[] = $matterLicenceRenewalLog;
  4576. $matterLicenceRenewalLog->setProject($this);
  4577. }
  4578. return $this;
  4579. }
  4580. /**
  4581. * @param MatterLicenceRenewalLog $matterLicenceRenewalLog
  4582. *
  4583. * @return self
  4584. */
  4585. public function removeMatterLicenceRenewalLog(MatterLicenceRenewalLog $matterLicenceRenewalLog): self
  4586. {
  4587. if ($this->matterLicenceRenewalLogs->removeElement($matterLicenceRenewalLog)) {
  4588. // set the owning side to null (unless already changed)
  4589. if ($matterLicenceRenewalLog->getProject() === $this) {
  4590. $matterLicenceRenewalLog->setProject(null);
  4591. }
  4592. }
  4593. return $this;
  4594. }
  4595. /**
  4596. * Get a valid Licence Renewal Term belonging to the Project
  4597. * For a term to be valid the Project's created date must fall between the effective renewal date and effective renewal end date
  4598. *
  4599. * @return LicenceRenewalTerm|null
  4600. */
  4601. public function getLicenceRenewalTerm(): ?LicenceRenewalTerm
  4602. {
  4603. $terms = $this->getAccount()->getLicenceRenewalTerms();
  4604. // if the Account doesn't have any associated terms return
  4605. if (empty($terms)) {
  4606. return null;
  4607. }
  4608. // find only the applicable term for this project
  4609. foreach ($terms as $term) {
  4610. // If we have an artificial created date to slot it into the renewal period, use that instead.
  4611. if ($this->getForcedRenewalCreated()) {
  4612. $validStartCriteria = $this->getForcedRenewalCreated() >= $term->getEffectiveDate();
  4613. $validEndCriteria = $term->getEffectiveEndDate() === null || ($this->getForcedRenewalCreated() <= $term->getEffectiveEndDate());
  4614. } else {
  4615. $validStartCriteria = $this->getCreated() >= $term->getEffectiveDate();
  4616. $validEndCriteria = $term->getEffectiveEndDate() === null || ($this->getCreated() <= $term->getEffectiveEndDate());
  4617. }
  4618. // return the qualifying term, effectiveEndDate of null indicates the last term, thus a recurring term
  4619. if ($validStartCriteria && $validEndCriteria) {
  4620. return $term;
  4621. }
  4622. };
  4623. return null;
  4624. }
  4625. /**
  4626. * @return string|null
  4627. */
  4628. public function getPermanentDeleteStatus(): ?string
  4629. {
  4630. return $this->permanentDeleteStatus;
  4631. }
  4632. /**
  4633. * @param string|null $permanentDeleteStatus
  4634. *
  4635. * @return self
  4636. */
  4637. public function setPermanentDeleteStatus(?string $permanentDeleteStatus): self
  4638. {
  4639. $this->permanentDeleteStatus = $permanentDeleteStatus;
  4640. return $this;
  4641. }
  4642. /**
  4643. * If there is a renewal date, it calculates the difference in days between it and today's date.
  4644. *
  4645. * @return int|null Number of days until renewal, or null if there's no renewal date.
  4646. */
  4647. public function getNumberOfDaysTillRenewal(): ?int
  4648. {
  4649. $nextRenewalDate = $this->getNextRenewalDate();
  4650. if ($nextRenewalDate !== null) {
  4651. $currentDate = (new DateTime())->setTime(0, 0, 0);
  4652. // Calculate the difference in days
  4653. $dueForRenewalInDays = $nextRenewalDate->diff($currentDate, false)->days;
  4654. $dueForRenewalInDays = max(0, $dueForRenewalInDays);
  4655. return $dueForRenewalInDays;
  4656. }
  4657. return null;
  4658. }
  4659. /**
  4660. * @return ClinicalSummary|null
  4661. */
  4662. public function getClinicalSummary(): ?ClinicalSummary
  4663. {
  4664. return $this->clinicalSummary;
  4665. }
  4666. /**
  4667. * @param ClinicalSummary|null $clinicalSummary
  4668. *
  4669. * @return self
  4670. */
  4671. public function setClinicalSummary(?ClinicalSummary $clinicalSummary): self
  4672. {
  4673. $this->clinicalSummary = $clinicalSummary;
  4674. return $this;
  4675. }
  4676. /**
  4677. * Retrieves the counts of an array of Serviceable entities, grouped by their ServiceRequest status.
  4678. *
  4679. * @param array $serviceables
  4680. * @param bool $uninvoicedOnly
  4681. *
  4682. * @return array
  4683. */
  4684. private function getServiceableCountsByStatus(array $serviceables, $uninvoicedOnly = true)
  4685. {
  4686. $serviceableCounts = [];
  4687. // Go through each serviceable entity
  4688. foreach ($serviceables as $serviceable) {
  4689. // Check that it is in fact a Serviceable entity, and that it has a ServiceRequest
  4690. // attached to it.
  4691. if ($serviceable instanceof ServiceableInterface && $serviceable->getServiceRequest()) {
  4692. // If we are only looking for uninvoiced, and this serviceable entity has been billed for,
  4693. // continue to next element of the array.
  4694. if ($uninvoicedOnly && $serviceable->isBilled()) {
  4695. continue;
  4696. }
  4697. // Use the status integer as the key
  4698. $key = $serviceable->getServiceRequest()->getStatus();
  4699. // If the array element does not already exist, setup the defaults for it.
  4700. if (!isset($serviceableCounts[$key])) {
  4701. // Place the count and label as two separate elements of the array
  4702. // so we can easily access them using the status integer key
  4703. $serviceableCounts[$key] = [
  4704. 'label' => $serviceable->getServiceRequest()->getStatusLabel(),
  4705. 'count' => 0,
  4706. ];
  4707. }
  4708. // Increment the count for the status
  4709. $serviceableCounts[$key]['count']++;
  4710. }
  4711. }
  4712. // Sort the elements by key (status)
  4713. ksort($serviceableCounts);
  4714. return $serviceableCounts;
  4715. }
  4716. }