src/Entity/Project.php line 666

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