Форматирование
This commit is contained in:
@@ -1,15 +1,13 @@
|
||||
<?php
|
||||
|
||||
// app/Services/BedDayService.php
|
||||
|
||||
namespace App\Services;
|
||||
|
||||
use App\Models\MedicalHistorySnapshot;
|
||||
use App\Models\MetrikaResult;
|
||||
use App\Models\Report;
|
||||
use App\Models\MedicalHistorySnapshot;
|
||||
use App\Models\MisMedicalHistory;
|
||||
use Carbon\Carbon;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use Illuminate\Support\Collection;
|
||||
|
||||
class BedDayService
|
||||
{
|
||||
@@ -28,7 +26,7 @@ class BedDayService
|
||||
*/
|
||||
public function getAverageBedDaysFromSnapshots(int $departmentId, string $startDate, string $endDate, bool $isRangeOneDay): float
|
||||
{
|
||||
$cacheKey = "snapshots_{$departmentId}_{$startDate}_{$endDate}_" . ($isRangeOneDay ? '1day' : 'range');
|
||||
$cacheKey = "snapshots_{$departmentId}_{$startDate}_{$endDate}_".($isRangeOneDay ? '1day' : 'range');
|
||||
|
||||
if (isset($this->cache[$cacheKey])) {
|
||||
return $this->cache[$cacheKey];
|
||||
@@ -47,6 +45,7 @@ class BedDayService
|
||||
|
||||
if ($reports->isEmpty()) {
|
||||
$this->cache[$cacheKey] = 0;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -59,6 +58,7 @@ class BedDayService
|
||||
|
||||
if ($snapshots->isEmpty()) {
|
||||
$this->cache[$cacheKey] = 0;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -96,7 +96,7 @@ class BedDayService
|
||||
return [];
|
||||
}
|
||||
|
||||
$cacheKey = 'all_snapshots_' . md5(implode(',', $departmentIds) . $startDate . $endDate . ($isRangeOneDay ? '1day' : 'range'));
|
||||
$cacheKey = 'all_snapshots_'.md5(implode(',', $departmentIds).$startDate.$endDate.($isRangeOneDay ? '1day' : 'range'));
|
||||
|
||||
if (isset($this->cache[$cacheKey])) {
|
||||
return $this->cache[$cacheKey];
|
||||
@@ -121,6 +121,7 @@ class BedDayService
|
||||
|
||||
if ($departmentReports->isEmpty()) {
|
||||
$averages[$departmentId] = 0;
|
||||
|
||||
continue;
|
||||
}
|
||||
|
||||
@@ -135,6 +136,7 @@ class BedDayService
|
||||
|
||||
if ($snapshots->isEmpty()) {
|
||||
$averages[$departmentId] = 0;
|
||||
|
||||
continue;
|
||||
}
|
||||
|
||||
@@ -199,7 +201,7 @@ class BedDayService
|
||||
'total_patients' => 0,
|
||||
'average_bed_days' => 0,
|
||||
'distribution' => [],
|
||||
'by_month' => []
|
||||
'by_month' => [],
|
||||
];
|
||||
}
|
||||
|
||||
@@ -216,7 +218,7 @@ class BedDayService
|
||||
'total_patients' => 0,
|
||||
'average_bed_days' => 0,
|
||||
'distribution' => [],
|
||||
'by_month' => []
|
||||
'by_month' => [],
|
||||
];
|
||||
}
|
||||
|
||||
@@ -226,7 +228,7 @@ class BedDayService
|
||||
'8-14' => 0,
|
||||
'15-21' => 0,
|
||||
'22-30' => 0,
|
||||
'30+' => 0
|
||||
'30+' => 0,
|
||||
];
|
||||
|
||||
$byMonth = [];
|
||||
@@ -245,16 +247,23 @@ class BedDayService
|
||||
$validCount++;
|
||||
|
||||
// Распределение
|
||||
if ($days <= 3) $distribution['1-3']++;
|
||||
elseif ($days <= 7) $distribution['4-7']++;
|
||||
elseif ($days <= 14) $distribution['8-14']++;
|
||||
elseif ($days <= 21) $distribution['15-21']++;
|
||||
elseif ($days <= 30) $distribution['22-30']++;
|
||||
else $distribution['30+']++;
|
||||
if ($days <= 3) {
|
||||
$distribution['1-3']++;
|
||||
} elseif ($days <= 7) {
|
||||
$distribution['4-7']++;
|
||||
} elseif ($days <= 14) {
|
||||
$distribution['8-14']++;
|
||||
} elseif ($days <= 21) {
|
||||
$distribution['15-21']++;
|
||||
} elseif ($days <= 30) {
|
||||
$distribution['22-30']++;
|
||||
} else {
|
||||
$distribution['30+']++;
|
||||
}
|
||||
|
||||
// По месяцам
|
||||
$month = $end->format('Y-m');
|
||||
if (!isset($byMonth[$month])) {
|
||||
if (! isset($byMonth[$month])) {
|
||||
$byMonth[$month] = ['total' => 0, 'count' => 0];
|
||||
}
|
||||
$byMonth[$month]['total'] += $days;
|
||||
@@ -269,7 +278,7 @@ class BedDayService
|
||||
$monthlyStats[] = [
|
||||
'month' => $month,
|
||||
'avg_days' => round($data['total'] / $data['count'], 1),
|
||||
'count' => $data['count']
|
||||
'count' => $data['count'],
|
||||
];
|
||||
}
|
||||
|
||||
@@ -279,7 +288,7 @@ class BedDayService
|
||||
'total_patients' => $validCount,
|
||||
'average_bed_days' => $validCount > 0 ? round($totalDays / $validCount, 1) : 0,
|
||||
'distribution' => $distribution,
|
||||
'by_month' => $monthlyStats
|
||||
'by_month' => $monthlyStats,
|
||||
];
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user