2020-05-18 15:42:14 +02:00
|
|
|
<?php
|
|
|
|
|
2020-06-17 04:33:48 +02:00
|
|
|
function connectDatabase() {
|
|
|
|
$connection = 'unix_socket';
|
|
|
|
$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-14 03:12:32 +02:00
|
|
|
function closeDatabase($pdo) {
|
|
|
|
$pdo = null;
|
2020-05-18 15:42:14 +02:00
|
|
|
}
|
2020-06-14 03:12:32 +02:00
|
|
|
|
|
|
|
function listRows($pdo, $table) {
|
|
|
|
$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
|
|
|
}
|
|
|
|
|
|
|
|
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-17 08:42:53 +02:00
|
|
|
function editPatient($pdo, $data, $id) {
|
|
|
|
$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-16 18:56:35 +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-14 03:12:32 +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";
|
|
|
|
}
|
|
|
|
|
|
|
|
function createHoliday($pdo, $data) {
|
2020-06-16 18:56:35 +02:00
|
|
|
$query = "INSERT INTO festivo (fecha_festivo, tipo_festivo, medico) VALUES (?,?,?)";
|
2020-06-14 03:12:32 +02:00
|
|
|
$pdo->prepare($query)->execute([$data["fecha_festivo"], $data["tipo_festivo"], $data["medico"]]);
|
|
|
|
return "Festivo creado con éxito";
|
|
|
|
}
|
|
|
|
|
|
|
|
function editHoliday($pdo, $attr, $param, $id) {
|
|
|
|
$query = "UPDATE festivo SET ? = ? WHERE id = ?";
|
|
|
|
$pdo->prepare($query)->execute([$attr, $param, $id]);
|
|
|
|
return "Festivo modificado con éxito";
|
|
|
|
}
|
|
|
|
|
|
|
|
function deleteHoliday($pdo, str $id) {
|
|
|
|
$statement = "DELETE FROM festivo where id = ?";
|
|
|
|
$pdo->prepare($statement)->execute([$id]);
|
|
|
|
return "Festivo borrado con éxito";
|
|
|
|
}
|
|
|
|
|
|
|
|
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-17 04:10:09 +02:00
|
|
|
function editUser($pdo, $data, $id) {
|
|
|
|
$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-17 04:10:09 +02:00
|
|
|
function deactivateUser($pdo, $data, $id) {
|
|
|
|
$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-16 18:56:35 +02:00
|
|
|
function listAppointments($pdo, string $doctor) {
|
2020-06-14 03:12:32 +02:00
|
|
|
findRows($pdo, "cita", "medico", $doctor);
|
|
|
|
}
|
|
|
|
|
2020-06-16 22:50:35 +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-17 05:34:36 +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;
|
|
|
|
}
|
|
|
|
|
|
|
|
function findUser($pdo, $input) {
|
|
|
|
$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-17 08:42:53 +02:00
|
|
|
function listPatients($pdo) {
|
|
|
|
$query = "SELECT * from paciente";
|
|
|
|
$result = $pdo->query($query)->fetchAll();
|
|
|
|
return $result;
|
|
|
|
}
|
|
|
|
|
|
|
|
function fetchPatientData($pdo, string $id) {
|
|
|
|
$query = "SELECT * FROM paciente WHERE id=?";
|
|
|
|
$result = $pdo->prepare($query);
|
|
|
|
$result->execute([$id]);
|
|
|
|
$data = $result->fetch();
|
|
|
|
return $data;
|
|
|
|
}
|
|
|
|
|
|
|
|
function findPatient($pdo, $input) {
|
|
|
|
$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-14 03:12:32 +02:00
|
|
|
?>
|