* добавил автоматическое создание движения при редактировании * добавил функционал для сохранения отчета и пациентов * изменил форматирование дат * добавил частичную перезагрузку при сохранении изменений
47 lines
1.4 KiB
PHP
47 lines
1.4 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:Y-m-d',
|
|
'recipient_date' => 'datetime:Y-m-d H:i:s',
|
|
'extract_date' => 'datetime:Y-m-d H:i:s',
|
|
'death_date' => 'datetime:Y-m-d H:i:s',
|
|
'male' => 'boolean',
|
|
];
|
|
|
|
public function migrations(): \Illuminate\Database\Eloquent\Relations\HasMany|MedicalHistory
|
|
{
|
|
return $this->hasMany(UnifiedMigrationPatient::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(UnifiedMigrationPatient::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);
|
|
}
|
|
}
|