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,
|
horario VARCHAR(15) NOT NULL,
|
||||||
sabado_habil BOOLEAN DEFAULT FALSE,
|
sabado_habil BOOLEAN DEFAULT FALSE,
|
||||||
domingo_habil BOOLEAN DEFAULT FALSE,
|
domingo_habil BOOLEAN DEFAULT FALSE,
|
||||||
duracion_cita_por_defecto INT DEFAULT 60,
|
duracion_cita_por_defecto INT,
|
||||||
medico INT,
|
medico INT,
|
||||||
PRIMARY KEY (id, medico),
|
PRIMARY KEY (id, medico),
|
||||||
FOREIGN KEY (medico)
|
FOREIGN KEY (medico)
|
||||||
|
|
|
@ -18,28 +18,29 @@
|
||||||
<body>
|
<body>
|
||||||
<?php include 'navbar.php'; ?>
|
<?php include 'navbar.php'; ?>
|
||||||
<?php
|
<?php
|
||||||
include 'database.php';
|
include 'appointment_management.php';
|
||||||
|
|
||||||
$pdo = connectDatabase();
|
$pdo = connectDatabase();
|
||||||
$list = listPatients($pdo);
|
$patients = listPatients($pdo);
|
||||||
$calendar_settings = fetchCalendarSettings($pdo, $doctor);
|
$calendar_settings = fetchCalendarSettings($pdo, $doctor);
|
||||||
|
$holidays = listHolidays($pdo);
|
||||||
?>
|
?>
|
||||||
<?php if($_SESSION["user_type"] == 1): ?>
|
<?php if($_SESSION["user_type"] == 1 and !isset($_GET["medico"])): ?>
|
||||||
<form name="select_doctor" method="post" action="appointment_management.php">
|
<form name="select_doctor" method="get" action="appointment.php">
|
||||||
<?php $doctors = listDoctors($pdo); ?>
|
<?php $doctors = listDoctors($pdo); ?>
|
||||||
<div class="input-group">
|
<div class="input-group">
|
||||||
<select id="medico" name="medico">
|
<select id="medico" name="medico">
|
||||||
<option>Seleccione un médico</option>
|
<option>Seleccione un médico</option>
|
||||||
<?php foreach ($doctors as $row) : ?>
|
<?php foreach ($doctors as $row) : ?>
|
||||||
<option value="<?php echo $row[0]; ?>"><?php echo $row[1]; ?></option>
|
<option value="<?php echo $row[0]; ?>"><?php echo $row[1]; ?></option>
|
||||||
<?php endforeach ?>
|
<?php endforeach ?>
|
||||||
</select>
|
</select>
|
||||||
<button class="create_btn" type="submit" name="select">Seleccionar</button>
|
<button class="create_btn" type="submit" name="select">Seleccionar</button>
|
||||||
</div>
|
</div>
|
||||||
|
</form>
|
||||||
<?php endif; ?>
|
<?php endif; ?>
|
||||||
<?php closeDatabase($pdo); ?>
|
|
||||||
<div id="dialog-form" title="Añadir cita" style="display:none;">
|
<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">
|
<div class="input-group">
|
||||||
<label for="hora">Hora</label>
|
<label for="hora">Hora</label>
|
||||||
<input type="time" name="hora" value="">
|
<input type="time" name="hora" value="">
|
||||||
|
@ -60,8 +61,11 @@
|
||||||
<?php endforeach ?>
|
<?php endforeach ?>
|
||||||
</select>
|
</select>
|
||||||
</div>
|
</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>
|
</form>
|
||||||
|
<?php closeDatabase($pdo); ?>
|
||||||
</div>
|
</div>
|
||||||
<div class="response"></div>
|
<div class="response"></div>
|
||||||
<div id="calendar"></div>
|
<div id="calendar"></div>
|
||||||
|
|
|
@ -8,28 +8,33 @@ function fetchDoctor($pdo){
|
||||||
$user = finduser($pdo, $_SESSION["user"]);
|
$user = finduser($pdo, $_SESSION["user"]);
|
||||||
return $user[0][4];
|
return $user[0][4];
|
||||||
}
|
}
|
||||||
$data = $_POST;
|
return $_GET["medico"];
|
||||||
return $_POST["medico"];
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
function listEvents(){
|
function listEvents($pdo){
|
||||||
$pdo = connectDatabase();
|
|
||||||
$doctor = fetchDoctor($pdo);
|
$doctor = fetchDoctor($pdo);
|
||||||
$events = fetchCalendarEvents($pdo, $doctor);
|
$events = fetchCalendarEvents($pdo, $doctor);
|
||||||
closeDatabase($pdo);
|
return json_encode($events);
|
||||||
echo json_encode($events);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
function listHolidays(){
|
function listHolidays($pdo){
|
||||||
$pdo = connectDatabase();
|
|
||||||
$doctor = fetchDoctor($pdo);
|
$doctor = fetchDoctor($pdo);
|
||||||
$holidays = fetchDoctorHolidays($pdo, $doctor);
|
$holidays = fetchDoctorHolidays($pdo, $doctor);
|
||||||
closeDatabase($pdo);
|
return json_encode($holidays);
|
||||||
echo json_encode($holidays);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
listEvents();
|
function appointmentCreation(){
|
||||||
listHolidays();
|
$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=?";
|
$query = "SELECT * from cita WHERE medico=?";
|
||||||
$result = $pdo->prepare($query);
|
$result = $pdo->prepare($query);
|
||||||
$result->execute([$doctor]);
|
$result->execute([$doctor]);
|
||||||
$data = $result->fetchAll();
|
$data = $result->fetchAll(PDO::FETCH_ASSOC);
|
||||||
return $data;
|
return $data;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -326,7 +326,7 @@ function fetchCalendarSettings($pdo, $doctor)
|
||||||
$query = "SELECT * from calendario WHERE medico=?";
|
$query = "SELECT * from calendario WHERE medico=?";
|
||||||
$result = $pdo->prepare($query);
|
$result = $pdo->prepare($query);
|
||||||
$result->execute([$doctor]);
|
$result->execute([$doctor]);
|
||||||
$data = $result->fetch();
|
$data = $result->fetch(PDO::FETCH_ASSOC);
|
||||||
if(empty($data[8])){
|
if(empty($data[8])){
|
||||||
$data[8] = 60;
|
$data[8] = 60;
|
||||||
}
|
}
|
||||||
|
@ -339,6 +339,14 @@ function fetchDoctorHolidays($pdo, $doctor)
|
||||||
$query = "SELECT * FROM festivo WHERE medico IS NULL OR medico=?";
|
$query = "SELECT * FROM festivo WHERE medico IS NULL OR medico=?";
|
||||||
$result = $pdo->prepare($query);
|
$result = $pdo->prepare($query);
|
||||||
$result->execute([$doctor]);
|
$result->execute([$doctor]);
|
||||||
$data = $result->fetchAll();
|
$data = $result->fetchAll(PDO::FETCH_ASSOC);
|
||||||
return $data;
|
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