Добавил реанимацию

Правки окна операций
This commit is contained in:
brusnitsyn
2026-05-07 22:37:07 +09:00
parent bb9e67ab3d
commit 6cf1ffbb2b
11 changed files with 137 additions and 45 deletions

View File

@@ -0,0 +1,56 @@
<?php
namespace App\Models;
use App\Services\DateRange;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Support\Facades\DB;
/**
* @property int $id
* @property int $migration_patient_id
* @property int $medical_history_id
* @property \Carbon\Carbon $in_date
* @property \Carbon\Carbon|null $out_date
* @property string|null $description
* @property int|null $stationar_branch_id
* @property int|null $department_id
* @property int|null $migration_stationar_branch_id
* @property int|null $migration_department_id
* @property int|null $doctor_id
*/
class Reanimation extends MaterializedViewModel
{
protected $table = 'mv_reanimation_summary';
protected $primaryKey = 'id';
public function medicalHistory()
{
return $this->belongsTo(MedicalHistory::class, 'medical_history_id', 'id');
}
public function migration()
{
return $this->belongsTo(MigrationPatient::class, 'migration_patient_id', 'id');
}
// Фильтр по подразделению
public function scopeDepartment($query, int $departmentId)
{
return $query->where('migration_department_id', $departmentId);
}
public function scopeCurrentOrAdmitted($query, DateRange $dateRange)
{
return $query->where(function ($q) use ($dateRange) {
// Вариант А: Пациент уже лежит (текущий)
$q->whereNull('out_date')
->whereNotNull('medical_history_id')
->where('in_date', '<', $dateRange->startSql());
})
->orWhere(function ($q) use ($dateRange) {
$q->where('in_date', '<=', $dateRange->endSql())
->where('in_date', '>', $dateRange->startSql());
});
}
}