Skip to content

Commit

Permalink
adicionadno modelos ao medicos e profissionais
Browse files Browse the repository at this point in the history
  • Loading branch information
leonardovilarinho committed Oct 1, 2017
1 parent 1f65d8c commit b997955
Show file tree
Hide file tree
Showing 13 changed files with 305 additions and 7 deletions.
12 changes: 11 additions & 1 deletion src/app/Http/Controllers/EvolucaoController.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
use App\Http\Requests\EvolucaoRequest;
use App\Model\Evolucao;
use App\Model\Paciente;
use App\Model\Modelo;
use App\Model\Usuario;

class EvolucaoController extends Controller
{
Expand Down Expand Up @@ -85,12 +87,20 @@ public function detalhes($id, $evo)

public function nova($id)
{
$usuario = Usuario::find(auth()->user()->id);
$medico = ($usuario->medico) ? $usuario->medico : $usuario->nao_medico;
$modelos = $medico->selectModelos();

$valor = '';
if(isset($_GET['modelo']))
$valor = Modelo::find($_GET['modelo'])->conteudo;

$paciente = Paciente::find($id);

if(!$paciente)
return redirect('pacientes')->withErro('Paciente não encontrado');

return view('pacientes.evolucao.criar', compact('paciente'));
return view('pacientes.evolucao.criar', compact('paciente', 'modelos', 'valor'));
}

public function salvar(EvolucaoRequest $requisicao, $id)
Expand Down
65 changes: 65 additions & 0 deletions src/app/Http/Controllers/ModeloController.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
<?php

namespace App\Http\Controllers;

use Illuminate\Http\Request;
use App\Model\Usuario;
use App\Model\Modelo;

class ModeloController extends Controller
{
public function lista() {
$usuario = Usuario::find(auth()->user()->id);
$medico = ($usuario->medico) ? $usuario->medico : $usuario->nao_medico;

$select = [];

foreach ($medico->modelos as $mol) {
$select[$mol->id] = $mol->titulo;
}

$modelo = new Modelo;

if(isset($_GET['modelo'])) {
$m = Modelo::find($_GET['modelo']);

if($m) {
if($m->medico_id == $usuario->id) {
$modelo = $m;
}
}
}

return view('modelos.lista', compact('medico', 'select', 'modelo'));
}

public function novo(Request $r) {
$usuario = Usuario::find(auth()->user()->id);
$medico = ($usuario->medico) ? $usuario->medico : $usuario->nao_medico;

if($r->tipo == 'novo') {
Modelo::create($r->all() + [ 'medico_id' => $medico->usuario_id ]);

return redirect('modelos')->withMsg('Modelo foi criado!');
}

$m = Modelo::find($r->modelo);
$m->fill($r->all());
$m->save();

return redirect('modelos')->withMsg('Modelo foi editado!');

}

public function manipular(Request $r) {
$usuario = Usuario::find(auth()->user()->id);
$medico = ($usuario->medico) ? $usuario->medico : $usuario->nao_medico;

if($r->acao == 'Apagar') {
Modelo::destroy($r->modelo);
return redirect('modelos')->withMsg('Modelo foi apagado!');
}

return redirect('modelos?modelo='.$r->modelo);
}
}
11 changes: 10 additions & 1 deletion src/app/Http/Controllers/ReceituarioController.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
use App\Http\Requests\ReceituarioRequest;
use App\Model\Receituario;
use App\Model\Paciente;
use App\Model\Modelo;
use App\Model\Usuario;

class ReceituarioController extends Controller
{
Expand Down Expand Up @@ -85,11 +87,18 @@ public function detalhes($id, $rec)
public function novo($id)
{
$paciente = Paciente::find($id);
$usuario = Usuario::find(auth()->user()->id);
$medico = ($usuario->medico) ? $usuario->medico : $usuario->nao_medico;
$modelos = $medico->selectModelos();

$valor = '';
if(isset($_GET['modelo']))
$valor = Modelo::find($_GET['modelo'])->conteudo;

if(!$paciente)
return redirect('pacientes')->withErro('Paciente não encontrado');

return view('pacientes.receituario.criar', compact('paciente'));
return view('pacientes.receituario.criar', compact('paciente', 'modelos', 'valor'));
}

public function salvar(ReceituarioRequest $requisicao, $id)
Expand Down
13 changes: 13 additions & 0 deletions src/app/Model/Medico.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,19 @@ public function ferias_()
return $this->hasMany(Feria::class, 'medico_id', 'usuario_id');
}

public function modelos()
{
return $this->hasMany(Modelo::class, 'medico_id', 'usuario_id');
}

public function selectModelos() {
$retorno = [];
foreach ($this->modelos as $mo) {
$retorno[$mo->id] = $mo->titulo;
}
return $retorno;
}

public function consultas()
{
return $this->hasMany(Consulta::class, 'usuario_id', 'usuario_id');
Expand Down
21 changes: 21 additions & 0 deletions src/app/Model/Modelo.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<?php

namespace App\Model;

use Illuminate\Database\Eloquent\Model;

class Modelo extends Model
{
public $timestamps = false;

protected $fillable = [
'titulo',
'conteudo',
'medico_id'
];

public function usuario()
{
return $this->belongsTo(Usuario::class, 'medico_id', 'usuario_id');
}
}
13 changes: 13 additions & 0 deletions src/app/Model/NaoMedico.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,19 @@ public function carga_horaria()
return $this->hasOne(CargaHoraria::class, 'medico_id', 'usuario_id');
}

public function modelos()
{
return $this->hasMany(Modelo::class, 'medico_id', 'usuario_id');
}

public function selectModelos() {
$retorno = [];
foreach ($this->modelos as $mo) {
$retorno[$mo->id] = $mo->titulo;
}
return $retorno;
}

public function dia()
{
return $this->hasOne(Dia::class, 'medico_id', 'usuario_id');
Expand Down
11 changes: 10 additions & 1 deletion src/atualizar
Original file line number Diff line number Diff line change
@@ -1,4 +1,13 @@
ALTER TABLE `consultas`
CHANGE COLUMN `status` `status` VARCHAR(250) NOT NULL COLLATE 'utf8mb4_unicode_ci' AFTER `obs`;



CREATE TABLE IF NOT EXISTS `modelos` (
`id` int(10) unsigned NOT NULL AUTO_INCREMENT,
`titulo` varchar(255) COLLATE utf8mb4_unicode_ci NOT NULL,
`conteudo` text COLLATE utf8mb4_unicode_ci NOT NULL,
`medico_id` int(10) unsigned NOT NULL,
PRIMARY KEY (`id`),
KEY `modelos_medico_id_foreign` (`medico_id`),
CONSTRAINT `modelos_medico_id_foreign` FOREIGN KEY (`medico_id`) REFERENCES `usuarios` (`id`) ON DELETE CASCADE
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
38 changes: 38 additions & 0 deletions src/database/migrations/2017_09_30_220718_create_modelos_table.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
<?php

use Illuminate\Support\Facades\Schema;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;

class CreateModelosTable extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::create('modelos', function (Blueprint $table) {
$table->increments('id');
$table->string('titulo');
$table->text('conteudo');
$table->integer('medico_id')->unsigned();

$table->foreign('medico_id')
->references('id')
->on('usuarios')
->onDelete('cascade');
});
}

/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::dropIfExists('modelos');
}
}
2 changes: 2 additions & 0 deletions src/resources/views/layouts/app.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@
<li><a href="{{ url('medicos/financas') }}">Finanças</a></li>
<li><a href="{{ url('medicos/config') }}">Horários</a></li>
<li><a href="{{ url('medicos/folga') }}">Férias / Folgas</a></li>
<li><a href="{{ url('modelos') }}">Modelos</a></li>

@elseif(auth()->user()->secretario)
<li><a href="{{ url('pacientes') }}">Pacientes</a></li>
Expand All @@ -84,6 +85,7 @@
<li><a href="{{ url('medicos/financas') }}">Finanças</a></li>
<li><a href="{{ url('medicos/config') }}">Horários</a></li>
<li><a href="{{ url('medicos/folga') }}">Férias / Folgas</a></li>
<li><a href="{{ url('modelos') }}">Modelos</a></li>

@endif
@endif
Expand Down
80 changes: 80 additions & 0 deletions src/resources/views/modelos/lista.blade.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
@extends('layouts.app')

@section('titulo', 'Seus modelos')

@section('lateral')
@endsection

@section('conteudo')
<p style="text-align:center">
@if(session('msg'))
<span class="texto-verde">
{{ session('msg') }}
</span>
@endif

@if(session('erro'))
<span class="texto-vermelho">
{{ session('erro') }}
</span>
@endif
</p>

{{ Form::open(['url' => 'modelos/manipular', 'method' => 'post']) }}
<section>
<div>
{{ Form::label('modelo', 'Modelo') }}
{{ Form::select('modelo', $select, $modelo->id,
['required' => '']
) }}

<input type="submit" name="acao" value="Apagar" class="btn vermelho" style='flex-grow: 1; margin-left: 3px' onclick="return confirm('Deseja realmente apagar?')">
<input type="submit" name="acao" value="Editar" class="btn amarelo" style='flex-grow: 1; margin-left: 3px'>

</div>
</section>
{{ Form::close() }}

{{ Form::open(['url' => 'modelos', 'method' => 'post']) }}
<header>
@if($modelo->id != null)
Editar modelo
@else
Novo modelo
@endif
</header>

<section>

@if($modelo->id != null)
<input type="hidden" name="tipo" value="editar">
<input type="hidden" name="modelo" value="{{ $modelo->id }}">
@else
<input type="hidden" name="tipo" value="novo">
@endif

<div>
{{ Form::label('titulo', 'Título (Apelido)') }}
{{ Form::text('titulo', $modelo->titulo, ['required' => '']) }}
</div>

<div>
{{ Form::label('conteudo', 'Conteúdo') }}
{!! Form::textarea('conteudo', $modelo->conteudo, ['required' => '', 'placeholder' => 'Digite seu modelo'] ) !!}
</div>
</section>

<footer>
<section>
<input type="submit" value="Salvar esse modelo" class="btn verde">
</section>

<span class="texto-vermelho">{{ $errors->first() }}</span>
</footer>
{{ Form::close() }}

<script>
CKEDITOR.config.width = '100%';
CKEDITOR.replace( 'conteudo' );
</script>
@endsection
21 changes: 18 additions & 3 deletions src/resources/views/pacientes/evolucao/criar.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,22 @@
<li><strong>Idade:</strong>{{ Saudacoes::idade($paciente->nascimento) }}</li>
<li><strong>Convênio:</strong>{{ $paciente->convenio }}</li>
</ul>


{{ Form::open(['url' => '#', 'method' => 'get']) }}
<section>
<div>
{{ Form::label('modelo', 'Modelo') }}
{{ Form::select('modelo', $modelos, '',
['required' => '']
) }}
<button class="btn verde" style='flex-grow: 1; margin-left: 3px'>
Selecionar
</button>

</div>
</section>
{{ Form::close() }}

{!! Form::open(['url' => 'pacientes/'.$paciente->id.'/evolucoes/nova', 'method' => 'post']) !!}
{{ Form::hidden('paciente_id', $paciente->id) }}
{{ Form::hidden('autor_id', auth()->user()->id) }}
Expand All @@ -21,10 +36,10 @@
</header>

<section>

<div>
{!! Form::label('evolucao', 'Evolução') !!}
{!! Form::textarea('evolucao', '', ['required' => '', 'placeholder' => 'Detalhes da evolução'] ) !!}
{!! Form::textarea('evolucao', $valor, ['required' => '', 'placeholder' => 'Detalhes da evolução'] ) !!}
</div>

<div>
Expand Down
Loading

0 comments on commit b997955

Please sign in to comment.