64 lines
1.9 KiB
PHP
64 lines
1.9 KiB
PHP
<?php
|
|
|
|
namespace App\Models;
|
|
use App\Enums\RecordStatusEnum;
|
|
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
|
use Illuminate\Support\Facades\Session;
|
|
|
|
class TestSample extends BaseModel
|
|
{
|
|
public $timestamps = false;
|
|
use HasFactory;
|
|
/**
|
|
* The table associated with the model.
|
|
*
|
|
* @var string
|
|
*/
|
|
|
|
protected $table='test_samples';
|
|
|
|
public static function boot()
|
|
{
|
|
parent::boot();
|
|
}
|
|
|
|
protected $fillable = ['sample_type_id', 'test_id','heading_id', 'group_result','category', 'code',
|
|
'unit_sign','usd_price', 'weight', 'lab_id','field_type', 'formula', 'format',
|
|
'description','is_bold','autocomplete_bind', BaseModel::CREATED_AT_FIELD, BaseModel::CREATED_BY_FIELD];
|
|
|
|
public function test(){
|
|
return $this->belongsTo(Test::class, 'test_id','id');
|
|
}
|
|
|
|
public function sample(){
|
|
return $this->belongsTo(SampleType::class, 'sample_type_id','id');
|
|
}
|
|
|
|
public function lab(){
|
|
return $this->belongsTo(Laboratory::class, 'lab_id','id');
|
|
}
|
|
|
|
public function organisms(){
|
|
return $this->hasMany(TestSampleOrganism::class, 'test_sample_id', 'id')->where(BaseModel::RECORD_STATUS_FIELD, RecordStatusEnum::ACTIVE);
|
|
}
|
|
|
|
public function tests(){
|
|
return $this->hasMany(self::class, 'heading_id','id')->where([
|
|
BaseModel::RECORD_STATUS_FIELD => RecordStatusEnum::ACTIVE,
|
|
'lab_id' => Session::get('base_lab_id')
|
|
]);
|
|
}
|
|
|
|
public function childTest(){
|
|
return $this->hasMany(self::class, 'heading_id','id')->where([
|
|
BaseModel::RECORD_STATUS_FIELD => RecordStatusEnum::ACTIVE,
|
|
'lab_id' => Session::get('base_lab_id')
|
|
]);
|
|
}
|
|
|
|
public function testValues(){
|
|
return $this->hasMany(TestNormalValue::class, 'test_sample_id', 'id')->where(BaseModel::RECORD_STATUS_FIELD, RecordStatusEnum::ACTIVE);
|
|
}
|
|
|
|
}
|