src/Entity/Project.php line 1592

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