149 lines
5.7 KiB
PHP
149 lines
5.7 KiB
PHP
<?php
|
|
|
|
namespace App\Http\Controllers\Regulacao;
|
|
|
|
use App\Http\Controllers\Controller;
|
|
use App\Models\Cadastro\Parametrizacao\Parametrizacao;
|
|
use App\Services\Geral\AgeService;
|
|
use App\Services\Regulacao\MonitoramentoProcolocoService;
|
|
use Carbon\Carbon;
|
|
use DateTime;
|
|
use Illuminate\Http\Response;
|
|
|
|
class MonitoramentoProcolocoController extends Controller
|
|
{
|
|
protected $modulo = 'regulacao';
|
|
protected $funcionalidade = 'monitoramento-protocolo';
|
|
|
|
public function autocompletePaciente()
|
|
{
|
|
return datatables()
|
|
->of(MonitoramentoProcolocoService::autocompletePaciente())
|
|
->filterColumn('cidadao.data_nascimento', function ($query, $keyword) {
|
|
|
|
$query->whereRaw("DATE_FORMAT(cidadao.data_nascimento, '%d/%m/%Y') like ?", ["%{$keyword}%"]);
|
|
})
|
|
->filterColumn('paciente.prontuario', function ($query, $keyword) {
|
|
|
|
$query->whereRaw("LPAD(paciente.prontuario, 7, 0) like ?", ["%{$keyword}%"]);
|
|
})
|
|
->filterColumn('cidadao.cpf', function ($query, $keyword) {
|
|
|
|
$query
|
|
->whereRaw("cidadao.cpf like ?", ["%{$keyword}%"])
|
|
->orWhereRaw(
|
|
"CONCAT(
|
|
SUBSTR(cidadao.cpf, 1, 3),
|
|
'.',
|
|
SUBSTR(cidadao.cpf, 4, 3),
|
|
'.',
|
|
SUBSTR(cidadao.cpf, 7, 3),
|
|
'-',
|
|
SUBSTR(cidadao.cpf, 10, 2)
|
|
) like ?",
|
|
["%{$keyword}%"]
|
|
);
|
|
})
|
|
->toJson();
|
|
}
|
|
|
|
public function autocompleteUsuarioResponsavel()
|
|
{
|
|
return datatables()
|
|
->of(MonitoramentoProcolocoService::autocompleteUsuarioResponsavel())
|
|
->toJson();
|
|
}
|
|
|
|
public function list()
|
|
{
|
|
return response()->json(MonitoramentoProcolocoService::list(), Response::HTTP_OK);
|
|
}
|
|
|
|
public function datatable()
|
|
{
|
|
$quantidadeDiasCadastroPaciente = Parametrizacao::first()->cadastro_paciente_desatualizado_quantidade_dias ?? 0;
|
|
|
|
return datatables()
|
|
->of(MonitoramentoProcolocoService::datatable())
|
|
->addColumn('data_ultima_atualizacao_paciente', function ($item) {
|
|
|
|
$updatedAt = $item->paciente_updated_at > $item->paciente_cidadao_updated_at
|
|
? $item->paciente_updated_at
|
|
: $item->paciente_cidadao_updated_at;
|
|
|
|
if ($updatedAt) {
|
|
|
|
return Carbon::create($updatedAt)->format('d/m/Y');
|
|
}
|
|
|
|
return null;
|
|
})
|
|
->addColumn('dias_cadastro_paciente_desatualizado', function ($item) use ($quantidadeDiasCadastroPaciente) {
|
|
|
|
$updatedAt = $item->paciente_updated_at > $item->paciente_cidadao_updated_at
|
|
? $item->paciente_updated_at
|
|
: $item->paciente_cidadao_updated_at;
|
|
|
|
$diasAtrasados = 0;
|
|
|
|
if ($updatedAt) {
|
|
|
|
$updatedAtCarbon = Carbon::createFromFormat('Y-m-d H:i:s', $updatedAt);
|
|
$updatedAtCarbon->addDays($quantidadeDiasCadastroPaciente);
|
|
$currentDateTime = Carbon::now();
|
|
|
|
if ($updatedAtCarbon->lessThan($currentDateTime)) {
|
|
|
|
$diasAtrasados = $updatedAtCarbon->diffInDays($currentDateTime);
|
|
$diasAtrasados = str_pad($diasAtrasados, 2, '0', STR_PAD_LEFT);
|
|
}
|
|
}
|
|
|
|
return $diasAtrasados;
|
|
})
|
|
->addColumn('paciente_idade', fn ($a) => is_null($a->paciente_data_nascimento)
|
|
? null : AgeService::getFormattedAge(new DateTime($a->paciente_data_nascimento))
|
|
)
|
|
->editColumn('paciente_data_nascimento', fn ($a) => is_null($a->paciente_data_nascimento)
|
|
? null : Carbon::create($a->paciente_data_nascimento)->format('d/m/Y')
|
|
)
|
|
->editColumn('prazo_restante', fn ($a) => (((bool) $a->is_concluido) ? null : (((bool) $a->is_vencido) ? 0 : $a->prazo_restante)))
|
|
->editColumn('is_concluido', fn ($a) => (bool) $a->is_concluido)
|
|
->editColumn('is_vencido', fn ($a) => (bool) $a->is_vencido)
|
|
->editColumn('is_paciente_em_obito', fn ($a) => (bool) $a->is_paciente_em_obito)
|
|
->editColumn('cids', fn ($a) => explode('#', $a->cids))
|
|
->skipTotalRecords()
|
|
->toJson();
|
|
}
|
|
|
|
public function getAtendimentos($acompanhamentoOciId)
|
|
{
|
|
return response()->json(MonitoramentoProcolocoService::getAtendimentos($acompanhamentoOciId), Response::HTTP_OK);
|
|
}
|
|
|
|
public function getSolicitacoes($acompanhamentoOciId)
|
|
{
|
|
return response()->json(MonitoramentoProcolocoService::getSolicitacoes($acompanhamentoOciId), Response::HTTP_OK);
|
|
}
|
|
|
|
public function createEncerramentoOci($acompanhamentoOciId)
|
|
{
|
|
return response()->json(MonitoramentoProcolocoService::createEncerramentoOci($acompanhamentoOciId), Response::HTTP_OK);
|
|
}
|
|
|
|
public function storeEncerramentoOci($acompanhamentoOciId)
|
|
{
|
|
return response()->json(MonitoramentoProcolocoService::storeEncerramentoOci($acompanhamentoOciId), Response::HTTP_OK);
|
|
}
|
|
|
|
public function updateSolicitacoes($acompanhamentoOciId)
|
|
{
|
|
return response()->json(MonitoramentoProcolocoService::updateSolicitacoes($acompanhamentoOciId), Response::HTTP_OK);
|
|
}
|
|
|
|
public function dadosProcedimentosPreenchidos($acompanhamentoOciId)
|
|
{
|
|
return response()->json(MonitoramentoProcolocoService::dadosProcedimentosPreenchidos($acompanhamentoOciId), Response::HTTP_OK);
|
|
}
|
|
}
|