This commit is contained in:
48
api/app/Http/Controllers/ProntoAtendimento/AihController.php
Normal file
48
api/app/Http/Controllers/ProntoAtendimento/AihController.php
Normal file
@@ -0,0 +1,48 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\ProntoAtendimento;
|
||||
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Services\ProntoAtendimento\Aih\AihService;
|
||||
use Illuminate\Http\Response;
|
||||
|
||||
class AihController extends Controller
|
||||
{
|
||||
protected $modulo = 'pronto-atendimento';
|
||||
protected $funcionalidade = 'aih';
|
||||
|
||||
public function datatable()
|
||||
{
|
||||
return AihService::datatable()->skipTotalRecords()->toJson();
|
||||
}
|
||||
|
||||
public function index()
|
||||
{
|
||||
return response()->json(AihService::index(), Response::HTTP_OK);
|
||||
}
|
||||
|
||||
public function list()
|
||||
{
|
||||
return response()->json(AihService::list(), Response::HTTP_OK);
|
||||
}
|
||||
|
||||
public function create($pacienteId = null)
|
||||
{
|
||||
return response()->json(AihService::create($pacienteId), Response::HTTP_OK);
|
||||
}
|
||||
|
||||
public function store()
|
||||
{
|
||||
return response()->json(AihService::store(), Response::HTTP_CREATED);
|
||||
}
|
||||
|
||||
public function edit($id)
|
||||
{
|
||||
return response()->json(AihService::edit($id), Response::HTTP_OK);
|
||||
}
|
||||
|
||||
public function update($id)
|
||||
{
|
||||
return response()->json(AihService::update($id), Response::HTTP_OK);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,26 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\ProntoAtendimento;
|
||||
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Services\ProntoAtendimento\AssinaturaEletronicaService;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Http\Response;
|
||||
|
||||
class AssinaturaEletronicaController extends Controller
|
||||
{
|
||||
protected $modulo = 'pronto-atendimento';
|
||||
protected $funcionalidade = 'assinatura-eletronica';
|
||||
|
||||
public function list()
|
||||
{
|
||||
$this->auth(__FUNCTION__);
|
||||
|
||||
return response()->json(AssinaturaEletronicaService::list(), Response::HTTP_OK);
|
||||
}
|
||||
|
||||
public function datatable(Request $request)
|
||||
{
|
||||
return response()->json(AssinaturaEletronicaService::datatable($request), Response::HTTP_OK);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,39 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\ProntoAtendimento\AssistenciaSocial;
|
||||
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Services\ProntoAtendimento\AssistenciaSocial\AssistenciaSocialService;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Http\Response;
|
||||
|
||||
class AssistenciaSocialController extends Controller
|
||||
{
|
||||
protected $modulo = 'pronto-atendimento';
|
||||
protected $funcionalidade = 'assistencia-social';
|
||||
|
||||
public function list()
|
||||
{
|
||||
$this->auth(__FUNCTION__);
|
||||
|
||||
return response()->json(AssistenciaSocialService::list(), Response::HTTP_OK);
|
||||
}
|
||||
|
||||
public function datatable(Request $request)
|
||||
{
|
||||
return response()->json(AssistenciaSocialService::datatable($request), Response::HTTP_OK);
|
||||
}
|
||||
|
||||
public function edit($id)
|
||||
{
|
||||
$this->auth(__FUNCTION__);
|
||||
|
||||
return response()->json(AssistenciaSocialService::edit($id), Response::HTTP_OK);
|
||||
}
|
||||
|
||||
public function store(Request $request)
|
||||
{
|
||||
$this->auth(__FUNCTION__);
|
||||
return response()->json(AssistenciaSocialService::store($request), Response::HTTP_CREATED);
|
||||
}
|
||||
}
|
||||
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,26 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\ProntoAtendimento\Atendimento\Evasao;
|
||||
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Services\ProntoAtendimento\Evasao\CancelamentoEvasaoService;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Http\Response;
|
||||
|
||||
class CancelamentoEvasaoController extends Controller
|
||||
{
|
||||
protected $modulo = 'pronto-atendimento';
|
||||
protected $funcionalidade = 'cancelamento-evasao';
|
||||
|
||||
public function datatable(Request $request)
|
||||
{
|
||||
return response()->json(CancelamentoEvasaoService::datatable($request), Response::HTTP_OK);
|
||||
}
|
||||
|
||||
public function cancel(Request $request, $faaId)
|
||||
{
|
||||
$this->auth(__FUNCTION__);
|
||||
|
||||
return response()->json(CancelamentoEvasaoService::cancel($request, $faaId), Response::HTTP_NO_CONTENT);
|
||||
}
|
||||
}
|
||||
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,20 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\ProntoAtendimento\Atendimento\Medico;
|
||||
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Models\ProntoAtendimento\Atendimento\Medico\DeclaracaoComparecimentoTipo;
|
||||
use Illuminate\Http\Response;
|
||||
|
||||
class DeclaracaoComparecimentoTipoController extends Controller
|
||||
{
|
||||
public function index()
|
||||
{
|
||||
return response()->json($this->get(DeclaracaoComparecimentoTipo::class)->get(), Response::HTTP_OK);
|
||||
}
|
||||
|
||||
public function show($id)
|
||||
{
|
||||
return response()->json($this->get(DeclaracaoComparecimentoTipo::class, $id), Response::HTTP_OK);
|
||||
}
|
||||
}
|
||||
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,632 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\ProntoAtendimento\Atendimento;
|
||||
|
||||
use App\Enums\Administracao\Modulo;
|
||||
use App\Enums\Cadastro\Estabelecimento\Servico as EstabelecimentoServico;
|
||||
use App\Enums\Cadastro\SujeitoAtencao\Classificacao;
|
||||
use App\Enums\PainelSenha\PrioridadeTipo as PainelSenhaPrioridade;
|
||||
use App\Enums\ProntoAtendimento\Atendimento\Desfecho;
|
||||
use App\Enums\ProntoAtendimento\Atendimento\OrigemEntrada as AtendimentoOrigemEntrada;
|
||||
use App\Enums\ProntoAtendimento\OrigemUnidadeEncaminhamento;
|
||||
use App\Enums\ProntoAtendimento\Plantao\Status as PlantaoStatus;
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Http\Requests\ProntoAtendimento\Atendimento\RecepcaoRequest;
|
||||
use App\Models\Cadastro\Estabelecimento\CentroCusto;
|
||||
use App\Models\Cadastro\Estabelecimento\Servico;
|
||||
use App\Models\Cadastro\Parametrizacao\ParametrizacaoPermissaoUsuario;
|
||||
use App\Models\Cadastro\SujeitoAtencao\Lotacao;
|
||||
use App\Models\Cadastro\SujeitoAtencao\Paciente;
|
||||
use App\Models\Cadastro\SujeitoAtencao\PacienteClassificacao;
|
||||
use App\Models\Cadastro\SujeitoAtencao\Sexo;
|
||||
use App\Models\Cns\TermoInvalido;
|
||||
use App\Models\PainelSenha\Encaminhamento;
|
||||
use App\Models\PainelSenha\Fila;
|
||||
use App\Models\PainelSenha\OpcaoEntrada;
|
||||
use App\Models\PainelSenha\Prioridade;
|
||||
use App\Models\ProntoAtendimento\Atendimento\Faa;
|
||||
use App\Models\ProntoAtendimento\Atendimento\OrigemEntrada;
|
||||
use App\Models\ProntoAtendimento\Plantao\Plantao;
|
||||
use App\Models\ProntoAtendimento\Raat\RegimeTrabalho;
|
||||
use App\Models\ProntoAtendimento\Raat\TipoAcidente;
|
||||
use App\Services\Administracao\ModuloService;
|
||||
use App\Services\Cadastro\SujeitoAtencao\PacienteDesconhecidoSaveService;
|
||||
use App\Services\Integracao\CnsService;
|
||||
use App\Services\ProntoAtendimento\Fila\FilaService;
|
||||
use App\Services\ProntoAtendimento\Impressao\ImpressaoService;
|
||||
use App\Services\ProntoAtendimento\PlantaoService;
|
||||
use App\Utils\MaskUtil;
|
||||
use Carbon\Carbon;
|
||||
use Illuminate\Http\Response;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
|
||||
class RecepcaoController extends Controller
|
||||
{
|
||||
protected $modulo = 'pronto-atendimento';
|
||||
protected $funcionalidade = 'atendimento-recepcao';
|
||||
|
||||
public function index()
|
||||
{
|
||||
$plantao = PlantaoService::getCurrentPlantao();
|
||||
|
||||
$lotacao = $this->getCurrentLotacao();
|
||||
|
||||
$permissaoUsuario = ParametrizacaoPermissaoUsuario::where('usuario_id', $lotacao->usuario_id)
|
||||
->where('infraestrutura_id', $lotacao->infraestrutura_id)
|
||||
->first();
|
||||
|
||||
$countUsuario = ParametrizacaoPermissaoUsuario::count();
|
||||
|
||||
$classificacoes = $permissaoUsuario
|
||||
? PacienteClassificacao::orderBy('descricao')
|
||||
->get()
|
||||
->filter(function ($classificacao) use ($permissaoUsuario) {
|
||||
|
||||
$exibe = false;
|
||||
|
||||
switch ($classificacao->id) {
|
||||
case Classificacao::MUNICIPE:
|
||||
$exibe = $permissaoUsuario->municipe;
|
||||
break;
|
||||
case Classificacao::PROVISORIO:
|
||||
$exibe = $permissaoUsuario->provisorio;
|
||||
break;
|
||||
case Classificacao::OUTRO_MUNICIPIO:
|
||||
$exibe = $permissaoUsuario->outro_municipio;
|
||||
break;
|
||||
}
|
||||
|
||||
return $exibe ? [
|
||||
'id' => $classificacao->id,
|
||||
'descricao' => $classificacao->descricao
|
||||
] : null;
|
||||
})
|
||||
->values()
|
||||
: [];
|
||||
|
||||
return response()->json(
|
||||
[
|
||||
'additionals' => [
|
||||
'plantao_id' => $plantao->id ?? null,
|
||||
'plantao_faixa_etaria_id' => $plantao->faixa_etaria_id ?? null,
|
||||
'classificacoes' => $classificacoes,
|
||||
'is_permissao_cadastro' => $countUsuario === 0 ? true : false,
|
||||
],
|
||||
],
|
||||
Response::HTTP_OK
|
||||
);
|
||||
}
|
||||
|
||||
public function create()
|
||||
{
|
||||
$this->auth(__FUNCTION__);
|
||||
|
||||
$now = Carbon::now();
|
||||
$senha = '';
|
||||
$opcaoEntradaId = null;
|
||||
$pacienteIdentificado = null;
|
||||
$isAtendimentoPreferencial = false;
|
||||
$prioridadeId = null;
|
||||
$alertFaaAberta = false;
|
||||
$alertFaaEvadida = false;
|
||||
$dataHoraDesfecho = null;
|
||||
|
||||
if (is_numeric(request()->fila_id)) {
|
||||
|
||||
$fila = Fila::findOrFail(request()->fila_id);
|
||||
|
||||
$senha = $fila->senha;
|
||||
$opcaoEntradaId = $fila->opcao_entrada_id;
|
||||
|
||||
if ($fila->prioridade_id) {
|
||||
|
||||
$isAtendimentoPreferencial = true;
|
||||
$prioridadeId = $fila->prioridade_id;
|
||||
}
|
||||
}
|
||||
|
||||
if (is_numeric(request()->paciente_id)) {
|
||||
|
||||
$faa = Faa::with('atendimentos.fila')
|
||||
->where('paciente_id', request()->paciente_id)
|
||||
->whereHas('atendimentos.fila', function($query) {
|
||||
|
||||
$query
|
||||
->whereHas('centroCusto', function($query) {
|
||||
$query->where(
|
||||
'infraestrutura_id',
|
||||
Lotacao::findOrFail(auth()->payload()->get('lotacao_id'))->infraestrutura_id
|
||||
);
|
||||
});
|
||||
})
|
||||
->where(function($query) {
|
||||
$query->whereNull('desfecho_id')
|
||||
->orWhere('desfecho_id', Desfecho::EVASAO);
|
||||
})
|
||||
->orderByDesc('id')
|
||||
->first();
|
||||
|
||||
if ($faa) {
|
||||
$setor = null;
|
||||
$createdAt = null;
|
||||
$procedimentos = 0;
|
||||
$finalizado = false;
|
||||
|
||||
$faa->atendimentos->map(function($atendimento) use (&$setor, &$procedimentos, &$createdAt, &$finalizado) {
|
||||
$createdAt = $atendimento->fila->created_at;
|
||||
$setor = $atendimento->fila->centroCusto->setor;
|
||||
$procedimentos = $atendimento->procedimentos->count();
|
||||
$finalizado = $atendimento->fila->finalizado;
|
||||
});
|
||||
|
||||
$createdAt = Carbon::parse($createdAt)->addDay()->format('Y-m-d h:i');
|
||||
|
||||
if ($createdAt >= Carbon::now()->format('Y-m-d h:i')) {
|
||||
|
||||
if($faa->desfecho_id == Desfecho::EVASAO) {
|
||||
$alertFaaEvadida = true;
|
||||
$dataHoraDesfecho = Carbon::parse($faa->data_hora_desfecho)->format('d/m/Y H:i');
|
||||
}
|
||||
|
||||
elseif ($faa->desfecho_id == null || ($procedimentos > 0 && $finalizado)) {
|
||||
|
||||
$alertFaaAberta = true;
|
||||
}
|
||||
} else {
|
||||
|
||||
if ($faa->desfecho_id == null) {
|
||||
|
||||
$alertFaaAberta = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$paciente = Paciente::findOrFail(request()->paciente_id);
|
||||
$endereco = '';
|
||||
|
||||
if ($paciente->cidadao->domicilio_id) {
|
||||
|
||||
$endereco = $paciente->cidadao->domicilio->endereco;
|
||||
$endereco = $endereco->completo . ' - ' . MaskUtil::getCepMasked($endereco->logradouro->cep);
|
||||
}
|
||||
|
||||
$pacienteIdentificado = [
|
||||
'prontuario' => $paciente->prontuario,
|
||||
'classificacao_id' => $paciente->classificacao_id,
|
||||
'cns' => $paciente->cidadao->cns,
|
||||
'nome' => $paciente->cidadao->nome,
|
||||
'nome_social' => $paciente->cidadao->nome_social,
|
||||
'preferencia_nome_id' => $paciente->cidadao->preferencia_nome_id ?? null,
|
||||
'nome_mae' => $paciente->cidadao->nome_mae ?? '',
|
||||
'sexo' => [
|
||||
'id' => $paciente->cidadao->sexo->id,
|
||||
'descricao' => $paciente->cidadao->sexo->descricao,
|
||||
],
|
||||
'data_nascimento' => $paciente->cidadao->data_nascimento->format('d/m/Y'),
|
||||
'idade' => $paciente->cidadao->idade,
|
||||
'endereco' => $endereco,
|
||||
'telefones' => $paciente->cidadao->telefones->map(fn ($telefone) => [
|
||||
'id' => $telefone->id,
|
||||
'numero' => MaskUtil::getPhoneMasked($telefone->numero),
|
||||
'observacao' => $telefone->observacao ?? '',
|
||||
'autoriza_sms' => $telefone->autoriza_sms,
|
||||
'principal' => $telefone->principal,
|
||||
]),
|
||||
'cidadao_id' => $paciente->cidadao_id,
|
||||
];
|
||||
|
||||
if ($paciente->cidadao->idade['anos'] >= 60) {
|
||||
|
||||
$isAtendimentoPreferencial = true;
|
||||
$prioridadeId = PainelSenhaPrioridade::IDOSO;
|
||||
}
|
||||
}
|
||||
|
||||
$ocupacoes = collect();
|
||||
|
||||
Plantao::whereIn('status_id', [
|
||||
PlantaoStatus::CADASTRADO,
|
||||
PlantaoStatus::CONFIRMADO,
|
||||
PlantaoStatus::COM_ATENDIMENTO_AGENDADO
|
||||
])
|
||||
->whereRaw("DATE_SUB(pronto_atendimento_plantao.inicio, INTERVAL 60 MINUTE) <= '{$now->format('Y-m-d H:i:s')}'")
|
||||
->where('pronto_atendimento_plantao.fim', '>=', $now->format('Y-m-d H:i:s'))
|
||||
->get()
|
||||
->map(function ($plantao) use ($ocupacoes) {
|
||||
|
||||
if ($plantao->servico_id === EstabelecimentoServico::CONSULTA_MEDICA) {
|
||||
|
||||
$ocupacao = $plantao->lotacao->ocupacao;
|
||||
|
||||
if (!$ocupacoes->contains('id', $ocupacao->id)) {
|
||||
|
||||
$ocupacoes->push([
|
||||
'id' => $ocupacao->id,
|
||||
'codigoNome' => $ocupacao->codigo_nome,
|
||||
]);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
$lotacao = $this->getCurrentLotacao();
|
||||
|
||||
$permissaoUsuario = ParametrizacaoPermissaoUsuario::where('usuario_id', $lotacao->usuario_id)
|
||||
->where('infraestrutura_id', $lotacao->infraestrutura_id)
|
||||
->first();
|
||||
|
||||
$countUsuario = ParametrizacaoPermissaoUsuario::count();
|
||||
|
||||
$classificacoes = $permissaoUsuario
|
||||
? PacienteClassificacao::orderBy('descricao')
|
||||
->get()
|
||||
->filter(function ($classificacao) use ($permissaoUsuario) {
|
||||
|
||||
$exibe = false;
|
||||
|
||||
switch ($classificacao->id) {
|
||||
case Classificacao::MUNICIPE:
|
||||
$exibe = $permissaoUsuario->municipe;
|
||||
break;
|
||||
case Classificacao::PROVISORIO:
|
||||
$exibe = $permissaoUsuario->provisorio;
|
||||
break;
|
||||
case Classificacao::OUTRO_MUNICIPIO:
|
||||
$exibe = $permissaoUsuario->outro_municipio;
|
||||
break;
|
||||
}
|
||||
|
||||
return $exibe ? [
|
||||
'id' => $classificacao->id,
|
||||
'descricao' => $classificacao->descricao
|
||||
] : null;
|
||||
})
|
||||
->values()
|
||||
: [];
|
||||
|
||||
return response()->json(
|
||||
[
|
||||
'additionals' => [
|
||||
'permissoes_atualizacao_cadastro_paciente' => self::getPermissoesAtualizacaoCadastroPaciente(),
|
||||
],
|
||||
'data_atual' => $now->format('d/m/Y'),
|
||||
'termos_invalidos' => TermoInvalido::all()->map(fn ($termo) => $termo->descricao),
|
||||
'form' => [
|
||||
'senha' => $senha,
|
||||
'alert_faa_aberta' => $alertFaaAberta,
|
||||
'setor' => $setor['nome'] ?? null,
|
||||
'alert_faa_evadida' => $alertFaaEvadida,
|
||||
'data_hora_desfecho' => $dataHoraDesfecho,
|
||||
'is_atendimento_preferencial' => $isAtendimentoPreferencial,
|
||||
'prioridades' => Prioridade::orderBy('nome')
|
||||
->get()
|
||||
->map(fn ($prioridade) => [
|
||||
'id' => $prioridade->id,
|
||||
'nome' => $prioridade->nome,
|
||||
]),
|
||||
'prioridade_id' => $prioridadeId,
|
||||
'paciente_identificado' => $pacienteIdentificado,
|
||||
'paciente_desconhecido' => [
|
||||
'sexos' => Sexo::orderBy('descricao')
|
||||
->get()
|
||||
->map(fn ($sexo) => [
|
||||
'id' => $sexo->id,
|
||||
'descricao' => $sexo->descricao
|
||||
]),
|
||||
],
|
||||
'opcoes_entrada' => OpcaoEntrada::where('modulo_id', ModuloService::getId(Modulo::PRONTO_ATENDIMENTO))
|
||||
->orderBy('nome')
|
||||
->where('centro_custo_id', auth()->payload()->get('centro_custo_id'))
|
||||
->get()
|
||||
->map(fn($opcao) => [
|
||||
'id' => $opcao->id,
|
||||
'nome' => $opcao->nome,
|
||||
'prioridade_obrigatoria' => $opcao->prioridade_obrigatoria
|
||||
]),
|
||||
'opcao_entrada_id' => $opcaoEntradaId,
|
||||
'origens_entrada' => OrigemEntrada::orderBy('nome')
|
||||
->get()
|
||||
->map(fn ($origem) => [
|
||||
'id' => $origem->id,
|
||||
'nome' => $origem->nome,
|
||||
]),
|
||||
'origem_entrada_id' => AtendimentoOrigemEntrada::ESPONTANEA,
|
||||
'origens_unidade' => [
|
||||
[ 'id' => OrigemUnidadeEncaminhamento::INTERNA, 'nome' => 'INTERNA' ],
|
||||
[ 'id' => OrigemUnidadeEncaminhamento::EXTERNA, 'nome' => 'EXTERNA' ],
|
||||
],
|
||||
'origem_unidade_value' => OrigemUnidadeEncaminhamento::INTERNA,
|
||||
'servicos' => Servico::orderBy('nome')
|
||||
->get()
|
||||
->map(fn ($servico) => [
|
||||
'id' => $servico->id,
|
||||
'nome' => $servico->nome,
|
||||
]),
|
||||
'ocupacoes' => $ocupacoes,
|
||||
'centros_custo_para' => Encaminhamento::where('centro_custo_id_de', auth()->payload()->get('centro_custo_id'))
|
||||
->get()
|
||||
->map(fn ($encaminhamento) => [
|
||||
'id' => $encaminhamento->centroCustoPara->id,
|
||||
'nome' => $encaminhamento->centroCustoPara->setor->nome,
|
||||
'setor_tipo_id' => $encaminhamento->centroCustoPara->setor->tipo_id
|
||||
]),
|
||||
'raat_data' => [
|
||||
'form' => [
|
||||
'raat' => [
|
||||
'tipo_acidente' => TipoAcidente::orderBy('nome')
|
||||
->get()
|
||||
->map(fn ($tipo) => [
|
||||
'id' => $tipo->id,
|
||||
'nome' => $tipo->nome,
|
||||
]),
|
||||
'regime_trabalho' => RegimeTrabalho::orderBy('nome')
|
||||
->get()
|
||||
->map(fn ($tipo) => [
|
||||
'id' => $tipo->id,
|
||||
'nome' => $tipo->nome,
|
||||
]),
|
||||
]
|
||||
]
|
||||
],
|
||||
'classificacoes' => $classificacoes,
|
||||
'is_permissao_cadastro' => $countUsuario === 0 ? true : false,
|
||||
],
|
||||
],
|
||||
Response::HTTP_OK
|
||||
);
|
||||
}
|
||||
|
||||
public function store(RecepcaoRequest $request)
|
||||
{
|
||||
$this->auth(__FUNCTION__);
|
||||
|
||||
$recepcao = null;
|
||||
|
||||
DB::beginTransaction();
|
||||
|
||||
try {
|
||||
$params = $this->getParams($request);
|
||||
|
||||
sleep(rand(1, 3));
|
||||
|
||||
$faaRecente = Faa::where('paciente_id', $params['paciente'])->where('created_at', '>=', now()->subMinutes(5))->first();
|
||||
|
||||
if ($faaRecente) {
|
||||
|
||||
throw new \Exception('O paciente teve uma FAA criada a menos de 5 minutos, caso deseje criar outra tente novamente após esse tempo.');
|
||||
}
|
||||
|
||||
$pacienteId = $this->savePaciente($params['paciente'], $params['atendido_em']);
|
||||
$faa = Faa::create(['paciente_id' => $pacienteId]);
|
||||
|
||||
if (isset($params['raat'])) {
|
||||
|
||||
$this->saveRaat($faa, $params['raat']);
|
||||
}
|
||||
|
||||
$filaId = $this->saveFila($params['fila']);
|
||||
$atendimento = $faa->atendimentos()->create(['fila_id' => $filaId]);
|
||||
$recepcao = $this->saveAtendimentoRecepcao($atendimento, $params);
|
||||
|
||||
if (isset($params['observacao'])) {
|
||||
|
||||
$atendimento->observacoes()->create([
|
||||
'atendimento_recepcao_id' => $recepcao->id,
|
||||
'descricao' => $params['observacao'],
|
||||
]);
|
||||
}
|
||||
|
||||
$this->encaminharFila($pacienteId, $filaId, $params['fila']);
|
||||
|
||||
DB::commit();
|
||||
|
||||
$recepcao->refresh();
|
||||
$recepcao->impressoes = $this->getImpressoes($recepcao);
|
||||
|
||||
} catch (\Exception $e) {
|
||||
|
||||
DB::rollBack();
|
||||
return response()->json(['message' => $e->getMessage()], Response::HTTP_BAD_REQUEST);
|
||||
}
|
||||
|
||||
return response()->json($recepcao, Response::HTTP_CREATED);
|
||||
}
|
||||
|
||||
private function getParams($request)
|
||||
{
|
||||
$params = $request->all();
|
||||
|
||||
if (isset($params['paciente']['nome'])) {
|
||||
|
||||
$params['paciente']['nome'] = mb_strtoupper($params['paciente']['nome']);
|
||||
}
|
||||
|
||||
if (isset($params['urgente_motivo'])) {
|
||||
|
||||
$params['urgente_motivo'] = mb_strtoupper($params['urgente_motivo']);
|
||||
}
|
||||
|
||||
if (isset($params['medico_samu'])) {
|
||||
|
||||
$params['medico_samu'] = mb_strtoupper($params['medico_samu']);
|
||||
}
|
||||
|
||||
if (isset($params['acompanhante'])) {
|
||||
|
||||
$params['acompanhante'] = mb_strtoupper($params['acompanhante']);
|
||||
}
|
||||
|
||||
if (isset($params['medico_solicitante_encaminhamento'])) {
|
||||
|
||||
$params['medico_solicitante_encaminhamento'] = mb_strtoupper($params['medico_solicitante_encaminhamento']);
|
||||
}
|
||||
|
||||
if (isset($params['raat']['empresa']['nome'])) {
|
||||
|
||||
$params['raat']['empresa']['nome'] = mb_strtoupper($params['raat']['empresa']['nome']);
|
||||
}
|
||||
|
||||
if (isset($params['raat']['empresa']['ramo_atividade'])) {
|
||||
|
||||
$params['raat']['empresa']['ramo_atividade'] = mb_strtoupper($params['raat']['empresa']['ramo_atividade']);
|
||||
}
|
||||
|
||||
if (isset($params['raat']['empresa']['endereco'])) {
|
||||
|
||||
$params['raat']['empresa']['endereco'] = mb_strtoupper($params['raat']['empresa']['endereco']);
|
||||
}
|
||||
|
||||
if (isset($params['raat']['acidente']['local'])) {
|
||||
|
||||
$params['raat']['acidente']['local'] = mb_strtoupper($params['raat']['acidente']['local']);
|
||||
}
|
||||
|
||||
if (isset($params['raat']['acidente']['regime_trabalho_outro'])) {
|
||||
|
||||
$params['raat']['acidente']['regime_trabalho_outro'] = mb_strtoupper(
|
||||
$params['raat']['acidente']['regime_trabalho_outro']
|
||||
);
|
||||
}
|
||||
|
||||
return $params;
|
||||
}
|
||||
|
||||
private function savePaciente($params, $atendidoEm)
|
||||
{
|
||||
if (isset($params['id'])) {
|
||||
|
||||
return $params['id'];
|
||||
}
|
||||
|
||||
return (new PacienteDesconhecidoSaveService(
|
||||
$atendidoEm,
|
||||
$params['sexo_id'],
|
||||
$params['caracteristicas_fisicas'] ?? null
|
||||
))->save()->id;
|
||||
}
|
||||
|
||||
private function saveRaat($faa, $params)
|
||||
{
|
||||
return $faa->raat()->create([
|
||||
'empresa_nome' => $params['empresa']['nome'],
|
||||
'empresa_ramo_atividade' => $params['empresa']['ramo_atividade'] ?? null,
|
||||
'empresa_endereco' => $params['empresa']['endereco'] ?? null,
|
||||
'empresa_telefone' => $params['empresa']['telefone'] ?? null,
|
||||
'acidente_data' => $params['acidente']['data'],
|
||||
'acidente_hora' => $params['acidente']['hora'] ?? null,
|
||||
'acidente_tipo_id' => $params['acidente']['tipo_id'] ?? null,
|
||||
'acidente_local' => $params['acidente']['local'] ?? null,
|
||||
'acidente_descricao' => $params['acidente']['descricao'],
|
||||
'regime_trabalho_id' => $params['regime_trabalho_id'] ?? null,
|
||||
'regime_trabalho_outro' => $params['regime_trabalho_outro'] ?? null
|
||||
]);
|
||||
}
|
||||
|
||||
private function saveFila($params)
|
||||
{
|
||||
if (isset($params['id'])) {
|
||||
|
||||
return $params['id'];
|
||||
}
|
||||
|
||||
$centroCusto = CentroCusto::findOrFail(auth()->payload()->get('centro_custo_id'));
|
||||
|
||||
$fila = FilaService::store([
|
||||
'centro_custo_id' => $centroCusto->id,
|
||||
'opcao_entrada_id' => $params['opcao_entrada_id'],
|
||||
'prioridade_id' => $params['prioridade_id']
|
||||
]);
|
||||
|
||||
return $fila->id;
|
||||
}
|
||||
|
||||
private function saveAtendimentoRecepcao($atendimento, $params)
|
||||
{
|
||||
$plantaoId = $params['plantao_id'] ?? PlantaoService::getCurrentPlantao()->id ?? null;
|
||||
|
||||
if (isset($plantaoId)) {
|
||||
|
||||
PlantaoService::setStatusComAtendimento($plantaoId);
|
||||
}
|
||||
|
||||
return $atendimento->recepcao()->create([
|
||||
'plantao_id' => $plantaoId,
|
||||
'atendido_em' => $params['atendido_em'],
|
||||
'urgente' => $params['urgente'] ?? null,
|
||||
'urgente_motivo' => $params['urgente_motivo'] ?? null,
|
||||
'origem_entrada_id' => $params['origem_entrada_id'] ?? null,
|
||||
'medico_samu' => $params['medico_samu'] ?? null,
|
||||
'motivo_atendimento' => $params['motivo_atendimento'] ?? null,
|
||||
'acompanhante' => $params['acompanhante'] ?? null,
|
||||
'unidade_encaminhamento_id' => $params['unidade_encaminhamento_id'] ?? null,
|
||||
'unidade_externa_encaminhamento_id' => $params['unidade_externa_encaminhamento_id'] ?? null,
|
||||
'medico_solicitante_encaminhamento' => $params['medico_solicitante_encaminhamento'] ?? null,
|
||||
'servico_id' => $params['servico_id'],
|
||||
'ocupacao_id' => $params['ocupacao_id'] ?? null,
|
||||
'observacao' => $params['observacao'] ?? null,
|
||||
]);
|
||||
}
|
||||
|
||||
private function encaminharFila($pacienteId, $filaId, $params)
|
||||
{
|
||||
FilaService::forward([
|
||||
'centro_custo_id_para' => $params['centro_custo_id_para'],
|
||||
'prioridade_id' => $params['prioridade_id'] ?? null,
|
||||
'paciente_id' => $pacienteId,
|
||||
], $filaId);
|
||||
}
|
||||
|
||||
private function getImpressoes($recepcao)
|
||||
{
|
||||
$cidadao = $recepcao->atendimento->faa->paciente->cidadao;
|
||||
$fila = $recepcao->atendimento->fila;
|
||||
|
||||
$impressoesFAA = ImpressaoService::getImpressoesFaa($recepcao->atendimento_id);
|
||||
$indiceFaaEletronica = array_search('eletronica', array_column($impressoesFAA, 'value'));
|
||||
unset($impressoesFAA[$indiceFaaEletronica]);
|
||||
|
||||
return [
|
||||
'recepcao' => ImpressaoService::getImpressoesRecepcao(
|
||||
$recepcao->atendimento_id,
|
||||
[
|
||||
'etiqueta' => [
|
||||
'atendido_em' => (new Carbon($recepcao->atendido_em))->format('d/m/Y H:i'),
|
||||
'infraestrutura' => $recepcao->createdLotacao->infraestrutura->nome,
|
||||
'acompanhante' => $recepcao->acompanhante ?? '',
|
||||
'paciente' => $cidadao->nome,
|
||||
'data_nascimento' => $cidadao->data_nascimento
|
||||
? $cidadao->data_nascimento->format('d/m/Y') : '',
|
||||
'senha' => $recepcao->atendimento->fila->senha
|
||||
],
|
||||
'senha' => [
|
||||
'data' => $fila->data_emissao,
|
||||
'hora' => $fila->hora_emissao,
|
||||
'senha' => $fila->senha,
|
||||
]
|
||||
]
|
||||
),
|
||||
'faa' => array_values($impressoesFAA)
|
||||
];
|
||||
}
|
||||
|
||||
private static function getPermissoesAtualizacaoCadastroPaciente()
|
||||
{
|
||||
$parametrizacao = CnsService::getParametrizacao();
|
||||
|
||||
if (!is_null($parametrizacao)) {
|
||||
$lotacao = self::getCurrentLotacao();
|
||||
|
||||
return DB::table('cadastro_parametrizacao_permissao_usuario')
|
||||
->select([
|
||||
'municipe',
|
||||
'provisorio',
|
||||
'outro_municipio',
|
||||
])
|
||||
->where('infraestrutura_id', $lotacao->infraestrutura_id)
|
||||
->where('usuario_id', $lotacao->usuario_id)
|
||||
->get()
|
||||
->first();
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,92 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\ProntoAtendimento\Atendimento;
|
||||
|
||||
use App\Enums\Cadastro\SujeitoAtencao\Classificacao;
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Models\Cadastro\Parametrizacao\ParametrizacaoPermissaoUsuario;
|
||||
use App\Models\Cadastro\SujeitoAtencao\PacienteClassificacao;
|
||||
use App\Services\ProntoAtendimento\Atendimento\RetroativoService;
|
||||
use Illuminate\Http\Response;
|
||||
|
||||
class RetroativoController extends Controller
|
||||
{
|
||||
protected $modulo = 'pronto-atendimento';
|
||||
protected $funcionalidade = 'atendimento-retroativo';
|
||||
|
||||
public function create()
|
||||
{
|
||||
$this->auth(__FUNCTION__);
|
||||
|
||||
$pacienteHasAtendimento = RetroativoService::pacienteHasAtendimento(request()->paciente_id ?? null);
|
||||
|
||||
if($pacienteHasAtendimento != false) {
|
||||
|
||||
return response()->json($pacienteHasAtendimento, $pacienteHasAtendimento['response']);
|
||||
}
|
||||
|
||||
return response()->json(RetroativoService::create(), Response::HTTP_OK);
|
||||
}
|
||||
|
||||
public function index()
|
||||
{
|
||||
|
||||
$lotacao = $this->getCurrentLotacao();
|
||||
|
||||
$permissaoUsuario = ParametrizacaoPermissaoUsuario::where('usuario_id', $lotacao->usuario_id)
|
||||
->where('infraestrutura_id', $lotacao->infraestrutura_id)
|
||||
->first();
|
||||
|
||||
$countUsuario = ParametrizacaoPermissaoUsuario::count();
|
||||
|
||||
$classificacoes = $permissaoUsuario
|
||||
? PacienteClassificacao::orderBy('descricao')
|
||||
->get()
|
||||
->filter(function ($classificacao) use ($permissaoUsuario) {
|
||||
|
||||
$exibe = false;
|
||||
|
||||
switch ($classificacao->id) {
|
||||
case Classificacao::MUNICIPE:
|
||||
$exibe = $permissaoUsuario->municipe;
|
||||
break;
|
||||
case Classificacao::PROVISORIO:
|
||||
$exibe = $permissaoUsuario->provisorio;
|
||||
break;
|
||||
case Classificacao::OUTRO_MUNICIPIO:
|
||||
$exibe = $permissaoUsuario->outro_municipio;
|
||||
break;
|
||||
}
|
||||
|
||||
return $exibe ? [
|
||||
'id' => $classificacao->id,
|
||||
'descricao' => $classificacao->descricao
|
||||
] : null;
|
||||
})
|
||||
->values()
|
||||
: [];
|
||||
|
||||
return response()->json(
|
||||
[
|
||||
'classificacoes' => $classificacoes,
|
||||
'is_permissao_cadastro' => $countUsuario === 0 ? true : false,
|
||||
],
|
||||
Response::HTTP_OK
|
||||
);
|
||||
}
|
||||
|
||||
public function store()
|
||||
{
|
||||
$this->auth(__FUNCTION__);
|
||||
|
||||
$pacienteHasAtendimento = RetroativoService::pacienteHasAtendimento(request()->get('paciente')['id'] ?? null);
|
||||
|
||||
if($pacienteHasAtendimento != false) {
|
||||
|
||||
return response()->json($pacienteHasAtendimento, $pacienteHasAtendimento['response']);
|
||||
}
|
||||
|
||||
return response()->json(RetroativoService::store(), Response::HTTP_CREATED);
|
||||
}
|
||||
|
||||
}
|
||||
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,116 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\ProntoAtendimento\ClassificacaoRisco;
|
||||
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Http\Requests\ProntoAtendimento\ClassificacaoRisco\ClassificacaoRiscoRequest;
|
||||
use App\Models\ProntoAtendimento\ClassificacaoRisco\ClassificacaoRisco;
|
||||
use App\Models\ProntoAtendimento\ClassificacaoRisco\Tipo;
|
||||
use Illuminate\Http\Response;
|
||||
use DB;
|
||||
|
||||
class ClassificacaoRiscoController extends Controller
|
||||
{
|
||||
protected $modulo = 'pronto-atendimento';
|
||||
protected $funcionalidade = 'classificacao-risco';
|
||||
|
||||
public function datatable()
|
||||
{
|
||||
$classificacoes = DB::table('pronto_atendimento_classificacao_risco')
|
||||
->whereNull('pronto_atendimento_classificacao_risco.deleted_at')
|
||||
->join(
|
||||
'pronto_atendimento_classificacao_risco_tipo',
|
||||
'pronto_atendimento_classificacao_risco_tipo.id',
|
||||
'pronto_atendimento_classificacao_risco.tipo_id'
|
||||
)
|
||||
->select([
|
||||
'pronto_atendimento_classificacao_risco.id',
|
||||
'pronto_atendimento_classificacao_risco.nome',
|
||||
'pronto_atendimento_classificacao_risco_tipo.nome as tipo',
|
||||
'pronto_atendimento_classificacao_risco_tipo.cor as cor',
|
||||
]);
|
||||
|
||||
return datatables()->of($classificacoes)->toJson();
|
||||
}
|
||||
|
||||
public function index()
|
||||
{
|
||||
$this->auth(__FUNCTION__);
|
||||
|
||||
$classificacoes = $this->get(ClassificacaoRisco::class)->orderBy('nome')->get();
|
||||
|
||||
return response()->json($classificacoes, Response::HTTP_OK);
|
||||
}
|
||||
|
||||
public function create()
|
||||
{
|
||||
$this->auth(__FUNCTION__);
|
||||
|
||||
$classificacao = new ClassificacaoRisco();
|
||||
$classificacao->fill(array_fill_keys($classificacao->getFillable(), null));
|
||||
|
||||
return response()->json(
|
||||
[
|
||||
'form' => $this->getFormData(),
|
||||
'model' => $classificacao->makeHidden('id')
|
||||
],
|
||||
Response::HTTP_OK
|
||||
);
|
||||
}
|
||||
|
||||
public function store(ClassificacaoRiscoRequest $request)
|
||||
{
|
||||
$this->auth(__FUNCTION__);
|
||||
|
||||
$classificacao = ClassificacaoRisco::create($request->all())->fresh();
|
||||
|
||||
return response()->json($classificacao, Response::HTTP_CREATED);
|
||||
}
|
||||
|
||||
public function show($id)
|
||||
{
|
||||
$this->auth(__FUNCTION__);
|
||||
|
||||
return response()->json($this->get(ClassificacaoRisco::class, $id), Response::HTTP_OK);
|
||||
}
|
||||
|
||||
public function edit($id)
|
||||
{
|
||||
$this->auth(__FUNCTION__);
|
||||
|
||||
$classificacao = ClassificacaoRisco::findOrFail($id);
|
||||
|
||||
return response()->json(
|
||||
[
|
||||
'form' => $this->getFormData(),
|
||||
'model' => $classificacao->makeHidden('id')->unsetRelation('tipo'),
|
||||
],
|
||||
Response::HTTP_OK
|
||||
);
|
||||
}
|
||||
|
||||
private function getFormData()
|
||||
{
|
||||
return [
|
||||
'tipos' => Tipo::orderBy('nome')->get(['id', 'nome'])
|
||||
];
|
||||
}
|
||||
|
||||
public function update(ClassificacaoRiscoRequest $request, $id)
|
||||
{
|
||||
$this->auth(__FUNCTION__);
|
||||
|
||||
$classificacao = tap(ClassificacaoRisco::findOrFail($id))->update($request->all());
|
||||
|
||||
return response()->json($classificacao->fresh(), Response::HTTP_OK);
|
||||
}
|
||||
|
||||
public function destroy($id)
|
||||
{
|
||||
$this->auth(__FUNCTION__);
|
||||
|
||||
ClassificacaoRisco::findOrFail($id)->delete();
|
||||
|
||||
return response()->json(null, Response::HTTP_NO_CONTENT);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,59 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\ProntoAtendimento\FechamentoFaa;
|
||||
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Services\ProntoAtendimento\FechamentoFaa\FechamentoFaaService;
|
||||
use Illuminate\Http\Response;
|
||||
|
||||
class FechamentoFaaController extends Controller
|
||||
{
|
||||
protected $modulo = 'pronto-atendimento';
|
||||
protected $funcionalidade = 'fechamento-faa';
|
||||
|
||||
public function list()
|
||||
{
|
||||
$this->auth(__FUNCTION__);
|
||||
|
||||
return response()->json(
|
||||
FechamentoFaaService::list(),
|
||||
Response::HTTP_OK
|
||||
);
|
||||
}
|
||||
|
||||
public function procedimento()
|
||||
{
|
||||
return response()->json(
|
||||
FechamentoFaaService::getProcedimentosFaa(),
|
||||
Response::HTTP_OK
|
||||
);
|
||||
}
|
||||
|
||||
public function index()
|
||||
{
|
||||
$this->auth(__FUNCTION__);
|
||||
|
||||
return response()->json(
|
||||
FechamentoFaaService::index(),
|
||||
Response::HTTP_OK
|
||||
);
|
||||
}
|
||||
|
||||
public function update($id)
|
||||
{
|
||||
$this->auth(__FUNCTION__);
|
||||
|
||||
return response()->json(
|
||||
FechamentoFaaService::update($id),
|
||||
Response::HTTP_CREATED
|
||||
);
|
||||
}
|
||||
|
||||
public function cancelarFaa($id)
|
||||
{
|
||||
return response()->json(
|
||||
FechamentoFaaService::cancelarFaa($id),
|
||||
Response::HTTP_CREATED
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,57 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\ProntoAtendimento;
|
||||
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Services\ProntoAtendimento\FechamentoFaaMassaService;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Http\Response;
|
||||
|
||||
class FechamentoFaaMassaController extends Controller
|
||||
{
|
||||
protected $modulo = 'pronto-atendimento';
|
||||
protected $funcionalidade = 'fechamento-faa-massa';
|
||||
|
||||
public function create()
|
||||
{
|
||||
$this->auth(__FUNCTION__);
|
||||
|
||||
return response()->json(FechamentoFaaMassaService::create(), Response::HTTP_OK);
|
||||
}
|
||||
|
||||
public function list()
|
||||
{
|
||||
$this->auth(__FUNCTION__);
|
||||
|
||||
return response()->json(FechamentoFaaMassaService::list(), Response::HTTP_OK);
|
||||
}
|
||||
|
||||
public function store(Request $request)
|
||||
{
|
||||
$this->auth(__FUNCTION__);
|
||||
|
||||
return response()->json(FechamentoFaaMassaService::store($request), Response::HTTP_CREATED);
|
||||
}
|
||||
|
||||
public function datatable()
|
||||
{
|
||||
return datatables()
|
||||
->of(FechamentoFaaMassaService::datatable())
|
||||
->filterColumn('pronto_atendimento_faa.created_at', function ($query, $keyword) {
|
||||
$query->whereRaw("DATE_FORMAT(pronto_atendimento_faa.created_at, '%d/%m/%Y') LIKE ?", ["%{$keyword}%"])
|
||||
->orWhereRaw(
|
||||
"CONCAT(
|
||||
SUBSTR(pronto_atendimento_faa.created_at,9,2),
|
||||
SUBSTR(pronto_atendimento_faa.created_at,6,2),
|
||||
SUBSTR(pronto_atendimento_faa.created_at,1,4)
|
||||
) like ?",
|
||||
["%{$keyword}%"]
|
||||
);
|
||||
})
|
||||
->filterColumn('cadastro_infraestrutura.nome', function ($query, $keyword) {
|
||||
$query->whereRaw("COALESCE(cadastro_infraestrutura.nome, cadastro_unidade.nome_fantasia) LIKE ?", ["%{$keyword}%"]);
|
||||
})
|
||||
->skipTotalRecords()
|
||||
->make(true);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,16 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\ProntoAtendimento\Fila;
|
||||
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Http\Requests\PainelSenha\ChamadaRequest;
|
||||
use App\Services\ProntoAtendimento\Fila\ChamadaService;
|
||||
use Illuminate\Http\Response;
|
||||
|
||||
class ChamadaController extends Controller
|
||||
{
|
||||
public function store(ChamadaRequest $request)
|
||||
{
|
||||
return response()->json(ChamadaService::store($request), Response::HTTP_CREATED);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,64 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\ProntoAtendimento\Fila;
|
||||
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Http\Requests\PainelSenha\FilaRequest;
|
||||
use App\Services\ProntoAtendimento\Fila\FilaService;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Http\Response;
|
||||
|
||||
class FilaController extends Controller
|
||||
{
|
||||
public function list()
|
||||
{
|
||||
return response()->json(FilaService::list(request()), Response::HTTP_OK);
|
||||
}
|
||||
|
||||
public function index()
|
||||
{
|
||||
$params = request()->all();
|
||||
|
||||
return response()->json(FilaService::index($params), Response::HTTP_OK);
|
||||
}
|
||||
|
||||
public function update(Request $request, $id)
|
||||
{
|
||||
return response()->json(FilaService::update($request, $id), Response::HTTP_OK);
|
||||
}
|
||||
|
||||
public function destroy($id)
|
||||
{
|
||||
return response()->json(FilaService::destroy($id), Response::HTTP_NO_CONTENT);
|
||||
}
|
||||
|
||||
public function answer($id)
|
||||
{
|
||||
return response()->json(FilaService::answer($id), Response::HTTP_OK);
|
||||
}
|
||||
|
||||
public function sendBack($id)
|
||||
{
|
||||
return response()->json(FilaService::sendBack($id), Response::HTTP_OK);
|
||||
}
|
||||
|
||||
public function forward(FilaRequest $request, $id)
|
||||
{
|
||||
return response()->json(FilaService::forward($request, $id), Response::HTTP_OK);
|
||||
}
|
||||
|
||||
public function evade(FilaRequest $request, $id)
|
||||
{
|
||||
return response()->json(FilaService::evade($request, $id), Response::HTTP_OK);
|
||||
}
|
||||
|
||||
public function getAdditionalEnfermagemData($atendimentoId)
|
||||
{
|
||||
return response()->json(FilaService::getAdditionalEnfermagemData($atendimentoId), Response::HTTP_OK);
|
||||
}
|
||||
|
||||
public function getImpressoes($atendimentoId, $setorTipoId)
|
||||
{
|
||||
return response()->json(FilaService::getImpressoes($atendimentoId, $setorTipoId), Response::HTTP_OK);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,27 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\ProntoAtendimento;
|
||||
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Services\ProntoAtendimento\FilaAtendimentoService;
|
||||
use Illuminate\Http\Response;
|
||||
|
||||
class FilaAtendimentoController extends Controller
|
||||
{
|
||||
protected $modulo = 'pronto-atendimento';
|
||||
protected $funcionalidade = 'fila-atendimento';
|
||||
|
||||
public function list()
|
||||
{
|
||||
$this->auth(__FUNCTION__);
|
||||
|
||||
return response()->json(FilaAtendimentoService::list(), Response::HTTP_OK);
|
||||
}
|
||||
|
||||
public function index()
|
||||
{
|
||||
$this->auth(__FUNCTION__);
|
||||
|
||||
return response()->json(FilaAtendimentoService::index(), Response::HTTP_OK);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,26 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\ProntoAtendimento\Impressao;
|
||||
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Services\ProntoAtendimento\Impressao\ImpressaoFaaEletronicaService;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Http\Response;
|
||||
|
||||
class FaaEletronicaController extends Controller
|
||||
{
|
||||
protected $modulo = 'pronto-atendimento';
|
||||
protected $funcionalidade = 'impressao-faa-eletronica';
|
||||
|
||||
public function list()
|
||||
{
|
||||
$this->auth(__FUNCTION__);
|
||||
|
||||
return response()->json(ImpressaoFaaEletronicaService::list(), Response::HTTP_OK);
|
||||
}
|
||||
|
||||
public function datatable(Request $request)
|
||||
{
|
||||
return response()->json(ImpressaoFaaEletronicaService::datatable($request), Response::HTTP_OK);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,36 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\ProntoAtendimento\Impressao;
|
||||
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Services\ProntoAtendimento\Impressao\ImpressaoService;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Http\Response;
|
||||
|
||||
class ImpressaoController extends Controller
|
||||
{
|
||||
protected $modulo = 'pronto-atendimento';
|
||||
protected $funcionalidade = 'impressao';
|
||||
|
||||
public function list()
|
||||
{
|
||||
$this->auth(__FUNCTION__);
|
||||
|
||||
return response()->json(ImpressaoService::list(), Response::HTTP_OK);
|
||||
}
|
||||
|
||||
public function datatable(Request $request)
|
||||
{
|
||||
return response()->json(ImpressaoService::datatable($request), Response::HTTP_OK);
|
||||
}
|
||||
|
||||
public function getAtendimentosAssinados($atendimentoId)
|
||||
{
|
||||
return response()->json(ImpressaoService::getAtendimentosAssinados($atendimentoId), Response::HTTP_OK);
|
||||
}
|
||||
|
||||
public function faturarEnfermagem(Request $request)
|
||||
{
|
||||
return response()->json(ImpressaoService::faturarEnfermagem($request), Response::HTTP_OK);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,535 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\ProntoAtendimento\PacienteBusca;
|
||||
|
||||
use App\Enums\Cadastro\Estabelecimento\SetorTipo;
|
||||
use App\Enums\ProntoAtendimento\Atendimento\Desfecho as DesfechoEnum;
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Models\Cadastro\Estabelecimento\CentroCusto;
|
||||
use App\Models\Cadastro\SujeitoAtencao\Lotacao;
|
||||
use App\Models\PainelSenha\Fila;
|
||||
use App\Models\PainelSenha\FilaHistorico;
|
||||
use App\Models\ProntoAtendimento\Atendimento\Atendimento;
|
||||
use App\Models\ProntoAtendimento\Atendimento\Faa;
|
||||
use App\Models\ProntoAtendimento\Atendimento\FaaReabertura;
|
||||
use App\Services\ProntoAtendimento\Fila\FilaService;
|
||||
use Carbon\Carbon;
|
||||
use Illuminate\Http\Response;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
|
||||
class PacienteBuscaController extends Controller
|
||||
{
|
||||
protected $modulo = 'pronto-atendimento';
|
||||
protected $funcionalidade = 'paciente-busca';
|
||||
|
||||
public function datatable()
|
||||
{
|
||||
$historico = DB::table('pronto_atendimento_atendimento')
|
||||
->select([
|
||||
'cadastro_cidadao.caracteristicas_fisicas',
|
||||
'cadastro_cidadao.nome AS paciente_nome',
|
||||
'cadastro_cidadao.preferencia_nome_id AS preferencia_nome_id',
|
||||
'cadastro_cidadao.nome_social AS nome_social',
|
||||
'cadastro_paciente.prontuario',
|
||||
'cadastro_paciente.sequencial_desconhecido',
|
||||
'pronto_atendimento_faa.id as faa_id',
|
||||
'pronto_atendimento_faa.numero as faa_numero',
|
||||
'pronto_atendimento_faa.deleted_at AS faa_cancelada',
|
||||
'pronto_atendimento_atendimento_procedimento.atendimento_id as procedimento_id',
|
||||
'cadastro_cidadao.nome AS procedimento',
|
||||
DB::raw('DATE_FORMAT(pronto_atendimento_atendimento_recepcao.atendido_em, "%H:%i") AS hora'),
|
||||
DB::raw('DATE_FORMAT(pronto_atendimento_atendimento_recepcao.atendido_em, "%d/%m/%Y") AS data'),
|
||||
DB::raw('
|
||||
(
|
||||
CASE WHEN cadastro_cidadao.nome_mae IS NULL THEN
|
||||
"Não informado"
|
||||
ELSE
|
||||
cadastro_cidadao.nome_mae
|
||||
END
|
||||
) as nome_mae'
|
||||
),
|
||||
DB::raw('
|
||||
(
|
||||
CASE WHEN DATE_FORMAT(cadastro_cidadao.data_nascimento, "%d/%m/%Y") IS NULL THEN
|
||||
"Não informada"
|
||||
ELSE
|
||||
DATE_FORMAT(cadastro_cidadao.data_nascimento, "%d/%m/%Y")
|
||||
END
|
||||
) as data_nascimento
|
||||
'),
|
||||
'cadastro_setor.nome AS setor_atual',
|
||||
DB::raw('
|
||||
(
|
||||
SELECT TRUE
|
||||
FROM painel_senha_fila_historico
|
||||
INNER JOIN cadastro_centro_custo
|
||||
ON cadastro_centro_custo.id = painel_senha_fila_historico.centro_custo_id
|
||||
WHERE painel_senha_fila_historico.fila_id = painel_senha_fila.id
|
||||
AND cadastro_centro_custo.setor_id IN (
|
||||
' . SetorTipo::CONSULTORIO .',
|
||||
' . SetorTipo::ENFERMAGEM .',
|
||||
' . SetorTipo::EXAMES .',
|
||||
' . SetorTipo::OBSERVACAO .'
|
||||
)
|
||||
LIMIT 1
|
||||
) bloqueado
|
||||
'),
|
||||
'pronto_atendimento_faa.finalizado',
|
||||
'pronto_atendimento_faa.cancelado',
|
||||
'painel_senha_fila.centro_custo_id',
|
||||
DB::raw('
|
||||
(
|
||||
CASE WHEN pronto_atendimento_faa.deleted_at IS NOT NULL THEN
|
||||
"FAA EXCLUÍDA"
|
||||
|
||||
WHEN pronto_atendimento_faa.cancelado = 1 THEN
|
||||
"FAA CANCELADA"
|
||||
|
||||
WHEN pronto_atendimento_faa.finalizado = 1 THEN
|
||||
"ATENDIMENTO FINALIZADO"
|
||||
ELSE
|
||||
CASE WHEN cadastro_setor.nome IS NULL THEN
|
||||
"RECEPÇÃO - ATENDIMENTO RETROATIVO"
|
||||
ELSE
|
||||
pronto_atendimento_faa_desfecho.nome
|
||||
END
|
||||
END
|
||||
) AS desfecho
|
||||
'),
|
||||
])
|
||||
->distinct()
|
||||
->join(
|
||||
'pronto_atendimento_faa',
|
||||
'pronto_atendimento_faa.id',
|
||||
'pronto_atendimento_atendimento.faa_id'
|
||||
)
|
||||
->leftJoin (
|
||||
'pronto_atendimento_faa_desfecho',
|
||||
'pronto_atendimento_faa_desfecho.id',
|
||||
'pronto_atendimento_faa.desfecho_id'
|
||||
)
|
||||
->join(
|
||||
'cadastro_centro_custo as centro_custo_atendimento',
|
||||
'centro_custo_atendimento.id',
|
||||
'pronto_atendimento_atendimento.created_centro_custo_id'
|
||||
)
|
||||
->join(
|
||||
'pronto_atendimento_atendimento_recepcao',
|
||||
'pronto_atendimento_atendimento_recepcao.atendimento_id',
|
||||
'pronto_atendimento_atendimento.id'
|
||||
)
|
||||
->join(
|
||||
'cadastro_paciente',
|
||||
'cadastro_paciente.id',
|
||||
'pronto_atendimento_faa.paciente_id'
|
||||
)
|
||||
->join(
|
||||
'cadastro_cidadao',
|
||||
'cadastro_cidadao.id',
|
||||
'cadastro_paciente.cidadao_id'
|
||||
)
|
||||
->leftJoin(
|
||||
'painel_senha_fila',
|
||||
'painel_senha_fila.id',
|
||||
'pronto_atendimento_atendimento.fila_id'
|
||||
)
|
||||
->leftJoin(
|
||||
'cadastro_centro_custo',
|
||||
'cadastro_centro_custo.id',
|
||||
'painel_senha_fila.centro_custo_id'
|
||||
)
|
||||
->leftJoin(
|
||||
'cadastro_setor',
|
||||
'cadastro_setor.id',
|
||||
'cadastro_centro_custo.setor_id'
|
||||
)
|
||||
->leftJoin(
|
||||
'pronto_atendimento_atendimento_procedimento',
|
||||
'pronto_atendimento_atendimento_procedimento.atendimento_id',
|
||||
'pronto_atendimento_atendimento.id'
|
||||
)
|
||||
->where('centro_custo_atendimento.infraestrutura_id', $this->getCentroCustoLogado()->infraestrutura_id);
|
||||
|
||||
if (!request()->get('order')) {
|
||||
$historico->orderByDesc('pronto_atendimento_atendimento_recepcao.atendido_em');
|
||||
}
|
||||
|
||||
return datatables()
|
||||
->of($historico)
|
||||
->filterColumn('data', function ($query, $keyword) {
|
||||
$query->whereRaw("DATE_FORMAT(pronto_atendimento_atendimento_recepcao.atendido_em, '%d/%m/%Y') like ?", ["%{$keyword}%"])
|
||||
->orWhereRaw(
|
||||
"CONCAT(
|
||||
SUBSTR(pronto_atendimento_atendimento_recepcao.atendido_em,9,2),
|
||||
SUBSTR(pronto_atendimento_atendimento_recepcao.atendido_em,6,2),
|
||||
SUBSTR(pronto_atendimento_atendimento_recepcao.atendido_em,1,4)
|
||||
) like ?",
|
||||
["%{$keyword}%"]
|
||||
);
|
||||
})
|
||||
->filterColumn('hora', function ($query, $keyword) {
|
||||
$query->whereRaw("DATE_FORMAT(pronto_atendimento_atendimento_recepcao.atendido_em, '%H:%i') like ?", ["%{$keyword}%"]);
|
||||
})
|
||||
->filterColumn('setor_atual', function ($query, $keyword) {
|
||||
$query->whereRaw('
|
||||
CASE WHEN pronto_atendimento_faa.deleted_at IS NOT NULL THEN
|
||||
"FAA EXCLUÍDA"
|
||||
WHEN pronto_atendimento_faa.finalizado = 1 THEN
|
||||
"ATENDIMENTO FINALIZADO"
|
||||
ELSE
|
||||
cadastro_setor.nome
|
||||
END like ?', ["%{$keyword}%"]
|
||||
);
|
||||
})
|
||||
|
||||
->orderColumn('data', function ($query, $order) {
|
||||
$query->orderBy('pronto_atendimento_atendimento_recepcao.atendido_em', $order);
|
||||
})
|
||||
->orderColumn('hora', function ($query, $order) {
|
||||
$query->orderByRaw('DATE_FORMAT(pronto_atendimento_atendimento_recepcao.atendido_em, "%H:%i") ' . $order);
|
||||
})
|
||||
->orderColumn('setor_atual', function ($query, $order) {
|
||||
$query->orderByRaw( '
|
||||
CASE WHEN pronto_atendimento_faa.deleted_at IS NOT NULL THEN
|
||||
"FAA EXCLUÍDA"
|
||||
WHEN pronto_atendimento_faa.finalizado = 1 THEN
|
||||
"ATENDIMENTO FINALIZADO"
|
||||
ELSE
|
||||
cadastro_setor.nome
|
||||
END ' . $order
|
||||
);
|
||||
})
|
||||
->skipTotalRecords()
|
||||
->make(true);
|
||||
}
|
||||
|
||||
public function create()
|
||||
{
|
||||
return response()->json([
|
||||
'form' => [
|
||||
'centros_custo_encaminhamento' => self::getCentroCustoLogado()->infraestrutura->centrosCusto()
|
||||
|
||||
->whereHas('setor', function ($query) {
|
||||
$query->whereNotIn('tipo_id', [
|
||||
SetorTipo::RECEPCAO
|
||||
]);
|
||||
})
|
||||
->get()
|
||||
->map(fn ($cc) => [
|
||||
'id' => $cc->id,
|
||||
'setor_nome' => $cc->setor->nome
|
||||
])
|
||||
->sortBy('setor_nome')
|
||||
->values(),
|
||||
]
|
||||
], Response::HTTP_OK);
|
||||
}
|
||||
|
||||
public function show($id)
|
||||
{
|
||||
$this->auth(__FUNCTION__);
|
||||
|
||||
$atendimento = Faa::withTrashed()->findOrFail($id)->atendimentos()->withTrashed()->first();
|
||||
$atendimentos = collect();
|
||||
|
||||
$atendimentoExcluido = Faa::withTrashed()->findOrFail($id);
|
||||
|
||||
if ($atendimentoExcluido->trashed()) {
|
||||
|
||||
$centroCusto = CentroCusto::with(['setor'])->findOrFail($atendimentoExcluido->deleted_centro_custo_id);
|
||||
|
||||
if($centroCusto->setor->id == SetorTipo::TRIAGEM){
|
||||
|
||||
$atendimento->atendimentosTriagem->each(fn ($atendimentoTriagem) => $atendimentos->push([
|
||||
'is_observacao' => false,
|
||||
'setor' => $atendimentoTriagem->createdCentroCusto->setor->nome,
|
||||
'data_hora' => $atendimentoTriagem->created_at,
|
||||
'usuario' => Lotacao::find($atendimentoExcluido->deleted_lotacao_id)->usuario->cidadao->nome,
|
||||
'data_exclusao' => $atendimentoExcluido->deleted_at,
|
||||
'cbo' => $this->retornaCbo($atendimentoExcluido->deleted_lotacao_id),
|
||||
]));
|
||||
|
||||
} else if ($centroCusto->setor->id == SetorTipo::RECEPCAO){
|
||||
|
||||
$usuario = Lotacao::find($atendimento->created_lotacao_id)->usuario->cidadao->nome;
|
||||
|
||||
$atendimentos->push([
|
||||
'is_observacao' => false,
|
||||
'setor' => 'RECEPÇÃO',
|
||||
'data_hora' => new Carbon($atendimento->recepcao->atendido_em),
|
||||
'usuario' => $usuario,
|
||||
'cbo' => $this->retornaCbo($atendimentoExcluido->deleted_lotacao_id),
|
||||
'data_exclusao' => $atendimentoExcluido->deleted_at,
|
||||
]);
|
||||
}
|
||||
|
||||
} else {
|
||||
|
||||
if ($atendimento->recepcao) {
|
||||
|
||||
$lotacaoLocal = Lotacao::find($atendimento->updated_lotacao_id);
|
||||
$atendimentos->push(collect([
|
||||
'is_observacao' => false,
|
||||
'setor' => is_null($atendimento->fila)
|
||||
? 'RECEPÇÃO - ATENDIMENTO RETROATIVO'
|
||||
: $atendimento->recepcao->createdCentroCusto->setor->nome,
|
||||
'data_hora' => new Carbon($atendimento->recepcao->atendido_em),
|
||||
'usuario' => $lotacaoLocal->usuario->cidadao->nome ?? null,
|
||||
'cbo' => $lotacaoLocal->ocupacao->nome ?? null,
|
||||
]));
|
||||
}
|
||||
}
|
||||
|
||||
$atendimento->atendimentosTriagem->each(fn ($atendimentoTriagem) => $atendimentos->push([
|
||||
'is_observacao' => false,
|
||||
'setor' => $atendimentoTriagem->createdCentroCusto->setor->nome,
|
||||
'data_hora' => $atendimentoTriagem->created_at,
|
||||
'usuario' => Lotacao::find($atendimentoTriagem->updated_lotacao_id)->usuario->cidadao->nome,
|
||||
'cbo' => Lotacao::find($atendimentoTriagem->updated_lotacao_id)->ocupacao->nome,
|
||||
]));
|
||||
|
||||
$atendimento->atendimentosMedico->each(fn ($atendimentoMedico) => $atendimentos->push([
|
||||
'is_observacao' => false,
|
||||
'setor' => $atendimentoMedico->createdCentroCusto->setor->nome,
|
||||
'data_hora' => $atendimentoMedico->created_at,
|
||||
'usuario' => Lotacao::find($atendimentoMedico->updated_lotacao_id)->usuario->cidadao->nome,
|
||||
'cbo' => Lotacao::find($atendimentoMedico->updated_lotacao_id)->ocupacao->nome,
|
||||
]));
|
||||
|
||||
$atendimento->atendimentosEnfermagem->each(fn ($atendimentoEnfermagem) => $atendimentos->push([
|
||||
'is_observacao' => false,
|
||||
'setor' => $atendimentoEnfermagem->automatico ? 'ENFERMAGEM' : $atendimentoEnfermagem->createdCentroCusto->setor->nome,
|
||||
'data_hora' => $atendimentoEnfermagem->created_at,
|
||||
'usuario' => Lotacao::find($atendimentoEnfermagem->updated_lotacao_id)->usuario->cidadao->nome ?? null,
|
||||
'cbo' => Lotacao::find($atendimentoEnfermagem->updated_lotacao_id)->ocupacao->nome ?? null,
|
||||
]));
|
||||
|
||||
$atendimento->atendimentosExameImagem->each(fn ($atendimentoExameImagem) => $atendimentos->push([
|
||||
'is_observacao' => false,
|
||||
'setor' => $atendimentoExameImagem->createdCentroCusto->setor->nome,
|
||||
'data_hora' => $atendimentoExameImagem->created_at,
|
||||
'usuario' => Lotacao::find($atendimentoExameImagem->updated_lotacao_id)->usuario->cidadao->nome,
|
||||
'cbo' => Lotacao::find($atendimentoExameImagem->updated_lotacao_id)->ocupacao->nome,
|
||||
]));
|
||||
|
||||
$atendimento->pacienteObservacoes->each(fn ($atendimentoObservacao) => $atendimentos->push([
|
||||
'is_observacao' => true,
|
||||
'setor' => $atendimentoObservacao->createdCentroCusto->setor->nome,
|
||||
'data_hora' => $atendimentoObservacao->created_at,
|
||||
]));
|
||||
|
||||
if (isset($atendimento->fila->historico)) {
|
||||
|
||||
$atendimento->fila->historico->each(function ($historico) use ($atendimentos) {
|
||||
|
||||
if ($historico->evadido) {
|
||||
$atendimentos->push([
|
||||
'is_observacao' => false,
|
||||
'setor' => 'EVASÃO',
|
||||
'data_hora' => $historico->created_at,
|
||||
'usuario' => Lotacao::find($historico->created_lotacao_id)->usuario->cidadao->nome,
|
||||
'motivo_evasao' => $historico->motivo_evasao,
|
||||
'cbo' => Lotacao::find($historico->created_lotacao_id)->ocupacao->nome,
|
||||
]);
|
||||
} else {
|
||||
if ($atendimentos->last()['setor'] == 'EVASÃO') {
|
||||
$atendimentos->push([
|
||||
'is_observacao' => false,
|
||||
'setor' => 'CANCELAMENTO DA EVASÃO',
|
||||
'data_hora' => $historico->created_at,
|
||||
'usuario' => Lotacao::find($historico->created_lotacao_id)->usuario->cidadao->nome,
|
||||
'motivo_cancelamento_evasao' => $historico->motivo_cancelamento_evasao,
|
||||
'cbo' => Lotacao::find($historico->created_lotacao_id)->ocupacao->nome,
|
||||
]);
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
if ($atendimento->fila && !$atendimento->faa->finalizado) {
|
||||
|
||||
$lotacaoLocal = Lotacao::find($atendimento->created_lotacao_id);
|
||||
$atendimentos->push([
|
||||
'is_observacao' => false,
|
||||
'setor' => $atendimento->fila->centroCusto->setor->nome,
|
||||
'data_hora' => $atendimento->fila->updated_at,
|
||||
]);
|
||||
|
||||
} elseif (!$atendimento->fila) {
|
||||
|
||||
if ($atendimentoExcluido->deleted_centro_custo_id) {
|
||||
|
||||
$centroCusto = CentroCusto::with(['setor'])->findOrFail($atendimentoExcluido->deleted_centro_custo_id);
|
||||
|
||||
$novoAtendimento = [
|
||||
'is_observacao' => false,
|
||||
'data_hora' => new Carbon($atendimento->recepcao->atendido_em),
|
||||
'usuario' => Lotacao::find($atendimentoExcluido->deleted_lotacao_id)->usuario->cidadao->nome,
|
||||
'cbo' => Lotacao::find($atendimentoExcluido->deleted_lotacao_id)->ocupacao->nome,
|
||||
];
|
||||
|
||||
$setoresOrigemRecepcao = collect([
|
||||
SetorTipo::TRIAGEM,
|
||||
SetorTipo::CONSULTORIO,
|
||||
SetorTipo::ENFERMAGEM,
|
||||
SetorTipo::EXAMES,
|
||||
SetorTipo::ADMINISTRACAO,
|
||||
SetorTipo::OBSERVACAO
|
||||
]);
|
||||
|
||||
if ($setoresOrigemRecepcao->contains($centroCusto->setor->id)) {
|
||||
$novoAtendimento['setor'] = 'RECEPÇÃO';
|
||||
$novoAtendimento['usuario'] = Lotacao::find($atendimento->created_lotacao_id)->usuario->cidadao->nome;
|
||||
$novoAtendimento['cbo'] = $this->retornaCbo($atendimento->created_lotacao_id);
|
||||
} else if ($centroCusto->setor->id == SetorTipo::RECEPCAO) {
|
||||
|
||||
$novoAtendimento['setor'] = 'TRIAGEM';
|
||||
$novoAtendimento['usuario'] = Lotacao::find($atendimento->created_lotacao_id)->usuario->cidadao->nome;
|
||||
$novoAtendimento['cbo'] = $this->retornaCbo($atendimento->created_lotacao_id);
|
||||
}
|
||||
|
||||
$atendimentos->prepend($novoAtendimento);
|
||||
|
||||
$atendimentos = $atendimentos->sortBy(function ($item) {
|
||||
return $item['setor'];
|
||||
});
|
||||
|
||||
$atendimentos->push([
|
||||
'is_observacao' => false,
|
||||
'setor' => 'FAA EXCLUÍDA',
|
||||
'data_hora' => $atendimentoExcluido->deleted_at,
|
||||
'usuario' => Lotacao::find($atendimentoExcluido->deleted_lotacao_id)->usuario->cidadao->nome,
|
||||
'data_exclusao' => $atendimentoExcluido->deleted_at,
|
||||
'cbo' => Lotacao::find($atendimentoExcluido->deleted_lotacao_id)->ocupacao->nome,
|
||||
]);
|
||||
}
|
||||
} elseif ($atendimento->faa->finalizado && !$atendimento->faa->cancelado){
|
||||
|
||||
if($atendimento->faa->desfecho_id != DesfechoEnum::EVASAO){
|
||||
$atendimentos->push([
|
||||
'is_observacao' => false,
|
||||
'setor' => 'ATENDIMENTO FINALIZADO',
|
||||
'data_hora' => $atendimento->faa->updated_at,
|
||||
'usuario' => Lotacao::find($atendimento->faa->updated_lotacao_id)->usuario->cidadao->nome,
|
||||
'cbo' => $this->retornaCbo($atendimento->faa->updated_lotacao_id),
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
||||
if ($atendimento->faa->cancelado){
|
||||
$atendimentos->push([
|
||||
'is_observacao' => false,
|
||||
'setor' => 'FAA CANCELADA',
|
||||
'data_hora' => $atendimento->faa->updated_at,
|
||||
'usuario' => Lotacao::find($atendimento->faa->updated_lotacao_id)->usuario->cidadao->nome,
|
||||
'cbo' => $this->retornaCbo($atendimento->faa->updated_lotacao_id),
|
||||
'motivo_cancelamento' => $atendimento->faa->motivo_cancelamento,
|
||||
]);
|
||||
}
|
||||
|
||||
|
||||
$faaReaberturas = FaaReabertura::with('createdLotacao.usuario.cidadao') // Eager loading
|
||||
->where('faa_id', $id)
|
||||
->get();
|
||||
|
||||
foreach ($faaReaberturas as $reabertura) {
|
||||
$atendimentos->push([
|
||||
'is_observacao' => false,
|
||||
'setor' => 'FAA REABERTA',
|
||||
'data_hora' => $reabertura->created_at,
|
||||
'usuario' => $reabertura->createdLotacao->usuario->cidadao->nome,
|
||||
'cbo' => $reabertura->createdLotacao->ocupacao->nome
|
||||
]);
|
||||
}
|
||||
|
||||
$isObservacao = false;
|
||||
|
||||
$atendimentos = $atendimentos
|
||||
->sortBy(function ($atendimento) {
|
||||
return $atendimento['data_hora']->format('Y-m-d H:i') . ($atendimento['setor'] === 'FAA REABERTA' ? 'a' : 'b');
|
||||
})
|
||||
->values();
|
||||
|
||||
$lastIndex = $atendimentos->count() - 1;
|
||||
|
||||
$atendimentos = $atendimentos->map(function ($atendimento, $index) use (&$isObservacao, $lastIndex) {
|
||||
|
||||
if ($atendimento['is_observacao']) {
|
||||
$isObservacao = true;
|
||||
}
|
||||
|
||||
$isLastEntry = $index === $lastIndex;
|
||||
|
||||
$usuarioIsEmpty = empty($atendimento['usuario']);
|
||||
$cboIsEmpty = empty($atendimento['cbo']);
|
||||
|
||||
if ($isLastEntry || (!$usuarioIsEmpty && !$cboIsEmpty)) {
|
||||
return [
|
||||
'setor' => $atendimento['setor'] . ($isObservacao ? ' (OBSERVAÇÃO)' : ''),
|
||||
'data' => $atendimento['data_hora']->format('d/m/Y'),
|
||||
'hora' => $atendimento['data_hora']->format('H:i'),
|
||||
'evadido' => isset($atendimento['evadido']) && $atendimento['evadido'] == 1 ? 'Sim' : 'Não',
|
||||
'motivo_evasao' => $atendimento['motivo_evasao'] ?? null,
|
||||
'motivo_cancelamento_evasao' => $atendimento['motivo_cancelamento_evasao'] ?? null,
|
||||
'usuario' => $atendimento['usuario'] ?? '-',
|
||||
'cbo' => $atendimento['cbo'] ?? '-',
|
||||
'data_exclusao' => isset($atendimento['data_exclusao']) ? $atendimento['data_exclusao']->format('d/m/Y') : null,
|
||||
'hora_exclusao' => isset($atendimento['data_exclusao']) ? $atendimento['data_exclusao']->format('H:i') : null,
|
||||
'motivo_cancelamento' => $atendimento['motivo_cancelamento'] ?? null,
|
||||
];
|
||||
}
|
||||
|
||||
return null;
|
||||
});
|
||||
|
||||
$atendimentos = $atendimentos->filter()->values();
|
||||
|
||||
return response()->json($atendimentos, Response::HTTP_OK);
|
||||
}
|
||||
|
||||
private function retornaCbo($lotacaoId) {
|
||||
return Lotacao::find($lotacaoId)->ocupacao->nome;
|
||||
}
|
||||
|
||||
public function realocar($id)
|
||||
{
|
||||
$this->auth(__FUNCTION__);
|
||||
|
||||
$faa = Faa::findOrFail($id);
|
||||
|
||||
DB::transaction(function () use ($faa) {
|
||||
|
||||
$fila = $faa->atendimentos()->first()->fila;
|
||||
|
||||
FilaService::forward([
|
||||
'centro_custo_id_para' => request()->centro_custo_id,
|
||||
], $fila->id);
|
||||
});
|
||||
|
||||
return response()->json($faa->fresh(), Response::HTTP_OK);
|
||||
}
|
||||
|
||||
public function destroy($id)
|
||||
{
|
||||
$this->auth(__FUNCTION__);
|
||||
|
||||
$atendimento = Atendimento::where('faa_id', $id)->firstOrFail();
|
||||
|
||||
DB::transaction(function () use ($atendimento) {
|
||||
|
||||
Faa::findOrFail($atendimento->faa_id)->delete();
|
||||
|
||||
if($atendimento->fila_id !== null){
|
||||
|
||||
Fila::findOrFail($atendimento->fila_id)->delete();
|
||||
}
|
||||
});
|
||||
|
||||
return response()->json(null, Response::HTTP_NO_CONTENT);
|
||||
}
|
||||
|
||||
private function getCentroCustoLogado()
|
||||
{
|
||||
return CentroCusto::findOrFail(auth()->payload()->get('centro_custo_id'));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,223 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\ProntoAtendimento\Parametrizacao;
|
||||
|
||||
use App\Enums\Sigtap\Ocupacao;
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Http\Requests\ProntoAtendimento\Parametrizacao\ParametrizacaoRequest;
|
||||
use App\Models\Cadastro\Estabelecimento\Unidade;
|
||||
use App\Models\Cadastro\SujeitoAtencao\Usuario;
|
||||
use App\Models\ProntoAtendimento\Atendimento\Medico\AtendimentoMedicoTipo;
|
||||
use App\Models\ProntoAtendimento\Parametrizacao\AtendimentoMedico;
|
||||
use App\Models\ProntoAtendimento\Parametrizacao\AtendimentoMedicoTipo as ParametrizacaoAtendimentoMedicoTipo;
|
||||
use App\Models\ProntoAtendimento\Parametrizacao\FaturamentoExameLaboratorial;
|
||||
use App\Models\ProntoAtendimento\Parametrizacao\Parametrizacao;
|
||||
use App\Models\ProntoAtendimento\Parametrizacao\ServicoEnfermagem;
|
||||
use App\Services\Sigtap\ProcedimentoService;
|
||||
use App\Utils\DataUtil;
|
||||
use DB;
|
||||
use Illuminate\Http\Response;
|
||||
|
||||
class ParametrizacaoController extends Controller
|
||||
{
|
||||
protected $modulo = 'pronto-atendimento';
|
||||
protected $funcionalidade = 'parametrizacao';
|
||||
|
||||
public function autocompleteServicoEnfermagem()
|
||||
{
|
||||
$procedimento = new ProcedimentoService([
|
||||
'only_servicos_enfermagem' => true,
|
||||
'search_by_apelido' => DataUtil::isStringTrue(request()->query('search_by_apelido')),
|
||||
]);
|
||||
|
||||
return datatables()->of($procedimento->getProcedimentosBuilder())->toJson();
|
||||
}
|
||||
|
||||
public function create()
|
||||
{
|
||||
$this->auth(__FUNCTION__);
|
||||
|
||||
$parametrizacao = Parametrizacao::first();
|
||||
|
||||
return response()->json(
|
||||
[
|
||||
'form' => $this->getFormData(),
|
||||
'model' => [
|
||||
'servicos_enfermagem' => ServicoEnfermagem::all(),
|
||||
'atendimento_medico' => $this->getAtendimentoMedicoModel(),
|
||||
'faturamento_automatico_enfermagem' => $parametrizacao->faturamento_automatico_enfermagem ?? false,
|
||||
'assinatura_eletronica' => $parametrizacao->assinatura_eletronica ?? false,
|
||||
'lotacoes_exame_laboratorial' => FaturamentoExameLaboratorial::all()->map(fn($param) => [
|
||||
'lotacao_id' => $param->lotacao_id,
|
||||
'usuario_nome' => $param->lotacao()->withTrashed()->first()->usuario->cidadao->nome,
|
||||
'unidade_nome_fantasia' => $param->lotacao()->withTrashed()->first()->infraestrutura->unidade->nome_fantasia,
|
||||
'infraestrutura_nome' => $param->lotacao()->withTrashed()->first()->infraestrutura->nome,
|
||||
'ocupacao_descricao' => $param->lotacao()->withTrashed()->first()->ocupacao->codigo . ' - '
|
||||
. $param->lotacao()->withTrashed()->first()->ocupacao->nome
|
||||
]),
|
||||
'tempo_adicional_plantao' => $parametrizacao->tempo_adicional_plantao ?? null,
|
||||
],
|
||||
'additionals' => $this->getAdditionalsData()
|
||||
],
|
||||
Response::HTTP_OK
|
||||
);
|
||||
}
|
||||
|
||||
public function getOcupacoes($infraestruturaId, $usuarioId)
|
||||
{
|
||||
$ocupacoes = Usuario::findOrFail($usuarioId)->lotacoes()
|
||||
->where('infraestrutura_id', $infraestruturaId)
|
||||
->get()
|
||||
->map(fn ($lotacao) => [
|
||||
'lotacao_id' => $lotacao->id,
|
||||
'descricao' => $lotacao->ocupacao->codigo . " - " . $lotacao->ocupacao->nome,
|
||||
])
|
||||
->sortBy('descricao')
|
||||
->values();
|
||||
|
||||
return response()->json($ocupacoes, Response::HTTP_OK);
|
||||
}
|
||||
|
||||
private function getFormData()
|
||||
{
|
||||
return [
|
||||
'atendimento_medico' => [
|
||||
'tipos' => AtendimentoMedicoTipo::orderBy('nome')->get(),
|
||||
],
|
||||
'unidades' => Unidade::orderBy('nome_fantasia')
|
||||
->get()
|
||||
->map(fn ($query) => [
|
||||
'id' => $query->id,
|
||||
'nome_fantasia' => $query->nome_fantasia,
|
||||
'infraestruturas' => $query->infraestruturas
|
||||
->map(fn ($query) => [
|
||||
'id' => $query->id,
|
||||
'nome' => $query->nome,
|
||||
])
|
||||
->sortBy('nome')
|
||||
->values(),
|
||||
]),
|
||||
];
|
||||
}
|
||||
|
||||
private function getAdditionalsData()
|
||||
{
|
||||
return [
|
||||
'servicos_enfermagem' => [
|
||||
'cbos_permitidos' => [
|
||||
Ocupacao::ENFERMEIRO,
|
||||
Ocupacao::TECNICO_ENFERMAGEM,
|
||||
Ocupacao::AUXILIAR_ENFERMAGEM,
|
||||
]
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
private function getAtendimentoMedicoModel()
|
||||
{
|
||||
$parametrizacao = AtendimentoMedico::first();
|
||||
|
||||
return [
|
||||
'procedimento_padrao' => $parametrizacao->procedimento_padrao ?? null,
|
||||
'tipos' => ParametrizacaoAtendimentoMedicoTipo::all()
|
||||
->map(fn ($tipo) => [
|
||||
'tipo' => [
|
||||
'id' => $tipo->tipo->id,
|
||||
'nome' => $tipo->tipo->nome,
|
||||
],
|
||||
'unidade' => [
|
||||
'id' => $tipo->infraestrutura->unidade->id,
|
||||
'nome_fantasia' => $tipo->infraestrutura->unidade->nome_fantasia,
|
||||
'infraestrutura' => [
|
||||
'id' => $tipo->infraestrutura->id,
|
||||
'nome' => $tipo->infraestrutura->nome,
|
||||
],
|
||||
],
|
||||
]),
|
||||
];
|
||||
}
|
||||
|
||||
public function store(ParametrizacaoRequest $request)
|
||||
{
|
||||
$this->auth(__FUNCTION__);
|
||||
|
||||
DB::transaction(function () use ($request) {
|
||||
|
||||
$this->saveServicosEnfermagem($request);
|
||||
$this->saveAtendimentoMedico($request);
|
||||
$this->saveParametrizacao($request);
|
||||
$this->saveLotacoesExameLaboratorial($request);
|
||||
});
|
||||
|
||||
return response()->json(null, Response::HTTP_OK);
|
||||
}
|
||||
|
||||
private function saveServicosEnfermagem($request)
|
||||
{
|
||||
$ids = [];
|
||||
|
||||
foreach ($request->servicos_enfermagem as $params) {
|
||||
|
||||
$tipo = ServicoEnfermagem::where('procedimento_codigo', $params['procedimento_codigo'])
|
||||
->first() ?? new ServicoEnfermagem();
|
||||
|
||||
$tipo->fill($params);
|
||||
$tipo->save();
|
||||
|
||||
$ids[] = $tipo->id;
|
||||
}
|
||||
|
||||
ServicoEnfermagem::destroy(ServicoEnfermagem::whereNotIn('id', $ids)->pluck('id'));
|
||||
}
|
||||
|
||||
private function saveAtendimentoMedico($request)
|
||||
{
|
||||
$atendimentoMedico = AtendimentoMedico::first() ?? new AtendimentoMedico();
|
||||
$atendimentoMedico->fill($request->atendimento_medico);
|
||||
$atendimentoMedico->save();
|
||||
|
||||
$ids = [];
|
||||
|
||||
foreach ($request->atendimento_medico['tipos'] as $params) {
|
||||
|
||||
$tipo = ParametrizacaoAtendimentoMedicoTipo::where('infraestrutura_id', $params['infraestrutura_id'])
|
||||
->first() ?? new ParametrizacaoAtendimentoMedicoTipo();
|
||||
|
||||
$tipo->fill($params);
|
||||
$tipo->save();
|
||||
|
||||
$ids[] = $tipo->id;
|
||||
}
|
||||
|
||||
ParametrizacaoAtendimentoMedicoTipo::destroy(
|
||||
ParametrizacaoAtendimentoMedicoTipo::whereNotIn('id', $ids)->pluck('id')
|
||||
);
|
||||
}
|
||||
|
||||
private function saveParametrizacao($request)
|
||||
{
|
||||
$paramatrizacao = Parametrizacao::first();
|
||||
|
||||
if (is_null($paramatrizacao)) {
|
||||
|
||||
Parametrizacao::create($request->all());
|
||||
}
|
||||
else {
|
||||
|
||||
$paramatrizacao->update($request->all());
|
||||
}
|
||||
}
|
||||
|
||||
private function saveLotacoesExameLaboratorial($request)
|
||||
{
|
||||
$ids = [];
|
||||
|
||||
foreach ($request->lotacoes_exame_laboratorial as $lotacaoId) {
|
||||
|
||||
$ids[] = (FaturamentoExameLaboratorial::where('lotacao_id', $lotacaoId)
|
||||
->first() ?? FaturamentoExameLaboratorial::create(['lotacao_id' => $lotacaoId]))->id;
|
||||
}
|
||||
|
||||
FaturamentoExameLaboratorial::destroy(FaturamentoExameLaboratorial::whereNotIn('id', $ids)->pluck('id'));
|
||||
}
|
||||
}
|
||||
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,30 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\ProntoAtendimento\PedidoExame;
|
||||
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Http\Requests\ProntoAtendimento\PedidoExame\LaudoRequest;
|
||||
use App\Services\ProntoAtendimento\PedidoExame\LaudoService;
|
||||
use Illuminate\Http\Response;
|
||||
use Illuminate\Support\Facades\Hash;
|
||||
|
||||
class LaudoController extends Controller
|
||||
{
|
||||
public function destroy($id)
|
||||
{
|
||||
$this->auth(__FUNCTION__);
|
||||
|
||||
$laudoService = new LaudoService();
|
||||
|
||||
return response()->json($laudoService->destroy($id), Response::HTTP_NO_CONTENT);
|
||||
}
|
||||
|
||||
public function download($id)
|
||||
{
|
||||
$laudoService = new LaudoService();
|
||||
|
||||
$download = $laudoService->download($id, request()->hash);
|
||||
|
||||
return response()->download($download['path'], $download['nome'], $download['headers']);
|
||||
}
|
||||
}
|
||||
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,27 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\ProntoAtendimento\Plantao;
|
||||
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Services\ProntoAtendimento\Plantao\RelatorioPlantaoService;
|
||||
use Illuminate\Http\Response;
|
||||
|
||||
class RelatorioPlantaoController extends Controller
|
||||
{
|
||||
protected $modulo = 'pronto-atendimento';
|
||||
protected $funcionalidade = 'relatorio-plantao';
|
||||
|
||||
public function index()
|
||||
{
|
||||
$this->auth(__FUNCTION__);
|
||||
|
||||
return response()->json(RelatorioPlantaoService::index(), Response::HTTP_OK);
|
||||
}
|
||||
|
||||
public function list()
|
||||
{
|
||||
$this->auth(__FUNCTION__);
|
||||
|
||||
return response()->json(RelatorioPlantaoService::list(), Response::HTTP_OK);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,187 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\ProntoAtendimento\ReaberturaAtendimento;
|
||||
|
||||
use App\Enums\Cadastro\Estabelecimento\SetorTipo;
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Models\Cadastro\Estabelecimento\CentroCusto;
|
||||
use App\Models\Cadastro\SujeitoAtencao\Lotacao;
|
||||
use App\Models\ProntoAtendimento\Atendimento\FaaReabertura;
|
||||
use App\Models\ProntoAtendimento\ReaberturaAtendimento\ReaberturaAtendimento;
|
||||
use App\Services\ProntoAtendimento\Fila\FilaService;
|
||||
use Carbon\Carbon;
|
||||
use Illuminate\Http\Response;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
|
||||
class ReaberturaAtendimentoController extends Controller
|
||||
{
|
||||
protected $modulo = 'pronto-atendimento';
|
||||
protected $funcionalidade = 'reabertura-atendimento';
|
||||
|
||||
public function datatable()
|
||||
{
|
||||
$atendimentos = DB::table('pronto_atendimento_atendimento')
|
||||
->select([
|
||||
'cadastro_cidadao.caracteristicas_fisicas',
|
||||
'cadastro_cidadao.nome AS paciente_nome',
|
||||
'cadastro_sexo.descricao AS sexo',
|
||||
'cadastro_paciente.prontuario',
|
||||
'cadastro_paciente.sequencial_desconhecido',
|
||||
'pronto_atendimento_faa.id as faa_id',
|
||||
'pronto_atendimento_faa.numero as faa_numero',
|
||||
DB::raw('DATE_FORMAT(pronto_atendimento_atendimento_recepcao.atendido_em, "%d/%m/%Y") AS data'),
|
||||
DB::raw('
|
||||
(
|
||||
CASE WHEN cadastro_cidadao.nome_mae IS NULL THEN
|
||||
"Não informado"
|
||||
ELSE
|
||||
cadastro_cidadao.nome_mae
|
||||
END
|
||||
) as nome_mae'
|
||||
),
|
||||
DB::raw('
|
||||
(
|
||||
CASE WHEN DATE_FORMAT(cadastro_cidadao.data_nascimento, "%d/%m/%Y") IS NULL THEN
|
||||
"Não informada"
|
||||
ELSE
|
||||
DATE_FORMAT(cadastro_cidadao.data_nascimento, "%d/%m/%Y")
|
||||
END
|
||||
) as data_nascimento
|
||||
'),
|
||||
])
|
||||
->join(
|
||||
'pronto_atendimento_faa',
|
||||
'pronto_atendimento_faa.id',
|
||||
'pronto_atendimento_atendimento.faa_id'
|
||||
)
|
||||
->join(
|
||||
'pronto_atendimento_atendimento_recepcao',
|
||||
'pronto_atendimento_atendimento_recepcao.atendimento_id',
|
||||
'pronto_atendimento_atendimento.id'
|
||||
)
|
||||
->join(
|
||||
'cadastro_paciente',
|
||||
'cadastro_paciente.id',
|
||||
'pronto_atendimento_faa.paciente_id'
|
||||
)
|
||||
->join(
|
||||
'cadastro_cidadao',
|
||||
'cadastro_cidadao.id',
|
||||
'cadastro_paciente.cidadao_id'
|
||||
)
|
||||
->join(
|
||||
'cadastro_sexo',
|
||||
'cadastro_sexo.id',
|
||||
'cadastro_cidadao.sexo_id'
|
||||
)
|
||||
->join(
|
||||
'cadastro_centro_custo',
|
||||
'cadastro_centro_custo.id',
|
||||
'pronto_atendimento_atendimento.created_centro_custo_id'
|
||||
)
|
||||
->where('pronto_atendimento_faa.finalizado', true)
|
||||
->whereNull('pronto_atendimento_faa.deleted_at')
|
||||
->where('cadastro_centro_custo.infraestrutura_id', $this->getCentroCustoLogado()->infraestrutura_id);
|
||||
|
||||
if (!request()->get('order')) {
|
||||
$atendimentos->orderByDesc('pronto_atendimento_atendimento_recepcao.atendido_em');
|
||||
}
|
||||
|
||||
return datatables()
|
||||
->of($atendimentos)
|
||||
->filterColumn('data', function ($query, $keyword) {
|
||||
$query->whereRaw("DATE_FORMAT(pronto_atendimento_atendimento_recepcao.atendido_em, '%d/%m/%Y') like ?", ["%{$keyword}%"])
|
||||
->orWhereRaw(
|
||||
"CONCAT(
|
||||
SUBSTR(pronto_atendimento_atendimento_recepcao.atendido_em,9,2),
|
||||
SUBSTR(pronto_atendimento_atendimento_recepcao.atendido_em,6,2),
|
||||
SUBSTR(pronto_atendimento_atendimento_recepcao.atendido_em,1,4)
|
||||
) like ?",
|
||||
["%{$keyword}%"]
|
||||
);
|
||||
})
|
||||
->orderColumn('data', function ($query, $order) {
|
||||
$query->orderBy('pronto_atendimento_atendimento_recepcao.atendido_em', $order);
|
||||
})
|
||||
->skipTotalRecords()
|
||||
->make(true);
|
||||
}
|
||||
|
||||
public function create()
|
||||
{
|
||||
return response()->json([
|
||||
'form' => [
|
||||
'centros_custo_encaminhamento' => self::getCentroCustoLogado()->infraestrutura->centrosCusto()
|
||||
->whereHas('setor', function ($query) {
|
||||
$query->whereNotIn('tipo_id', [
|
||||
SetorTipo::RECEPCAO,
|
||||
SetorTipo::TRIAGEM,
|
||||
]);
|
||||
})
|
||||
->get()
|
||||
->map(fn ($cc) => [
|
||||
'id' => $cc->id,
|
||||
'setor_nome' => $cc->setor->nome
|
||||
])
|
||||
->sortBy('setor_nome')
|
||||
->values(),
|
||||
]
|
||||
], Response::HTTP_OK);
|
||||
}
|
||||
|
||||
public function update($id)
|
||||
{
|
||||
$this->auth(__FUNCTION__);
|
||||
|
||||
$faa = ReaberturaAtendimento::findOrFail($id);
|
||||
|
||||
$reabertura = new FaaReabertura;
|
||||
$reabertura->faa_id = $id;
|
||||
$reabertura->save();
|
||||
|
||||
DB::transaction(function () use ($faa) {
|
||||
|
||||
if (is_null(request()->centro_custo_id)) {
|
||||
|
||||
$faa->update([
|
||||
'finalizado' => false,
|
||||
'reaberto_em' => Carbon::Now(),
|
||||
'reabertura_usuario_id' => Lotacao::find(auth()->payload()->get('lotacao_id'))->usuario_id,
|
||||
]);
|
||||
}
|
||||
else {
|
||||
|
||||
$faa->update([
|
||||
'desfecho_id' => null,
|
||||
'finalizado' => false,
|
||||
'reaberto_em' => Carbon::Now(),
|
||||
'reabertura_usuario_id' => Lotacao::find(auth()->payload()->get('lotacao_id'))->usuario_id,
|
||||
]);
|
||||
|
||||
|
||||
$fila = $faa->atendimentos()->first()->fila;
|
||||
|
||||
if ($fila !== null) {
|
||||
|
||||
$fila->update([
|
||||
'finalizado' => false,
|
||||
'evadido' => false,
|
||||
'reaberto_em' => Carbon::now(),
|
||||
'reabertura_lotacao_id' => auth()->payload()->get('lotacao_id'),
|
||||
]);
|
||||
|
||||
FilaService::forward([
|
||||
'centro_custo_id_para' => request()->centro_custo_id,
|
||||
], $fila->id);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
return response()->json($faa->fresh(), Response::HTTP_OK);
|
||||
}
|
||||
|
||||
private function getCentroCustoLogado()
|
||||
{
|
||||
return CentroCusto::findOrFail(auth()->payload()->get('centro_custo_id'));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,117 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\ProntoAtendimento\RegularizacaoCadastro;
|
||||
|
||||
use App\Enums\Cadastro\SujeitoAtencao\Classificacao;
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Models\Cadastro\Estabelecimento\CentroCusto;
|
||||
use App\Models\Cadastro\Parametrizacao\ParametrizacaoPermissaoUsuario;
|
||||
use App\Models\Cadastro\SujeitoAtencao\PacienteClassificacao;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
|
||||
class RegularizacaoCadastroController extends Controller
|
||||
{
|
||||
protected $modulo = 'pronto-atendimento';
|
||||
protected $funcionalidade = 'regularizacao-cadastro';
|
||||
|
||||
public function datatable()
|
||||
{
|
||||
$atendimentos = DB::table('cadastro_paciente as paciente')
|
||||
->select([
|
||||
'cidadao.caracteristicas_fisicas',
|
||||
'cidadao.nome',
|
||||
'faa.id as faa_id',
|
||||
'faa.numero as faa_numero',
|
||||
'paciente.id as id',
|
||||
'paciente.prontuario',
|
||||
'paciente.classificacao_id',
|
||||
'paciente.sequencial_desconhecido',
|
||||
'sexo.descricao as sexo',
|
||||
DB::raw('DATE_FORMAT(COALESCE(paciente.sem_documentos_em, paciente.sequencial_desconhecido_em), "%d/%m/%Y") as data'),
|
||||
DB::raw('IF (cidadao.data_nascimento IS NULL, "Não informada", DATE_FORMAT(cidadao.data_nascimento, "%d/%m/%Y")) as data_nascimento'),
|
||||
DB::raw('IF (cidadao.nome_mae IS NULL, "Não informado", cidadao.nome_mae) as nome_mae'),
|
||||
])
|
||||
->join('cadastro_cidadao as cidadao', 'cidadao.id', 'paciente.cidadao_id')
|
||||
->join('cadastro_sexo as sexo', 'sexo.id', 'cidadao.sexo_id')
|
||||
->join('cadastro_centro_custo as centro_custo', 'centro_custo.id', 'paciente.created_centro_custo_id')
|
||||
->leftJoin('pronto_atendimento_faa as faa', 'faa.paciente_id', 'paciente.id')
|
||||
->where('centro_custo.infraestrutura_id', $this->getCentroCustoLogado()->infraestrutura_id)
|
||||
->where(function ($query) {
|
||||
$query->whereNotNull('paciente.sem_documentos_em')
|
||||
->orWhereNotNull('paciente.sequencial_desconhecido_em');
|
||||
})
|
||||
->whereNull('paciente.deleted_at');
|
||||
|
||||
if (!request()->get('order')) {
|
||||
$atendimentos->orderByRaw('COALESCE(paciente.sem_documentos_em, paciente.sequencial_desconhecido_em) DESC');
|
||||
}
|
||||
|
||||
return datatables()
|
||||
->of($atendimentos)
|
||||
->filterColumn('data', function ($query, $keyword) {
|
||||
$query->whereRaw("DATE_FORMAT(COALESCE(paciente.sem_documentos_em, paciente.sequencial_desconhecido_em), '%d/%m/%Y') like ?", ["%{$keyword}%"])
|
||||
->orWhereRaw(
|
||||
"CONCAT(
|
||||
SUBSTR(COALESCE(paciente.sem_documentos_em, paciente.sequencial_desconhecido_em),9,2),
|
||||
SUBSTR(COALESCE(paciente.sem_documentos_em, paciente.sequencial_desconhecido_em),6,2),
|
||||
SUBSTR(COALESCE(paciente.sem_documentos_em, paciente.sequencial_desconhecido_em),1,4)
|
||||
) like ?",
|
||||
["%{$keyword}%"]
|
||||
);
|
||||
})
|
||||
->orderColumn('data', function ($query, $order) {
|
||||
$query->orderByRaw('COALESCE(paciente.sem_documentos_em, paciente.sequencial_desconhecido_em) ' . $order);
|
||||
})
|
||||
->skipTotalRecords()
|
||||
->make(true);
|
||||
}
|
||||
|
||||
public function index()
|
||||
{
|
||||
|
||||
$lotacao = $this->getCurrentLotacao();
|
||||
|
||||
$permissaoUsuario = ParametrizacaoPermissaoUsuario::where('usuario_id', $lotacao->usuario_id)
|
||||
->where('infraestrutura_id', $lotacao->infraestrutura_id)
|
||||
->first();
|
||||
|
||||
$countUsuario = ParametrizacaoPermissaoUsuario::count();
|
||||
|
||||
$classificacoes = $permissaoUsuario
|
||||
? PacienteClassificacao::orderBy('descricao')
|
||||
->get()
|
||||
->filter(function ($classificacao) use ($permissaoUsuario) {
|
||||
|
||||
$exibe = false;
|
||||
|
||||
switch ($classificacao->id) {
|
||||
case Classificacao::MUNICIPE:
|
||||
$exibe = $permissaoUsuario->municipe;
|
||||
break;
|
||||
case Classificacao::PROVISORIO:
|
||||
$exibe = $permissaoUsuario->provisorio;
|
||||
break;
|
||||
case Classificacao::OUTRO_MUNICIPIO:
|
||||
$exibe = $permissaoUsuario->outro_municipio;
|
||||
break;
|
||||
}
|
||||
|
||||
return $exibe ? [
|
||||
'id' => $classificacao->id,
|
||||
'descricao' => $classificacao->descricao
|
||||
] : null;
|
||||
})
|
||||
->values()
|
||||
: [];
|
||||
|
||||
return [
|
||||
'classificacoes' => $classificacoes,
|
||||
'is_permissao_cadastro' => $countUsuario === 0 ? true : false,
|
||||
];
|
||||
}
|
||||
|
||||
private function getCentroCustoLogado()
|
||||
{
|
||||
return CentroCusto::findOrFail(auth()->payload()->get('centro_custo_id'));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,83 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\ProntoAtendimento;
|
||||
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Services\ProntoAtendimento\RelatorioAtendimentoService;
|
||||
use Illuminate\Http\Response;
|
||||
|
||||
class RelatorioAtendimentoController extends Controller
|
||||
{
|
||||
protected $modulo = 'pronto-atendimento';
|
||||
protected $funcionalidade = 'relatorio-atendimento';
|
||||
|
||||
public function index()
|
||||
{
|
||||
return response()->json(RelatorioAtendimentoService::index(), Response::HTTP_OK);
|
||||
}
|
||||
|
||||
public function list()
|
||||
{
|
||||
return response()->json(RelatorioAtendimentoService::list(), Response::HTTP_OK);
|
||||
}
|
||||
|
||||
public function autocompletePaciente()
|
||||
{
|
||||
return datatables()->of(RelatorioAtendimentoService::autocompletePaciente())->toJson();
|
||||
}
|
||||
|
||||
public function filtragemPorDiaSemana()
|
||||
{
|
||||
return response()->json(RelatorioAtendimentoService::filtragemPorDiaSemana(), Response::HTTP_OK);
|
||||
}
|
||||
|
||||
public function filtragemPorUnidade()
|
||||
{
|
||||
return response()->json(RelatorioAtendimentoService::filtragemPorUnidade(), Response::HTTP_OK);
|
||||
}
|
||||
|
||||
public function filtragemPorLocalAtendimento()
|
||||
{
|
||||
return response()->json(RelatorioAtendimentoService::filtragemPorLocalAtendimento(), Response::HTTP_OK);
|
||||
}
|
||||
|
||||
public function filtragemPorClassificacaoRisco()
|
||||
{
|
||||
return response()->json(RelatorioAtendimentoService::filtragemPorClassificacaoRisco(), Response::HTTP_OK);
|
||||
}
|
||||
|
||||
public function filtragemPorDesfecho()
|
||||
{
|
||||
return response()->json(RelatorioAtendimentoService::filtragemPorDesfecho(), Response::HTTP_OK);
|
||||
}
|
||||
|
||||
public function filtragemPorOcupacao()
|
||||
{
|
||||
return response()->json(RelatorioAtendimentoService::filtragemPorOcupacao(), Response::HTTP_OK);
|
||||
}
|
||||
|
||||
public function filtragemPorProfissional()
|
||||
{
|
||||
return response()->json(RelatorioAtendimentoService::filtragemPorProfissional(), Response::HTTP_OK);
|
||||
}
|
||||
|
||||
public function filtragemPorStatus()
|
||||
{
|
||||
return response()->json(RelatorioAtendimentoService::filtragemPorStatus(), Response::HTTP_OK);
|
||||
}
|
||||
|
||||
public function filtragemPorCid()
|
||||
{
|
||||
return response()->json(RelatorioAtendimentoService::filtragemPorCid(), Response::HTTP_OK);
|
||||
}
|
||||
|
||||
public function filtragemPorSexo()
|
||||
{
|
||||
return response()->json(RelatorioAtendimentoService::filtragemPorSexo(), Response::HTTP_OK);
|
||||
}
|
||||
|
||||
public function filtragemPorClassificacaoPaciente()
|
||||
{
|
||||
return response()->json(RelatorioAtendimentoService::filtragemPorClassificacaoPaciente(), Response::HTTP_OK);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,23 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\ProntoAtendimento;
|
||||
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Services\ProntoAtendimento\RelatorioClassificacaoRiscoService;
|
||||
use Illuminate\Http\Response;
|
||||
|
||||
class RelatorioClassificacaoRiscoController extends Controller
|
||||
{
|
||||
protected $modulo = 'pronto-atendimento';
|
||||
protected $funcionalidade = 'relatorio-classificacao-risco';
|
||||
|
||||
public function index()
|
||||
{
|
||||
return response()->json(RelatorioClassificacaoRiscoService::index(), Response::HTTP_OK);
|
||||
}
|
||||
|
||||
public function list()
|
||||
{
|
||||
return response()->json(RelatorioClassificacaoRiscoService::list(), Response::HTTP_OK);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,27 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\ProntoAtendimento;
|
||||
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Services\ProntoAtendimento\RelatorioDocumentoNaoAssinadoService;
|
||||
use Illuminate\Http\Response;
|
||||
|
||||
class RelatorioDocumentoNaoAssinadoController extends Controller
|
||||
{
|
||||
protected $modulo = 'pronto-atendimento';
|
||||
protected $funcionalidade = 'relatorio-documento-nao-assinado';
|
||||
|
||||
public function index()
|
||||
{
|
||||
$this->auth(__FUNCTION__);
|
||||
|
||||
return response()->json(RelatorioDocumentoNaoAssinadoService::index(), Response::HTTP_OK);
|
||||
}
|
||||
|
||||
public function list()
|
||||
{
|
||||
$this->auth(__FUNCTION__);
|
||||
|
||||
return response()->json(RelatorioDocumentoNaoAssinadoService::list(), Response::HTTP_OK);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,23 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\ProntoAtendimento;
|
||||
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Services\ProntoAtendimento\RelatorioExameImagemService;
|
||||
use Illuminate\Http\Response;
|
||||
|
||||
class RelatorioExameImagemController extends Controller
|
||||
{
|
||||
protected $modulo = 'pronto-atendimento';
|
||||
protected $funcionalidade = 'relatorio-exame-imagem';
|
||||
|
||||
public function index()
|
||||
{
|
||||
return response()->json(RelatorioExameImagemService::index(), Response::HTTP_OK);
|
||||
}
|
||||
|
||||
public function list()
|
||||
{
|
||||
return response()->json(RelatorioExameImagemService::list(), Response::HTTP_OK);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,58 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\ProntoAtendimento;
|
||||
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Services\ProntoAtendimento\RelatorioPrescricaoInternaService;
|
||||
use Illuminate\Http\Response;
|
||||
|
||||
class RelatorioPrescricaoInternaController extends Controller
|
||||
{
|
||||
protected $modulo = 'pronto-atendimento';
|
||||
protected $funcionalidade = 'relatorio-prescricao-interna';
|
||||
|
||||
public function index()
|
||||
{
|
||||
return response()->json(RelatorioPrescricaoInternaService::index(), Response::HTTP_OK);
|
||||
}
|
||||
|
||||
public function list()
|
||||
{
|
||||
return response()->json(RelatorioPrescricaoInternaService::list(), Response::HTTP_OK);
|
||||
}
|
||||
|
||||
public function autocompletePaciente()
|
||||
{
|
||||
return datatables()->of(RelatorioPrescricaoInternaService::autocompletePaciente())->toJson();
|
||||
}
|
||||
|
||||
public function filtragemPorUnidade()
|
||||
{
|
||||
return response()->json(RelatorioPrescricaoInternaService::filtragemPorUnidade(), Response::HTTP_OK);
|
||||
}
|
||||
|
||||
public function filtragemPorLocalAtendimento()
|
||||
{
|
||||
return response()->json(RelatorioPrescricaoInternaService::filtragemPorLocalAtendimento(), Response::HTTP_OK);
|
||||
}
|
||||
|
||||
public function filtragemPorOcupacao()
|
||||
{
|
||||
return response()->json(RelatorioPrescricaoInternaService::filtragemPorOcupacao(), Response::HTTP_OK);
|
||||
}
|
||||
|
||||
public function filtragemPorProfissional()
|
||||
{
|
||||
return response()->json(RelatorioPrescricaoInternaService::filtragemPorProfissional(), Response::HTTP_OK);
|
||||
}
|
||||
|
||||
public function filtragemPorMedicamento()
|
||||
{
|
||||
return response()->json(RelatorioPrescricaoInternaService::filtragemPorMedicamento(), Response::HTTP_OK);
|
||||
}
|
||||
|
||||
public function filtragemPorStatus()
|
||||
{
|
||||
return response()->json(RelatorioPrescricaoInternaService::filtragemPorStatus(), Response::HTTP_OK);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,23 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\ProntoAtendimento;
|
||||
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Services\ProntoAtendimento\RelatorioProducaoMedicoService;
|
||||
use Illuminate\Http\Response;
|
||||
|
||||
class RelatorioProducaoMedicoController extends Controller
|
||||
{
|
||||
protected $modulo = 'pronto-atendimento';
|
||||
protected $funcionalidade = 'relatorio-producao-medico';
|
||||
|
||||
public function index()
|
||||
{
|
||||
return response()->json(RelatorioProducaoMedicoService::index(), Response::HTTP_OK);
|
||||
}
|
||||
|
||||
public function list()
|
||||
{
|
||||
return response()->json(RelatorioProducaoMedicoService::list(), Response::HTTP_OK);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,23 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\ProntoAtendimento;
|
||||
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Services\ProntoAtendimento\RelatorioQuantitativoProducaoService;
|
||||
use Illuminate\Http\Response;
|
||||
|
||||
class RelatorioQuantitativoProducaoController extends Controller
|
||||
{
|
||||
protected $modulo = 'pronto-atendimento';
|
||||
protected $funcionalidade = 'relatorio-quantitativo-producao';
|
||||
|
||||
public function index()
|
||||
{
|
||||
return response()->json(RelatorioQuantitativoProducaoService::index(), Response::HTTP_OK);
|
||||
}
|
||||
|
||||
public function list()
|
||||
{
|
||||
return response()->json(RelatorioQuantitativoProducaoService::list(), Response::HTTP_OK);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user