ESH/bmi_and_diabetes_relation_report.php

291 lines
12 KiB
PHP
Raw Normal View History

2024-10-23 18:28:06 +05:30
<?php
include('includes/config/config.php');
include('includes/functions.php');
error_reporting(E_ERROR | E_PARSE);
$ohc_type = $_REQUEST['ohc_location'];
$patient_category = $_REQUEST['patient_category'];
$dept = $_REQUEST['dept'];
$emp_designation = $_REQUEST['emp_designation'];
$emp_cadre = $_REQUEST['emp_cadre'];
$employer_contractor = $_REQUEST['employer_contractor'];
$gender = $_REQUEST['gender'];
$start_date = $_REQUEST['startDate'];
$end_date = $_REQUEST['endDate'];
$year = implode(',', $_REQUEST['year']);
$month = implode(',', $_REQUEST['month']);
$year2 = implode(',', $_REQUEST['year']);
$year1 = explode(',', $year);
$qry_filter = "";
$qry_date = "";
if (isset($ohc_location) && $ohc_location != '') {
$qry_filter .= " and ohc_location_id ='" . $ohc_location . "' ";
}
if (isset($patient_category) && $patient_category != '') {
$qry_filter .= " and emp_cat_id ='" . $patient_category . "' ";
}
if (isset($dept) && $dept != '') {
$qry_filter .= " and dept_id ='" . $dept . "' ";
}
if (isset($emp_designation) && $emp_designation != '') {
$qry_filter .= " and designation_id ='" . $emp_designation . "' ";
}
if (isset($emp_cadre) && $emp_cadre != '') {
$qry_filter .= " and emp_cadre ='" . $emp_cadre . "' ";
}
if (isset($employer_contractor) && $employer_contractor != '') {
$qry_filter .= " and employer_contractor_id ='" . $employer_contractor . "' ";
}
if (isset($gender) && $gender != '') {
$qry_filter .= " and gender ='" . $gender . "' ";
}
if (isset($start_date) && $start_date != '') {
$qry_date .= " and medical_entry_date >=str_to_date('" . $start_date . "','%d-%m-%Y') ";
}
if (isset($end_date) && $end_date != '') {
$qry_date .= " and medical_entry_date <=str_to_date('" . $end_date . "','%d-%m-%Y') ";
}
$i = 0;
$record = array();
if (isset($year) && $year != '' && sizeof($year1) > 1) {
for ($j = 0; $j < sizeof($year1); $j++) {
error_log("year:" . $year1[$j] . " size:" . sizeof($year1));
$qry_date1 = "";
$qry_doj = "";
$qry_date1 .= "and year(medical_entry_date) ='" . $year1[$j] . "'";
$qry_doj .= "and year(doj) <= '" . $year1[$j] . "'";
$total = 0;
$pat_query = "select max(medical_exam_id) from medical_examination where patient_id in (SELECT id FROM `patient_master` where status='Active' $qry_filter $qry_doj ORDER by id asc) $qry_date $qry_date1 and bmi<18.5 GROUP BY patient_id ORDER BY patient_id asc";
$pat_result = mysqli_query($conn, $pat_query);
$total = mysqli_num_rows($pat_result);
$percentage_for_less_18 = 0;
$count_bmi = "select max(medical_exam_id),bmi,patient_id from medical_examination where patient_id in (SELECT id FROM `patient_master` where status='Active' $qry_filter $qry_doj ORDER by id asc) and bmi<18.5 and diabetes='1' $qry_date $qry_date1 GROUP BY patient_id ORDER BY patient_id asc";
$bmi_result = mysqli_query($conn, $count_bmi);
$bmi_row_count = mysqli_num_rows($bmi_result);
if ($total == 0 || $bmi_row_count == 0) {
$data['Less_Than_18.5'][$year1[$j]]['total'] = 0;
} else {
$percentage_for_less_18 = ($bmi_row_count / $total) * 100;
$data['Less_Than_18.5'][$year1[$j]]['total'] = round($percentage_for_less_18, 2);
}
error_log("count bmi:" . $count_bmi);
error_log("count:" . $bmi_row_count);
error_log("total:" . $total);
error_log("per:" . $percentage_for_less_18);
$total = 0;
$pat_query = "select max(medical_exam_id),bmi,patient_id from medical_examination where patient_id in (SELECT id FROM `patient_master` where status='Active' $qry_filter $qry_doj ORDER by id asc) $qry_date $qry_date1 and bmi>=18.5 and bmi<25 GROUP BY patient_id ORDER BY patient_id asc";
$pat_result = mysqli_query($conn, $pat_query);
$total = mysqli_num_rows($pat_result);
$percentage_for_18_25 = 0;
$count_bmi = "select max(medical_exam_id),bmi,patient_id from medical_examination where patient_id in (SELECT id FROM `patient_master` where status='Active' $qry_filter $qry_doj ORDER by id asc) $qry_date $qry_date1 and bmi>=18.5 and bmi<25 and diabetes='1' GROUP BY patient_id ORDER BY patient_id asc";
$bmi_result = mysqli_query($conn, $count_bmi);
$bmi_row_count = mysqli_num_rows($bmi_result);
if ($total == 0 || $bmi_row_count == 0) {
$data['18.5_25'][$year1[$j]]['total'] = 0;
} else {
$percentage_for_18_25 = ($bmi_row_count / $total) * 100;
$data['18.5_25'][$year1[$j]]['total'] = round($percentage_for_18_25, 2);
}
error_log("count bmi:" . $count_bmi);
error_log("count:" . $bmi_row_count);
error_log("total:" . $total);
error_log("per:" . $percentage_for_18_25);
$total = 0;
$pat_query = "select max(medical_exam_id),bmi,patient_id from medical_examination where patient_id in (SELECT id FROM `patient_master` where status='Active' $qry_filter $qry_doj ORDER by id asc) $qry_date $qry_date1 and bmi>=25 and bmi<30 GROUP BY patient_id ORDER BY patient_id asc";
$pat_result = mysqli_query($conn, $pat_query);
$total = mysqli_num_rows($pat_result);
$percentage_for_25_30 = 0;
$count_bmi = "select max(medical_exam_id),bmi,patient_id from medical_examination where patient_id in (SELECT id FROM `patient_master` where status='Active' $qry_filter $qry_doj ORDER by id asc) $qry_date $qry_date1 and bmi>=25 and bmi<30 and diabetes='1' GROUP BY patient_id ORDER BY patient_id asc";
$bmi_result = mysqli_query($conn, $count_bmi);
$bmi_row_count = mysqli_num_rows($bmi_result);
if ($total == 0 || $bmi_row_count == 0) {
$data['25_30'][$year1[$j]]['total'] = 0;
} else {
$percentage_for_25_30 = ($bmi_row_count / $total) * 100;
$data['25_30'][$year1[$j]]['total'] = round($percentage_for_25_30, 2);
}
error_log("count bmi:" . $count_bmi);
error_log("count:" . $bmi_row_count);
error_log("total:" . $total);
error_log("per:" . $percentage_for_25_30);
$total = 0;
$pat_query = "select max(medical_exam_id),bmi,patient_id from medical_examination where patient_id in (SELECT id FROM `patient_master` where status='Active' $qry_filter $qry_doj ORDER by id asc) $qry_date $qry_date1 and bmi>30 GROUP BY patient_id ORDER BY patient_id asc";
$pat_result = mysqli_query($conn, $pat_query);
$total = mysqli_num_rows($pat_result);
$percentage_for_more_30 = 0;
$count_bmi = "select max(medical_exam_id),bmi,patient_id from medical_examination where patient_id in (SELECT id FROM `patient_master` where status='Active' $qry_filter $qry_doj ORDER by id asc) and bmi>30 and diabetes='1' $qry_date $qry_date1 GROUP BY patient_id ORDER BY patient_id asc";
$bmi_result = mysqli_query($conn, $count_bmi);
$bmi_row_count = mysqli_num_rows($bmi_result);
if ($total == 0 || $bmi_row_count == 0) {
$data['More_Than_30'][$year1[$j]]['total'] = 0;
} else {
$percentage_for_more_30 = ($bmi_row_count / $total) * 100;
$data['More_Than_30'][$year1[$j]]['total'] = round($percentage_for_more_30, 2);
}
error_log("count bmi:" . $count_bmi);
error_log("count:" . $bmi_row_count);
error_log("total:" . $total);
error_log("per:" . $percentage_for_more_30);
}
} else {
if (isset($year2) && $year2 != '') {
$qry_date .= " and year(medical_entry_date) ='" . $year2 . "'";
$qry_doj .= "and year(doj) <= '" . $year2 . "'";
}
$pat_query = "select max(medical_exam_id) from medical_examination where patient_id in (SELECT id FROM `patient_master` where status='Active' $qry_filter $qry_doj ORDER by id asc) $qry_date and bmi<18.5 GROUP BY patient_id ORDER BY patient_id asc";
$pat_result = mysqli_query($conn, $pat_query);
$total = mysqli_num_rows($pat_result);
$percentage_emp_per_bmi = 0;
$count_bmi = "select max(medical_exam_id),bmi,patient_id,hbd from medical_examination where patient_id in (SELECT id FROM `patient_master` where status='Active' $qry_filter $qry_doj ORDER by id asc) and bmi<18.5 and diabetes='1' $qry_date GROUP BY patient_id ORDER BY patient_id asc";
error_log("count bmi:" . $count_bmi);
$bmi_result = mysqli_query($conn, $count_bmi);
$bmi_row_count = mysqli_num_rows($bmi_result);
error_log("count:" . $bmi_row_count);
if ($total == 0 || $bmi_row_count == 0) {
$data['bmi_less_18.5_per']['per'] = 0;
} else {
$percentage_emp_per_bmi = ($bmi_row_count / $total) * 100;
$data['bmi_less_18.5_per']['per'] = round($percentage_emp_per_bmi, 2);
}
$data['bmi_less_18.5']['total'] = $total;
$data['bmi_less_18.5']['hbd'] = $bmi_row_count;
$pat_query = "select max(medical_exam_id),bmi,patient_id from medical_examination where patient_id in (SELECT id FROM `patient_master` where status='Active' $qry_filter $qry_doj ORDER by id asc) $qry_date and bmi>=18.5 and bmi<25 GROUP BY patient_id ORDER BY patient_id asc";
$pat_result = mysqli_query($conn, $pat_query);
$total = mysqli_num_rows($pat_result);
$data['bmi_18.5_25']['total'] = $total;
$percentage_emp_per_bmi = 0;
$count_bmi = "select max(medical_exam_id),bmi,patient_id from medical_examination where patient_id in (SELECT id FROM `patient_master` where status='Active' $qry_filter $qry_doj ORDER by id asc) $qry_date and bmi>=18.5 and bmi<25 and diabetes='1' GROUP BY patient_id ORDER BY patient_id asc";
error_log("count bmi:" . $count_bmi);
$bmi_result = mysqli_query($conn, $count_bmi);
$bmi_row_count = mysqli_num_rows($bmi_result);
error_log("count:" . $bmi_row_count);
$data['bmi_18.5_25']['hbd'] = $bmi_row_count;
if ($total == 0 || $bmi_row_count == 0) {
$data['bmi_18.5_25_per']['per'] = 0;
} else {
$percentage_emp_per_bmi = ($bmi_row_count / $total) * 100;
$data['bmi_18.5_25_per']['per'] = round($percentage_emp_per_bmi, 2);
}
$pat_query = "select max(medical_exam_id),bmi,patient_id from medical_examination where patient_id in (SELECT id FROM `patient_master` where status='Active' $qry_filter $qry_doj ORDER by id asc) $qry_date and bmi>=25 and bmi<30 GROUP BY patient_id ORDER BY patient_id asc";
$pat_result = mysqli_query($conn, $pat_query);
$total = mysqli_num_rows($pat_result);
$data['bmi_25_30']['total'] = $total;
$percentage_emp_per_bmi = 0;
$count_bmi = "select max(medical_exam_id),bmi,patient_id from medical_examination where patient_id in (SELECT id FROM `patient_master` where status='Active' $qry_filter $qry_doj ORDER by id asc) $qry_date and bmi>=25 and bmi<30 and diabetes='1' GROUP BY patient_id ORDER BY patient_id asc";
error_log("count bmi:" . $count_bmi);
$bmi_result = mysqli_query($conn, $count_bmi);
$bmi_row_count = mysqli_num_rows($bmi_result);
error_log("count:" . $bmi_row_count);
$data['bmi_25_30']['hbd'] = $bmi_row_count;
if ($total == 0 || $bmi_row_count == 0) {
$data['bmi_25_30_per']['per'] = 0;
} else {
$percentage_emp_per_bmi = ($bmi_row_count / $total) * 100;
$data['bmi_25_30_per']['per'] = round($percentage_emp_per_bmi, 2);
}
$pat_query = "select max(medical_exam_id),bmi,patient_id from medical_examination where patient_id in (SELECT id FROM `patient_master` where status='Active' $qry_filter $qry_doj ORDER by id asc) $qry_date and bmi>=30 GROUP BY patient_id ORDER BY patient_id asc";
$pat_result = mysqli_query($conn, $pat_query);
$total = mysqli_num_rows($pat_result);
$data['bmi_30']['total'] = $total;
$percentage_emp_per_bmi = 0;
$count_bmi = "select max(medical_exam_id),bmi,patient_id from medical_examination where patient_id in (SELECT id FROM `patient_master` where status='Active' $qry_filter $qry_doj ORDER by id asc) $qry_date and bmi>=30 and hbd = '1' GROUP BY patient_id ORDER BY patient_id asc";
error_log("count bmi:" . $count_bmi);
$bmi_result = mysqli_query($conn, $count_bmi);
$bmi_row_count = mysqli_num_rows($bmi_result);
error_log("count:" . $bmi_row_count);
$data['bmi_30']['hbd'] = $bmi_row_count;
if ($total == 0 || $bmi_row_count == 0) {
$data['bmi_30_per']['per'] = 0;
} else {
$percentage_emp_per_bmi = ($bmi_row_count / $total) * 100;
$data['bmi_30_per']['per'] = round($percentage_emp_per_bmi, 2);
}
}
echo json_encode($data);