Skip to content

Commit

Permalink
UML-3136: Update viewer journey templates to support combined LPAs (#…
Browse files Browse the repository at this point in the history
…2903)

* update types to display viewer journey

* update casters and templates for remaining combined lpa format

* add code-sniffer-pre-commit

* fix brackets

* include pre-commit origins

* feature flag by separate templates

* drop unused template

* cover new enums and entities

* drop sniffer hook, share mock data, cover feature enabled injection

* cover ParseLpaData

* cover serialisation

* return HowAttorneysAct and WhenCanLpaBeUsed from API, fix templates, fix PDF download

* format

* add missing strict_types

* more test fixes

* test fixes

* cover getters

* revert api changes (to be extracted to new branch)

* more api revert

* ensure LpaType is accessible, fix addresses, make mock combined data dynamic

* reinstate mocked values

* bump cov

* revert api

* fix sniffs

* fix sniffs

* Remove Serialisation code and revert field name change.

* Fix unit tests and remove tests we don't need

* Remove JsonSerializable definitions

* Further test cleanup

* Use correct 'uid' field name

---------

Co-authored-by: Allen Annom <[email protected]>
Co-authored-by: Adam Cooper <[email protected]>
  • Loading branch information
3 people authored Nov 27, 2024
1 parent 1bc3a1d commit 4f38b73
Show file tree
Hide file tree
Showing 57 changed files with 2,057 additions and 1,197 deletions.
1 change: 1 addition & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ services:
XDEBUG_MODE: develop,debug,coverage
SESSION_EXPIRES: 30 # session expiry length to support timeout message.
COOKIE_EXPIRES: 1440 # cookie expiry for complete logout - initial value to be 24 hours.
SUPPORT_DATASTORE_LPAS: "false"
depends_on:
- api-web

Expand Down
31 changes: 20 additions & 11 deletions service-front/app/src/Common/src/Entity/Address.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

class Address
{
protected int $id;
protected ?int $id = null;
protected ?string $town = null;
protected ?string $county = null;
protected ?string $postcode = null;
Expand All @@ -16,93 +16,102 @@ class Address
protected ?string $addressLine2 = null;
protected ?string $addressLine3 = null;

public function getId(): int
public function getId(): ?int
{
return $this->id;
}

public function setId(int $id): void
public function setId(int $id): self
{
$this->id = $id;
return $this;
}

public function getTown(): ?string
{
return $this->town;
}

public function setTown(string $town): void
public function setTown(string $town): self
{
$this->town = $town;
return $this;
}

public function getCounty(): ?string
{
return $this->county;
}

public function setCounty(string $county): void
public function setCounty(?string $county): self
{
$this->county = $county;
return $this;
}

public function getPostcode(): ?string
{
return $this->postcode;
}

public function setPostcode(string $postcode): void
public function setPostcode(string $postcode): self
{
$this->postcode = $postcode;
return $this;
}

public function getCountry(): ?string
{
return $this->country;
}

public function setCountry(string $country): void
public function setCountry(?string $country): self
{
$this->country = $country;
return $this;
}

public function getType(): ?string
{
return $this->type;
}

public function setType(string $type): void
public function setType(string $type): self
{
$this->type = $type;
return $this;
}

public function getAddressLine1(): ?string
{
return $this->addressLine1;
}

public function setAddressLine1(string $addressLine1): void
public function setAddressLine1(string $addressLine1): self
{
$this->addressLine1 = $addressLine1;
return $this;
}

public function getAddressLine2(): ?string
{
return $this->addressLine2;
}

public function setAddressLine2(string $addressLine2): void
public function setAddressLine2(?string $addressLine2): self
{
$this->addressLine2 = $addressLine2;
return $this;
}

public function getAddressLine3(): ?string
{
return $this->addressLine3;
}

public function setAddressLine3(string $addressLine3): void
public function setAddressLine3(?string $addressLine3): self
{
$this->addressLine3 = $addressLine3;
return $this;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,12 @@
#[Attribute(Attribute::TARGET_PARAMETER)]
class CastToCaseSubtype implements PropertyCaster
{
public function cast(mixed $value, ObjectMapper $hydrator): string
public function cast(mixed $value, ObjectMapper $hydrator): ?string
{
return LpaType::fromShortName($value)->value;
if (is_null(LpaType::tryFrom($value))) {
return LpaType::fromShortName($value)->value;
}

return LpaType::from($value)->value;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<?php

declare(strict_types=1);

namespace Common\Entity\Casters;

use Attribute;
use Common\Enum\HowAttorneysMakeDecisions;
use Common\Enum\WhenTheLpaCanBeUsed;
use EventSauce\ObjectHydrator\ObjectMapper;
use EventSauce\ObjectHydrator\PropertyCaster;

#[Attribute(Attribute::TARGET_PARAMETER)]
class CastToHowAttorneysMakeDecisions implements PropertyCaster
{
public function cast(mixed $value, ObjectMapper $hydrator): ?string
{
return HowAttorneysMakeDecisions::from($value)->value;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

use Common\Enum\LifeSustainingTreatment;
use Attribute;
use Common\Enum\LpaType;
use EventSauce\ObjectHydrator\ObjectMapper;
use EventSauce\ObjectHydrator\PropertyCaster;

Expand All @@ -14,6 +15,10 @@ class CastToLifeSustainingTreatment implements PropertyCaster
{
public function cast(mixed $value, ObjectMapper $hydrator): mixed
{
if (is_null(LifeSustainingTreatment::tryFrom($value))) {
return LifeSustainingTreatment::fromShortName($value)->value;
}

return LifeSustainingTreatment::from($value)->value;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@

namespace Common\Entity\Casters;

use Common\Enum\HowAttorneysMakeDecisions;
use Attribute;
use Common\Enum\WhenTheLpaCanBeUsed;
use EventSauce\ObjectHydrator\ObjectMapper;
use EventSauce\ObjectHydrator\PropertyCaster;

Expand All @@ -14,6 +14,14 @@ class CastToWhenTheLpaCanBeUsed implements PropertyCaster
{
public function cast(mixed $value, ObjectMapper $hydrator): ?string
{
return HowAttorneysMakeDecisions::from($value)->value;
if (is_null(WhenTheLpaCanBeUsed::tryFrom($value))) {
$value = match ($value) {
'when registered' => WhenTheLpaCanBeUsed::WHEN_HAS_CAPACITY->value,
'loss of capacity' => WhenTheLpaCanBeUsed::WHEN_CAPACITY_LOST->value,
default => '',
};
}

return WhenTheLpaCanBeUsed::from($value)->value;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<?php

declare(strict_types=1);

namespace Common\Entity\Casters;

use Attribute;
use EventSauce\ObjectHydrator\ObjectMapper;
use EventSauce\ObjectHydrator\PropertyCaster;

#[Attribute(Attribute::TARGET_PARAMETER)]
class ExtractPostcodeFromLpaStore implements PropertyCaster
{
public function cast(mixed $value, ObjectMapper $hydrator): ?string
{
if (is_array($value) && isset($value['postcode'])) {
return $value['postcode'];
}

return null;
}
}
77 changes: 62 additions & 15 deletions service-front/app/src/Common/src/Entity/CombinedLpa.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,22 +9,24 @@
use Common\Enum\LpaType;
use Common\Service\Lpa\ServiceInterfaces\GroupLpasInterface;
use Common\Service\Lpa\ServiceInterfaces\SortLpasInterface;
use Common\Enum\WhenTheLpaCanBeUsed;
use DateTimeImmutable;
use JsonSerializable;

class CombinedLpa implements JsonSerializable, SortLpasInterface, GroupLpasInterface
class CombinedLpa implements SortLpasInterface, GroupLpasInterface
{
public function __construct(
public readonly ?bool $applicationHasGuidance,
public readonly ?bool $applicationHasRestrictions,
public readonly ?string $applicationType,
public readonly ?HowAttorneysMakeDecisions $attorneyActDecisions,
/** @var Person[] $attorneys */
public readonly ?array $attorneys,
public readonly ?LpaType $caseSubtype,
public readonly ?string $channel,
public readonly ?DateTimeImmutable $dispatchDate,
public readonly ?Person $donor,
public readonly ?bool $hasSeveranceWarning,
public readonly ?HowAttorneysMakeDecisions $howAttorneysMakeDecisions,
public readonly ?DateTimeImmutable $invalidDate,
public readonly ?LifeSustainingTreatment $lifeSustainingTreatment,
public readonly ?DateTimeImmutable $lpaDonorSignatureDate,
Expand All @@ -33,28 +35,18 @@ public function __construct(
public readonly ?DateTimeImmutable $receiptDate,
public readonly ?DateTimeImmutable $registrationDate,
public readonly ?DateTimeImmutable $rejectedDate,
/** @var Person[] $replacementAttorneys */
public readonly ?array $replacementAttorneys,
public readonly ?string $status,
public readonly ?DateTimeImmutable $statusDate,
/** @var Person[] $trustCorporations */
public readonly ?array $trustCorporations,
public readonly ?string $uId,
public readonly ?DateTimeImmutable $withdrawnDate,
public readonly ?WhenTheLpaCanBeUsed $whenTheLpaCanBeUsed,
) {
}

public function jsonSerialize(): mixed
{
$data = get_object_vars($this);

array_walk($data, function (&$value) {
if ($value instanceof DateTimeImmutable) {
$value = $value->format('Y-m-d H:i:s.uO');
}
});

return $data;
}

public function getLpaDonorSignatureDate(): ?DateTimeImmutable
{
return $this->lpaDonorSignatureDate;
Expand Down Expand Up @@ -84,4 +76,59 @@ public function getCaseSubtype(): string
{
return $this->caseSubtype->value;
}

public function getStatus(): ?string
{
return $this->status;
}

public function getLifeSustainingTreatment(): string
{
return $this->lifeSustainingTreatment->value;
}

public function getHowAttorneysMakeDecisions(): HowAttorneysMakeDecisions
{
return $this->howAttorneysMakeDecisions;
}

public function getCaseAttorneySingular(): bool
{
return $this->howAttorneysMakeDecisions === HowAttorneysMakeDecisions::SINGULAR;
}

public function getCaseAttorneyJointly(): bool
{
return $this->howAttorneysMakeDecisions === HowAttorneysMakeDecisions::JOINTLY;
}

public function getCaseAttorneyJointlyAndSeverally(): bool
{
return $this->howAttorneysMakeDecisions === HowAttorneysMakeDecisions::JOINTLY_AND_SEVERALLY;
}

public function getCaseAttorneyJointlyAndJointlyAndSeverally(): bool
{
return $this->howAttorneysMakeDecisions === HowAttorneysMakeDecisions::JOINTLY_FOR_SOME_SEVERALLY_FOR_OTHERS;
}

public function getActiveAttorneys(): ?array
{
return $this->attorneys;
}

public function getTrustCorporations(): ?array
{
return $this->trustCorporations;
}

public function getWhenTheLpaCanBeUsed(): WhenTheLpaCanBeUsed
{
return $this->whenTheLpaCanBeUsed;
}

public function getLpaType(): LpaType
{
return LpaType::from($this->getCaseSubtype());
}
}
Loading

0 comments on commit 4f38b73

Please sign in to comment.