Skip to content
This repository has been archived by the owner on Apr 14, 2023. It is now read-only.

Commit

Permalink
Citas - Especialidades
Browse files Browse the repository at this point in the history
  • Loading branch information
Marc15975 committed Dec 11, 2022
1 parent 1b91bf8 commit 6ec0568
Show file tree
Hide file tree
Showing 23 changed files with 472 additions and 67 deletions.
21 changes: 13 additions & 8 deletions app/Http/Controllers/CitasController.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,35 +4,40 @@

use Illuminate\Http\Request;
use App\Models\Citas;
use App\Models\Especialidad;
use App\Models\User;

class CitasController extends Controller
{
public function index()
{
//$User =User::get();
$Citas =Citas::with('users')->get();
$Citas =Citas::with(['medico:id,id_persona','medico.persona:id_persona,nombre_per,apellido_pa_per,apellido_ma_per','paciente:id,id_persona','paciente.persona:id_persona,nombre_per,apellido_pa_per,apellido_ma_per'])->get();

//return $Citas;
return view ('admin.Citas.index',compact('Citas'));
}

public function create()
{
$User = User::get();
return view('admin.Citas.create');
$Users = User::with(['persona:id_persona,nombre_per,apellido_pa_per,apellido_ma_per','persona.has_especialidad'])->get();

$Especialidades =Especialidad::all();

return view('admin.Citas.create',compact('Users','Especialidades'));
}

public function store(Request $request)
{
$request->validate([

'fecha_cita'=>['required'],
'detalles_cita'=>['required','max:50']

]);
$input = $request->all();
Citas::create($input);
$Cita = $request->all();

$Nivel=['estado' => 1,'id_paciente'=> 1];
$Cita= array_merge($Nivel, $Cita);

Citas::create($Cita);
return redirect('Citas')->with('flash_message', 'Citas Addedd!');
}

Expand Down
52 changes: 52 additions & 0 deletions app/Http/Controllers/EspecialidadController.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
<?php

namespace App\Http\Controllers;

use Illuminate\Http\Request;
use App\Models\Especialidad;

class EspecialidadController extends Controller
{

public function index()
{
//
$Especialidades = Especialidad::all();
return view('admin.Especialidades.index',compact('Especialidades'));
}


public function create()
{
//
}


public function store(Request $request)
{
//
}


public function show($id)
{
//
}


public function edit($id)
{
//
}

public function update(Request $request, $id)
{
//
}


public function destroy($id)
{
//
}
}
10 changes: 7 additions & 3 deletions app/Models/Citas.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,14 @@ class Citas extends Model
use HasFactory;
protected $table = 'citas';
protected $primaryKey = 'id_cita';
protected $fillable = ['fecha_cita','detalles_cita','id_secretaria ','id_paciente '];
protected $fillable = ['fecha_cita','estado','detalles_cita','id_medico','id_paciente'];

public function users()
public function medico()
{
return $this->belongsTo(User::class,'id');
return $this->hasOne(User::class,'id','id_medico');
}
public function paciente()
{
return $this->hasOne(User::class,'id' ,'id_paciente');
}
}
17 changes: 17 additions & 0 deletions app/Models/Especialidad.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;

class Especialidad extends Model
{
use HasFactory;
protected $table = 'especialidades';
protected $primaryKey = 'id_especialidad';
protected $fillable = [
'nombre_especialidad',
'descripcion_especialidad',
];
}
5 changes: 5 additions & 0 deletions app/Models/Persona.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,4 +34,9 @@ public function pariente(){
return $this->belongsTo(Persona::class,'id_pariente','id_persona');
}

public function has_especialidad()
{
return $this->hasMany(Usario_has_especialidad::class,'id_medico','id_persona');
}

}
21 changes: 21 additions & 0 deletions app/Models/Usario_has_especialidad.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;

class Usario_has_especialidad extends Model
{
use HasFactory;
protected $table = 'medicos_has_especialidades';

protected $fillable = [
'id_medico',
'id_especialidad',
];
public function especialidad()
{
return $this->hasOne(Especialidad::class,'id_especialidad','id_especialidad');
}
}
5 changes: 3 additions & 2 deletions database/migrations/2022_09_26_151715_create_citas.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,10 @@ public function up()
$table->increments('id_cita');
$table->dateTime('fecha_cita');
$table->string('detalles_cita');
$table->boolean('estado');
//TODO: arreglar el nullable
$table->Integer('id_secretaria')->unsigned()->nullable();
$table->foreign('id_secretaria')->references('id')->on('users');
$table->Integer('id_medico')->unsigned()->nullable();
$table->foreign('id_medico')->references('id')->on('users');
$table->Integer('id_paciente')->unsigned()->nullable();
$table->foreign('id_paciente')->references('id')->on('users');
$table->timestamps();
Expand Down
29 changes: 29 additions & 0 deletions database/migrations/2022_12_11_051408_create_especialidades.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
<?php

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

return new class extends Migration
{

public function up()
{
Schema::create('especialidades', function (Blueprint $table) {
$table->increments('id_especialidad');
$table->string('nombre_especialidad')->unique();
$table->string('descripcion_especialidad');
$table->timestamps();
});
}

/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::dropIfExists('especialidades');
}
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
<?php

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

return new class extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::create('medicos_has_especialidades', function (Blueprint $table) {
$table->Integer('id_medico')->unsigned()->nullable();
$table->foreign('id_medico')->references('id')->on('users');


$table->Integer('id_especialidad')->unsigned()->nullable();
$table->foreign('id_especialidad')->references('id_especialidad')->on('especialidades');
$table->timestamps();
});
}

/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::dropIfExists('medicos_has_especialidades');
}
};
72 changes: 69 additions & 3 deletions resources/views/admin/Citas/create.blade.php
Original file line number Diff line number Diff line change
@@ -1,25 +1,91 @@
<x-layouts.app>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.6.1/jquery.min.js"></script>
<div class="card">
<div class="card-header">Crear Cita</div>
<div class="card-body">

<form action="{{ url('Citas') }}" method="post">
{!! csrf_field() !!}
<div class="row">
<div class="col-6">
<label for="">Especialidad</label>

<select name="especialidad" class="form-control" id="select1">
<option value="" selected>Selecione una especialidad</option>
@foreach ($Especialidades as $Especialidad)
<option value="{{$Especialidad->id_especialidad}}"> {{$Especialidad->nombre_especialidad}} </option>
@endforeach


</select>
</div>

<div class="col-6">
<label for="">Medico</label>

<select name="id_medico" class="form-control" disabled id="select2">
@foreach ($Users as $User)
@if ($User->rol == 1)
<option value="" selected>Selecione un Medico</option>
@foreach ($User->persona->has_especialidad as $has)
<option data-name="{{$has->id_especialidad}}" value="{{$User->id}}"> {{$User->persona->nombre_per." ". $User->persona->apellido_pa_per ." ". $User->persona->apellido_ma_per}} </option>
@endforeach
@endif
@endforeach


</select>
</div>
</div>

<label>Fecha</label></br>
<input type="date" name="fecha_cita" id="fecha_cita" class="form-control"></br>
<input type="datetime-local" name="fecha_cita" id="fecha_cita" class="form-control"></br>
@error('fecha_cita')
<small style="color: red">{{$message}}</small>
@enderror


<label>Detalles</label></br>
<input value="{{old('detalles_cita')}}" type="text" name="detalles_cita" id="detalles_cita" class="form-control"></br>
@error('detalles_cita')
<small style="color: red">{{$message}}</small>
@enderror
<label>Paciente</label></br>


{{-- <label>Paciente</label></br>
<input value="{{old('id_secretarias')}}" type="text" name="id_secretaria" id="id_secretaria" class="form-control"></br>
<input type="submit" value="Save" class="btn btn-success"></br>
@error('detalles_cita')
<small style="color: red">{{$message}}</small>
@enderror --}}
<input type="submit" value="Registrar Cita" class="btn btn-success"></br>
</form>

</div>
</div>
<script>
$( function() {
$("#select1").change( function() {
if ($(this).val() === "") {
$("#select2").prop("disabled", true);
} else {
$("#select2").prop("disabled", false);
}
});
});
$("#select1").change(function () {
if ($(this).data('options') == undefined) {
$(this).data('options', $('#select2 option').clone());
}
var id = $(this).val();
if (id == "all") {
var options = $(this).data('options');
$('#select2').html(options);
}
else {
var options = $(this).data('options').filter('[data-name=' + id + ']');
$('#select2').html(options);
}
});
</script>
</x-layouts.app>
Loading

0 comments on commit 6ec0568

Please sign in to comment.