Добавил базовые датасеты и агрегации для конструктора отчетов
This commit is contained in:
85
app/Services/Analytics/DataSetRegistry.php
Normal file
85
app/Services/Analytics/DataSetRegistry.php
Normal file
@@ -0,0 +1,85 @@
|
||||
<?php
|
||||
|
||||
namespace App\Services\Analytics;
|
||||
|
||||
use App\Services\Analytics\Contracts\DataSet;
|
||||
use App\Services\Analytics\DataSets\DepartmentStatisticsDataSet;
|
||||
use App\Services\Analytics\DataSets\NurseJournalDataSet;
|
||||
use App\Services\Analytics\DataSets\NurseShiftsDataSet;
|
||||
use App\Services\Analytics\DataSets\PatientsDataSet;
|
||||
use App\Services\Analytics\DataSets\ShiftsDataSet;
|
||||
use App\Services\Analytics\DataSets\UnwantedEventsDataSet;
|
||||
use InvalidArgumentException;
|
||||
|
||||
/**
|
||||
* Каталог источников данных конструктора отчётов.
|
||||
*/
|
||||
class DataSetRegistry
|
||||
{
|
||||
/** @var array<string,DataSet> */
|
||||
private array $datasets;
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
$this->datasets = [];
|
||||
foreach ([new ShiftsDataSet, new PatientsDataSet, new UnwantedEventsDataSet, new NurseJournalDataSet, new NurseShiftsDataSet, new DepartmentStatisticsDataSet] as $dataset) {
|
||||
$this->datasets[$dataset->key()] = $dataset;
|
||||
}
|
||||
}
|
||||
|
||||
/** @return array<string,DataSet> */
|
||||
public function all(): array
|
||||
{
|
||||
return $this->datasets;
|
||||
}
|
||||
|
||||
public function has(string $key): bool
|
||||
{
|
||||
return isset($this->datasets[$key]);
|
||||
}
|
||||
|
||||
public function get(string $key): DataSet
|
||||
{
|
||||
if (! isset($this->datasets[$key])) {
|
||||
throw new InvalidArgumentException("Неизвестный источник данных: {$key}");
|
||||
}
|
||||
|
||||
return $this->datasets[$key];
|
||||
}
|
||||
|
||||
/**
|
||||
* Метаданные всех датасетов для фронта (источники, измерения, показатели, фильтры).
|
||||
*
|
||||
* @return array<int,array<string,mixed>>
|
||||
*/
|
||||
public function metadata(): array
|
||||
{
|
||||
return array_values(array_map(fn (DataSet $d) => [
|
||||
'key' => $d->key(),
|
||||
'label' => $d->label(),
|
||||
'description' => $d->description(),
|
||||
'category' => $d->category(),
|
||||
'fixed' => $d->fixed(),
|
||||
'dimensions' => array_map(fn (Dimension $dim) => [
|
||||
'key' => $dim->key,
|
||||
'label' => $dim->label,
|
||||
'type' => $dim->type,
|
||||
], $d->dimensions()),
|
||||
'measures' => array_map(fn (Measure $m) => [
|
||||
'key' => $m->key,
|
||||
'label' => $m->label,
|
||||
'unit' => $m->unit,
|
||||
], $d->measures()),
|
||||
'filters' => array_map(fn (FilterDef $f) => [
|
||||
'key' => $f->key,
|
||||
'label' => $f->label,
|
||||
'type' => $f->type,
|
||||
'optionsSource' => $f->optionsSource,
|
||||
'options' => $f->options === null ? null : collect($f->options)
|
||||
->map(fn ($label, $value) => ['label' => $label, 'value' => $value])
|
||||
->values()
|
||||
->all(),
|
||||
], $d->filters()),
|
||||
], $this->datasets));
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user