This commit is contained in:
178
api/app/Http/Controllers/Regulacao/SolicitacaoController.php
Normal file
178
api/app/Http/Controllers/Regulacao/SolicitacaoController.php
Normal file
@@ -0,0 +1,178 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\Regulacao;
|
||||
|
||||
use App\Exceptions\Regulacao\CannotCancelSolicitacaoException;
|
||||
use App\Exceptions\Regulacao\CannotUpdateSolicitacaoException;
|
||||
use App\Exceptions\Regulacao\CannotCreateSolicitacaoException;
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Services\Regulacao\SolicitacaoService;
|
||||
use Illuminate\Http\Response;
|
||||
|
||||
class SolicitacaoController extends Controller
|
||||
{
|
||||
protected $modulo = 'regulacao';
|
||||
protected $funcionalidade = 'solicitacao';
|
||||
|
||||
public function datatable()
|
||||
{
|
||||
return datatables()
|
||||
->of(SolicitacaoService::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}%"]
|
||||
);
|
||||
})
|
||||
->skipTotalRecords()
|
||||
->toJson();
|
||||
}
|
||||
|
||||
public function autocompleteExame()
|
||||
{
|
||||
return datatables()
|
||||
->of(SolicitacaoService::autocompleteExame())
|
||||
->toJson();
|
||||
}
|
||||
|
||||
public function autocompleteProcedimentoCirurgico()
|
||||
{
|
||||
return datatables()
|
||||
->of(SolicitacaoService::autocompleteProcedimentoCirurgico())
|
||||
->toJson();
|
||||
}
|
||||
|
||||
public function autocompleteEspecialidade()
|
||||
{
|
||||
return datatables()
|
||||
->of(SolicitacaoService::autocompleteEspecialidade())
|
||||
->toJson();
|
||||
}
|
||||
|
||||
public function index($pacienteId)
|
||||
{
|
||||
$this->auth(__FUNCTION__);
|
||||
|
||||
return response()->json(SolicitacaoService::index($pacienteId), Response::HTTP_OK);
|
||||
}
|
||||
|
||||
public function list()
|
||||
{
|
||||
return response()->json(SolicitacaoService::list(), Response::HTTP_OK);
|
||||
}
|
||||
|
||||
public function create($pacienteId)
|
||||
{
|
||||
$this->auth(__FUNCTION__);
|
||||
|
||||
return response()->json(SolicitacaoService::create($pacienteId), Response::HTTP_OK);
|
||||
}
|
||||
|
||||
public function edit($id)
|
||||
{
|
||||
$this->auth(__FUNCTION__);
|
||||
|
||||
return response()->json(SolicitacaoService::edit($id), Response::HTTP_OK);
|
||||
}
|
||||
|
||||
public function store()
|
||||
{
|
||||
$this->auth(__FUNCTION__);
|
||||
|
||||
try {
|
||||
|
||||
return response()->json(SolicitacaoService::store(), Response::HTTP_CREATED);
|
||||
|
||||
}
|
||||
catch (CannotCreateSolicitacaoException $e) {
|
||||
|
||||
return response()->json(['message' => $e->getMessage()], Response::HTTP_BAD_REQUEST);
|
||||
}
|
||||
}
|
||||
|
||||
public function update($id)
|
||||
{
|
||||
$this->auth(__FUNCTION__);
|
||||
|
||||
try {
|
||||
|
||||
return response()->json(SolicitacaoService::update($id), Response::HTTP_OK);
|
||||
}
|
||||
catch (CannotUpdateSolicitacaoException $e) {
|
||||
|
||||
return response()->json(['message' => $e->getMessage()], Response::HTTP_BAD_REQUEST);
|
||||
}
|
||||
}
|
||||
|
||||
public function cancel($id)
|
||||
{
|
||||
$this->auth(__FUNCTION__);
|
||||
|
||||
try {
|
||||
|
||||
return response()->json(SolicitacaoService::cancel($id, request()->all()), Response::HTTP_OK);
|
||||
}
|
||||
catch (CannotCancelSolicitacaoException $e) {
|
||||
|
||||
return response()->json(['message' => $e->getMessage()], Response::HTTP_BAD_REQUEST);
|
||||
}
|
||||
}
|
||||
|
||||
public function getInfoProfissional()
|
||||
{
|
||||
|
||||
return response()->json(SolicitacaoService::getInfoProfissional(), Response::HTTP_OK);
|
||||
}
|
||||
|
||||
public function getAgendamentoExameNoPrazoDeValidade($pacienteId, $exameId)
|
||||
{
|
||||
return response()->json(
|
||||
SolicitacaoService::getAgendamentoExameNoPrazoDeValidade($pacienteId, $exameId),
|
||||
Response::HTTP_OK
|
||||
);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user