Много всего

This commit is contained in:
brusnitsyn
2025-12-12 17:10:05 +09:00
parent 54f36e91fa
commit 98e9f8b52e
25 changed files with 1118 additions and 145 deletions

View File

@@ -9,6 +9,7 @@ use Illuminate\Database\Eloquent\Model;
class SttMedicalHistory extends Model
{
protected $table = 'si_stt_patients';
protected $connection = 'pgsql';
protected $fillable = [
'family', // Фамилия
@@ -39,6 +40,34 @@ class SttMedicalHistory extends Model
return $this->morphOne(ArchiveInfo::class, 'historyable');
}
/**
* Проверяет, можно ли выдать эту карту
*/
public function canBeIssued(): bool
{
// Проверяем, есть ли открытые выдачи
$hasOpenIssue = $this->archiveHistory()
->whereNotNull('issue_at')
->whereNull('return_at')
->where('has_lost', false)
->exists();
return !$hasOpenIssue;
}
/**
* Получает текущую открытую выдачу (если есть)
*/
public function getCurrentIssue(): ?ArchiveHistory
{
return $this->archiveHistory()
->whereNotNull('issue_at')
->whereNull('return_at')
->where('has_lost', false)
->latest('issue_at')
->first();
}
public function scopeSearch($query, $searchText)
{
return $query->where(function($q) use ($searchText) {