340 lines
14 KiB
PHP
340 lines
14 KiB
PHP
<?php
|
|
include('includes/config/config.php');
|
|
include('includes/functions.php');
|
|
include('log_entry.php');
|
|
error_reporting(E_ERROR | E_PARSE);
|
|
|
|
$ohc_type = $_REQUEST['ohc_location'];
|
|
$patient_category = $_REQUEST['patient_category'];
|
|
$dept = $_REQUEST['dept'];
|
|
$emp_designation = $_REQUEST['emp_designation'];
|
|
$emp_cadre = $_REQUEST['emp_cadre'];
|
|
$employer_contractor = $_REQUEST['employer_contractor'];
|
|
$gender = $_REQUEST['gender'];
|
|
$start_date = $_REQUEST['startDate'];
|
|
$end_date = $_REQUEST['endDate'];
|
|
$year = implode(',', $_REQUEST['year']);
|
|
$month = implode(',', $_REQUEST['month']);
|
|
|
|
$year2 = implode(',', $_REQUEST['year']);
|
|
|
|
$year1 = explode(',', $year);
|
|
// $year1 = array(2020,2021);
|
|
|
|
|
|
error_log("values::" . $ohc_location . " " . $patient_category . " " . $dept . " " . $emp_designation . " " . $emp_cadre . " " . $employer_contractor . " " . $gender . " " . $start_date . " " . $end_date . " " . $year . " " . $month);
|
|
|
|
|
|
|
|
$qry_filter = "";
|
|
|
|
if (isset($dept) && $dept != '') {
|
|
$qry_filter .= " and dept_id ='" . $dept . "' ";
|
|
}
|
|
|
|
|
|
if (isset($ohc_type) && $ohc_type != '') {
|
|
$qry_filter .= " and ohc_type_id ='" . $ohc_type . "' ";
|
|
}
|
|
|
|
if (isset($gender) && $gender != '') {
|
|
$qry_filter .= " and gender ='" . $gender . "' ";
|
|
}
|
|
|
|
if (isset($patient_category) && $patient_category != '') {
|
|
$qry_filter .= " and emp_cat_id ='" . $patient_category . "' ";
|
|
}
|
|
|
|
if (isset($emp_designation) && $emp_designation != '') {
|
|
$qry_filter .= " and designation_id ='" . $emp_designation . "' ";
|
|
}
|
|
|
|
if (isset($emp_cadre) && $emp_cadre != '') {
|
|
$qry_filter .= " and emp_cadre ='" . $emp_cadre . "' ";
|
|
}
|
|
|
|
if (isset($employer_contractor) && $employer_contractor != '') {
|
|
$qry_filter .= " and employer_contractor_id ='" . $employer_contractor . "' ";
|
|
}
|
|
|
|
if (isset($start_date) && $start_date != '') {
|
|
$qry_date1 .= " and date(medical_entry_date) >=str_to_date('" . $start_date . "','%d-%m-%Y') ";
|
|
}
|
|
if (isset($end_date) && $end_date != '') {
|
|
$qry_date1 .= " and date(medical_entry_date) <=str_to_date('" . $end_date . "','%d-%m-%Y') ";
|
|
}
|
|
|
|
if (isset($month) && $month != '') {
|
|
$qry_date1 .= " and month(medical_entry_date) in (" . $month . ")";
|
|
}
|
|
|
|
|
|
$data = array();
|
|
|
|
if (isset($year) && $year != '' && sizeof($year1) > 1) {
|
|
|
|
for ($j = 0; $j < sizeof($year1); $j++) {
|
|
|
|
error_log("year:" . $year1[$j] . " size:" . sizeof($year1));
|
|
$qry_date = "";
|
|
$qry_doj = "";
|
|
|
|
$qry_date .= "and year(medical_entry_date) ='" . $year1[$j] . "'";
|
|
$qry_doj .= "and year(doj) <= '" . $year1[$j] . "'";
|
|
|
|
$per_for_18_to_25 = 0;
|
|
$total_psychiatric_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 $qry_doj";
|
|
|
|
$pat_result = mysqli_query($conn, $pat_query);
|
|
$total = mysqli_num_rows($pat_result);
|
|
|
|
|
|
$count_psychiatric = "SELECT max(medical_exam_id),patient_id,psychiatric 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 psychiatric='1' GROUP by patient_id";
|
|
|
|
error_log("count psychiatric:" . $count_psychiatric);
|
|
$psychiatric_result = mysqli_query($conn, $count_psychiatric);
|
|
$total_psychiatric_pat = mysqli_num_rows($psychiatric_result);
|
|
|
|
if ($total == 0 || $total_psychiatric_pat == 0) {
|
|
$data['18-25'][$year1[$j]]['total'] = 0;
|
|
} else {
|
|
$per_for_18_to_25 = ($total_psychiatric_pat / $total) * 100;
|
|
$data['18-25'][$year1[$j]]['total'] = round($per_for_18_to_25, 2);
|
|
}
|
|
|
|
|
|
|
|
error_log("Query1::" . $count_psychiatric);
|
|
|
|
$per_for_26_to_30 = 0;
|
|
$total_psychiatric_pat = 0;
|
|
$total = 0;
|
|
$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_psychiatric = "SELECT max(medical_exam_id),patient_id,psychiatric 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 psychiatric='1' GROUP by patient_id";
|
|
|
|
error_log("count psychiatric:" . $count_psychiatric);
|
|
$psychiatric_result = mysqli_query($conn, $count_psychiatric);
|
|
$total_psychiatric_pat = mysqli_num_rows($psychiatric_result);
|
|
|
|
if ($total == 0 || $total_psychiatric_pat == 0) {
|
|
$data['25-30'][$year1[$j]]['total'] = 0;
|
|
} else {
|
|
$per_for_26_to_30 = ($total_psychiatric_pat / $total) * 100;
|
|
$data['25-30'][$year1[$j]]['total'] = round($per_for_26_to_30, 2);
|
|
}
|
|
|
|
|
|
error_log("Query2::" . $count_psychiatric);
|
|
|
|
$per_for_31_to_40 = 0;
|
|
$total_psychiatric_pat = 0;
|
|
$total = 0;
|
|
$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_psychiatric = "SELECT max(medical_exam_id),patient_id,psychiatric 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 psychiatric='1' GROUP by patient_id";
|
|
|
|
error_log("count psychiatric:" . $count_psychiatric);
|
|
$psychiatric_result = mysqli_query($conn, $count_psychiatric);
|
|
$total_psychiatric_pat = mysqli_num_rows($psychiatric_result);
|
|
|
|
if ($total == 0 || $total_psychiatric_pat == 0) {
|
|
$data['30-40'][$year1[$j]]['total'] = 0;
|
|
} else {
|
|
$per_for_31_to_40 = ($total_psychiatric_pat / $total) * 100;
|
|
$data['30-40'][$year1[$j]]['total'] = round($per_for_31_to_40, 2);
|
|
}
|
|
|
|
error_log("Query3::" . $count_psychiatric);
|
|
|
|
$per_for_41_to_50 = 0;
|
|
$total_psychiatric_pat = 0;
|
|
$total = 0;
|
|
$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_psychiatric = "SELECT max(medical_exam_id),patient_id,psychiatric 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 psychiatric='1' GROUP by patient_id";
|
|
|
|
error_log("count psychiatric:" . $count_psychiatric);
|
|
$psychiatric_result = mysqli_query($conn, $count_psychiatric);
|
|
$total_psychiatric_pat = mysqli_num_rows($psychiatric_result);
|
|
|
|
if ($total == 0 || $total_psychiatric_pat == 0) {
|
|
$data['40-50'][$year1[$j]]['total'] = 0;
|
|
} else {
|
|
$per_for_41_to_50 = ($total_psychiatric_pat / $total) * 100;
|
|
$data['40-50'][$year1[$j]]['total'] = round($per_for_41_to_50, 2);
|
|
}
|
|
error_log("Query4::" . $count_psychiatric);
|
|
|
|
$per_greater_than_50 = 0;
|
|
$total_psychiatric_pat = 0;
|
|
$total = 0;
|
|
$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_psychiatric = "SELECT max(medical_exam_id),patient_id,psychiatric 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 psychiatric='1' GROUP by patient_id";
|
|
|
|
error_log("count psychiatric:" . $count_psychiatric);
|
|
$psychiatric_result = mysqli_query($conn, $count_psychiatric);
|
|
$total_psychiatric_pat = mysqli_num_rows($psychiatric_result);
|
|
|
|
if ($total == 0 || $total_psychiatric_pat == 0) {
|
|
$data['>=50'][$year1[$j]]['total'] = 0;
|
|
} else {
|
|
$per_greater_than_50 = ($total_psychiatric_pat / $total) * 100;
|
|
$data['>=50'][$year1[$j]]['total'] = round($per_greater_than_50, 2);
|
|
}
|
|
error_log("Query5::" . $count_psychiatric);
|
|
}
|
|
} else {
|
|
if (isset($year2) && $year2 != '') {
|
|
$qry_date1 .= " and year(medical_entry_date) ='" . $year2 . "'";
|
|
$qry_filter .= " and year(doj) <= '" . $year2 . "'";
|
|
}
|
|
|
|
//for 18 to 25
|
|
|
|
$total_psychiatric_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);
|
|
|
|
$per_for_18_to_25 = 0;
|
|
$count_psychiatric = "SELECT max(medical_exam_id),patient_id,psychiatric 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 psychiatric='1' GROUP by patient_id";
|
|
|
|
error_log("count psychiatric:" . $count_psychiatric);
|
|
$psychiatric_result = mysqli_query($conn, $count_psychiatric);
|
|
$total_psychiatric_pat = mysqli_num_rows($psychiatric_result);
|
|
|
|
$data['age_18_25']['total'] = $total_psychiatric_pat;
|
|
$data['age_18_25']['gtotal'] = $total;
|
|
if ($total == 0 || $total_psychiatric_pat == 0) {
|
|
$data['age_18_25']['per'] = 0;
|
|
} else {
|
|
$per_for_18_to_25 = ($total_psychiatric_pat / $total) * 100;
|
|
$data['age_18_25']['per'] = round($per_for_18_to_25, 2);
|
|
}
|
|
|
|
|
|
//for 26 to 30
|
|
|
|
$total_psychiatric_pat = 0;
|
|
$total = 0;
|
|
$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);
|
|
|
|
$per_for_25_to_30 = 0;
|
|
$count_psychiatric = "SELECT max(medical_exam_id),patient_id,psychiatric 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 psychiatric='1' GROUP by patient_id";
|
|
|
|
error_log("count psychiatric:" . $count_psychiatric);
|
|
$psychiatric_result = mysqli_query($conn, $count_psychiatric);
|
|
$total_psychiatric_pat = mysqli_num_rows($psychiatric_result);
|
|
|
|
$data['age_25_30']['total'] = $total_psychiatric_pat;
|
|
$data['age_25_30']['gtotal'] = $total;
|
|
if ($total == 0 || $total_psychiatric_pat == 0) {
|
|
$data['age_25_30']['per'] = 0;
|
|
} else {
|
|
$per_for_25_to_30 = ($total_psychiatric_pat / $total) * 100;
|
|
$data['age_25_30']['per'] = round($per_for_25_to_30, 2);
|
|
}
|
|
|
|
//for 31 to 40
|
|
$total_psychiatric_pat = 0;
|
|
$total = 0;
|
|
$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);
|
|
|
|
$per_for_30_to_40 = 0;
|
|
$count_psychiatric = "SELECT max(medical_exam_id),patient_id,psychiatric 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 psychiatric='1' GROUP by patient_id";
|
|
|
|
error_log("count psychiatric:" . $count_psychiatric);
|
|
$psychiatric_result = mysqli_query($conn, $count_psychiatric);
|
|
$total_psychiatric_pat = mysqli_num_rows($psychiatric_result);
|
|
|
|
$data['age_30_40']['total'] = $total_psychiatric_pat;
|
|
$data['age_30_40']['gtotal'] = $total;
|
|
if ($total == 0 || $total_psychiatric_pat == 0) {
|
|
$data['age_30_40']['per'] = 0;
|
|
} else {
|
|
$per_for_30_to_40 = ($total_psychiatric_pat / $total) * 100;
|
|
$data['age_30_40']['per'] = round($per_for_30_to_40, 2);
|
|
}
|
|
|
|
//for 41 to 50
|
|
$total_psychiatric_pat = 0;
|
|
$total = 0;
|
|
$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);
|
|
|
|
$per_for_40_to_50 = 0;
|
|
$count_psychiatric = "SELECT max(medical_exam_id),patient_id,psychiatric 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 psychiatric='1' GROUP by patient_id";
|
|
|
|
error_log("count psychiatric:" . $count_psychiatric);
|
|
$psychiatric_result = mysqli_query($conn, $count_psychiatric);
|
|
$total_psychiatric_pat = mysqli_num_rows($psychiatric_result);
|
|
|
|
$data['age_40_50']['total'] = $total_psychiatric_pat;
|
|
$data['age_40_50']['gtotal'] = $total;
|
|
if ($total == 0 || $total_psychiatric_pat == 0) {
|
|
$data['age_40_50']['per'] = 0;
|
|
} else {
|
|
$per_for_40_to_50 = ($total_psychiatric_pat / $total) * 100;
|
|
$data['age_40_50']['per'] = round($per_for_40_to_50, 2);
|
|
}
|
|
|
|
//for >50
|
|
$total_psychiatric_pat = 0;
|
|
$total = 0;
|
|
$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);
|
|
|
|
$per_greater_than_equal_50 = 0;
|
|
$count_psychiatric = "SELECT max(medical_exam_id),patient_id,psychiatric 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 psychiatric='1' GROUP by patient_id";
|
|
|
|
error_log("count psychiatric:" . $count_psychiatric);
|
|
$psychiatric_result = mysqli_query($conn, $count_psychiatric);
|
|
$total_psychiatric_pat = mysqli_num_rows($psychiatric_result);
|
|
|
|
|
|
$data['age_more_equal_50']['total'] = $total_psychiatric_pat;
|
|
$data['age_more_equal_50']['gtotal'] = $total;
|
|
if ($total == 0 || $total_psychiatric_pat == 0) {
|
|
$data['age_more_equal_50']['per'] = 0;
|
|
} else {
|
|
$per_greater_than_equal_50 = ($total_psychiatric_pat / $total) * 100;
|
|
$data['age_more_equal_50']['per'] = round($per_greater_than_equal_50, 2);
|
|
}
|
|
}
|
|
echo json_encode($data);
|