Добавил базовые датасеты и агрегации для конструктора отчетов
This commit is contained in:
138
app/Services/Analytics/ReportPresetRegistry.php
Normal file
138
app/Services/Analytics/ReportPresetRegistry.php
Normal file
@@ -0,0 +1,138 @@
|
||||
<?php
|
||||
|
||||
namespace App\Services\Analytics;
|
||||
|
||||
/**
|
||||
* Готовые пресеты (системные шаблоны) для каталога и модалки выбора шаблона.
|
||||
* Каждый пресет — это преднастроенная конфигурация конструктора.
|
||||
*/
|
||||
class ReportPresetRegistry
|
||||
{
|
||||
/**
|
||||
* @return array<int,array<string,mixed>>
|
||||
*/
|
||||
public function all(): array
|
||||
{
|
||||
return [
|
||||
[
|
||||
'key' => 'blank',
|
||||
'label' => 'Без шаблона',
|
||||
'description' => 'Самостоятельно выберите источник, группировки и показатели',
|
||||
'category' => 'Все',
|
||||
'dataset' => null,
|
||||
'thumbnail' => [],
|
||||
'config' => $this->config(null),
|
||||
],
|
||||
[
|
||||
'key' => 'by_shifts',
|
||||
'label' => 'По сменам',
|
||||
'description' => 'Показатели дежурных смен по датам',
|
||||
'category' => 'Дежурства',
|
||||
'dataset' => 'shifts',
|
||||
'thumbnail' => ['Дата смены', 'Поступило', 'Выписано', 'Умерло'],
|
||||
'config' => $this->config('shifts', ['shift_date'],
|
||||
['shifts_count', 'recipient_plan', 'recipient_emergency', 'discharged', 'deceased'],
|
||||
['metric' => 'recipient_plan', 'type' => 'bar']),
|
||||
],
|
||||
[
|
||||
'key' => 'by_patients',
|
||||
'label' => 'По пациентам',
|
||||
'description' => 'Структура пациентов по срочности и исходам',
|
||||
'category' => 'Пациенты',
|
||||
'dataset' => 'patients',
|
||||
'thumbnail' => ['Срочность', 'Исход', 'Пациентов'],
|
||||
'config' => $this->config('patients', ['urgency', 'outcome'],
|
||||
['patients_count', 'admitted', 'discharged', 'deceased'],
|
||||
['metric' => 'patients_count', 'type' => 'donut']),
|
||||
],
|
||||
[
|
||||
'key' => 'unwanted',
|
||||
'label' => 'Нежелательные события',
|
||||
'description' => 'Количество нежелательных событий по типам',
|
||||
'category' => 'События',
|
||||
'dataset' => 'unwanted_events',
|
||||
'thumbnail' => ['Событие', 'Количество'],
|
||||
'config' => $this->config('unwanted_events', ['event_title'],
|
||||
['events_count'],
|
||||
['metric' => 'events_count', 'type' => 'bar']),
|
||||
],
|
||||
[
|
||||
'key' => 'nurse',
|
||||
'label' => 'Журнал медсестры',
|
||||
'description' => 'Пациенты журнала по исходам',
|
||||
'category' => 'Журнал',
|
||||
'dataset' => 'nurse_journal',
|
||||
'thumbnail' => ['Исход', 'Пациентов', 'Умерло'],
|
||||
'config' => $this->config('nurse_journal', ['outcome'],
|
||||
['patients_count', 'admitted', 'discharged', 'deceased'],
|
||||
['metric' => 'patients_count', 'type' => 'bar']),
|
||||
],
|
||||
[
|
||||
'key' => 'department_statistics',
|
||||
'label' => 'Статистика по отделениям',
|
||||
'description' => 'Сводная статистика по всем отделениям (профили, ИТОГО)',
|
||||
'category' => 'Сводные',
|
||||
'dataset' => 'department_statistics',
|
||||
'thumbnail' => ['Отделение', 'Коек', 'Поступило', 'Состоит', 'Умерло'],
|
||||
'config' => $this->config('department_statistics'),
|
||||
],
|
||||
[
|
||||
'key' => 'nurse_shifts',
|
||||
'label' => 'Смены медсестры',
|
||||
'description' => 'Список своих смен с показателями по пациентам',
|
||||
'category' => 'Журнал',
|
||||
'dataset' => 'nurse_shifts',
|
||||
'thumbnail' => ['Дата смены', 'Поступило', 'Выписано', 'Умерло'],
|
||||
'config' => $this->config('nurse_shifts', ['shift_date'],
|
||||
['shifts_count', 'patients_count', 'admitted', 'discharged', 'deceased'],
|
||||
['metric' => 'admitted', 'type' => 'bar']),
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
public function find(string $key): ?array
|
||||
{
|
||||
foreach ($this->all() as $preset) {
|
||||
if ($preset['key'] === $key) {
|
||||
return $preset;
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array<int,string>
|
||||
*/
|
||||
public function categories(): array
|
||||
{
|
||||
return ['Все', ...collect($this->all())
|
||||
->pluck('category')
|
||||
->reject(fn ($c) => $c === 'Все')
|
||||
->unique()
|
||||
->values()
|
||||
->all()];
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array<int,string> $dimensions
|
||||
* @param array<int,string> $measures
|
||||
* @param array<string,string> $chart
|
||||
* @return array<string,mixed>
|
||||
*/
|
||||
private function config(?string $dataset, array $dimensions = [], array $measures = [], array $chart = []): array
|
||||
{
|
||||
return [
|
||||
'dataset' => $dataset,
|
||||
'dimensions' => $dimensions,
|
||||
'measures' => $measures,
|
||||
'filters' => [],
|
||||
'mode' => 'period',
|
||||
'detalization' => 'month',
|
||||
'chart' => [
|
||||
'metric' => $chart['metric'] ?? ($measures[0] ?? null),
|
||||
'type' => $chart['type'] ?? 'bar',
|
||||
],
|
||||
];
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user