This commit is contained in:
175
api/app/Models/PainelSenha/Fila.php
Normal file
175
api/app/Models/PainelSenha/Fila.php
Normal file
@@ -0,0 +1,175 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models\PainelSenha;
|
||||
|
||||
use App\Models\Ambulatorio\Atendimento as AmbulatorioAtendimento;
|
||||
use App\Models\Cadastro\Estabelecimento\CentroCusto;
|
||||
use App\Models\Cadastro\SujeitoAtencao\Lotacao;
|
||||
use App\Models\Cadastro\SujeitoAtencao\Paciente;
|
||||
use App\Models\Model;
|
||||
use Illuminate\Database\Eloquent\SoftDeletes;
|
||||
|
||||
class Fila extends Model
|
||||
{
|
||||
use SoftDeletes;
|
||||
|
||||
protected $table = 'painel_senha_fila';
|
||||
|
||||
protected $fillable = [
|
||||
'centro_custo_id',
|
||||
'opcao_entrada_id',
|
||||
'opcao_entrada_destino_id',
|
||||
'prioridade_id',
|
||||
'status_id',
|
||||
'paciente_id',
|
||||
'senha',
|
||||
'evadido',
|
||||
'motivo_evasao',
|
||||
'motivo_cancelamento_evasao',
|
||||
'finalizado',
|
||||
'emitido_em',
|
||||
'atualizado_em',
|
||||
'reaberto_em',
|
||||
'reabertura_lotacao_id',
|
||||
];
|
||||
|
||||
protected $appends = [
|
||||
'data_emissao',
|
||||
'hora_emissao',
|
||||
];
|
||||
|
||||
protected $hidden = [
|
||||
'centroCusto',
|
||||
'opcaoEntrada',
|
||||
'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',
|
||||
];
|
||||
|
||||
public static function boot()
|
||||
{
|
||||
parent::boot();
|
||||
|
||||
self::created(function($model) {
|
||||
$model = (object) $model->fresh()->getRawOriginal();
|
||||
|
||||
FilaHistorico::create([
|
||||
'fila_id' => $model->id,
|
||||
'centro_custo_id' => $model->centro_custo_id,
|
||||
'opcao_entrada_id' => $model->opcao_entrada_id,
|
||||
'opcao_entrada_destino_id' => $model->opcao_entrada_destino_id,
|
||||
'prioridade_id' => $model->prioridade_id,
|
||||
'status_id' => $model->status_id,
|
||||
'senha' => $model->senha,
|
||||
'evadido' => $model->evadido,
|
||||
'motivo_evasao' => $model->motivo_evasao,
|
||||
'motivo_cancelamento_evasao' => $model->motivo_cancelamento_evasao,
|
||||
'finalizado' => $model->finalizado,
|
||||
'emitido_em' => $model->emitido_em,
|
||||
'atualizado_em' => $model->atualizado_em,
|
||||
]);
|
||||
});
|
||||
|
||||
self::updated(function($model) {
|
||||
$model = (object) $model->fresh()->getRawOriginal();
|
||||
|
||||
FilaHistorico::create([
|
||||
'fila_id' => $model->id,
|
||||
'centro_custo_id' => $model->centro_custo_id,
|
||||
'opcao_entrada_id' => $model->opcao_entrada_id,
|
||||
'opcao_entrada_destino_id' => $model->opcao_entrada_destino_id,
|
||||
'prioridade_id' => $model->prioridade_id,
|
||||
'status_id' => $model->status_id,
|
||||
'senha' => $model->senha,
|
||||
'evadido' => $model->evadido,
|
||||
'motivo_evasao' => $model->motivo_evasao,
|
||||
'motivo_cancelamento_evasao' => $model->motivo_cancelamento_evasao,
|
||||
'finalizado' => $model->finalizado,
|
||||
'emitido_em' => $model->emitido_em,
|
||||
'atualizado_em' => $model->atualizado_em,
|
||||
]);
|
||||
});
|
||||
}
|
||||
|
||||
public function centroCusto()
|
||||
{
|
||||
return $this->belongsTo(CentroCusto::class);
|
||||
}
|
||||
|
||||
public function opcaoEntrada()
|
||||
{
|
||||
return $this->belongsTo(OpcaoEntrada::class)->withTrashed();
|
||||
}
|
||||
|
||||
public function opcaoEntradaDestino()
|
||||
{
|
||||
return $this->belongsTo(OpcaoEntrada::class)->withTrashed();
|
||||
}
|
||||
|
||||
public function status()
|
||||
{
|
||||
return $this->belongsTo(Status::class);
|
||||
}
|
||||
|
||||
public function prioridade()
|
||||
{
|
||||
return $this->belongsTo(Prioridade::class);
|
||||
}
|
||||
|
||||
public function reaberturaLotacao()
|
||||
{
|
||||
return $this->belongsTo(Lotacao::class);
|
||||
}
|
||||
|
||||
public function historico()
|
||||
{
|
||||
return $this->hasMany(FilaHistorico::class);
|
||||
}
|
||||
|
||||
public function ambulatorioAtendimento()
|
||||
{
|
||||
return $this->hasOne(AmbulatorioAtendimento::class);
|
||||
}
|
||||
|
||||
public function getSenhaAttribute($value)
|
||||
{
|
||||
return $this->opcaoEntrada->sigla . $value;
|
||||
}
|
||||
|
||||
public function getDataEmissaoAttribute()
|
||||
{
|
||||
return $this->created_at->format('d/m/Y');
|
||||
}
|
||||
|
||||
public function getHoraEmissaoAttribute()
|
||||
{
|
||||
return $this->created_at->format('H:i:s');
|
||||
}
|
||||
|
||||
public function chamadas()
|
||||
{
|
||||
return $this->hasMany(Chamada::class)->where('status_id', $this->status_id);
|
||||
}
|
||||
|
||||
public function getIsAllowedToDeleteAttribute()
|
||||
{
|
||||
return $this->centroCusto()
|
||||
->exists();
|
||||
}
|
||||
|
||||
public function getOpcaoEntradaAtualAttribute()
|
||||
{
|
||||
return $this->opcaoEntradaDestino ?? $this->opcaoEntrada;
|
||||
}
|
||||
|
||||
public function paciente()
|
||||
{
|
||||
return $this->belongsTo(Paciente::class)->withTrashed();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user