Добавил реанимацию
Правки окна операций
This commit is contained in:
@@ -84,6 +84,9 @@ class DutyReportController extends Controller
|
||||
$transferredHistories = MedicalHistoryResource::collection(
|
||||
$this->medicalHistoryService->getTransferredHistories($dateRange, $department->rf_mis_department_id)
|
||||
);
|
||||
$reanimationHistories = MedicalHistoryResource::collection(
|
||||
$this->medicalHistoryService->getReanimationHistories($dateRange, $department->rf_mis_department_id)
|
||||
);
|
||||
}
|
||||
|
||||
return Inertia::render('Report/Index', [
|
||||
@@ -94,6 +97,7 @@ class DutyReportController extends Controller
|
||||
'dischargedHistories' => $dischargedHistories,
|
||||
'deceasedHistories' => $deceasedHistories,
|
||||
'transferredHistories' => $transferredHistories,
|
||||
'reanimationHistories' => $reanimationHistories,
|
||||
'dates' => [
|
||||
$dateRange->startDate->getTimestampMs(),
|
||||
$dateRange->endDate->getTimestampMs(),
|
||||
|
||||
@@ -36,6 +36,11 @@ class MedicalHistory extends MaterializedViewModel
|
||||
->latest('ingoing_date');
|
||||
}
|
||||
|
||||
public function reanimations()
|
||||
{
|
||||
return $this->hasMany(Reanimation::class, 'medical_history_id', 'id');
|
||||
}
|
||||
|
||||
public function operationsInDepartment($query, $departmentId)
|
||||
{
|
||||
return $this->operations()->where('department_id', $departmentId);
|
||||
|
||||
@@ -31,6 +31,12 @@ class MigrationPatient extends MaterializedViewModel
|
||||
->orderBy('end_date', 'desc');
|
||||
}
|
||||
|
||||
public function reanimations()
|
||||
{
|
||||
return $this->hasMany(Reanimation::class, 'migration_patient_id', 'id')
|
||||
->orderBy('out_date', 'desc');
|
||||
}
|
||||
|
||||
// Пересечение с отчетным периодом
|
||||
public function scopeDateRange($query, string $from, string $to)
|
||||
{
|
||||
|
||||
56
app/Models/Reanimation.php
Normal file
56
app/Models/Reanimation.php
Normal 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());
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -76,6 +76,7 @@ class MedicalHistoryService
|
||||
->sortByDesc(fn ($mh) => $mh->latestMigration->ingoing_date ?? $mh->recipient_date)
|
||||
->values();
|
||||
}
|
||||
|
||||
public function getEmergencyHistories(DateRange $dateRange, int $departmentId)
|
||||
{
|
||||
return MedicalHistory::query()
|
||||
@@ -146,4 +147,27 @@ class MedicalHistoryService
|
||||
}, 'latestMigration.operations'])
|
||||
->get();
|
||||
}
|
||||
|
||||
public function getReanimationHistories(DateRange $dateRange, int $departmentId)
|
||||
{
|
||||
return MedicalHistory::query()
|
||||
->whereHas('migrations', function ($q) use ($departmentId, $dateRange) {
|
||||
$q->department($departmentId)->currentOrAdmitted($dateRange);
|
||||
})
|
||||
->whereHas('latestMigration.reanimations', function ($q) use ($dateRange) {
|
||||
$q->currentOrAdmitted($dateRange);
|
||||
})
|
||||
->with(
|
||||
[
|
||||
'latestMigration' => function ($q) use ($departmentId, $dateRange) {
|
||||
$q->department($departmentId)->currentOrAdmitted($dateRange)->latest('ingoing_date'); // подгружаем только отфильтрованные движения
|
||||
},
|
||||
'latestMigration.operations',
|
||||
'latestMigration.reanimations'
|
||||
])
|
||||
->get()
|
||||
// Сортировка по дате поступления в отделение (поле дочерней таблицы)
|
||||
->sortByDesc(fn ($mh) => $mh->latestMigration->ingoing_date ?? $mh->recipient_date)
|
||||
->values();
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user