Много всего

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

@@ -6,6 +6,8 @@ use Illuminate\Database\Eloquent\Model;
class ArchiveHistory extends Model
{
protected $connection = 'pgsql';
protected static function booted()
{
static::created(function ($archiveHistory) {

View File

@@ -6,6 +6,8 @@ use Illuminate\Database\Eloquent\Model;
class ArchiveInfo extends Model
{
protected $connection = 'pgsql';
protected $table = 'archive_infos';
protected $fillable = [
'historyable_type',
'historyable_id',

View File

@@ -0,0 +1,58 @@
<?php
namespace App\Models\Mis;
use App\Models\ArchiveHistory;
use App\Models\ArchiveInfo;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Support\Facades\DB;
class SttMedicalHistory extends Model
{
protected $primaryKey = 'MedicalHistoryID';
protected $table = 'stt_medicalhistory';
protected $connection = 'mis';
public function getFullNameAttribute()
{
return "$this->FAMILY $this->Name $this->OT";
}
public function archiveHistory()
{
return $this->morphMany(ArchiveHistory::class, 'historyable');
}
public function archiveInfo()
{
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();
}
}

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) {