Files
onboard/app/Models/MisSurgicalOperation.php
2026-04-24 16:46:10 +09:00

75 lines
2.1 KiB
PHP
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<?php
namespace App\Models;
use Illuminate\Database\Eloquent\Model;
use LaravelIdea\Helper\App\Models\_IH_MisSurgicalOperation_QB;
class MisSurgicalOperation extends Model
{
private const COMPLETED_OPERATION_STATUS_ID = 3;
private const CANCELLED_OPERATION_STATUS_ID = 4;
protected $table = 'stt_surgicaloperation';
protected $primaryKey = 'SurgicalOperationID';
public function serviceMedical()
{
return $this->belongsTo(MisServiceMedical::class, 'rf_kl_ServiceMedicalID', 'ServiceMedicalID');
}
public function medicalHistory()
{
return $this->belongsTo(MisMedicalHistory::class, 'rf_MedicalHistoryID', 'MedicalHistoryID');
}
public function operationPurpose()
{
return $this->hasOne(MisOperationPurpose::class, 'rf_SurgicalOperationID', 'SurgicalOperationID');
}
/**
* Получить операции у которых исход <> 0
*
* @return _IH_MisSurgicalOperation_QB|_IH_MisSurgicalOperation_QB
*/
public function scopeCompleted($query)
{
return $query->whereNot('rf_OperationResultID', 0);
}
/**
* Получить операции с благоприятным исходом
*
* @return _IH_MisSurgicalOperation_QB|_IH_MisSurgicalOperation_QB
*/
public function scopePositiveResult($query)
{
return $query->where('rf_OperationResultID', 1);
}
/**
* Получить операции с неблагоприятным исходом
*
* @return _IH_MisSurgicalOperation_QB|_IH_MisSurgicalOperation_QB
*/
public function scopeNotPositiveResult($query)
{
return $query->where('rf_OperationResultID', 2);
}
/**
* Получить отмененные операции через назначение
*
* @return _IH_MisSurgicalOperation_QB
*/
public function scopeCanceled($query)
{
return $query->whereHas('operationPurpose', function ($purposeQuery) {
$purposeQuery->where('rf_OperationStatusID', self::CANCELLED_OPERATION_STATUS_ID);
});
}
}