This commit is contained in:
145
api/app/Services/PainelSenha/FilaService.php
Normal file
145
api/app/Services/PainelSenha/FilaService.php
Normal file
@@ -0,0 +1,145 @@
|
||||
<?php
|
||||
|
||||
namespace App\Services\PainelSenha;
|
||||
|
||||
use App\Enums\Administracao\Modulo;
|
||||
use App\Enums\PainelSenha\Status;
|
||||
use App\Models\PainelSenha\Fila;
|
||||
use App\Models\PainelSenha\OpcaoEntrada;
|
||||
use App\Models\PainelSenha\Prioridade;
|
||||
use App\Models\PainelSenha\TempoEspera;
|
||||
use App\Services\Administracao\ModuloService;
|
||||
use App\Services\Ambulatorio\FilaService as AmbulatorioFilaService;
|
||||
use App\Services\Farmacia\FilaAtendimentoService as FarmaciaFilaAtendimentoService;
|
||||
use App\Services\Imunizacao\FilaAtendimentoService as ImunizacaoFilaAtendimentoService;
|
||||
use App\Services\PainelSenha\FilaAtendimentoService as PainelSenhaFilaAtendimentoService;
|
||||
use App\Services\Service;
|
||||
|
||||
class FilaService extends Service
|
||||
{
|
||||
public static function index()
|
||||
{
|
||||
return Fila::query();
|
||||
}
|
||||
|
||||
public static function create()
|
||||
{
|
||||
return [
|
||||
'form' => [
|
||||
'opcoes_entrada' => OpcaoEntrada::orderBy('nome')
|
||||
->whereHas('centroCusto', function($query) {
|
||||
$query->where('id', self::getCurrentCentroCusto()->id);
|
||||
})
|
||||
->get()
|
||||
->map(function($query) {
|
||||
return [
|
||||
'id' => $query->id,
|
||||
'nome' => $query->nome,
|
||||
'prioridade_obrigatoria' => $query->prioridade_obrigatoria
|
||||
];
|
||||
}),
|
||||
'prioridades' => Prioridade::orderBy('nome')
|
||||
->get()
|
||||
->map(function($query) {
|
||||
return [
|
||||
'id' => $query->id,
|
||||
'nome' => $query->nome,
|
||||
];
|
||||
}),
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
public static function store($request)
|
||||
{
|
||||
$fila = new Fila();
|
||||
|
||||
$tempoEspera = TempoEspera::orderBy('tempo')
|
||||
->first();
|
||||
|
||||
$senha = (
|
||||
$fila->where('opcao_entrada_id', $request['opcao_entrada_id'])
|
||||
->whereRaw('emitido_em = CURRENT_DATE')
|
||||
->max('senha') ?? 0
|
||||
) + 1;
|
||||
|
||||
$params = [
|
||||
'opcao_entrada_id' => $request['opcao_entrada_id'],
|
||||
'centro_custo_id' => $request['centro_custo_id'],
|
||||
'tempo_espera_id' => $tempoEspera->id ?? null,
|
||||
'prioridade_id' => $request['prioridade_id'] ?? null,
|
||||
'status_id' => Status::EM_ESPERA,
|
||||
'senha' => $senha,
|
||||
];
|
||||
|
||||
$fila = $fila->create($params)->fresh();
|
||||
|
||||
if ($fila->opcaoEntrada->modulo_id === ModuloService::getId(Modulo::PAINEL_SENHA)) {
|
||||
|
||||
PainelSenhaFilaAtendimentoService::dispatch($fila->opcaoEntradaAtual->id, $fila->centro_custo_id);
|
||||
}
|
||||
else if ($fila->opcaoEntrada->modulo_id === ModuloService::getId(Modulo::AMBULATORIO)) {
|
||||
|
||||
AmbulatorioFilaService::dispatch($fila->centro_custo_id);
|
||||
}
|
||||
else if ($fila->opcaoEntrada->modulo_id === ModuloService::getId(Modulo::IMUNIZACAO)) {
|
||||
|
||||
ImunizacaoFilaAtendimentoService::dispatch($fila->opcaoEntradaAtual->id, $fila->centro_custo_id);
|
||||
}
|
||||
else if ($fila->opcaoEntrada->modulo_id === ModuloService::getId(Modulo::FARMACIA)) {
|
||||
|
||||
FarmaciaFilaAtendimentoService::dispatch($fila->opcaoEntradaAtual->id, $fila->centro_custo_id);
|
||||
}
|
||||
|
||||
return $fila;
|
||||
}
|
||||
|
||||
public static function show($id)
|
||||
{
|
||||
return self::get(Fila::class, $id);
|
||||
}
|
||||
|
||||
public static function destroy($id)
|
||||
{
|
||||
self::show($id)->delete();
|
||||
}
|
||||
|
||||
public static function answer($id)
|
||||
{
|
||||
$fila = self::show($id);
|
||||
|
||||
$params = [
|
||||
'status_id' => Status::EM_ATENDIMENTO
|
||||
];
|
||||
|
||||
return tap($fila)->update($params)
|
||||
->fresh();
|
||||
}
|
||||
|
||||
public static function forward($request, $id)
|
||||
{
|
||||
$fila = self::show($id);
|
||||
|
||||
$params = [
|
||||
'centro_custo_id' => $request['centro_custo_id_para'],
|
||||
'status_id' => Status::EM_ESPERA,
|
||||
'prioridade_id' => $request['prioridade_id'] ?? null,
|
||||
];
|
||||
|
||||
return tap($fila)->update($params)
|
||||
->fresh();
|
||||
}
|
||||
|
||||
public static function evade($request, $id)
|
||||
{
|
||||
$fila = self::show($id);
|
||||
|
||||
$params = [
|
||||
'evadido' => true,
|
||||
'motivo_evasao' => $request['motivo_evasao'],
|
||||
];
|
||||
|
||||
return tap($fila)->update($params)
|
||||
->fresh();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user