src/Entity/Project.php line 1199

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