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

359 lines
12 KiB
PHP

<?php
$a_shift=array();
$b_shift=array();
$c_shift=array();
$g_shift=array();
$xaxis = array();
$no_of_days = cal_days_in_month(CAL_GREGORIAN,date('m'),date('Y'));
for($i=$no_of_days; $i>=0; $i--){
$query="SELECT count(a.appointment_id) as count_mf,DATE(NOW()-INTERVAL $i DAY) from employee_appointment a where DATE(a.appointment_date) = date(NOW()-INTERVAL $i DAY) and shift_type = 'A'";
// echo $query;
error_log("SHIFT A ::" .$query);
if (!$result = @mysqli_query($conn,$query)) {
exit(mysqli_error($conn));
}
if(mysqli_num_rows($result) > 0) {
while ($row = @mysqli_fetch_array($result)) {
array_push($xaxis,$row[1]);
array_push($a_shift,$row[0]);
}
} else {
echo '0';
}
}
for($i=$no_of_days; $i>=0; $i--){
$query="SELECT count(a.appointment_id) as count_mf from employee_appointment a where DATE(a.appointment_date) = date(NOW()-INTERVAL $i DAY) and shift_type = 'B'";
// echo $query;
if (!$result = @mysqli_query($conn,$query)) {
exit(mysqli_error($conn));
}
if(mysqli_num_rows($result) > 0) {
while ($row = @mysqli_fetch_array($result)) {
array_push($b_shift,$row[0]);
}
} else {
echo '0';
}
}
for($i=$no_of_days; $i>=0; $i--){
$query="SELECT count(a.appointment_id) as count_mf from employee_appointment a where DATE(a.appointment_date) = date(NOW()-INTERVAL $i DAY) and shift_type = 'C'";
if (!$result = @mysqli_query($conn,$query)) {
exit(mysqli_error($conn));
}
if(mysqli_num_rows($result) > 0) {
while ($row = @mysqli_fetch_array($result)) {
array_push($c_shift,$row[0]);
}
} else {
echo '0';
}
}
for($i=$no_of_days; $i>=0; $i--){
$query="SELECT count(a.appointment_id) as count_mf from employee_appointment a where DATE(a.appointment_date) = date(NOW()-INTERVAL $i DAY) and shift_type = 'G'";
if (!$result = @mysqli_query($conn,$query)) {
exit(mysqli_error($conn));
}
if(mysqli_num_rows($result) > 0) {
while ($row = @mysqli_fetch_array($result)) {
array_push($g_shift,$row[0]);
}
} else {
echo '0';
}
}
// print_r($xaxis);
// print_r($injury);
// print_r($sickness);
?>
<script>
var ctx = document.getElementById('patienDetails').getContext('2d');
var a_shift = [<?php echo join(',',$a_shift); ?>];
var b_shift = [<?php echo join(',',$b_shift); ?>];
var c_shift = [<?php echo join(',',$c_shift); ?>];
var g_shift = [<?php echo join(',',$g_shift); ?>];
var xaxis = [<?php echo json_encode($xaxis); ?>];
console.log("XAXIS"+xaxis);
var no_of_days = <?php echo cal_days_in_month(CAL_GREGORIAN,date('m'),date('Y'));?>;
function formatDate (input) {
var datePart = input.match(/\d+/g),
year = datePart[0],
month = datePart[1],
day = datePart[2];
return day+'-'+month+'-'+year;
}
for (let i = 0; i < no_of_days; i++) {
xaxis[0][i] = formatDate (xaxis[0][i]);
}
var myChart = new Chart(ctx, {
type: 'line',
options: {
title:{
display: true,
text: "OPD Shift wise Male and Female"
},
legend:{
position:"bottom"
},
scales: {
yAxes: [{
ticks: {
precision: 0
}
}]
}
},
data: {
labels: xaxis[0],
datasets: [{
data: a_shift,
label: "SHIFT A",
borderColor: "#3e95cd",
backgroundColor: "#7bb6dd",
fill: false,
}, {
data: b_shift,
label: "SHIFT B",
borderColor: "#3cba9f",
backgroundColor: "#71d1bd",
fill: false,
},
{
data: c_shift,
label: "SHIFT C",
borderColor: "#ffa500",
backgroundColor: "#ffc04d",
fill: false,
},
{
data: g_shift,
label: "SHIFT G",
borderColor: "#990073",
backgroundColor: "#990099",
fill: false,
},
]
},
});
</script>
<style>
* {
box-sizing: border-box;
}
.tbl-row {
margin-left:-5px;
margin-right:-5px;
}
.tbl-column {
float: left;
width: 50%;
padding: 5px;
}
/* Clearfix (clear floats) */
.tbl-row::after {
content: "";
clear: both;
display: table;
}
table {
border-collapse: collapse;
border-spacing: 0;
width: 100%;
border: 1px solid #ddd;
}
</style>
<div class="tbl-row">
<div class="tbl-column">
<table border="1" height="150" width="50%">
<?php $sql_shift_total = "select count(a.appointment_id) as count_male from employee_appointment a left join patient_master b on a.emp_id = b.id where b.gender = 'M' and DATE(a.appointment_date) = date(NOW()-INTERVAL 1 DAY) and a.shift_type in ('A','B','C','G')";
$result_shift_total = mysqli_query($conn,$sql_shift_total);
$row_shift_total = mysqli_fetch_array($result_shift_total);
?>
<tr>
<th rowspan="6"><center>MALE</center></th>
<th><center>Shift</center></th>
<th><center>Nos.</center></th>
<th><center>%</center></th>
</tr>
<?php $sql_shifta = "select count(a.appointment_id) as count_male from employee_appointment a left join patient_master b on a.emp_id = b.id where b.gender = 'M' and DATE(a.appointment_date) = date(NOW()-INTERVAL 1 DAY) and a.shift_type = 'A'";
$result_shifta = mysqli_query($conn,$sql_shifta);
$row_shifta = mysqli_fetch_array($result_shifta);
$percent_a = round(($row_shifta['count_male']/$row_shift_total['count_male'] * 100),2); ?>
<tr>
<td width="25%"><center><strong>A</strong></center></td>
<td><center><?php echo $row_shifta['count_male'];?></center></td>
<td><center><?php echo $percent_a;?></center></td>
</tr>
<?php $sql_shiftb = "select count(a.appointment_id) as count_male from employee_appointment a left join patient_master b on a.emp_id = b.id where b.gender = 'M' and DATE(a.appointment_date) = date(NOW()-INTERVAL 1 DAY) and a.shift_type = 'B'";
$result_shiftb = mysqli_query($conn,$sql_shiftb);
$row_shiftb = mysqli_fetch_array($result_shiftb);
$percent_b = round(($row_shiftb['count_male']/$row_shift_total['count_male'] * 100),2); ?>
<tr>
<td width="25%"><center><strong>B</strong></center></td>
<td><center><?php echo $row_shiftb['count_male'];?></center></td>
<td><center><?php echo $percent_b;?></center></td>
</tr>
<?php $sql_shiftg = "select count(a.appointment_id) as count_male from employee_appointment a left join patient_master b on a.emp_id = b.id where b.gender = 'M' and DATE(a.appointment_date) = date(NOW()-INTERVAL 1 DAY) and a.shift_type = 'G'";
$result_shiftg = mysqli_query($conn,$sql_shiftg);
$row_shiftg = mysqli_fetch_array($result_shiftg);
$percent_g = round(($row_shiftg['count_male']/$row_shift_total['count_male'] * 100),2);?>
<tr>
<td width="25%"><center><strong>G</strong></center></td>
<td><center><?php echo $row_shiftg['count_male'];?></center></td>
<td><center><?php echo $percent_g;?></center></td>
</tr>
<?php $sql_shiftc = "select count(a.appointment_id) as count_male from employee_appointment a left join patient_master b on a.emp_id = b.id where b.gender = 'M' and DATE(a.appointment_date) = date(NOW()-INTERVAL 1 DAY) and a.shift_type = 'C'";
$result_shiftc = mysqli_query($conn,$sql_shiftc);
$row_shiftc = mysqli_fetch_array($result_shiftc);
$percent_c = round(($row_shiftc['count_male']/$row_shift_total['count_male'] * 100),2);?>
<tr>
<td width="25%"><center><strong>C</strong></center></td>
<td><center><?php echo $row_shiftc['count_male'];?></center></td>
<td><center><?php echo $percent_c;?></center></td>
</tr>
<tr>
<td width="25%"><center><strong>Total</strong></center></td>
<td><center><?php echo $row_shift_total['count_male'];?></center></td>
<td><center><?php echo ($percent_a+$percent_b+$percent_c+$percent_g)?></center></td>
</tr>
</table>
</div>
<div class="tbl-column">
<table border="1" height="150" width="50%">
<?php $sql_shift_total = "select count(a.appointment_id) as count_female from employee_appointment a left join patient_master b on a.emp_id = b.id where b.gender = 'F' and DATE(a.appointment_date) = date(NOW()-INTERVAL 1 DAY) and a.shift_type in ('A','B','C','G')";
$result_shift_total = mysqli_query($conn,$sql_shift_total);
$row_shift_total = mysqli_fetch_array($result_shift_total);?>
<tr>
<th rowspan="6"><center>FEMALE</center></th>
<th><center>Shift</center></th>
<th><center>Nos.</center></th>
<th><center>%</center></th>
</tr>
<?php $sql_shifta = "select count(a.appointment_id) as count_female from employee_appointment a left join patient_master b on a.emp_id = b.id where b.gender = 'F' and DATE(a.appointment_date) = date(NOW()-INTERVAL 1 DAY) and a.shift_type = 'A'";
$result_shifta = mysqli_query($conn,$sql_shifta);
$row_shifta = mysqli_fetch_array($result_shifta);
$percent_fa = round(($row_shifta['count_female']/$row_shift_total['count_female'] * 100),2);?>
<tr>
<td width="25%"><center><strong>A</strong></center></td>
<td><center><?php echo $row_shifta['count_female'];?></center></td>
<td><center><?php echo $percent_fa;?></center></td>
</tr>
<?php $sql_shiftb = "select count(a.appointment_id) as count_female from employee_appointment a left join patient_master b on a.emp_id = b.id where b.gender = 'F' and DATE(a.appointment_date) = date(NOW()-INTERVAL 1 DAY) and a.shift_type = 'B'";
$result_shiftb = mysqli_query($conn,$sql_shiftb);
$row_shiftb = mysqli_fetch_array($result_shiftb);
$percent_fb = round(($row_shiftb['count_female']/$row_shift_total['count_female'] * 100),2);?>
<tr>
<td width="25%"><center><strong>B</strong></center></td>
<td><center><?php echo $row_shiftb['count_female'];?></center></td>
<td><center><?php echo $percent_fb;?></center></td>
</tr>
<?php $sql_shiftg = "select count(a.appointment_id) as count_female from employee_appointment a left join patient_master b on a.emp_id = b.id where b.gender = 'F' and DATE(a.appointment_date) = date(NOW()-INTERVAL 1 DAY) and a.shift_type = 'G'";
$result_shiftg = mysqli_query($conn,$sql_shiftg);
$row_shiftg = mysqli_fetch_array($result_shiftg);
$percent_fg = round(($row_shiftg['count_female']/$row_shift_total['count_female'] * 100),2);?>
<tr>
<td width="25%"><center><strong>G</strong></center></td>
<td><center><?php echo $row_shiftg['count_female'];?></center></td>
<td><center><?php echo $percent_fg;?></center></td>
</tr>
<?php $sql_shiftc = "select count(a.appointment_id) as count_female from employee_appointment a left join patient_master b on a.emp_id = b.id where b.gender = 'F' and DATE(a.appointment_date) = date(NOW()-INTERVAL 1 DAY) and a.shift_type = 'C'";
$result_shiftc = mysqli_query($conn,$sql_shiftc);
$row_shiftc = mysqli_fetch_array($result_shiftc);
$percent_fc = round(($row_shiftc['count_female']/$row_shift_total['count_female'] * 100),2);?>
<tr>
<td width="25%"><center><strong>C</strong></center></td>
<td><center><?php echo $row_shiftc['count_female'];?></center></td>
<td><center><?php echo $percent_fc;?></center></td>
</tr>
<tr>
<td width="25%"><center><strong>Total</strong></center></td>
<td><center><?php echo $row_shift_total['count_female'];?></center></td>
<td><center><?php echo ($percent_fa+$percent_fb+$percent_fc+$percent_fg)?></center></td>
</tr>
</table>
</div>
</div>
<br>
<table border="1" width="100%">
<tr><th colspan="2" style="background-color: blue;color: white"><center><strong>CANTEEN SURVEILLANCE</strong></center></th></tr>
<tr>
<?php $sql = "select count(distinct(a.response_id)) as count_ffi from questionaire_master_response a left join questionaire_master_response_details b on a.response_id = b.response_id left join patient_master c on a.patient_id = c.id WHERE a.form_type IN ('ffi') and a.approval_status = 'Y' AND a.f_status = 'CLS'";
$result = mysqli_query($conn, $sql);
$row = mysqli_fetch_array($result);?>
<td width="50%"><center><strong>FFI</strong></center></td>
<td><center><strong><?php echo $row['count_ffi']?></strong></center></td>
</tr>
</table>