/** * Store a newly created resource in storage. * * @return Response */ public function store() { $data = Input::all(); $rules = array('cedula' => 'unique:pacientes,cedula'); $validator = Validator::make(array('cedula' => $data['cedula']), $rules); if ($validator->fails()) { return Redirect::back()->withInput()->withErrors($validator); } else { $paciente = new Paciente(); $paciente->primer_nombre = $data['primer_nombre']; $paciente->segundo_nombre = $data['segundo_nombre']; $paciente->primer_apellido = $data['primer_apellido']; $paciente->segundo_apellido = $data['segundo_apellido']; $paciente->cedula = $data['cedula']; $paciente->sexo = $data['sexo']; $paciente->id_tipo_sangre = $data['id_tipo_sangre']; $paciente->fecha_nacimiento = $data['fecha_nacimiento']; $paciente->ocupacion = $data['ocupacion']; $paciente->diabetes = $data['diabetes']; $paciente->clasificacion = $data['clasificacion']; $paciente->examen = $data['examen']; $paciente->referido_por = $data['referido_por']; $paciente->observaciones = $data['observaciones']; $paciente->direccion = $data['direccion']; $paciente->telefono = $data['telefono']; $paciente->celular = $data['celular']; $paciente->email = $data['email']; $paciente->save(); return Redirect::route('datos.pacientes.index'); } }
/** * Performs the work of inserting or updating the row in the database. * * If the object is new, it inserts it; otherwise an update is performed. * All related objects are also updated in this method. * * @param PropelPDO $con * @return int The number of rows affected by this insert/update and any referring fk objects' save() operations. * @throws PropelException * @see save() */ protected function doSave(PropelPDO $con) { $affectedRows = 0; // initialize var to track total num of affected rows if (!$this->alreadyInSave) { $this->alreadyInSave = true; // We call the save method on the following object(s) if they // were passed to this object by their corresponding set // method. This object relates to these object(s) by a // foreign key reference. if ($this->aPaciente !== null) { if ($this->aPaciente->isModified() || $this->aPaciente->isNew()) { $affectedRows += $this->aPaciente->save($con); } $this->setPaciente($this->aPaciente); } if ($this->isNew() || $this->isModified()) { // persist changes if ($this->isNew()) { $this->doInsert($con); } else { $this->doUpdate($con); } $affectedRows += 1; $this->resetModified(); } if ($this->cargoventasScheduledForDeletion !== null) { if (!$this->cargoventasScheduledForDeletion->isEmpty()) { CargoventaQuery::create()->filterByPrimaryKeys($this->cargoventasScheduledForDeletion->getPrimaryKeys(false))->delete($con); $this->cargoventasScheduledForDeletion = null; } } if ($this->collCargoventas !== null) { foreach ($this->collCargoventas as $referrerFK) { if (!$referrerFK->isDeleted() && ($referrerFK->isNew() || $referrerFK->isModified())) { $affectedRows += $referrerFK->save($con); } } } if ($this->facturasScheduledForDeletion !== null) { if (!$this->facturasScheduledForDeletion->isEmpty()) { foreach ($this->facturasScheduledForDeletion as $factura) { // need to save related object because we set the relation to null $factura->save($con); } $this->facturasScheduledForDeletion = null; } } if ($this->collFacturas !== null) { foreach ($this->collFacturas as $referrerFK) { if (!$referrerFK->isDeleted() && ($referrerFK->isNew() || $referrerFK->isModified())) { $affectedRows += $referrerFK->save($con); } } } $this->alreadyInSave = false; } return $affectedRows; }
/** * Performs the work of inserting or updating the row in the database. * * If the object is new, it inserts it; otherwise an update is performed. * All related objects are also updated in this method. * * @param PropelPDO $con * @return int The number of rows affected by this insert/update and any referring fk objects' save() operations. * @throws PropelException * @see save() */ protected function doSave(PropelPDO $con) { $affectedRows = 0; // initialize var to track total num of affected rows if (!$this->alreadyInSave) { $this->alreadyInSave = true; // We call the save method on the following object(s) if they // were passed to this object by their corresponding set // method. This object relates to these object(s) by a // foreign key reference. if ($this->aMedico !== null) { if ($this->aMedico->isModified() || $this->aMedico->isNew()) { $affectedRows += $this->aMedico->save($con); } $this->setMedico($this->aMedico); } if ($this->aPaciente !== null) { if ($this->aPaciente->isModified() || $this->aPaciente->isNew()) { $affectedRows += $this->aPaciente->save($con); } $this->setPaciente($this->aPaciente); } if ($this->isNew() || $this->isModified()) { // persist changes if ($this->isNew()) { $this->doInsert($con); } else { $this->doUpdate($con); } $affectedRows += 1; $this->resetModified(); } $this->alreadyInSave = false; } return $affectedRows; }
/** * Update the specified resource in storage. * * @param int $id * @return Response */ public function update($id) { $foto = Input::file('foto'); $paciente = Paciente::find($id); $data = Input::all(); //Pregunto si no es nulo la variable foto y asi saber si seleccione una nueva foto if (!is_null($foto)) { //Si no es nulo fue que seleccione una foto //Extraigo la extension de la foto $extension = $foto->getClientOriginalExtension(); //Armo el nombre de la foto con el id y la extension de la nueva foto $nombre_foto = 'p_' . $id . '.' . $extension; //Ingreso el nuevo nombre de la foto en la base de datos con todo y extension $paciente->foto = $nombre_foto; //Busco en la carpeta de foto si existe alguna foto con ese mismo nombre y extension y la elimino File::delete('./imgs/' . $nombre_foto); //Muevo la nueva foto a la carpeta imgs $foto->move("imgs", $nombre_foto); } //Si en caso el paciente fue borrado justo cuando fue editado se almacenara de nuevo if (is_null($paciente)) { $paciente = new Paciente(); } //Sentencias para almacenar los datos correspondientes de cada paciente $paciente->cedula = $data['cedula']; $paciente->primer_nombre = $data['primer_nombre']; $paciente->segundo_nombre = $data['segundo_nombre']; $paciente->apellido_paterno = $data['apellido_paterno']; $paciente->apellido_materno = $data['apellido_materno']; $paciente->sexo = $data['sexo']; $paciente->fecha_nacimiento = $data['fecha_nacimiento']; $paciente->lugar_nacimiento = $data['lugar_nacimiento']; $paciente->id_provincia_nacimiento = $data['id_provincia']; $paciente->id_distrito_nacimiento = $data['id_distrito']; $paciente->id_corregimiento_nacimiento = $data['id_corregimiento']; $paciente->id_provincia_residencia = $data['id_provincia_residencia']; $paciente->id_distrito_residencia = $data['id_distrito_residencia']; $paciente->id_corregimiento_residencia = $data['id_corregimiento_residencia']; $paciente->lugar_residencia = $data['lugar_residencia']; $paciente->telefono = $data['telefono']; $paciente->celular = $data['celular']; $paciente->email = $data['email']; $paciente->id_nacionalidad = $data['id_nacionalidad']; $paciente->id_tipo_sangre = $data['id_tipo_sanguineo']; $paciente->id_raza = $data['id_raza']; $paciente->id_etnia = $data['id_etnia']; $paciente->diabetes = $data['diabetes']; $paciente->fuma = $data['fuma']; $paciente->embarazo_trisomia = $data['embarazo_trisomia']; $paciente->save(); return Redirect::route('datos.pacientes.index'); }
/** * Display a listing of the resource. * * @return Response */ public function DatosGenerales() { $antiguaTabla = DB::table('GRALES')->where('ced', '<>', '')->get(); //$antiguaTabla = DB::table('GRALES')->where('', '4-807-2005')->get(); $x = 0; foreach ($antiguaTabla as $datos) { $x++; $NuevaTabla = new Paciente(); $PrimerNombre = ''; $SegundoNombre = ''; $PrimerApellido = ''; $SegundoApellido = ''; $nombres = explode(" ", $datos->nombre); $x = 1; foreach ($nombres as $nombre) { if ($x == 1) { $PrimerNombre = $nombre; $x = 0; } else { $SegundoNombre .= $nombre . ' '; } } $apellidos = explode(" ", $datos->apellido); $x = 1; foreach ($apellidos as $apellido) { if ($x == 1) { $PrimerApellido = $apellido; $x = 0; } else { $SegundoApellido .= $apellido . ' '; } } $NuevaTabla->primer_nombre = $PrimerNombre; $NuevaTabla->segundo_nombre = $SegundoNombre; $NuevaTabla->primer_apellido = $PrimerApellido; $NuevaTabla->segundo_apellido = $SegundoApellido; $NuevaTabla->cedula = $datos->ced; $NuevaTabla->id_tipo_sangre = 1; if ($datos->sexo == 'F') { $NuevaTabla->sexo = 0; } else { $NuevaTabla->sexo = 1; } $NuevaTabla->celular = $datos->tel; $NuevaTabla->telefono = $datos->tel2; $NuevaTabla->email = $datos->tel3; $NuevaTabla->fecha_nacimiento = $datos->fech_cump; $NuevaTabla->ocupacion = $datos->ocup; $NuevaTabla->direccion = $datos->direc; $NuevaTabla->examen = $datos->eg; $dataFicha = Ficha::where('ced', $datos->ced)->first(); $diabetes = 0; if (!empty($dataFicha)) { if ($dataFicha->diab == 'SI') { $diabetes = 1; } $NuevaTabla->observaciones = $dataFicha->obs1 . $dataFicha->obs2; } $NuevaTabla->diabetes = $diabetes; $NuevaTabla->referido_por = $datos->ref; $NuevaTabla->clasificacion = $datos->clasif; $NuevaTabla->save(); } echo 'Pacientes Nuevos: ' . $x . ''; }