Добавил базовые датасеты и агрегации для конструктора отчетов
This commit is contained in:
83
app/Services/Analytics/DataSets/NurseJournalDataSet.php
Normal file
83
app/Services/Analytics/DataSets/NurseJournalDataSet.php
Normal file
@@ -0,0 +1,83 @@
|
||||
<?php
|
||||
|
||||
namespace App\Services\Analytics\DataSets;
|
||||
|
||||
use App\Models\Department;
|
||||
use App\Services\Analytics\AbstractDataSet;
|
||||
use App\Services\Analytics\AnalyticsQuery;
|
||||
use App\Services\Analytics\DataSets\Concerns\PatientAggregates;
|
||||
use App\Services\Analytics\Dimension;
|
||||
use App\Services\Analytics\FilterDef;
|
||||
use Illuminate\Database\Query\Builder;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
|
||||
class NurseJournalDataSet extends AbstractDataSet
|
||||
{
|
||||
use PatientAggregates;
|
||||
|
||||
public function key(): string
|
||||
{
|
||||
return 'nurse_journal';
|
||||
}
|
||||
|
||||
public function label(): string
|
||||
{
|
||||
return 'Журнал медсестры';
|
||||
}
|
||||
|
||||
public function description(): string
|
||||
{
|
||||
return 'Пациенты из сданных журналов старшей медсестры';
|
||||
}
|
||||
|
||||
public function category(): string
|
||||
{
|
||||
return 'Журнал';
|
||||
}
|
||||
|
||||
protected function dateField(): string
|
||||
{
|
||||
return 'p.recipient_date';
|
||||
}
|
||||
|
||||
protected function baseQuery(AnalyticsQuery $query): Builder
|
||||
{
|
||||
return DB::table('report_nurse_patients as p')
|
||||
->join('report_nurses as rn', 'rn.id', '=', 'p.report_nurse_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 [
|
||||
$this->urgencyDimension('p'),
|
||||
$this->outcomeDimension('p'),
|
||||
new Dimension('recipient_date', 'Дата поступления', 'date', 'CAST(p.recipient_date AS date)'),
|
||||
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 $this->patientMeasures('p', 'rn');
|
||||
}
|
||||
|
||||
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 => 'Экстренно']),
|
||||
];
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user