Files
kartoteka/app/Models/SI/SttMedicalHistory.php
2025-12-01 17:38:11 +09:00

50 lines
1.3 KiB
PHP

<?php
namespace App\Models\SI;
use App\Models\ArchiveHistory;
use Illuminate\Database\Eloquent\Model;
class SttMedicalHistory extends Model
{
protected $table = 'si_stt_patients';
protected $fillable = [
'fam', // Фамилия
'im', // Имя
'ot', // Отчество
'mpostdate', // Д. пост.
'menddate', // Д. вып.
'narhiv', // № в архиве
'datearhiv', // Д. архив
'statgod', // Год нахождения в стационаре
'enp', // ЕНП
'nkarta', // № карты
'dr', // ДР
];
public function getFullNameAttribute()
{
return "$this->fam $this->im $this->ot";
}
public function getArchiveHistory()
{
return $this->morphMany(ArchiveHistory::class, 'historyable');
}
public function scopeSearch($query, $searchText)
{
return $query->where(function($q) use ($searchText) {
if (is_numeric($searchText)) {
$q->where('nkarta', 'LIKE', "$searchText%");
} else {
// Ищем по всем частям ФИО
$q->where('fam', 'LIKE', "%$searchText%")
->orWhere('im', 'LIKE', "%$searchText%")
->orWhere('ot', 'LIKE', "%$searchText%");
}
});
}
}