='".$start_date."' "; $qry_date.=" and medical_entry_date >=str_to_date('".$start_date."','%d-%m-%Y') "; } if(isset($end_date) && $end_date!=''){ //$qry_date.=" and checkup_date <='".$end_date."' "; $qry_date.=" and medical_entry_date <=str_to_date('".$end_date."','%d-%m-%Y') "; } $i=0; $record =array(); /* starting from 18 to 25 */ $query1="select id FROM patient_master where YEAR(CURDATE())-year(dob)>=18 and YEAR(CURDATE())-year(dob)<=25 ".$qry_bu; $query="SELECT count(DISTINCT(patient_id)) as total from medical_examination where (air_cond_left is not null AND air_cond_left!='') AND (air_cond_right is not null AND air_cond_right!='') AND (bone_cond_left is not null AND bone_cond_left!='') AND (bone_cond_right is not null AND bone_cond_right!='') AND patient_id in ($query1) $qry_date"; //echo $query; if (!$result = @mysqli_query($conn,$query)) { exit(mysqli_error($conn)); } if(mysqli_num_rows($result) > 0) { if ($row = mysqli_fetch_assoc($result)) { $record[$i]['key'] ='18-25'; $record[$i]['total'] =$row['total']; } } $query="SELECT count(DISTINCT(patient_id)) as total from medical_examination where (air_cond_left='abnormal' or air_cond_right='abnormal' or bone_cond_left='abnormal' or bone_cond_right='abnormal' ) and patient_id in ($query1) $qry_date"; if (!$result = @mysqli_query($conn,$query)) { exit(mysqli_error($conn)); } if(mysqli_num_rows($result) > 0) { if ($row = mysqli_fetch_assoc($result)) { $record[$i]['is_abnormal_audiometry']=$row['total']; $i++; } } /* ending from 18 to 25 */ /* starting from 26 to 30 */ $query1="select id FROM patient_master where YEAR(CURDATE())-year(dob)>=26 and YEAR(CURDATE())-year(dob)<=30 ".$qry_bu; $query="SELECT count(DISTINCT(patient_id)) as total from medical_examination where (air_cond_left is not null AND air_cond_left!='') AND (air_cond_right is not null AND air_cond_right!='') AND (bone_cond_left is not null AND bone_cond_left!='') AND (bone_cond_right is not null AND bone_cond_right!='') AND patient_id in ($query1) $qry_date"; if (!$result = @mysqli_query($conn,$query)) { exit(mysqli_error($conn)); } if(mysqli_num_rows($result) > 0) { if ($row = mysqli_fetch_assoc($result)) { $record[$i]['key'] ='26-30'; $record[$i]['total'] =$row['total']; } } //echo $query; $query="SELECT count(DISTINCT(patient_id)) as total from medical_examination where (air_cond_left='abnormal' or air_cond_right='abnormal' or bone_cond_left='abnormal' or bone_cond_right='abnormal' ) and patient_id in ($query1) $qry_date"; //echo $query; if (!$result = @mysqli_query($conn,$query)) { exit(mysqli_error($conn)); } if(mysqli_num_rows($result) > 0) { if ($row = mysqli_fetch_assoc($result)) { $record[$i]['is_abnormal_audiometry']=$row['total']; $i++; } } /* ending from 26 to 30 */ /* starting from 31 to 40 */ $query1="select id FROM patient_master where YEAR(CURDATE())-year(dob)>=31 and YEAR(CURDATE())-year(dob)<=40 ".$qry_bu; $query="SELECT count(DISTINCT(patient_id)) as total from medical_examination where (air_cond_left is not null AND air_cond_left!='') AND (air_cond_right is not null AND air_cond_right!='') AND (bone_cond_left is not null AND bone_cond_left!='') AND (bone_cond_right is not null AND bone_cond_right!='') AND patient_id in ($query1) $qry_date" ; // echo $query; if (!$result = @mysqli_query($conn,$query)) { exit(mysqli_error($conn)); } if(mysqli_num_rows($result) > 0) { if ($row = mysqli_fetch_assoc($result)) { $record[$i]['key'] ='31-40'; $record[$i]['total'] =$row['total']; } } //echo $query; $query="SELECT count(DISTINCT(patient_id)) as total from medical_examination where (air_cond_left='abnormal' or air_cond_right='abnormal' or bone_cond_left='abnormal' or bone_cond_right='abnormal' ) and patient_id in ($query1) $qry_date"; //echo $query; if (!$result = @mysqli_query($conn,$query)) { exit(mysqli_error($conn)); } if(mysqli_num_rows($result) > 0) { if ($row = mysqli_fetch_assoc($result)) { $record[$i]['is_abnormal_audiometry']=$row['total']; $i++; } } $query1="select id FROM patient_master where YEAR(CURDATE())-year(dob)>=41 and YEAR(CURDATE())-year(dob)<=50 ".$qry_bu; $query="SELECT count(DISTINCT(patient_id)) as total from medical_examination where (air_cond_left is not null AND air_cond_left!='') AND (air_cond_right is not null AND air_cond_right!='') AND (bone_cond_left is not null AND bone_cond_left!='') AND (bone_cond_right is not null AND bone_cond_right!='') AND patient_id in ($query1) $qry_date"; if (!$result = @mysqli_query($conn,$query)) { exit(mysqli_error($conn)); } if(mysqli_num_rows($result) > 0) { if ($row = mysqli_fetch_assoc($result)) { $record[$i]['key'] ='41-50'; $record[$i]['total'] =$row['total']; } } $query="SELECT count(DISTINCT(patient_id)) as total from medical_examination where (air_cond_left='abnormal' or air_cond_right='abnormal' or bone_cond_left='abnormal' or bone_cond_right='abnormal' ) and patient_id in ($query1) $qry_date"; //echo $query; if (!$result = @mysqli_query($conn,$query)) { exit(mysqli_error($conn)); } if(mysqli_num_rows($result) > 0) { if ($row = mysqli_fetch_assoc($result)) { $record[$i]['is_abnormal_audiometry']=$row['total']; $i++; } } $query1="select id FROM patient_master where YEAR(CURDATE())-year(dob)>50 ".$qry_bu; $query="SELECT count(DISTINCT(patient_id)) as total from medical_examination where (air_cond_left is not null AND air_cond_left!='') AND (air_cond_right is not null AND air_cond_right!='') AND (bone_cond_left is not null AND bone_cond_left!='') AND (bone_cond_right is not null AND bone_cond_right!='') AND patient_id in ($query1) $qry_date"; if (!$result = @mysqli_query($conn,$query)) { exit(mysqli_error($conn)); } if(mysqli_num_rows($result) > 0) { if ($row = mysqli_fetch_assoc($result)) { $record[$i]['key'] ='>50'; $record[$i]['total'] =$row['total']; } } $query="SELECT count(DISTINCT(patient_id)) as total from medical_examination where (air_cond_left='abnormal' or air_cond_right='abnormal' or bone_cond_left='abnormal' or bone_cond_right='abnormal' ) and patient_id in ($query1) $qry_date"; //echo $query; if (!$result = @mysqli_query($conn,$query)) { exit(mysqli_error($conn)); } if(mysqli_num_rows($result) > 0) { if ($row = mysqli_fetch_assoc($result)) { $record[$i]['is_abnormal_audiometry']=$row['total']; $i++; } } echo json_encode($record); ?>