ohctech_p8/api2/chart_bmi.php
2024-10-16 19:18:52 +05:30

162 lines
7.2 KiB
PHP

<?php
error_reporting(0);
include "../includes/config/config.php";
include "functions.php";
include 'log_entry.php';
$startDate = $_REQUEST['startDate'];
$endDate = $_REQUEST['endDate'];
$id = $_REQUEST['id'];
$combined_data = array();
// Fetching height data
$sql_height = "SELECT height, date(appointment_date) as dat FROM employee_appointment
where emp_id='$id'and height != ''
UNION
SELECT cf.checkup_form_value as height ,date(c.checkup_date) as dat from
checkup_form c left join checkup_form_key_value cf on
c.checkup_id=cf.checkup_form_id left join checkup_parameter cp on
cp.`column_name` = cf.checkup_form_key
where c.emp_id='$id' and cp.key_health_map_name=(select key_param_id from key_health_reportable_parameter_master where key_param_name='height') ORDER BY dat DESC limit 25";
$result_height = mysqli_query($conn, $sql_height);
error_log("error :". $sql_height);
while ($row_height = mysqli_fetch_assoc($result_height)) {
$combined_data[date_format(date_create($row_height['dat']), "d-m-Y")]['height'] = $row_height['height'];
}
// Fetching weight data
$sql_weight = "SELECT `weight`, date(appointment_date) as dat FROM employee_appointment
where emp_id='$id' and `weight` != ''
UNION
SELECT cf.checkup_form_value as weight ,date(c.checkup_date) as dat from
checkup_form c left join checkup_form_key_value cf on
c.checkup_id=cf.checkup_form_id left join checkup_parameter cp on
cp.`column_name` = cf.checkup_form_key
where c.emp_id='$id' and cp.key_health_map_name=(select key_param_id from key_health_reportable_parameter_master where key_param_name='weight') ORDER BY dat DESC limit 25";
error_log("error :". $sql_weight);
$result_weight = mysqli_query($conn, $sql_weight);
while ($row_weight = mysqli_fetch_assoc($result_weight)) {
$combined_data[date_format(date_create($row_weight['dat']), "d-m-Y")]['weight'] = $row_weight['weight'];
}
// Fetching BMI data
$sql_bmi = "SELECT bmi, date(appointment_date) as dat FROM employee_appointment
where emp_id='$id' and bmi != ''
UNION
SELECT cf.checkup_form_value as bmi ,date(c.checkup_date) as dat from
checkup_form c left join checkup_form_key_value cf on
c.checkup_id=cf.checkup_form_id left join checkup_parameter cp on
cp.`column_name` = cf.checkup_form_key
where c.emp_id='$id' and cp.key_health_map_name=(select key_param_id from key_health_reportable_parameter_master where key_param_name='bmi') ORDER BY dat DESC limit 25";
$result_bmi = mysqli_query($conn, $sql_bmi);
while ($row_bmi = mysqli_fetch_assoc($result_bmi)) {
$combined_data[date_format(date_create($row_bmi['dat']), "d-m-Y")]['bmi'] = $row_bmi['bmi'];
}
$query_sbp = "SELECT bp_sbp as sbp, date(appointment_date) as dat FROM employee_appointment
where emp_id='$id'and bp_sbp != ''
UNION
SELECT cf.checkup_form_value as sbp ,date(c.checkup_date) as dat from
checkup_form c left join checkup_form_key_value cf on
c.checkup_id=cf.checkup_form_id left join checkup_parameter cp on
cp.`column_name` = cf.checkup_form_key
where c.emp_id='$id' and (cp.key_health_map_name=(select key_param_id from key_health_reportable_parameter_master where key_param_name='sbp') or
cp.key_health_map_name=(select key_param_id from key_health_reportable_parameter_master where key_param_name='sbp/dbp')) order by dat desc limit 25 ";
error_log("sbp query " . $query_sbp);
$result_sbp = @mysqli_query($conn, $query_sbp);
while ($row_sbp = @mysqli_fetch_array($result_sbp)) {
$combined_data[date_format(date_create($row_sbp['dat']), "d-m-Y")]['sbp'] = $row_sbp['sbp'];
}
$query_dbp = "SELECT bp_dbp as dbp, date(appointment_date) as dat FROM employee_appointment
where emp_id='$id'and bp_dbp != ''
UNION
SELECT cf.checkup_form_value as dbp ,date(c.checkup_date) as dat from
checkup_form c left join checkup_form_key_value cf on
c.checkup_id=cf.checkup_form_id left join checkup_parameter cp on
cp.`column_name` = cf.checkup_form_key
where c.emp_id='$id' and (cp.key_health_map_name=(select key_param_id from key_health_reportable_parameter_master where key_param_name='dbp') or
cp.key_health_map_name=(select key_param_id from key_health_reportable_parameter_master where key_param_name='sbp/dbp')) order by dat desc limit 25 ";
error_log("dbp query " . $query_dbp);
$result_dbp = @mysqli_query($conn, $query_dbp);
while ($row_dbp = @mysqli_fetch_array($result_dbp)) {
$combined_data[date_format(date_create($row_dbp['dat']), "d-m-Y")]['dbp'] = $row_dbp['dbp'];
}
// Fetching blood sugar data
$query_rbs = "SELECT blood_sugar_rbs as rbs, date(appointment_date) as dat FROM employee_appointment
where emp_id='$id'and blood_sugar_rbs != ''
UNION
SELECT cf.checkup_form_value as rbs ,date(c.checkup_date) as dat from
checkup_form c left join checkup_form_key_value cf on
c.checkup_id=cf.checkup_form_id left join checkup_parameter cp on
cp.`column_name` = cf.checkup_form_key
where c.emp_id='$id' and cp.key_health_map_name=(select key_param_id from key_health_reportable_parameter_master where key_param_name='rbs') order by dat desc limit 25 ";
error_log("rbs query " . $query_rbs);
$result_rbs = @mysqli_query($conn, $query_rbs);
while ($row_rbs = @mysqli_fetch_array($result_rbs)) {
$combined_data[date_format(date_create($row_rbs['dat']), "d-m-Y")]['rbs'] = $row_rbs['rbs'];
}
$query_fbs = "SELECT blood_sugar_fbs as fbs, date(appointment_date) as dat FROM employee_appointment
where emp_id='$id'and blood_sugar_fbs != ''
UNION
SELECT cf.checkup_form_value as fbs ,date(c.checkup_date) as dat from
checkup_form c left join checkup_form_key_value cf on
c.checkup_id=cf.checkup_form_id left join checkup_parameter cp on
cp.`column_name` = cf.checkup_form_key
where c.emp_id='$id' and cp.key_health_map_name=(select key_param_id from key_health_reportable_parameter_master where key_param_name='fbs') order by dat desc limit 25 ";
error_log("fbs query " . $query_fbs);
$result_fbs = @mysqli_query($conn, $query_fbs);
while ($row_fbs = @mysqli_fetch_array($result_fbs)) {
$combined_data[date_format(date_create($row_fbs['dat']), "d-m-Y")]['fbs'] = $row_fbs['fbs'];
}
$query_ppbs = "SELECT blood_sugar_ppbs as ppbs, date(appointment_date) as dat FROM employee_appointment
where emp_id='$id'and blood_sugar_ppbs != ''
UNION
SELECT cf.checkup_form_value as ppbs ,date(c.checkup_date) as dat from
checkup_form c left join checkup_form_key_value cf on
c.checkup_id=cf.checkup_form_id left join checkup_parameter cp on
cp.`column_name` = cf.checkup_form_key
where c.emp_id='$id' and cp.key_health_map_name=(select key_param_id from key_health_reportable_parameter_master where key_param_name='ppbs') order by dat desc limit 25";
error_log("ppbs query " . $query_ppbs);
$result_ppbs = @mysqli_query($conn, $query_ppbs);
while ($row_ppbs = @mysqli_fetch_array($result_ppbs)) {
$combined_data[date_format(date_create($row_ppbs['dat']), "d-m-Y")]['ppbs'] = $row_ppbs['ppbs'];
}
// Format the result
$final_data = array();
foreach ($combined_data as $date => $params) {
$final_data[] = array(
'date' => $date,
'height' => $params['height'] ?? 0,
'weight' => $params['weight'] ?? 0,
'bmi' => $params['bmi'] ?? 0,
'sbp' => $params['sbp'] ?? 0,
'dbp' => $params['dbp'] ?? 0,
'rbs' => $params['rbs'] ?? 0,
'fbs' => $params['fbs'] ?? 0,
'ppbs' => $params['ppbs'] ?? 0
);
}
echo json_encode($final_data);
?>