src/Entity/Project.php line 1612

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