97 lines
2.3 KiB
PHP
97 lines
2.3 KiB
PHP
<?php
|
|
|
|
namespace App\Models\Sigtap;
|
|
|
|
use App\Models\Parametrizacao\Procedimento as ParametrizacaoProcedimento;
|
|
use Illuminate\Database\Eloquent\Model;
|
|
|
|
class Procedimento extends Model
|
|
{
|
|
protected $connection = 'sigtap';
|
|
|
|
protected $table = 'procedimento';
|
|
|
|
protected $fillable = [
|
|
'competencia_id',
|
|
'financiamento_id',
|
|
'rubrica_id',
|
|
'codigo',
|
|
'nome',
|
|
'complexidade',
|
|
'sexo',
|
|
'quantidade_maxima_execucao',
|
|
'quantidade_dias_permanencia',
|
|
'quantidade_pontos',
|
|
'idade_minima',
|
|
'idade_maxima',
|
|
'valor_servico_hospitalar',
|
|
'valor_servico_ambilatorial',
|
|
'valor_servico_profissional',
|
|
'quantidade_tempo_permanencia',
|
|
];
|
|
|
|
protected $hidden = [
|
|
'created_at',
|
|
'updated_at',
|
|
];
|
|
|
|
protected $appends = [
|
|
'has_cid_principal',
|
|
'has_cid_secundario',
|
|
];
|
|
|
|
public function competencia()
|
|
{
|
|
return $this->belongsTo(Competencia::class);
|
|
}
|
|
|
|
public function ocupacoes()
|
|
{
|
|
return $this->belongsToMany(Ocupacao::class, 'procedimento_ocupacao');
|
|
}
|
|
|
|
public function registros()
|
|
{
|
|
return $this->belongsToMany(Registro::class, 'procedimento_registro');
|
|
}
|
|
|
|
public function detalhes()
|
|
{
|
|
return $this->belongsToMany(Detalhe::class, 'procedimento_detalhe');
|
|
}
|
|
|
|
public function cids()
|
|
{
|
|
return $this->belongsToMany(Cid::class, 'procedimento_cid')
|
|
->as('procedimentoCid')
|
|
->withPivot('principal', 'competencia_id')
|
|
->withTimestamps();
|
|
}
|
|
|
|
public function cidsPrincipais()
|
|
{
|
|
return $this->cids()->where('principal', 'S');
|
|
}
|
|
|
|
public function cidsSecundarios()
|
|
{
|
|
return $this->cids()->where('principal', 'N');
|
|
}
|
|
|
|
public function parametrizacaoProcedimento()
|
|
{
|
|
return $this->setConnection(app('config')->get('database.default'))
|
|
->hasOne(ParametrizacaoProcedimento::class, 'procedimento_codigo', 'codigo');
|
|
}
|
|
|
|
public function getHasCidPrincipalAttribute()
|
|
{
|
|
return $this->cidsPrincipais()->get()->isNotEmpty();
|
|
}
|
|
|
|
public function getHasCidSecundarioAttribute()
|
|
{
|
|
return $this->cidsSecundarios()->get()->isNotEmpty();
|
|
}
|
|
}
|