diff --git a/app/Http/Controllers/HistorialController.php b/app/Http/Controllers/HistorialController.php index 86d4677..444dd4a 100644 --- a/app/Http/Controllers/HistorialController.php +++ b/app/Http/Controllers/HistorialController.php @@ -3,6 +3,10 @@ namespace App\Http\Controllers; use App\Models\Historial; + +use App\Models\Sede; +use App\Models\User; +use App\Models\Persona; use Illuminate\Http\Request; class HistorialController extends Controller @@ -11,14 +15,21 @@ class HistorialController extends Controller public function index() { // - $Historias = Historial::all(); + $Historias = Historial::with(['personas:id_persona,nombre_per,apellido_pa_per,apellido_ma_per','users.persona:id_persona,nombre_per,apellido_pa_per,apellido_ma_per','sede:id_sede,nombre_sede'])->get(); return view('admin.Historial.index',compact('Historias')); + + //return $Historias; } public function create() { // - return view('admin.Historial.create'); + $Sedes = Sede::all(); + $Users = User::with('persona')->get(); + + return view('admin.Historial.create',compact('Sedes','Users')); + + //return $Users; } public function store(Request $request) @@ -32,20 +43,30 @@ public function store(Request $request) } - public function show(Historial $Historial) + public function show($Historial) { // $Historia= Historial::find($Historial); + $Historial = Historial::with(['personas:id_persona,nombre_per,apellido_pa_per,apellido_ma_per','users.persona:id_persona,nombre_per,apellido_pa_per,apellido_ma_per','sede:id_sede,nombre_sede'])->find($Historial); + return View ('admin.Historial.show',compact('Historial')); + // + } - public function edit($historial) + public function edit($Historial) { // - $Historia= Historial::find($historial); - return View ('admin.Historial.edit',compact('Historia')); + $Sedes = Sede::all(); + $Users = User::with('persona')->get(); + $Historia = Historial::with(['personas:id_persona,nombre_per,apellido_pa_per,apellido_ma_per','users.persona:id_persona,nombre_per,apellido_pa_per,apellido_ma_per','sede:id_sede,nombre_sede'])->find($Historial); + + return View ('admin.Historial.edit',compact('Historia','Sedes','Users')); + + //return $Historia; + } diff --git a/app/Http/Controllers/PersonaController.php b/app/Http/Controllers/PersonaController.php index 27d7163..aa858a0 100644 --- a/app/Http/Controllers/PersonaController.php +++ b/app/Http/Controllers/PersonaController.php @@ -2,7 +2,9 @@ namespace App\Http\Controllers; +use App\Http\Requests\StorePersonaRequest; use App\Models\Persona; +use App\Models\TipoSangre; use Illuminate\Http\Request; use Psy\CodeCleaner\ReturnTypePass; @@ -16,6 +18,7 @@ class PersonaController extends Controller public function index() { $personas = Persona::get(); + //return $personas; return view('admin.Persona.index', compact('personas')); } @@ -26,7 +29,9 @@ public function index() */ public function create() { - return view('admin.Persona.create'); + $personas = Persona::get(); + $tipos_sangre = TipoSangre::get(); + return view('admin.Persona.create', compact('tipos_sangre','personas')); } /** @@ -35,7 +40,7 @@ public function create() * @param \Illuminate\Http\Request $request * @return \Illuminate\Http\Response */ - public function store(Request $request) + public function store(StorePersonaRequest $request) { $datos = $request->all(); Persona::create($datos); diff --git a/app/Http/Controllers/TipoRelacionController.php b/app/Http/Controllers/TipoRelacionController.php index 4916bd6..644aa3d 100644 --- a/app/Http/Controllers/TipoRelacionController.php +++ b/app/Http/Controllers/TipoRelacionController.php @@ -2,6 +2,7 @@ namespace App\Http\Controllers; +use App\Models\Persona; use App\Models\TipoRelacion; use Illuminate\Http\Request; @@ -15,6 +16,7 @@ class TipoRelacionController extends Controller public function index() { $TipoRelaciones = TipoRelacion::get(); + //return $TipoRelaciones; return view('admin.tipo_relacion.index', compact('TipoRelaciones')); } @@ -25,7 +27,8 @@ public function index() */ public function create() { - return view('admin.tipo_relacion.create'); + $personas = Persona::get(); + return view('admin.tipo_relacion.create', compact('personas')); } /** diff --git a/app/Http/Controllers/UsuarioController.php b/app/Http/Controllers/UsuarioController.php new file mode 100644 index 0000000..2c656fa --- /dev/null +++ b/app/Http/Controllers/UsuarioController.php @@ -0,0 +1,83 @@ + + */ + public function rules() + { + return [ + 'nombre_per'=> 'required|string|max:255', + 'apellido_pa_per'=> 'required|string|max:255', + 'apellido_ma_per'=> 'required|string|max:255', + 'ci_per'=> 'required', + 'cel_per'=> 'required', + 'fecha_nac'=> 'required|date', + 'num_seguro'=> 'nullable', + 'donante'=> 'required', + 'id_tipo_sangre'=> 'required', + 'id_pariente'=>'required' + ]; + } +} diff --git a/app/Models/Historial.php b/app/Models/Historial.php index 66aaa09..b7fe245 100644 --- a/app/Models/Historial.php +++ b/app/Models/Historial.php @@ -12,4 +12,20 @@ class Historial extends Model protected $table = 'historial'; protected $primaryKey = 'id_historial'; protected $fillable = ['id_persona','id_sede','id_medico','fecha_historial','detalles_historial']; + public function personas() + { + return $this->belongsTo(Persona::class,'id_persona'); + } + + public function users() + { + return $this->belongsTo(User::class,'id_medico'); + } + + public function sede() + { + return $this->belongsTo(Sede::class,'id_sede'); + } + + } diff --git a/app/Models/Persona.php b/app/Models/Persona.php index c27fdae..c80556e 100644 --- a/app/Models/Persona.php +++ b/app/Models/Persona.php @@ -19,10 +19,19 @@ class Persona extends Model 'fecha_nac', 'num_seguro', 'donante', - 'id_tipo_sangre' + 'id_tipo_sangre', + 'id_pariente' + ]; + protected $dates = [ + 'fecha_nac' ]; public function tipo_sangre(){ return $this->belongsTo(TipoSangre::class,'id_tipo_sangre','id_tipo_sangre'); } + + public function pariente(){ + return $this->belongsTo(Persona::class,'id_pariente','id_persona'); + } + } diff --git a/app/Models/User.php b/app/Models/User.php index 7ac239b..6665665 100644 --- a/app/Models/User.php +++ b/app/Models/User.php @@ -43,4 +43,8 @@ class User extends Authenticatable protected $casts = [ 'email_verified_at' => 'datetime', ]; + public function persona() + { + return $this->belongsTo(Persona::class,'id_persona','id_persona'); + } } diff --git a/database/migrations/2022_08_23_053433_create_tipo_sangres_table.php b/database/migrations/2022_08_23_053433_create_tipo_sangres_table.php index c7a360d..2434997 100644 --- a/database/migrations/2022_08_23_053433_create_tipo_sangres_table.php +++ b/database/migrations/2022_08_23_053433_create_tipo_sangres_table.php @@ -13,7 +13,6 @@ */ public function up() { - Schema::create('tipos_sangre', function (Blueprint $table) { $table->increments('id_tipo_sangre'); $table->string('nombre_tipo_sangre')->unique(); diff --git a/database/migrations/2022_09_22_152240_create_personas.php b/database/migrations/2022_09_22_152240_create_personas.php index d20801c..1810792 100644 --- a/database/migrations/2022_09_22_152240_create_personas.php +++ b/database/migrations/2022_09_22_152240_create_personas.php @@ -25,6 +25,8 @@ public function up() $table->date('fecha_nac'); $table->Integer('id_tipo_sangre')->unsigned(); $table->foreign('id_tipo_sangre')->references('id_tipo_sangre')->on('tipos_sangre'); + $table->integer('id_pariente')->unsigned()->nullable(); + $table->foreign('id_pariente')->references('id_persona')->on('personas'); $table->timestamps(); }); } diff --git a/database/migrations/2022_09_26_151743_create_tipo_relacion.php b/database/migrations/2022_09_26_151743_create_tipo_relacion.php index 9a02dbd..af7710e 100644 --- a/database/migrations/2022_09_26_151743_create_tipo_relacion.php +++ b/database/migrations/2022_09_26_151743_create_tipo_relacion.php @@ -14,7 +14,7 @@ public function up() { Schema::create('tipo_relacion', function (Blueprint $table) { - $table->increments('id_tipo_rel'); + $table->increments('id_tipo_relacion'); $table->string('relacion'); $table->Integer('id_persona')->unsigned(); $table->foreign('id_persona')->references('id_persona')->on('personas'); diff --git a/resources/views/admin/Historial/create.blade.php b/resources/views/admin/Historial/create.blade.php index e325ee8..d00ca50 100644 --- a/resources/views/admin/Historial/create.blade.php +++ b/resources/views/admin/Historial/create.blade.php @@ -5,29 +5,52 @@