=str_to_date('" . $start_date . "','%d-%m-%Y') "; } if (isset($end_date) && $end_date != '') { $qry_date1 .= " 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 . ")"; } $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] . "'"; $per_for_18_to_25 = 0; $total_alcohol_pat = 0; $total = 0; $pat_query = "SELECT id FROM patient_master where YEAR(CURDATE())-year(dob)>=18 and YEAR(CURDATE())-year(dob)<25 and status='Active' $qry_filter $qry_doj"; $pat_result = mysqli_query($conn, $pat_query); $total = mysqli_num_rows($pat_result); $count_alcohol = "SELECT max(medical_exam_id),patient_id,alcohol from medical_examination where patient_id in (SELECT id FROM patient_master where YEAR(CURDATE())-year(dob)>=18 and YEAR(CURDATE())-year(dob)<25 and status='Active' $qry_filter $qry_doj) $qry_date1 $qry_date and alcohol='1' GROUP by patient_id"; error_log("count alcohol:" . $count_alcohol); $alcohol_result = mysqli_query($conn, $count_alcohol); $total_alcohol_pat = mysqli_num_rows($alcohol_result); if ($total == 0 || $total_alcohol_pat == 0) { $data['18-25'][$year1[$j]]['total'] = 0; } else { $per_for_18_to_25 = ($total_alcohol_pat / $total) * 100; $data['18-25'][$year1[$j]]['total'] = round($per_for_18_to_25, 2); } error_log("Query1::" . $count_alcohol); $per_for_26_to_30 = 0; $total_alcohol_pat = 0; $total = 0; $pat_query = "SELECT id FROM patient_master where YEAR(CURDATE())-year(dob)>=25 and YEAR(CURDATE())-year(dob)<30 and status='Active' $qry_filter $qry_doj"; $pat_result = mysqli_query($conn, $pat_query); $total = mysqli_num_rows($pat_result); $count_alcohol = "SELECT max(medical_exam_id),patient_id,alcohol from medical_examination where patient_id in (SELECT id FROM patient_master where YEAR(CURDATE())-year(dob)>=25 and YEAR(CURDATE())-year(dob)<30 and status='Active' $qry_filter $qry_doj) $qry_date1 $qry_date and alcohol='1' GROUP by patient_id"; error_log("count alcohol:" . $count_alcohol); $alcohol_result = mysqli_query($conn, $count_alcohol); $total_alcohol_pat = mysqli_num_rows($alcohol_result); if ($total == 0 || $total_alcohol_pat == 0) { $data['25-30'][$year1[$j]]['total'] = 0; } else { $per_for_26_to_30 = ($total_alcohol_pat / $total) * 100; $data['25-30'][$year1[$j]]['total'] = round($per_for_26_to_30, 2); } error_log("Query2::" . $count_alcohol); $per_for_31_to_40 = 0; $total_alcohol_pat = 0; $total = 0; $pat_query = "SELECT id FROM patient_master where YEAR(CURDATE())-year(dob)>=30 and YEAR(CURDATE())-year(dob)<40 and status='Active' $qry_filter $qry_doj"; $pat_result = mysqli_query($conn, $pat_query); $total = mysqli_num_rows($pat_result); $count_alcohol = "SELECT max(medical_exam_id),patient_id,alcohol from medical_examination where patient_id in (SELECT id FROM patient_master where YEAR(CURDATE())-year(dob)>=30 and YEAR(CURDATE())-year(dob)<40 and status='Active' $qry_filter $qry_doj) $qry_date1 $qry_date and alcohol='1' GROUP by patient_id"; error_log("count alcohol:" . $count_alcohol); $alcohol_result = mysqli_query($conn, $count_alcohol); $total_alcohol_pat = mysqli_num_rows($alcohol_result); if ($total == 0 || $total_alcohol_pat == 0) { $data['30-40'][$year1[$j]]['total'] = 0; } else { $per_for_31_to_40 = ($total_alcohol_pat / $total) * 100; $data['30-40'][$year1[$j]]['total'] = round($per_for_31_to_40, 2); } error_log("Query3::" . $count_alcohol); $per_for_41_to_50 = 0; $total_alcohol_pat = 0; $total = 0; $pat_query = "SELECT id FROM patient_master where YEAR(CURDATE())-year(dob)>=40 and YEAR(CURDATE())-year(dob)<50 and status='Active' $qry_filter $qry_doj"; $pat_result = mysqli_query($conn, $pat_query); $total = mysqli_num_rows($pat_result); $count_alcohol = "SELECT max(medical_exam_id),patient_id,alcohol from medical_examination where patient_id in (SELECT id FROM patient_master where YEAR(CURDATE())-year(dob)>=40 and YEAR(CURDATE())-year(dob)<50 and status='Active' $qry_filter $qry_doj) $qry_date1 $qry_date and alcohol='1' GROUP by patient_id"; error_log("count alcohol:" . $count_alcohol); $alcohol_result = mysqli_query($conn, $count_alcohol); $total_alcohol_pat = mysqli_num_rows($alcohol_result); if ($total == 0 || $total_alcohol_pat == 0) { $data['40-50'][$year1[$j]]['total'] = 0; } else { $per_for_41_to_50 = ($total_alcohol_pat / $total) * 100; $data['40-50'][$year1[$j]]['total'] = round($per_for_41_to_50, 2); } error_log("Query4::" . $count_alcohol); $per_greater_than_50 = 0; $total_alcohol_pat = 0; $total = 0; $pat_query = "SELECT id FROM patient_master where YEAR(CURDATE())-year(dob)>=50 and status='Active' $qry_filter $qry_doj"; $pat_result = mysqli_query($conn, $pat_query); $total = mysqli_num_rows($pat_result); $count_alcohol = "SELECT max(medical_exam_id),patient_id,alcohol from medical_examination where patient_id in (SELECT id FROM patient_master where YEAR(CURDATE())-year(dob)>=50 and status='Active' $qry_filter $qry_doj) $qry_date1 $qry_date and alcohol='1' GROUP by patient_id"; error_log("count alcohol:" . $count_alcohol); $alcohol_result = mysqli_query($conn, $count_alcohol); $total_alcohol_pat = mysqli_num_rows($alcohol_result); if ($total == 0 || $total_alcohol_pat == 0) { $data['>=50'][$year1[$j]]['total'] = 0; } else { $per_greater_than_50 = ($total_alcohol_pat / $total) * 100; $data['>=50'][$year1[$j]]['total'] = round($per_greater_than_50, 2); } error_log("Query5::" . $count_alcohol); } } else { if (isset($year2) && $year2 != '') { $qry_date1 .= " and year(medical_entry_date) ='" . $year2 . "'"; $qry_filter .= " and year(doj) <= '" . $year2 . "'"; } //for 18 to 25 $total_alcohol_pat = 0; $total = 0; $pat_query = "SELECT id FROM patient_master where YEAR(CURDATE())-year(dob)>=18 and YEAR(CURDATE())-year(dob)<25 and status='Active' $qry_filter"; $pat_result = mysqli_query($conn, $pat_query); $total = mysqli_num_rows($pat_result); $count_alcohol = "SELECT max(medical_exam_id),patient_id,alcohol from medical_examination where patient_id in (SELECT id FROM patient_master where YEAR(CURDATE())-year(dob)>=18 and YEAR(CURDATE())-year(dob)<25 and status='Active' $qry_filter) $qry_date1 and alcohol='1' GROUP by patient_id"; error_log("count alcohol:" . $count_alcohol); $alcohol_result = mysqli_query($conn, $count_alcohol); $total_alcohol_pat = mysqli_num_rows($alcohol_result); $data['age_18_25']['total'] = $total_alcohol_pat; $data['age_18_25']['gtotal'] = $total; //for 26 to 30 $total_alcohol_pat = 0; $total = 0; $pat_query = "SELECT id FROM patient_master where YEAR(CURDATE())-year(dob)>=25 and YEAR(CURDATE())-year(dob)<30 and status='Active' $qry_filter"; $pat_result = mysqli_query($conn, $pat_query); $total = mysqli_num_rows($pat_result); $count_alcohol = "SELECT max(medical_exam_id),patient_id,alcohol from medical_examination where patient_id in (SELECT id FROM patient_master where YEAR(CURDATE())-year(dob)>=25 and YEAR(CURDATE())-year(dob)<30 and status='Active' $qry_filter) $qry_date1 and alcohol='1' GROUP by patient_id"; error_log("count alcohol:" . $count_alcohol); $alcohol_result = mysqli_query($conn, $count_alcohol); $total_alcohol_pat = mysqli_num_rows($alcohol_result); $data['age_25_30']['total'] = $total_alcohol_pat; $data['age_25_30']['gtotal'] = $total; //for 31 to 40 $total_alcohol_pat = 0; $total = 0; $pat_query = "SELECT id FROM patient_master where YEAR(CURDATE())-year(dob)>=30 and YEAR(CURDATE())-year(dob)<40 and status='Active' $qry_filter"; $pat_result = mysqli_query($conn, $pat_query); $total = mysqli_num_rows($pat_result); $count_alcohol = "SELECT max(medical_exam_id),patient_id,alcohol from medical_examination where patient_id in (SELECT id FROM patient_master where YEAR(CURDATE())-year(dob)>=30 and YEAR(CURDATE())-year(dob)<40 and status='Active' $qry_filter) $qry_date1 and alcohol='1' GROUP by patient_id"; error_log("count alcohol:" . $count_alcohol); $alcohol_result = mysqli_query($conn, $count_alcohol); $total_alcohol_pat = mysqli_num_rows($alcohol_result); $data['age_30_40']['total'] = $total_alcohol_pat; $data['age_30_40']['gtotal'] = $total; //for 41 to 50 $total_alcohol_pat = 0; $total = 0; $pat_query = "SELECT id FROM patient_master where YEAR(CURDATE())-year(dob)>=40 and YEAR(CURDATE())-year(dob)<50 and status='Active' $qry_filter"; $pat_result = mysqli_query($conn, $pat_query); $total = mysqli_num_rows($pat_result); $count_alcohol = "SELECT max(medical_exam_id),patient_id,alcohol from medical_examination where patient_id in (SELECT id FROM patient_master where YEAR(CURDATE())-year(dob)>=40 and YEAR(CURDATE())-year(dob)<50 and status='Active' $qry_filter) $qry_date1 and alcohol='1' GROUP by patient_id"; error_log("count alcohol:" . $count_alcohol); $alcohol_result = mysqli_query($conn, $count_alcohol); $total_alcohol_pat = mysqli_num_rows($alcohol_result); $data['age_40_50']['total'] = $total_alcohol_pat; $data['age_40_50']['gtotal'] = $total; //for >50 $total_alcohol_pat = 0; $total = 0; $pat_query = "SELECT id FROM patient_master where YEAR(CURDATE())-year(dob)>=50 and status='Active' $qry_filter"; $pat_result = mysqli_query($conn, $pat_query); $total = mysqli_num_rows($pat_result); $count_alcohol = "SELECT max(medical_exam_id),patient_id,alcohol from medical_examination where patient_id in (SELECT id FROM patient_master where YEAR(CURDATE())-year(dob)>50 and status='Active' $qry_filter) $qry_date1 and alcohol='1' GROUP by patient_id"; error_log("count alcohol:" . $count_alcohol); $alcohol_result = mysqli_query($conn, $count_alcohol); $total_alcohol_pat = mysqli_num_rows($alcohol_result); $data['age_more_equal_50']['total'] = $total_alcohol_pat; $data['age_more_equal_50']['gtotal'] = $total; } echo json_encode($data);