Implement appointment fetch and insertion

This commit is contained in:
coolneng 2020-07-12 20:07:05 +02:00
parent a6262a5b38
commit d5ea8bec33
Signed by: coolneng
GPG Key ID: 9893DA236405AF57
4 changed files with 57 additions and 149 deletions

View File

@ -1,8 +0,0 @@
<?php
include 'appointment_management.php';
$pdo = connectDatabase();
$events = listEvents($pdo);
echo $events;
closeDatabase($pdo);
?>

40
src/appointment_feed.php Normal file
View File

@ -0,0 +1,40 @@
<?php
include 'appointment_management.php';
function computeEndTime(&$data){
foreach($data as &$row){
$time = new DateTime($row["hora"]);
$time->modify("+{$row["duracion"]} minutes");
$time_string = $time->format('H:i:s');
$row += ["end" => $time_string];
}
}
function renameArray($data){
computeEndTime($data);
$events = array();
foreach($data as $row){
$events[] = array(
"id" => $row["id"],
"title" => "Cita de " . $row["apellido"],
"start" => $row["fecha"] . " " . $row["hora"],
"end" => $row["fecha"] . " " . $row["end"],
);
}
return $events;
}
function fetchDatabase(){
$pdo = connectDatabase();
$data = listEvents($pdo);
closeDatabase($pdo);
return $data;
}
$result = fetchDatabase();
$events = renameArray($result);
echo json_encode($events);
?>

View File

@ -1,45 +1,15 @@
$(document).ready(function() { $(document).ready(function() {
var date = new Date();
var d = date.getDate();
var m = date.getMonth();
var y = date.getFullYear();
var calendar = $('#calendar').fullCalendar({ var calendar = $('#calendar').fullCalendar({
editable: true, editable: true,
header: { header: {
left: 'prev,next,today', left: 'prev,next,today',
center: 'patient',
right: 'month,agendaWeek,agendaDay' right: 'month,agendaWeek,agendaDay'
}, },
events: "appointment_feed.php",
events: "appointment-feed.php",
eventRender: function(event, element, view) {
if (event.allDay === 'true') {
event.allDay = true;
} else {
event.allDay = false;
}
},
selectable: true, selectable: true,
@ -47,108 +17,12 @@
select: function(start, end, allDay) { select: function(start, end, allDay) {
$("#dialog-form").dialog({ modal: true, patient: event.paciente, width:450}); $("#dialog-form").dialog({ modal: true, width:450});
var date = $.fullCalendar.formatDate(start, 'YYYY-MM-DD');
calendar.fullCalendar('renderEvent', $("#fecha").val(date);
{
start: start,
end: end,
allDay: allDay
},
);
calendar.fullCalendar('unselect');
},
editable: true,
eventDrop: function(event, delta) {
var start = $.fullCalendar.formatDate(event.start, "Y-MM-DD HH:mm:ss");
var end = $.fullCalendar.formatDate(event.end, "Y-MM-DD HH:mm:ss");
$.ajax({
url: 'update_events.php',
data: 'patient='+ event.patient+'&start='+ start +'&end='+ end +'&id='+ event.id ,
type: "POST",
success: function(json) {
alert("Updated Successfully");
} }
}); });
});
},
eventClick: function(event) {
element.click(function() {
});
$.ajax({
type: "POST",
url: "delete_event.php",
data: "&id=" + event.id,
success: function(json) {
$('#calendar').fullCalendar('removeEvents', event.id);
alert("Updated Successfully");}
});
},
eventResize: function(event) {
var start = $.fullCalendar.formatDate(event.start, "yyyy-MM-dd HH:mm:ss");
var end = $.fullCalendar.formatDate(event.end, "yyyy-MM-dd HH:mm:ss");
$.ajax({
url: 'update_events.php',
data: 'patient='+ event.patient+'&start='+ start +'&end='+ end +'&id='+ event.id ,
type: "POST",
success: function(json) {
alert("Updated Successfully");
}
});
}
});
});

View File

@ -370,7 +370,9 @@ function configureCalendar($pdo, $data)
function fetchCalendarEvents($pdo, $doctor) function fetchCalendarEvents($pdo, $doctor)
{ {
$query = "SELECT * from cita WHERE medico=?"; $query = "SELECT cita.id, fecha, hora, duracion, medico, observaciones, apellido, documento_identificativo from cita
INNER JOIN paciente ON cita.paciente = paciente.id
WHERE medico=?";
$result = $pdo->prepare($query); $result = $pdo->prepare($query);
$result->execute([$doctor]); $result->execute([$doctor]);
$data = $result->fetchAll(PDO::FETCH_ASSOC); $data = $result->fetchAll(PDO::FETCH_ASSOC);