Implement report CRUD functionalities

This commit is contained in:
coolneng 2020-06-18 12:24:13 +02:00
parent 0127b3014f
commit cfdf2e8ebc
Signed by: coolneng
GPG Key ID: 9893DA236405AF57
5 changed files with 164 additions and 2 deletions

View File

@ -107,5 +107,5 @@ CREATE TABLE IF NOT EXISTS informe(
INSERT INTO rol (codigo, nombre) VALUES (1, "administrativo"); INSERT INTO rol (codigo, nombre) VALUES (1, "administrativo");
INSERT INTO rol (codigo, nombre) VALUES (2, "medico"); INSERT INTO rol (codigo, nombre) VALUES (2, "medico");
INSERT INTO usuario (nombre, usuario, contraseña, rol) VALUES ("Sysadmin", "Admin", "admin", "chimba",1); INSERT INTO usuario (nombre, usuario, contraseña, correo, rol) VALUES ("Sysadmin", "Admin", "chimba", "admin@example.com", 1);
INSERT INTO usuario (nombre, usuario, contraseña, rol) VALUES ("Nabil", "nabil", "menisco", 2); INSERT INTO usuario (nombre, usuario, contraseña, correo, rol) VALUES ("Nabil", "nabil", "menisco","doctor@example.com", 2);

View File

@ -195,4 +195,52 @@ function fetchHolidayData($pdo, string $id) {
return $data; return $data;
} }
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;
}
?> ?>

52
src/report.php Normal file
View File

@ -0,0 +1,52 @@
<!doctype html>
<html class="no-js" lang="es">
<head>
<meta charset="utf-8">
<meta http-equiv="x-ua-compatible" content="ie=edge">
<title>Gestión de informes</title>
<meta name="description" content="">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href="../static/style.css" type="text/css" media="screen" />
</head>
<body>
<div style="text-align: right; margin-top: 20px;">
<a href="forms/report_create_form.php" class="create_btn" >Crear</a>
</div>
<table>
<thead>
<tr>
<th>Titulo</th>
<th>Fecha</th>
<th>Hora</th>
<th>Paciente</th>
<th>Médico</th>
<th colspan="2">Acciones</th>
</tr>
</thead>
<?php
include 'database.php';
$pdo = connectDatabase();
$list = listReports($pdo);
foreach($list as $row) :
?>
<tr>
<td><?php echo $row[1]; ?></td>
<td><?php echo $row[2]; ?></td>
<td><?php echo $row[3]; ?></td>
<td><?php echo $row[4]; ?></td>
<td><?php echo $row[5]; ?></td>
<td>
<a href="forms/report_edit_form.php?edit=<?php echo $row[0]; ?>" class="edit_btn">Editar</a>
</td>
<td>
<a href="report_management.php?delete=<?php echo $row[0]; ?>" class="del_btn">Borrar</a>
</td>
</tr>
<?php endforeach ?>
<?php closeDatabase($pdo); ?>
</table>
</body>
</html>

40
src/report_management.php Normal file
View File

@ -0,0 +1,40 @@
<?php
include'database.php';
function reportCreation(){
$data = $_POST;
$pdo = connectDatabase();
createReport($pdo, $data);
closeDatabase($pdo);
header('location: report.php');
}
function reportModification(){
$data = $_POST;
$id = $_POST["id"];
$pdo = connectDatabase();
editReport($pdo, $data, $id);
closeDatabase($pdo);
header('location: report.php');
}
function reportDeletion(){
$id = $_GET["delete"];
$pdo = connectDatabase();
deleteReport($pdo, $id);
closeDatabase($pdo);
header('location: report.php');
}
if (isset($_POST["create"])) {
reportCreation();
}
if (isset($_POST["edit"])) {
reportModification();
}
if (isset($_GET["delete"])) {
reportDeletion();
}

22
src/validate_report.js Normal file
View File

@ -0,0 +1,22 @@
function validateString(input){
if(input == ""){
return false;
}
return true;
}
function validateReport(){
var title = document.forms["create_form"]["titulo"];
var content = document.forms["create_form"]["contenido"];
if(!validateString(title.value)){
alert("Introduce el título");
return false;
}
if(!validateString(content.value)){
alert("Introduce el contenido");
return false;
}
return true;
}