=str_to_date('" . $start_date . "','%d-%m-%Y') "; } if (isset($end_date) && $end_date != '') { $qry_date1 .= " and date(checkup_date) <=str_to_date('" . $end_date . "','%d-%m-%Y') "; } if (isset($month) && $month != '') { $qry_date1 .= " and month(checkup_date) in (" . $month . ")"; } $data = array(); if (isset($year) && $year != '' && sizeof($year1) > 1) { for ($j = 0; $j < sizeof($year1); $j++) { error_log("year:" . $year1[$j] . " size:" . sizeof($year1)); $qry_date = ""; $qry_dob = ""; $qry_date .= "and year(checkup_date) ='" . $year1[$j] . "'"; $qry_dob .= "and year(doj) <= '" . $year1[$j] . "'"; //for 0 to 2 $total = 0; $pat_query = "SELECT id FROM patient_master where (datediff(CURRENT_DATE,doj)/365)>=0 and (datediff(CURRENT_DATE,doj)/365)<2 and status='Active' $qry_filter $qry_dob"; $pat_result = mysqli_query($conn, $pat_query); if (mysqli_num_rows($pat_result)) { $total = mysqli_num_rows($pat_result); } else { $total = 0; } $per_for_0_to_2 = []; $count_health_index = "SELECT max(checkup_id),health_index from checkup_form where emp_id in (SELECT id FROM patient_master where (datediff(CURRENT_DATE,doj)/365)>=0 and (datediff(CURRENT_DATE,doj)/365)<2 and status='Active' $qry_filter $qry_dob) $qry_date1 $qry_date GROUP by emp_id"; error_log("count health_index:" . $count_health_index); $health_index_result = mysqli_query($conn, $count_health_index); $i = 0; if (mysqli_num_rows($health_index_result)) { while ($row_health_index = mysqli_fetch_assoc($health_index_result)) { $per_for_0_to_2[$i] = $row_health_index['health_index']; $i++; } } $avg = 0; if (count($per_for_0_to_2)) { $avg = round(array_sum($per_for_0_to_2) / count($per_for_0_to_2), 2); } $data['0-2'][$year1[$j]]['total'] = $avg; // for 2 to 5 $total = 0; $pat_query = "SELECT id FROM patient_master where (datediff(CURRENT_DATE,doj)/365)>=2 and (datediff(CURRENT_DATE,doj)/365)<5 and status='Active' $qry_filter $qry_dob"; $pat_result = mysqli_query($conn, $pat_query); if (mysqli_num_rows($pat_result)) { $total = mysqli_num_rows($pat_result); } else { $total = 0; } $per_for_2_to_5 = []; $count_health_index = "SELECT max(checkup_id),health_index from checkup_form where emp_id in (SELECT id FROM patient_master where (datediff(CURRENT_DATE,doj)/365)>=2 and (datediff(CURRENT_DATE,doj)/365)<5 and status='Active' $qry_filter $qry_dob) $qry_date1 $qry_date GROUP by emp_id"; error_log("count health_index:" . $count_health_index); $health_index_result = mysqli_query($conn, $count_health_index); $i = 0; if (mysqli_num_rows($health_index_result)) { while ($row_health_index = mysqli_fetch_assoc($health_index_result)) { $per_for_2_to_5[$i] = $row_health_index['health_index']; $i++; } } $avg = 0; if (count($per_for_2_to_5)) { $avg = round(array_sum($per_for_2_to_5) / count($per_for_2_to_5), 2); } $data['2-5'][$year1[$j]]['total'] = $avg; // for 5 to 10 $total = 0; $pat_query = "SELECT id FROM patient_master where (datediff(CURRENT_DATE,doj)/365)>=5 and (datediff(CURRENT_DATE,doj)/365)<10 and status='Active' $qry_filter $qry_dob"; $pat_result = mysqli_query($conn, $pat_query); if (mysqli_num_rows($pat_result)) { $total = mysqli_num_rows($pat_result); } else { $total = 0; } $per_for_5_to_10 = []; $count_health_index = "SELECT max(checkup_id),health_index from checkup_form where emp_id in (SELECT id FROM patient_master where (datediff(CURRENT_DATE,doj)/365)>=5 and (datediff(CURRENT_DATE,doj)/365)<10 and status='Active' $qry_filter $qry_dob) $qry_date1 $qry_date GROUP by emp_id"; error_log("count health_index:" . $count_health_index); $health_index_result = mysqli_query($conn, $count_health_index); $i = 0; if (mysqli_num_rows($health_index_result)) { while ($row_health_index = mysqli_fetch_assoc($health_index_result)) { $per_for_5_to_10[$i] = $row_health_index['health_index']; $i++; } } $avg = 0; if (count($per_for_5_to_10)) { $avg = round(array_sum($per_for_5_to_10) / count($per_for_5_to_10), 2); } $data['5-10'][$year1[$j]]['total'] = $avg; //for 10 to 15 $total = 0; $pat_query = "SELECT id FROM patient_master where (datediff(CURRENT_DATE,doj)/365)>=10 and (datediff(CURRENT_DATE,doj)/365)<15 and status='Active' $qry_filter $qry_dob"; $pat_result = mysqli_query($conn, $pat_query); if (mysqli_num_rows($pat_result)) { $total = mysqli_num_rows($pat_result); } else { $total = 0; } $per_for_10_to_15 = []; $count_health_index = "SELECT max(checkup_id),health_index from checkup_form where emp_id in (SELECT id FROM patient_master where (datediff(CURRENT_DATE,doj)/365)>=10 and (datediff(CURRENT_DATE,doj)/365)<15 and status='Active' $qry_filter $qry_dob) $qry_date1 $qry_date GROUP by emp_id"; error_log("count health_index:" . $count_health_index); $health_index_result = mysqli_query($conn, $count_health_index); $i = 0; if (mysqli_num_rows($health_index_result)) { while ($row_health_index = mysqli_fetch_assoc($health_index_result)) { $per_for_10_to_15[$i] = $row_health_index['health_index']; $i++; } } $avg = 0; if (count($per_for_10_to_15)) { $avg = round(array_sum($per_for_10_to_15) / count($per_for_10_to_15), 2); } $data['10-15'][$year1[$j]]['total'] = $avg; // for 15 to 20 $total = 0; $pat_query = "SELECT id FROM patient_master where (datediff(CURRENT_DATE,doj)/365)>=15 and (datediff(CURRENT_DATE,doj)/365)<20 and status='Active' $qry_filter $qry_dob"; $pat_result = mysqli_query($conn, $pat_query); if (mysqli_num_rows($pat_result)) { $total = mysqli_num_rows($pat_result); } else { $total = 0; } $per_for_15_to_20 = []; $count_health_index = "SELECT max(checkup_id),health_index from checkup_form where emp_id in (SELECT id FROM patient_master where (datediff(CURRENT_DATE,doj)/365)>=15 and (datediff(CURRENT_DATE,doj)/365)<20 and status='Active' $qry_filter $qry_dob) $qry_date1 $qry_date GROUP by emp_id"; error_log("count health_index:" . $count_health_index); $health_index_result = mysqli_query($conn, $count_health_index); $i = 0; if (mysqli_num_rows($health_index_result)) { while ($row_health_index = mysqli_fetch_assoc($health_index_result)) { $per_for_15_to_20[$i] = $row_health_index['health_index']; $i++; } } $avg = 0; if (count($per_for_15_to_20)) { $avg = round(array_sum($per_for_15_to_20) / count($per_for_15_to_20), 2); } $data['15-20'][$year1[$j]]['total'] = $avg; // for 20 to 25 $total = 0; $pat_query = "SELECT id FROM patient_master where (datediff(CURRENT_DATE,doj)/365)>=20 and (datediff(CURRENT_DATE,doj)/365)<25 and status='Active' $qry_filter $qry_dob"; $pat_result = mysqli_query($conn, $pat_query); if (mysqli_num_rows($pat_result)) { $total = mysqli_num_rows($pat_result); } else { $total = 0; } $per_for_20_to_25 = []; $count_health_index = "SELECT max(checkup_id),health_index from checkup_form where emp_id in (SELECT id FROM patient_master where (datediff(CURRENT_DATE,doj)/365)>=20 and (datediff(CURRENT_DATE,doj)/365)<25 and status='Active' $qry_filter $qry_dob) $qry_date1 $qry_date GROUP by emp_id"; error_log("count health_index:" . $count_health_index); $health_index_result = mysqli_query($conn, $count_health_index); $i = 0; if (mysqli_num_rows($health_index_result)) { while ($row_health_index = mysqli_fetch_assoc($health_index_result)) { $per_for_20_to_25[$i] = $row_health_index['health_index']; $i++; } } $avg = 0; if (count($per_for_20_to_25)) { $avg = round(array_sum($per_for_20_to_25) / count($per_for_20_to_25), 2); } $data['20-25'][$year1[$j]]['total'] = $avg; //for greater_than_equal_to_25 $total = 0; $pat_query = "SELECT id FROM patient_master where (datediff(CURRENT_DATE,doj)/365)>=25 and status='Active' $qry_filter $qry_dob"; $pat_result = mysqli_query($conn, $pat_query); if (mysqli_num_rows($pat_result)) { $total = mysqli_num_rows($pat_result); } else { $total = 0; } $per_for_greater_than_equal_to_25 = []; $count_health_index = "SELECT max(checkup_id),health_index from checkup_form where emp_id in (SELECT id FROM patient_master where (datediff(CURRENT_DATE,doj)/365)>=25 and status='Active' $qry_filter $qry_dob) $qry_date1 $qry_date GROUP by emp_id"; error_log("count health_index:" . $count_health_index); $health_index_result = mysqli_query($conn, $count_health_index); $i = 0; if (mysqli_num_rows($health_index_result)) { while ($row_health_index = mysqli_fetch_assoc($health_index_result)) { $per_for_greater_than_equal_to_25[$i] = $row_health_index['health_index']; $i++; } } $avg = 0; if (count($per_for_greater_than_equal_to_25)) { $avg = round(array_sum($per_for_greater_than_equal_to_25) / count($per_for_greater_than_equal_to_25), 2); } $data['>=50'][$year1[$j]]['total'] = $avg; } } else { if (isset($year2) && $year2 != '') { $qry_date1 .= " and year(checkup_date) ='" . $year2 . "'"; $qry_dob .= "and year(doj) <= '" . $year2 . "'"; } //for 0 to 2 $total = 0; $pat_query = "SELECT id FROM patient_master where (datediff(CURRENT_DATE,doj)/365)>=0 and (datediff(CURRENT_DATE,doj)/365)<2 and status='Active' $qry_filter $qry_dob"; $pat_result = mysqli_query($conn, $pat_query); if (mysqli_num_rows($pat_result)) { $total = mysqli_num_rows($pat_result); } else { $total = 0; } $per_for_0_to_2 = []; $count_health_index = "SELECT max(checkup_id),health_index from checkup_form where emp_id in (SELECT id FROM patient_master where (datediff(CURRENT_DATE,doj)/365)>=0 and (datediff(CURRENT_DATE,doj)/365)<2 and status='Active' $qry_filter $qry_dob) $qry_date1 GROUP by emp_id"; error_log("count health_index:" . $count_health_index); $health_index_result = mysqli_query($conn, $count_health_index); $i = 0; if (mysqli_num_rows($health_index_result)) { while ($row_health_index = mysqli_fetch_assoc($health_index_result)) { $per_for_0_to_2[$i] = $row_health_index['health_index']; $i++; } } $avg = 0; if (count($per_for_0_to_2)) { $avg = round(array_sum($per_for_0_to_2) / count($per_for_0_to_2), 2); } $data['exp_0_2']['avg'] = $avg; $data['exp_0_2']['gtotal'] = $total; // for 2 to 5 $total = 0; $pat_query = "SELECT id FROM patient_master where (datediff(CURRENT_DATE,doj)/365)>=2 and (datediff(CURRENT_DATE,doj)/365)<5 and status='Active' $qry_filter $qry_dob"; $pat_result = mysqli_query($conn, $pat_query); if (mysqli_num_rows($pat_result)) { $total = mysqli_num_rows($pat_result); } else { $total = 0; } $per_for_2_to_5 = []; $count_health_index = "SELECT max(checkup_id),health_index from checkup_form where emp_id in (SELECT id FROM patient_master where (datediff(CURRENT_DATE,doj)/365)>=2 and (datediff(CURRENT_DATE,doj)/365)<5 and status='Active' $qry_filter $qry_dob) $qry_date1 GROUP by emp_id"; error_log("count health_index:" . $count_health_index); $health_index_result = mysqli_query($conn, $count_health_index); $i = 0; if (mysqli_num_rows($health_index_result)) { while ($row_health_index = mysqli_fetch_assoc($health_index_result)) { $per_for_2_to_5[$i] = $row_health_index['health_index']; $i++; } } $avg = 0; if (count($per_for_2_to_5)) { $avg = round(array_sum($per_for_2_to_5) / count($per_for_2_to_5), 2); } $data['exp_2_5']['avg'] = $avg; $data['exp_2_5']['gtotal'] = $total; // for 5 to 10 $total = 0; $pat_query = "SELECT id FROM patient_master where (datediff(CURRENT_DATE,doj)/365)>=5 and (datediff(CURRENT_DATE,doj)/365)<10 and status='Active' $qry_filter $qry_dob"; $pat_result = mysqli_query($conn, $pat_query); if (mysqli_num_rows($pat_result)) { $total = mysqli_num_rows($pat_result); } else { $total = 0; } $per_for_5_to_10 = []; $count_health_index = "SELECT max(checkup_id),health_index from checkup_form where emp_id in (SELECT id FROM patient_master where (datediff(CURRENT_DATE,doj)/365)>=5 and (datediff(CURRENT_DATE,doj)/365)<10 and status='Active' $qry_filter $qry_dob) $qry_date1 GROUP by emp_id"; error_log("count health_index:" . $count_health_index); $health_index_result = mysqli_query($conn, $count_health_index); $i = 0; if (mysqli_num_rows($health_index_result)) { while ($row_health_index = mysqli_fetch_assoc($health_index_result)) { $per_for_5_to_10[$i] = $row_health_index['health_index']; $i++; } } $avg = 0; if (count($per_for_5_to_10)) { $avg = round(array_sum($per_for_5_to_10) / count($per_for_5_to_10), 2); } $data['exp_5_10']['avg'] = $avg; $data['exp_5_10']['gtotal'] = $total; //for 10 to 15 $total = 0; $pat_query = "SELECT id FROM patient_master where (datediff(CURRENT_DATE,doj)/365)>=10 and (datediff(CURRENT_DATE,doj)/365)<15 and status='Active' $qry_filter $qry_dob"; $pat_result = mysqli_query($conn, $pat_query); if (mysqli_num_rows($pat_result)) { $total = mysqli_num_rows($pat_result); } else { $total = 0; } $per_for_10_to_15 = []; $count_health_index = "SELECT max(checkup_id),health_index from checkup_form where emp_id in (SELECT id FROM patient_master where (datediff(CURRENT_DATE,doj)/365)>=10 and (datediff(CURRENT_DATE,doj)/365)<15 and status='Active' $qry_filter $qry_dob) $qry_date1 GROUP by emp_id"; error_log("count health_index:" . $count_health_index); $health_index_result = mysqli_query($conn, $count_health_index); $i = 0; if (mysqli_num_rows($health_index_result)) { while ($row_health_index = mysqli_fetch_assoc($health_index_result)) { $per_for_10_to_15[$i] = $row_health_index['health_index']; $i++; } } $avg = 0; if (count($per_for_10_to_15)) { $avg = round(array_sum($per_for_10_to_15) / count($per_for_10_to_15), 2); } $data['exp_10_15']['avg'] = $avg; $data['exp_10_15']['gtotal'] = $total; // for 15 to 20 $total = 0; $pat_query = "SELECT id FROM patient_master where (datediff(CURRENT_DATE,doj)/365)>=15 and (datediff(CURRENT_DATE,doj)/365)<20 and status='Active' $qry_filter $qry_dob"; $pat_result = mysqli_query($conn, $pat_query); if (mysqli_num_rows($pat_result)) { $total = mysqli_num_rows($pat_result); } else { $total = 0; } $per_for_15_to_20 = []; $count_health_index = "SELECT max(checkup_id),health_index from checkup_form where emp_id in (SELECT id FROM patient_master where (datediff(CURRENT_DATE,doj)/365)>=15 and (datediff(CURRENT_DATE,doj)/365)<20 and status='Active' $qry_filter $qry_dob) $qry_date1 GROUP by emp_id"; error_log("count health_index:" . $count_health_index); $health_index_result = mysqli_query($conn, $count_health_index); $i = 0; if (mysqli_num_rows($health_index_result)) { while ($row_health_index = mysqli_fetch_assoc($health_index_result)) { $per_for_15_to_20[$i] = $row_health_index['health_index']; $i++; } } $avg = 0; if (count($per_for_15_to_20)) { $avg = round(array_sum($per_for_15_to_20) / count($per_for_15_to_20), 2); } $data['exp_15_20']['avg'] = $avg; $data['exp_15_20']['gtotal'] = $total; // for 20 to 25 $total = 0; $pat_query = "SELECT id FROM patient_master where (datediff(CURRENT_DATE,doj)/365)>=20 and (datediff(CURRENT_DATE,doj)/365)<25 and status='Active' $qry_filter $qry_dob"; $pat_result = mysqli_query($conn, $pat_query); if (mysqli_num_rows($pat_result)) { $total = mysqli_num_rows($pat_result); } else { $total = 0; } $per_for_20_to_25 = []; $count_health_index = "SELECT max(checkup_id),health_index from checkup_form where emp_id in (SELECT id FROM patient_master where (datediff(CURRENT_DATE,doj)/365)>=20 and (datediff(CURRENT_DATE,doj)/365)<25 and status='Active' $qry_filter $qry_dob) $qry_date1 GROUP by emp_id"; error_log("count health_index:" . $count_health_index); $health_index_result = mysqli_query($conn, $count_health_index); $i = 0; if (mysqli_num_rows($health_index_result)) { while ($row_health_index = mysqli_fetch_assoc($health_index_result)) { $per_for_20_to_25[$i] = $row_health_index['health_index']; $i++; } } $avg = 0; if (count($per_for_20_to_25)) { $avg = round(array_sum($per_for_20_to_25) / count($per_for_20_to_25), 2); } $data['exp_20_25']['avg'] = $avg; $data['exp_20_25']['gtotal'] = $total; //for greater_than_equal_to_25 $total = 0; $pat_query = "SELECT id FROM patient_master where (datediff(CURRENT_DATE,doj)/365)>=25 and status='Active' $qry_filter $qry_dob"; $pat_result = mysqli_query($conn, $pat_query); if (mysqli_num_rows($pat_result)) { $total = mysqli_num_rows($pat_result); } else { $total = 0; } $per_for_greater_than_equal_to_25 = []; $count_health_index = "SELECT max(checkup_id),health_index from checkup_form where emp_id in (SELECT id FROM patient_master where (datediff(CURRENT_DATE,doj)/365)>=25 and status='Active' $qry_filter $qry_dob) $qry_date1 GROUP by emp_id"; error_log("count health_index:" . $count_health_index); $health_index_result = mysqli_query($conn, $count_health_index); $i = 0; if (mysqli_num_rows($health_index_result)) { while ($row_health_index = mysqli_fetch_assoc($health_index_result)) { $per_for_greater_than_equal_to_25[$i] = $row_health_index['health_index']; $i++; } } $avg = 0; if (count($per_for_greater_than_equal_to_25)) { $avg = round(array_sum($per_for_greater_than_equal_to_25) / count($per_for_greater_than_equal_to_25), 2); } $data['exp_greater_than_equal_to_25']['avg'] = $avg; $data['exp_greater_than_equal_to_25']['gtotal'] = $total; } echo json_encode($data);