Перевод на доменную архитектуру

This commit is contained in:
brusnitsyn
2026-04-26 23:37:50 +09:00
parent 75ca01ffd8
commit f107ebd167
70 changed files with 4656 additions and 2070 deletions

View 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,
) {}
}

View 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);
}
}

View 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,
) {}
}

View 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;
}
}

View 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 = [],
) {}
}

View 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,
];
}
}

View File

@@ -0,0 +1,11 @@
<?php
namespace App\Domain\Reports\Models;
final readonly class SavedReportResult
{
public function __construct(
public int $reportId,
public ReportSnapshot $snapshot,
) {}
}

View 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,
) {}
}