=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 != '' && sizeof($year1) > 1) { for ($j = 0; $j < sizeof($year1); $j++) { error_log("year:" . $year1[$j] . " size:" . sizeof($year1)); $qry_date = ""; $qry_doj = ""; $qry_date .= "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_10 = 0; $count_health_index = "select max(medical_exam_id),health_index,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 health_index<10 $qry_date GROUP BY patient_id ORDER BY patient_id asc"; error_log("count health_index:" . $count_health_index); $health_index_result = mysqli_query($conn, $count_health_index); $health_index_row_count = mysqli_num_rows($health_index_result); error_log("count:" . $health_index_row_count); $percentage_for_less_10 = ($health_index_row_count / $pat_num_row['total']) * 100; $data['Less_Than_10'][$year1[$j]]['total'] = round($percentage_for_less_10, 2); $percentage_for_10_15 = 0; $count_health_index = "select max(medical_exam_id),health_index,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 health_index>=10 and health_index<15 $qry_date GROUP BY patient_id ORDER BY patient_id asc"; error_log("count health_index:" . $count_health_index); $health_index_result = mysqli_query($conn, $count_health_index); $health_index_row_count = mysqli_num_rows($health_index_result); error_log("count:" . $health_index_row_count); $percentage_for_10_15 = ($health_index_row_count / $pat_num_row['total']) * 100; $data['10_15'][$year1[$j]]['total'] = round($percentage_for_10_15, 2); $percentage_for_15_20 = 0; $count_health_index = "select max(medical_exam_id),health_index,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 health_index>=15 and health_index<20 $qry_date GROUP BY patient_id ORDER BY patient_id asc"; error_log("count health_index:" . $count_health_index); $health_index_result = mysqli_query($conn, $count_health_index); $health_index_row_count = mysqli_num_rows($health_index_result); error_log("count:" . $health_index_row_count); $percentage_for_15_20 = ($health_index_row_count / $pat_num_row['total']) * 100; $data['15_20'][$year1[$j]]['total'] = round($percentage_for_15_20, 2); $percentage_for_more_20 = 0; $count_health_index = "select max(medical_exam_id),health_index,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 health_index>=20 $qry_date GROUP BY patient_id ORDER BY patient_id asc"; error_log("count health_index:" . $count_health_index); $health_index_result = mysqli_query($conn, $count_health_index); $health_index_row_count = mysqli_num_rows($health_index_result); error_log("count:" . $health_index_row_count); $percentage_for_more_20 = ($health_index_row_count / $pat_num_row['total']) * 100; $data['More_Than_20'][$year1[$j]]['total'] = round($percentage_for_more_20, 2); } } else { if (isset($year2) && $year2 != '') { $qry_date .= " and year(medical_entry_date) ='" . $year2 . "'"; $qry_filter .= " and year(doj) <='" . $year2 . "'"; } $pat_query = "SELECT count(*) as total FROM patient_master where status='Active' $qry_filter"; $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_health_index = 0; $count_health_index = "select max(medical_exam_id),health_index,patient_id from medical_examination where patient_id in (SELECT id FROM `patient_master` where status='Active' $qry_filter ORDER by id asc) and health_index<10 $qry_date GROUP BY patient_id ORDER BY patient_id asc"; error_log("count health_index:" . $count_health_index); $health_index_result = mysqli_query($conn, $count_health_index); $health_index_row_count = mysqli_num_rows($health_index_result); error_log("count:" . $health_index_row_count); $data['health_index_less_10'] = $health_index_row_count; $percentage_emp_per_health_index = ($health_index_row_count / $pat_num_row['total']) * 100; $data['health_index_less_10_per'] = round($percentage_emp_per_health_index, 2); $percentage_emp_per_health_index = 0; $count_health_index = "select max(medical_exam_id),health_index,patient_id from medical_examination where patient_id in (SELECT id FROM `patient_master` where status='Active' $qry_filter ORDER by id asc) and health_index>=10 and health_index<15 $qry_date GROUP BY patient_id ORDER BY patient_id asc"; error_log("count health_index:" . $count_health_index); $health_index_result = mysqli_query($conn, $count_health_index); $health_index_row_count = mysqli_num_rows($health_index_result); error_log("count:" . $health_index_row_count); $data['health_index_10_15'] = $health_index_row_count; $percentage_emp_per_health_index = ($health_index_row_count / $pat_num_row['total']) * 100; $data['health_index_10_15_per'] = round($percentage_emp_per_health_index, 2); $percentage_emp_per_health_index = 0; $count_health_index = "select max(medical_exam_id),health_index,patient_id from medical_examination where patient_id in (SELECT id FROM `patient_master` where status='Active' $qry_filter ORDER by id asc) and health_index>=15 and health_index<20 $qry_date GROUP BY patient_id ORDER BY patient_id asc"; error_log("count health_index:" . $count_health_index); $health_index_result = mysqli_query($conn, $count_health_index); $health_index_row_count = mysqli_num_rows($health_index_result); error_log("count:" . $health_index_row_count); $data['health_index_15_20'] = $health_index_row_count; $percentage_emp_per_health_index = ($health_index_row_count / $pat_num_row['total']) * 100; $data['health_index_15_20_per'] = round($percentage_emp_per_health_index, 2); $percentage_emp_per_health_index = 0; $count_health_index = "select max(medical_exam_id),health_index,patient_id from medical_examination where patient_id in (SELECT id FROM `patient_master` where status='Active' $qry_filter ORDER by id asc) and health_index>=20 $qry_date GROUP BY patient_id ORDER BY patient_id asc"; error_log("count health_index:" . $count_health_index); $health_index_result = mysqli_query($conn, $count_health_index); $health_index_row_count = mysqli_num_rows($health_index_result); error_log("count:" . $health_index_row_count); $data['health_index_20'] = $health_index_row_count; $percentage_emp_per_health_index = ($health_index_row_count / $pat_num_row['total']) * 100; $data['health_index_20_per'] = round($percentage_emp_per_health_index, 2); } echo json_encode($data);