Files
onboard/app/Models/UnifiedMedicalHistory.php
brusnitsyn 82673f385b Добавлено сохранение правок поверх МИС
Добавлено версионирование сохраненных правок
Добавлено сохранение отчета мед. сестры
2026-05-04 22:23:21 +09:00

47 lines
1.3 KiB
PHP

<?php
namespace App\Models;
use Illuminate\Database\Eloquent\Model;
class UnifiedMedicalHistory extends MaterializedViewModel
{
protected $table = 'v_unified_medical_history_nurse';
protected $primaryKey = 'id';
protected $casts = [
'birth_date' => 'date',
'recipient_date' => 'datetime',
'extract_date' => 'datetime',
'death_date' => 'datetime',
'male' => 'boolean',
];
public function migrations(): \Illuminate\Database\Eloquent\Relations\HasMany|MedicalHistory
{
return $this->hasMany(MigrationPatient::class, 'medical_history_id', 'id');
}
public function operations(): \Illuminate\Database\Eloquent\Relations\HasMany|MedicalHistory
{
return $this->hasMany(SurgicalOperation::class, 'medical_history_id', 'id');
}
public function latestMigration()
{
return $this->hasOne(MigrationPatient::class, 'medical_history_id', 'id')
->latest('ingoing_date');
}
public function operationsInDepartment($query, $departmentId)
{
return $this->operations()->where('department_id', $departmentId);
}
// Скоупы
public function scopeUrgency($query, $typeId) // 1 = Экстренно, 2 = Планово
{
return $query->where('urgency_id', $typeId);
}
}