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

68 lines
1.6 KiB
PHP

<?php
$weight=array();
$medical_date=array();
$query="SELECT `weight`,date(medical_entry_date),`height` FROM medical_examination Where patient_id = '$id' ORDER BY medical_exam_id DESC LIMIT 7";
if (!$result = @mysqli_query($conn,$query)) {
exit(mysqli_error($conn));
}
if(mysqli_num_rows($result) > 0) {
while ($row = @mysqli_fetch_array($result)) {
array_push($weight,calcBMI($row[0],$row[2]));
array_push($medical_date,$row[1]);
}
} else {
echo '0';
}
?>
<script>
var ctx = document.getElementById('patient_bmi').getContext('2d');
var weight = [<?php echo join(',',$weight); ?>];
var xaxis = [<?php echo json_encode($medical_date); ?>];
function formatDateBMI (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[0].length; i++) {
xaxis[0][i] = formatDateBMI (xaxis[0][i]);
}
var myChart = new Chart(ctx, {
type: 'line',
options: {
title:{
display: true,
text: "BMI Graph"
},
legend:{
position:"bottom"
},
scales: {
yAxes: [{
ticks: {
precision: 0
}
}]
}
},
data: {
labels: xaxis[0],
datasets: [{
data: weight,
label: "BMI",
borderColor: "#7bb6dd",
backgroundColor: "#7bb6dd",
fill: false,
}
]
},
});
</script>