Добавил вывод метрик для врача дежурного
This commit is contained in:
@@ -928,11 +928,11 @@ class DutyReportService
|
||||
$admitted = $stats['admitted'] ?? [];
|
||||
|
||||
// === Базовые счётчики ===
|
||||
$patientsIsRecipient = array_key_exists('recipient', $statsOverride)
|
||||
$patientsIsRecipient = array_key_exists('recipient', $statsOverride) && !empty($statsOverride['recipient'])
|
||||
? $statsOverride['recipient'] : $byStatus['recipient'] ?? 0;
|
||||
$patientsInDepartment = array_key_exists('in_department', $statsOverride)
|
||||
$patientsInDepartment = array_key_exists('in_department', $statsOverride) && !empty($statsOverride['in_department'])
|
||||
? $statsOverride['in_department'] : $byStatus['in_department'] ?? 0;
|
||||
$patientsIsDischarged = array_key_exists('outcome', $statsOverride)
|
||||
$patientsIsDischarged = array_key_exists('outcome', $statsOverride) && !empty($statsOverride['outcome'])
|
||||
? $statsOverride['outcome'] : $byStatus['outcome'] ?? 0;
|
||||
$patientsIsTransferred = $stats['transferred'] ?? 0;
|
||||
$patientsIsDeceased = $byStatus['deceased'] ?? 0;
|
||||
@@ -977,7 +977,7 @@ class DutyReportService
|
||||
$this->saveMetric($reportDuty->id, 8, $patientsInDepartment); // Пациентов в отделении
|
||||
$this->saveMetric($reportDuty->id, 3, $patientsIsRecipient); // Поступило
|
||||
$this->saveMetric($reportDuty->id, 15, $patientsIsDischarged); // Выписано
|
||||
$this->saveMetric($reportDuty->id, 7, $patientsIsDischarged); // Выписано
|
||||
$this->saveMetric($reportDuty->id, 7, $patientsIsDischarged); // Выписано
|
||||
$this->saveMetric($reportDuty->id, 13, $patientsIsTransferred); // Переведено
|
||||
$this->saveMetric($reportDuty->id, 9, $patientsIsDeceased); // Умерло
|
||||
|
||||
|
||||
@@ -6,6 +6,8 @@ use App\Models\MedicalHistory;
|
||||
use App\Models\MedicalHistorySnapshot;
|
||||
use App\Models\Report;
|
||||
use Illuminate\Support\Carbon;
|
||||
use Illuminate\Support\Collection;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
|
||||
class MetrikaService
|
||||
{
|
||||
@@ -110,4 +112,32 @@ class MetrikaService
|
||||
|
||||
return $metrics;
|
||||
}
|
||||
|
||||
/**
|
||||
* Подсчитывает базовую статистику для отчетов дежурного врача
|
||||
* Поступило, выбыло, состоит и мед. персонал
|
||||
* @param Collection $reportsDuty
|
||||
* @return array
|
||||
*/
|
||||
public function calculateBaseStatistics(Collection $reportsDuty): array
|
||||
{
|
||||
$reportIds = $reportsDuty->pluck('id'); // получаем ID всех отчётов
|
||||
|
||||
// Один запрос, который сразу возвращает суммы по каждому типу
|
||||
$totals = DB::table('duty_report_metric_results')
|
||||
->whereIn('rf_report_id', $reportIds) // предполагаем внешний ключ `report_id`
|
||||
->whereIn('rf_metrika_item_id', [3, 7, 8, 17])
|
||||
->select('rf_metrika_item_id', DB::raw('SUM(value::integer) as total'))
|
||||
->groupBy('rf_metrika_item_id')
|
||||
->pluck('total', 'rf_metrika_item_id')
|
||||
->toArray();
|
||||
|
||||
// Формируем итоговый массив с ключами, как у вас
|
||||
return [
|
||||
'recipient' => $totals[3] ?? 0,
|
||||
'outcome' => $totals[7] ?? 0,
|
||||
'current' => $totals[8] ?? 0,
|
||||
'staff' => $totals[17] ?? 0,
|
||||
];
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user