src/Entity/Project.php line 733

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