Перевод на доменную архитектуру
This commit is contained in:
33
app/Domain/Reports/Calculators/BedDaysCalculator.php
Normal file
33
app/Domain/Reports/Calculators/BedDaysCalculator.php
Normal file
@@ -0,0 +1,33 @@
|
||||
<?php
|
||||
|
||||
namespace App\Domain\Reports\Calculators;
|
||||
|
||||
use App\Domain\Reports\Models\MetricAggregate;
|
||||
use App\Domain\Reports\Models\StayInterval;
|
||||
|
||||
final class BedDaysCalculator
|
||||
{
|
||||
/**
|
||||
* @param iterable<StayInterval> $intervals
|
||||
*/
|
||||
public function calculate(iterable $intervals): MetricAggregate
|
||||
{
|
||||
$totalDays = 0;
|
||||
$patientCount = 0;
|
||||
|
||||
foreach ($intervals as $interval) {
|
||||
if ($interval->endAt < $interval->startAt) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$totalDays += $interval->startAt->setTime(0, 0)->diff($interval->endAt->setTime(0, 0))->days;
|
||||
$patientCount++;
|
||||
}
|
||||
|
||||
return new MetricAggregate(
|
||||
total: $totalDays,
|
||||
count: $patientCount,
|
||||
average: $patientCount > 0 ? round($totalDays / $patientCount, 2) : 0.0,
|
||||
);
|
||||
}
|
||||
}
|
||||
15
app/Domain/Reports/Calculators/DepartmentLoadCalculator.php
Normal file
15
app/Domain/Reports/Calculators/DepartmentLoadCalculator.php
Normal file
@@ -0,0 +1,15 @@
|
||||
<?php
|
||||
|
||||
namespace App\Domain\Reports\Calculators;
|
||||
|
||||
final class DepartmentLoadCalculator
|
||||
{
|
||||
public function calculate(int|float $currentCount, int|float $bedsCount): int
|
||||
{
|
||||
if ($bedsCount <= 0) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
return (int) round($currentCount * 100 / $bedsCount);
|
||||
}
|
||||
}
|
||||
@@ -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,
|
||||
);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user