/** * Deletes a particular model. * If deletion is successful, the browser will be redirected to the 'admin' page. * @param integer $id the ID of the model to be deleted */ public function actionDelete($id) { $model = $this->loadModel($id); $resultado = Pacientes::model()->countByAttributes(array('idAseguradora' => $model->idAseguradora)); if ($resultado > 0) { throw new CHttpException(404, 'No se puede realizar el borrado'); } else { $model->delete(); // if AJAX request (triggered by deletion via admin grid view), we should not redirect the browser if (!isset($_GET['ajax'])) { $this->redirect(isset($_POST['returnUrl']) ? $_POST['returnUrl'] : array('admin')); } } }
public function populate() { require '../vendor/autoload.php'; // Pacientes for ($i = 0; $i < 200; $i++) { $faker = Faker\Factory::create('es_ES'); //$nb = array('mujer','varon'); $nombre = $faker->firstname; $numerohistoria = $faker->unique()->randomNumber(4); $apellido1 = $faker->lastname; $apellido2 = $faker->lastname; $NIF_nr = $faker->randomNumber(8); $NIF_ltr = $faker->randomLetter; $NIF = $NIF_nr . $NIF_ltr; $fechanacimiento = $faker->dateTimeThisCentury; $title = $faker->title; if ($title == 'Mr.') { $sexo = "varon"; } else { $sexo = "mujer"; } //$sexo = $faker->words('mujer','varon'); $Direccion = $faker->streetAddress; $addrnamestre = $faker->streetName; $addrtel1 = $faker->phoneNumber; $addrtel2 = $faker->phoneNumber; $terrdesc = $faker->state; $addrpostcode = $faker->postcode; $compania = $faker->numberBetween(1, 7); $compania2 = $faker->numberBetween(0, 3); while ($compania2 == $compania) { $compania2 = $faker->numberBetween(0, 3); } $populator = array('numerohistoria' => $numerohistoria, 'apellido1' => $apellido1, 'apellido2' => $apellido2, 'nombre' => $nombre, 'NIF' => $NIF, 'fechanacimiento' => $fechanacimiento, 'sexo' => $sexo, 'Direccion' => $Direccion, 'addrnamestre' => $addrnamestre, 'addrtel1' => $addrtel1, 'addrtel2' => $addrtel2, 'terrdesc' => $terrdesc, 'addrpostcode' => $addrpostcode, 'compania' => $compania, 'compania2' => $compania2); //Populate::; Pacientes::create($populator); } //$extracto = Populate::table('pacientes')->lists('nombre','sexo'); //var_dump($extracto); // Profesionales for ($i = 0; $i < 4; $i++) { $faker = Faker\Factory::create('es_ES'); $nombre = $faker->firstname; $apellido1 = $faker->lastname; $apellido2 = $faker->lastname; $especialidades_id = $faker->randomNumber(4); $populator = array('nombre' => $nombre, 'apellido1' => $apellido1, 'apellido2' => $apellido2, 'especialidades_id' => $especialidades_id); PopulateProfesional::create($populator); } }
public function scopePaciente($query, $numerohistoria) { $paciente = Pacientes::where('numerohistoria', $numerohistoria)->first(); $companias = array(); $companias[] = $paciente->compania; if (is_numeric($paciente->compania2)) { $companias[] = $paciente->compania2; } $preciosObj = $query->whereIn('companias_id', $companias)->get(array('tratamientos_id', 'precio', 'companias_id')); $precios = array(); foreach ($preciosObj as $p) { $precios[$p->tratamientos_id][$p->companias_id] = $p->precio; } return $precios; }
/** * Display the specified resource. * * @param int $id * @return Response */ public function verpresupuestos($numerohistoria) { $paciente_b = Pacientes::where('numerohistoria', $numerohistoria)->firstOrFail(); $companias_list = Companias::lists('nombre', 'id'); $paciente_b->companias_text = $companias_list[$paciente_b->compania]; if ($paciente_b->compania2 != 0) { $paciente_b->companias_text .= ' y ' . $companias_list[$paciente_b->compania2]; } $profesionales1 = Profesional::get(array(DB::raw("CONCAT_WS(' ', nombre, apellido1, apellido2) AS nombre"), 'id')); $profesionales = array(); foreach ($profesionales1 as $p) { $profesionales[$p->id] = $p->nombre; } $users1 = User::get(array(DB::raw("CONCAT_WS(' ', firstname, lastname) AS nombre"), 'id')); $users = array(); foreach ($users1 as $u) { $users[$u->id] = $u->nombre; } $presupuestos = Presupuestos::where('numerohistoria', $numerohistoria)->select('presupuestos.*', DB::raw("DATE_FORMAT(presupuestos.created_at, '%d/%m/%Y') as creado"), DB::raw("DATE_FORMAT(presupuestos.updated_at, '%d/%m/%Y') as actualizado"))->orderBy('updated_at', 'desc')->get(); $precios = Precios::paciente($numerohistoria); foreach ($presupuestos as $p) { $total = 0; $tratamientos = $p->tratamientos()->get(array('presupuestos_tratamientos.*', 'tratamientos.nombre')); foreach ($tratamientos as $t) { $total += $t->precio_final; } if ($p->tipodescuento == 'P') { $descuento = $p->descuento * $total / 100; $descuentotext = $p->descuento . '%'; } else { $descuento = $p->descuento; $descuentotext = $p->descuento . '€'; } $p->importe_total = $total - $descuento; $p->descuentototal = $descuentotext; $p->profesional_n = $profesionales[$p->profesional_id]; $p->user_n = $users[$p->user_id]; } return View::make('presupuestos.presupuestos')->with('paciente', $paciente_b)->with(array('presupuestos' => $presupuestos)); }
/** * Returns the data model based on the primary key given in the GET variable. * If the data model is not found, an HTTP exception will be raised. * @param integer $id the ID of the model to be loaded * @return Pacientes the loaded model * @throws CHttpException */ public function loadModel($id) { $model = Pacientes::model()->findByPk($id); if ($model === null) { throw new CHttpException(404, 'The requested page does not exist.'); } return $model; }
public function busqueda() { $q_busca = Input::get('q', ''); if ($q_busca != '') { $busca = '%' . $q_busca . '%'; $pacientes = Pacientes::where(DB::raw('concat(pacientes.nombre, " ", pacientes.apellido1, " ", pacientes.apellido2)'), 'LIKE', $busca)->orWhere(DB::raw('concat(pacientes.apellido1, " ", pacientes.apellido2, " ", pacientes.nombre)'), 'LIKE', $busca)->orWhere('numerohistoria', 'LIKE', $busca)->get(); } else { return Redirect::action('Historial_clinicoController@index'); } return View::make('historial.busqueda')->with(array('pacientes' => $pacientes, 'busca' => $q_busca)); }
/** * Show the form for editing the specified resource. * * @param int $id * @return Response */ public function update($id) { $paciente = Pacientes::find($id); $paciente->update(Input::all()); return Redirect::action('PacientesController@index')->with('message', 'Paciente modificado con éxito.'); }