2020-05-18 15:42:14 +02:00
|
|
|
<?php
|
|
|
|
|
2020-06-22 23:00:43 +02:00
|
|
|
function connectDatabase()
|
|
|
|
{
|
2020-06-17 04:33:48 +02:00
|
|
|
$connection = 'unix_socket';
|
2020-06-21 19:36:38 +02:00
|
|
|
$host = '../.mysql/mysql.sock';
|
2020-05-18 15:42:14 +02:00
|
|
|
$charset = 'utf8mb4';
|
2020-06-17 04:33:48 +02:00
|
|
|
$db = 'practica';
|
|
|
|
$dsn = "mysql:$connection=$host;dbname=$db;charset=$charset";
|
|
|
|
$pdo = new PDO($dsn, "practica", "practica");
|
2020-06-14 03:12:32 +02:00
|
|
|
return $pdo;
|
2020-05-18 15:42:14 +02:00
|
|
|
}
|
|
|
|
|
2020-06-22 23:00:43 +02:00
|
|
|
function closeDatabase($pdo)
|
|
|
|
{
|
2020-06-14 03:12:32 +02:00
|
|
|
$pdo = null;
|
2020-05-18 15:42:14 +02:00
|
|
|
}
|
2020-06-14 03:12:32 +02:00
|
|
|
|
2020-06-22 23:00:43 +02:00
|
|
|
function listRows($pdo, $table)
|
|
|
|
{
|
2020-06-14 03:12:32 +02:00
|
|
|
$query = "SELECT * FROM ?";
|
|
|
|
$result = $pdo->prepare($query)->execute([$table]);
|
2020-06-17 04:10:09 +02:00
|
|
|
return $result;
|
2020-06-14 03:12:32 +02:00
|
|
|
}
|
|
|
|
|
2020-06-22 23:00:43 +02:00
|
|
|
function createPatient($pdo, $data)
|
|
|
|
{
|
2020-06-16 18:56:35 +02:00
|
|
|
$query = "INSERT INTO paciente
|
|
|
|
(nombre, apellido, fecha_de_nacimiento, documento_identificativo, tipo_documento, direccion, localidad, provincia, pais)
|
|
|
|
VALUES (?,?,?,?,?,?,?,?,?)";
|
|
|
|
$pdo->prepare($query)->execute([$data["nombre"], $data["apellido"], $data["fecha_de_nacimiento"],
|
|
|
|
$data["documento_identificativo"], $data["tipo_documento"], $data["direccion"],
|
|
|
|
$data["localidad"], $data["provincia"], $data["pais"]]);
|
2020-06-14 03:12:32 +02:00
|
|
|
return "Paciente creado con éxito";
|
|
|
|
}
|
|
|
|
|
2020-06-22 23:00:43 +02:00
|
|
|
function editPatient($pdo, $data, $id)
|
|
|
|
{
|
2020-06-17 08:42:53 +02:00
|
|
|
$query = "UPDATE paciente SET nombre=?, apellido=?, fecha_de_nacimiento=?, documento_identificativo=?,
|
|
|
|
tipo_documento=?, direccion=?, localidad=?, provincia=?, pais=? WHERE id=?";
|
|
|
|
$result = $pdo->prepare($query);
|
|
|
|
$result->execute([$data["nombre"], $data["apellido"], $data["fecha_de_nacimiento"],
|
|
|
|
$data["documento_identificativo"], $data["tipo_documento"], $data["direccion"],
|
|
|
|
$data["localidad"], $data["provincia"], $data["pais"], $id]);
|
2020-06-14 03:12:32 +02:00
|
|
|
return "Paciente modificado con éxito";
|
|
|
|
}
|
|
|
|
|
2020-06-22 23:00:43 +02:00
|
|
|
function deletePatient($pdo, string $id)
|
|
|
|
{
|
2020-06-14 03:12:32 +02:00
|
|
|
$check = "SELECT * FROM informes where paciente = ?";
|
2020-06-17 08:42:53 +02:00
|
|
|
$result = $pdo->prepare($check);
|
|
|
|
$result->execute([$id]);
|
2020-06-22 23:00:43 +02:00
|
|
|
if ($result->columnCount() == 0) {
|
2020-06-17 08:42:53 +02:00
|
|
|
$statement = "DELETE FROM paciente where id=?";
|
2020-06-14 03:12:32 +02:00
|
|
|
$pdo->prepare($statement)->execute([$id]);
|
|
|
|
return "El paciente se ha eliminado correctamente";
|
|
|
|
}
|
|
|
|
return "No se puede eliminar el paciente dado que tiene citas";
|
|
|
|
}
|
|
|
|
|
2020-06-22 23:00:43 +02:00
|
|
|
function createHoliday($pdo, $data)
|
|
|
|
{
|
|
|
|
if (empty($data["medico"])) {
|
2020-06-18 09:04:44 +02:00
|
|
|
$query = "INSERT INTO festivo (fecha_festivo, tipo_festivo, medico) VALUES (?,?,?)";
|
|
|
|
$pdo->prepare($query)->execute([$data["fecha_festivo"], $data["tipo_festivo"], $data["medico"]]);
|
|
|
|
} else {
|
|
|
|
$query = "INSERT INTO festivo (fecha_festivo, tipo_festivo) VALUES (?,?)";
|
|
|
|
$pdo->prepare($query)->execute([$data["fecha_festivo"], $data["tipo_festivo"]]);
|
|
|
|
}
|
2020-06-14 03:12:32 +02:00
|
|
|
return "Festivo creado con éxito";
|
|
|
|
}
|
|
|
|
|
2020-06-22 23:00:43 +02:00
|
|
|
function editHoliday($pdo, $data, $id)
|
|
|
|
{
|
2020-06-18 09:04:44 +02:00
|
|
|
$query = "UPDATE festivo SET fecha_festivo=?, tipo_festivo=?, medico=? WHERE id=?";
|
|
|
|
$pdo->prepare($query)->execute([$data["fecha_festivo"], $data["tipo_festivo"], $data["medico"], $id]);
|
2020-06-14 03:12:32 +02:00
|
|
|
return "Festivo modificado con éxito";
|
|
|
|
}
|
|
|
|
|
2020-06-22 23:00:43 +02:00
|
|
|
function deleteHoliday($pdo, $id)
|
|
|
|
{
|
2020-06-18 09:04:44 +02:00
|
|
|
$statement = "DELETE FROM festivo where id=?";
|
2020-06-14 03:12:32 +02:00
|
|
|
$pdo->prepare($statement)->execute([$id]);
|
|
|
|
return "Festivo borrado con éxito";
|
|
|
|
}
|
|
|
|
|
2020-06-22 23:00:43 +02:00
|
|
|
function createUser($pdo, $data)
|
|
|
|
{
|
2020-06-16 18:56:35 +02:00
|
|
|
$query = "INSERT INTO usuario (nombre, usuario, contraseña, rol, correo) VALUES (?,?,?,?,?)";
|
2020-06-14 04:25:11 +02:00
|
|
|
$pdo->prepare($query)->execute([$data["nombre"], $data["usuario"], $data["contraseña"], $data["rol"], $data["correo"]]);
|
2020-06-14 03:12:32 +02:00
|
|
|
return "Usuario creado con éxito";
|
|
|
|
}
|
|
|
|
|
2020-06-22 23:00:43 +02:00
|
|
|
function editUser($pdo, $data, $id)
|
|
|
|
{
|
2020-06-17 04:10:09 +02:00
|
|
|
$query = "UPDATE usuario SET nombre=?, usuario=?, contraseña=?, rol=?, correo=? WHERE id=?";
|
|
|
|
$result = $pdo->prepare($query);
|
|
|
|
$result->execute([$data["nombre"], $data["usuario"], $data["contraseña"], $data["rol"], $data["correo"], $id]);
|
2020-06-14 03:12:32 +02:00
|
|
|
return "Usuario modificado con éxito";
|
|
|
|
}
|
|
|
|
|
2020-06-22 23:00:43 +02:00
|
|
|
function deactivateUser($pdo, $data, $id)
|
|
|
|
{
|
2020-06-17 04:10:09 +02:00
|
|
|
$query = "UPDATE usuario SET fecha_baja=now() WHERE id=?";
|
|
|
|
$result = $pdo->prepare($query);
|
|
|
|
$result->execute([$id]);
|
2020-06-14 03:12:32 +02:00
|
|
|
return "Usuario desactivado con éxito";
|
|
|
|
}
|
|
|
|
|
2020-06-22 23:00:43 +02:00
|
|
|
function listUsers($pdo)
|
|
|
|
{
|
2020-06-17 04:10:09 +02:00
|
|
|
$query = "SELECT usuario.nombre, usuario.usuario, rol.nombre, usuario.correo, usuario.id, fecha_baja FROM usuario
|
2020-06-16 22:50:35 +02:00
|
|
|
INNER JOIN rol ON usuario.rol = rol.codigo";
|
|
|
|
$result = $pdo->query($query)->fetchAll();
|
|
|
|
return $result;
|
|
|
|
}
|
|
|
|
|
2020-06-22 23:00:43 +02:00
|
|
|
function fetchUserData($pdo, string $id)
|
|
|
|
{
|
2020-06-17 04:10:09 +02:00
|
|
|
$query = "SELECT * FROM usuario WHERE id=?";
|
|
|
|
$result = $pdo->prepare($query);
|
2020-06-17 05:34:36 +02:00
|
|
|
$result->execute([$id]);
|
|
|
|
$data = $result->fetch();
|
|
|
|
return $data;
|
|
|
|
}
|
|
|
|
|
2020-06-22 23:00:43 +02:00
|
|
|
function findUser($pdo, $input)
|
|
|
|
{
|
2020-06-17 05:34:36 +02:00
|
|
|
$input = "%$input%";
|
|
|
|
$query = "SELECT usuario.nombre, usuario.usuario, rol.nombre, usuario.correo, usuario.id, fecha_baja
|
|
|
|
FROM usuario, rol WHERE usuario.rol=rol.codigo AND (usuario.nombre LIKE ? OR usuario.usuario LIKE ? OR usuario.correo LIKE ?)";
|
|
|
|
$result = $pdo->prepare($query);
|
|
|
|
$result->execute([$input, $input, $input]);
|
|
|
|
$data = $result->fetchAll();
|
2020-06-17 04:10:09 +02:00
|
|
|
return $data;
|
|
|
|
}
|
|
|
|
|
2020-06-22 23:00:43 +02:00
|
|
|
function listPatients($pdo)
|
|
|
|
{
|
2020-06-17 12:08:52 +02:00
|
|
|
$query = "SELECT paciente.id, paciente.nombre, paciente.apellido, paciente.fecha_de_nacimiento, paciente.documento_identificativo,
|
2020-06-18 09:04:44 +02:00
|
|
|
paciente.tipo_documento, paciente.direccion, municipios.nombre, provincias.provincia, paciente.pais, cita.id, informe.titulo
|
|
|
|
FROM paciente INNER JOIN municipios ON paciente.localidad = municipios.id_municipio
|
|
|
|
INNER JOIN provincias ON paciente.provincia = provincias.id_provincia
|
|
|
|
LEFT JOIN cita ON paciente.id=cita.paciente LEFT JOIN informe ON paciente.id=informe.paciente
|
2020-06-17 12:08:52 +02:00
|
|
|
GROUP BY paciente.id, cita.id, informe.titulo";
|
|
|
|
$result = $pdo->prepare($query);
|
|
|
|
$result->execute();
|
|
|
|
$data = $result->fetchAll();
|
|
|
|
return $data;
|
2020-06-17 08:42:53 +02:00
|
|
|
}
|
|
|
|
|
2020-06-17 12:08:52 +02:00
|
|
|
|
2020-06-22 23:00:43 +02:00
|
|
|
function fetchPatientData($pdo, string $id)
|
|
|
|
{
|
2020-06-17 08:42:53 +02:00
|
|
|
$query = "SELECT * FROM paciente WHERE id=?";
|
|
|
|
$result = $pdo->prepare($query);
|
|
|
|
$result->execute([$id]);
|
|
|
|
$data = $result->fetch();
|
|
|
|
return $data;
|
|
|
|
}
|
|
|
|
|
2020-06-22 23:00:43 +02:00
|
|
|
function findPatient($pdo, $input)
|
|
|
|
{
|
2020-06-17 08:42:53 +02:00
|
|
|
$input = "%$input%";
|
|
|
|
$query = "SELECT * FROM paciente WHERE nombre LIKE ? OR apellido LIKE ? OR documento_identificativo LIKE ?";
|
|
|
|
$result = $pdo->prepare($query);
|
|
|
|
$result->execute([$input, $input, $input]);
|
|
|
|
$data = $result->fetchAll();
|
|
|
|
return $data;
|
|
|
|
}
|
|
|
|
|
2020-06-22 23:00:43 +02:00
|
|
|
function fetchCities($pdo, $id)
|
|
|
|
{
|
2020-06-17 22:02:27 +02:00
|
|
|
$query = "SELECT * FROM municipios WHERE id_provincia=?";
|
|
|
|
$result = $pdo->prepare($query);
|
|
|
|
$result->execute([$id]);
|
|
|
|
$data = $result->fetchAll();
|
|
|
|
return $data;
|
|
|
|
}
|
|
|
|
|
2020-06-22 23:00:43 +02:00
|
|
|
function fetchRegions($pdo)
|
|
|
|
{
|
2020-06-17 22:02:27 +02:00
|
|
|
$query = "SELECT * FROM provincias";
|
|
|
|
$result = $pdo->prepare($query);
|
|
|
|
$result->execute();
|
|
|
|
$data = $result->fetchAll();
|
|
|
|
return $data;
|
|
|
|
}
|
|
|
|
|
2020-06-25 21:15:52 +02:00
|
|
|
function fetchHolidays($pdo)
|
2020-06-22 23:00:43 +02:00
|
|
|
{
|
2020-06-18 09:04:44 +02:00
|
|
|
$query = "SELECT * FROM festivo";
|
|
|
|
$result = $pdo->prepare($query);
|
|
|
|
$result->execute();
|
|
|
|
$data = $result->fetchAll();
|
|
|
|
return $data;
|
|
|
|
}
|
|
|
|
|
2020-06-22 23:00:43 +02:00
|
|
|
function listDoctors($pdo)
|
|
|
|
{
|
2020-06-18 09:04:44 +02:00
|
|
|
$query = "SELECT * FROM usuario where rol=2";
|
|
|
|
$result = $pdo->prepare($query);
|
|
|
|
$result->execute();
|
|
|
|
$data = $result->fetchAll();
|
|
|
|
return $data;
|
|
|
|
}
|
|
|
|
|
2020-06-22 23:00:43 +02:00
|
|
|
function fetchHolidayData($pdo, string $id)
|
|
|
|
{
|
2020-06-18 09:04:44 +02:00
|
|
|
$query = "SELECT * FROM festivo WHERE id=?";
|
|
|
|
$result = $pdo->prepare($query);
|
|
|
|
$result->execute([$id]);
|
|
|
|
$data = $result->fetch();
|
|
|
|
return $data;
|
|
|
|
}
|
|
|
|
|
2020-06-22 23:00:43 +02:00
|
|
|
function listReports($pdo)
|
|
|
|
{
|
2020-06-18 12:24:13 +02:00
|
|
|
$query = "SELECT informe.id, informe.titulo, informe.fecha, informe.hora, paciente.apellido,
|
|
|
|
usuario.nombre FROM informe INNER JOIN paciente ON paciente.id = informe.paciente
|
|
|
|
INNER JOIN usuario ON usuario.id = informe.medico";
|
|
|
|
$result = $pdo->prepare($query);
|
|
|
|
$result->execute();
|
|
|
|
$data = $result->fetchAll();
|
|
|
|
return $data;
|
|
|
|
}
|
|
|
|
|
2020-06-22 23:00:43 +02:00
|
|
|
function createReport($pdo, $data)
|
|
|
|
{
|
2020-06-18 12:24:13 +02:00
|
|
|
$query = "INSERT INTO informe
|
|
|
|
(fecha, hora, paciente, titulo, contenido, medico)
|
|
|
|
VALUES (?,?,?,?,?,?)";
|
|
|
|
$pdo->prepare($query)->execute([$data["fecha"], $data["hora"], $data["paciente"],
|
|
|
|
$data["titulo"], $data["contenido"], $data["medico"]]);
|
|
|
|
return "Informe creado con éxito";
|
|
|
|
}
|
|
|
|
|
2020-06-22 23:00:43 +02:00
|
|
|
function editReport($pdo, $data, $id)
|
|
|
|
{
|
2020-06-18 12:24:13 +02:00
|
|
|
$query = "UPDATE informe SET fecha=?, hora=?, paciente=?, titulo=?, contenido=?, medico=? WHERE id=?";
|
|
|
|
$pdo->prepare($query)->execute([$data["fecha"], $data["hora"], $data["paciente"],
|
|
|
|
$data["titulo"], $data["contenido"], $data["medico"], $id]);
|
|
|
|
return "Informe modificado con éxito";
|
|
|
|
}
|
|
|
|
|
2020-06-22 23:00:43 +02:00
|
|
|
function deleteReport($pdo, $id)
|
|
|
|
{
|
2020-06-18 12:24:13 +02:00
|
|
|
$statement = "DELETE FROM informe where id=?";
|
|
|
|
$pdo->prepare($statement)->execute([$id]);
|
|
|
|
return "Informe borrado con éxito";
|
|
|
|
}
|
|
|
|
|
2020-06-22 23:00:43 +02:00
|
|
|
function fetchPatients($pdo)
|
|
|
|
{
|
2020-06-18 12:24:13 +02:00
|
|
|
$query = "SELECT id, apellido from paciente";
|
|
|
|
$result = $pdo->prepare($query);
|
|
|
|
$result->execute();
|
|
|
|
$data = $result->fetchAll();
|
|
|
|
return $data;
|
|
|
|
}
|
|
|
|
|
2020-06-22 23:00:43 +02:00
|
|
|
function fetchReportData($pdo, string $id)
|
|
|
|
{
|
2020-06-18 12:24:13 +02:00
|
|
|
$query = "SELECT * FROM informe WHERE id=?";
|
|
|
|
$result = $pdo->prepare($query);
|
|
|
|
$result->execute([$id]);
|
|
|
|
$data = $result->fetch();
|
|
|
|
return $data;
|
|
|
|
}
|
|
|
|
|
2020-06-22 23:00:43 +02:00
|
|
|
function fetchLoginData($pdo, $data)
|
|
|
|
{
|
2020-06-18 14:48:12 +02:00
|
|
|
$query = "SELECT usuario, contraseña, rol FROM usuario WHERE usuario=? AND fecha_baja IS NULL";
|
|
|
|
$result = $pdo->prepare($query);
|
|
|
|
$result->execute([$data["usuario"]]);
|
|
|
|
$data = $result->fetch();
|
|
|
|
return $data;
|
|
|
|
}
|
|
|
|
|
2020-06-22 23:00:43 +02:00
|
|
|
function checkExistingCalendar($pdo, $data)
|
|
|
|
{
|
2020-06-22 01:49:49 +02:00
|
|
|
$query = "SELECT * from calendario WHERE medico=?";
|
|
|
|
$result = $pdo->prepare($query);
|
|
|
|
$result->execute([$data["medico"]]);
|
|
|
|
$data = $result->fetch();
|
|
|
|
return $data;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-06-22 23:00:43 +02:00
|
|
|
function configureCalendar($pdo, $data)
|
|
|
|
{
|
2020-06-22 01:49:49 +02:00
|
|
|
$existing = checkExistingCalendar($pdo, $data);
|
2020-06-22 23:00:43 +02:00
|
|
|
if (!$existing) {
|
2020-06-22 01:49:49 +02:00
|
|
|
$query = "INSERT INTO calendario
|
|
|
|
(hora_inicio_mañana, hora_fin_mañana, hora_inicio_tarde, hora_fin_tarde,
|
|
|
|
horario, sabado_habil, domingo_habil, duracion_cita_por_defecto, medico)
|
|
|
|
VALUES (?,?,?,?,?,?,?,?,?)";
|
|
|
|
$pdo->prepare($query)->execute([$data["hora_inicio_mañana"], $data["hora_fin_mañana"], $data["hora_inicio_tarde"],
|
|
|
|
$data["hora_fin_tarde"], $data["horario"], $data["sabado_habil"], $data["domingo_habil"],
|
|
|
|
$data["duracion_cita_por_defecto"], $data["medico"]]);
|
|
|
|
} else {
|
|
|
|
$query = "UPDATE calendario SET hora_inicio_mañana=?, hora_fin_mañana=?,
|
|
|
|
hora_inicio_tarde=?, hora_fin_tarde=?, horario=?, sabado_habil=?, domingo_habil=?,
|
|
|
|
duracion_cita_por_defecto=?, medico=? WHERE medico=?";
|
|
|
|
$pdo->prepare($query)->execute([$data["hora_inicio_mañana"], $data["hora_fin_mañana"], $data["hora_inicio_tarde"],
|
|
|
|
$data["hora_fin_tarde"], $data["horario"], $data["sabado_habil"], $data["domingo_habil"],
|
|
|
|
$data["duracion_cita_por_defecto"], $data["medico"], $data["medico"]]);
|
|
|
|
}
|
|
|
|
return "Calendario configurado con éxito";
|
|
|
|
}
|
2020-06-25 17:59:56 +02:00
|
|
|
|
|
|
|
|
2020-06-25 20:01:41 +02:00
|
|
|
function fetchCalendarEvents($pdo, $doctor)
|
2020-06-25 17:59:56 +02:00
|
|
|
{
|
2020-06-25 20:01:41 +02:00
|
|
|
$query = "SELECT * from cita WHERE medico=?";
|
2020-06-25 17:59:56 +02:00
|
|
|
$result = $pdo->prepare($query);
|
2020-06-25 20:01:41 +02:00
|
|
|
$result->execute([$doctor]);
|
2020-06-25 17:59:56 +02:00
|
|
|
$data = $result->fetchAll();
|
|
|
|
return $data;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
function fetchCalendarSettings($pdo, $doctor)
|
|
|
|
{
|
|
|
|
$query = "SELECT * from calendario WHERE medico=?";
|
|
|
|
$result = $pdo->prepare($query);
|
|
|
|
$result->execute([$doctor]);
|
|
|
|
$data = $result->fetch();
|
2020-06-26 12:19:51 +02:00
|
|
|
if(empty($data[8])){
|
|
|
|
$data[8] = 60;
|
|
|
|
}
|
2020-06-25 17:59:56 +02:00
|
|
|
return $data;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
function fetchDoctorHolidays($pdo, $doctor)
|
|
|
|
{
|
|
|
|
$query = "SELECT * FROM festivo WHERE medico IS NULL OR medico=?";
|
|
|
|
$result = $pdo->prepare($query);
|
2020-06-25 20:01:41 +02:00
|
|
|
$result->execute([$doctor]);
|
2020-06-25 17:59:56 +02:00
|
|
|
$data = $result->fetchAll();
|
|
|
|
return $data;
|
|
|
|
}
|