304 lines
8.8 KiB
PHP
304 lines
8.8 KiB
PHP
<?php
|
|
|
|
namespace App\Models\Parametrizacao\Exame;
|
|
|
|
use App\Models\Ambulatorio\AtendimentoSoapResultadoExame;
|
|
use App\Models\Ambulatorio\AtendimentoSoapSolicitacaoExameItem;
|
|
use App\Models\AtencaoBasica\AtendimentoIndividual\AtendimentoIndividualOutroExame;
|
|
use App\Models\Cadastro\Grupo\Grupo;
|
|
use App\Models\Cadastro\Grupo\GrupoTipo;
|
|
use App\Models\ExameImagem\Agendamento\AgendamentoExame as AgendamentoExameImagem;
|
|
use App\Models\ExameImagem\Agendamento\AgendamentoHistoricoExclusao;
|
|
use App\Models\ExameImagem\Fechamento\Faturamento;
|
|
use App\Models\ExameLaboratorial\AgendamentoExame\AgendamentoExame as AgendamentoExameLaboratorial;
|
|
use App\Models\ExameLaboratorial\AgendamentoExame\AgendamentoExameBloqueado;
|
|
use App\Models\ExameLaboratorial\Parametrizacao\CotaExame;
|
|
use App\Models\ExameLaboratorial\Parametrizacao\CotaExamePeriodo;
|
|
use App\Models\Model;
|
|
use App\Models\Parametrizacao\Exame\ExameComposicao;
|
|
use App\Models\Parametrizacao\Exame\ExameTextoPronto;
|
|
use App\Models\Parametrizacao\Exame\ExameTipo;
|
|
use App\Models\Parametrizacao\KitExame\Item as KitExameItem;
|
|
use App\Models\ProntoAtendimento\PedidoExame\Item as PedidoExameItem;
|
|
use App\Models\Regulacao\ParametrizacaoPrestadorExterno;
|
|
use App\Models\Regulacao\ParametrizacaoPrestadorExternoExame;
|
|
use App\Models\Regulacao\ParametrizacaoPrestadorInterno;
|
|
use App\Models\Regulacao\ParametrizacaoPrestadorInternoExame;
|
|
use App\Models\Regulacao\ParametrizacaoRegulador;
|
|
use App\Models\Regulacao\ParametrizacaoReguladorExame;
|
|
use App\Models\Regulacao\ParametrizacaoSolicitanteRegulador;
|
|
use App\Models\Regulacao\ParametrizacaoSolicitanteReguladorExame;
|
|
use App\Models\Regulacao\Tipo as RegulacaoTipo;
|
|
use App\Models\Sigtap\Procedimento;
|
|
use App\Models\WebService\Laboratorio\Cliente\Exame as WebServiceLaboratorioClienteExame;
|
|
use Illuminate\Database\Eloquent\SoftDeletes;
|
|
|
|
class Exame extends Model
|
|
{
|
|
use SoftDeletes;
|
|
|
|
protected $table = 'parametrizacao_exame';
|
|
|
|
protected $casts = [
|
|
'ativo' => 'boolean',
|
|
'outro_municipio' => 'boolean',
|
|
'provisorio' => 'boolean',
|
|
'sigilo' => 'boolean',
|
|
'senha_supervisor' => 'boolean',
|
|
'mapa_agrupado' => 'boolean',
|
|
'valor_sigtap' => 'boolean',
|
|
'exige_procedimento' => 'boolean',
|
|
'is_ppi' => 'boolean',
|
|
'permite_repeticao' => 'boolean',
|
|
'exigir_peso_altura_circunferencia' => 'boolean',
|
|
];
|
|
|
|
protected $fillable = [
|
|
'tipo_id',
|
|
'grupo_tipo_id',
|
|
'codigo',
|
|
'nome',
|
|
'ativo',
|
|
'observacao',
|
|
'sigla_exame',
|
|
'prazo_entrega',
|
|
'validade',
|
|
'valor',
|
|
'quantidade_maxima',
|
|
'outro_municipio',
|
|
'provisorio',
|
|
'sigilo',
|
|
'senha_supervisor',
|
|
'ultimo_resultado',
|
|
'resultado',
|
|
'mapa_agrupado',
|
|
'posicao_mapa',
|
|
'valor_sigtap',
|
|
'exige_procedimento',
|
|
'sexo_id',
|
|
'quantidade_reagente',
|
|
'regulacao_tipo_id',
|
|
'is_ppi',
|
|
'valor_ppi',
|
|
'permite_repeticao',
|
|
'exigir_peso_altura_circunferencia',
|
|
'tempo_medio_previsto_atendimento_dias',
|
|
];
|
|
|
|
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 $with = [
|
|
'tipo',
|
|
];
|
|
|
|
protected $appends = [
|
|
'procedimento',
|
|
'is_regulado',
|
|
];
|
|
|
|
public function tipo()
|
|
{
|
|
return $this->belongsTo(ExameTipo::class);
|
|
}
|
|
|
|
public function grupo()
|
|
{
|
|
return $this->belongsTo(Grupo::class, 'grupo_tipo_id');
|
|
}
|
|
|
|
public function grupoTipo()
|
|
{
|
|
return $this->belongsTo(GrupoTipo::class);
|
|
}
|
|
|
|
public function regulacaoTipo()
|
|
{
|
|
return $this->belongsTo(RegulacaoTipo::class);
|
|
}
|
|
|
|
public function exameLaboratorialCotasAnual()
|
|
{
|
|
return $this->hasMany(CotaExamePeriodo::class);
|
|
}
|
|
|
|
public function exameComposicao()
|
|
{
|
|
return $this->hasMany(ExameComposicao::class);
|
|
}
|
|
|
|
public function exameImagemFechamentoFaturamento()
|
|
{
|
|
return $this->hasMany(Faturamento::class);
|
|
}
|
|
|
|
public function atendimentoSoapResultadoExame()
|
|
{
|
|
return $this->hasMany(AtendimentoSoapResultadoExame::class);
|
|
}
|
|
|
|
public function pedidoExameItem()
|
|
{
|
|
return $this->hasMany(PedidoExameItem::class);
|
|
}
|
|
|
|
public function agendamentoExameBloqueado()
|
|
{
|
|
return $this->hasMany(AgendamentoExameBloqueado::class);
|
|
}
|
|
|
|
public function atendimentoIndividualOutroExame()
|
|
{
|
|
return $this->hasMany(AtendimentoIndividualOutroExame::class);
|
|
}
|
|
|
|
public function atendimentoSoapSolicitacaoExameItem()
|
|
{
|
|
return $this->hasMany(AtendimentoSoapSolicitacaoExameItem::class);
|
|
}
|
|
|
|
public function kitExameItem()
|
|
{
|
|
return $this->hasMany(KitExameItem::class);
|
|
}
|
|
|
|
public function cotaExame()
|
|
{
|
|
return $this->hasMany(CotaExame::class);
|
|
}
|
|
|
|
public function exameTextoPronto()
|
|
{
|
|
return $this->hasMany(ExameTextoPronto::class);
|
|
}
|
|
|
|
public function agendamentoExameLaboratorial()
|
|
{
|
|
return $this->hasMany(AgendamentoExameLaboratorial::class);
|
|
}
|
|
|
|
public function agendamentoExameImagem()
|
|
{
|
|
return $this->hasMany(AgendamentoExameImagem::class);
|
|
}
|
|
|
|
public function AgendamentoHistoricoExclusao()
|
|
{
|
|
return $this->hasMany(AgendamentoHistoricoExclusao::class);
|
|
}
|
|
|
|
public function regulacaoParametrizacoesPrestadoresExternos()
|
|
{
|
|
return $this->belongsToMany(
|
|
ParametrizacaoPrestadorExterno::class,
|
|
'regulacao_parametrizacao_prestador_externo_exame',
|
|
'exame_id',
|
|
'prestador_externo_id'
|
|
)
|
|
->using(ParametrizacaoPrestadorExternoExame::class)
|
|
->as('pivotPrestadorExame')
|
|
->withPivot(['observacoes', 'ativo'])
|
|
->withTimestamps();
|
|
}
|
|
|
|
public function regulacaoParametrizacoesPrestadoresInternos()
|
|
{
|
|
return $this->belongsToMany(
|
|
ParametrizacaoPrestadorInterno::class,
|
|
'regulacao_parametrizacao_prestador_interno_exame',
|
|
'exame_id',
|
|
'prestador_interno_id'
|
|
)
|
|
->using(ParametrizacaoPrestadorInternoExame::class)
|
|
->as('pivotPrestadorExame')
|
|
->withPivot(['observacoes', 'ativo'])
|
|
->withTimestamps();
|
|
}
|
|
|
|
public function regulacaoParametrizacoesReguladoresExames()
|
|
{
|
|
return $this->belongsToMany(
|
|
ParametrizacaoRegulador::class,
|
|
'regulacao_parametrizacao_regulador_exame',
|
|
'exame_id',
|
|
'regulador_id'
|
|
)
|
|
->using(ParametrizacaoReguladorExame::class)
|
|
->as('pivotReguladorExame')
|
|
->withPivot(['ativo'])
|
|
->withTimestamps();
|
|
}
|
|
|
|
public function regulacaoParametrizacoesSolicitantesReguladores()
|
|
{
|
|
return $this->belongsToMany(
|
|
ParametrizacaoSolicitanteRegulador::class,
|
|
'regulacao_parametrizacao_solicitante_regulador_exame',
|
|
'exame_id',
|
|
'solicitante_regulador_id'
|
|
)
|
|
->using(ParametrizacaoSolicitanteReguladorExame::class)
|
|
->as('pivotSolicitanteReguladorExame')
|
|
->withTimestamps();
|
|
}
|
|
|
|
public function getProcedimentoAttribute()
|
|
{
|
|
if (!$this->codigo) {
|
|
|
|
return null;
|
|
}
|
|
|
|
return Procedimento::where('codigo', $this->codigo)
|
|
->orderByDesc('competencia_id')
|
|
->first();
|
|
}
|
|
|
|
public function getIsReguladoAttribute()
|
|
{
|
|
return !is_null($this->regulacao_tipo_id);
|
|
}
|
|
|
|
public function getIsAllowedToDeleteAttribute()
|
|
{
|
|
return $this->hasNoOne([
|
|
'exameLaboratorialCotasAnual',
|
|
'exameComposicao',
|
|
'exameImagemFechamentoFaturamento',
|
|
'atendimentoSoapResultadoExame',
|
|
'pedidoExameItem',
|
|
'agendamentoExameBloqueado',
|
|
'atendimentoIndividualOutroExame',
|
|
'atendimentoSoapSolicitacaoExameItem',
|
|
'kitExameItem',
|
|
'cotaExame',
|
|
'exameTextoPronto',
|
|
'agendamentoExameLaboratorial',
|
|
'agendamentoExameImagem',
|
|
'regulacaoParametrizacoesPrestadoresExternos',
|
|
'regulacaoParametrizacoesPrestadoresInternos',
|
|
'regulacaoParametrizacoesReguladoresExames',
|
|
'regulacaoParametrizacoesSolicitantesReguladores',
|
|
]);
|
|
}
|
|
|
|
public function procedimento()
|
|
{
|
|
return $this->belongsTo(Procedimento::class, 'codigo', 'codigo')->whereNotNull('codigo');
|
|
}
|
|
|
|
public function webServiceLaboratorioClienteExame()
|
|
{
|
|
return $this->hasMany(WebServiceLaboratorioClienteExame::class, 'conectasus_exame_id');
|
|
}
|
|
}
|