This commit is contained in:
@@ -0,0 +1,161 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\Mobile\ConectaCidadao\HistoricoAtendimento;
|
||||
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Models\Cadastro\SujeitoAtencao\Paciente;
|
||||
use Illuminate\Database\Eloquent\ModelNotFoundException;
|
||||
use App\Services\Mobile\ConectaCidadao\HistoricoAtendimento\HistoricoAtendimentoService;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Http\Response;
|
||||
use Exception;
|
||||
|
||||
class HistoricoAtendimentoController extends Controller
|
||||
{
|
||||
private HistoricoAtendimentoService $historicoAtendimentoService;
|
||||
|
||||
public function __construct(HistoricoAtendimentoService $historicoAtendimentoService)
|
||||
{
|
||||
$this->historicoAtendimentoService = $historicoAtendimentoService;
|
||||
}
|
||||
|
||||
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
|
||||
);
|
||||
}
|
||||
|
||||
$limit = $request->input('limit', 15);
|
||||
$historico = $this->historicoAtendimentoService->getHistorico($paciente, $limit);
|
||||
|
||||
} catch (Exception $exception) {
|
||||
return response()->json(
|
||||
[
|
||||
'message' => $exception->getMessage(),
|
||||
],
|
||||
Response::HTTP_INTERNAL_SERVER_ERROR
|
||||
);
|
||||
}
|
||||
|
||||
return response()->json($historico, Response::HTTP_OK);
|
||||
}
|
||||
|
||||
public function show($id, Request $request)
|
||||
{
|
||||
try {
|
||||
|
||||
$sourceType = $request->input('source_type');
|
||||
|
||||
if (!$sourceType) {
|
||||
|
||||
return response()->json(
|
||||
[
|
||||
'message' => 'O parâmetro source_type é obrigatório.'
|
||||
],
|
||||
Response::HTTP_BAD_REQUEST);
|
||||
}
|
||||
|
||||
$detalhes = $this->historicoAtendimentoService->getDetalhes($id, $sourceType);
|
||||
|
||||
return response()->json($detalhes, Response::HTTP_OK);
|
||||
|
||||
} catch (ModelNotFoundException $e) {
|
||||
|
||||
return response()->json(
|
||||
[
|
||||
'message' => 'Atendimento não encontrado.'
|
||||
],
|
||||
Response::HTTP_NOT_FOUND
|
||||
);
|
||||
} catch (\Exception $exception) {
|
||||
return response()->json(
|
||||
[
|
||||
'message' => $exception->getMessage(),
|
||||
],
|
||||
Response::HTTP_INTERNAL_SERVER_ERROR
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
public function avaliar($sourceType, $id, Request $request)
|
||||
{
|
||||
try {
|
||||
|
||||
$params = $request->all();
|
||||
|
||||
$this->historicoAtendimentoService->avaliar($sourceType, $id, $params);
|
||||
|
||||
return response()->json(
|
||||
[
|
||||
'message' => 'Avaliação registrada com sucesso.'
|
||||
],
|
||||
Response::HTTP_OK
|
||||
);
|
||||
|
||||
} catch (ModelNotFoundException $e) {
|
||||
|
||||
return response()->json(
|
||||
[
|
||||
'message' => 'Atendimento não encontrado.'
|
||||
],
|
||||
Response::HTTP_NOT_FOUND
|
||||
);
|
||||
} catch (\Exception $exception) {
|
||||
return response()->json(
|
||||
[
|
||||
'message' => $exception->getMessage(),
|
||||
],
|
||||
Response::HTTP_INTERNAL_SERVER_ERROR
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
public function avaliacao($sourceType, $id, Request $request)
|
||||
{
|
||||
try {
|
||||
|
||||
$params = $request->all();
|
||||
|
||||
$avaliacao = $this->historicoAtendimentoService->avaliacao($sourceType, $id, $params);
|
||||
|
||||
return response()->json($avaliacao, Response::HTTP_OK);
|
||||
} catch (ModelNotFoundException $e) {
|
||||
|
||||
return response()->json(
|
||||
[
|
||||
'message' => 'Avaliação não encontrada.'
|
||||
],
|
||||
Response::HTTP_NOT_FOUND
|
||||
);
|
||||
} catch (\Exception $exception) {
|
||||
return response()->json(
|
||||
[
|
||||
'message' => $exception->getMessage(),
|
||||
],
|
||||
Response::HTTP_INTERNAL_SERVER_ERROR
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user