of(AgendamentoService::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 index() { $this->auth(__FUNCTION__); return response()->json(AgendamentoService::index((object) request()->all()), Response::HTTP_OK); } public function create($pacienteId) { $this->auth(__FUNCTION__); return response()->json(AgendamentoService::create($pacienteId), Response::HTTP_OK); } public function createAgendamentoDemandaEspontanea($pacienteId) { return response()->json(AgendamentoService::createAgendamentoDemandaEspontanea($pacienteId), Response::HTTP_OK); } public function edit($id) { $this->auth(__FUNCTION__); return response()->json(AgendamentoService::edit($id), Response::HTTP_OK); } public function list() { return response()->json(AgendamentoService::list(), Response::HTTP_OK); } public function getSugestao($pacienteId, $infraestruturaId, $ocupacaoId, $especialidadeId, $usuarioId) { return response()->json( AgendamentoService::getSugestao( $pacienteId, $infraestruturaId, $ocupacaoId, $especialidadeId, $usuarioId ), Response::HTTP_OK ); } public function unidadePaciente($pacienteId, $infraestruturaId) { return response()->json( AgendamentoService::unidadePaciente( $pacienteId, $infraestruturaId ), Response::HTTP_OK ); } public function store() { $this->auth(__FUNCTION__); try { return response()->json(AgendamentoService::store(), Response::HTTP_CREATED); } catch (AgendamentoConflitanteException | AgendamentoNaoPermitidoJornadaGrupoException $e ) { return response()->json(['message' => $e->getMessage()], Response::HTTP_BAD_REQUEST); } } public function update($id) { $this->auth(__FUNCTION__); try { return response()->json(AgendamentoService::update($id), Response::HTTP_OK); } catch (AgendamentoConflitanteException | AgendamentoNaoPermitidoJornadaGrupoException $e ) { return response()->json(['message' => $e->getMessage()], Response::HTTP_BAD_REQUEST); } } public function cancel($id) { $this->auth(__FUNCTION__); try { return response()->json(AgendamentoService::cancel($id, request()->all()), Response::HTTP_OK); } catch (NaoPodeAlterarStatusAgendamentoException $e) { return response()->json(['message' => $e->getMessage()], Response::HTTP_BAD_REQUEST); } } public function destroy($id) { $this->auth(__FUNCTION__); try { AgendamentoService::destroy($id); return response()->noContent(); } catch (NaoPodeExcluirAgendamentoException $e) { return response()->json(['message' => $e->getMessage()], Response::HTTP_BAD_REQUEST); } } public function absent($id) { AgendamentoService::absent($id); return response()->noContent(); } public function undoAbsent($id) { AgendamentoService::undoAbsent($id); return response()->noContent(); } public function getAgendamentosDemandasEspontaneas() { return response()->json(AgendamentoService::getAgendamentosDemandasEspontaneas((object) request()->all()), Response::HTTP_OK); } }