src/Entity/Project.php line 1536

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