58 lines
1.8 KiB
PHP
58 lines
1.8 KiB
PHP
<?php
|
|
include('includes/config/config.php');
|
|
|
|
|
|
$injuryClassCounts = array();
|
|
$injuryClassNames = array();
|
|
|
|
$endDate = date("Y-m-d");
|
|
$startDate = date("Y-m-d", strtotime("-1 week"));
|
|
|
|
$classSql = "SELECT inj_class_id, inj_class_name FROM injury_class";
|
|
$classResult = mysqli_query($conn, $classSql);
|
|
while ($classRow = mysqli_fetch_assoc($classResult)) {
|
|
$injuryClassNames[$classRow['inj_class_id']] = $classRow['inj_class_name'];
|
|
foreach (range(strtotime($startDate), strtotime($endDate), 86400) as $date) {
|
|
$formattedDate = date("Y-m-d", $date);
|
|
$injuryClassCounts[$formattedDate][$classRow['inj_class_id']] = 0;
|
|
}
|
|
}
|
|
|
|
$ohc_id = $_SESSION['current_ohcttype'];
|
|
$countSql = "SELECT DATE(appointment_date) as appointment_date, injury_classes_new
|
|
FROM employee_appointment
|
|
WHERE DATE(appointment_date) BETWEEN ? AND ? AND ohc_type_id=? AND appointment_type='I'";
|
|
|
|
|
|
$stmt = mysqli_prepare($conn, $countSql);
|
|
mysqli_stmt_bind_param($stmt, "sss", $startDate, $endDate, $ohc_id);
|
|
mysqli_stmt_execute($stmt);
|
|
$result = mysqli_stmt_get_result($stmt);
|
|
|
|
while ($row = mysqli_fetch_assoc($result)) {
|
|
$date = $row['appointment_date'];
|
|
$classes = explode(",", $row['injury_classes_new']);
|
|
foreach ($classes as $classId) {
|
|
if (isset($injuryClassCounts[$date][$classId])) {
|
|
$injuryClassCounts[$date][$classId]++;
|
|
}
|
|
}
|
|
}
|
|
|
|
mysqli_stmt_close($stmt);
|
|
|
|
$graphData = array(
|
|
'dates' => array(),
|
|
'labels' => array_values($injuryClassNames),
|
|
'data' => array()
|
|
);
|
|
|
|
foreach ($injuryClassCounts as $date => $counts) {
|
|
$graphData['dates'][] = date("d-m-Y", strtotime($date));
|
|
foreach ($counts as $classId => $count) {
|
|
$graphData['data'][$classId][] = $count;
|
|
}
|
|
}
|
|
|
|
echo json_encode($graphData);
|