*/ 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 */ 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> */ 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)); } }