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

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,33 @@
<?php
namespace App\Domain\Reports\Calculators;
use App\Domain\Reports\Models\MetricAggregate;
use App\Domain\Reports\Models\OperationInterval;
final class PreoperativeDaysCalculator
{
/**
* @param iterable<OperationInterval> $intervals
*/
public function calculate(iterable $intervals): MetricAggregate
{
$totalDays = 0;
$patientCount = 0;
foreach ($intervals as $interval) {
if ($interval->operationAt < $interval->admittedAt) {
continue;
}
$totalDays += $interval->admittedAt->setTime(0, 0)->diff($interval->operationAt->setTime(0, 0))->days;
$patientCount++;
}
return new MetricAggregate(
total: $totalDays,
count: $patientCount,
average: $patientCount > 0 ? round($totalDays / $patientCount, 1) : 0.0,
);
}
}