This commit is contained in:
@@ -0,0 +1,61 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\Mobile\ConectaCidadao\PerfilCidadao;
|
||||
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Models\Cadastro\SujeitoAtencao\Paciente;
|
||||
use App\Services\Mobile\ConectaCidadao\PerfilCidadao\PerfilCidadaoService;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Http\Response;
|
||||
use Exception;
|
||||
|
||||
class PerfilCidadaoController extends Controller
|
||||
{
|
||||
private PerfilCidadaoService $perfilCidadaoService;
|
||||
|
||||
public function __construct(PerfilCidadaoService $perfilCidadaoService)
|
||||
{
|
||||
$this->perfilCidadaoService = $perfilCidadaoService;
|
||||
}
|
||||
|
||||
public function index(Request $request)
|
||||
{
|
||||
try {
|
||||
|
||||
$pacienteId = $request->input('paciente_id');
|
||||
|
||||
if (!$pacienteId) {
|
||||
|
||||
return response()->json(
|
||||
[
|
||||
'message' => 'O parâmetro paciente_id é obrigatório.'
|
||||
],
|
||||
Response::HTTP_BAD_REQUEST
|
||||
);
|
||||
}
|
||||
|
||||
$paciente = Paciente::find($pacienteId);
|
||||
|
||||
if (!$paciente) {
|
||||
|
||||
return response()->json(
|
||||
[
|
||||
'message' => 'Paciente não encontrado.'
|
||||
],
|
||||
Response::HTTP_NOT_FOUND
|
||||
);
|
||||
}
|
||||
|
||||
$dadosCidadao = $this->perfilCidadaoService->getDadosCidadao($paciente);
|
||||
} catch (Exception $exception) {
|
||||
return response()->json(
|
||||
[
|
||||
'message' => $exception->getMessage(),
|
||||
],
|
||||
Response::HTTP_INTERNAL_SERVER_ERROR
|
||||
);
|
||||
}
|
||||
|
||||
return response()->json($dadosCidadao, Response::HTTP_OK);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user