$qry_date.=" and year(checkup_date) ='".$year1[$j]."'";
$qry_doj.=" and year(doj) <= '".$year1[$j]."'";
$count_query="select count(*) as total FROM patient_master where status = 'Active' and bu_id = '".$bu_row['bu_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_health_index="SELECT max(checkup_id),health_index from checkup_form where emp_id in (SELECT id FROM patient_master where bu_id = '".$bu_row['bu_id']."' and status='Active' $qry_filter$qry_doj ORDER by id asc) $qry_date1$qry_date GROUP by emp_id";
$bu_query="select bu_id, bu_name from bussiness_unit";
$result_bu=mysqli_query($conn,$bu_query);
$total=0;
while($bu_row=mysqli_fetch_assoc($result_bu)){
$count_query="select count(*) as total FROM patient_master where status = 'Active' and bu_id = '".$bu_row['bu_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);
$business_unit[$i]['key']=$bu_row['bu_name'];
$business_unit[$i]['total']=$row_count['total'];
}
$count_health_index="SELECT max(checkup_id) from checkup_form where (health_index >=0 and health_index <= 4) and emp_id in (SELECT id FROM patient_master where bu_id = '".$bu_row['bu_id']."' and status='Active' $qry_filter ORDER by id asc) $qry_date1 GROUP by emp_id";
$bu_query="select bu_id, bu_name from bussiness_unit";
$result_bu=mysqli_query($conn,$bu_query);
$total=0;
while($bu_row=mysqli_fetch_assoc($result_bu)){
$count_health_index="SELECT max(checkup_id) from checkup_form where (health_index > 4 and health_index <= 10) and emp_id in (SELECT id FROM patient_master where bu_id = '".$bu_row['bu_id']."' and status='Active' $qry_filter ORDER by id asc) $qry_date1 GROUP by emp_id";
$bu_query="select bu_id, bu_name from bussiness_unit";
$result_bu=mysqli_query($conn,$bu_query);
$total=0;
while($bu_row=mysqli_fetch_assoc($result_bu)){
$count_health_index="SELECT max(checkup_id) from checkup_form where health_index > 10 and emp_id in (SELECT id FROM patient_master where bu_id = '".$bu_row['bu_id']."' and status='Active' $qry_filter ORDER by id asc) $qry_date1 GROUP by emp_id";
$bu_query="select bu_id, bu_name from bussiness_unit";
$result_bu=mysqli_query($conn,$bu_query);
$total=0;
while($bu_row=mysqli_fetch_assoc($result_bu)){
$count_health_index="SELECT max(checkup_id) from checkup_form where (health_index >=0 and health_index <= 4) and emp_id in (SELECT id FROM patient_master where bu_id = '".$bu_row['bu_id']."' and status='Active' $qry_filter ORDER by id asc) $qry_date2 GROUP by emp_id";
$bu_query="select bu_id, bu_name from bussiness_unit";
$result_bu=mysqli_query($conn,$bu_query);
$total=0;
while($bu_row=mysqli_fetch_assoc($result_bu)){
$count_health_index="SELECT max(checkup_id) from checkup_form where (health_index > 4 and health_index <= 10) and emp_id in (SELECT id FROM patient_master where bu_id = '".$bu_row['bu_id']."' and status='Active' $qry_filter ORDER by id asc) $qry_date2 GROUP by emp_id";
$bu_query="select bu_id, bu_name from bussiness_unit";
$result_bu=mysqli_query($conn,$bu_query);
$total=0;
while($bu_row=mysqli_fetch_assoc($result_bu)){
$count_health_index="SELECT max(checkup_id) from checkup_form where health_index > 10 and emp_id in (SELECT id FROM patient_master where bu_id = '".$bu_row['bu_id']."' and status='Active' $qry_filter ORDER by id asc) $qry_date2 GROUP by emp_id";