Обновлен стартовый экран

Переписаны запросы для статистики, отчетов
Добавлена интеграция отчета сестры
This commit is contained in:
brusnitsyn
2026-05-28 22:10:00 +09:00
parent 90e0d04dfd
commit 739168d427
96 changed files with 6663 additions and 1465 deletions

View File

@@ -47,13 +47,35 @@ class StatisticsService
$allDeptIds = $departments->flatten()->pluck('department_id')->toArray();
// 2а. Нежелательные события по отделениям за период (прямой запрос)
$unwantedCounts = DB::table('duty_unwanted_events as due')
->join('report_duties as rd', 'rd.id', '=', 'due.report_duty_id')
->whereIn('rd.rf_department_id', $allDeptIds)
->where('rd.period_start', '>=', $startDate)
->where('rd.period_end', '<=', $endDate)
->select('rd.rf_department_id', DB::raw('COUNT(*) as count'))
->groupBy('rd.rf_department_id')
->get()
->keyBy('rf_department_id');
// 2б. Пациенты на контроле по отделениям за период (прямой запрос)
$observableCounts = DB::table('observable_medical_histories as omh')
->join('report_duty_patients as rdp', 'rdp.original_id', '=', 'omh.original_id')
->join('report_duties as rd', 'rd.id', '=', 'rdp.report_duty_id')
->whereIn('rd.rf_department_id', $allDeptIds)
->where('omh.observable_in', '>=', $startDate)
->where('omh.observable_in', '<=', $endDate)
->select('rd.rf_department_id', DB::raw('COUNT(DISTINCT omh.id) as count'))
->groupBy('rd.rf_department_id')
->get()
->keyBy('rf_department_id');
// 2. Получаем ВСЕ метрики за период ОДНИМ запросом
$metrics = DB::table('reports as r')
->join('metrika_results as mr', 'r.report_id', '=', 'mr.rf_report_id')
$metrics = DB::table('report_duties as r')
->join('duty_report_metric_results as mr', 'r.id', '=', 'mr.rf_report_id')
->whereIn('r.rf_department_id', $allDeptIds)
->where('r.period_start', '>=', $startDate)
->where('r.period_start', '<=', $endDate)
->where('r.status', 'submitted')
->where('r.period_end', '<=', $endDate)
->select(
'r.rf_department_id',
'mr.rf_metrika_item_id',
@@ -65,11 +87,11 @@ class StatisticsService
->groupBy('rf_department_id');
// 3. Получаем текущих пациентов
$currentPatients = DB::table('reports as r')
->join('metrika_results as mr', 'r.report_id', '=', 'mr.rf_report_id')
$currentPatients = DB::table('report_duties as r')
->join('duty_report_metric_results as mr', 'r.id', '=', 'mr.rf_report_id')
->whereIn('r.rf_department_id', $allDeptIds)
->where('mr.rf_metrika_item_id', 8)
->where('r.period_start', '<=', $endDate)
->where('r.period_end', '<=', $endDate)
->select('r.rf_department_id', 'mr.value', 'r.created_at')
->orderBy('r.rf_department_id') // Сначала поле из DISTINCT ON
->orderBy('r.period_end', 'desc') // Потом остальные
@@ -130,8 +152,8 @@ class StatisticsService
$outcome = 0;
$deceased = 0;
$staff = 0;
$observable = 0;
$unwanted = 0;
$observable = (int) ($observableCounts[$deptId]->count ?? 0);
$unwanted = (int) ($unwantedCounts[$deptId]->count ?? 0);
$bedDaysSum = 0;
$avgBedDays = 0;
$preoperativeSum = 0;
@@ -154,8 +176,6 @@ class StatisticsService
7 => $outcome = (int) $value,
9 => $deceased = (int) $value,
17 => $staff = (int) $value,
14 => $observable = (int) $value,
16 => $unwanted = (int) $value,
25 => $bedDaysSum += $value,
19 => $lethalitySum = $value,
21 => $preoperativeAverageSum += $value,
@@ -363,8 +383,9 @@ class StatisticsService
*/
private function createTotalRow(string $type, array $total, bool $isGrandTotal): array
{
if ($total['preoperativePatientCount'] === 0) $total['preoperativePatientCount'] = 1;
if ($total['outcome_sum'] === 0) $total['outcome_sum'] = 1;
$outcomeSum = $total['outcome_sum'];
$preopPatients = $total['preoperativePatientCount'];
return [
'isTotalRow' => ! $isGrandTotal,
'isGrandTotal' => $isGrandTotal,
@@ -376,7 +397,7 @@ class StatisticsService
'emergency' => $total['recipients_emergency_sum'],
'transferred' => $total['recipients_transferred_sum'],
],
'outcome' => $total['outcome_sum'],
'outcome' => $outcomeSum,
'consist' => $total['consist_sum'],
'percentLoadedBeds' => '—',
'surgical' => [
@@ -384,9 +405,15 @@ class StatisticsService
'emergency' => $total['emergency_surgical_sum'],
],
'deceased' => $total['deceased_sum'],
'averageBedDays' => round($total['bedDaysSum'] / $total['outcome_sum'], 1),
'preoperativeDays' => round($total['preoperativeSum'] / $total['preoperativePatientCount'] < 0 ?? 1, 1),
'lethality' => round(($total['deceased_sum'] / $total['outcome_sum']) * 100, 2),
'averageBedDays' => $outcomeSum > 0
? round($total['bedDaysSum'] / $outcomeSum, 1)
: 0,
'preoperativeDays' => $preopPatients > 0
? round($total['preoperativeSum'] / $preopPatients, 1)
: 0,
'lethality' => $outcomeSum > 0
? round(($total['deceased_sum'] / $outcomeSum) * 100, 2)
: 0,
'type' => $type,
'departments_count' => $total['departments_count'],
'countStaff' => $total['staff_sum'],