Files
rkm-conectasus-ci-sandbox/api/app/Http/Controllers/Ambulatorio/HistoricoAtendimentoController.php
Antonio Lopes dos Santos afec302c3e
All checks were successful
build-api-image / build (push) Successful in 51s
init commit
2026-08-04 16:52:02 -03:00

91 lines
3.2 KiB
PHP

<?php
namespace App\Http\Controllers\Ambulatorio;
use App\Http\Controllers\Controller;
use App\Services\Ambulatorio\HistoricoAtendimentoService;
use Illuminate\Http\Response;
class HistoricoAtendimentoController extends Controller
{
protected $modulo = 'ambulatorio';
protected $funcionalidade = 'historico-atendimento';
public function datatable()
{
return datatables()
->of(HistoricoAtendimentoService::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 show($id)
{
$this->auth(__FUNCTION__);
return response()->json(HistoricoAtendimentoService::show($id), Response::HTTP_OK);
}
}