=str_to_date('" . $start_date . "','%d-%m-%Y') "; } if (isset($end_date) && $end_date != '') { $qry_date .= " and date(medical_entry_date) <=str_to_date('" . $end_date . "','%d-%m-%Y') "; } // if(isset($month) && $month!=''){ // $qry_date1.=" and month(medical_entry_date) in (".$month.")"; // } $i = 0; $data = array(); if (isset($year) && $year != '' && count($year1) > 1) { for ($j = 0; $j < count($year1); $j++) { error_log("year:" . $year1[$j] . " size:" . count($year1)); $qry_date1 = ""; $qry_doj = ""; $qry_date1 .= "and year(medical_entry_date) ='" . $year1[$j] . "'"; $qry_doj .= "and year(doj) <= '" . $year1[$j] . "'"; $pat_query = "SELECT count(*) as total FROM patient_master where status='Active' $qry_filter $qry_doj"; $pat_result = mysqli_query($conn, $pat_query); $pat_num_row = mysqli_fetch_assoc($pat_result); error_log("total:" . $pat_num_row['total']); $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 $qry_date $qry_date1 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); $percentage_for_less_18 = ($bmi_row_count / $pat_num_row['total']) * 100; $data['Less_Than_18.5'][$year1[$j]]['total'] = round($percentage_for_less_18, 2); $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) and bmi>=18.5 and bmi<25 $qry_date $qry_date1 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); $percentage_for_18_25 = ($bmi_row_count / $pat_num_row['total']) * 100; $data['18.5_25'][$year1[$j]]['total'] = round($percentage_for_18_25, 2); $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) and bmi>=25 and bmi<30 $qry_date $qry_date1 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); $percentage_for_25_30 = ($bmi_row_count / $pat_num_row['total']) * 100; $data['25_30'][$year1[$j]]['total'] = round($percentage_for_25_30, 2); $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 $qry_date $qry_date1 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); $percentage_for_more_30 = ($bmi_row_count / $pat_num_row['total']) * 100; $data['More_Than_30'][$year1[$j]]['total'] = round($percentage_for_more_30, 2); } } else { if (isset($year2) && $year2 != '') { $qry_date .= " and year(medical_entry_date) ='" . $year2 . "'"; $qry_doj .= " and year(doj) <= '" . $year2 . "'"; } $pat_query = "SELECT count(*) as total FROM patient_master where status='Active' $qry_filter $qry_doj"; $pat_result = mysqli_query($conn, $pat_query); $pat_num_row = mysqli_fetch_assoc($pat_result); $data['total_count'] = $pat_num_row['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) and bmi<18.5 $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); $data['bmi_less_18.5'] = $bmi_row_count; $percentage_emp_per_bmi = ($bmi_row_count / $pat_num_row['total']) * 100; $data['bmi_less_18.5_per'] = round($percentage_emp_per_bmi, 2); $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) and bmi>=18.5 and bmi<25 $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); $data['bmi_18.5_25'] = $bmi_row_count; $percentage_emp_per_bmi = ($bmi_row_count / $pat_num_row['total']) * 100; $data['bmi_18.5_25_per'] = round($percentage_emp_per_bmi, 2); $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) and bmi>=25 and bmi<30 $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); $data['bmi_25_30'] = $bmi_row_count; $percentage_emp_per_bmi = ($bmi_row_count / $pat_num_row['total']) * 100; $data['bmi_25_30_per'] = round($percentage_emp_per_bmi, 2); $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) and bmi>=30 $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); $data['bmi_30'] = $bmi_row_count; $percentage_emp_per_bmi = ($bmi_row_count / $pat_num_row['total']) * 100; $data['bmi_30_per'] = round($percentage_emp_per_bmi, 2); } echo json_encode($data);