2020-05-18 15:42:14 +02:00
|
|
|
<?php
|
|
|
|
|
2020-06-17 04:33:48 +02:00
|
|
|
function connectDatabase() {
|
|
|
|
$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-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-18 09:04:44 +02:00
|
|
|
if(empty($data["medico"])){
|
|
|
|
$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-18 09:04:44 +02:00
|
|
|
function editHoliday($pdo, $data, $id) {
|
|
|
|
$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-18 09:04:44 +02:00
|
|
|
function deleteHoliday($pdo, $id) {
|
|
|
|
$statement = "DELETE FROM festivo where id=?";
|
2020-06-14 03:12:32 +02:00
|
|
|
$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 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) {
|
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-17 08:42:53 +02:00
|
|
|
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-17 22:02:27 +02:00
|
|
|
function fetchCities($pdo, $id){
|
|
|
|
$query = "SELECT * FROM municipios WHERE id_provincia=?";
|
|
|
|
$result = $pdo->prepare($query);
|
|
|
|
$result->execute([$id]);
|
|
|
|
$data = $result->fetchAll();
|
|
|
|
return $data;
|
|
|
|
}
|
|
|
|
|
|
|
|
function fetchRegions($pdo){
|
|
|
|
$query = "SELECT * FROM provincias";
|
|
|
|
$result = $pdo->prepare($query);
|
|
|
|
$result->execute();
|
|
|
|
$data = $result->fetchAll();
|
|
|
|
return $data;
|
|
|
|
}
|
|
|
|
|
2020-06-18 09:04:44 +02:00
|
|
|
function listHolidays($pdo){
|
|
|
|
$query = "SELECT * FROM festivo";
|
|
|
|
$result = $pdo->prepare($query);
|
|
|
|
$result->execute();
|
|
|
|
$data = $result->fetchAll();
|
|
|
|
return $data;
|
|
|
|
}
|
|
|
|
|
|
|
|
function listDoctors($pdo){
|
|
|
|
$query = "SELECT * FROM usuario where rol=2";
|
|
|
|
$result = $pdo->prepare($query);
|
|
|
|
$result->execute();
|
|
|
|
$data = $result->fetchAll();
|
|
|
|
return $data;
|
|
|
|
}
|
|
|
|
|
|
|
|
function fetchHolidayData($pdo, string $id) {
|
|
|
|
$query = "SELECT * FROM festivo WHERE id=?";
|
|
|
|
$result = $pdo->prepare($query);
|
|
|
|
$result->execute([$id]);
|
|
|
|
$data = $result->fetch();
|
|
|
|
return $data;
|
|
|
|
}
|
|
|
|
|
2020-06-18 12:24:13 +02:00
|
|
|
function listReports($pdo){
|
|
|
|
$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;
|
|
|
|
}
|
|
|
|
|
|
|
|
function createReport($pdo, $data) {
|
|
|
|
$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";
|
|
|
|
}
|
|
|
|
|
|
|
|
function editReport($pdo, $data, $id){
|
|
|
|
$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";
|
|
|
|
}
|
|
|
|
|
|
|
|
function deleteReport($pdo, $id) {
|
|
|
|
$statement = "DELETE FROM informe where id=?";
|
|
|
|
$pdo->prepare($statement)->execute([$id]);
|
|
|
|
return "Informe borrado con éxito";
|
|
|
|
}
|
|
|
|
|
|
|
|
function fetchPatients($pdo){
|
|
|
|
$query = "SELECT id, apellido from paciente";
|
|
|
|
$result = $pdo->prepare($query);
|
|
|
|
$result->execute();
|
|
|
|
$data = $result->fetchAll();
|
|
|
|
return $data;
|
|
|
|
}
|
|
|
|
|
|
|
|
function fetchReportData($pdo, string $id) {
|
|
|
|
$query = "SELECT * FROM informe WHERE id=?";
|
|
|
|
$result = $pdo->prepare($query);
|
|
|
|
$result->execute([$id]);
|
|
|
|
$data = $result->fetch();
|
|
|
|
return $data;
|
|
|
|
}
|
|
|
|
|
2020-06-18 14:48:12 +02:00
|
|
|
function fetchLoginData($pdo, $data){
|
|
|
|
$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-14 03:12:32 +02:00
|
|
|
?>
|