src/Entity/MatterRequest/MatterRequest.php line 134

Open in your IDE?
  1. <?php
  2. namespace MedBrief\MSR\Entity\MatterRequest;
  3. use ApiPlatform\Core\Annotation\ApiResource;
  4. use ApiPlatform\Core\Annotation\ApiSubresource;
  5. use DH\Auditor\Provider\Doctrine\Auditing\Annotation as Audit;
  6. use Doctrine\Common\Collections\ArrayCollection;
  7. use Doctrine\Common\Collections\Collection;
  8. use Doctrine\ORM\EntityNotFoundException;
  9. use Doctrine\ORM\Mapping as ORM;
  10. use Doctrine\Persistence\Proxy;
  11. use Gedmo\Mapping\Annotation as Gedmo;
  12. use MedBrief\MSR\Controller\MatterRequest\CaseTypes;
  13. use MedBrief\MSR\Controller\MatterRequest\ClaimValues;
  14. use MedBrief\MSR\Controller\MatterRequest\CreateMatter;
  15. use MedBrief\MSR\Dto\MatterRequestFullDto;
  16. use MedBrief\MSR\Entity\Account;
  17. use MedBrief\MSR\Entity\MatterRequest\Details\Chronology;
  18. use MedBrief\MSR\Entity\MatterRequest\Details\PostProcessing;
  19. use MedBrief\MSR\Entity\MatterRequest\Details\Review;
  20. use MedBrief\MSR\Entity\MatterRequest\Details\ServiceSelection;
  21. use MedBrief\MSR\Entity\MatterRequest\Details\Sort;
  22. use MedBrief\MSR\Entity\Project;
  23. use MedBrief\MSR\Entity\User;
  24. use MedBrief\MSR\Repository\MatterRequestRepository;
  25. use MedBrief\MSR\Service\ErrorHandling\ApiErrorCodeAwareInterface;
  26. use MedBrief\MSR\Traits\FilterableClassConstantsTrait;
  27. use Symfony\Bridge\Doctrine\Validator\Constraints\UniqueEntity;
  28. use Symfony\Component\Serializer\Annotation\Groups;
  29. use Symfony\Component\Validator\Constraints as Assert;
  30. /**
  31. * @ApiResource(
  32. * collectionOperations={
  33. * "post"={"access_control"="is_granted('CREATE', object)"},
  34. * "matter_request_full_create"={
  35. * "method"="POST",
  36. * "input"=MatterRequestFullDto::class,
  37. * "output"=MatterRequestFullDto::class,
  38. * "path"="/matter_requests/matter_request_full",
  39. * "normalization_context"={"groups"={"matter_request_full:read"}},
  40. * "denormalization_context"={"groups"={"matter_request_full:create"}},
  41. * "validation_groups"={"Default", "matter_request_full:create"},
  42. * "openapi_context"={
  43. * "summary"="Create a Matter Request.",
  44. * "description"="Use this call to create a new matter request and associated matter. See [Create Matter](/docs/api/detail#create-matter)"
  45. * }
  46. * },
  47. * "matter_request_full_update"={
  48. * "method"="POST",
  49. * "input"=MatterRequestFullDto::class,
  50. * "output"=MatterRequestFullDto::class,
  51. * "path"="/matter_requests/matter_request_full/update",
  52. * "normalization_context"={"groups"={"matter_request_full:read"}},
  53. * "denormalization_context"={"groups"={"matter_request_full:update"}},
  54. * "validation_groups"={"Default", "matter_request_full:update"},
  55. * "openapi_context"={
  56. * "summary"="Update a Matter Request and related Matter.",
  57. * "description"="Use this call to update/re-open an existing matter. See [Update/Re-Open Matter](/docs/api/detail#update-matter)",
  58. * "external_docs"={"url"="/docs/api/detail#update-matter", "description"="Read Documentation"}
  59. * }
  60. * },
  61. * "case_types"={
  62. * "access_control"="is_granted('CREATE_MATTER_REQUEST')",
  63. * "method"="GET",
  64. * "path"="/matter_requests/case_types",
  65. * "controller"=CaseTypes::class,
  66. * "defaults"={"_api_receive"=false},
  67. * "openapi_context"={
  68. * "summary"="Return all Case Type options.",
  69. * "description"="Return all Case Type options. See [Case Types](/docs/api/detail#case-types)",
  70. * "responses"={
  71. * "200"={
  72. * "description"="A list of Case Types options.",
  73. * }
  74. * }
  75. * }
  76. * },
  77. * "claim_values"={
  78. * "access_control"="is_granted('CREATE_MATTER_REQUEST')",
  79. * "method"="GET",
  80. * "path"="/matter_requests/claim_values",
  81. * "controller"=ClaimValues::class,
  82. * "defaults"={"_api_receive"=false},
  83. * "openapi_context"={
  84. * "summary"="Return all Claim Value options.",
  85. * "description"="Return all Claim Value options. The 'value' value is to be used in the claimValue field when creating a Matter Request.",
  86. * "responses"={
  87. * "200"={
  88. * "description"="A list of Claim Value options.",
  89. * }
  90. * }
  91. * }
  92. * }
  93. * },
  94. * itemOperations={
  95. * "get"={
  96. * "access_control"="is_granted('READ', object)",
  97. * "normalization_context"={"groups"={"matter_request:read"}, "enable_max_depth"=true}
  98. * },
  99. * "put"={"access_control"="is_granted('UPDATE', object)"},
  100. * "create_matter"={
  101. * "method"="POST",
  102. * "path"="/matter_requests/{id}/create_matter",
  103. * "controller"=CreateMatter::class,
  104. * "deserialize"=false,
  105. * "defaults"={"_api_receive"=false},
  106. * "swagger_context"={
  107. * "summary"="Create the matter associated with the MatterRequest.",
  108. * "parameters" = {
  109. * {"name" = "id","in" = "path","description" = "id","required" = "true","type" : "integer"}
  110. * }
  111. * }
  112. * }
  113. * },
  114. * attributes={
  115. * "validation_groups"={MatterRequest::class, "validationGroups"},
  116. * "denormalization_context"={"skip_null_values"=true},
  117. * },
  118. * )
  119. *
  120. * @Audit\Auditable
  121. *
  122. * @Audit\Security(view={"ROLE_ALLOWED_TO_AUDIT"})
  123. *
  124. * @UniqueEntity({"matterReference", "firm"}, groups={"Default", "md_step1"}, repositoryMethod="findByProjectClientReference", payload={"error_code": ApiErrorCodeAwareInterface::INVALID_MATTER_REFERENCE__ALREADY_USED})
  125. * @UniqueEntity({"matterReference", "firm"}, groups={"Default", "md_step1"}, payload={"error_code": ApiErrorCodeAwareInterface::INVALID_MATTER_REFERENCE__ALREADY_USED})
  126. *
  127. * @ORM\Table(name="MatterRequest")
  128. *
  129. * @ORM\Entity(repositoryClass=MatterRequestRepository::class)
  130. */
  131. class MatterRequest
  132. {
  133. use FilterableClassConstantsTrait;
  134. public const DEFENDANT_SEPARATOR = '#';
  135. // selectedServiceGroup constants
  136. public const SERVICE_GROUP_HOSTING_ONLY = 'hostingOnlyGroup';
  137. public const SERVICE_GROUP_HOSTING_ONLY__LABEL = 'Hosting Only';
  138. public const SERVICE_GROUP_EXTENDED = 'extendedServicesGroup';
  139. public const SERVICE_GROUP_EXTENDED__LABEL = 'Extended Services';
  140. // Status constants
  141. public const STATUS_INCOMPLETE = 'incomplete';
  142. public const STATUS_INCOMPLETE__LABEL = 'Incomplete';
  143. public const STATUS_INSTRUCTED = 'instructed';
  144. public const STATUS_INSTRUCTED__LABEL = 'Instructed';
  145. public const STATUS_IN_PROGRESS = 'in_progress';
  146. public const STATUS_IN_PROGRESS__LABEL = 'In Progress';
  147. public const STATUS_QUERY_WITH_CLIENT = 'query_with_client';
  148. public const STATUS_QUERY_WITH_CLIENT__LABEL = 'Query with client';
  149. public const STATUS_QA = 'qa';
  150. public const STATUS_QA__LABEL = 'QA';
  151. public const STATUS_COMPLETED = 'completed';
  152. public const STATUS_COMPLETED__LABEL = 'Completed';
  153. public const STATUS_CANCELLED = 'canceled';
  154. public const STATUS_CANCELLED__LABEL = 'Cancelled';
  155. // Used when changes have been requested to the matter request at a future date
  156. // Currently, only used when a case is re-opened via the API
  157. public const STATUS_RE_INSTRUCTED = 're_instructed';
  158. public const STATUS_RE_INSTRUCTED__LABEL = 'Re-Instructed';
  159. // Indicates the source of the matter request
  160. public const SOURCE_WEBSITE = 'website';
  161. public const SOURCE_WEBSITE__LABEL = 'Website';
  162. public const SOURCE_API = 'api';
  163. public const SOURCE_API__LABEL = 'Api';
  164. /**
  165. * @var int
  166. *
  167. * @Groups({"matter_request:read"})
  168. *
  169. * @ORM\Column(name="id", type="integer")
  170. *
  171. * @ORM\Id
  172. *
  173. * @ORM\GeneratedValue(strategy="IDENTITY")
  174. */
  175. protected $id;
  176. /**
  177. * A unique reference number for this Matter.
  178. *
  179. * @var string
  180. *
  181. * @Assert\NotBlank(groups={"Default", "md_step1"}, message="Please complete this field.")
  182. *
  183. * @Groups({"matter_request:read", "matter_request:create_full"})
  184. *
  185. * @ORM\Column(name="matterReference", type="string")
  186. */
  187. protected $matterReference;
  188. /**
  189. * DateTime the MatterRequest was created.
  190. *
  191. * @var \DateTimeImmutable
  192. *
  193. * @Groups({"matter_request:read"})
  194. *
  195. * @ORM\Column(name="created", type="datetime_immutable")
  196. *
  197. * @Gedmo\Timestampable(on="create")
  198. */
  199. protected $created;
  200. /**
  201. * Last update time of this MatterRequest.
  202. *
  203. * @var \DateTime
  204. *
  205. * @Groups({"matter_request:read"})
  206. *
  207. * @ORM\Column(name="updated", type="datetime")
  208. *
  209. * @Gedmo\Timestampable(on="update")
  210. */
  211. protected $updated;
  212. /**
  213. * One or more Claimants to whom this MatterRequest relates.
  214. *
  215. * @var string
  216. *
  217. * @Assert\NotBlank(groups={"Default", "md_step3"})
  218. *
  219. * @Groups({"matter_request:read", "matter_request:create_full"})
  220. *
  221. * @ORM\Column(name="claimant", type="string", nullable=true)
  222. */
  223. protected $claimant;
  224. /**
  225. * Any Defendants to whom this MatterRequest relates.
  226. *
  227. * @var string
  228. *
  229. * @Assert\Expression(
  230. * "value != '' or this.getDefendantUnknown() === true",
  231. * message="Please specify at least one defendant, or indicate 'Not Sure'.",
  232. * groups={"Default", "md_step3"}
  233. * )
  234. *
  235. * @Groups({"matter_request:read", "matter_request:create_full"})
  236. *
  237. * @ORM\Column(name="defendant", type="text", nullable=true)
  238. */
  239. protected $defendant;
  240. /**
  241. * Any Defendants to whom this MatterRequest relates.
  242. *
  243. * @var bool
  244. *
  245. * @Groups({"matter_request:read", "matter_request:create_full"})
  246. *
  247. * @ORM\Column(name="defendantUnknown", type="boolean", nullable=true, options={"default"=false})
  248. */
  249. protected $defendantUnknown = false;
  250. /**
  251. * The Team handling this Matter, where applicable.
  252. *
  253. * @var null|string
  254. *
  255. * @Groups({"matter_request:read", "matter_request:create_full"})
  256. *
  257. * @ORM\Column(name="team", type="string", nullable=true)
  258. */
  259. protected $team;
  260. /**
  261. * The Billing Code to be used for this Matter.
  262. *
  263. * @var null|string
  264. *
  265. * @Assert\Expression(
  266. * "(this.getFirm() and !this.getFirm().getMatterRequestDefaults()) or (this.getFirm() and this.getFirm().getMatterRequestDefaults() and !this.getFirm().getMatterRequestDefaults().isFieldForceCompulsory('billingCode')) or value != ''",
  267. * message="Please complete this field.",
  268. * groups={"Default", "md_step1"}
  269. *)
  270. *
  271. * @Groups({"matter_request:read", "matter_request:create_full"})
  272. *
  273. * @ORM\Column(name="billingCode", type="string", nullable=true)
  274. */
  275. protected $billingCode;
  276. /**
  277. * An indication of the estimated claim value for this Matter, if known.
  278. *
  279. * @var null|int
  280. *
  281. * @Assert\Expression(
  282. * "(this.getFirm() and this.getFirm().getMatterRequestDefaults() and this.getFirm().getMatterRequestDefaults().isFieldForceOptional('claimValue')) or value != ''",
  283. * message="This value should not be blank.",
  284. * groups={"Default", "md_step2"}
  285. *)
  286. *
  287. * @Groups({"matter_request:read", "matter_request:create_full"})
  288. *
  289. * @ORM\Column(name="claimValue", type="integer", nullable=true)
  290. */
  291. protected $claimValue;
  292. /**
  293. * The key allegations applicable to this Matter, if known.
  294. *
  295. * @var array|null
  296. *
  297. * @Assert\NotNull(groups={"Default", "md_step2"})})
  298. *
  299. * @Assert\Expression(
  300. * "(this.getFirm() and this.getFirm().getMatterRequestDefaults() and this.getFirm().getMatterRequestDefaults().isFieldForceOptional('keyAllegations')) or this.hasKeyAllegations()",
  301. * message="Please enter an allegation.",
  302. * groups={"Default", "md_step2"}
  303. * )
  304. *
  305. * @Groups({"matter_request:read", "matter_request:create_full"})
  306. *
  307. * @ORM\Column(name="keyAllegations", type="array")
  308. */
  309. protected $keyAllegations = [];
  310. /**
  311. * The date of alleged negligence applicable to this Matter, if known.
  312. *
  313. * @var null|\DateTime
  314. *
  315. * @Assert\Expression(
  316. * "(this.getFirm() and this.getFirm().getMatterRequestDefaults() and this.getFirm().getMatterRequestDefaults().isFieldForceOptional('negligenceDate')) or value != ''",
  317. * message="This value should not be blank.",
  318. * groups={"Default", "md_step2"}
  319. *)
  320. *
  321. * @Groups({"matter_request:read", "matter_request:create_full"})
  322. *
  323. * @ORM\Column(name="negligenceDate", type="datetime", nullable=true)
  324. */
  325. protected $negligenceDate;
  326. /**
  327. * The date of knowledge applicable to this Matter.
  328. *
  329. * @var null|\DateTime
  330. *
  331. * @Groups({"matter_request:read", "matter_request:create_full"})
  332. *
  333. * @ORM\Column(name="knowledgeDate", type="datetime", nullable=true)
  334. */
  335. protected $knowledgeDate;
  336. /**
  337. * The limitation date applicable to this Matter, if known.
  338. *
  339. * @var null|\DateTime
  340. *
  341. * @Assert\Expression(
  342. * "(this.getFirm() and this.getFirm().getMatterRequestDefaults() and this.getFirm().getMatterRequestDefaults().isFieldForceOptional('limitationDate')) or value != ''",
  343. * message="This value should not be blank.",
  344. * groups={"Default", "md_step2"}
  345. *)
  346. *
  347. * @Groups({"matter_request:read", "matter_request:create_full"})
  348. *
  349. * @ORM\Column(name="limitationDate", type="datetime", nullable=true)
  350. */
  351. protected $limitationDate;
  352. /**
  353. * The category to which this Matter belongs.
  354. *
  355. * @var int
  356. *
  357. * @Assert\Expression(
  358. * "(this.getFirm() and this.getFirm().getMatterRequestDefaults() and this.getFirm().getMatterRequestDefaults().isFieldForceOptional('claimCategory')) or value != ''",
  359. * message="This value should not be blank.",
  360. * groups={"Default", "md_step2"}
  361. *)
  362. *
  363. * @Groups({"matter_request:read", "matter_request:create_full"})
  364. *
  365. * @ORM\Column(name="claimCategory", type="integer", nullable=true)
  366. */
  367. protected $claimCategory;
  368. /**
  369. * The background to the matter.
  370. *
  371. * @var string
  372. *
  373. * @Assert\NotBlank(groups={"Default", "md_step2"})
  374. *
  375. * @Groups({"matter_request:read", "matter_request:create_full"})
  376. *
  377. * @ORM\Column(name="background", type="text", nullable=true)
  378. */
  379. protected $background;
  380. /**
  381. * The current step of the Matter Creation Form, so we can
  382. * return the user to edit the form, as well apply validation specific to the step.
  383. *
  384. * @var string
  385. *
  386. * @Groups({"matter_request:read"})
  387. *
  388. * @ORM\Column(name="currentFormStep", type="string", nullable=true)
  389. */
  390. protected $currentFormStep;
  391. /**
  392. * The selected service group passed through from the form.
  393. *
  394. * @var string
  395. *
  396. * @Groups({"matter_request:read"})
  397. *
  398. * @ORM\Column(name="selectedServiceGroup", type="string", nullable=true)
  399. */
  400. protected $selectedServiceGroup;
  401. /**
  402. * The Client/Firm initiating this MatterRequest.
  403. *
  404. * @var Account
  405. *
  406. * @Assert\NotNull(groups={"Default", "md_step1"}, message="Please select a storage area for this matter.")
  407. *
  408. * @Groups({"matter_request:read", "matter_request:create_full"})
  409. *
  410. * @ORM\ManyToOne(targetEntity="MedBrief\MSR\Entity\Account")
  411. *
  412. * @ORM\JoinColumns({
  413. *
  414. * @ORM\JoinColumn(name="firm_id", referencedColumnName="id")
  415. * })
  416. */
  417. protected $firm;
  418. /**
  419. * The Fee Earner for this Matter.
  420. *
  421. * @var User
  422. *
  423. * @Assert\NotNull(groups={"Default", "md_step1"}, message="Please select an option.")
  424. *
  425. * @ApiSubresource()
  426. *
  427. * @Groups({"matter_request:read", "matter_request:create_full"})
  428. *
  429. * @ORM\ManyToOne(targetEntity="MedBrief\MSR\Entity\User")
  430. *
  431. * @ORM\JoinColumns({
  432. *
  433. * @ORM\JoinColumn(name="manager_id", referencedColumnName="id")
  434. * })
  435. */
  436. protected $manager;
  437. /**
  438. * @var null|Collection|User[]
  439. *
  440. * @Groups({"matter_request:read", "matter_request:create_full"})
  441. *
  442. * @ORM\ManyToMany(targetEntity=User::class, cascade={"persist"}, fetch="EAGER")
  443. *
  444. * @ORM\JoinTable(name="matter_request_additional_contacts",
  445. * joinColumns={@ORM\JoinColumn(name="matter_request_id", referencedColumnName="id", nullable=true)},
  446. * inverseJoinColumns={@ORM\JoinColumn(name="user_id", referencedColumnName="id", nullable=true)}
  447. * )
  448. *
  449. * @Assert\Expression(
  450. * "this.hasAdditionalContactsEmpty()",
  451. * message="All additional contacts must be fully completed or removed.",
  452. * groups={"Default", "md_step1"}
  453. * )
  454. */
  455. protected $additionalContacts;
  456. /**
  457. * The Project to which this MatterRequest relates.
  458. *
  459. * @var null|Project
  460. *
  461. * @ORM\OneToOne(targetEntity="MedBrief\MSR\Entity\Project", inversedBy="matterRequest")
  462. *
  463. * @ORM\JoinColumns({
  464. *
  465. * @ORM\JoinColumn(name="matter_id", referencedColumnName="id", unique=true)
  466. * })
  467. */
  468. protected $matter;
  469. /**
  470. * The Project ID to which this MatterRequest relates.
  471. *
  472. * Not mapped, used only for API.
  473. *
  474. * @Groups({"matter_request:read"})
  475. *
  476. * @var null|int
  477. */
  478. protected $matterId;
  479. /**
  480. * The Patients associated to this Matter.
  481. *
  482. * @var Collection
  483. *
  484. * @ApiSubresource()
  485. *
  486. * @Groups({"matter_request:read", "matter_request:create_full"})
  487. *
  488. * @ORM\OneToMany(targetEntity="MedBrief\MSR\Entity\MatterRequest\Patient", mappedBy="matterRequest", orphanRemoval=true, cascade={"persist"})
  489. */
  490. protected $patients;
  491. /**
  492. * The Trust Centres associated to this Matter.
  493. *
  494. * @var Collection
  495. *
  496. * @ApiSubresource()
  497. *
  498. * @Assert\Count(
  499. * min = 1,
  500. * minMessage = "You must specify at least one Trust Centre",
  501. * groups={"rr_step1"}
  502. * )
  503. *
  504. * @Groups({"matter_request:read"})
  505. *
  506. * @ORM\OneToMany(targetEntity="MedBrief\MSR\Entity\MatterRequest\TrustCentre", mappedBy="matterRequest", orphanRemoval=true, cascade={"persist"})
  507. */
  508. protected $trustCentres;
  509. /**
  510. * @var null|PostProcessing
  511. *
  512. * @ApiSubresource()
  513. *
  514. * @Groups({"matter_request:read"})
  515. *
  516. * @ORM\OneToOne(targetEntity="MedBrief\MSR\Entity\MatterRequest\Details\PostProcessing", inversedBy="matterRequest", orphanRemoval=true, cascade={"persist"})
  517. *
  518. * @ORM\JoinColumns({
  519. *
  520. * @ORM\JoinColumn(name="postProcessingDetails_id", referencedColumnName="id", unique=true)
  521. * })
  522. */
  523. protected $postProcessingDetails;
  524. /**
  525. * @var null|Chronology
  526. *
  527. * @ApiSubresource()
  528. *
  529. * @Groups({"matter_request:read"})
  530. *
  531. * @ORM\OneToOne(targetEntity="MedBrief\MSR\Entity\MatterRequest\Details\Chronology", inversedBy="matterRequest", orphanRemoval=true, cascade={"persist"})
  532. *
  533. * @ORM\JoinColumns({
  534. *
  535. * @ORM\JoinColumn(name="chronologyDetails_id", referencedColumnName="id", unique=true)
  536. * })
  537. */
  538. protected $chronologyDetails;
  539. /**
  540. * @var null|Review
  541. *
  542. * @ApiSubresource()
  543. *
  544. * @Groups({"matter_request:read"})
  545. *
  546. * @ORM\OneToOne(targetEntity="MedBrief\MSR\Entity\MatterRequest\Details\Review", inversedBy="matterRequest", orphanRemoval=true, cascade={"persist"})
  547. *
  548. * @ORM\JoinColumns({
  549. *
  550. * @ORM\JoinColumn(name="reviewDetails_id", referencedColumnName="id", unique=true)
  551. * })
  552. */
  553. protected $reviewDetails;
  554. /**
  555. * @var null|Sort
  556. *
  557. * @ApiSubresource()
  558. *
  559. * @Groups({"matter_request:read"})
  560. *
  561. * @ORM\OneToOne(targetEntity="MedBrief\MSR\Entity\MatterRequest\Details\Sort", inversedBy="matterRequest", orphanRemoval=true, cascade={"persist"})
  562. *
  563. * @ORM\JoinColumns({
  564. *
  565. * @ORM\JoinColumn(name="sortDetails_id", referencedColumnName="id", unique=true)
  566. * })
  567. */
  568. protected $sortDetails;
  569. /**
  570. * @var null|ServiceSelection
  571. *
  572. * @ApiSubresource()
  573. *
  574. * @Groups({"matter_request:read"})
  575. *
  576. * @ORM\OneToOne(targetEntity="MedBrief\MSR\Entity\MatterRequest\Details\ServiceSelection", inversedBy="matterRequest", orphanRemoval=true, cascade={"persist"})
  577. *
  578. * @ORM\JoinColumns({
  579. *
  580. * @ORM\JoinColumn(name="serviceSelectionDetails_id", referencedColumnName="id", unique=true)
  581. * })
  582. */
  583. protected $serviceSelectionDetails;
  584. /**
  585. * @var string
  586. *
  587. * @ORM\Column(name="status", type="string", nullable=true)
  588. */
  589. protected $status;
  590. /**
  591. * @var User
  592. *
  593. * @ORM\ManyToOne(targetEntity="MedBrief\MSR\Entity\User")
  594. *
  595. * @ORM\JoinColumns({
  596. *
  597. * @ORM\JoinColumn(name="creator_id", referencedColumnName="id")
  598. * })
  599. */
  600. protected $creator;
  601. /**
  602. * @ORM\Column(name="source", type="string", options={"default"=self::SOURCE_WEBSITE})
  603. */
  604. protected string $source = self::SOURCE_WEBSITE;
  605. /**
  606. * @ORM\Column(name="historicalApiValues", type="json", nullable=true)
  607. */
  608. protected ?array $historicalApiValues = null;
  609. /**
  610. * @return void
  611. */
  612. public function __construct()
  613. {
  614. $this->patients = new ArrayCollection();
  615. $this->trustCentres = new ArrayCollection();
  616. $this->status = self::STATUS_INCOMPLETE;
  617. $this->source = self::SOURCE_WEBSITE;
  618. $this->additionalContacts = new ArrayCollection();
  619. }
  620. /**
  621. * __toString
  622. *
  623. * @return string
  624. */
  625. public function __toString(): string
  626. {
  627. return (string) ($this->getId() ?? 'Unknown');
  628. }
  629. /**
  630. * Determines the validation group to use, based on the currentFormStep for the
  631. * matterRequest.
  632. *
  633. * @param MatterRequest $matterRequest
  634. *
  635. * @return array
  636. */
  637. public static function validationGroups(MatterRequest $matterRequest): array
  638. {
  639. switch ($matterRequest->getCurrentFormStep()) {
  640. case 'md.step1':
  641. return ['md_step1'];
  642. case 'md.step2':
  643. return ['md_step2'];
  644. case 'md.step3':
  645. return ['md_step3'];
  646. case 'rr.step1':
  647. return ['rr_step1'];
  648. default:
  649. return ['Default'];
  650. }
  651. }
  652. /**
  653. * @return int
  654. */
  655. public function getId(): ?int
  656. {
  657. return $this->id;
  658. }
  659. /**
  660. * Set matterReference.
  661. *
  662. * @param string $matterReference
  663. *
  664. * @return MatterRequest
  665. */
  666. public function setMatterReference($matterReference)
  667. {
  668. $this->matterReference = $matterReference;
  669. // Update the associated matter as well, if it exists, and if the values are different,
  670. // to avoid a recursive loop.
  671. if ($this->getMatter() && $this->getMatter()->getClientReference() != $this->matterReference) {
  672. $this->getMatter()->setClientReference($this->matterReference);
  673. }
  674. return $this;
  675. }
  676. /**
  677. * Get matterReference.
  678. *
  679. * @return string
  680. */
  681. public function getMatterReference()
  682. {
  683. return $this->matterReference;
  684. }
  685. /**
  686. * Set created.
  687. *
  688. * @param \DateTimeImmutable $created
  689. *
  690. * @return MatterRequest
  691. */
  692. public function setCreated($created)
  693. {
  694. $this->created = $created;
  695. return $this;
  696. }
  697. /**
  698. * Get created.
  699. *
  700. * @return \DateTimeImmutable
  701. */
  702. public function getCreated()
  703. {
  704. return $this->created;
  705. }
  706. /**
  707. * Set updated.
  708. *
  709. * @param \DateTime $updated
  710. *
  711. * @return MatterRequest
  712. */
  713. public function setUpdated($updated)
  714. {
  715. $this->updated = $updated;
  716. return $this;
  717. }
  718. /**
  719. * Get updated.
  720. *
  721. * @return \DateTime
  722. */
  723. public function getUpdated()
  724. {
  725. return $this->updated;
  726. }
  727. /**
  728. * @return string
  729. */
  730. public function getClaimant(): ?string
  731. {
  732. return $this->claimant;
  733. }
  734. /**
  735. * @param string $claimant
  736. *
  737. * @return MatterRequest
  738. */
  739. public function setClaimant(string $claimant): MatterRequest
  740. {
  741. $this->claimant = $claimant;
  742. if ($this->getMatter()) {
  743. $this->getMatter()->setName($this->generateMatterName());
  744. }
  745. return $this;
  746. }
  747. /**
  748. * @return string|null
  749. */
  750. public function getDefendant(): ?string
  751. {
  752. return $this->defendant;
  753. }
  754. /**
  755. * @return array
  756. */
  757. public function getDefendantArray(): array
  758. {
  759. return explode(MatterRequest::DEFENDANT_SEPARATOR, $this->getDefendant());
  760. }
  761. /**
  762. * @param string|null $defendant
  763. *
  764. * @return MatterRequest
  765. */
  766. public function setDefendant(?string $defendant = null): MatterRequest
  767. {
  768. $this->defendant = $defendant;
  769. if ($this->getMatter()) {
  770. $this->getMatter()->setName($this->generateMatterName());
  771. }
  772. return $this;
  773. }
  774. /**
  775. * @param ?array $defendant
  776. *
  777. * @return MatterRequest
  778. */
  779. public function setDefendantArray(?array $defendant = null): MatterRequest
  780. {
  781. if ($defendant === null || empty($defendant)) {
  782. $this->setDefendant(null);
  783. }
  784. $this->setDefendant(implode(MatterRequest::DEFENDANT_SEPARATOR, $defendant));
  785. return $this;
  786. }
  787. /**
  788. * @return string|null
  789. */
  790. public function getTeam(): ?string
  791. {
  792. return $this->team;
  793. }
  794. /**
  795. * @param string $team
  796. *
  797. * @return MatterRequest
  798. */
  799. public function setTeam(?string $team = null): MatterRequest
  800. {
  801. $this->team = $team;
  802. // Update the associated matter as well, if it exists, and if the values are different,
  803. // to avoid a recursive loop.
  804. if ($this->getMatter() && $this->getMatter()->getTeam() != $this->team) {
  805. $this->getMatter()->setTeam($this->team);
  806. }
  807. return $this;
  808. }
  809. /**
  810. * @return string|null
  811. */
  812. public function getBillingCode(): ?string
  813. {
  814. return $this->billingCode;
  815. }
  816. /**
  817. * @param string $billingCode
  818. *
  819. * @return MatterRequest
  820. */
  821. public function setBillingCode(?string $billingCode = null): MatterRequest
  822. {
  823. $this->billingCode = $billingCode;
  824. // Update the associated matter as well, if it exists, and if the values are different,
  825. // to avoid a recursive loop.
  826. if ($this->getMatter() && $this->getMatter()->getBillingCode() != $this->billingCode) {
  827. $this->getMatter()->setBillingCode($this->billingCode);
  828. }
  829. return $this;
  830. }
  831. /**
  832. * @return null|int
  833. */
  834. public function getClaimValue(): ?int
  835. {
  836. return $this->claimValue;
  837. }
  838. /**
  839. * @return string
  840. */
  841. public function getClaimValueLabel(): string
  842. {
  843. $claimValues = array_flip(Project::getConstantsWithLabelsAsChoices('ESTIMATED_CLAIM_VALUE'));
  844. return $claimValues[$this->claimValue] ?? '';
  845. }
  846. /**
  847. * @param int $claimValue
  848. *
  849. * @return MatterRequest
  850. */
  851. public function setClaimValue(?int $claimValue = null): MatterRequest
  852. {
  853. $this->claimValue = $claimValue;
  854. // Update the associated matter as well, if it exists, and if the values are different,
  855. // to avoid a recursive loop.
  856. if ($this->getMatter() && $this->getMatter()->getEstimatedClaimValue() != $this->claimValue) {
  857. $this->getMatter()->setEstimatedClaimValue($this->claimValue);
  858. }
  859. return $this;
  860. }
  861. /**
  862. * @param int|null $rawAmount
  863. *
  864. * @return self
  865. */
  866. public function setClaimValueFromRawAmount(?int $rawAmount = null): self
  867. {
  868. if ($rawAmount === null) {
  869. $this->setClaimValue(null);
  870. return $this;
  871. }
  872. switch (true) {
  873. case $rawAmount >= 0 && $rawAmount <= 25000:
  874. $this->setClaimValue(Project::ESTIMATED_CLAIM_VALUE_0_25000);
  875. break;
  876. case $rawAmount >= 25001 && $rawAmount <= 50000:
  877. $this->setClaimValue(Project::ESTIMATED_CLAIM_VALUE_25001_50000);
  878. break;
  879. case $rawAmount >= 50001 && $rawAmount <= 100000:
  880. $this->setClaimValue(Project::ESTIMATED_CLAIM_VALUE_50001_100000);
  881. break;
  882. case $rawAmount >= 100001 && $rawAmount <= 250000:
  883. $this->setClaimValue(Project::ESTIMATED_CLAIM_VALUE_100001_250000);
  884. break;
  885. case $rawAmount >= 250001 && $rawAmount <= 500000:
  886. $this->setClaimValue(Project::ESTIMATED_CLAIM_VALUE_250001_500000);
  887. break;
  888. case $rawAmount >= 500001 && $rawAmount <= 1000000:
  889. $this->setClaimValue(Project::ESTIMATED_CLAIM_VALUE_500001_1000000);
  890. break;
  891. case $rawAmount >= 1000000:
  892. $this->setClaimValue(Project::ESTIMATED_CLAIM_VALUE_1000001);
  893. break;
  894. }
  895. return $this;
  896. }
  897. /**
  898. * @return null|\DateTime
  899. */
  900. public function getNegligenceDate(): ?\DateTime
  901. {
  902. return $this->negligenceDate;
  903. }
  904. /**
  905. * @param \DateTime $negligenceDate
  906. *
  907. * @return MatterRequest
  908. */
  909. public function setNegligenceDate(?\DateTime $negligenceDate = null): MatterRequest
  910. {
  911. $this->negligenceDate = $negligenceDate;
  912. return $this;
  913. }
  914. /**
  915. * @return null|\DateTime
  916. */
  917. public function getKnowledgeDate(): ?\DateTime
  918. {
  919. return $this->knowledgeDate;
  920. }
  921. /**
  922. * @param \DateTime $knowledgeDate
  923. *
  924. * @return MatterRequest
  925. */
  926. public function setKnowledgeDate(?\DateTime $knowledgeDate = null): MatterRequest
  927. {
  928. $this->knowledgeDate = $knowledgeDate;
  929. return $this;
  930. }
  931. /**
  932. * @return null|\DateTime
  933. */
  934. public function getLimitationDate(): ?\DateTime
  935. {
  936. return $this->limitationDate;
  937. }
  938. /**
  939. * @param \DateTime $limitationDate
  940. *
  941. * @return MatterRequest
  942. */
  943. public function setLimitationDate(?\DateTime $limitationDate = null): MatterRequest
  944. {
  945. $this->limitationDate = $limitationDate;
  946. // Update the associated matter as well, if it exists, and if the values are different,
  947. // to avoid a recursive loop.
  948. if ($this->getMatter() && $this->getMatter()->getLimitationDate() != $this->limitationDate) {
  949. $this->getMatter()->setLimitationDate($this->limitationDate);
  950. }
  951. return $this;
  952. }
  953. /**
  954. * @return int
  955. */
  956. public function getClaimCategory(): ?int
  957. {
  958. return $this->claimCategory;
  959. }
  960. /**
  961. * @return string
  962. */
  963. public function getClaimCategoryLabel(): string
  964. {
  965. $claimCategories = array_flip(Project::getConstantsWithLabelsAsChoices('CLAIM_CATEGORY'));
  966. return $claimCategories[$this->claimCategory] ?? 'Other';
  967. }
  968. /**
  969. * @return bool
  970. */
  971. public function isClaimCategoryBirthInjury(): bool
  972. {
  973. return in_array($this->getClaimCategory(), Project::getBirthInjuryClaimCategories());
  974. }
  975. /**
  976. * @param int $claimCategory
  977. *
  978. * @return MatterRequest
  979. */
  980. public function setClaimCategory(?int $claimCategory = null): MatterRequest
  981. {
  982. $this->claimCategory = $claimCategory;
  983. // Update the associated matter as well, if it exists, and if the values are different,
  984. // to avoid a recursive loop.
  985. if ($this->getMatter() && $this->getMatter()->getClaimCategory() != $this->claimCategory) {
  986. $this->getMatter()->setClaimCategory($this->claimCategory);
  987. }
  988. return $this;
  989. }
  990. /**
  991. * @return Collection|Patient[]
  992. */
  993. public function getPatients(): Collection
  994. {
  995. return $this->patients;
  996. }
  997. /**
  998. * @param Collection $patients
  999. *
  1000. * @return MatterRequest
  1001. */
  1002. public function setPatients(Collection $patients): MatterRequest
  1003. {
  1004. $this->patients = $patients;
  1005. return $this;
  1006. }
  1007. public function addPatient(Patient $patient): MatterRequest
  1008. {
  1009. $patient->setMatterRequest($this);
  1010. $this->patients[] = $patient;
  1011. return $this;
  1012. }
  1013. /**
  1014. * @return Collection
  1015. */
  1016. public function getTrustCentres(): Collection
  1017. {
  1018. return $this->trustCentres;
  1019. }
  1020. /**
  1021. * @param Collection $trustCentres
  1022. *
  1023. * @return MatterRequest
  1024. */
  1025. public function setTrustCentres(Collection $trustCentres): MatterRequest
  1026. {
  1027. $this->trustCentres = $trustCentres;
  1028. return $this;
  1029. }
  1030. public function addTrustCentre(TrustCentre $trustCentre): MatterRequest
  1031. {
  1032. $trustCentre->setMatterRequest($this);
  1033. $this->trustCentres[] = $trustCentre;
  1034. return $this;
  1035. }
  1036. /**
  1037. * @return PostProcessing|null
  1038. */
  1039. public function getPostProcessingDetails(): ?PostProcessing
  1040. {
  1041. return $this->postProcessingDetails;
  1042. }
  1043. /**
  1044. * @param PostProcessing|null $postProcessingDetails
  1045. *
  1046. * @return MatterRequest
  1047. */
  1048. public function setPostProcessingDetails(?PostProcessing $postProcessingDetails): MatterRequest
  1049. {
  1050. $this->postProcessingDetails = $postProcessingDetails;
  1051. return $this;
  1052. }
  1053. /**
  1054. * @return Chronology|null
  1055. */
  1056. public function getChronologyDetails(): ?Chronology
  1057. {
  1058. return $this->chronologyDetails;
  1059. }
  1060. /**
  1061. * @param Chronology|null $chronologyDetails
  1062. *
  1063. * @return MatterRequest
  1064. */
  1065. public function setChronologyDetails(?Chronology $chronologyDetails): MatterRequest
  1066. {
  1067. $this->chronologyDetails = $chronologyDetails;
  1068. return $this;
  1069. }
  1070. /**
  1071. * @return Review|null
  1072. */
  1073. public function getReviewDetails(): ?Review
  1074. {
  1075. return $this->reviewDetails;
  1076. }
  1077. /**
  1078. * @param Review|null $reviewDetails
  1079. *
  1080. * @return MatterRequest
  1081. */
  1082. public function setReviewDetails(?Review $reviewDetails): MatterRequest
  1083. {
  1084. $this->reviewDetails = $reviewDetails;
  1085. return $this;
  1086. }
  1087. /**
  1088. * @return Sort|null
  1089. */
  1090. public function getSortDetails(): ?Sort
  1091. {
  1092. return $this->sortDetails;
  1093. }
  1094. /**
  1095. * @param Sort|null $sortDetails
  1096. *
  1097. * @return MatterRequest
  1098. */
  1099. public function setSortDetails(?Sort $sortDetails): MatterRequest
  1100. {
  1101. $this->sortDetails = $sortDetails;
  1102. return $this;
  1103. }
  1104. /**
  1105. * @return Account
  1106. */
  1107. public function getFirm(): ?Account
  1108. {
  1109. return $this->firm;
  1110. }
  1111. /**
  1112. * @param Account|null $firm
  1113. *
  1114. * @return MatterRequest
  1115. */
  1116. public function setFirm(?Account $firm = null): MatterRequest
  1117. {
  1118. $this->firm = $firm;
  1119. return $this;
  1120. }
  1121. /**
  1122. * retrieves the manager of the project
  1123. *
  1124. * @return User|null
  1125. */
  1126. public function getManager(): ?User
  1127. {
  1128. try {
  1129. // If the manager is a Proxy, we need to load it to ensure it is fully initialized.
  1130. if ($this->manager instanceof Proxy) {
  1131. $this->manager->__load();
  1132. }
  1133. return $this->manager;
  1134. } catch (EntityNotFoundException $e) {
  1135. // If the manager is not found (has been soft/hard deleted), return null.
  1136. return null;
  1137. }
  1138. }
  1139. /**
  1140. * @param User|null $manager
  1141. *
  1142. * @return MatterRequest
  1143. */
  1144. public function setManager(?User $manager = null): MatterRequest
  1145. {
  1146. $this->manager = $manager;
  1147. // Update the associated matter as well, if it exists, and if the values are different,
  1148. // to avoid a recursive loop.
  1149. if ($this->getMatter() && $this->getMatter()->getManager() != $this->manager) {
  1150. $this->getMatter()->setManager($this->manager);
  1151. }
  1152. return $this;
  1153. }
  1154. /**
  1155. * @return Project|null
  1156. */
  1157. public function getMatter(): ?Project
  1158. {
  1159. return $this->matter;
  1160. }
  1161. /**
  1162. * @param Project|null $matter
  1163. *
  1164. * @return MatterRequest
  1165. */
  1166. public function setMatter(?Project $matter): MatterRequest
  1167. {
  1168. $this->matter = $matter;
  1169. return $this;
  1170. }
  1171. /**
  1172. * @return array|null
  1173. */
  1174. public function getKeyAllegations(): ?array
  1175. {
  1176. return $this->keyAllegations;
  1177. }
  1178. /**
  1179. * @return bool
  1180. */
  1181. public function hasKeyAllegations(): bool
  1182. {
  1183. return count($this->keyAllegations) > 0 && !in_array('', $this->keyAllegations);
  1184. }
  1185. /**
  1186. * @param array|null $keyAllegations
  1187. *
  1188. * @return MatterRequest
  1189. */
  1190. public function setKeyAllegations(?array $keyAllegations = null): MatterRequest
  1191. {
  1192. $this->keyAllegations = $keyAllegations;
  1193. return $this;
  1194. }
  1195. /**
  1196. * Validates key allegations.
  1197. *
  1198. * @return bool
  1199. */
  1200. public function validateKeyAllegations(): bool
  1201. {
  1202. if (count((array) $this->getKeyAllegations())) {
  1203. return false;
  1204. }
  1205. foreach ($this->getKeyAllegations() as $keyAllegation) {
  1206. if ($keyAllegation == '') {
  1207. return false;
  1208. }
  1209. }
  1210. return true;
  1211. }
  1212. /**
  1213. * @return bool
  1214. */
  1215. public function hasAdditionalContactsEmpty(): bool
  1216. {
  1217. if (count($this->getAdditionalContacts()) > 1) {
  1218. return !in_array('', $this->getAdditionalContacts()->toArray(), true);
  1219. }
  1220. return true;
  1221. }
  1222. /**
  1223. * @return string
  1224. */
  1225. public function getBackground(): ?string
  1226. {
  1227. return $this->background;
  1228. }
  1229. /**
  1230. * @param string $background
  1231. *
  1232. * @return MatterRequest
  1233. */
  1234. public function setBackground(string $background): MatterRequest
  1235. {
  1236. $this->background = $background;
  1237. // Update the associated matter as well, if it exists, and if the values are different,
  1238. // to avoid a recursive loop.
  1239. if ($this->getMatter() && $this->getMatter()->getBackground() != $this->background) {
  1240. $this->getMatter()->setBackground($this->background);
  1241. }
  1242. return $this;
  1243. }
  1244. /**
  1245. * Set currentFormStep.
  1246. *
  1247. * @param string|null $currentFormStep
  1248. *
  1249. * @return MatterRequest
  1250. */
  1251. public function setCurrentFormStep($currentFormStep = null)
  1252. {
  1253. $this->currentFormStep = $currentFormStep;
  1254. return $this;
  1255. }
  1256. /**
  1257. * Get currentFormStep.
  1258. *
  1259. * @return string|null
  1260. */
  1261. public function getCurrentFormStep()
  1262. {
  1263. return $this->currentFormStep;
  1264. }
  1265. /**
  1266. * Set selectedServiceGroup.
  1267. *
  1268. * @param string|null $selectedServiceGroup
  1269. *
  1270. * @return MatterRequest
  1271. */
  1272. public function setSelectedServiceGroup($selectedServiceGroup = null)
  1273. {
  1274. $this->selectedServiceGroup = $selectedServiceGroup;
  1275. return $this;
  1276. }
  1277. /**
  1278. * Get selectedServiceGroup.
  1279. *
  1280. * @return string|null
  1281. */
  1282. public function getSelectedServiceGroup()
  1283. {
  1284. return $this->selectedServiceGroup;
  1285. }
  1286. /**
  1287. * @return string
  1288. */
  1289. public function getSelectedServiceGroupLabel()
  1290. {
  1291. $serviceGroups = array_flip(static::getConstantsWithLabelsAsChoices('SERVICE_GROUP'));
  1292. return $serviceGroups[$this->selectedServiceGroup] ?? '';
  1293. }
  1294. /**
  1295. * Set serviceSelectionDetails.
  1296. *
  1297. * @param ServiceSelection|null $serviceSelectionDetails
  1298. *
  1299. * @return MatterRequest
  1300. */
  1301. public function setServiceSelectionDetails(?ServiceSelection $serviceSelectionDetails = null)
  1302. {
  1303. $this->serviceSelectionDetails = $serviceSelectionDetails;
  1304. return $this;
  1305. }
  1306. /**
  1307. * Get serviceSelectionDetails.
  1308. *
  1309. * @return ServiceSelection|null
  1310. */
  1311. public function getServiceSelectionDetails()
  1312. {
  1313. return $this->serviceSelectionDetails;
  1314. }
  1315. /**
  1316. * Returns true if one of the patients on the matter request has an additional supporting document added.
  1317. *
  1318. * @return bool
  1319. */
  1320. public function hasAdditionalSupportingDocuments(): bool
  1321. {
  1322. $patients = $this->getPatients()->filter(function (Patient $patient) {
  1323. $additionalSupportDocuments = $patient->getSupportingDocuments()->filter(function (SupportingDocument $supportingDocument) {
  1324. return $supportingDocument->isAdditionalDocumentType();
  1325. });
  1326. return $additionalSupportDocuments->count();
  1327. });
  1328. return $patients->count();
  1329. }
  1330. /**
  1331. * Set defendantUnknown.
  1332. *
  1333. * @param bool|null $defendantUnknown
  1334. *
  1335. * @return MatterRequest
  1336. */
  1337. public function setDefendantUnknown(?bool $defendantUnknown = null)
  1338. {
  1339. $this->defendantUnknown = $defendantUnknown;
  1340. return $this;
  1341. }
  1342. /**
  1343. * Get defendantUnknown.
  1344. *
  1345. * @return bool|null
  1346. */
  1347. public function getDefendantUnknown()
  1348. {
  1349. return $this->defendantUnknown;
  1350. }
  1351. /**
  1352. * Generates the string representation for the matter name.
  1353. *
  1354. * @return string
  1355. */
  1356. public function generateMatterName(): string
  1357. {
  1358. // If the defendant was marked as unknown, return just the claimant name for the matter name.
  1359. if ($this->getDefendantUnknown()) {
  1360. return $this->getClaimant();
  1361. } elseif (strpos($this->getDefendant() ?? '', self::DEFENDANT_SEPARATOR) === false) {
  1362. // else, if there's no comma, we only have one defendant.
  1363. $projectDefendantStr = $this->getDefendant();
  1364. } else {
  1365. // If there is comma, we have more than one, and need to format them.
  1366. $defendantArray = $this->getDefendantArray();
  1367. $projectDefendantStr = implode(' ', array_map(function (string $currentItem, $currentKey) {
  1368. return sprintf('(%1$s) %2$s', $currentKey + 1, $currentItem);
  1369. }, $defendantArray, array_keys($defendantArray)));
  1370. }
  1371. return sprintf('%1$s -v- %2$s', $this->getClaimant(), $projectDefendantStr);
  1372. }
  1373. /**
  1374. * Returns a string representation of all patient names.
  1375. *
  1376. * @return void
  1377. */
  1378. public function getPatientNamesStr()
  1379. {
  1380. return implode(', ', $this->getPatients()->map(function (Patient $patient) {
  1381. return $patient->getName();
  1382. })->toArray());
  1383. }
  1384. /**
  1385. * Returns the associated matter ID.
  1386. *
  1387. * @return int|null
  1388. */
  1389. public function getMatterId(): ?int
  1390. {
  1391. return $this->getMatter() ? $this->getMatter()->getId() : null;
  1392. }
  1393. /**
  1394. * Set status.
  1395. *
  1396. * @param string|null $status
  1397. *
  1398. * @return MatterRequest
  1399. */
  1400. public function setStatus(?string $status = null): MatterRequest
  1401. {
  1402. $this->status = $status;
  1403. return $this;
  1404. }
  1405. /**
  1406. * Get status.
  1407. *
  1408. * @return string|null
  1409. */
  1410. public function getStatus()
  1411. {
  1412. return $this->status;
  1413. }
  1414. /**
  1415. * @return string
  1416. */
  1417. public function getStatusLabel(): string
  1418. {
  1419. $statuses = array_flip(static::getConstantsWithLabelsAsChoices('STATUS'));
  1420. return $statuses[$this->status] ?? '';
  1421. }
  1422. /**
  1423. * Returns true if the status incomplete.
  1424. *
  1425. * @return bool
  1426. */
  1427. public function isStatusIncomplete(): bool
  1428. {
  1429. return $this->status === self::STATUS_INCOMPLETE;
  1430. }
  1431. /**
  1432. * Remove patient.
  1433. *
  1434. * @param Patient $patient
  1435. *
  1436. * @return bool TRUE if this collection contained the specified element, FALSE otherwise.
  1437. */
  1438. public function removePatient(Patient $patient)
  1439. {
  1440. return $this->patients->removeElement($patient);
  1441. }
  1442. /**
  1443. * Remove trustCentre.
  1444. *
  1445. * @param TrustCentre $trustCentre
  1446. *
  1447. * @return bool TRUE if this collection contained the specified element, FALSE otherwise.
  1448. */
  1449. public function removeTrustCentre(TrustCentre $trustCentre)
  1450. {
  1451. return $this->trustCentres->removeElement($trustCentre);
  1452. }
  1453. /**
  1454. * Set creator.
  1455. *
  1456. * @param User|null $creator
  1457. *
  1458. * @return MatterRequest
  1459. */
  1460. public function setCreator(?User $creator = null)
  1461. {
  1462. $this->creator = $creator;
  1463. return $this;
  1464. }
  1465. /**
  1466. * Get creator.
  1467. *
  1468. * @return User|null
  1469. */
  1470. public function getCreator()
  1471. {
  1472. return $this->creator;
  1473. }
  1474. /**
  1475. * Get String of Defendants separated by & and not a #
  1476. *
  1477. * @return string
  1478. */
  1479. public function getDefendantFormatted(): string
  1480. {
  1481. return implode(' & ', $this->getDefendantArray());
  1482. }
  1483. /**
  1484. * @return bool
  1485. */
  1486. public function isHostingOnlyMatter(): bool
  1487. {
  1488. return $this->getSelectedServiceGroup() === self::SERVICE_GROUP_HOSTING_ONLY;
  1489. }
  1490. /**
  1491. * @return string|null
  1492. */
  1493. public function getSource(): ?string
  1494. {
  1495. return $this->source;
  1496. }
  1497. /**
  1498. * @param string $source
  1499. *
  1500. * @return self
  1501. */
  1502. public function setSource(string $source): self
  1503. {
  1504. $this->source = $source;
  1505. return $this;
  1506. }
  1507. /**
  1508. * @return array
  1509. */
  1510. public static function getSourceOptions(): array
  1511. {
  1512. return static::getConstantsWithLabelsAsChoices('SOURCE');
  1513. }
  1514. /**
  1515. * @return string
  1516. */
  1517. public function getSourceLabel(): string
  1518. {
  1519. $options = array_flip(static::getSourceOptions());
  1520. return $options[$this->source] ?? '';
  1521. }
  1522. /**
  1523. * Represented by a multi-dimensional array of field changes.
  1524. *
  1525. * @return array|null
  1526. */
  1527. public function getHistoricalApiValues(): ?array
  1528. {
  1529. return $this->historicalApiValues;
  1530. }
  1531. /**
  1532. *
  1533. * @param \DateTime|null $archivedDate
  1534. * @param string|null $oldBillingCode
  1535. * @param string|null $oldMatterNumber
  1536. * @param bool $wasArchived
  1537. *
  1538. * @return self
  1539. */
  1540. public function addHistoricalApiValues(
  1541. ?\DateTime $archivedDate,
  1542. ?string $oldBillingCode,
  1543. ?string $oldMatterNumber,
  1544. bool $wasArchived = false
  1545. ): self {
  1546. $historicalApiValues = $this->getHistoricalApiValues() ?? [];
  1547. $historicalApiValues[] = [
  1548. 'oldBillingCode' => $oldBillingCode ?? 'NA',
  1549. 'oldMatterNumber' => $oldMatterNumber ?? 'NA',
  1550. 'wasArchived' => $wasArchived,
  1551. 'archivedDate' => $archivedDate ?? 'NA',
  1552. 'modified' => new \DateTime(),
  1553. ];
  1554. $this->setHistoricalApiValues($historicalApiValues);
  1555. return $this;
  1556. }
  1557. /**
  1558. * Get additional contacts
  1559. *
  1560. * @return null|Collection|User[]
  1561. */
  1562. public function getAdditionalContacts(): ?Collection
  1563. {
  1564. return $this->additionalContacts;
  1565. }
  1566. /**
  1567. * Set additional contacts
  1568. *
  1569. * @param null|Collection|User[] $additionalContacts
  1570. *
  1571. * @return self
  1572. */
  1573. public function setAdditionalContacts(?Collection $additionalContacts): self
  1574. {
  1575. $this->additionalContacts = $additionalContacts;
  1576. return $this;
  1577. }
  1578. /**
  1579. * Add an additional contact
  1580. *
  1581. * @param User $user
  1582. *
  1583. * @return self
  1584. */
  1585. public function addAdditionalContact(User $user): self
  1586. {
  1587. if (!$this->additionalContacts->contains($user)) {
  1588. $this->additionalContacts[] = $user;
  1589. }
  1590. return $this;
  1591. }
  1592. /**
  1593. * Remove an additional contact
  1594. *
  1595. * @param User $user
  1596. *
  1597. * @return self
  1598. */
  1599. public function removeAdditionalContact(User $user): self
  1600. {
  1601. $this->additionalContacts->removeElement($user);
  1602. return $this;
  1603. }
  1604. // get a string of additional contacts by looping through the collection
  1605. /**
  1606. * Get a formatted string of additional contacts' full names.
  1607. *
  1608. * @return string
  1609. */
  1610. public function getAdditionalContactsFormatted(): string
  1611. {
  1612. $names = [];
  1613. foreach ($this->additionalContacts as $user) {
  1614. $names[] = $user->getFullName();
  1615. }
  1616. return implode(', ', $names);
  1617. }
  1618. /**
  1619. * Represented by a multi-dimensional array of field changes.
  1620. * Do not allow access to setter, use the addHistoricalApiValues method instead.
  1621. *
  1622. * @param null|array $historicalApiValues
  1623. *
  1624. * @return self
  1625. */
  1626. protected function setHistoricalApiValues(?array $historicalApiValues): self
  1627. {
  1628. $this->historicalApiValues = $historicalApiValues;
  1629. return $this;
  1630. }
  1631. }