Skip to content

Commit

Permalink
Merge pull request #67 from cpa-bayarea/feature-60-triagem
Browse files Browse the repository at this point in the history
[MELHORIAS] Cadastro de Triagem.
  • Loading branch information
dougs007 committed Dec 8, 2019
2 parents f8b3b4c + a20f9a1 commit f4c0852
Show file tree
Hide file tree
Showing 34 changed files with 5,239 additions and 557 deletions.
2 changes: 1 addition & 1 deletion app/Http/Controllers/AbstractController.php
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,6 @@ public function destroy($id)

protected function _recuperarDados()
{
return null;
return [];
}
}
56 changes: 17 additions & 39 deletions app/Http/Controllers/AgendamentoController.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,10 @@

namespace App\Http\Controllers;

use App\Models\Agendamento;
use App\Models\Aluno;
use App\Models\Paciente;
use Exception;
use App\Models\{AgendamentoStatus, Agendamento, Aluno, Paciente};
use Illuminate\Support\Facades\{DB, Session};
use Illuminate\Http\Request;
use Illuminate\Support\Facades\DB;
use Illuminate\Support\Facades\Session;
use Exception;

class AgendamentoController extends Controller
{
Expand All @@ -20,19 +17,9 @@ class AgendamentoController extends Controller
public function index()
{
$agendamentos = Agendamento::all();
$alunos = Aluno::all();
$pacientes = Paciente::orderBy('nome', 'asc')->get();
return view('agendamento.index', compact('agendamentos', 'alunos', 'pacientes'));
}

/**
* Show the form for creating a new resource.
*
* @return \Illuminate\Http\Response
*/
public function create()
{
//
$terapeutas = Aluno::all();
$pacientes = Paciente::orderBy('tx_nome', 'asc')->get();
return view('agendamento.index', compact('agendamentos', 'terapeutas', 'pacientes'));
}

/**
Expand All @@ -54,14 +41,14 @@ public function store(Request $request)
$aluno = Aluno::find($request->aluno_id);
$paciente = Paciente::find($request->paciente_id);
$agendamento = new Agendamento();
$agendamento->title = $aluno->tx_nome . " - " . $paciente->nome;
$agendamento->title = $aluno->user->name . " - " . $paciente->tx_nome;
$agendamento->color = '#f8ac59';
$agendamento->aluno_id = $request->aluno_id;
$agendamento->paciente_id = $request->paciente_id;
$agendamento->status_id = 1;
$agendamento->status_id = AgendamentoStatus::AGSTATUS_AGENDADO;
$agendamento->start = $request->date . " " . $request->start;
$agendamento->end = $request->date . " " . $request->end;
$checkAgendamento = $this->checkAgendamento($agendamento->aluno_id, $agendamento->start, $agendamento->end);
$checkAgendamento = $this->_checkAgendamento($agendamento->aluno_id, $agendamento->start, $agendamento->end);
if (count($checkAgendamento) == 0) {
if ($request->prontuario_id == null) {
$prontuario = (new ProntuarioController())->createByAgendamento($request);
Expand All @@ -74,21 +61,10 @@ public function store(Request $request)
return redirect()->route('agendamento.index');
}
} catch (Exception $e) {
throw new exception('Não foi possível realizar o agendamento!');
return back()->with('error', 'Não foi possível realizar a agendamento!');
}
}

/**
* Display the specified resource.
*
* @param int $id
* @return \Illuminate\Http\Response
*/
public function show($id)
{
//
}

/**
* Show the form for editing the specified resource.
*
Expand All @@ -102,9 +78,11 @@ public function edit(Request $request, $id)
$agendamento->start = $request->start;
$agendamento->end = $request->end;
$agendamento->save();
return redirect()->route('agendamento.index');
$response = response()->json([$agendamento->title, "msg" => "Dados atualizados com sucesso!"]);
return $response;
} catch (Exception $e) {
throw new exception('Não foi possível alterar o agendamento!');
$response = response()->json([$agendamento->title, "msg" => "Não foi possível alterar o agendamento!"]);
return $response;
}
}

Expand All @@ -118,10 +96,10 @@ public function edit(Request $request, $id)
public function update(Request $request, $id)
{
try {
$aluno = Aluno::find($request->aluno_id);
$terapeuta = Aluno::find($request->aluno_id);
$paciente = Paciente::find($request->paciente_id);
$agendamento = Agendamento::find($id);
$agendamento->title = $aluno->tx_nome . " - " . $paciente->nome;
$agendamento->title = $terapeuta->user->name . " - " . $paciente->tx_nome;
$agendamento->paciente_id = $request->paciente_id;
$agendamento->aluno_id = $request->aluno_id;
$agendamento->start = $request->date . " " . $request->start;
Expand Down Expand Up @@ -182,7 +160,7 @@ public function findById($id)
return ['agendamento' => $agendamento];
}

private function checkAgendamento($aluno_id, $start, $end)
private function _checkAgendamento($aluno_id, $start, $end)
{
return DB::table('agendamentos')
->where(function ($query) use ($start, $end) {
Expand Down
3 changes: 2 additions & 1 deletion app/Http/Controllers/AlunoController.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,10 @@ class AlunoController extends AbstractController

public function store(Request $request)
{

if ($id = base64_decode($request->id)) {
$this->_model = $this->_model->find($id);
$user = User::find($id);
$user = User::find($this->_model->user_id);
} else {
$user = new User();
}
Expand Down
2 changes: 1 addition & 1 deletion app/Http/Controllers/ProntuarioController.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ public function createByAgendamento($request)
$prontuario->numero = 0;
$prontuario->aluno_id = $request->aluno_id;
$prontuario->paciente_id = $request->paciente_id;
$prontuario->prontuario_status_id = 1;
$prontuario->prontuario_status_id = ProntuarioStatus::P_STATUS_EM_ATENDIMENTO;
$prontuario->valor = 0;

$prontuario->save();
Expand Down
4 changes: 2 additions & 2 deletions app/Http/Controllers/SupervisorController.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ public function store(Request $request)
{
if ($id = base64_decode($request->id)) {
$this->_model = $this->_model->find($id);
$user = User::find($id);
$user = User::find($this->_model->user_id);
} else {
$user = new User();
}
Expand All @@ -36,7 +36,7 @@ public function store(Request $request)

$this->_model->user_id = $user->id;
$this->_model->linha_id = $request->linha_id;
$this->_model->nu_crp = $request->nu_crp;
$this->_model->nu_crp = str_replace('/', '', $request->nu_crp);
$this->_model->save();

return redirect($this->_redirectSave);
Expand Down
Loading

0 comments on commit f4c0852

Please sign in to comment.