src/Entity/Project.php line 666

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