Send doctor ID as hidden input in appointments
This commit is contained in:
parent
1ee89ef1f5
commit
9858920b11
|
@ -67,7 +67,7 @@ CREATE TABLE IF NOT EXISTS calendario (
|
|||
horario VARCHAR(15) NOT NULL,
|
||||
sabado_habil BOOLEAN DEFAULT FALSE,
|
||||
domingo_habil BOOLEAN DEFAULT FALSE,
|
||||
duracion_cita_por_defecto INT DEFAULT 60,
|
||||
duracion_cita_por_defecto INT,
|
||||
medico INT,
|
||||
PRIMARY KEY (id, medico),
|
||||
FOREIGN KEY (medico)
|
||||
|
|
|
@ -18,28 +18,29 @@
|
|||
<body>
|
||||
<?php include 'navbar.php'; ?>
|
||||
<?php
|
||||
include 'database.php';
|
||||
include 'appointment_management.php';
|
||||
|
||||
$pdo = connectDatabase();
|
||||
$list = listPatients($pdo);
|
||||
$patients = listPatients($pdo);
|
||||
$calendar_settings = fetchCalendarSettings($pdo, $doctor);
|
||||
$holidays = listHolidays($pdo);
|
||||
?>
|
||||
<?php if($_SESSION["user_type"] == 1): ?>
|
||||
<form name="select_doctor" method="post" action="appointment_management.php">
|
||||
<?php if($_SESSION["user_type"] == 1 and !isset($_GET["medico"])): ?>
|
||||
<form name="select_doctor" method="get" action="appointment.php">
|
||||
<?php $doctors = listDoctors($pdo); ?>
|
||||
<div class="input-group">
|
||||
<select id="medico" name="medico">
|
||||
<option>Seleccione un médico</option>
|
||||
<?php foreach ($doctors as $row) : ?>
|
||||
<option value="<?php echo $row[0]; ?>"><?php echo $row[1]; ?></option>
|
||||
<?php endforeach ?>
|
||||
</select>
|
||||
<button class="create_btn" type="submit" name="select">Seleccionar</button>
|
||||
</div>
|
||||
<div class="input-group">
|
||||
<select id="medico" name="medico">
|
||||
<option>Seleccione un médico</option>
|
||||
<?php foreach ($doctors as $row) : ?>
|
||||
<option value="<?php echo $row[0]; ?>"><?php echo $row[1]; ?></option>
|
||||
<?php endforeach ?>
|
||||
</select>
|
||||
<button class="create_btn" type="submit" name="select">Seleccionar</button>
|
||||
</div>
|
||||
</form>
|
||||
<?php endif; ?>
|
||||
<?php closeDatabase($pdo); ?>
|
||||
<div id="dialog-form" title="Añadir cita" style="display:none;">
|
||||
<form>
|
||||
<form name="add_appointment" method="post" action="appointment_management.php">
|
||||
<div class="input-group">
|
||||
<label for="hora">Hora</label>
|
||||
<input type="time" name="hora" value="">
|
||||
|
@ -60,8 +61,11 @@
|
|||
<?php endforeach ?>
|
||||
</select>
|
||||
</div>
|
||||
<button class="create_btn" type="submit" name="crear" >Añadir cita</button>
|
||||
<button class="create_btn" type="submit" name="create" >Añadir cita</button>
|
||||
<?php $doctor = fetchDoctor($pdo); ?>
|
||||
<input type="hidden" name="doctor" value="<?php echo $doctor; ?>">
|
||||
</form>
|
||||
<?php closeDatabase($pdo); ?>
|
||||
</div>
|
||||
<div class="response"></div>
|
||||
<div id="calendar"></div>
|
||||
|
|
|
@ -8,28 +8,33 @@ function fetchDoctor($pdo){
|
|||
$user = finduser($pdo, $_SESSION["user"]);
|
||||
return $user[0][4];
|
||||
}
|
||||
$data = $_POST;
|
||||
return $_POST["medico"];
|
||||
return $_GET["medico"];
|
||||
}
|
||||
|
||||
|
||||
function listEvents(){
|
||||
$pdo = connectDatabase();
|
||||
function listEvents($pdo){
|
||||
$doctor = fetchDoctor($pdo);
|
||||
$events = fetchCalendarEvents($pdo, $doctor);
|
||||
closeDatabase($pdo);
|
||||
echo json_encode($events);
|
||||
return json_encode($events);
|
||||
}
|
||||
|
||||
|
||||
function listHolidays(){
|
||||
$pdo = connectDatabase();
|
||||
function listHolidays($pdo){
|
||||
$doctor = fetchDoctor($pdo);
|
||||
$holidays = fetchDoctorHolidays($pdo, $doctor);
|
||||
closeDatabase($pdo);
|
||||
echo json_encode($holidays);
|
||||
return json_encode($holidays);
|
||||
}
|
||||
|
||||
|
||||
listEvents();
|
||||
listHolidays();
|
||||
function appointmentCreation(){
|
||||
$data = $_POST;
|
||||
$pdo = connectDatabase();
|
||||
createAppointment($pdo, $data);
|
||||
closeDatabase($pdo);
|
||||
header('location: appointment.php');
|
||||
}
|
||||
|
||||
|
||||
if(isset($_POST["create"])){
|
||||
appointmentCreation();
|
||||
}
|
||||
|
|
|
@ -316,7 +316,7 @@ function fetchCalendarEvents($pdo, $doctor)
|
|||
$query = "SELECT * from cita WHERE medico=?";
|
||||
$result = $pdo->prepare($query);
|
||||
$result->execute([$doctor]);
|
||||
$data = $result->fetchAll();
|
||||
$data = $result->fetchAll(PDO::FETCH_ASSOC);
|
||||
return $data;
|
||||
}
|
||||
|
||||
|
@ -326,7 +326,7 @@ function fetchCalendarSettings($pdo, $doctor)
|
|||
$query = "SELECT * from calendario WHERE medico=?";
|
||||
$result = $pdo->prepare($query);
|
||||
$result->execute([$doctor]);
|
||||
$data = $result->fetch();
|
||||
$data = $result->fetch(PDO::FETCH_ASSOC);
|
||||
if(empty($data[8])){
|
||||
$data[8] = 60;
|
||||
}
|
||||
|
@ -339,6 +339,14 @@ function fetchDoctorHolidays($pdo, $doctor)
|
|||
$query = "SELECT * FROM festivo WHERE medico IS NULL OR medico=?";
|
||||
$result = $pdo->prepare($query);
|
||||
$result->execute([$doctor]);
|
||||
$data = $result->fetchAll();
|
||||
$data = $result->fetchAll(PDO::FETCH_ASSOC);
|
||||
return $data;
|
||||
}
|
||||
|
||||
|
||||
function createAppointment($pdo, $data){
|
||||
$query = "INSERT INTO cita (fecha, hora, duracion, medico, observaciones, paciente) VALUES (?,?,?,?,?,?)";
|
||||
$pdo->prepare($query)->execute([$data["fecha"], $data["hora"], $data["duracion"],
|
||||
$data["medico"], $data["observaciones"], $data["paciente"]]);
|
||||
return "Cita creada con éxito";
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue