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

212 lines
5.9 KiB
PHP

<?php
include('includes/config/config.php');
$opd=array();
$xaxis = array();
$opd2=array();
$xaxis2 = array();
$opd3=array();
$xaxis3 = array();
$year = date("Y");
for($i=15;$i>0;$i--){
$query="SELECT COUNT(appointment_id) as count,date(NOW()-INTERVAL $i DAY) as date FROM employee_appointment WHERE DATE(appointment_date) = date(NOW()-INTERVAL $i DAY) AND APPOINTMENT_TYPE='O';";
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,date('d-m-Y',strtotime($row["date"])));
array_push($opd,$row['count']);
error_log('dd'.$row["date"]) ;
}
}
}
for($j=15;$j>0;$j--){
$query2="SELECT COUNT(appointment_id) as count,date(NOW()-INTERVAL $j DAY) as date FROM employee_appointment WHERE DATE(appointment_date) = date(NOW()-INTERVAL $j DAY) AND APPOINTMENT_TYPE='O' and ailment_systems_new='1'";
if (!$result2 = @mysqli_query($conn,$query2)) {
exit(mysqli_error($conn));
}
if(mysqli_num_rows($result2) > 0) {
while ($row2 = @mysqli_fetch_array($result2)) {
array_push($xaxis2,date('d-m-Y',strtotime($row2["date"])));
array_push($opd2,$row2['count']);
error_log('dd2'.$row2["date"]) ;
}
}
}
for($j=15;$j>0;$j--){
$query3="SELECT COUNT(e.appointment_id) as count,date(NOW()-INTERVAL $j DAY) as date FROM employee_appointment e left join patient_master p on e.emp_id=p.id WHERE DATE(e.appointment_date) = date(NOW()-INTERVAL $j DAY) AND e.APPOINTMENT_TYPE='O' and p.designation_id='38'";
if (!$result3 = @mysqli_query($conn,$query3)) {
exit(mysqli_error($conn));
}
if(mysqli_num_rows($result3) > 0) {
while ($row3 = @mysqli_fetch_array($result3)) {
array_push($xaxis3,date('d-m-Y',strtotime($row3["date"])));
array_push($opd3,$row3['count']);
error_log('dd3'.$row3["date"]) ;
}
}
}
?>
<script>
var ctx = document.getElementById('patient_daywise').getContext('2d');
var opd = [<?php echo join(',',$opd); ?>];
var xaxis = [<?php echo json_encode($xaxis); ?>];
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 < xaxis.length; i++) {
xaxis[0][i] = formatDate(xaxis[0][i]);
}
var myChart = new Chart(ctx, {
type: 'line',
options: {
title: {
display: true,
text: "Day Wise No. of OPD Patients"
},
legend: {
position: "bottom"
},
scales: {
yAxes: [{
ticks: {
precision: 0
}
}]
}
},
data: {
labels: xaxis[0],
datasets: [{
data: opd,
label: "OPD",
borderColor: "#d45087",
backgroundColor: "#d45087",
fill: false,
pointBackgroundColor: function(context) {
var index = context.dataIndex;
var value = context.dataset.data[index];
return value < 85 ? 'red' : // draw negative values in red
index % 2 ? 'blue' :
// else, alternate values in blue and green
'green';
}
}]
},
});
var ctx2 = document.getElementById('patient_daywise2').getContext('2d');
var opd2 = [<?php echo join(',',$opd2); ?>];
var xaxis2 = [<?php echo json_encode($xaxis2); ?>];
for (let i = 0; i < xaxis2.length; i++) {
xaxis2[0][i] = formatDate(xaxis2[0][i]);
}
var myChart2 = new Chart(ctx2, {
type: 'line',
options: {
title: {
display: true,
text: "Day Wise No. of Patients"
},
legend: {
position: "bottom"
},
scales: {
yAxes: [{
ticks: {
precision: 0
}
}]
}
},
data: {
labels: xaxis2[0],
datasets: [{
data: opd2,
label: "OPD",
borderColor: "#d45087",
backgroundColor: "#d45087",
fill: false,
pointBackgroundColor: function(context) {
var index = context.dataIndex;
var value = context.dataset.data[index];
return value < 85 ? 'red' : // draw negative values in red
index % 2 ? 'blue' :
// else, alternate values in blue and green
'green';
}
}]
},
});
////desig chart
var ctx3 = document.getElementById('patient_daywise3').getContext('2d');
var opd3 = [<?php echo join(',',$opd3); ?>];
var xaxis3 = [<?php echo json_encode($xaxis3); ?>];
for (let i = 0; i < xaxis3.length; i++) {
xaxis3[0][i] = formatDate(xaxis3[0][i]);
}
var myChart3 = new Chart(ctx3, {
type: 'line',
options: {
title: {
display: true,
text: "Day Wise No. of Patients"
},
legend: {
position: "bottom"
},
scales: {
yAxes: [{
ticks: {
precision: 0
}
}]
}
},
data: {
labels: xaxis3[0],
datasets: [{
data: opd3,
label: "OPD",
borderColor: "#d45087",
backgroundColor: "#d45087",
fill: false,
pointBackgroundColor: function(context) {
var index = context.dataIndex;
var value = context.dataset.data[index];
return value < 85 ? 'red' : // draw negative values in red
index % 2 ? 'blue' :
// else, alternate values in blue and green
'green';
}
}]
},
});
</script>