src/Entity/Project.php line 779

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