Implement appointment modification

This commit is contained in:
coolneng 2020-07-14 14:48:35 +02:00
parent b9bf92ea55
commit 5e0285d608
Signed by: coolneng
GPG Key ID: 9893DA236405AF57
5 changed files with 70 additions and 6 deletions

View File

@ -76,7 +76,7 @@
<div id="event-end"/></div>
<form method="post" action="appointment_management.php">
<input type="hidden" name="event_id" id="event_id">
<button class="create_btn" type="submit" name="edit">Editar</button>
<button class="create_btn" type="submit" name="edit_form">Editar</button>
<button class="del_btn" type="submit" name="delete">Borrar</button>
</form>
</div>

View File

@ -0,0 +1,48 @@
<?php session_start(); ?>
<head>
<meta charset="utf-8">
<meta http-equiv="x-ua-compatible" content="ie=edge">
<title>Gestión de citas</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>
<?php include 'navbar.php'; ?>
<?php
include 'database.php';
$pdo = connectDatabase();
$data = fetchAppointmentData($pdo, $_GET["event_id"]);
$patients = fetchPatients($pdo);
?>
<form name="edit_appointment" method="post" action="appointment_management.php">
<div class="input-group">
<label for="fecha">Fecha</label>
<input type="date" name="fecha" value="<?php echo $data[1]; ?>">
</div>
<div class="input-group">
<label for="hora">Hora</label>
<input type="time" name="hora" value="<?php echo $data[2]; ?>">
</div>
<div class="input-group">
<label for="duracion">Duración</label>
<input type="number" name="duracion" value="<?php echo $data[3]; ?>" step="30">
</div>
<div class="input-group">
<label for="observaciones">Observaciones</label>
<input type="text" name="observaciones" value="<?php echo $data[4]; ?>">
</div>
<div class="input-group">
<select id="paciente" name="paciente">
<option>Seleccione un paciente</option>
<?php foreach ($patients as $row) : ?>
<option value="<?php echo $row[0]; ?>"><?php echo $row[1]; ?></option>
<?php endforeach ?>
</select>
</div>
<button class="create_btn" type="submit" name="edit">Editar</button>
<input type="hidden" name="id" value="<?php echo $_GET["event_id"]; ?>">
</form>
<?php closeDatabase($pdo); ?>
</body>

View File

@ -57,6 +57,11 @@ if(isset($_POST["create"])){
appointmentCreation();
}
if(isset($_POST["edit_form"])){
$event_id = $_POST["event_id"];
header("location: appointment_edit_form.php?event_id=$event_id");
}
if(isset($_POST["edit"])){
appointmentModification();
}

View File

@ -2,10 +2,11 @@
var queryString = window.location.search;
var calendar = $('#calendar').fullCalendar({
editable: true,
editable: false,
header: {
left: 'prev,next,today',
center: 'title',
right: 'month,agendaWeek,agendaDay'
},

View File

@ -370,7 +370,7 @@ function configureCalendar($pdo, $data)
function fetchCalendarEvents($pdo, $doctor)
{
$query = "SELECT cita.id, fecha, hora, duracion, medico, observaciones, nombre, apellido, documento_identificativo from cita
$query = "SELECT cita.id, fecha, hora, duracion, medico, observaciones, nombre, apellido, documento_identificativo FROM cita
INNER JOIN paciente ON cita.paciente = paciente.id
WHERE medico=?";
$result = $pdo->prepare($query);
@ -412,9 +412,10 @@ function createAppointment($pdo, $data){
function editAppointment($pdo, $data){
$query = "UPDATE cita SET (fecha, hora, duracion, medico, observaciones, paciente) VALUES (?,?,?,?,?,?)";
$query = "UPDATE cita SET fecha=?, hora=?, duracion=?, observaciones=?, paciente=?
WHERE id=?";
$pdo->prepare($query)->execute([$data["fecha"], $data["hora"], $data["duracion"],
$data["doctor"], $data["observaciones"], $data["paciente"]]);
$data["observaciones"], $data["paciente"], $data["id"]]);
return "Cita modificada con éxito";
}
@ -424,3 +425,12 @@ function deleteAppointment($pdo, $id){
$pdo->prepare($statement)->execute([$id]);
return "Cita borrada con éxito";
}
function fetchAppointmentData($pdo, $id){
$query = "SELECT id, fecha, hora, duracion, observaciones FROM cita WHERE id=?";
$result = $pdo->prepare($query);
$result->execute([$id]);
$data = $result->fetch();
return $data;
}