Перевод на доменную архитектуру
This commit is contained in:
12
app/Domain/Reports/Models/MetricAggregate.php
Normal file
12
app/Domain/Reports/Models/MetricAggregate.php
Normal file
@@ -0,0 +1,12 @@
|
||||
<?php
|
||||
|
||||
namespace App\Domain\Reports\Models;
|
||||
|
||||
final readonly class MetricAggregate
|
||||
{
|
||||
public function __construct(
|
||||
public int $total,
|
||||
public int $count,
|
||||
public float $average,
|
||||
) {}
|
||||
}
|
||||
23
app/Domain/Reports/Models/MetricResultCollection.php
Normal file
23
app/Domain/Reports/Models/MetricResultCollection.php
Normal file
@@ -0,0 +1,23 @@
|
||||
<?php
|
||||
|
||||
namespace App\Domain\Reports\Models;
|
||||
|
||||
use App\Domain\Reports\ValueObjects\MetrikaConfig;
|
||||
|
||||
final readonly class MetricResultCollection
|
||||
{
|
||||
/**
|
||||
* @param array<int|string, int|float|string|null> $metrics
|
||||
*/
|
||||
public function __construct(
|
||||
public array $metrics = [],
|
||||
) {}
|
||||
|
||||
/**
|
||||
* @return array<int, int|float|string|null>
|
||||
*/
|
||||
public function normalized(): array
|
||||
{
|
||||
return MetrikaConfig::normalizeMetrics($this->metrics);
|
||||
}
|
||||
}
|
||||
13
app/Domain/Reports/Models/OperationInterval.php
Normal file
13
app/Domain/Reports/Models/OperationInterval.php
Normal file
@@ -0,0 +1,13 @@
|
||||
<?php
|
||||
|
||||
namespace App\Domain\Reports\Models;
|
||||
|
||||
use DateTimeImmutable;
|
||||
|
||||
final readonly class OperationInterval
|
||||
{
|
||||
public function __construct(
|
||||
public DateTimeImmutable $admittedAt,
|
||||
public DateTimeImmutable $operationAt,
|
||||
) {}
|
||||
}
|
||||
20
app/Domain/Reports/Models/PatientCollection.php
Normal file
20
app/Domain/Reports/Models/PatientCollection.php
Normal file
@@ -0,0 +1,20 @@
|
||||
<?php
|
||||
|
||||
namespace App\Domain\Reports\Models;
|
||||
|
||||
final readonly class PatientCollection
|
||||
{
|
||||
/**
|
||||
* @param array<int, array<string, mixed>> $items
|
||||
* @param array<string, mixed> $metadata
|
||||
*/
|
||||
public function __construct(
|
||||
public array $items = [],
|
||||
public array $metadata = [],
|
||||
) {}
|
||||
|
||||
public function metadata(string $key, mixed $default = null): mixed
|
||||
{
|
||||
return $this->metadata[$key] ?? $default;
|
||||
}
|
||||
}
|
||||
21
app/Domain/Reports/Models/ReportContext.php
Normal file
21
app/Domain/Reports/Models/ReportContext.php
Normal file
@@ -0,0 +1,21 @@
|
||||
<?php
|
||||
|
||||
namespace App\Domain\Reports\Models;
|
||||
|
||||
use DateTimeImmutable;
|
||||
|
||||
final readonly class ReportContext
|
||||
{
|
||||
/**
|
||||
* @param array<string, mixed> $metadata
|
||||
*/
|
||||
public function __construct(
|
||||
public int $departmentId,
|
||||
public int $userId,
|
||||
public ?int $actorUserId,
|
||||
public DateTimeImmutable $periodStart,
|
||||
public DateTimeImmutable $periodEnd,
|
||||
public string $reportType = 'daily',
|
||||
public array $metadata = [],
|
||||
) {}
|
||||
}
|
||||
85
app/Domain/Reports/Models/ReportSnapshot.php
Normal file
85
app/Domain/Reports/Models/ReportSnapshot.php
Normal file
@@ -0,0 +1,85 @@
|
||||
<?php
|
||||
|
||||
namespace App\Domain\Reports\Models;
|
||||
|
||||
use App\Domain\Reports\ValueObjects\MetrikaConfig;
|
||||
use DateTimeImmutable;
|
||||
use InvalidArgumentException;
|
||||
|
||||
final readonly class ReportSnapshot
|
||||
{
|
||||
/**
|
||||
* @param array<int|string, int|float|string|null> $metrics
|
||||
* @param array<int, array<string, mixed>> $observationPatients
|
||||
* @param array<int, array<string, mixed>> $unwantedEvents
|
||||
*/
|
||||
public function __construct(
|
||||
public int $departmentId,
|
||||
public int $userId,
|
||||
public ?int $actorUserId,
|
||||
public DateTimeImmutable $periodStart,
|
||||
public DateTimeImmutable $periodEnd,
|
||||
public string $status = 'draft',
|
||||
public bool $autoFill = false,
|
||||
public array $metrics = [],
|
||||
public array $observationPatients = [],
|
||||
public array $unwantedEvents = [],
|
||||
public ?int $reportId = null,
|
||||
public ?DateTimeImmutable $createdAt = null,
|
||||
public ?DateTimeImmutable $sentAt = null,
|
||||
public string $reportType = 'daily',
|
||||
) {
|
||||
if ($this->departmentId <= 0) {
|
||||
throw new InvalidArgumentException('departmentId must be positive.');
|
||||
}
|
||||
|
||||
if ($this->userId <= 0) {
|
||||
throw new InvalidArgumentException('userId must be positive.');
|
||||
}
|
||||
|
||||
if ($this->periodEnd < $this->periodStart) {
|
||||
throw new InvalidArgumentException('periodEnd must not be earlier than periodStart.');
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array<int, int|float|string|null>
|
||||
*/
|
||||
public function normalizedMetrics(): array
|
||||
{
|
||||
return MetrikaConfig::normalizeMetrics($this->metrics);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array<string, int|float|string|null>
|
||||
*/
|
||||
public function payloadMetrics(): array
|
||||
{
|
||||
return MetrikaConfig::toPayloadMetrics($this->normalizedMetrics());
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array<string, mixed>
|
||||
*/
|
||||
public function toComparableArray(): array
|
||||
{
|
||||
$observationPatients = $this->observationPatients;
|
||||
$unwantedEvents = $this->unwantedEvents;
|
||||
|
||||
sort($observationPatients);
|
||||
sort($unwantedEvents);
|
||||
|
||||
return [
|
||||
'department_id' => $this->departmentId,
|
||||
'user_id' => $this->userId,
|
||||
'actor_user_id' => $this->actorUserId,
|
||||
'period_start' => $this->periodStart->format('Y-m-d H:i:s'),
|
||||
'period_end' => $this->periodEnd->format('Y-m-d H:i:s'),
|
||||
'status' => $this->status,
|
||||
'auto_fill' => $this->autoFill,
|
||||
'metrics' => $this->normalizedMetrics(),
|
||||
'observation_patients' => $observationPatients,
|
||||
'unwanted_events' => $unwantedEvents,
|
||||
];
|
||||
}
|
||||
}
|
||||
11
app/Domain/Reports/Models/SavedReportResult.php
Normal file
11
app/Domain/Reports/Models/SavedReportResult.php
Normal file
@@ -0,0 +1,11 @@
|
||||
<?php
|
||||
|
||||
namespace App\Domain\Reports\Models;
|
||||
|
||||
final readonly class SavedReportResult
|
||||
{
|
||||
public function __construct(
|
||||
public int $reportId,
|
||||
public ReportSnapshot $snapshot,
|
||||
) {}
|
||||
}
|
||||
13
app/Domain/Reports/Models/StayInterval.php
Normal file
13
app/Domain/Reports/Models/StayInterval.php
Normal file
@@ -0,0 +1,13 @@
|
||||
<?php
|
||||
|
||||
namespace App\Domain\Reports\Models;
|
||||
|
||||
use DateTimeImmutable;
|
||||
|
||||
final readonly class StayInterval
|
||||
{
|
||||
public function __construct(
|
||||
public DateTimeImmutable $startAt,
|
||||
public DateTimeImmutable $endAt,
|
||||
) {}
|
||||
}
|
||||
Reference in New Issue
Block a user