230 lines
5.8 KiB
PHP
230 lines
5.8 KiB
PHP
<?php
|
|
|
|
namespace App\Models\Regulacao;
|
|
|
|
use App\Enums\Regulacao\Tipo;
|
|
use App\Models\Ambulatorio\AcompanhamentoOci;
|
|
use App\Models\Ambulatorio\AcompanhamentoOciEtapaClinicaConcluida;
|
|
use App\Models\Ambulatorio\Agendamento as AmbulatorioAgendamento;
|
|
use App\Models\Ambulatorio\AtendimentoSoap;
|
|
use App\Models\Cadastro\Estabelecimento\Infraestrutura;
|
|
use App\Models\Cadastro\SujeitoAtencao\Lotacao;
|
|
use App\Models\Cadastro\SujeitoAtencao\Paciente;
|
|
use App\Models\Cadastro\SujeitoAtencao\Usuario;
|
|
use App\Models\ExameImagem\Agendamento\Agendamento as ExameImagemAgendamento;
|
|
use App\Models\ExameLaboratorial\AgendamentoExame\Agendamento as ExameLaboratorialAgendamento;
|
|
use App\Models\Geral\Ciap;
|
|
use App\Models\Model;
|
|
use App\Models\Sigtap\Cid;
|
|
|
|
class Solicitacao extends Model
|
|
{
|
|
protected $table = 'regulacao_solicitacao';
|
|
|
|
protected $casts = [
|
|
'data' => 'datetime:d/m/Y',
|
|
'data_desejada' => 'datetime:d/m/Y',
|
|
'confirmado_em' => 'datetime:d/m/Y H:i:s',
|
|
'cancelado_em' => 'datetime:d/m/Y H:i:s',
|
|
'data_agendada' => 'datetime:d/m/Y',
|
|
'hora_agendada' => 'datetime:H:i',
|
|
];
|
|
|
|
protected $fillable = [
|
|
'id',
|
|
'numero',
|
|
'posicao_municipal',
|
|
'posicao_regulador',
|
|
'posicao_portal',
|
|
'data',
|
|
'paciente_id',
|
|
'status_id',
|
|
'infraestrutura_solicitante_id',
|
|
'usuario_solicitante_id',
|
|
'usuario_solicitante_especialidade_id',
|
|
'regulador_id',
|
|
'prestador_interno_id',
|
|
'prestador_externo_id',
|
|
'cid_id',
|
|
'ciap_id',
|
|
'hipotese_diagnostica_justificativa',
|
|
'prioridade_id',
|
|
'observacao',
|
|
'data_desejada',
|
|
'peso',
|
|
'altura',
|
|
'confirmado_em',
|
|
'confirmado_lotacao_id',
|
|
'cancelado_em',
|
|
'cancelado_lotacao_id',
|
|
'justificativa_cancelamento',
|
|
'justificativa_reagendamento',
|
|
'justificativa_remarcacao',
|
|
'justificativa_devolucao',
|
|
'justificativa_reenvio',
|
|
'justificativa_falta',
|
|
'opcao_retirada_protocolo_agendamento_id',
|
|
'nome_pessoa_retirada_protocolo_agendamento',
|
|
'data_agendada',
|
|
'hora_agendada',
|
|
'motivo_alteracao_prioridade',
|
|
'soap_id',
|
|
'unidade_usuario_id',
|
|
'infraestrutura_usuario_id',
|
|
'ocupacao_usuario_id',
|
|
'lotaca_usuario_id',
|
|
'acompanhamento_oci_id',
|
|
'ocupacao_executora_id',
|
|
'usuario_executor_nome',
|
|
];
|
|
|
|
protected $hidden = [
|
|
'created_at',
|
|
'created_lotacao_id',
|
|
'created_centro_custo_id',
|
|
'updated_at',
|
|
'updated_lotacao_id',
|
|
'updated_centro_custo_id',
|
|
];
|
|
|
|
protected $appends = [
|
|
'confirmado',
|
|
];
|
|
|
|
public function getConfirmadoAttribute()
|
|
{
|
|
return !is_null($this->confirmado_em);
|
|
}
|
|
|
|
public function getRegulacaoTipoIdAttribute()
|
|
{
|
|
$item = $this->itens->first();
|
|
|
|
if (!is_null($item->procedimentoCirurgico)) {
|
|
|
|
return Tipo::EXTERNO;
|
|
}
|
|
|
|
return isset($item->exame->regulacao_tipo_id)
|
|
? $item->exame->regulacao_tipo_id
|
|
: (isset($item->especialidade->regulacao_tipo_id)
|
|
? $item->especialidade->regulacao_tipo_id
|
|
: null);
|
|
}
|
|
|
|
public function paciente()
|
|
{
|
|
return $this->belongsTo(Paciente::class);
|
|
}
|
|
|
|
public function status()
|
|
{
|
|
return $this->belongsTo(Status::class);
|
|
}
|
|
|
|
public function infraestruturaSolicitante()
|
|
{
|
|
return $this->belongsTo(Infraestrutura::class);
|
|
}
|
|
|
|
public function usuarioSolicitante()
|
|
{
|
|
return $this->belongsTo(Usuario::class);
|
|
}
|
|
|
|
public function regulador()
|
|
{
|
|
return $this->belongsTo(ParametrizacaoRegulador::class);
|
|
}
|
|
|
|
public function prestadorInterno()
|
|
{
|
|
return $this->belongsTo(ParametrizacaoPrestadorInterno::class);
|
|
}
|
|
|
|
public function prestadorExterno()
|
|
{
|
|
return $this->belongsTo(ParametrizacaoPrestadorExterno::class);
|
|
}
|
|
|
|
public function cid()
|
|
{
|
|
return $this->belongsTo(Cid::class);
|
|
}
|
|
|
|
public function ciap()
|
|
{
|
|
return $this->belongsTo(Ciap::class);
|
|
}
|
|
|
|
public function prioridade()
|
|
{
|
|
return $this->belongsTo(SolicitacaoPrioridade::class);
|
|
}
|
|
|
|
public function confirmadoLotacao()
|
|
{
|
|
return $this->belongsTo(Lotacao::class);
|
|
}
|
|
|
|
public function canceladoLotacao()
|
|
{
|
|
return $this->belongsTo(Lotacao::class);
|
|
}
|
|
|
|
public function opcaoRetiradaProtocoloAgendamento()
|
|
{
|
|
return $this->belongsTo(ParametrizacaoOpcaoRetiradaProtocoloAgendamento::class);
|
|
}
|
|
|
|
public function soap()
|
|
{
|
|
return $this->belongsTo(AtendimentoSoap::class);
|
|
}
|
|
|
|
public function lotacaUsuario()
|
|
{
|
|
return $this->belongsTo(Lotacao::class);
|
|
}
|
|
|
|
public function acompanhamentoOci()
|
|
{
|
|
return $this->belongsTo(AcompanhamentoOci::class);
|
|
}
|
|
|
|
public function ambulatorioAgendamentos()
|
|
{
|
|
return $this->hasMany(AmbulatorioAgendamento::class, 'regulacao_solicitacao_id');
|
|
}
|
|
|
|
public function exameImagemAgendamento()
|
|
{
|
|
return $this->hasOne(ExameImagemAgendamento::class, 'regulacao_solicitacao_id');
|
|
}
|
|
|
|
public function exameLaboratorialAgendamento()
|
|
{
|
|
return $this->hasOne(ExameLaboratorialAgendamento::class, 'regulacao_solicitacao_id');
|
|
}
|
|
|
|
public function acompanhamentoOciEtapaClincaConcluida()
|
|
{
|
|
return $this->hasOne(AcompanhamentoOciEtapaClinicaConcluida::class, 'regulacao_solicitacao_id');
|
|
}
|
|
|
|
public function tentativasContato()
|
|
{
|
|
return $this->hasMany(SolicitacaoTentativaContato::class);
|
|
}
|
|
|
|
public function itens()
|
|
{
|
|
return $this->hasMany(SolicitacaoItem::class);
|
|
}
|
|
|
|
public function historico()
|
|
{
|
|
return $this->hasMany(SolicitacaoHistorico::class);
|
|
}
|
|
}
|