src/Entity/Project.php line 1603

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