src/Entity/Project.php line 1542

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