This commit is contained in:
74
api/app/Services/ProntoAtendimento/PlantaoService.php
Normal file
74
api/app/Services/ProntoAtendimento/PlantaoService.php
Normal file
@@ -0,0 +1,74 @@
|
||||
<?php
|
||||
|
||||
namespace App\Services\ProntoAtendimento;
|
||||
|
||||
use App\Enums\Cadastro\Estabelecimento\Servico;
|
||||
use App\Enums\ProntoAtendimento\Plantao\Status;
|
||||
use App\Models\ProntoAtendimento\Parametrizacao\Parametrizacao;
|
||||
use App\Models\ProntoAtendimento\Plantao\Plantao;
|
||||
use Carbon\Carbon;
|
||||
|
||||
class PlantaoService
|
||||
{
|
||||
public static function getCurrentPlantao($isObservacao = false)
|
||||
{
|
||||
$parametrizacao = Parametrizacao::first();
|
||||
|
||||
$now = Carbon::now();
|
||||
|
||||
$plantao = Plantao::whereIn('status_id', [Status::CONFIRMADO, Status::COM_ATENDIMENTO_AGENDADO])
|
||||
->where('lotacao_id', auth()->payload()->get('lotacao_id'))
|
||||
->when($isObservacao,
|
||||
function ($query) {
|
||||
|
||||
$query->whereIn('servico_id', [
|
||||
Servico::CONSULTA_MEDICA,
|
||||
Servico::ENFERMAGEM,
|
||||
Servico::EXAME_RAIO_X
|
||||
]);
|
||||
},
|
||||
function ($query) {
|
||||
|
||||
$query->whereHas('servico', function ($query) {
|
||||
|
||||
$query->whereHas('setores', function ($query) {
|
||||
|
||||
$query->whereHas('centrosCusto', function($query) {
|
||||
|
||||
$query->where('id', auth()->payload()->get('centro_custo_id'));
|
||||
});
|
||||
});
|
||||
});
|
||||
}
|
||||
)
|
||||
->where('inicio', '<=', $now->format('Y-m-d H:i:s'))
|
||||
->where('fim', '>', $now->subMinutes($parametrizacao->tempo_adicional_plantao ?? 0)->format('Y-m-d H:i:s'))
|
||||
->first();
|
||||
|
||||
return $plantao;
|
||||
}
|
||||
|
||||
public static function setStatusComAtendimento($plantaoId)
|
||||
{
|
||||
$plantao = Plantao::findOrFail($plantaoId);
|
||||
|
||||
if ($plantao->status_id !== Status::COM_ATENDIMENTO_AGENDADO) {
|
||||
|
||||
$plantao->status_id = Status::COM_ATENDIMENTO_AGENDADO;
|
||||
|
||||
$plantao->save();
|
||||
}
|
||||
}
|
||||
|
||||
public static function setStatusConfirmado($plantaoId)
|
||||
{
|
||||
$plantao = Plantao::findOrFail($plantaoId);
|
||||
|
||||
if ($plantao->status_id !== Status::CONFIRMADO) {
|
||||
|
||||
$plantao->status_id = Status::CONFIRMADO;
|
||||
|
||||
$plantao->save();
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user