ESH/get_categorywise_abnormality_detailed_data.php
2024-10-23 18:28:06 +05:30

263 lines
11 KiB
PHP

<?php
include('includes/config/config.php');
include('includes/functions.php');
include('log_entry.php');
error_reporting(E_ERROR | E_PARSE);
error_log("inside abnormality category wise distribution");
// $year = implode(',', $_REQUEST['year']);
$year2 = $_REQUEST['year'];
// $year1 = explode(',', $year);
$qry_filter = "";
$query_date = "";
$start_date = $_REQUEST['startDate'];
$end_date = $_REQUEST['endDate'];
$ohc_id = $_REQUEST['ohc'];
error_log("ohc id " . $ohc_id);
if (isset($ohc_id) && $ohc_id != '') {
$qry_filter .= " and ohc_type_id = '" . $ohc_id . "' ";
}
if (isset($start_date) && $start_date != '') {
$qry_date .= " and date(checkup_date) >=str_to_date('" . $start_date . "','%d-%m-%Y') ";
}
if (isset($end_date) && $end_date != '') {
$qry_date .= " and date(checkup_date) <=str_to_date('" . $end_date . "','%d-%m-%Y') ";
}
$abnormality_id = $_POST['abnormality_type'];
$abnormality_name = getFieldFromTable('abnormality_name', 'abnormality', 'abnormality_id', $abnormality_id);
if (isset($year2) && $year2 != '') {
$qry_filter .= " and year(checkup_date) ='" . $year2 . "'";
}
// selecting different age groups
$query_age_part = "";
$data_age = [];
$data_gender = [];
$data_pat_cat = [];
$data_collar = [];
$data_agewise_total = [];
$data_pat_cat_total = [];
$data_gender_total = [];
$query_age = "select * from rule_age_range";
if (!$result_age = mysqli_query($conn, $query_age)) {
error_log("error in age range query " . $query_age . " query " . $query_age);
} else {
while ($row_age = mysqli_fetch_assoc($result_age)) {
$start_age = $row_age['rule_age_start'];
$end_age = $row_age['rule_age_end'];
if ($end_age == 0) {
$start_age = $row_age['rule_age_start'];
$query_age_part = "year(CURDATE())-year(dob)>='" . $start_age . "'";
} else {
$query_age_part = "year(CURDATE())-year(dob)>='" . $start_age . "' and year(CURDATE())-year(dob)<'" . $end_age . "'";
}
$query = "select max(checkup_id) from checkup_form where emp_id in (select id from patient_master where status='Active' and $query_age_part order by id asc) $qry_filter $qry_date and (abnormality_ids ='" . $abnormality_id . "' or abnormality_ids like '%," . $abnormality_id . "' or abnormality_ids like '" . $abnormality_id . ",%' or abnormality_ids like '%," . $abnormality_id . ",%') group by emp_id order by emp_id ";
error_log("query for abnormality count " . $query);
if (!$result = mysqli_query($conn, $query)) {
error_log("error " . mysqli_error($conn) . " query " . $query);
} else {
$count = mysqli_num_rows($result);
if ($count > 0) {
$data_age[$abnormality_id][$start_age] = $count;
} else {
$data_age[$abnormality_id][$start_age] = 0;
}
}
}
}
// for gender distribution
$query1 = "select max(checkup_id) from checkup_form where emp_id in (select id from patient_master where status='Active' and gender='M' order by id asc) $qry_filter $qry_date and (abnormality_ids ='" . $abnormality_id . "' or abnormality_ids like '%," . $abnormality_id . "' or abnormality_ids like '" . $abnormality_id . ",%' or abnormality_ids like '%," . $abnormality_id . ",%') group by emp_id order by emp_id ";
if (!$result1 = mysqli_query($conn, $query1)) {
error_log("error in query for male count " . mysqli_error($conn));
}
$count = mysqli_num_rows($result1);
if ($count > 0) {
$data_gender[$abnormality_id]['male'] = $count;
} else {
$data_gender[$abnormality_id]['male'] = 0;
}
error_log("query for male count " . $query1);
$query2 = "select max(checkup_id) from checkup_form where emp_id in (select id from patient_master where status='Active' and gender='F' order by id asc) $qry_filter $qry_date and (abnormality_ids ='" . $abnormality_id . "' or abnormality_ids like '%," . $abnormality_id . "' or abnormality_ids like '" . $abnormality_id . ",%' or abnormality_ids like '%," . $abnormality_id . ",%') group by emp_id order by emp_id ";
if (!$result2 = mysqli_query($conn, $query2)) {
error_log("error in female count query " . mysqli_error($conn));
}
$count = mysqli_num_rows($result2);
if ($count > 0) {
$data_gender[$abnormality_id]['female'] = $count;
} else {
$data_gender[$abnormality_id]['female'] = 0;
}
error_log("query for female count " . $query2);
// for patient category distribution
$query_cat = "select * from patient_category";
$result_cat = mysqli_query($conn, $query_cat);
while ($row_cat = mysqli_fetch_assoc($result_cat)) {
$pat_cat = $row_cat['patient_cat_id'];
$query3 = "select max(checkup_id) from checkup_form where emp_id in (select id from patient_master where status='Active' and patient_cat_id = '" . $pat_cat . "' order by id asc) $qry_filter $qry_date and (abnormality_ids ='" . $abnormality_id . "' or abnormality_ids like '%," . $abnormality_id . "' or abnormality_ids like '" . $abnormality_id . ",%' or abnormality_ids like '%," . $abnormality_id . ",%') group by emp_id order by emp_id ";
if (!$result3 = mysqli_query($conn, $query3)) {
error_log("error in cat wise query " . $query3);
}
error_log("query " . $query3);
$count = mysqli_num_rows($result3);
if ($count > 0) {
$data_pat_cat[$abnormality_id][$pat_cat] = $count;
} else {
$data_pat_cat[$abnormality_id][$pat_cat] = 0;
}
}
// for designation collar distribution for WC
$query4 = "select max(checkup_id) from checkup_form where emp_id in (select id from patient_master where status='Active' and designation_id in (select designation_id from designation where designation_collar='WC') order by id asc) $qry_filter $qry_date and (abnormality_ids ='" . $abnormality_id . "' or abnormality_ids like '%," . $abnormality_id . "' or abnormality_ids like '" . $abnormality_id . ",%' or abnormality_ids like '%," . $abnormality_id . ",%') group by emp_id order by emp_id ";
if (!$result4 = mysqli_query($conn, $query4)) {
error_log("error in query 4 " . mysqli_error($conn) . " query " . $query4);
}
$count = mysqli_num_rows($result4);
if ($count > 0) {
$data_collar[$abnormality_id]["WC"] = $count;
} else {
$data_collar[$abnormality_id]["WC"] = 0;
}
// for designation collar distribution for BC
$query5 = "select max(checkup_id) from checkup_form where emp_id in (select id from patient_master where status='Active' and designation_id in (select designation_id from designation where designation_collar='BC' ) order by id asc) $qry_filter $qry_date and (abnormality_ids ='" . $abnormality_id . "' or abnormality_ids like '%," . $abnormality_id . "' or abnormality_ids like '" . $abnormality_id . ",%' or abnormality_ids like '%," . $abnormality_id . ",%') group by emp_id order by emp_id ";
if (!$result5 = mysqli_query($conn, $query5)) {
error_log("error in query 5 " . mysqli_error($conn) . " query " . $query5);
}
$count = mysqli_num_rows($result5);
if ($count > 0) {
$data_collar[$abnormality_id]["BC"] = $count;
} else {
$data_collar[$abnormality_id]["BC"] = 0;
}
$data_abnormality = array($abnormality_name, $abnormality_id);
$query_age = "select * from rule_age_range";
if (!$result_age = mysqli_query($conn, $query_age)) {
error_log("error in age range query " . $query_age . " query " . $query_age);
} else {
while ($row_age = mysqli_fetch_assoc($result_age)) {
$start_age = $row_age['rule_age_start'];
$end_age = $row_age['rule_age_end'];
if ($end_age == 0) {
$start_age = $row_age['rule_age_start'];
$query_age_part = "year(CURDATE())-year(dob)>='" . $start_age . "'";
} else {
$query_age_part = "year(CURDATE())-year(dob)>='" . $start_age . "' and year(CURDATE())-year(dob)<'" . $end_age . "'";
}
$query1 = "select max(checkup_id) from checkup_form where emp_id in (select id from patient_master where status='Active' and $query_age_part order by id asc) $qry_filter $qry_date group by emp_id order by emp_id ";
if (!$result1 = mysqli_query($conn, $query1)) {
error_log("error in query for total count " . $start_age . " " . mysqli_error($conn));
}
$count = mysqli_num_rows($result1);
if ($count > 0) {
$data_agewise_total[$start_age] = $count;
} else {
$data_agewise_total[$start_age] = 0;
}
error_log("query for total count agewise " . $start_age . " " . $query1);
}
}
// for patient category distribution
$query_cat_1 = "select * from patient_category";
$result_cat_1 = mysqli_query($conn, $query_cat_1);
while ($row_cat_1 = mysqli_fetch_assoc($result_cat_1)) {
$pat_cat_1 = $row_cat_1['patient_cat_id'];
$query_3 = "select max(checkup_id) from checkup_form where emp_id in (select id from patient_master where status='Active' and patient_cat_id = '" . $pat_cat_1 . "' order by id asc) $qry_filter $qry_date group by emp_id order by emp_id ";
if (!$result_3 = mysqli_query($conn, $query_3)) {
error_log("error in cat wise total query " . $query_3);
}
error_log("query to get each pat cat count " . $query_3);
$count = mysqli_num_rows($result_3);
if ($count > 0) {
$data_pat_cat_total[$pat_cat_1] = $count;
} else {
$data_pat_cat_total[$pat_cat_1] = 0;
}
}
$query_gender_male = "select max(checkup_id) from checkup_form where emp_id in (select id from patient_master where status='Active' and gender='M' order by id asc) $qry_filter $qry_date group by emp_id order by emp_id ";
if (!$result_gender_male = mysqli_query($conn, $query_gender_male)) {
error_log("error in query for male count " . mysqli_error($conn));
}
error_log("query to get total male count " . $query_gender_male);
$count = mysqli_num_rows($result_gender_male);
if ($count > 0) {
$data_gender_total["male"] = $count;
} else {
$data_gender_total["male"] = 0;
}
$query_gender_female = "select max(checkup_id) from checkup_form where emp_id in (select id from patient_master where status='Active' and gender='F' order by id asc) $qry_filter $qry_date group by emp_id order by emp_id ";
if (!$result_gender_female = mysqli_query($conn, $query_gender_female)) {
error_log("error in query for male count " . mysqli_error($conn));
}
error_log("query to get total female count " . $query_gender_female);
$count = mysqli_num_rows($result_gender_female);
if ($count > 0) {
$data_gender_total["female"] = $count;
} else {
$data_gender_total["female"] = 0;
}
$data = array(
'abnormality' => $data_abnormality,
'age' => $data_age,
'gender' => $data_gender,
'patient_category' => $data_pat_cat,
'collar' => $data_collar,
'agewise_total' => $data_agewise_total,
'pat_cat_total' => $data_pat_cat_total,
'gender_total' => $data_gender_total
);
error_log("data " . print_r($data, true));
echo json_encode($data);