94 lines
2.9 KiB
PHP
94 lines
2.9 KiB
PHP
<?php
|
|
|
|
namespace App\Services\Analytics\DataSets;
|
|
|
|
use App\Models\Department;
|
|
use App\Models\MisLpuDoctor;
|
|
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 PatientsDataSet extends AbstractDataSet
|
|
{
|
|
use PatientAggregates;
|
|
|
|
public function key(): string
|
|
{
|
|
return 'patients';
|
|
}
|
|
|
|
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_duty_patients as p')
|
|
->join('report_duties as rd', 'rd.id', '=', 'p.report_duty_id')
|
|
->where('rd.rf_department_id', $query->department->department_id)
|
|
->where('rd.status_id', 2)
|
|
->where('rd.period_start', '>=', $query->dateRange->startSql())
|
|
->where('rd.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(
|
|
'doctor',
|
|
'Врач',
|
|
'string',
|
|
'rd.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(),
|
|
),
|
|
new Dimension(
|
|
'department',
|
|
'Отделение',
|
|
'string',
|
|
'rd.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', 'rd');
|
|
}
|
|
|
|
public function filters(): array
|
|
{
|
|
return [
|
|
new FilterDef('doctor', 'Врач', 'rd.rf_lpudoctor_id', 'select', null, 'doctors'),
|
|
new FilterDef('urgency', 'Срочность', 'p.urgency_id', 'select', [1 => 'Планово', 2 => 'Экстренно']),
|
|
];
|
|
}
|
|
}
|