=str_to_date('".$start_date."','%d-%m-%Y') "; } if(isset($end_date) && $end_date!=''){ $qry_filter.=" and date(medical_entry_date) <=str_to_date('".$end_date."','%d-%m-%Y') "; } if(isset($month) && $month!=''){ $qry_filter.=" and month(medical_entry_date) in (".$month.")"; } $i=0; $record = array(); $qry_date.=" and year(medical_entry_date) ='".$year2."'"; $dept_query = "select dept_id, dept_name from department $qry_filter1"; $result_dept = mysqli_query($conn,$dept_query); while($dept_row = mysqli_fetch_assoc($result_dept)){ $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']; } $id_query = "select id from patient_master where status='Active' and dept_id = '".$dept_row['dept_id']."' $qry_filter"; $id_result = mysqli_query($conn,$id_query); $total=0; while($row_id = mysqli_fetch_assoc($id_result)){ $count_bmi = "select patient_id from medical_examination where health_index<5 and medical_exam_id = (select max(medical_exam_id) from medical_examination where patient_id='".$row_id['id']."') $qry_date1 $qry_date"; $bmi_result = mysqli_query($conn,$count_bmi); error_log("count_bmi::".$count_bmi); if(mysqli_num_rows($bmi_result)>0){ $total+=1; } $count_bmi = "select patient_id from medical_examination where health_index>=6 and health_index<=12 and medical_exam_id = (select max(medical_exam_id) from medical_examination where patient_id='".$row_id['id']."') $qry_date1 $qry_date"; $bmi_result = mysqli_query($conn,$count_bmi); error_log("count_bmi::".$count_bmi); if(mysqli_num_rows($bmi_result)>0){ $total+=1; } $count_bmi = "select patient_id from medical_examination where health_index>=13 and health_index<=18 and medical_exam_id = (select max(medical_exam_id) from medical_examination where patient_id='".$row_id['id']."') $qry_date1 $qry_date"; $bmi_result = mysqli_query($conn,$count_bmi); error_log("count_bmi::".$count_bmi); if(mysqli_num_rows($bmi_result)>0){ $total+=1; } } $record[$i]['bmi_total']=$total; $i++; } // if(isset($year) && $year!='' && count($year1)>1){ // for($j=0; $j50'] query:".$query5); // $query="select count(*) as total_count from medical_examination $qry_date $qry_filter"; // if (!$result = @mysqli_query($conn,$query)) { // die(mysqli_error($conn)); // } // $row_count = mysqli_fetch_assoc($result); // error_log("count query:".$query); // if(mysqli_num_rows($result1) > 0) { // if ($row1 = mysqli_fetch_assoc($result1)) { // $per_for_less_than_5 = ($row1['total']/$row_count['total_count'])*100; // $data['<5'][$year1[$j]]['total'] = round($per_for_less_than_5,2); // } // } // if(mysqli_num_rows($result2) > 0) { // if ($row2 = mysqli_fetch_assoc($result2)) { // $per_for_6_to_12 = ($row2['total']/$row_count['total_count'])*100; // $data['6-12'][$year1[$j]]['total'] = round($per_for_6_to_12,2); // } // } // if(mysqli_num_rows($result3) > 0) { // if ($row3 = mysqli_fetch_assoc($result3)) { // $per_for_13_to_18 = ($row3['total']/$row_count['total_count'])*100; // $data['13-18'][$year1[$j]]['total'] = round($per_for_13_to_18,2); // } // } // // if(mysqli_num_rows($result4) > 0) { // // if ($row4 = mysqli_fetch_assoc($result4)) { // // $per_for_41_to_50 = ($row4['total']/$row_count['total_count'])*100; // // $data['41-50'][$year1[$j]]['total'] = round($per_for_41_to_50,2); // // } // // } // // if(mysqli_num_rows($result5) > 0) { // // if ($row5 = mysqli_fetch_assoc($result5)) { // // $per_greater_than_50 = ($row5['total']/$row_count['total_count'])*100; // // $data['>50'][$year1[$j]]['total'] = round($per_greater_than_50,2); // // } // // } // } // } // else{ // if(isset($year2) && $year2!=''){ // $qry_filter.=" and year(medical_entry_date) ='".$year2."'"; // } // $qry_date=""; // $qry_date.="and year(medical_entry_date) ='".$year2."'"; // $query="select count(*) as total,health_index from medical_examination where medical_exam_id = (select max(medical_exam_id)) $qry_filter $qry_date"; // //echo $query.$qry_bu; // if (!$result = @mysqli_query($conn,$query)) { // die(mysqli_error($conn)); // } // if(mysqli_num_rows($result) > 0) { // if ($row = mysqli_fetch_assoc($result)) { // $data['age_less5'] = $row; // } // } // error_log("['age_less5'] query:".$query); // $query="select count(*) as total,health_index from medical_examination where medical_exam_id = (select max(medical_exam_id)) $qry_filter $qry_date"; // if (!$result = @mysqli_query($conn,$query)) { // die(mysqli_error($conn)); // } // if(mysqli_num_rows($result) > 0) { // if ($row = mysqli_fetch_assoc($result)) { // $data['age_6_12'] = $row; // } // } // error_log("['age_6_12'] query:".$query); // $query="select count(*) as total,health_index from medical_examination where medical_exam_id = (select max(medical_exam_id)) $qry_filter $qry_date"; // if (!$result = @mysqli_query($conn,$query)) { // die(mysqli_error($conn)); // } // if(mysqli_num_rows($result) > 0) { // if ($row = mysqli_fetch_assoc($result)) { // $data['age_13_18'] = $row; // } // } // error_log("['age_13_18'] query:".$query); // // $query="select count(*) as total,health_index from medical_examination $qry_filter $qry_date"; // // if (!$result = @mysqli_query($conn,$query)) { // // die(mysqli_error($conn)); // // } // // if(mysqli_num_rows($result) > 0) { // // if ($row = mysqli_fetch_assoc($result)) { // // $data['age_41_50'] = $row; // // } // // } // // error_log("['age_41_50'] query:".$query); // // $query="SELECT count(id) as total,hbd FROM patient_master where YEAR(CURDATE())-year(dob)>50 and hbd='1' $qry_filter $qry_date"; // // if (!$result = @mysqli_query($conn,$query)) { // // die(mysqli_error($conn)); // // } // // if(mysqli_num_rows($result) > 0) { // // if ($row = mysqli_fetch_assoc($result)) { // // $data['age_more50'] = $row; // // } // // } // // error_log("['age_more50'] query:".$query); // $query="SELECT count(*) as total FROM medical_examination $qry_filter"; // if (!$result = @mysqli_query($conn,$query)) { // die(mysqli_error($conn)); // } // if(mysqli_num_rows($result) > 0) { // if ($row = mysqli_fetch_assoc($result)) { // $data['total_count'] = $row; // } // } // error_log("count query:".$query); echo json_encode($data); ?>