leftJoin('report_nurse_patients as p', 'p.report_nurse_id', '=', 'rn.id') ->where('rn.rf_department_id', $query->department->department_id) ->where('rn.status_id', 2) ->where('rn.period_start', '>=', $query->dateRange->startSql()) ->where('rn.period_end', '<=', $query->dateRange->endSql()); } public function dimensions(): array { return [ new Dimension('shift_date', 'Дата смены', 'date', 'CAST(rn.period_start AS date)'), new Dimension( 'nurse', 'Медсестра', 'string', 'rn.rf_lpudoctor_id', labels: fn (array $ids) => MisLpuDoctor::whereIn('LPUDoctorID', $ids)->get() ->mapWithKeys(fn ($d) => [$d->LPUDoctorID => trim("{$d->FAM_V} {$d->IM_V} {$d->OT_V}") ?: "Сотрудник #{$d->LPUDoctorID}"]) ->all(), ), $this->urgencyDimension('p'), $this->outcomeDimension('p'), new Dimension( 'department', 'Отделение', 'string', 'rn.rf_department_id', labels: fn (array $ids) => Department::whereIn('department_id', $ids)->get() ->mapWithKeys(fn ($d) => [$d->department_id => $d->name_full ?? $d->name_short]) ->all(), ), ]; } public function measures(): array { return [ new Measure('shifts_count', 'Количество смен', 'count', 'COUNT(DISTINCT rn.id)'), new Measure('patients_count', 'Пациентов', 'count', 'COUNT(p.id)'), $this->admittedMeasure('p', 'rn'), ...$this->outcomeMeasures('p'), ]; } public function filters(): array { return [ new FilterDef('nurse', 'Медсестра', 'rn.rf_lpudoctor_id', 'select', null, 'nurse_doctors'), new FilterDef('urgency', 'Срочность', 'p.urgency_id', 'select', [1 => 'Планово', 2 => 'Экстренно']), ]; } }