<?php
namespace MedBrief\MSR\Entity\MatterRequest;
use ApiPlatform\Core\Annotation\ApiResource;
use ApiPlatform\Core\Annotation\ApiSubresource;
use DH\Auditor\Provider\Doctrine\Auditing\Annotation as Audit;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
use Doctrine\ORM\EntityNotFoundException;
use Doctrine\ORM\Mapping as ORM;
use Doctrine\Persistence\Proxy;
use Gedmo\Mapping\Annotation as Gedmo;
use MedBrief\MSR\Controller\MatterRequest\CaseTypes;
use MedBrief\MSR\Controller\MatterRequest\ClaimValues;
use MedBrief\MSR\Controller\MatterRequest\CreateMatter;
use MedBrief\MSR\Dto\MatterRequestFullDto;
use MedBrief\MSR\Entity\Account;
use MedBrief\MSR\Entity\MatterRequest\Details\Chronology;
use MedBrief\MSR\Entity\MatterRequest\Details\PostProcessing;
use MedBrief\MSR\Entity\MatterRequest\Details\Review;
use MedBrief\MSR\Entity\MatterRequest\Details\ServiceSelection;
use MedBrief\MSR\Entity\MatterRequest\Details\Sort;
use MedBrief\MSR\Entity\Project;
use MedBrief\MSR\Entity\User;
use MedBrief\MSR\Repository\MatterRequestRepository;
use MedBrief\MSR\Service\ErrorHandling\ApiErrorCodeAwareInterface;
use MedBrief\MSR\Traits\FilterableClassConstantsTrait;
use Symfony\Bridge\Doctrine\Validator\Constraints\UniqueEntity;
use Symfony\Component\Serializer\Annotation\Groups;
use Symfony\Component\Validator\Constraints as Assert;
/**
* @ApiResource(
* collectionOperations={
* "post"={"access_control"="is_granted('CREATE', object)"},
* "matter_request_full_create"={
* "method"="POST",
* "input"=MatterRequestFullDto::class,
* "output"=MatterRequestFullDto::class,
* "path"="/matter_requests/matter_request_full",
* "normalization_context"={"groups"={"matter_request_full:read"}},
* "denormalization_context"={"groups"={"matter_request_full:create"}},
* "validation_groups"={"Default", "matter_request_full:create"},
* "openapi_context"={
* "summary"="Create a Matter Request.",
* "description"="Use this call to create a new matter request and associated matter. See [Create Matter](/docs/api/detail#create-matter)"
* }
* },
* "matter_request_full_update"={
* "method"="POST",
* "input"=MatterRequestFullDto::class,
* "output"=MatterRequestFullDto::class,
* "path"="/matter_requests/matter_request_full/update",
* "normalization_context"={"groups"={"matter_request_full:read"}},
* "denormalization_context"={"groups"={"matter_request_full:update"}},
* "validation_groups"={"Default", "matter_request_full:update"},
* "openapi_context"={
* "summary"="Update a Matter Request and related Matter.",
* "description"="Use this call to update/re-open an existing matter. See [Update/Re-Open Matter](/docs/api/detail#update-matter)",
* "external_docs"={"url"="/docs/api/detail#update-matter", "description"="Read Documentation"}
* }
* },
* "case_types"={
* "access_control"="is_granted('CREATE_MATTER_REQUEST')",
* "method"="GET",
* "path"="/matter_requests/case_types",
* "controller"=CaseTypes::class,
* "defaults"={"_api_receive"=false},
* "openapi_context"={
* "summary"="Return all Case Type options.",
* "description"="Return all Case Type options. See [Case Types](/docs/api/detail#case-types)",
* "responses"={
* "200"={
* "description"="A list of Case Types options.",
* }
* }
* }
* },
* "claim_values"={
* "access_control"="is_granted('CREATE_MATTER_REQUEST')",
* "method"="GET",
* "path"="/matter_requests/claim_values",
* "controller"=ClaimValues::class,
* "defaults"={"_api_receive"=false},
* "openapi_context"={
* "summary"="Return all Claim Value options.",
* "description"="Return all Claim Value options. The 'value' value is to be used in the claimValue field when creating a Matter Request.",
* "responses"={
* "200"={
* "description"="A list of Claim Value options.",
* }
* }
* }
* }
* },
* itemOperations={
* "get"={
* "access_control"="is_granted('READ', object)",
* "normalization_context"={"groups"={"matter_request:read"}, "enable_max_depth"=true}
* },
* "put"={"access_control"="is_granted('UPDATE', object)"},
* "create_matter"={
* "method"="POST",
* "path"="/matter_requests/{id}/create_matter",
* "controller"=CreateMatter::class,
* "deserialize"=false,
* "defaults"={"_api_receive"=false},
* "swagger_context"={
* "summary"="Create the matter associated with the MatterRequest.",
* "parameters" = {
* {"name" = "id","in" = "path","description" = "id","required" = "true","type" : "integer"}
* }
* }
* }
* },
* attributes={
* "validation_groups"={MatterRequest::class, "validationGroups"},
* "denormalization_context"={"skip_null_values"=true},
* },
* )
*
* @Audit\Auditable
*
* @Audit\Security(view={"ROLE_ALLOWED_TO_AUDIT"})
*
* @UniqueEntity({"matterReference", "firm"}, groups={"Default", "md_step1"}, repositoryMethod="findByProjectClientReference", payload={"error_code": ApiErrorCodeAwareInterface::INVALID_MATTER_REFERENCE__ALREADY_USED})
* @UniqueEntity({"matterReference", "firm"}, groups={"Default", "md_step1"}, payload={"error_code": ApiErrorCodeAwareInterface::INVALID_MATTER_REFERENCE__ALREADY_USED})
*
* @ORM\Table(name="MatterRequest")
*
* @ORM\Entity(repositoryClass=MatterRequestRepository::class)
*/
class MatterRequest
{
use FilterableClassConstantsTrait;
public const DEFENDANT_SEPARATOR = '#';
// selectedServiceGroup constants
public const SERVICE_GROUP_HOSTING_ONLY = 'hostingOnlyGroup';
public const SERVICE_GROUP_HOSTING_ONLY__LABEL = 'Hosting Only';
public const SERVICE_GROUP_EXTENDED = 'extendedServicesGroup';
public const SERVICE_GROUP_EXTENDED__LABEL = 'Extended Services';
// Status constants
public const STATUS_INCOMPLETE = 'incomplete';
public const STATUS_INCOMPLETE__LABEL = 'Incomplete';
public const STATUS_INSTRUCTED = 'instructed';
public const STATUS_INSTRUCTED__LABEL = 'Instructed';
public const STATUS_IN_PROGRESS = 'in_progress';
public const STATUS_IN_PROGRESS__LABEL = 'In Progress';
public const STATUS_QUERY_WITH_CLIENT = 'query_with_client';
public const STATUS_QUERY_WITH_CLIENT__LABEL = 'Query with client';
public const STATUS_QA = 'qa';
public const STATUS_QA__LABEL = 'QA';
public const STATUS_COMPLETED = 'completed';
public const STATUS_COMPLETED__LABEL = 'Completed';
public const STATUS_CANCELLED = 'canceled';
public const STATUS_CANCELLED__LABEL = 'Cancelled';
// Used when changes have been requested to the matter request at a future date
// Currently, only used when a case is re-opened via the API
public const STATUS_RE_INSTRUCTED = 're_instructed';
public const STATUS_RE_INSTRUCTED__LABEL = 'Re-Instructed';
// Indicates the source of the matter request
public const SOURCE_WEBSITE = 'website';
public const SOURCE_WEBSITE__LABEL = 'Website';
public const SOURCE_API = 'api';
public const SOURCE_API__LABEL = 'Api';
/**
* @var int
*
* @Groups({"matter_request:read"})
*
* @ORM\Column(name="id", type="integer")
*
* @ORM\Id
*
* @ORM\GeneratedValue(strategy="IDENTITY")
*/
protected $id;
/**
* A unique reference number for this Matter.
*
* @var string
*
* @Assert\NotBlank(groups={"Default", "md_step1"}, message="Please complete this field.")
*
* @Groups({"matter_request:read", "matter_request:create_full"})
*
* @ORM\Column(name="matterReference", type="string")
*/
protected $matterReference;
/**
* DateTime the MatterRequest was created.
*
* @var \DateTimeImmutable
*
* @Groups({"matter_request:read"})
*
* @ORM\Column(name="created", type="datetime_immutable")
*
* @Gedmo\Timestampable(on="create")
*/
protected $created;
/**
* Last update time of this MatterRequest.
*
* @var \DateTime
*
* @Groups({"matter_request:read"})
*
* @ORM\Column(name="updated", type="datetime")
*
* @Gedmo\Timestampable(on="update")
*/
protected $updated;
/**
* One or more Claimants to whom this MatterRequest relates.
*
* @var string
*
* @Assert\NotBlank(groups={"Default", "md_step3"})
*
* @Groups({"matter_request:read", "matter_request:create_full"})
*
* @ORM\Column(name="claimant", type="string", nullable=true)
*/
protected $claimant;
/**
* Any Defendants to whom this MatterRequest relates.
*
* @var string
*
* @Assert\Expression(
* "value != '' or this.getDefendantUnknown() === true",
* message="Please specify at least one defendant, or indicate 'Not Sure'.",
* groups={"Default", "md_step3"}
* )
*
* @Groups({"matter_request:read", "matter_request:create_full"})
*
* @ORM\Column(name="defendant", type="text", nullable=true)
*/
protected $defendant;
/**
* Any Defendants to whom this MatterRequest relates.
*
* @var bool
*
* @Groups({"matter_request:read", "matter_request:create_full"})
*
* @ORM\Column(name="defendantUnknown", type="boolean", nullable=true, options={"default"=false})
*/
protected $defendantUnknown = false;
/**
* The Team handling this Matter, where applicable.
*
* @var null|string
*
* @Groups({"matter_request:read", "matter_request:create_full"})
*
* @ORM\Column(name="team", type="string", nullable=true)
*/
protected $team;
/**
* The Billing Code to be used for this Matter.
*
* @var null|string
*
* @Assert\Expression(
* "(this.getFirm() and !this.getFirm().getMatterRequestDefaults()) or (this.getFirm() and this.getFirm().getMatterRequestDefaults() and !this.getFirm().getMatterRequestDefaults().isFieldForceCompulsory('billingCode')) or value != ''",
* message="Please complete this field.",
* groups={"Default", "md_step1"}
*)
*
* @Groups({"matter_request:read", "matter_request:create_full"})
*
* @ORM\Column(name="billingCode", type="string", nullable=true)
*/
protected $billingCode;
/**
* An indication of the estimated claim value for this Matter, if known.
*
* @var null|int
*
* @Assert\Expression(
* "(this.getFirm() and this.getFirm().getMatterRequestDefaults() and this.getFirm().getMatterRequestDefaults().isFieldForceOptional('claimValue')) or value != ''",
* message="This value should not be blank.",
* groups={"Default", "md_step2"}
*)
*
* @Groups({"matter_request:read", "matter_request:create_full"})
*
* @ORM\Column(name="claimValue", type="integer", nullable=true)
*/
protected $claimValue;
/**
* The key allegations applicable to this Matter, if known.
*
* @var array|null
*
* @Assert\NotNull(groups={"Default", "md_step2"})})
*
* @Assert\Expression(
* "(this.getFirm() and this.getFirm().getMatterRequestDefaults() and this.getFirm().getMatterRequestDefaults().isFieldForceOptional('keyAllegations')) or this.hasKeyAllegations()",
* message="Please enter an allegation.",
* groups={"Default", "md_step2"}
* )
*
* @Groups({"matter_request:read", "matter_request:create_full"})
*
* @ORM\Column(name="keyAllegations", type="array")
*/
protected $keyAllegations = [];
/**
* The date of alleged negligence applicable to this Matter, if known.
*
* @var null|\DateTime
*
* @Assert\Expression(
* "(this.getFirm() and this.getFirm().getMatterRequestDefaults() and this.getFirm().getMatterRequestDefaults().isFieldForceOptional('negligenceDate')) or value != ''",
* message="This value should not be blank.",
* groups={"Default", "md_step2"}
*)
*
* @Groups({"matter_request:read", "matter_request:create_full"})
*
* @ORM\Column(name="negligenceDate", type="datetime", nullable=true)
*/
protected $negligenceDate;
/**
* The date of knowledge applicable to this Matter.
*
* @var null|\DateTime
*
* @Groups({"matter_request:read", "matter_request:create_full"})
*
* @ORM\Column(name="knowledgeDate", type="datetime", nullable=true)
*/
protected $knowledgeDate;
/**
* The limitation date applicable to this Matter, if known.
*
* @var null|\DateTime
*
* @Assert\Expression(
* "(this.getFirm() and this.getFirm().getMatterRequestDefaults() and this.getFirm().getMatterRequestDefaults().isFieldForceOptional('limitationDate')) or value != ''",
* message="This value should not be blank.",
* groups={"Default", "md_step2"}
*)
*
* @Groups({"matter_request:read", "matter_request:create_full"})
*
* @ORM\Column(name="limitationDate", type="datetime", nullable=true)
*/
protected $limitationDate;
/**
* The category to which this Matter belongs.
*
* @var int
*
* @Assert\Expression(
* "(this.getFirm() and this.getFirm().getMatterRequestDefaults() and this.getFirm().getMatterRequestDefaults().isFieldForceOptional('claimCategory')) or value != ''",
* message="This value should not be blank.",
* groups={"Default", "md_step2"}
*)
*
* @Groups({"matter_request:read", "matter_request:create_full"})
*
* @ORM\Column(name="claimCategory", type="integer", nullable=true)
*/
protected $claimCategory;
/**
* The background to the matter.
*
* @var string
*
* @Assert\NotBlank(groups={"Default", "md_step2"})
*
* @Groups({"matter_request:read", "matter_request:create_full"})
*
* @ORM\Column(name="background", type="text", nullable=true)
*/
protected $background;
/**
* The current step of the Matter Creation Form, so we can
* return the user to edit the form, as well apply validation specific to the step.
*
* @var string
*
* @Groups({"matter_request:read"})
*
* @ORM\Column(name="currentFormStep", type="string", nullable=true)
*/
protected $currentFormStep;
/**
* The selected service group passed through from the form.
*
* @var string
*
* @Groups({"matter_request:read"})
*
* @ORM\Column(name="selectedServiceGroup", type="string", nullable=true)
*/
protected $selectedServiceGroup;
/**
* The Client/Firm initiating this MatterRequest.
*
* @var Account
*
* @Assert\NotNull(groups={"Default", "md_step1"}, message="Please select a storage area for this matter.")
*
* @Groups({"matter_request:read", "matter_request:create_full"})
*
* @ORM\ManyToOne(targetEntity="MedBrief\MSR\Entity\Account")
*
* @ORM\JoinColumns({
*
* @ORM\JoinColumn(name="firm_id", referencedColumnName="id")
* })
*/
protected $firm;
/**
* The Fee Earner for this Matter.
*
* @var User
*
* @Assert\NotNull(groups={"Default", "md_step1"}, message="Please select an option.")
*
* @ApiSubresource()
*
* @Groups({"matter_request:read", "matter_request:create_full"})
*
* @ORM\ManyToOne(targetEntity="MedBrief\MSR\Entity\User")
*
* @ORM\JoinColumns({
*
* @ORM\JoinColumn(name="manager_id", referencedColumnName="id")
* })
*/
protected $manager;
/**
* @var null|Collection|User[]
*
* @Groups({"matter_request:read", "matter_request:create_full"})
*
* @ORM\ManyToMany(targetEntity=User::class, cascade={"persist"}, fetch="EAGER")
*
* @ORM\JoinTable(name="matter_request_additional_contacts",
* joinColumns={@ORM\JoinColumn(name="matter_request_id", referencedColumnName="id", nullable=true)},
* inverseJoinColumns={@ORM\JoinColumn(name="user_id", referencedColumnName="id", nullable=true)}
* )
*
* @Assert\Expression(
* "this.hasAdditionalContactsEmpty()",
* message="All additional contacts must be fully completed or removed.",
* groups={"Default", "md_step1"}
* )
*/
protected $additionalContacts;
/**
* The Project to which this MatterRequest relates.
*
* @var null|Project
*
* @ORM\OneToOne(targetEntity="MedBrief\MSR\Entity\Project", inversedBy="matterRequest")
*
* @ORM\JoinColumns({
*
* @ORM\JoinColumn(name="matter_id", referencedColumnName="id", unique=true)
* })
*/
protected $matter;
/**
* The Project ID to which this MatterRequest relates.
*
* Not mapped, used only for API.
*
* @Groups({"matter_request:read"})
*
* @var null|int
*/
protected $matterId;
/**
* The Patients associated to this Matter.
*
* @var Collection
*
* @ApiSubresource()
*
* @Groups({"matter_request:read", "matter_request:create_full"})
*
* @ORM\OneToMany(targetEntity="MedBrief\MSR\Entity\MatterRequest\Patient", mappedBy="matterRequest", orphanRemoval=true, cascade={"persist"})
*/
protected $patients;
/**
* The Trust Centres associated to this Matter.
*
* @var Collection
*
* @ApiSubresource()
*
* @Assert\Count(
* min = 1,
* minMessage = "You must specify at least one Trust Centre",
* groups={"rr_step1"}
* )
*
* @Groups({"matter_request:read"})
*
* @ORM\OneToMany(targetEntity="MedBrief\MSR\Entity\MatterRequest\TrustCentre", mappedBy="matterRequest", orphanRemoval=true, cascade={"persist"})
*/
protected $trustCentres;
/**
* @var null|PostProcessing
*
* @ApiSubresource()
*
* @Groups({"matter_request:read"})
*
* @ORM\OneToOne(targetEntity="MedBrief\MSR\Entity\MatterRequest\Details\PostProcessing", inversedBy="matterRequest", orphanRemoval=true, cascade={"persist"})
*
* @ORM\JoinColumns({
*
* @ORM\JoinColumn(name="postProcessingDetails_id", referencedColumnName="id", unique=true)
* })
*/
protected $postProcessingDetails;
/**
* @var null|Chronology
*
* @ApiSubresource()
*
* @Groups({"matter_request:read"})
*
* @ORM\OneToOne(targetEntity="MedBrief\MSR\Entity\MatterRequest\Details\Chronology", inversedBy="matterRequest", orphanRemoval=true, cascade={"persist"})
*
* @ORM\JoinColumns({
*
* @ORM\JoinColumn(name="chronologyDetails_id", referencedColumnName="id", unique=true)
* })
*/
protected $chronologyDetails;
/**
* @var null|Review
*
* @ApiSubresource()
*
* @Groups({"matter_request:read"})
*
* @ORM\OneToOne(targetEntity="MedBrief\MSR\Entity\MatterRequest\Details\Review", inversedBy="matterRequest", orphanRemoval=true, cascade={"persist"})
*
* @ORM\JoinColumns({
*
* @ORM\JoinColumn(name="reviewDetails_id", referencedColumnName="id", unique=true)
* })
*/
protected $reviewDetails;
/**
* @var null|Sort
*
* @ApiSubresource()
*
* @Groups({"matter_request:read"})
*
* @ORM\OneToOne(targetEntity="MedBrief\MSR\Entity\MatterRequest\Details\Sort", inversedBy="matterRequest", orphanRemoval=true, cascade={"persist"})
*
* @ORM\JoinColumns({
*
* @ORM\JoinColumn(name="sortDetails_id", referencedColumnName="id", unique=true)
* })
*/
protected $sortDetails;
/**
* @var null|ServiceSelection
*
* @ApiSubresource()
*
* @Groups({"matter_request:read"})
*
* @ORM\OneToOne(targetEntity="MedBrief\MSR\Entity\MatterRequest\Details\ServiceSelection", inversedBy="matterRequest", orphanRemoval=true, cascade={"persist"})
*
* @ORM\JoinColumns({
*
* @ORM\JoinColumn(name="serviceSelectionDetails_id", referencedColumnName="id", unique=true)
* })
*/
protected $serviceSelectionDetails;
/**
* @var string
*
* @ORM\Column(name="status", type="string", nullable=true)
*/
protected $status;
/**
* @var User
*
* @ORM\ManyToOne(targetEntity="MedBrief\MSR\Entity\User")
*
* @ORM\JoinColumns({
*
* @ORM\JoinColumn(name="creator_id", referencedColumnName="id")
* })
*/
protected $creator;
/**
* @ORM\Column(name="source", type="string", options={"default"=self::SOURCE_WEBSITE})
*/
protected string $source = self::SOURCE_WEBSITE;
/**
* @ORM\Column(name="historicalApiValues", type="json", nullable=true)
*/
protected ?array $historicalApiValues = null;
/**
* @return void
*/
public function __construct()
{
$this->patients = new ArrayCollection();
$this->trustCentres = new ArrayCollection();
$this->status = self::STATUS_INCOMPLETE;
$this->source = self::SOURCE_WEBSITE;
$this->additionalContacts = new ArrayCollection();
}
/**
* __toString
*
* @return string
*/
public function __toString(): string
{
return (string) ($this->getId() ?? 'Unknown');
}
/**
* Determines the validation group to use, based on the currentFormStep for the
* matterRequest.
*
* @param MatterRequest $matterRequest
*
* @return array
*/
public static function validationGroups(MatterRequest $matterRequest): array
{
switch ($matterRequest->getCurrentFormStep()) {
case 'md.step1':
return ['md_step1'];
case 'md.step2':
return ['md_step2'];
case 'md.step3':
return ['md_step3'];
case 'rr.step1':
return ['rr_step1'];
default:
return ['Default'];
}
}
/**
* @return int
*/
public function getId(): ?int
{
return $this->id;
}
/**
* Set matterReference.
*
* @param string $matterReference
*
* @return MatterRequest
*/
public function setMatterReference($matterReference)
{
$this->matterReference = $matterReference;
// Update the associated matter as well, if it exists, and if the values are different,
// to avoid a recursive loop.
if ($this->getMatter() && $this->getMatter()->getClientReference() != $this->matterReference) {
$this->getMatter()->setClientReference($this->matterReference);
}
return $this;
}
/**
* Get matterReference.
*
* @return string
*/
public function getMatterReference()
{
return $this->matterReference;
}
/**
* Set created.
*
* @param \DateTimeImmutable $created
*
* @return MatterRequest
*/
public function setCreated($created)
{
$this->created = $created;
return $this;
}
/**
* Get created.
*
* @return \DateTimeImmutable
*/
public function getCreated()
{
return $this->created;
}
/**
* Set updated.
*
* @param \DateTime $updated
*
* @return MatterRequest
*/
public function setUpdated($updated)
{
$this->updated = $updated;
return $this;
}
/**
* Get updated.
*
* @return \DateTime
*/
public function getUpdated()
{
return $this->updated;
}
/**
* @return string
*/
public function getClaimant(): ?string
{
return $this->claimant;
}
/**
* @param string $claimant
*
* @return MatterRequest
*/
public function setClaimant(string $claimant): MatterRequest
{
$this->claimant = $claimant;
if ($this->getMatter()) {
$this->getMatter()->setName($this->generateMatterName());
}
return $this;
}
/**
* @return string|null
*/
public function getDefendant(): ?string
{
return $this->defendant;
}
/**
* @return array
*/
public function getDefendantArray(): array
{
return explode(MatterRequest::DEFENDANT_SEPARATOR, $this->getDefendant());
}
/**
* @param string|null $defendant
*
* @return MatterRequest
*/
public function setDefendant(?string $defendant = null): MatterRequest
{
$this->defendant = $defendant;
if ($this->getMatter()) {
$this->getMatter()->setName($this->generateMatterName());
}
return $this;
}
/**
* @param ?array $defendant
*
* @return MatterRequest
*/
public function setDefendantArray(?array $defendant = null): MatterRequest
{
if ($defendant === null || empty($defendant)) {
$this->setDefendant(null);
}
$this->setDefendant(implode(MatterRequest::DEFENDANT_SEPARATOR, $defendant));
return $this;
}
/**
* @return string|null
*/
public function getTeam(): ?string
{
return $this->team;
}
/**
* @param string $team
*
* @return MatterRequest
*/
public function setTeam(?string $team = null): MatterRequest
{
$this->team = $team;
// Update the associated matter as well, if it exists, and if the values are different,
// to avoid a recursive loop.
if ($this->getMatter() && $this->getMatter()->getTeam() != $this->team) {
$this->getMatter()->setTeam($this->team);
}
return $this;
}
/**
* @return string|null
*/
public function getBillingCode(): ?string
{
return $this->billingCode;
}
/**
* @param string $billingCode
*
* @return MatterRequest
*/
public function setBillingCode(?string $billingCode = null): MatterRequest
{
$this->billingCode = $billingCode;
// Update the associated matter as well, if it exists, and if the values are different,
// to avoid a recursive loop.
if ($this->getMatter() && $this->getMatter()->getBillingCode() != $this->billingCode) {
$this->getMatter()->setBillingCode($this->billingCode);
}
return $this;
}
/**
* @return null|int
*/
public function getClaimValue(): ?int
{
return $this->claimValue;
}
/**
* @return string
*/
public function getClaimValueLabel(): string
{
$claimValues = array_flip(Project::getConstantsWithLabelsAsChoices('ESTIMATED_CLAIM_VALUE'));
return $claimValues[$this->claimValue] ?? '';
}
/**
* @param int $claimValue
*
* @return MatterRequest
*/
public function setClaimValue(?int $claimValue = null): MatterRequest
{
$this->claimValue = $claimValue;
// Update the associated matter as well, if it exists, and if the values are different,
// to avoid a recursive loop.
if ($this->getMatter() && $this->getMatter()->getEstimatedClaimValue() != $this->claimValue) {
$this->getMatter()->setEstimatedClaimValue($this->claimValue);
}
return $this;
}
/**
* @param int|null $rawAmount
*
* @return self
*/
public function setClaimValueFromRawAmount(?int $rawAmount = null): self
{
if ($rawAmount === null) {
$this->setClaimValue(null);
return $this;
}
switch (true) {
case $rawAmount >= 0 && $rawAmount <= 25000:
$this->setClaimValue(Project::ESTIMATED_CLAIM_VALUE_0_25000);
break;
case $rawAmount >= 25001 && $rawAmount <= 50000:
$this->setClaimValue(Project::ESTIMATED_CLAIM_VALUE_25001_50000);
break;
case $rawAmount >= 50001 && $rawAmount <= 100000:
$this->setClaimValue(Project::ESTIMATED_CLAIM_VALUE_50001_100000);
break;
case $rawAmount >= 100001 && $rawAmount <= 250000:
$this->setClaimValue(Project::ESTIMATED_CLAIM_VALUE_100001_250000);
break;
case $rawAmount >= 250001 && $rawAmount <= 500000:
$this->setClaimValue(Project::ESTIMATED_CLAIM_VALUE_250001_500000);
break;
case $rawAmount >= 500001 && $rawAmount <= 1000000:
$this->setClaimValue(Project::ESTIMATED_CLAIM_VALUE_500001_1000000);
break;
case $rawAmount >= 1000000:
$this->setClaimValue(Project::ESTIMATED_CLAIM_VALUE_1000001);
break;
}
return $this;
}
/**
* @return null|\DateTime
*/
public function getNegligenceDate(): ?\DateTime
{
return $this->negligenceDate;
}
/**
* @param \DateTime $negligenceDate
*
* @return MatterRequest
*/
public function setNegligenceDate(?\DateTime $negligenceDate = null): MatterRequest
{
$this->negligenceDate = $negligenceDate;
return $this;
}
/**
* @return null|\DateTime
*/
public function getKnowledgeDate(): ?\DateTime
{
return $this->knowledgeDate;
}
/**
* @param \DateTime $knowledgeDate
*
* @return MatterRequest
*/
public function setKnowledgeDate(?\DateTime $knowledgeDate = null): MatterRequest
{
$this->knowledgeDate = $knowledgeDate;
return $this;
}
/**
* @return null|\DateTime
*/
public function getLimitationDate(): ?\DateTime
{
return $this->limitationDate;
}
/**
* @param \DateTime $limitationDate
*
* @return MatterRequest
*/
public function setLimitationDate(?\DateTime $limitationDate = null): MatterRequest
{
$this->limitationDate = $limitationDate;
// Update the associated matter as well, if it exists, and if the values are different,
// to avoid a recursive loop.
if ($this->getMatter() && $this->getMatter()->getLimitationDate() != $this->limitationDate) {
$this->getMatter()->setLimitationDate($this->limitationDate);
}
return $this;
}
/**
* @return int
*/
public function getClaimCategory(): ?int
{
return $this->claimCategory;
}
/**
* @return string
*/
public function getClaimCategoryLabel(): string
{
$claimCategories = array_flip(Project::getConstantsWithLabelsAsChoices('CLAIM_CATEGORY'));
return $claimCategories[$this->claimCategory] ?? 'Other';
}
/**
* @return bool
*/
public function isClaimCategoryBirthInjury(): bool
{
return in_array($this->getClaimCategory(), Project::getBirthInjuryClaimCategories());
}
/**
* @param int $claimCategory
*
* @return MatterRequest
*/
public function setClaimCategory(?int $claimCategory = null): MatterRequest
{
$this->claimCategory = $claimCategory;
// Update the associated matter as well, if it exists, and if the values are different,
// to avoid a recursive loop.
if ($this->getMatter() && $this->getMatter()->getClaimCategory() != $this->claimCategory) {
$this->getMatter()->setClaimCategory($this->claimCategory);
}
return $this;
}
/**
* @return Collection|Patient[]
*/
public function getPatients(): Collection
{
return $this->patients;
}
/**
* @param Collection $patients
*
* @return MatterRequest
*/
public function setPatients(Collection $patients): MatterRequest
{
$this->patients = $patients;
return $this;
}
public function addPatient(Patient $patient): MatterRequest
{
$patient->setMatterRequest($this);
$this->patients[] = $patient;
return $this;
}
/**
* @return Collection
*/
public function getTrustCentres(): Collection
{
return $this->trustCentres;
}
/**
* @param Collection $trustCentres
*
* @return MatterRequest
*/
public function setTrustCentres(Collection $trustCentres): MatterRequest
{
$this->trustCentres = $trustCentres;
return $this;
}
public function addTrustCentre(TrustCentre $trustCentre): MatterRequest
{
$trustCentre->setMatterRequest($this);
$this->trustCentres[] = $trustCentre;
return $this;
}
/**
* @return PostProcessing|null
*/
public function getPostProcessingDetails(): ?PostProcessing
{
return $this->postProcessingDetails;
}
/**
* @param PostProcessing|null $postProcessingDetails
*
* @return MatterRequest
*/
public function setPostProcessingDetails(?PostProcessing $postProcessingDetails): MatterRequest
{
$this->postProcessingDetails = $postProcessingDetails;
return $this;
}
/**
* @return Chronology|null
*/
public function getChronologyDetails(): ?Chronology
{
return $this->chronologyDetails;
}
/**
* @param Chronology|null $chronologyDetails
*
* @return MatterRequest
*/
public function setChronologyDetails(?Chronology $chronologyDetails): MatterRequest
{
$this->chronologyDetails = $chronologyDetails;
return $this;
}
/**
* @return Review|null
*/
public function getReviewDetails(): ?Review
{
return $this->reviewDetails;
}
/**
* @param Review|null $reviewDetails
*
* @return MatterRequest
*/
public function setReviewDetails(?Review $reviewDetails): MatterRequest
{
$this->reviewDetails = $reviewDetails;
return $this;
}
/**
* @return Sort|null
*/
public function getSortDetails(): ?Sort
{
return $this->sortDetails;
}
/**
* @param Sort|null $sortDetails
*
* @return MatterRequest
*/
public function setSortDetails(?Sort $sortDetails): MatterRequest
{
$this->sortDetails = $sortDetails;
return $this;
}
/**
* @return Account
*/
public function getFirm(): ?Account
{
return $this->firm;
}
/**
* @param Account|null $firm
*
* @return MatterRequest
*/
public function setFirm(?Account $firm = null): MatterRequest
{
$this->firm = $firm;
return $this;
}
/**
* retrieves the manager of the project
*
* @return User|null
*/
public function getManager(): ?User
{
try {
// If the manager is a Proxy, we need to load it to ensure it is fully initialized.
if ($this->manager instanceof Proxy) {
$this->manager->__load();
}
return $this->manager;
} catch (EntityNotFoundException $e) {
// If the manager is not found (has been soft/hard deleted), return null.
return null;
}
}
/**
* @param User|null $manager
*
* @return MatterRequest
*/
public function setManager(?User $manager = null): MatterRequest
{
$this->manager = $manager;
// Update the associated matter as well, if it exists, and if the values are different,
// to avoid a recursive loop.
if ($this->getMatter() && $this->getMatter()->getManager() != $this->manager) {
$this->getMatter()->setManager($this->manager);
}
return $this;
}
/**
* @return Project|null
*/
public function getMatter(): ?Project
{
return $this->matter;
}
/**
* @param Project|null $matter
*
* @return MatterRequest
*/
public function setMatter(?Project $matter): MatterRequest
{
$this->matter = $matter;
return $this;
}
/**
* @return array|null
*/
public function getKeyAllegations(): ?array
{
return $this->keyAllegations;
}
/**
* @return bool
*/
public function hasKeyAllegations(): bool
{
return count($this->keyAllegations) > 0 && !in_array('', $this->keyAllegations);
}
/**
* @param array|null $keyAllegations
*
* @return MatterRequest
*/
public function setKeyAllegations(?array $keyAllegations = null): MatterRequest
{
$this->keyAllegations = $keyAllegations;
return $this;
}
/**
* Validates key allegations.
*
* @return bool
*/
public function validateKeyAllegations(): bool
{
if (count((array) $this->getKeyAllegations())) {
return false;
}
foreach ($this->getKeyAllegations() as $keyAllegation) {
if ($keyAllegation == '') {
return false;
}
}
return true;
}
/**
* @return bool
*/
public function hasAdditionalContactsEmpty(): bool
{
if (count($this->getAdditionalContacts()) > 1) {
return !in_array('', $this->getAdditionalContacts()->toArray(), true);
}
return true;
}
/**
* @return string
*/
public function getBackground(): ?string
{
return $this->background;
}
/**
* @param string $background
*
* @return MatterRequest
*/
public function setBackground(string $background): MatterRequest
{
$this->background = $background;
// Update the associated matter as well, if it exists, and if the values are different,
// to avoid a recursive loop.
if ($this->getMatter() && $this->getMatter()->getBackground() != $this->background) {
$this->getMatter()->setBackground($this->background);
}
return $this;
}
/**
* Set currentFormStep.
*
* @param string|null $currentFormStep
*
* @return MatterRequest
*/
public function setCurrentFormStep($currentFormStep = null)
{
$this->currentFormStep = $currentFormStep;
return $this;
}
/**
* Get currentFormStep.
*
* @return string|null
*/
public function getCurrentFormStep()
{
return $this->currentFormStep;
}
/**
* Set selectedServiceGroup.
*
* @param string|null $selectedServiceGroup
*
* @return MatterRequest
*/
public function setSelectedServiceGroup($selectedServiceGroup = null)
{
$this->selectedServiceGroup = $selectedServiceGroup;
return $this;
}
/**
* Get selectedServiceGroup.
*
* @return string|null
*/
public function getSelectedServiceGroup()
{
return $this->selectedServiceGroup;
}
/**
* @return string
*/
public function getSelectedServiceGroupLabel()
{
$serviceGroups = array_flip(static::getConstantsWithLabelsAsChoices('SERVICE_GROUP'));
return $serviceGroups[$this->selectedServiceGroup] ?? '';
}
/**
* Set serviceSelectionDetails.
*
* @param ServiceSelection|null $serviceSelectionDetails
*
* @return MatterRequest
*/
public function setServiceSelectionDetails(?ServiceSelection $serviceSelectionDetails = null)
{
$this->serviceSelectionDetails = $serviceSelectionDetails;
return $this;
}
/**
* Get serviceSelectionDetails.
*
* @return ServiceSelection|null
*/
public function getServiceSelectionDetails()
{
return $this->serviceSelectionDetails;
}
/**
* Returns true if one of the patients on the matter request has an additional supporting document added.
*
* @return bool
*/
public function hasAdditionalSupportingDocuments(): bool
{
$patients = $this->getPatients()->filter(function (Patient $patient) {
$additionalSupportDocuments = $patient->getSupportingDocuments()->filter(function (SupportingDocument $supportingDocument) {
return $supportingDocument->isAdditionalDocumentType();
});
return $additionalSupportDocuments->count();
});
return $patients->count();
}
/**
* Set defendantUnknown.
*
* @param bool|null $defendantUnknown
*
* @return MatterRequest
*/
public function setDefendantUnknown(?bool $defendantUnknown = null)
{
$this->defendantUnknown = $defendantUnknown;
return $this;
}
/**
* Get defendantUnknown.
*
* @return bool|null
*/
public function getDefendantUnknown()
{
return $this->defendantUnknown;
}
/**
* Generates the string representation for the matter name.
*
* @return string
*/
public function generateMatterName(): string
{
// If the defendant was marked as unknown, return just the claimant name for the matter name.
if ($this->getDefendantUnknown()) {
return $this->getClaimant();
} elseif (strpos($this->getDefendant() ?? '', self::DEFENDANT_SEPARATOR) === false) {
// else, if there's no comma, we only have one defendant.
$projectDefendantStr = $this->getDefendant();
} else {
// If there is comma, we have more than one, and need to format them.
$defendantArray = $this->getDefendantArray();
$projectDefendantStr = implode(' ', array_map(function (string $currentItem, $currentKey) {
return sprintf('(%1$s) %2$s', $currentKey + 1, $currentItem);
}, $defendantArray, array_keys($defendantArray)));
}
return sprintf('%1$s -v- %2$s', $this->getClaimant(), $projectDefendantStr);
}
/**
* Returns a string representation of all patient names.
*
* @return void
*/
public function getPatientNamesStr()
{
return implode(', ', $this->getPatients()->map(function (Patient $patient) {
return $patient->getName();
})->toArray());
}
/**
* Returns the associated matter ID.
*
* @return int|null
*/
public function getMatterId(): ?int
{
return $this->getMatter() ? $this->getMatter()->getId() : null;
}
/**
* Set status.
*
* @param string|null $status
*
* @return MatterRequest
*/
public function setStatus(?string $status = null): MatterRequest
{
$this->status = $status;
return $this;
}
/**
* Get status.
*
* @return string|null
*/
public function getStatus()
{
return $this->status;
}
/**
* @return string
*/
public function getStatusLabel(): string
{
$statuses = array_flip(static::getConstantsWithLabelsAsChoices('STATUS'));
return $statuses[$this->status] ?? '';
}
/**
* Returns true if the status incomplete.
*
* @return bool
*/
public function isStatusIncomplete(): bool
{
return $this->status === self::STATUS_INCOMPLETE;
}
/**
* Remove patient.
*
* @param Patient $patient
*
* @return bool TRUE if this collection contained the specified element, FALSE otherwise.
*/
public function removePatient(Patient $patient)
{
return $this->patients->removeElement($patient);
}
/**
* Remove trustCentre.
*
* @param TrustCentre $trustCentre
*
* @return bool TRUE if this collection contained the specified element, FALSE otherwise.
*/
public function removeTrustCentre(TrustCentre $trustCentre)
{
return $this->trustCentres->removeElement($trustCentre);
}
/**
* Set creator.
*
* @param User|null $creator
*
* @return MatterRequest
*/
public function setCreator(?User $creator = null)
{
$this->creator = $creator;
return $this;
}
/**
* Get creator.
*
* @return User|null
*/
public function getCreator()
{
return $this->creator;
}
/**
* Get String of Defendants separated by & and not a #
*
* @return string
*/
public function getDefendantFormatted(): string
{
return implode(' & ', $this->getDefendantArray());
}
/**
* @return bool
*/
public function isHostingOnlyMatter(): bool
{
return $this->getSelectedServiceGroup() === self::SERVICE_GROUP_HOSTING_ONLY;
}
/**
* @return string|null
*/
public function getSource(): ?string
{
return $this->source;
}
/**
* @param string $source
*
* @return self
*/
public function setSource(string $source): self
{
$this->source = $source;
return $this;
}
/**
* @return array
*/
public static function getSourceOptions(): array
{
return static::getConstantsWithLabelsAsChoices('SOURCE');
}
/**
* @return string
*/
public function getSourceLabel(): string
{
$options = array_flip(static::getSourceOptions());
return $options[$this->source] ?? '';
}
/**
* Represented by a multi-dimensional array of field changes.
*
* @return array|null
*/
public function getHistoricalApiValues(): ?array
{
return $this->historicalApiValues;
}
/**
*
* @param \DateTime|null $archivedDate
* @param string|null $oldBillingCode
* @param string|null $oldMatterNumber
* @param bool $wasArchived
*
* @return self
*/
public function addHistoricalApiValues(
?\DateTime $archivedDate,
?string $oldBillingCode,
?string $oldMatterNumber,
bool $wasArchived = false
): self {
$historicalApiValues = $this->getHistoricalApiValues() ?? [];
$historicalApiValues[] = [
'oldBillingCode' => $oldBillingCode ?? 'NA',
'oldMatterNumber' => $oldMatterNumber ?? 'NA',
'wasArchived' => $wasArchived,
'archivedDate' => $archivedDate ?? 'NA',
'modified' => new \DateTime(),
];
$this->setHistoricalApiValues($historicalApiValues);
return $this;
}
/**
* Get additional contacts
*
* @return null|Collection|User[]
*/
public function getAdditionalContacts(): ?Collection
{
return $this->additionalContacts;
}
/**
* Set additional contacts
*
* @param null|Collection|User[] $additionalContacts
*
* @return self
*/
public function setAdditionalContacts(?Collection $additionalContacts): self
{
$this->additionalContacts = $additionalContacts;
return $this;
}
/**
* Add an additional contact
*
* @param User $user
*
* @return self
*/
public function addAdditionalContact(User $user): self
{
if (!$this->additionalContacts->contains($user)) {
$this->additionalContacts[] = $user;
}
return $this;
}
/**
* Remove an additional contact
*
* @param User $user
*
* @return self
*/
public function removeAdditionalContact(User $user): self
{
$this->additionalContacts->removeElement($user);
return $this;
}
// get a string of additional contacts by looping through the collection
/**
* Get a formatted string of additional contacts' full names.
*
* @return string
*/
public function getAdditionalContactsFormatted(): string
{
$names = [];
foreach ($this->additionalContacts as $user) {
$names[] = $user->getFullName();
}
return implode(', ', $names);
}
/**
* Represented by a multi-dimensional array of field changes.
* Do not allow access to setter, use the addHistoricalApiValues method instead.
*
* @param null|array $historicalApiValues
*
* @return self
*/
protected function setHistoricalApiValues(?array $historicalApiValues): self
{
$this->historicalApiValues = $historicalApiValues;
return $this;
}
}