ESH/chart_patient_catwise_datewise.php
2024-10-23 18:28:06 +05:30

60 lines
2.0 KiB
PHP

<?php
include('includes/config/config.php');
include('includes/functions.php');
$xaxis = array();
$date = date("Y-m-d");
$default_start_date = date('Y-m-d', strtotime($date . ' -7 days'));
$default_end_date = date('Y-m-d', strtotime($date));
error_log("date ." . $default_start_date . " " . $default_end_date);
if (!empty($_POST['start_date'])) {
$default_start_date = date('Y-m-d', strtotime($_POST['start_date']));
}
if (!empty($_POST['end_date'])) {
$default_end_date = date('Y-m-d', strtotime($_POST['end_date']));
}
error_log("date after filter ." . $default_start_date . " " . $default_end_date);
$total_patient_cat = array();
$total_patient_count = array();
$sql = "select * from patient_category where patient_cat_name != ''";
$result = mysqli_query($conn, $sql);
while ($row = mysqli_fetch_assoc($result)) {
array_push($total_patient_cat, '"' . $row['patient_cat_name'] . '"');
array_push($total_patient_count, $row['patient_cat_id']);
}
error_log("total medical " . print_r($total_patient_count, true));
$checkup_data = array();
$date_data = array();
for ($i = 0; $i < sizeof($total_patient_count); $i++) {
$query = "select count(e.appointment_id) from employee_appointment e left join patient_master p on e.emp_id=p.id where date(e.appointment_date) >= '" . $default_start_date . "' and date(e.appointment_date) <= '" . $default_end_date . "' and appointment_type='O' and p.patient_cat_id='" . $total_patient_count[$i] . "' ";
if (!$result = @mysqli_query($conn, $query)) {
error_log("error in opd chart" . mysqli_error($conn));
exit();
}
if (mysqli_num_rows($result) > 0) {
while ($row = @mysqli_fetch_array($result)) {
array_push($checkup_data, $row[0]);
// array_push($date_data, $row[1]);
}
} else {
array_push($checkup_data, 0);
}
}
error_log("opd cat data trend " . print_r($checkup_data, true));
$data = array(
'checkup_data' => ($checkup_data),
'total_patient_cat' => ($total_patient_cat),
);
echo json_encode($data);