Files
rkm-conectasus-ci-sandbox/api/app/Http/Controllers/Mobile/ConectaCidadao/PerfilCidadao/PerfilCidadaoController.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

62 lines
1.7 KiB
PHP

<?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);
}
}