87 lines
2.0 KiB
PHP
87 lines
2.0 KiB
PHP
<?php
|
|
|
|
namespace App\Models\Cadastro;
|
|
|
|
use App\Models\Cadastro\SujeitoAtencao\Lotacao;
|
|
use App\Models\Model;
|
|
use App\Models\Sigtap\Procedimento;
|
|
|
|
class Oci extends Model
|
|
{
|
|
protected $table = 'cadastro_oci';
|
|
|
|
protected $casts = [
|
|
'ativo' => 'boolean',
|
|
'inativado_em' => 'datetime:d/m/Y H:i:s'
|
|
];
|
|
|
|
protected $fillable = [
|
|
'codigo',
|
|
'nome',
|
|
'procedimento_codigo',
|
|
'linha_cuidado',
|
|
'descricao_geral',
|
|
'objetivo_assistencial',
|
|
'ativo',
|
|
'motivo_inativacao',
|
|
'inativado_em',
|
|
'inativacao_lotacao_id',
|
|
];
|
|
|
|
protected $hidden = [
|
|
'created_at',
|
|
'created_lotacao_id',
|
|
'created_centro_custo_id',
|
|
'updated_at',
|
|
'updated_lotacao_id',
|
|
'updated_centro_custo_id',
|
|
];
|
|
|
|
public function etapasClinicas()
|
|
{
|
|
return $this->belongsToMany(
|
|
EtapaClinica::class,
|
|
'cadastro_oci_etapa_clinica',
|
|
'oci_id',
|
|
'etapa_clinica_id'
|
|
)
|
|
->using(OciEtapaClinica::class)
|
|
->as('ociEtapaClinica')
|
|
->withTimestamps();
|
|
}
|
|
|
|
public function inativacaoLotacao()
|
|
{
|
|
return $this->belongsTo(Lotacao::class);
|
|
}
|
|
|
|
public function portarias()
|
|
{
|
|
return $this->hasMany(OciPortaria::class);
|
|
}
|
|
|
|
public function procedimentosPrimarios()
|
|
{
|
|
return $this->hasMany(OciProcedimentoPrimario::class);
|
|
}
|
|
|
|
public function procedimentosSecundarios()
|
|
{
|
|
return $this->hasMany(OciProcedimentoSecundario::class);
|
|
}
|
|
|
|
public function unidadesExecutoras()
|
|
{
|
|
return $this->hasMany(OciUnidadeExecutora::class);
|
|
}
|
|
|
|
public function getProcedimentoAttribute()
|
|
{
|
|
return is_null($this->procedimento_codigo)
|
|
? null
|
|
: Procedimento::where('codigo', $this->procedimento_codigo)
|
|
->orderByDesc('competencia_id')
|
|
->first();
|
|
}
|
|
}
|