init commit
All checks were successful
build-api-image / build (push) Successful in 51s

This commit is contained in:
Antonio Lopes dos Santos
2026-08-04 16:52:02 -03:00
commit afec302c3e
11594 changed files with 1636728 additions and 0 deletions

View File

@@ -0,0 +1,147 @@
<?php
namespace App\Http\Controllers\Ambulatorio;
use App\Exceptions\Ambulatorio\AgendamentoConflitanteException;
use App\Exceptions\Ambulatorio\AgendamentoNaoPermitidoJornadaGrupoException;
use App\Exceptions\Ambulatorio\NaoPodeExcluirAgendamentoException;
use App\Http\Controllers\Controller;
use App\Services\Ambulatorio\AgendamentoRetroativoService;
use Illuminate\Http\Response;
class AgendamentoRetroativoController extends Controller
{
protected $modulo = 'ambulatorio';
protected $funcionalidade = 'agendamento-retroativo';
public function datatable()
{
return datatables()
->of(AgendamentoRetroativoService::datatable())
->filterColumn('cidadao.data_nascimento', function ($query, $keyword) {
$query->whereRaw("DATE_FORMAT(cidadao.data_nascimento, '%d/%m/%Y') like ?", ["%{$keyword}%"])
->orWhereRaw(
"CONCAT(
SUBSTR(cidadao.data_nascimento,9,2),
SUBSTR(cidadao.data_nascimento,6,2),
SUBSTR(cidadao.data_nascimento,1,4)
) 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}%"]
);
})
->filterColumn('cidadao.cns', function ($query, $keyword) {
$query
->whereRaw("cidadao.cns like ?", ["%{$keyword}%"])
->orWhereRaw(
"CONCAT(
SUBSTR(cidadao.cns, 1, 3),
' ',
SUBSTR(cidadao.cns, 4, 4),
' ',
SUBSTR(cidadao.cns, 8, 4),
' ',
SUBSTR(cidadao.cns, 12, 4)
) like ?",
["%{$keyword}%"]
);
})
->filterColumn('municipio_uf', function ($query, $keyword) {
$query->whereRaw("CONCAT(municipio.nome, ' / ', estado.uf) like ?", ["%{$keyword}%"]);
})
->filterColumn('validade_fim', function ($query, $keyword) {
$query->whereRaw("IF(paciente.validade_fim IS NULL,
'INDETERMINADO',
DATE_FORMAT(paciente.validade_fim, '%d/%m/%Y')
) like ?", ["%{$keyword}%"]);
})
->skipTotalRecords()
->toJson();
}
public function unidadePaciente($pacienteId, $infraestruturaId)
{
return response()->json(
AgendamentoRetroativoService::unidadePaciente(
$pacienteId,
$infraestruturaId
),
Response::HTTP_OK
);
}
public function index()
{
$this->auth(__FUNCTION__);
return response()->json(AgendamentoRetroativoService::index(), Response::HTTP_OK);
}
public function create($pacienteId)
{
$this->auth(__FUNCTION__);
return response()->json(AgendamentoRetroativoService::create($pacienteId), Response::HTTP_OK);
}
public function list()
{
return response()->json(AgendamentoRetroativoService::list(), Response::HTTP_OK);
}
public function store()
{
$this->auth(__FUNCTION__);
try {
return response()->json(AgendamentoRetroativoService::store(), Response::HTTP_CREATED);
}
catch (AgendamentoConflitanteException
| AgendamentoNaoPermitidoJornadaGrupoException $e
) {
return response()->json(['message' => $e->getMessage()], Response::HTTP_BAD_REQUEST);
}
}
public function destroy($id)
{
$this->auth(__FUNCTION__);
try {
AgendamentoRetroativoService::destroy($id);
return response()->noContent();
}
catch (NaoPodeExcluirAgendamentoException $e) {
return response()->json(['message' => $e->getMessage()], Response::HTTP_BAD_REQUEST);
}
}
}