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. 'Expert Reports' => $this->getExpertReportRequestCountsByStatus(),
  4083. ];
  4084. }
  4085. // @todo The below functions could probably all be rolled up in to one easy catchall
  4086. // like ::getServiceRequestCountByTypeAndStatus( $type, $status ) but only
  4087. // thought of it too late ┐('~`;)┌
  4088. /**
  4089. * Gets a count of all completed ServiceRequests given a specific Type
  4090. *
  4091. * @param $service_request_type
  4092. *
  4093. * @throws Exception
  4094. *
  4095. * @return int|mixed
  4096. */
  4097. public function getCompleteServiceRequestCountsByType($service_request_type)
  4098. {
  4099. switch ($service_request_type) {
  4100. case ServiceRequest::TYPE_RECORDS_REQUEST:
  4101. $serviceables = $this->getRecordsRequestsCountByServiceRequestStatus(false);
  4102. break;
  4103. case ServiceRequest::TYPE_BATCH_REQUEST:
  4104. $serviceables = $this->getBatchRequestsCountByServiceRequestStatus(false);
  4105. break;
  4106. case ServiceRequest::TYPE_CHRONOLOGY_REQUEST:
  4107. $serviceables = $this->getChronologyRequestsCountByServiceRequestStatus(false);
  4108. break;
  4109. case ServiceRequest::TYPE_ADDITIONAL_REQUEST:
  4110. $serviceables = $this->getAdditionalRequestsCountByServiceRequestStatus(false);
  4111. break;
  4112. case ServiceRequest::TYPE_EXPERT_REPORT:
  4113. $serviceables = $this->getExpertReportRequestsCountByServiceRequestStatus(false);
  4114. break;
  4115. default:
  4116. throw new Exception('Invalid Service Request Type.');
  4117. }
  4118. $complete = isset($serviceables[ServiceRequest::STATUS_COMPLETE]) ? $serviceables[ServiceRequest::STATUS_COMPLETE]['count'] : 0;
  4119. $releasedToClient = isset($serviceables[ServiceRequest::STATUS_RELEASED_TO_CLIENT]) ? $serviceables[ServiceRequest::STATUS_RELEASED_TO_CLIENT]['count'] : 0;
  4120. return $complete + $releasedToClient;
  4121. }
  4122. /**
  4123. * Gets a count of all in progress ServiceRequests given a specific Type
  4124. *
  4125. * @param $service_request_type
  4126. *
  4127. * @throws Exception
  4128. *
  4129. * @return int|mixed
  4130. */
  4131. public function getInProgressServiceRequestCountsByType($service_request_type)
  4132. {
  4133. switch ($service_request_type) {
  4134. case ServiceRequest::TYPE_RECORDS_REQUEST:
  4135. $serviceables = $this->getRecordsRequestsCountByServiceRequestStatus(false);
  4136. break;
  4137. case ServiceRequest::TYPE_BATCH_REQUEST:
  4138. $serviceables = $this->getBatchRequestsCountByServiceRequestStatus(false);
  4139. break;
  4140. case ServiceRequest::TYPE_CHRONOLOGY_REQUEST:
  4141. $serviceables = $this->getChronologyRequestsCountByServiceRequestStatus(false);
  4142. break;
  4143. case ServiceRequest::TYPE_ADDITIONAL_REQUEST:
  4144. $serviceables = $this->getAdditionalRequestsCountByServiceRequestStatus(false);
  4145. break;
  4146. case ServiceRequest::TYPE_EXPERT_REPORT:
  4147. $serviceables = $this->getExpertReportRequestsCountByServiceRequestStatus(false);
  4148. break;
  4149. default:
  4150. throw new Exception('Invalid Service Request Type.');
  4151. }
  4152. return isset($serviceables[ServiceRequest::STATUS_IN_PROGRESS]) ? $serviceables[ServiceRequest::STATUS_IN_PROGRESS]['count'] : 0;
  4153. }
  4154. /**
  4155. * Gets a count of all on hold ServiceRequests given a specific Type
  4156. *
  4157. * @param $service_request_type
  4158. *
  4159. * @throws Exception
  4160. *
  4161. * @return int|mixed
  4162. */
  4163. public function getOnHoldServiceRequestCountsByType($service_request_type)
  4164. {
  4165. switch ($service_request_type) {
  4166. case ServiceRequest::TYPE_RECORDS_REQUEST:
  4167. $serviceables = $this->getRecordsRequestsCountByServiceRequestStatus(false);
  4168. break;
  4169. case ServiceRequest::TYPE_BATCH_REQUEST:
  4170. $serviceables = $this->getBatchRequestsCountByServiceRequestStatus(false);
  4171. break;
  4172. case ServiceRequest::TYPE_CHRONOLOGY_REQUEST:
  4173. $serviceables = $this->getChronologyRequestsCountByServiceRequestStatus(false);
  4174. break;
  4175. case ServiceRequest::TYPE_ADDITIONAL_REQUEST:
  4176. $serviceables = $this->getAdditionalRequestsCountByServiceRequestStatus(false);
  4177. break;
  4178. case ServiceRequest::TYPE_EXPERT_REPORT:
  4179. $serviceables = $this->getExpertReportRequestsCountByServiceRequestStatus(false);
  4180. break;
  4181. default:
  4182. throw new Exception('Invalid Service Request Type.');
  4183. }
  4184. return isset($serviceables[ServiceRequest::STATUS_ON_HOLD]) ? $serviceables[ServiceRequest::STATUS_ON_HOLD]['count'] : 0;
  4185. }
  4186. /**
  4187. * Gets a count of all ServiceRequests awaiting records given a specific Type
  4188. *
  4189. * @param $service_request_type
  4190. *
  4191. * @throws Exception
  4192. *
  4193. * @return int|mixed
  4194. */
  4195. public function getPendingServiceRequestCountsByType($service_request_type)
  4196. {
  4197. switch ($service_request_type) {
  4198. case ServiceRequest::TYPE_RECORDS_REQUEST:
  4199. $serviceables = $this->getRecordsRequestsCountByServiceRequestStatus(false);
  4200. break;
  4201. case ServiceRequest::TYPE_BATCH_REQUEST:
  4202. $serviceables = $this->getBatchRequestsCountByServiceRequestStatus(false);
  4203. break;
  4204. case ServiceRequest::TYPE_CHRONOLOGY_REQUEST:
  4205. $serviceables = $this->getChronologyRequestsCountByServiceRequestStatus(false);
  4206. break;
  4207. case ServiceRequest::TYPE_ADDITIONAL_REQUEST:
  4208. $serviceables = $this->getAdditionalRequestsCountByServiceRequestStatus(false);
  4209. break;
  4210. case ServiceRequest::TYPE_EXPERT_REPORT:
  4211. $serviceables = $this->getExpertReportRequestsCountByServiceRequestStatus(false);
  4212. break;
  4213. default:
  4214. throw new Exception('Invalid Service Request Type.');
  4215. }
  4216. return isset($serviceables[ServiceRequest::STATUS_AWAITING_RECORDS]) ? $serviceables[ServiceRequest::STATUS_AWAITING_RECORDS]['count'] : 0;
  4217. }
  4218. /**
  4219. * Gets a count of all cancelled ServiceRequests given a specific Type
  4220. *
  4221. * @param $service_request_type
  4222. *
  4223. * @throws Exception
  4224. *
  4225. * @return int|mixed
  4226. */
  4227. public function getCancelledServiceRequestCountsByType($service_request_type)
  4228. {
  4229. switch ($service_request_type) {
  4230. case ServiceRequest::TYPE_RECORDS_REQUEST:
  4231. $serviceables = $this->getRecordsRequestsCountByServiceRequestStatus(false);
  4232. break;
  4233. case ServiceRequest::TYPE_BATCH_REQUEST:
  4234. $serviceables = $this->getBatchRequestsCountByServiceRequestStatus(false);
  4235. break;
  4236. case ServiceRequest::TYPE_CHRONOLOGY_REQUEST:
  4237. $serviceables = $this->getChronologyRequestsCountByServiceRequestStatus(false);
  4238. break;
  4239. case ServiceRequest::TYPE_ADDITIONAL_REQUEST:
  4240. $serviceables = $this->getAdditionalRequestsCountByServiceRequestStatus(false);
  4241. break;
  4242. case ServiceRequest::TYPE_EXPERT_REPORT:
  4243. $serviceables = $this->getExpertReportRequestsCountByServiceRequestStatus(false);
  4244. break;
  4245. default:
  4246. throw new Exception('Invalid Service Request Type.');
  4247. }
  4248. return isset($serviceables[ServiceRequest::STATUS_CANCELLED]) ? $serviceables[ServiceRequest::STATUS_CANCELLED]['count'] : 0;
  4249. }
  4250. /**
  4251. * Set team
  4252. *
  4253. * @param string $team
  4254. *
  4255. * @return Project
  4256. */
  4257. public function setTeam($team)
  4258. {
  4259. $this->team = $team;
  4260. // Update the associated matter request as well, if it exists, and if the values are different,
  4261. // to avoid a recursive loop.
  4262. if ($this->getMatterRequest() && $this->getMatterRequest()->getTeam() != $this->team) {
  4263. $this->getMatterRequest()->setTeam($this->team);
  4264. }
  4265. return $this;
  4266. }
  4267. /**
  4268. * Get team
  4269. *
  4270. * @return string
  4271. */
  4272. public function getTeam()
  4273. {
  4274. return $this->team;
  4275. }
  4276. /**
  4277. * Set defaultRole
  4278. *
  4279. * @param string $defaultRole
  4280. *
  4281. * @return Project
  4282. */
  4283. public function setDefaultRole($defaultRole)
  4284. {
  4285. $this->default_role = $defaultRole;
  4286. return $this;
  4287. }
  4288. /**
  4289. * Get defaultRole
  4290. *
  4291. * @return string
  4292. */
  4293. public function getDefaultRole()
  4294. {
  4295. return $this->default_role;
  4296. }
  4297. /**
  4298. * Get defaultRoleOptions
  4299. *
  4300. * @return array
  4301. */
  4302. public static function getDefaultRoleOptions()
  4303. {
  4304. return [
  4305. self::DEFAULT_ROLE_EXPERT => 'Expert',
  4306. self::DEFAULT_ROLE_EXPERTVIEWER => 'Expert - View Only',
  4307. self::DEFAULT_ROLE_SCANNER => 'Scanner',
  4308. self::DEFAULT_ROLE_SCANNERDOWNLOAD => 'Scanner - Download Enabled',
  4309. self::DEFAULT_ROLE_PROJECTMANAGER => 'Project Manager',
  4310. ];
  4311. }
  4312. /**
  4313. * Get DefaultRoleLabel
  4314. *
  4315. * @return int
  4316. */
  4317. public function getDefaultRoleLabel()
  4318. {
  4319. $options = self::getDefaultRoleOptions();
  4320. return $options[$this->getDefaultRole()] ?? '';
  4321. }
  4322. /**
  4323. * Get DefaultRoleLabel
  4324. *
  4325. * @return string
  4326. */
  4327. public function getDefaultRoleAsRole()
  4328. {
  4329. if (!$this->getDefaultRole()) {
  4330. return '';
  4331. }
  4332. return 'ROLE_PROJECT_' . $this->getId() . '_' . $this->getDefaultRole();
  4333. }
  4334. /**
  4335. * Get the disabled UserNotification types
  4336. *
  4337. * @return array
  4338. */
  4339. public function getDisabledNotifications()
  4340. {
  4341. return $this->disabled_notifications ?: [];
  4342. }
  4343. /**
  4344. * @param array $disabled_notifications
  4345. *
  4346. * @return Project
  4347. */
  4348. public function setDisabledNotifications($disabled_notifications): Project
  4349. {
  4350. $this->disabled_notifications = $disabled_notifications;
  4351. return $this;
  4352. }
  4353. /**
  4354. * Disable a notification
  4355. *
  4356. * @param $notification_type
  4357. *
  4358. * @return Project
  4359. */
  4360. public function disableNotification($notification_type): Project
  4361. {
  4362. $this->disabled_notifications[] = $notification_type;
  4363. return $this;
  4364. }
  4365. /**
  4366. * Function to determine if the specific UserNotification is disabled for this Entity
  4367. *
  4368. * @param $notification_type
  4369. *
  4370. * @return bool
  4371. */
  4372. public function isNotificationDisabled($notification_type)
  4373. {
  4374. if (!$this->disabled_notifications || count($this->disabled_notifications) == 0) {
  4375. return false;
  4376. }
  4377. return in_array($notification_type, $this->disabled_notifications) ? true : false;
  4378. }
  4379. /**
  4380. * Add sortingSession
  4381. *
  4382. * @param SortingSession $sortingSession
  4383. *
  4384. * @return Project
  4385. */
  4386. public function addSortingSession(SortingSession $sortingSession)
  4387. {
  4388. $this->sortingSessions[] = $sortingSession;
  4389. return $this;
  4390. }
  4391. /**
  4392. * Remove sortingSession
  4393. *
  4394. * @param SortingSession $sortingSession
  4395. */
  4396. public function removeSortingSession(SortingSession $sortingSession)
  4397. {
  4398. $this->sortingSessions->removeElement($sortingSession);
  4399. }
  4400. /**
  4401. * Get sortingSessions
  4402. *
  4403. * @return DoctrineCollection|SortingSession[]
  4404. */
  4405. public function getSortingSessions()
  4406. {
  4407. return $this->sortingSessions;
  4408. }
  4409. /**
  4410. * Get completedSortingSessions
  4411. *
  4412. * @return ArrayCollection|DoctrineCollection|Collection
  4413. */
  4414. public function getCompletedSortingSessions()
  4415. {
  4416. return $this->getSortingSessions()->filter(
  4417. function ($sortingSession) {
  4418. return $sortingSession->hasBeenCompleted();
  4419. }
  4420. );
  4421. }
  4422. /**
  4423. * @return bool
  4424. */
  4425. public function hasIncompleteSortingSessions(): bool
  4426. {
  4427. foreach ($this->getSortingSessions() as $sortingSession) {
  4428. if (!$sortingSession->hasBeenCompleted() && !$sortingSession->isSortStatusDownloaded()) {
  4429. return true;
  4430. }
  4431. }
  4432. return false;
  4433. }
  4434. /**
  4435. * Returns true if there are any incomplete serviceables on the project.
  4436. * This is used to block a project from being archived or deleted when work is still on-going.
  4437. *
  4438. * @return bool
  4439. */
  4440. public function hasIncompleteServiceables(): bool
  4441. {
  4442. foreach ($this->getRecordsRequests() as $recordsRequest) {
  4443. $incompleteStatuses = [
  4444. ServiceRequest::STATUS_IN_PROGRESS,
  4445. ServiceRequest::STATUS_ON_HOLD,
  4446. ];
  4447. if ($recordsRequest->getServiceRequest() && in_array($recordsRequest->getServiceRequest()->getStatus(), $incompleteStatuses)) {
  4448. return true;
  4449. }
  4450. }
  4451. foreach ($this->getBatchRequests() as $batchRequest) {
  4452. $incompleteStatuses = [
  4453. ServiceRequest::STATUS_IN_PROGRESS,
  4454. ServiceRequest::STATUS_AWAITING_RECORDS,
  4455. ServiceRequest::STATUS_ON_HOLD,
  4456. ];
  4457. if ($batchRequest->getServiceRequest() && in_array($batchRequest->getServiceRequest()->getStatus(), $incompleteStatuses)) {
  4458. return true;
  4459. }
  4460. }
  4461. foreach ($this->getChronologyRequests() as $chronologyRequest) {
  4462. $incompleteStatuses = [
  4463. ServiceRequest::STATUS_INSTRUCTED,
  4464. ServiceRequest::STATUS_IN_PROGRESS,
  4465. ServiceRequest::STATUS_ON_HOLD,
  4466. ];
  4467. if ($chronologyRequest->getServiceRequest() && in_array($chronologyRequest->getServiceRequest()->getStatus(), $incompleteStatuses)) {
  4468. return true;
  4469. }
  4470. }
  4471. foreach ($this->getExpertReportRequests() as $expertReportRequest) {
  4472. $incompleteStatuses = [
  4473. ServiceRequest::STATUS_INSTRUCTED,
  4474. ServiceRequest::STATUS_IN_PROGRESS,
  4475. ServiceRequest::STATUS_ON_HOLD,
  4476. ];
  4477. if ($expertReportRequest->getServiceRequest() && in_array($expertReportRequest->getServiceRequest()->getStatus(), $incompleteStatuses)) {
  4478. return true;
  4479. }
  4480. }
  4481. foreach ($this->getAdditionalRequests() as $additionalRequest) {
  4482. $incompleteStatuses = [
  4483. ServiceRequest::STATUS_IN_PROGRESS,
  4484. ServiceRequest::STATUS_ON_HOLD,
  4485. ];
  4486. if ($additionalRequest->getServiceRequest() && in_array($additionalRequest->getServiceRequest()->getStatus(), $incompleteStatuses)) {
  4487. return true;
  4488. }
  4489. }
  4490. // Finally, we check if there are incomplete sorting sessions.
  4491. return $this->hasIncompleteSortingSessions();
  4492. }
  4493. /**
  4494. * Add matterNote
  4495. *
  4496. * @param MatterNote $matterNote
  4497. *
  4498. * @return Project
  4499. */
  4500. public function addMatterNote(MatterNote $matterNote)
  4501. {
  4502. $this->matterNotes[] = $matterNote;
  4503. $matterNote->setProject($this);
  4504. return $this;
  4505. }
  4506. /**
  4507. * Remove matterNote
  4508. *
  4509. * @param MatterNote $matterNote
  4510. */
  4511. public function removeMatterNote(MatterNote $matterNote)
  4512. {
  4513. $this->matterNotes->removeElement($matterNote);
  4514. }
  4515. /**
  4516. * Get matterNotes
  4517. *
  4518. * @return DoctrineCollection|MatterNote[]
  4519. */
  4520. public function getMatterNotes()
  4521. {
  4522. return $this->matterNotes;
  4523. }
  4524. /**
  4525. * @return array
  4526. */
  4527. public function getNoteCounts(): array
  4528. {
  4529. $noteCounts = [];
  4530. foreach ($this->getMatterNotes() as $note) {
  4531. if (!isset($noteCounts[$note->getType()])) {
  4532. $noteCounts[$note->getType()] = 0;
  4533. }
  4534. $noteCounts[$note->getType()]++;
  4535. }
  4536. return $noteCounts;
  4537. }
  4538. /**
  4539. * Set unsortedRecordsCollection.
  4540. *
  4541. * @param Collection|null $unsortedRecordsCollection
  4542. *
  4543. * @return Project
  4544. */
  4545. public function setUnsortedRecordsCollection(?Collection $unsortedRecordsCollection = null)
  4546. {
  4547. $this->unsortedRecordsCollection = $unsortedRecordsCollection;
  4548. return $this;
  4549. }
  4550. /**
  4551. * Set requirePasswordOnDownload.
  4552. *
  4553. * @param bool $requirePasswordOnDownload
  4554. *
  4555. * @return Project
  4556. */
  4557. public function setRequirePasswordOnDownload($requirePasswordOnDownload)
  4558. {
  4559. $this->require_password_on_download = $requirePasswordOnDownload;
  4560. return $this;
  4561. }
  4562. /**
  4563. * Get unsortedRecordsCollection.
  4564. *
  4565. * @return Collection|null
  4566. */
  4567. public function getUnsortedRecordsCollection()
  4568. {
  4569. return $this->unsortedRecordsCollection;
  4570. }
  4571. /**
  4572. * Get requirePasswordOnDownload.
  4573. *
  4574. * @return bool
  4575. */
  4576. public function getRequirePasswordOnDownload()
  4577. {
  4578. return $this->require_password_on_download;
  4579. }
  4580. /**
  4581. * Set inviteUserMustAuthenticate.
  4582. *
  4583. * @param bool $inviteUserMustAuthenticate
  4584. *
  4585. * @return Project
  4586. */
  4587. public function setInviteUserMustAuthenticate($inviteUserMustAuthenticate)
  4588. {
  4589. $this->inviteUserMustAuthenticate = $inviteUserMustAuthenticate;
  4590. return $this;
  4591. }
  4592. /**
  4593. * Get inviteUserMustAuthenticate.
  4594. *
  4595. * @return bool
  4596. */
  4597. public function getInviteUserMustAuthenticate()
  4598. {
  4599. return $this->inviteUserMustAuthenticate;
  4600. }
  4601. /**
  4602. * Set inviteUserPassword.
  4603. *
  4604. * @param string $inviteUserPassword
  4605. *
  4606. * @return Project
  4607. */
  4608. public function setInviteUserPassword($inviteUserPassword)
  4609. {
  4610. $this->inviteUserPassword = $inviteUserPassword;
  4611. return $this;
  4612. }
  4613. /**
  4614. * Get inviteUserPassword.
  4615. *
  4616. * @return string
  4617. */
  4618. public function getInviteUserPassword()
  4619. {
  4620. return $this->inviteUserPassword;
  4621. }
  4622. /**
  4623. * Set inviteUserContactName.
  4624. *
  4625. * @param string|null $inviteUserContactName
  4626. *
  4627. * @return Project
  4628. */
  4629. public function setInviteUserContactName($inviteUserContactName = null)
  4630. {
  4631. $this->inviteUserContactName = $inviteUserContactName;
  4632. return $this;
  4633. }
  4634. /**
  4635. * Get inviteUserContactName.
  4636. *
  4637. * @return string|null
  4638. */
  4639. public function getInviteUserContactName()
  4640. {
  4641. return $this->inviteUserContactName;
  4642. }
  4643. /**
  4644. * Set inviteUserContactEmail.
  4645. *
  4646. * @param string|null $inviteUserContactEmail
  4647. *
  4648. * @return Project
  4649. */
  4650. public function setInviteUserContactEmail($inviteUserContactEmail = null)
  4651. {
  4652. $this->inviteUserContactEmail = $inviteUserContactEmail;
  4653. return $this;
  4654. }
  4655. /**
  4656. * Get inviteUserContactEmail.
  4657. *
  4658. * @return string|null
  4659. */
  4660. public function getInviteUserContactEmail()
  4661. {
  4662. return $this->inviteUserContactEmail;
  4663. }
  4664. /**
  4665. * Set inviteUserContactPhoneNumber.
  4666. *
  4667. * @param string|null $inviteUserContactPhoneNumber
  4668. *
  4669. * @return Project
  4670. */
  4671. public function setInviteUserContactPhoneNumber($inviteUserContactPhoneNumber = null)
  4672. {
  4673. $this->inviteUserContactPhoneNumber = $inviteUserContactPhoneNumber;
  4674. return $this;
  4675. }
  4676. /**
  4677. * Get inviteUserContactPhoneNumber.
  4678. *
  4679. * @return string|null
  4680. */
  4681. public function getInviteUserContactPhoneNumber()
  4682. {
  4683. return $this->inviteUserContactPhoneNumber;
  4684. }
  4685. /**
  4686. * Tells if the contact type is Email.
  4687. *
  4688. * @return bool
  4689. */
  4690. public function isInviteUserContactTypeEmail()
  4691. {
  4692. return !is_null($this->getInviteUserContactEmail());
  4693. }
  4694. /**
  4695. * Tells if the contact type is Phone.
  4696. *
  4697. * @return bool
  4698. */
  4699. public function isInviteUserContactTypePhone()
  4700. {
  4701. return !is_null($this->getInviteUserContactPhoneNumber());
  4702. }
  4703. /**
  4704. * Set dateOnLetter.
  4705. *
  4706. * @param DateTime|null $dateOnLetter
  4707. *
  4708. * @return Project
  4709. */
  4710. public function setDateOnLetter($dateOnLetter = null)
  4711. {
  4712. $this->date_on_letter = $dateOnLetter;
  4713. return $this;
  4714. }
  4715. /**
  4716. * Get dateOnLetter.
  4717. *
  4718. * @return DateTime|null
  4719. */
  4720. public function getDateOnLetter()
  4721. {
  4722. return $this->date_on_letter;
  4723. }
  4724. /**
  4725. * Set caseMeritsAnalysis.
  4726. *
  4727. * @param string|null $caseMeritsAnalysis
  4728. *
  4729. * @return Project
  4730. */
  4731. public function setCaseMeritsAnalysis($caseMeritsAnalysis = null)
  4732. {
  4733. $this->case_merits_analysis = $caseMeritsAnalysis;
  4734. return $this;
  4735. }
  4736. /**
  4737. * Get caseMeritsAnalysis.
  4738. *
  4739. * @return string|null
  4740. */
  4741. public function getCaseMeritsAnalysis()
  4742. {
  4743. return $this->case_merits_analysis;
  4744. }
  4745. /**
  4746. * Returns an array of permitted values for the case_merits_analysis field and their
  4747. * associated labels.
  4748. *
  4749. * @return array
  4750. */
  4751. public static function getCaseMeritsAnalysisOptions()
  4752. {
  4753. return [
  4754. self::CASE_MERITS_ANALYSIS_SUPPORTIVE => 'Supportive',
  4755. self::CASE_MERITS_ANALYSIS_UNSUPPORTIVE => 'Unsupportive',
  4756. self::CASE_MERITS_ANALYSIS_INCONCLUSIVE => 'Inconclusive',
  4757. ];
  4758. }
  4759. /**
  4760. * Returns a human-readable version of the case_merits_analysis
  4761. *
  4762. * @return string
  4763. */
  4764. public function getCaseMeritsAnalysisName()
  4765. {
  4766. $options = self::getCaseMeritsAnalysisOptions();
  4767. return
  4768. $options[$this->getCaseMeritsAnalysis()] ?? $this->getCaseMeritsAnalysis();
  4769. }
  4770. /**
  4771. * Set claimantSolicitor.
  4772. *
  4773. * @param string|null $claimantSolicitor
  4774. *
  4775. * @return Project
  4776. */
  4777. public function setClaimantSolicitor($claimantSolicitor = null)
  4778. {
  4779. $this->claimant_solicitor = $claimantSolicitor;
  4780. return $this;
  4781. }
  4782. /**
  4783. * Get claimantSolicitor.
  4784. *
  4785. * @return string|null
  4786. */
  4787. public function getClaimantSolicitor()
  4788. {
  4789. return $this->claimant_solicitor;
  4790. }
  4791. /**
  4792. * Set typeOfLetter.
  4793. *
  4794. * @param string|null $typeOfLetter
  4795. *
  4796. * @return Project
  4797. */
  4798. public function setTypeOfLetter($typeOfLetter = null)
  4799. {
  4800. $this->type_of_letter = $typeOfLetter;
  4801. return $this;
  4802. }
  4803. /**
  4804. * Get typeOfLetter.
  4805. *
  4806. * @return string|null
  4807. */
  4808. public function getTypeOfLetter()
  4809. {
  4810. return $this->type_of_letter;
  4811. }
  4812. /**
  4813. * Returns an array of permitted values for the type_of_letter field and their
  4814. * associated labels.
  4815. *
  4816. * @return array
  4817. */
  4818. public static function getTypeOfLetterOptions()
  4819. {
  4820. return [
  4821. self::TYPE_OF_LETTER_LETTER_OF_CLAIM => 'Letter of claim',
  4822. self::TYPE_OF_LETTER_LETTER_OF_NOTIFICATION => 'Letter of notification',
  4823. self::TYPE_OF_LETTER_SUBJECT_ACCESS_REQUEST => 'Subject access request',
  4824. self::TYPE_OF_LETTER_DISCLOSURE_APPLICATION => 'Disclosure application',
  4825. ];
  4826. }
  4827. /**
  4828. * Returns a human-readable version of the type_of_letter
  4829. *
  4830. * @return string
  4831. */
  4832. public function getTypeOfLetterName()
  4833. {
  4834. $options = self::getTypeOfLetterOptions();
  4835. return
  4836. $options[$this->getTypeOfLetter()] ?? $this->getTypeOfLetter();
  4837. }
  4838. /**
  4839. * Set reviewType.
  4840. *
  4841. * @param string|null $reviewType
  4842. *
  4843. * @return Project
  4844. */
  4845. public function setReviewType($reviewType = null)
  4846. {
  4847. $this->review_type = $reviewType;
  4848. return $this;
  4849. }
  4850. /**
  4851. * Get reviewType.
  4852. *
  4853. * @return string|null
  4854. */
  4855. public function getReviewType()
  4856. {
  4857. return $this->review_type;
  4858. }
  4859. /**
  4860. * Returns an array of permitted values for the review_type field and their
  4861. * associated labels.
  4862. *
  4863. * @return array
  4864. */
  4865. public static function getReviewTypeOptions()
  4866. {
  4867. return [
  4868. self::REVIEW_TYPE_CASE_MERITS_ANALYSIS => 'Case merits analysis',
  4869. self::REVIEW_TYPE_CHRONOLOGY => 'Chronology',
  4870. ];
  4871. }
  4872. /**
  4873. * Returns a human-readable version of the review_type
  4874. *
  4875. * @return string
  4876. */
  4877. public function getReviewTypeName()
  4878. {
  4879. $options = self::getReviewTypeOptions();
  4880. return
  4881. $options[$this->getReviewType()] ?? $this->getReviewType();
  4882. }
  4883. /**
  4884. * Set expertsReportDate.
  4885. *
  4886. * @param DateTime|null $expertsReportDate
  4887. *
  4888. * @return Project
  4889. */
  4890. public function setExpertsReportDate($expertsReportDate = null)
  4891. {
  4892. $this->experts_report_date = $expertsReportDate;
  4893. return $this;
  4894. }
  4895. /**
  4896. * Get expertsReportDate.
  4897. *
  4898. * @return DateTime|null
  4899. */
  4900. public function getExpertsReportDate()
  4901. {
  4902. return $this->experts_report_date;
  4903. }
  4904. /**
  4905. * Set letterOfResponseAndExpertReportRequestDate.
  4906. *
  4907. * @param DateTime|null $letterOfResponseAndExpertReportRequestDate
  4908. *
  4909. * @return Project
  4910. */
  4911. public function setLetterOfResponseAndExpertReportRequestDate($letterOfResponseAndExpertReportRequestDate = null)
  4912. {
  4913. $this->letter_of_response_and_expert_report_date = $letterOfResponseAndExpertReportRequestDate;
  4914. return $this;
  4915. }
  4916. /**
  4917. * Get letterOfResponseAndExpertReportRequestDate.
  4918. *
  4919. * @return DateTime|null
  4920. */
  4921. public function getLetterOfResponseAndExpertReportRequestDate()
  4922. {
  4923. return $this->letter_of_response_and_expert_report_date;
  4924. }
  4925. /**
  4926. * Set letterOfResponsePreparedDate.
  4927. *
  4928. * @param DateTime|null $letterOfResponsePreparedDate
  4929. *
  4930. * @return Project
  4931. */
  4932. public function setLetterOfResponsePreparedDate($letterOfResponsePreparedDate = null)
  4933. {
  4934. $this->letter_of_response_prepared_date = $letterOfResponsePreparedDate;
  4935. return $this;
  4936. }
  4937. /**
  4938. * Get letterOfResponsePreparedDate.
  4939. *
  4940. * @return DateTime|null
  4941. */
  4942. public function getLetterOfResponsePreparedDate()
  4943. {
  4944. return $this->letter_of_response_prepared_date;
  4945. }
  4946. /**
  4947. * Set letterOfResponseSentDate.
  4948. *
  4949. * @param DateTime|null $letterOfResponseSentDate
  4950. *
  4951. * @return Project
  4952. */
  4953. public function setLetterOfResponseSentDate($letterOfResponseSentDate = null)
  4954. {
  4955. $this->letter_of_response_sent_date = $letterOfResponseSentDate;
  4956. return $this;
  4957. }
  4958. /**
  4959. * Get letterOfResponseSentDate.
  4960. *
  4961. * @return DateTime|null
  4962. */
  4963. public function getLetterOfResponseSentDate()
  4964. {
  4965. return $this->letter_of_response_sent_date;
  4966. }
  4967. public static function loadValidatorMetadata(ClassMetadata $metadata)
  4968. {
  4969. $metadata->addConstraint(new Assert\Callback('validate'));
  4970. }
  4971. public function validate(ExecutionContextInterface $context, $payload)
  4972. {
  4973. if ($this->getInviteUserMustAuthenticate()) {
  4974. $password = $this->getinviteUserPassword();
  4975. // If the password has not already been set, validate the plainPassword.
  4976. if (is_null($password)) {
  4977. $plainPassword = $this->getinviteUserPlainPassword();
  4978. $constraints = [
  4979. new Assert\Regex([
  4980. 'pattern' => '/(?=.*[A-Z])(?=.*[a-z])(?=.*[0-9])(?=.*[\d])(?=.*[\W]).{8,}/',
  4981. '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.',
  4982. ]),
  4983. new Assert\NotBlank([]),
  4984. new Assert\Length([
  4985. 'min' => 8,
  4986. 'max' => 255,
  4987. 'minMessage' => 'Your password must have at least {{ limit }} characters.',
  4988. 'maxMessage' => 'The password is too long.',
  4989. ]),
  4990. ];
  4991. $validator = Validation::createValidator();
  4992. foreach ($constraints as $constraint) {
  4993. $errors = $validator->validate(
  4994. $plainPassword,
  4995. $constraint
  4996. );
  4997. if (0 !== count($errors)) {
  4998. $errorMessage = $errors[0]->getMessage();
  4999. $context->buildViolation($errorMessage)
  5000. ->atPath('inviteUserPlainPassword')
  5001. ->addViolation()
  5002. ;
  5003. }
  5004. }
  5005. }
  5006. if (is_null($this->getInviteUserContactName())) {
  5007. $errorMessage = 'Contact name required.';
  5008. $context->buildViolation($errorMessage)
  5009. ->atPath('inviteUserContactName')
  5010. ->addViolation()
  5011. ;
  5012. }
  5013. if (is_null($this->getInviteUserContactEmail())
  5014. && is_null($this->getInviteUserContactPhoneNumber())
  5015. ) {
  5016. $errorMessage = 'Contact email address or phone number required.';
  5017. $context->buildViolation($errorMessage)
  5018. ->atPath('inviteUserContactEmail')
  5019. ->addViolation()
  5020. ;
  5021. $context->buildViolation($errorMessage)
  5022. ->atPath('inviteUserContactPhoneNumber')
  5023. ->addViolation()
  5024. ;
  5025. }
  5026. }
  5027. }
  5028. /**
  5029. * Set matterRequest.
  5030. *
  5031. * @param MatterRequest|null $matterRequest
  5032. *
  5033. * @return Project
  5034. */
  5035. public function setMatterRequest(?MatterRequest $matterRequest = null)
  5036. {
  5037. $this->matterRequest = $matterRequest;
  5038. return $this;
  5039. }
  5040. /**
  5041. * Get matterRequest.
  5042. *
  5043. * @return MatterRequest|null
  5044. */
  5045. public function getMatterRequest()
  5046. {
  5047. return $this->matterRequest;
  5048. }
  5049. /**
  5050. * Returns a radiology schedule array grouped by study of all related radiology on a project.
  5051. *
  5052. * @return array
  5053. */
  5054. public function getRadiologyScheduleArray()
  5055. {
  5056. $data = [];
  5057. $serieses = $this->getSeries();
  5058. /** @var Series $series */
  5059. foreach ($serieses as $series) {
  5060. // Grab the Study this Series is in
  5061. $study = $series->getStudy();
  5062. if ($study) {
  5063. // Skip studies that have no active (non-deleted) discs
  5064. $activeDiscs = $study->getDiscs()->filter(function (Disc $disc) {
  5065. return $disc->isActive() && $disc->getDeletedAt() === null;
  5066. });
  5067. if ($activeDiscs->isEmpty()) {
  5068. continue;
  5069. }
  5070. // Having named keys here isn't really necessary but we might want them later for something
  5071. // If we have Discs, we can fill out the `source` and `number` fields
  5072. $data[$study->getId()] = [
  5073. 'id' => $study->getId(),
  5074. 'matter' => $this->getClientReference(),
  5075. 'patient' => $study->getPatient()->getDicomPatientName(),
  5076. 'date' => $study->getStudyDate(),
  5077. 'description' => $study->getStudyDescription(),
  5078. 'centre' => $study->getStudyInstituteName(),
  5079. 'discs' => $study->getDiscs(),
  5080. 'longDescription' => $study->__toString(),
  5081. ];
  5082. }
  5083. }
  5084. usort($data, function ($a, $b) {
  5085. return strcmp($a['longDescription'], $b['longDescription']);
  5086. });
  5087. return $data;
  5088. }
  5089. /**
  5090. * Add matterCommunication.
  5091. *
  5092. * @param MatterCommunication $matterCommunication
  5093. *
  5094. * @return Project
  5095. */
  5096. public function addMatterCommunication(MatterCommunication $matterCommunication)
  5097. {
  5098. $this->matterCommunications[] = $matterCommunication;
  5099. return $this;
  5100. }
  5101. /**
  5102. * Remove matterCommunication.
  5103. *
  5104. * @param MatterCommunication $matterCommunication
  5105. *
  5106. * @return bool TRUE if this collection contained the specified element, FALSE otherwise.
  5107. */
  5108. public function removeMatterCommunication(MatterCommunication $matterCommunication)
  5109. {
  5110. return $this->matterCommunications->removeElement($matterCommunication);
  5111. }
  5112. /**
  5113. * Get matterCommunications.
  5114. *
  5115. * @return DoctrineCollection|MatterCommunication[]
  5116. */
  5117. public function getMatterCommunications()
  5118. {
  5119. return $this->matterCommunications;
  5120. }
  5121. /**
  5122. * Set deleteStatus
  5123. *
  5124. * @param int $deleteStatus
  5125. *
  5126. * @return Project
  5127. */
  5128. public function setDeleteStatus(?int $deleteStatus = null)
  5129. {
  5130. if ($this->deleteStatus !== $deleteStatus) {
  5131. $this->setDeleteStatusUpdated(new DateTime());
  5132. }
  5133. $this->deleteStatus = $deleteStatus;
  5134. return $this;
  5135. }
  5136. /**
  5137. * Get deleteStatus
  5138. *
  5139. * @return int
  5140. */
  5141. public function getDeleteStatus()
  5142. {
  5143. return $this->deleteStatus;
  5144. }
  5145. /**
  5146. * Return true if deletestatus is equal to the constants below
  5147. *
  5148. * @return bool
  5149. */
  5150. public function hasDeleteStatus()
  5151. {
  5152. $statuses = [
  5153. self::DELETE_STATUS_PENDING,
  5154. self::DELETE_STATUS_REMINDER_SENT,
  5155. self::DELETE_STATUS_PROCESSING,
  5156. self::DELETE_STATUS_COMPLETE,
  5157. ];
  5158. return in_array($this->getDeleteStatus(), $statuses);
  5159. }
  5160. /**
  5161. * Set deleteStatusUpdated
  5162. *
  5163. * @param DateTime $deleteStatusUpdated
  5164. *
  5165. * @return Project
  5166. */
  5167. public function setDeleteStatusUpdated(?DateTime $deleteStatusUpdated = null)
  5168. {
  5169. $this->deleteStatusUpdated = $deleteStatusUpdated;
  5170. return $this;
  5171. }
  5172. /**
  5173. * Get deleteStatusUpdated
  5174. *
  5175. * @return DateTime
  5176. */
  5177. public function getDeleteStatusUpdated()
  5178. {
  5179. return $this->deleteStatusUpdated;
  5180. }
  5181. /**
  5182. * Get archiveStatus as Label
  5183. *
  5184. * @return string
  5185. */
  5186. public function getArchiveStatusLabel()
  5187. {
  5188. $archiveStatusOptions = array_flip(static::getConstantsWithLabelsAsChoices('ARCHIVE_STATUS'));
  5189. return $archiveStatusOptions[$this->getArchiveStatus()] ?? '';
  5190. }
  5191. /**
  5192. * @return array
  5193. */
  5194. public static function getArchiveStatusChoices()
  5195. {
  5196. return static::getConstantsWithLabelsAsChoices('ARCHIVE_STATUS');
  5197. }
  5198. /**
  5199. * @return array
  5200. */
  5201. public static function getDeleteStatusChoices()
  5202. {
  5203. return static::getConstantsWithLabelsAsChoices('DELETE_STATUS');
  5204. }
  5205. /**
  5206. * Return true if matter is in the process of being deleted/archived, or is deleted or archived
  5207. *
  5208. * @return bool
  5209. */
  5210. public function isCloseInProgressOrComplete()
  5211. {
  5212. $archiveStatuses = [
  5213. self::ARCHIVE_STATUS_PENDING,
  5214. self::ARCHIVE_STATUS_PROCESSING,
  5215. self::ARCHIVE_STATUS_UNARCHIVE_PROCESSING,
  5216. self::ARCHIVE_STATUS_COMPLETE,
  5217. ];
  5218. $deleteStatuses = [
  5219. self::DELETE_STATUS_PENDING,
  5220. self::DELETE_STATUS_REMINDER_SENT,
  5221. self::DELETE_STATUS_PROCESSING,
  5222. self::DELETE_STATUS_COMPLETE,
  5223. self::DELETE_STATUS_DELETE_FAILED,
  5224. self::DELETE_STATUS_ANONYMISE_FAILED,
  5225. ];
  5226. return in_array($this->getArchiveStatus(), $archiveStatuses, true) || in_array($this->getDeleteStatus(), $deleteStatuses, true);
  5227. }
  5228. /**
  5229. * Return true if project status is active
  5230. *
  5231. * @return bool
  5232. */
  5233. public function isStatusActive()
  5234. {
  5235. return $this->getStatus() === self::STATUS_ACTIVE;
  5236. }
  5237. /**
  5238. * Return true if project archive status is pending
  5239. *
  5240. * @return bool
  5241. */
  5242. public function isArchiveStatusPending()
  5243. {
  5244. return $this->getArchiveStatus() === self::ARCHIVE_STATUS_PENDING;
  5245. }
  5246. /**
  5247. * Return true if project archive status is processing
  5248. *
  5249. * @return bool
  5250. */
  5251. public function isArchiveStatusProcessing()
  5252. {
  5253. return $this->getArchiveStatus() === self::ARCHIVE_STATUS_PROCESSING;
  5254. }
  5255. /**
  5256. * Return true if project archive status is complete
  5257. *
  5258. * @return bool
  5259. */
  5260. public function isArchiveStatusComplete()
  5261. {
  5262. return $this->getArchiveStatus() === self::ARCHIVE_STATUS_COMPLETE;
  5263. }
  5264. /**
  5265. * Return true if project archive status is unarchive in process
  5266. *
  5267. * @return bool
  5268. */
  5269. public function isArchiveStatusUnarchiveProcessing()
  5270. {
  5271. return $this->getArchiveStatus() === self::ARCHIVE_STATUS_UNARCHIVE_PROCESSING;
  5272. }
  5273. /**
  5274. * Return true if matter is in the process of being deleted/archived
  5275. *
  5276. * @return bool
  5277. */
  5278. public function isQueuedForArchiveOrDeletion(): bool
  5279. {
  5280. $archiveStatuses = [
  5281. self::ARCHIVE_STATUS_PENDING,
  5282. self::ARCHIVE_STATUS_PROCESSING,
  5283. self::ARCHIVE_STATUS_UNARCHIVE_PROCESSING,
  5284. ];
  5285. $deleteStatuses = [
  5286. self::DELETE_STATUS_PENDING,
  5287. self::DELETE_STATUS_REMINDER_SENT,
  5288. self::DELETE_STATUS_PROCESSING,
  5289. ];
  5290. return in_array($this->getArchiveStatus(), $archiveStatuses, true) || in_array($this->getDeleteStatus(), $deleteStatuses, true);
  5291. }
  5292. /**
  5293. * Return true if archive status is equal to the constants below
  5294. *
  5295. * @return bool
  5296. */
  5297. public function hasArchiveStatus(): bool
  5298. {
  5299. $statuses = [
  5300. self::ARCHIVE_STATUS_PENDING,
  5301. self::ARCHIVE_STATUS_PROCESSING,
  5302. self::ARCHIVE_STATUS_COMPLETE,
  5303. self::ARCHIVE_STATUS_UNARCHIVE_PROCESSING,
  5304. ];
  5305. return in_array($this->getArchiveStatus(), $statuses);
  5306. }
  5307. /**
  5308. * Get deleteStatus as Label
  5309. *
  5310. * @return string
  5311. */
  5312. public function getDeleteStatusLabel()
  5313. {
  5314. $deleteStatusOptions = array_flip(static::getConstantsWithLabelsAsChoices('DELETE_STATUS'));
  5315. return $deleteStatusOptions[$this->getDeleteStatus()] ?? '';
  5316. }
  5317. /**
  5318. * Return true if project delete status is pending
  5319. *
  5320. * @return bool
  5321. */
  5322. public function isDeleteStatusPending()
  5323. {
  5324. return $this->getDeleteStatus() === self::DELETE_STATUS_PENDING;
  5325. }
  5326. /**
  5327. * Return true if project delete status is pending immediate deletion.
  5328. *
  5329. * @return bool
  5330. */
  5331. public function isDeleteStatusPendingImmediate()
  5332. {
  5333. return $this->getDeleteStatus() === self::DELETE_STATUS_PENDING_IMMEDIATE;
  5334. }
  5335. /**
  5336. * Return true if project delete status is reminder sent
  5337. *
  5338. * @return bool
  5339. */
  5340. public function isDeleteStatusReminderSent()
  5341. {
  5342. return $this->getDeleteStatus() === self::DELETE_STATUS_REMINDER_SENT;
  5343. }
  5344. /**
  5345. * Return true if project delete status is processing
  5346. *
  5347. * @return bool
  5348. */
  5349. public function isDeleteStatusProcessing()
  5350. {
  5351. return $this->getDeleteStatus() === self::DELETE_STATUS_PROCESSING;
  5352. }
  5353. /**
  5354. * Return true if project delete status is complete
  5355. *
  5356. * @return bool
  5357. */
  5358. public function isDeleteStatusComplete()
  5359. {
  5360. return $this->getDeleteStatus() === self::DELETE_STATUS_COMPLETE;
  5361. }
  5362. /**
  5363. * Return true if project delete status is failed
  5364. *
  5365. * @return bool
  5366. */
  5367. public function isDeleteStatusFailed()
  5368. {
  5369. return $this->getDeleteStatus() === self::DELETE_STATUS_DELETE_FAILED;
  5370. }
  5371. /**
  5372. * Return true if the Project can be deleted.
  5373. *
  5374. * @return bool
  5375. */
  5376. public function canBeDeleted(): bool
  5377. {
  5378. return $this->isDeleteStatusReminderSent() || $this->isDeleteStatusProcessing();
  5379. }
  5380. /**
  5381. * Returns true if the project is queued for deletion.
  5382. *
  5383. * @return bool
  5384. */
  5385. public function isQueuedForDeletion(): bool
  5386. {
  5387. return $this->isDeleteStatusPending() || $this->isDeleteStatusReminderSent() || $this->isDeleteStatusPendingImmediate();
  5388. }
  5389. /**
  5390. * Return true if matter is in the process of being deleted/archived, and is not in the queue to be closed
  5391. *
  5392. * @return bool
  5393. */
  5394. public function isCloseInProgress()
  5395. {
  5396. $archiveStatuses = [
  5397. self::ARCHIVE_STATUS_PROCESSING,
  5398. self::ARCHIVE_STATUS_UNARCHIVE_PROCESSING,
  5399. ];
  5400. $deleteStatuses = [
  5401. self::DELETE_STATUS_PROCESSING,
  5402. ];
  5403. return in_array($this->getArchiveStatus(), $archiveStatuses, true) || in_array($this->getDeleteStatus(), $deleteStatuses, true);
  5404. }
  5405. /**
  5406. * Return true if matter deletion is complete
  5407. *
  5408. * @return bool
  5409. */
  5410. public function isDeleteComplete()
  5411. {
  5412. return $this->getDeleteStatus() === self::DELETE_STATUS_COMPLETE;
  5413. }
  5414. /**
  5415. * Returns the User that requested the deletion.
  5416. *
  5417. * @return User
  5418. */
  5419. public function getDeletionRequestedBy(): ?User
  5420. {
  5421. return $this->getProjectClosure() ? $this->getProjectClosure()->getClosedBy() : null;
  5422. }
  5423. /**
  5424. * getAllowExpertViewUnsortedRecords
  5425. *
  5426. * @return bool
  5427. */
  5428. public function getAllowExpertViewUnsortedRecords(): ?bool
  5429. {
  5430. return $this->allowExpertViewUnsortedRecords;
  5431. }
  5432. /**
  5433. * setAllowExpertViewUnsortedRecords
  5434. *
  5435. * @param bool $allowExpertViewUnsortedRecords
  5436. *
  5437. * @return self
  5438. */
  5439. public function setAllowExpertViewUnsortedRecords(?bool $allowExpertViewUnsortedRecords = null): self
  5440. {
  5441. $this->allowExpertViewUnsortedRecords = $allowExpertViewUnsortedRecords;
  5442. return $this;
  5443. }
  5444. /**
  5445. * Get the value of dateDeleted
  5446. *
  5447. * @return DateTime
  5448. */
  5449. public function getDateDeleted()
  5450. {
  5451. return $this->dateDeleted;
  5452. }
  5453. /**
  5454. * Set the value of dateDeleted
  5455. *
  5456. * @param DateTime|null $dateDeleted
  5457. *
  5458. * @return self
  5459. */
  5460. public function setDateDeleted(?DateTime $dateDeleted)
  5461. {
  5462. $this->dateDeleted = $dateDeleted;
  5463. return $this;
  5464. }
  5465. /**
  5466. * Get the value of projectDeletionReport
  5467. */
  5468. public function getProjectDeletionReport()
  5469. {
  5470. return $this->projectDeletionReport;
  5471. }
  5472. /**
  5473. * Set the value of projectDeletionReport
  5474. *
  5475. * @param ProjectDeletionReport|null $projectDeletionReport
  5476. *
  5477. * @return self
  5478. */
  5479. public function setProjectDeletionReport(?ProjectDeletionReport $projectDeletionReport)
  5480. {
  5481. $this->projectDeletionReport = $projectDeletionReport;
  5482. return $this;
  5483. }
  5484. /**
  5485. * Transforms matter Request entity into a usable array structure
  5486. *
  5487. * @return array
  5488. */
  5489. public function getDeletionSummaryArray(): array
  5490. {
  5491. $deletionReport = $this->getProjectDeletionReport();
  5492. if ($deletionReport === null) {
  5493. throw new Exception('Project deletion report has not been stored.');
  5494. }
  5495. return [
  5496. 'project' => $this,
  5497. 'patientDob' => $deletionReport->getPatientDateOfBirth(),
  5498. 'userWhoCompletedClosureWizard' => $this->getDeletionRequestedBy() ? $this->getDeletionRequestedBy()->getFullName() : '',
  5499. 'dateDeletionCompleted' => $deletionReport->getCreated(),
  5500. 'documents' => $deletionReport->getDocuments(),
  5501. ];
  5502. }
  5503. /**
  5504. * Sets the project delete status to failed.
  5505. *
  5506. * @return self
  5507. */
  5508. public function setDeleteStatusFailed(): self
  5509. {
  5510. $this->setDeleteStatus(self::DELETE_STATUS_DELETE_FAILED);
  5511. return $this;
  5512. }
  5513. /**
  5514. * Sets the project delete status to anonymise failed.
  5515. *
  5516. * @return self
  5517. */
  5518. public function setDeleteStatusAnonymiseFailed(): self
  5519. {
  5520. $this->setDeleteStatus(self::DELETE_STATUS_ANONYMISE_FAILED);
  5521. return $this;
  5522. }
  5523. /**
  5524. * Sets the project delete status to complete.
  5525. *
  5526. * @return self
  5527. */
  5528. public function setDeleteStatusComplete(): self
  5529. {
  5530. $this->setDeleteStatus(self::DELETE_STATUS_COMPLETE);
  5531. return $this;
  5532. }
  5533. /**
  5534. * Sets the project delete status to complete.
  5535. *
  5536. * @return self
  5537. */
  5538. public function setDeleteStatusProcessing(): self
  5539. {
  5540. $this->setDeleteStatus(self::DELETE_STATUS_PROCESSING);
  5541. return $this;
  5542. }
  5543. /**
  5544. * @return ProjectClosure|null
  5545. */
  5546. public function getProjectClosure(): ?ProjectClosure
  5547. {
  5548. return $this->projectClosure;
  5549. }
  5550. /**
  5551. * @param ProjectClosure|null $projectClosure
  5552. *
  5553. * @return self
  5554. */
  5555. public function setProjectClosure(?ProjectClosure $projectClosure): self
  5556. {
  5557. // unset the owning side of the relation if necessary
  5558. if ($projectClosure === null && $this->projectClosure !== null) {
  5559. $this->projectClosure->setProject(null);
  5560. }
  5561. // set the owning side of the relation if necessary
  5562. if ($projectClosure !== null && $projectClosure->getProject() !== $this) {
  5563. $projectClosure->setProject($this);
  5564. }
  5565. $this->projectClosure = $projectClosure;
  5566. return $this;
  5567. }
  5568. /**
  5569. * Returns all the root collections for a project. These are the root folders on the MedicalRecords page.
  5570. *
  5571. * @return Collection[]
  5572. */
  5573. public function getRootCollections(): array
  5574. {
  5575. $rootCollections = [];
  5576. if ($this->getMedicalRecordsCollection()) {
  5577. $rootCollections[] = $this->getMedicalRecordsCollection();
  5578. }
  5579. if ($this->getPrivateCollection()) {
  5580. $rootCollections[] = $this->getPrivateCollection();
  5581. }
  5582. if ($this->getPrivateSandboxCollection()) {
  5583. $rootCollections[] = $this->getPrivateSandboxCollection();
  5584. }
  5585. if ($this->getUnsortedRecordsCollection()) {
  5586. $rootCollections[] = $this->getUnsortedRecordsCollection();
  5587. }
  5588. return $rootCollections;
  5589. }
  5590. /**
  5591. * Return true if deleteStatus is PROCESSING or COMPLETE
  5592. *
  5593. * @return bool
  5594. */
  5595. public function isDeleteProcessingOrComplete()
  5596. {
  5597. $statuses = [
  5598. self::DELETE_STATUS_PROCESSING,
  5599. self::DELETE_STATUS_COMPLETE,
  5600. ];
  5601. return in_array($this->getDeleteStatus(), $statuses);
  5602. }
  5603. /**
  5604. * @Groups({"project_closure:read"})
  5605. *
  5606. * @return bool
  5607. */
  5608. public function getClosureQuestionsOptional(): bool
  5609. {
  5610. return $this->getAccount()->getMatterClosureQuestionsOptional();
  5611. }
  5612. /**
  5613. * @return string|null
  5614. */
  5615. public function getClosureStatusLabel(): ?string
  5616. {
  5617. if ($this->getArchiveStatus()) {
  5618. return 'Archived';
  5619. }
  5620. if ($this->getDeleteStatus()) {
  5621. return 'Deleted';
  5622. }
  5623. return null;
  5624. }
  5625. /**
  5626. * @return string|null
  5627. */
  5628. public function getFirmRecordsReviewStatus(): ?string
  5629. {
  5630. return $this->firmRecordsReviewStatus;
  5631. }
  5632. /**
  5633. * @param string|null $firmRecordsReviewStatus
  5634. *
  5635. * @return self
  5636. */
  5637. public function setFirmRecordsReviewStatus(?string $firmRecordsReviewStatus): self
  5638. {
  5639. if ($this->firmRecordsReviewStatus !== $firmRecordsReviewStatus) {
  5640. $this->setFirmRecordsReviewUpdated(new DateTime());
  5641. }
  5642. $this->firmRecordsReviewStatus = $firmRecordsReviewStatus;
  5643. return $this;
  5644. }
  5645. /**
  5646. * @return array
  5647. */
  5648. public static function getFirmRecordsReviewStatusOptions(): array
  5649. {
  5650. return static::getConstantsWithLabelsAsChoices('FIRM_RECORDS_REVIEW_STATUS');
  5651. }
  5652. /**
  5653. * @return string
  5654. */
  5655. public function getFirmRecordsReviewStatusLabel(): string
  5656. {
  5657. $options = array_flip($this->getFirmRecordsReviewStatusOptions());
  5658. return $options[$this->firmRecordsReviewStatus] ?? '';
  5659. }
  5660. /**
  5661. * @return bool
  5662. */
  5663. public function showFirmRecordsReviewAdditionalInstruction(): bool
  5664. {
  5665. $statuses = [
  5666. self::FIRM_RECORDS_REVIEW_STATUS_AWAITING_RECORDS,
  5667. self::FIRM_RECORDS_REVIEW_STATUS_UPLOADED,
  5668. ];
  5669. return in_array($this->getFirmRecordsReviewStatus(), $statuses);
  5670. }
  5671. /**
  5672. * @return DateTimeInterface|null
  5673. */
  5674. public function getFirmRecordsReviewUpdated(): ?DateTimeInterface
  5675. {
  5676. return $this->firmRecordsReviewUpdated;
  5677. }
  5678. /**
  5679. * @param DateTimeInterface|null $firmRecordsReviewUpdated
  5680. *
  5681. * @return self
  5682. */
  5683. public function setFirmRecordsReviewUpdated(?DateTimeInterface $firmRecordsReviewUpdated): self
  5684. {
  5685. $this->firmRecordsReviewUpdated = $firmRecordsReviewUpdated;
  5686. return $this;
  5687. }
  5688. /**
  5689. * @return string|null
  5690. */
  5691. public function getClinicalSummaryUnsortedStatus(): ?string
  5692. {
  5693. return $this->clinicalSummaryUnsortedStatus;
  5694. }
  5695. /**
  5696. * @param string|null $clinicalSummaryUnsortedStatus
  5697. *
  5698. * @return self
  5699. */
  5700. public function setClinicalSummaryUnsortedStatus(?string $clinicalSummaryUnsortedStatus): self
  5701. {
  5702. if ($this->clinicalSummaryUnsortedStatus !== $clinicalSummaryUnsortedStatus) {
  5703. $this->setClinicalSummaryUnsortedUpdated(new DateTime());
  5704. }
  5705. $this->clinicalSummaryUnsortedStatus = $clinicalSummaryUnsortedStatus;
  5706. return $this;
  5707. }
  5708. /**
  5709. * @return array
  5710. */
  5711. public static function getClinicalSummaryUnsortedStatusOptions(): array
  5712. {
  5713. return static::getConstantsWithLabelsAsChoices('CLINICAL_SUMMARY_UNSORTED_STATUS');
  5714. }
  5715. /**
  5716. * @return string
  5717. */
  5718. public function getClinicalSummaryUnsortedStatusLabel(): string
  5719. {
  5720. $options = array_flip($this->getClinicalSummaryUnsortedStatusOptions());
  5721. return $options[$this->clinicalSummaryUnsortedStatus] ?? '';
  5722. }
  5723. /**
  5724. * @return DateTimeInterface|null
  5725. */
  5726. public function getClinicalSummaryUnsortedUpdated(): ?DateTimeInterface
  5727. {
  5728. return $this->clinicalSummaryUnsortedUpdated;
  5729. }
  5730. /**
  5731. * @param DateTimeInterface|null $clinicalSummaryUnsortedUpdated
  5732. *
  5733. * @return self
  5734. */
  5735. public function setClinicalSummaryUnsortedUpdated(?DateTimeInterface $clinicalSummaryUnsortedUpdated): self
  5736. {
  5737. $this->clinicalSummaryUnsortedUpdated = $clinicalSummaryUnsortedUpdated;
  5738. return $this;
  5739. }
  5740. /**
  5741. * @return bool
  5742. */
  5743. public function showClinicalSummaryUnsortedAdditionalInstruction(): bool
  5744. {
  5745. $statuses = [
  5746. self::CLINICAL_SUMMARY_UNSORTED_STATUS_AWAITING_CONCLUSION,
  5747. self::CLINICAL_SUMMARY_UNSORTED_STATUS_INCONCLUSIVE,
  5748. ];
  5749. return in_array($this->getClinicalSummaryUnsortedStatus(), $statuses);
  5750. }
  5751. /**
  5752. * @param Instance $instance
  5753. *
  5754. * @return $this
  5755. */
  5756. public function addInstance(Instance $instance): Project
  5757. {
  5758. if (!$this->instances->contains($instance)) {
  5759. $this->instances[] = $instance;
  5760. }
  5761. return $this;
  5762. }
  5763. /**
  5764. * @param Instance $instance
  5765. *
  5766. * @return $this
  5767. */
  5768. public function removeInstance(Instance $instance): Project
  5769. {
  5770. $this->instances->removeElement($instance);
  5771. return $this;
  5772. }
  5773. /**
  5774. * @return DoctrineCollection<int, InterpartyDisclosure>
  5775. */
  5776. public function getInterpartyDisclosures(): DoctrineCollection
  5777. {
  5778. return $this->interpartyDisclosures;
  5779. }
  5780. /**
  5781. * This function name is no longer very descriptive as we include drafts that
  5782. * were saved intentionally as drafts for review.
  5783. *
  5784. * @return DoctrineCollection<int, InterpartyDisclosure>
  5785. */
  5786. public function getNonDraftInterpartyDisclosures(): DoctrineCollection
  5787. {
  5788. return $this->interpartyDisclosures->filter(function (InterpartyDisclosure $disclosure) {
  5789. return ($disclosure->isStatusDraft() === false || $disclosure->getSavedAsDraft() === true) && $disclosure->isCurrentHeadOfChain() === true;
  5790. });
  5791. }
  5792. /**
  5793. * Returns a unique array of matter numbers that have already been used as recipient firm
  5794. * matter numbers for disclosures on this project.
  5795. *
  5796. * @param ?InterpartyDisclosure $excludeDisclosure - Optionally exclude a specific disclosure from the list.
  5797. * @param bool $excludePreviousVersions
  5798. *
  5799. * @return array
  5800. */
  5801. public function getInterpartyDisclosureRecipientMatterNumbers(?InterpartyDisclosure $excludeDisclosure = null, bool $excludePreviousVersions = false): array
  5802. {
  5803. $matterNumbers = [];
  5804. foreach ($this->getInterpartyDisclosures() as $disclosure) {
  5805. if (
  5806. $excludeDisclosure === $disclosure
  5807. || ($excludePreviousVersions === true && $disclosure->isDisclosurePreviousVersionOf($excludeDisclosure))
  5808. || $disclosure->isStatusDraft()
  5809. || $disclosure->isStatusRevoked()
  5810. || $disclosure->isStatusFailed()
  5811. ) {
  5812. continue;
  5813. }
  5814. foreach ($disclosure->getRecipientFirms() as $recipientFirm) {
  5815. $matterNumbers[] = $recipientFirm->getMatterNumber();
  5816. }
  5817. }
  5818. // Don't call array unique here as it messes with the keys of the array.
  5819. return $matterNumbers;
  5820. }
  5821. /**
  5822. * @return bool
  5823. */
  5824. public function hasActiveInterpartyDisclosures(): bool
  5825. {
  5826. foreach ($this->getInterpartyDisclosures() as $disclosure) {
  5827. if ($disclosure->isStatusActive()) {
  5828. return true;
  5829. }
  5830. }
  5831. return false;
  5832. }
  5833. /**
  5834. * @return bool
  5835. */
  5836. public function hasExpiredInterpartyDisclosures(): bool
  5837. {
  5838. foreach ($this->getInterpartyDisclosures() as $disclosure) {
  5839. if ($disclosure->isStatusExpired()) {
  5840. return true;
  5841. }
  5842. }
  5843. return false;
  5844. }
  5845. /**
  5846. * @param InterpartyDisclosure $interpartyDisclosure
  5847. *
  5848. * @return self
  5849. */
  5850. public function addInterpartyDisclosure(InterpartyDisclosure $interpartyDisclosure): self
  5851. {
  5852. if (!$this->interpartyDisclosures->contains($interpartyDisclosure)) {
  5853. $this->interpartyDisclosures[] = $interpartyDisclosure;
  5854. $interpartyDisclosure->setProject($this);
  5855. }
  5856. return $this;
  5857. }
  5858. /**
  5859. * @param InterpartyDisclosure $interpartyDisclosure
  5860. *
  5861. * @return self
  5862. */
  5863. public function removeInterpartyDisclosure(InterpartyDisclosure $interpartyDisclosure): self
  5864. {
  5865. if ($this->interpartyDisclosures->removeElement($interpartyDisclosure)) {
  5866. // set the owning side to null (unless already changed)
  5867. if ($interpartyDisclosure->getProject() === $this) {
  5868. $interpartyDisclosure->setProject(null);
  5869. }
  5870. }
  5871. return $this;
  5872. }
  5873. /**
  5874. * Return the count of active disclosures relating to the current project.
  5875. *
  5876. * @return int
  5877. */
  5878. public function getActiveDisclosuresCount(): int
  5879. {
  5880. $interpartyDisclosuresArray = $this->getInterpartyDisclosures()->toArray();
  5881. $activeCount = array_reduce(
  5882. $interpartyDisclosuresArray,
  5883. function ($activeTotal, $disclosure) {
  5884. return $activeTotal + $disclosure->isStatusActive();
  5885. },
  5886. 0
  5887. );
  5888. return $activeCount;
  5889. }
  5890. /**
  5891. * @return string|null
  5892. *
  5893. */
  5894. public function getMatterType(): ?string
  5895. {
  5896. return $this->matterType;
  5897. }
  5898. /**
  5899. * @param string|null $matterType
  5900. *
  5901. * @return self
  5902. */
  5903. public function setMatterType(?string $matterType): self
  5904. {
  5905. $this->matterType = $matterType;
  5906. return $this;
  5907. }
  5908. /**
  5909. * @return array
  5910. */
  5911. public static function getMatterTypeOptions(): array
  5912. {
  5913. return self::getConstantsWithLabelsAsChoices('MATTER_TYPE');
  5914. }
  5915. /**
  5916. * @return string
  5917. */
  5918. public function getMatterTypeLabel(): string
  5919. {
  5920. if ($this->getMatterType() === null) {
  5921. return '';
  5922. }
  5923. $options = array_flip(self::getMatterTypeOptions());
  5924. return $options[$this->getMatterType()] ?? '';
  5925. }
  5926. /**
  5927. * @return bool
  5928. */
  5929. public function isClinicalNegligenceMatterType(): bool
  5930. {
  5931. return $this->getMatterType() === self::MATTER_TYPE_CLINICAL_NEGLIGENCE;
  5932. }
  5933. /**
  5934. * Get the value of useModernRadiology
  5935. */
  5936. public function getUseModernRadiology(): ?bool
  5937. {
  5938. return $this->useModernRadiology;
  5939. }
  5940. /**
  5941. * Set the value of useModernRadiology
  5942. *
  5943. * @param bool|null $useModernRadiology
  5944. *
  5945. * @return self
  5946. */
  5947. public function setUseModernRadiology(?bool $useModernRadiology)
  5948. {
  5949. $this->useModernRadiology = $useModernRadiology;
  5950. return $this;
  5951. }
  5952. /**
  5953. * Get the value of modernRadiologyMigrationStatus
  5954. */
  5955. public function getModernRadiologyMigrationStatus(): ?string
  5956. {
  5957. return $this->modernRadiologyMigrationStatus;
  5958. }
  5959. /**
  5960. * Set the value of modernRadiologyMigrationStatus
  5961. *
  5962. * @param mixed $modernRadiologyMigrationStatus
  5963. *
  5964. * @return self
  5965. */
  5966. public function setModernRadiologyMigrationStatus(?string $modernRadiologyMigrationStatus)
  5967. {
  5968. $this->modernRadiologyMigrationStatus = $modernRadiologyMigrationStatus;
  5969. // Once the migration completes, flick the switch that we should now use modern radiology.
  5970. if ($modernRadiologyMigrationStatus === self::MODERN_RADIOLOGY_MIGRATION_STATUS_COMPLETE
  5971. || $modernRadiologyMigrationStatus === self::MODERN_RADIOLOGY_MIGRATION_STATUS_SKIPPED) {
  5972. $this->setUseModernRadiology(true);
  5973. }
  5974. return $this;
  5975. }
  5976. /**
  5977. * @return bool
  5978. */
  5979. public function isModernRadiologyMigrationInProgress(): bool
  5980. {
  5981. return $this->getModernRadiologyMigrationStatus() === self::MODERN_RADIOLOGY_MIGRATION_STATUS_IN_PROGRESS;
  5982. }
  5983. /**
  5984. * @return string|null
  5985. */
  5986. public function getType(): ?string
  5987. {
  5988. return $this->type;
  5989. }
  5990. /**
  5991. * @param string|null $type
  5992. *
  5993. * @return self
  5994. */
  5995. public function setType(?string $type): self
  5996. {
  5997. $this->type = $type;
  5998. return $this;
  5999. }
  6000. /**
  6001. * @return bool
  6002. */
  6003. public function isTypeDisclosure(): bool
  6004. {
  6005. return $this->type === self::TYPE_MATTER_DISCLOSURE;
  6006. }
  6007. /**
  6008. * Returns an array of permitted values for the Matter Type field and their
  6009. * associated labels.
  6010. *
  6011. * @return array
  6012. */
  6013. public static function getTypeOptions()
  6014. {
  6015. $typeOptions = self::getConstantsWithLabelsAsChoices('TYPE_MATTER');
  6016. return $typeOptions;
  6017. }
  6018. /**
  6019. * Returns a human readable version of the type
  6020. *
  6021. * @return string
  6022. */
  6023. public function getTypeLabel()
  6024. {
  6025. return self::getConstantsWithLabels('TYPE_MATTER');
  6026. }
  6027. /**
  6028. * @return bool
  6029. */
  6030. public function hasNoRecordsForDisclosure(): bool
  6031. {
  6032. if ($this->getMedicalRecordsCollection() === null) {
  6033. return false;
  6034. }
  6035. return $this->getMedicalRecordsCollection()->getDocuments()->isEmpty() && $this->getUnsortedRecordsCollection()->getDocuments()->isEmpty();
  6036. }
  6037. /**
  6038. * @return bool
  6039. */
  6040. public function hasNoRadiologyForDisclosure(): bool
  6041. {
  6042. // Get failed discs too for this consideration, as you can disclose failed discs.
  6043. return $this->getFailedDiscs()->isEmpty() && $this->getActiveDiscs()->isEmpty() && $this->getStudies()->isEmpty();
  6044. }
  6045. /**
  6046. * Returns true if the project has no items for disclosure (records and radiology)
  6047. *
  6048. * @return bool
  6049. */
  6050. public function hasNoItemsForDisclosure(): bool
  6051. {
  6052. $hasNoRecords = $this->hasNoRecordsForDisclosure();
  6053. $hasNoRadiology = $this->hasNoRadiologyForDisclosure();
  6054. return $hasNoRecords === true && $hasNoRadiology === true;
  6055. }
  6056. /**
  6057. * Returns true if one of the project's discs does not have the same status as it had pre-migration.
  6058. *
  6059. * @return bool
  6060. */
  6061. public function hasProjectFailedDiscMigration(): bool
  6062. {
  6063. foreach ($this->getDiscs() as $disc) {
  6064. if ($disc->hasDiscFailedMigration()) {
  6065. return true;
  6066. }
  6067. }
  6068. return false;
  6069. }
  6070. /**
  6071. * @return bool|null
  6072. */
  6073. public function getHideFromInvoicing(): ?bool
  6074. {
  6075. return $this->hideFromInvoicing;
  6076. }
  6077. /**
  6078. * @param bool|null $hideFromInvoicing
  6079. *
  6080. * @return self
  6081. */
  6082. public function setHideFromInvoicing(?bool $hideFromInvoicing): self
  6083. {
  6084. $this->hideFromInvoicing = $hideFromInvoicing;
  6085. return $this;
  6086. }
  6087. /**
  6088. * @return DateTimeInterface|null
  6089. */
  6090. public function getLastRenewalDate(): ?DateTimeInterface
  6091. {
  6092. return $this->lastRenewalDate;
  6093. }
  6094. /**
  6095. * @param DateTimeInterface|null $lastRenewalDate
  6096. *
  6097. * @return self
  6098. */
  6099. public function setLastRenewalDate(?DateTimeInterface $lastRenewalDate): self
  6100. {
  6101. $this->lastRenewalDate = $lastRenewalDate;
  6102. return $this;
  6103. }
  6104. /**
  6105. * @return DateTimeInterface|null
  6106. */
  6107. public function getNextRenewalDate(): ?DateTimeInterface
  6108. {
  6109. return $this->nextRenewalDate;
  6110. }
  6111. /**
  6112. * @param DateTimeInterface|null $nextRenewalDate
  6113. *
  6114. * @return self
  6115. */
  6116. public function setNextRenewalDate(?DateTimeInterface $nextRenewalDate): self
  6117. {
  6118. $this->nextRenewalDate = $nextRenewalDate;
  6119. return $this;
  6120. }
  6121. /**
  6122. * @return array|null
  6123. */
  6124. public function getRenewalNotificationSent(): ?array
  6125. {
  6126. return $this->renewalNotificationSent;
  6127. }
  6128. /**
  6129. * @param array|null $renewalNotificationSent
  6130. *
  6131. * @return self
  6132. */
  6133. public function setRenewalNotificationSent(?array $renewalNotificationSent): self
  6134. {
  6135. $this->renewalNotificationSent = $renewalNotificationSent;
  6136. return $this;
  6137. }
  6138. /**
  6139. * Returns whether remaining hosting renewal reminders are suppressed.
  6140. *
  6141. * @return bool
  6142. */
  6143. public function isProceedWithRenewal(): bool
  6144. {
  6145. return $this->proceedWithRenewal;
  6146. }
  6147. /**
  6148. * Set the current-cycle hosting renewal reminder preference.
  6149. *
  6150. * @param bool $proceedWithRenewal
  6151. */
  6152. public function setProceedWithRenewal(bool $proceedWithRenewal): self
  6153. {
  6154. $this->proceedWithRenewal = $proceedWithRenewal;
  6155. return $this;
  6156. }
  6157. /**
  6158. * @return DoctrineCollection<int, MatterLicenceRenewalLog>
  6159. */
  6160. public function getMatterLicenceRenewalLogs(): DoctrineCollection
  6161. {
  6162. return $this->matterLicenceRenewalLogs;
  6163. }
  6164. /**
  6165. * @param MatterLicenceRenewalLog $matterLicenceRenewalLog
  6166. *
  6167. * @return self
  6168. */
  6169. public function addMatterLicenceRenewalLog(MatterLicenceRenewalLog $matterLicenceRenewalLog): self
  6170. {
  6171. if (!$this->matterLicenceRenewalLogs->contains($matterLicenceRenewalLog)) {
  6172. $this->matterLicenceRenewalLogs[] = $matterLicenceRenewalLog;
  6173. $matterLicenceRenewalLog->setProject($this);
  6174. }
  6175. return $this;
  6176. }
  6177. /**
  6178. * @param MatterLicenceRenewalLog $matterLicenceRenewalLog
  6179. *
  6180. * @return self
  6181. */
  6182. public function removeMatterLicenceRenewalLog(MatterLicenceRenewalLog $matterLicenceRenewalLog): self
  6183. {
  6184. if ($this->matterLicenceRenewalLogs->removeElement($matterLicenceRenewalLog)) {
  6185. // set the owning side to null (unless already changed)
  6186. if ($matterLicenceRenewalLog->getProject() === $this) {
  6187. $matterLicenceRenewalLog->setProject(null);
  6188. }
  6189. }
  6190. return $this;
  6191. }
  6192. /**
  6193. * Get a valid Licence Renewal Term belonging to the Project
  6194. * For a term to be valid the Project's created date must fall between the effective renewal date and effective renewal end date
  6195. *
  6196. * @return LicenceRenewalTerm|null
  6197. */
  6198. public function getLicenceRenewalTerm(): ?LicenceRenewalTerm
  6199. {
  6200. $terms = $this->getAccount()->getLicenceRenewalTerms();
  6201. // if the Account doesn't have any associated terms return
  6202. if (empty($terms)) {
  6203. return null;
  6204. }
  6205. // find only the applicable term for this project
  6206. foreach ($terms as $term) {
  6207. // If we have an artificial created date to slot it into the renewal period, use that instead.
  6208. if ($this->getForcedRenewalCreated()) {
  6209. $validStartCriteria = $this->getForcedRenewalCreated() >= $term->getEffectiveDate();
  6210. $validEndCriteria = $term->getEffectiveEndDate() === null || ($this->getForcedRenewalCreated() <= $term->getEffectiveEndDate());
  6211. } else {
  6212. $validStartCriteria = $this->getCreated() >= $term->getEffectiveDate();
  6213. $validEndCriteria = $term->getEffectiveEndDate() === null || ($this->getCreated() <= $term->getEffectiveEndDate());
  6214. }
  6215. // return the qualifying term, effectiveEndDate of null indicates the last term, thus a recurring term
  6216. if ($validStartCriteria && $validEndCriteria) {
  6217. return $term;
  6218. }
  6219. };
  6220. return null;
  6221. }
  6222. /**
  6223. * @return string|null
  6224. */
  6225. public function getPermanentDeleteStatus(): ?string
  6226. {
  6227. return $this->permanentDeleteStatus;
  6228. }
  6229. /**
  6230. * @param string|null $permanentDeleteStatus
  6231. *
  6232. * @return self
  6233. */
  6234. public function setPermanentDeleteStatus(?string $permanentDeleteStatus): self
  6235. {
  6236. $this->permanentDeleteStatus = $permanentDeleteStatus;
  6237. return $this;
  6238. }
  6239. /**
  6240. * If there is a renewal date, it calculates the difference in days between it and today's date.
  6241. *
  6242. * @return int|null Number of days until renewal, or null if there's no renewal date.
  6243. */
  6244. public function getNumberOfDaysTillRenewal(): ?int
  6245. {
  6246. $nextRenewalDate = $this->getNextRenewalDate();
  6247. if ($nextRenewalDate !== null) {
  6248. $currentDate = (new DateTime())->setTime(0, 0, 0);
  6249. // Calculate the difference in days
  6250. $dueForRenewalInDays = $nextRenewalDate->diff($currentDate, false)->days;
  6251. $dueForRenewalInDays = max(0, $dueForRenewalInDays);
  6252. return $dueForRenewalInDays;
  6253. }
  6254. return null;
  6255. }
  6256. /**
  6257. * @return ClinicalSummary|null
  6258. */
  6259. public function getClinicalSummary(): ?ClinicalSummary
  6260. {
  6261. return $this->clinicalSummary;
  6262. }
  6263. /**
  6264. * @param ClinicalSummary|null $clinicalSummary
  6265. *
  6266. * @return self
  6267. */
  6268. public function setClinicalSummary(?ClinicalSummary $clinicalSummary): self
  6269. {
  6270. $this->clinicalSummary = $clinicalSummary;
  6271. return $this;
  6272. }
  6273. /**
  6274. * Returns an array of service request groups for this project.
  6275. *
  6276. * @return array
  6277. */
  6278. public function getServiceRequestGroups(): array
  6279. {
  6280. // If you have a property or logic for service request groups, return it here.
  6281. // Otherwise, return an empty array to avoid errors.
  6282. return [];
  6283. }
  6284. /**
  6285. * Sets the number of unread match messages for this project.
  6286. * Defaults to -1 if null is provided (no messages in thread/project at all)
  6287. *
  6288. * @param int|null $unreadMatchMessages
  6289. *
  6290. * @return self
  6291. */
  6292. public function setUnreadMatchMessages(?int $unreadMatchMessages): self
  6293. {
  6294. $this->unreadMatchMessages = $unreadMatchMessages ?? -1;
  6295. return $this;
  6296. }
  6297. /**
  6298. * 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
  6299. *
  6300. * @return string|null
  6301. */
  6302. public function getLimitedMatterName(): ?string
  6303. {
  6304. return $this->limitedMatterName ?? null;
  6305. }
  6306. /**
  6307. * 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
  6308. *
  6309. * @param string|null $limitedMatterName
  6310. *
  6311. * @return self
  6312. */
  6313. public function setLimitedMatterName(?string $limitedMatterName): self
  6314. {
  6315. $this->limitedMatterName = $limitedMatterName;
  6316. return $this;
  6317. }
  6318. /**
  6319. * Returns the number of unread match messages for this project.
  6320. * Defaults to -1 if null is provided (no messages in thread/project at all)
  6321. *
  6322. * @return int
  6323. */
  6324. public function getUnreadMatchMessages(): int
  6325. {
  6326. return $this->unreadMatchMessages ?? -1;
  6327. }
  6328. /**
  6329. * Retrieves the counts of an array of Serviceable entities, grouped by their ServiceRequest status.
  6330. *
  6331. * @param array $serviceables
  6332. * @param bool $uninvoicedOnly
  6333. *
  6334. * @return array
  6335. */
  6336. private function getServiceableCountsByStatus(array $serviceables, $uninvoicedOnly = true)
  6337. {
  6338. $serviceableCounts = [];
  6339. // Go through each serviceable entity
  6340. foreach ($serviceables as $serviceable) {
  6341. // Check that it is in fact a Serviceable entity, and that it has a ServiceRequest
  6342. // attached to it.
  6343. if ($serviceable instanceof ServiceableInterface && $serviceable->getServiceRequest()) {
  6344. // If we are only looking for uninvoiced, and this serviceable entity has been billed for,
  6345. // continue to next element of the array.
  6346. if ($uninvoicedOnly && $serviceable->isBilled()) {
  6347. continue;
  6348. }
  6349. // Use the status integer as the key
  6350. $key = $serviceable->getServiceRequest()->getStatus();
  6351. // If the array element does not already exist, setup the defaults for it.
  6352. if (!isset($serviceableCounts[$key])) {
  6353. // Place the count and label as two separate elements of the array
  6354. // so we can easily access them using the status integer key
  6355. $serviceableCounts[$key] = [
  6356. 'label' => $serviceable->getServiceRequest()->getStatusLabel(),
  6357. 'count' => 0,
  6358. ];
  6359. }
  6360. // Increment the count for the status
  6361. $serviceableCounts[$key]['count']++;
  6362. }
  6363. }
  6364. // Sort the elements by key (status)
  6365. ksort($serviceableCounts);
  6366. return $serviceableCounts;
  6367. }
  6368. }