$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_spirometry_remarks="SELECT max(medical_exam_id),patient_id,spirometry_remarks 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 spirometry_remarks NOT LIKE 'WNL%' GROUP by patient_id";
$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_spirometry_remarks="SELECT max(medical_exam_id),patient_id,spirometry_remarks 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 spirometry_remarks NOT LIKE 'WNL%' GROUP by patient_id";
$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_spirometry_remarks="SELECT max(medical_exam_id),patient_id,spirometry_remarks 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 spirometry_remarks NOT LIKE 'WNL%' GROUP by patient_id";
$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_spirometry_remarks="SELECT max(medical_exam_id),patient_id,spirometry_remarks 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 spirometry_remarks NOT LIKE 'WNL%' GROUP by patient_id";
$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_spirometry_remarks="SELECT max(medical_exam_id),patient_id,spirometry_remarks 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 spirometry_remarks NOT LIKE 'WNL%' GROUP by patient_id";
$qry_date1.=" and year(medical_entry_date) ='".$year2."'";
$qry_filter.=" and year(doj) <= '".$year2."'";
}
//for 18 to 25
$total_spirometry_remarks_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_spirometry_remarks="SELECT max(medical_exam_id),patient_id,spirometry_remarks 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 spirometry_remarks GROUP by patient_id";
$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_spirometry_remarks="SELECT max(medical_exam_id),patient_id,spirometry_remarks 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 spirometry_remarks NOT LIKE 'WNL%' GROUP by patient_id";
$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_spirometry_remarks="SELECT max(medical_exam_id),patient_id,spirometry_remarks 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 spirometry_remarks NOT LIKE 'WNL%' GROUP by patient_id";
$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_spirometry_remarks="SELECT max(medical_exam_id),patient_id,spirometry_remarks 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 spirometry_remarks NOT LIKE 'WNL%' GROUP by patient_id";
$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_spirometry_remarks="SELECT max(medical_exam_id),patient_id,spirometry_remarks 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 spirometry_remarks NOT LIKE 'WNL%' GROUP by patient_id";