src/Entity/Project.php line 610

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