src/Entity/Project.php line 1577

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