Skip to content

Commit

Permalink
Uml 3692 & UML 3691 grouplpa and sortlpa refactored to handle new for…
Browse files Browse the repository at this point in the history
…mat (#2902)

* UML-3692 & UML-3691 added an interface similar to the current one in order to access donor properties
for sort and group lpa invokable functions

* added relevant test cases

* added GroupLpasInterface.php and moved interface to CombinedLpa.php

* added tests for getters in the CombinedLpaTest.php

* removed objecthydrator serialising usage and tests as it is un-needed - using json serialising

---------

Co-authored-by: Adam Cooper <[email protected]>
  • Loading branch information
allenannom and cooperaj authored Nov 5, 2024
1 parent 73ee16e commit 676f8fd
Show file tree
Hide file tree
Showing 14 changed files with 266 additions and 39 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

namespace App\Service\Lpa;

use App\Entity\Lpa;
use App\Entity\LpaStore\LpaStore;
use App\Entity\Sirius\SiriusLpa;
use EventSauce\ObjectHydrator\DefinitionProvider;
Expand Down
38 changes: 34 additions & 4 deletions service-front/app/src/Common/src/Entity/CombinedLpa.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,12 @@
use Common\Enum\HowAttorneysMakeDecisions;
use Common\Enum\LifeSustainingTreatment;
use Common\Enum\LpaType;
use Common\Service\Lpa\ServiceInterfaces\GroupLpasInterface;
use Common\Service\Lpa\ServiceInterfaces\SortLpasInterface;
use DateTimeImmutable;
use EventSauce\ObjectHydrator\DoNotSerialize;
use JsonSerializable;

class CombinedLpa implements JsonSerializable
class CombinedLpa implements JsonSerializable, SortLpasInterface, GroupLpasInterface
{
public function __construct(
public readonly ?bool $applicationHasGuidance,
Expand All @@ -22,7 +23,7 @@ public function __construct(
public readonly ?LpaType $caseSubtype,
public readonly ?string $channel,
public readonly ?DateTimeImmutable $dispatchDate,
public readonly ?object $donor,
public readonly ?Person $donor,
public readonly ?bool $hasSeveranceWarning,
public readonly ?DateTimeImmutable $invalidDate,
public readonly ?LifeSustainingTreatment $lifeSustainingTreatment,
Expand All @@ -41,7 +42,6 @@ public function __construct(
) {
}

#[DoNotSerialize]
public function jsonSerialize(): mixed
{
$data = get_object_vars($this);
Expand All @@ -54,4 +54,34 @@ public function jsonSerialize(): mixed

return $data;
}

public function getLpaDonorSignatureDate(): ?DateTimeImmutable
{
return $this->lpaDonorSignatureDate;
}

public function getUId(): ?string
{
return $this->uId;
}

public function getApplicationHasGuidance(): ?bool
{
return $this->applicationHasGuidance;
}

public function getApplicationHasRestrictions(): ?bool
{
return $this->applicationHasRestrictions;
}

public function getDonor(): Person
{
return $this->donor;
}

public function getCaseSubtype(): string
{
return $this->caseSubtype->value;
}
}
26 changes: 26 additions & 0 deletions service-front/app/src/Common/src/Entity/Person.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,4 +28,30 @@ public function __construct(
public readonly ?string $uId,
) {
}

public function getSalutation(): ?string
{
return '';
}

public function getFirstname(): ?string
{
return $this->firstname;
}

public function getMiddlenames(): ?string
{
return $this->otherNames;
}

public function getSurname(): ?string
{
return $this->surname;
}

public function getDob(): DateTimeImmutable|null
{
return $this->dob;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -56,9 +56,4 @@ private function getHydrationClass(array $lpa): string
? LpaStore::class
: SiriusLpa::class;
}

public function serializeObject(object $lpa): mixed
{
return $this->mapper->serializeObject($lpa);
}
}
2 changes: 1 addition & 1 deletion service-front/app/src/Common/src/Service/Lpa/GroupLpas.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

/**
* Single action invokeable that groups incoming LPA array objects according to our criteria.
* Groups LPAs by donor, separating incorrect matches by DoB
* Groups LPAs by donor, separating matches by DoB
*/
class GroupLpas
{
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<?php

declare(strict_types=1);

namespace Common\Service\Lpa\ServiceInterfaces;

use Common\Entity\Person;

interface GroupLpasInterface
{
public function getDonor(): Person;

public function getCaseSubtype(): string;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<?php

declare(strict_types=1);

namespace Common\Service\Lpa\ServiceInterfaces;

use Common\Entity\Person;

interface SortLpasInterface
{
public function getDonor(): Person;

public function getCaseSubtype(): string;
}
10 changes: 6 additions & 4 deletions service-front/app/src/Common/src/View/Twig/LpaExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,10 @@

namespace Common\View\Twig;

use Common\Entity\Person;
use Common\Entity\CaseActor;
use Common\Entity\Lpa;
use Common\Entity\CombinedLpa;
use DateTime;
use DateTimeInterface;
use Exception;
Expand Down Expand Up @@ -69,11 +71,11 @@ public function donorNameWithDobRemoved(string $donorNameAndDob): string
}

/**
* @param CaseActor $actor
* @param CaseActor|Person $actor
* @param bool $withSalutation Prepend salutation?
* @return string
*/
public function actorName(CaseActor $actor, bool $withSalutation = true): string
public function actorName(CaseActor|Person $actor, bool $withSalutation = true): string
{
$nameData = [];

Expand Down Expand Up @@ -193,13 +195,13 @@ public function formatViewerCode(string $viewerCode): string
return implode(' - ', $viewerCodeParts);
}

public function isLPACancelled(Lpa $lpa): bool
public function isLPACancelled(Lpa|CombinedLpa $lpa): bool
{
$status = $lpa->getStatus();
return ($status === 'Cancelled') || ($status === 'Revoked');
}

public function isDonorSignatureDateOld(Lpa $lpa): bool
public function isDonorSignatureDateOld(Lpa|CombinedLpa $lpa): bool
{
return $lpa->getLpaDonorSignatureDate() < new DateTime('2016-01-01');
}
Expand Down
38 changes: 38 additions & 0 deletions service-front/app/test/CommonTest/Entity/CombinedLpaTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
<?php

declare(strict_types=1);

namespace CommonTest\Entity;

use Common\Service\Lpa\Factory\LpaDataFormatter;
use DateTimeImmutable;
use PHPUnit\Framework\Attributes\Test;
use PHPUnit\Framework\TestCase;
use Prophecy\PhpUnit\ProphecyTrait;

class CombinedLpaTest extends TestCase
{
use ProphecyTrait;

private LpaDataFormatter $lpaDataFormatter;

public function setUp(): void
{
$this->lpaDataFormatter = new LpaDataFormatter();
}

#[Test]
public function can_test_getters()
{
$lpa = json_decode(file_get_contents(__DIR__ . '../../../../test/fixtures/test_lpa.json'), true);
$combinedLpa = ($this->lpaDataFormatter)($lpa);

$expectedUid = '700000000047';
$expectedApplicationHasGuidance = false;
$expectedHasRestrictions = false;

$this->assertEquals($expectedUid, $combinedLpa->getUId());
$this->assertEquals($expectedApplicationHasGuidance, $combinedLpa->getApplicationHasGuidance());
$this->assertEquals($expectedHasRestrictions, $combinedLpa->getApplicationHasRestrictions());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -129,17 +129,4 @@ public function can_serialise_datastore_lpa_to_modernise_format(): void

$this->assertEquals($expectedJsonLpa, $jsonLpa);
}

#[Test]
public function can_serialise_datastore_lpa_using_data_formatter(): void
{
$lpa = json_decode(file_get_contents(__DIR__ . '../../../../../test/fixtures/4UX3.json'), true);

$expectedLpa = $this->getExpectedLpa();

$newLpa = ($this->lpaDataFormatter)($lpa);
$serialisedLpa = $this->lpaDataFormatter->serializeObject($newLpa);

$this->assertEquals($expectedLpa, $serialisedLpa);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -151,16 +151,4 @@ public function can_serialise_sirius_lpa_to_modernise_format(): void

$this->assertEquals($expectedJsonLpa, $jsonLpa);
}

#[Test]
public function can_serialise_sirius_lpa_using_data_formatter(): void
{
$lpa = json_decode(file_get_contents(__DIR__ . '../../../../../test/fixtures/test_lpa.json'), true);

$expectedLpa = $this->getExpectedLpa();
$newLpa = ($this->lpaDataFormatter)($lpa);
$serialisedLpa = $this->lpaDataFormatter->serializeObject($newLpa);

$this->assertEquals($expectedLpa, $serialisedLpa);
}
}
42 changes: 42 additions & 0 deletions service-front/app/test/CommonTest/Entity/PersonTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
<?php

declare(strict_types=1);

namespace CommonTest\Entity;

use Common\Service\Lpa\Factory\LpaDataFormatter;
use DateTimeImmutable;
use PHPUnit\Framework\Attributes\Test;
use PHPUnit\Framework\TestCase;
use Prophecy\PhpUnit\ProphecyTrait;

class PersonTest extends TestCase
{
use ProphecyTrait;

private LpaDataFormatter $lpaDataFormatter;

public function setUp(): void
{
$this->lpaDataFormatter = new LpaDataFormatter();
}

#[Test]
public function can_test_getters()
{
$lpa = json_decode(file_get_contents(__DIR__ . '../../../../test/fixtures/test_lpa.json'), true);
$combinedLpa = ($this->lpaDataFormatter)($lpa);

$expectedSalutation = '';
$expectedFirstname = 'Rachel';
$expectedMiddlename = '';
$expectedSurname = 'Sanderson';
$expectedDob = new DateTimeImmutable('1948-11-01');

$this->assertEquals($expectedSalutation, $combinedLpa->getDonor()->getSalutation());
$this->assertEquals($expectedFirstname, $combinedLpa->getDonor()->getFirstname());
$this->assertEquals($expectedMiddlename, $combinedLpa->getDonor()->getMiddlenames());
$this->assertEquals($expectedSurname, $combinedLpa->getDonor()->getSurname());
$this->assertEquals($expectedDob, $combinedLpa->getDonor()->getDob());
}
}
70 changes: 70 additions & 0 deletions service-front/app/test/CommonTest/Entity/Sirius/SiriusLpaTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
<?php

declare(strict_types=1);

namespace CommonTest\Entity\Sirius;

use Common\Entity\Sirius\SiriusLpaDonor;
use Common\Service\Lpa\Factory\LpaDataFormatter;
use DateTimeImmutable;
use PHPUnit\Framework\Attributes\Test;
use PHPUnit\Framework\TestCase;
use Prophecy\PhpUnit\ProphecyTrait;

class SiriusLpaTest extends TestCase
{
use ProphecyTrait;

private LpaDataFormatter $lpaDataFormatter;

public function setUp(): void
{
$this->lpaDataFormatter = new LpaDataFormatter();
}

#[Test]
public function can_get_donor_test()
{
$lpa = json_decode(file_get_contents(__DIR__ . '../../../../../test/fixtures/test_lpa.json'), true);
$combinedLpa = ($this->lpaDataFormatter)($lpa);

$expectedDonor = new SiriusLpaDonor(
addressLine1: '81 Front Street',
addressLine2: 'LACEBY',
addressLine3: '',
country: '',
county: '',
dob: new DateTimeImmutable('1948-11-01'),
email: '[email protected]',
firstname: 'Rachel',
firstnames: null,
linked: [
[
'id' => 7,
'uId' => '700000000799',
],
],
name: null,
otherNames: null,
postcode: 'DN37 5SH',
surname: 'Sanderson',
systemStatus: null,
town: '',
type: 'Primary',
uId: '700000000799'
);

$this->assertEquals($expectedDonor, $combinedLpa->getDonor());
}

#[Test]
public function can_get_case_sub_type()
{
$lpa = json_decode(file_get_contents(__DIR__ . '../../../../../test/fixtures/test_lpa.json'), true);
$combinedLpa = ($this->lpaDataFormatter)($lpa);

$expectedCaseSubType = 'hw';

$this->assertEquals($expectedCaseSubType, $combinedLpa->getCaseSubType());
}
}
Loading

0 comments on commit 676f8fd

Please sign in to comment.