$qry_date.=" and year(medical_entry_date) ='".$year1[$j]."'";
$qry_doj.=" and year(doj) <= '".$year1[$j]."'";
$count_query="select count(*) as total FROM patient_master where status = 'Active' and dept_id = '".$dept_row['dept_id']."' $qry_filter$qry_doj";
$count_result=mysqli_query($conn,$count_query);
error_log("count_query::".$count_query);
$row_count=mysqli_fetch_assoc($count_result);
$count_bmi="select max(medical_exam_id),patient_id from medical_examination where patient_id in (SELECT id FROM `patient_master` where status='Active' and dept_id = '".$dept_row['dept_id']."' $qry_filter$qry_doj ORDER by id asc) $qry_date1$qry_date and (smoking='1' or alcohol='1' or tobacco='1') GROUP BY patient_id ORDER BY patient_id asc";
$count_query="select count(*) as total FROM patient_master where status = 'Active' and dept_id = '".$dept_row['dept_id']."' $qry_filter";
$count_result=mysqli_query($conn,$count_query);
error_log("count_query::".$count_query);
if(mysqli_num_rows($count_result)>0){
$row_count=mysqli_fetch_assoc($count_result);
$record[$i]['key']=$dept_row['dept_name'];
$record[$i]['total']=$row_count['total'];
}
$count_bmi="select max(medical_exam_id),patient_id from medical_examination where patient_id in (SELECT id FROM `patient_master` where status='Active' and dept_id = '".$dept_row['dept_id']."' $qry_filter ORDER by id asc) $qry_date1$qry_date and (smoking='1' or alcohol='1' or tobacco='1') GROUP BY patient_id ORDER BY patient_id asc";