This commit is contained in:
114
api/app/Models/ProntoAtendimento/Atendimento/Faa.php
Normal file
114
api/app/Models/ProntoAtendimento/Atendimento/Faa.php
Normal file
@@ -0,0 +1,114 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models\ProntoAtendimento\Atendimento;
|
||||
|
||||
use App\Models\Cadastro\SujeitoAtencao\Lotacao;
|
||||
use App\Models\Cadastro\SujeitoAtencao\Paciente;
|
||||
use App\Models\Cadastro\SujeitoAtencao\Usuario;
|
||||
use App\Models\Model;
|
||||
use Illuminate\Database\Eloquent\SoftDeletes;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
|
||||
class Faa extends Model
|
||||
{
|
||||
use SoftDeletes;
|
||||
|
||||
protected $table = 'pronto_atendimento_faa';
|
||||
|
||||
protected $casts = [
|
||||
'finalizado' => 'boolean',
|
||||
];
|
||||
|
||||
protected $fillable = [
|
||||
'id',
|
||||
'numero',
|
||||
'paciente_id',
|
||||
'desfecho_id',
|
||||
'finalizado',
|
||||
'usuario_id',
|
||||
'lotacao_id',
|
||||
'data_hora_desfecho',
|
||||
'motivo_cancelamento_evasao',
|
||||
'motivo_cancelamento',
|
||||
'cancelado',
|
||||
'canceled_desfecho_lotacao_id'
|
||||
];
|
||||
|
||||
protected $hidden = [
|
||||
'created_at',
|
||||
'created_lotacao_id',
|
||||
'created_centro_custo_id',
|
||||
'updated_at',
|
||||
'updated_lotacao_id',
|
||||
'updated_centro_custo_id',
|
||||
'deleted_at',
|
||||
'deleted_lotacao_id',
|
||||
'deleted_centro_custo_id',
|
||||
];
|
||||
|
||||
protected static function boot()
|
||||
{
|
||||
parent::boot();
|
||||
|
||||
static::creating(function ($model) {
|
||||
$model->numero = DB::table('pronto_atendimento_faa')->max('numero') + 1;
|
||||
});
|
||||
|
||||
static::updating(function ($model) {
|
||||
if (!is_null($model->desfecho_id)) {
|
||||
$model->motivo_cancelamento_evasao = null;
|
||||
$model->finalizado = true;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public function paciente()
|
||||
{
|
||||
return $this->belongsTo(Paciente::class);
|
||||
}
|
||||
|
||||
public function desfecho()
|
||||
{
|
||||
return $this->belongsTo(Desfecho::class);
|
||||
}
|
||||
|
||||
public function usuario()
|
||||
{
|
||||
return $this->belongsTo(Usuario::class);
|
||||
}
|
||||
|
||||
public function lotacao()
|
||||
{
|
||||
return $this->belongsTo(Lotacao::class);
|
||||
}
|
||||
|
||||
public function raat()
|
||||
{
|
||||
return $this->hasOne(Raat::class);
|
||||
}
|
||||
|
||||
public function cat()
|
||||
{
|
||||
return $this->hasOne(Cat::class);
|
||||
}
|
||||
|
||||
public function atendimentos()
|
||||
{
|
||||
return $this->hasMany(Atendimento::class)->withTrashed();
|
||||
}
|
||||
|
||||
public function getIsRaatAbertaAttribute()
|
||||
{
|
||||
return !is_null($this->raat);
|
||||
}
|
||||
|
||||
public function getIsCatAbertaAttribute()
|
||||
{
|
||||
return !is_null($this->cat);
|
||||
}
|
||||
|
||||
public function getIsAllowedToDeleteAttribute()
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user