src/Entity/Project.php line 608

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