ESH/illnesswise_patient_report.php

173 lines
5.6 KiB
PHP
Raw Normal View History

2024-10-23 18:28:06 +05:30
<?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'];
$illness = $_REQUEST['illness'];
$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,2018);
error_log("values::" . $ohc_location . " " . $patient_category . " " . $dept . " " . $emp_designation . " " . $emp_cadre . " " . $employer_contractor . " " . $gender . " " . $illness . " " . $start_date . " " . $end_date . " " . $year . " " . $month);
$qry_filter1 = "";
$qry_filter = "";
$qry_date = "";
$qry_date1 = "";
if (isset($illness) && $illness != '') {
$qry_filter1 .= " where param_id ='" . $illness . "'";
}
if (isset($dept) && $dept != '') {
$qry_filter .= " where 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(checkup_date) >=str_to_date('" . $start_date . "','%d-%m-%Y') ";
}
if (isset($end_date) && $end_date != '') {
$qry_date1 .= " and date(checkup_date) <=str_to_date('" . $end_date . "','%d-%m-%Y') ";
}
if (isset($month) && $month != '') {
$qry_date1 .= " and month(checkup_date) in (" . $month . ")";
}
$i = 0;
$record = array();
if (isset($year) && $year != '' && sizeof($year1) > 1) {
$param_query = "select param_id, param_name from history_parameter $qry_filter1";
$result_param = mysqli_query($conn, $param_query);
$query = "SELECT count(*) as total FROM patient_master where status='Active' $qry_filter ";
if (!$result = @mysqli_query($conn, $query)) {
exit(mysqli_error($conn));
}
if (mysqli_num_rows($result) > 0) {
if ($row = mysqli_fetch_assoc($result)) {
$total_count = $row['total'];
}
}
$total = 0;
while ($param_row = mysqli_fetch_assoc($result_param)) {
$param_id = $param_row['param_id'];
for ($j = 0; $j < sizeof($year1); $j++) {
$percentage_emp_per_illness = 0;
$total = 0;
$qry_date = "";
$qry_date .= " and year(checkup_date) ='" . $year1[$j] . "'";
$count_illness = "select max(checkup_id) from checkup_form where emp_id in (SELECT id FROM `patient_master` where status='Active' $qry_filter ORDER by id asc) $qry_date1 $qry_date and past_present_illness like '%$param_id, %' or '%$param_id$' GROUP BY emp_id ORDER BY emp_id asc";
$illness_result = mysqli_query($conn, $count_illness);
if (mysqli_num_rows($illness_result) > 0) {
$total = mysqli_num_rows($illness_result);
} else {
$total = 0;
}
error_log("query:" . $count_illness);
error_log("ftotal:" . $total . "Year:" . $year1[$j] . "param_id:" . $param_id);
$percentage_emp_per_illness = ($total / $total_count) * 100;
$record[$param_row['param_name']][$year1[$j]]['illness'] = round($percentage_emp_per_illness, 2);
}
}
} else {
if (isset($year2) && $year2 != '') {
$qry_date .= " and year(checkup_date) ='" . $year2 . "'";
}
$param_query = "select param_id,param_name from history_parameter $qry_filter1";
$result_param = mysqli_query($conn, $param_query);
$total_hbd_pat = 0;
while ($param_row = mysqli_fetch_assoc($result_param)) {
$param_id = $param_row['param_id'];
$param_name = $param_row['param_name'];
$count_illness = "select max(checkup_id) from checkup_form where emp_id in (SELECT id FROM `patient_master` where status='Active' $qry_filter ORDER by id asc) and past_present_illness like '%$param_id,%' or '%$param_id$' $qry_date1 $qry_date GROUP BY emp_id ORDER BY emp_id asc";
$illness_result = mysqli_query($conn, $count_illness);
error_log("count_illness::" . $count_illness);
if (mysqli_num_rows($illness_result) > 0) {
$total_hbd_pat = mysqli_num_rows($illness_result);
} else {
$total_hbd_pat = 0;
}
$record[$i]['key'] = $param_name;
$record[$i]['total'] = $total_hbd_pat;
$query = "SELECT count(*) as total FROM patient_master where status='Active' $qry_filter ";
if (!$result = @mysqli_query($conn, $query)) {
exit(mysqli_error($conn));
}
if (mysqli_num_rows($result) > 0) {
if ($row = mysqli_fetch_assoc($result)) {
$record[$i]['total_count'] = $row['total'];
}
}
$i++;
}
}
echo json_encode($record);