230 lines
8.6 KiB
PHP
230 lines
8.6 KiB
PHP
<?php
|
|
include('includes/config/config.php');
|
|
include('includes/functions.php');
|
|
include('log_entry.php');
|
|
error_reporting(E_ERROR | E_PARSE);
|
|
|
|
|
|
$start_date = $_REQUEST['startDate'];
|
|
$end_date = $_REQUEST['endDate'];
|
|
|
|
|
|
|
|
error_log("values::" . $ohc_location . " " . $patient_category . " " . $bu . " " . $emp_designation . " " . $emp_cadre . " " . $employer_contractor . " " . $gender . " " . $start_date . " " . $end_date . " " . $year . " " . $month);
|
|
|
|
|
|
$qry_filter1 = "";
|
|
$qry_filter = "";
|
|
$qry_date = "";
|
|
$qry_date1 = "";
|
|
|
|
|
|
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_date2 .= " and date(checkup_date) >= str_to_date('" . $end_date . "','%d-%m-%Y') ";
|
|
}
|
|
|
|
$i = 0;
|
|
$j = 0;
|
|
$record = array();
|
|
$business_unit = array();
|
|
|
|
if (isset($year) && $year != '' && sizeof($year1) > 1) {
|
|
|
|
$bu_query = "select bu_id, bu_name from bussiness_unit $qry_filter1";
|
|
|
|
$result_bu = mysqli_query($conn, $bu_query);
|
|
|
|
$percentage_emp_per_bu = 0;
|
|
|
|
$total = 0;
|
|
|
|
while ($bu_row = mysqli_fetch_assoc($result_bu)) {
|
|
|
|
for ($j = 0; $j < sizeof($year1); $j++) {
|
|
$qry_date = "";
|
|
$qry_doj = "";
|
|
|
|
$qry_date .= " and year(checkup_date) ='" . $year1[$j] . "'";
|
|
$qry_doj .= " and year(doj) <= '" . $year1[$j] . "'";
|
|
|
|
$count_query = "select count(*) as total FROM patient_master where status = 'Active' and bu_id = '" . $bu_row['bu_id'] . "' $qry_filter $qry_doj";
|
|
|
|
$count_result = mysqli_query($conn, $count_query);
|
|
|
|
error_log("count_query::" . $count_query);
|
|
|
|
$row_count = mysqli_fetch_assoc($count_result);
|
|
|
|
$count_health_index = "SELECT max(checkup_id),health_index from checkup_form where emp_id in (SELECT id FROM patient_master where bu_id = '" . $bu_row['bu_id'] . "' and status='Active' $qry_filter $qry_doj ORDER by id asc) $qry_date1 $qry_date GROUP by emp_id";
|
|
|
|
$health_index_result = mysqli_query($conn, $count_health_index);
|
|
error_log("count_health_index::" . $count_health_index);
|
|
|
|
$k = 0;
|
|
$data = [];
|
|
if (mysqli_num_rows($health_index_result)) {
|
|
while ($row_health_index = mysqli_fetch_assoc($health_index_result)) {
|
|
$data[$k] = $row_health_index['health_index'];
|
|
$k++;
|
|
}
|
|
}
|
|
|
|
$avg = 0;
|
|
if (count($data)) {
|
|
$avg = round(array_sum($data) / count($data), 2);
|
|
}
|
|
error_log("avg:" . $avg);
|
|
|
|
$record[$bu_row['bu_name']][$year1[$j]]['health_index'] = $avg;
|
|
error_log("habit per:" . $record[$bu_row['bu_name']][$year1[$j]]['health_index']);
|
|
}
|
|
}
|
|
} else {
|
|
$bu_query = "select bu_id, bu_name from bussiness_unit";
|
|
|
|
$result_bu = mysqli_query($conn, $bu_query);
|
|
$total = 0;
|
|
while ($bu_row = mysqli_fetch_assoc($result_bu)) {
|
|
|
|
$count_query = "select count(*) as total FROM patient_master where status = 'Active' and bu_id = '" . $bu_row['bu_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);
|
|
$business_unit[$i]['key'] = $bu_row['bu_name'];
|
|
$business_unit[$i]['total'] = $row_count['total'];
|
|
}
|
|
|
|
$count_health_index = "SELECT max(checkup_id) from checkup_form where (health_index >=0 and health_index <= 4) and emp_id in (SELECT id FROM patient_master where bu_id = '" . $bu_row['bu_id'] . "' and status='Active' $qry_filter ORDER by id asc) $qry_date1 GROUP by emp_id";
|
|
|
|
$health_index_result = mysqli_query($conn, $count_health_index);
|
|
error_log("count_health_index::" . $count_health_index);
|
|
|
|
if (mysqli_num_rows($health_index_result)) {
|
|
$record['first'][$bu_row['bu_name']]['0-4'] = mysqli_num_rows($health_index_result);
|
|
} else {
|
|
$record['first'][$bu_row['bu_name']]['0-4'] = 0;
|
|
}
|
|
$i++;
|
|
}
|
|
|
|
|
|
// for >4 to 10
|
|
|
|
$bu_query = "select bu_id, bu_name from bussiness_unit";
|
|
|
|
$result_bu = mysqli_query($conn, $bu_query);
|
|
$total = 0;
|
|
while ($bu_row = mysqli_fetch_assoc($result_bu)) {
|
|
|
|
$count_health_index = "SELECT max(checkup_id) from checkup_form where (health_index > 4 and health_index <= 10) and emp_id in (SELECT id FROM patient_master where bu_id = '" . $bu_row['bu_id'] . "' and status='Active' $qry_filter ORDER by id asc) $qry_date1 GROUP by emp_id";
|
|
|
|
$health_index_result = mysqli_query($conn, $count_health_index);
|
|
error_log("count_health_index::" . $count_health_index);
|
|
|
|
if (mysqli_num_rows($health_index_result)) {
|
|
$record['first'][$bu_row['bu_name']]['>4-10'] = mysqli_num_rows($health_index_result);
|
|
} else {
|
|
$record['first'][$bu_row['bu_name']]['>4-10'] = 0;
|
|
}
|
|
}
|
|
|
|
// for >10
|
|
|
|
$bu_query = "select bu_id, bu_name from bussiness_unit";
|
|
|
|
$result_bu = mysqli_query($conn, $bu_query);
|
|
$total = 0;
|
|
while ($bu_row = mysqli_fetch_assoc($result_bu)) {
|
|
$count_health_index = "SELECT max(checkup_id) from checkup_form where health_index > 10 and emp_id in (SELECT id FROM patient_master where bu_id = '" . $bu_row['bu_id'] . "' and status='Active' $qry_filter ORDER by id asc) $qry_date1 GROUP by emp_id";
|
|
|
|
$health_index_result = mysqli_query($conn, $count_health_index);
|
|
error_log("count_health_index::" . $count_health_index);
|
|
|
|
if (mysqli_num_rows($health_index_result)) {
|
|
$record['first'][$bu_row['bu_name']]['>10'] = mysqli_num_rows($health_index_result);
|
|
} else {
|
|
$record['first'][$bu_row['bu_name']]['>10'] = 0;
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// for after data
|
|
|
|
$j = 0;
|
|
$bu_query = "select bu_id, bu_name from bussiness_unit";
|
|
|
|
$result_bu = mysqli_query($conn, $bu_query);
|
|
$total = 0;
|
|
while ($bu_row = mysqli_fetch_assoc($result_bu)) {
|
|
|
|
$count_health_index = "SELECT max(checkup_id) from checkup_form where (health_index >=0 and health_index <= 4) and emp_id in (SELECT id FROM patient_master where bu_id = '" . $bu_row['bu_id'] . "' and status='Active' $qry_filter ORDER by id asc) $qry_date2 GROUP by emp_id";
|
|
|
|
$health_index_result = mysqli_query($conn, $count_health_index);
|
|
error_log("count_health_index::" . $count_health_index);
|
|
|
|
if (mysqli_num_rows($health_index_result)) {
|
|
$record['second'][$bu_row['bu_name']]['0-4'] = mysqli_num_rows($health_index_result);
|
|
} else {
|
|
$record['second'][$bu_row['bu_name']]['0-4'] = 0;
|
|
}
|
|
}
|
|
|
|
|
|
// for >4 to 10
|
|
|
|
$bu_query = "select bu_id, bu_name from bussiness_unit";
|
|
|
|
$result_bu = mysqli_query($conn, $bu_query);
|
|
$total = 0;
|
|
while ($bu_row = mysqli_fetch_assoc($result_bu)) {
|
|
|
|
$count_health_index = "SELECT max(checkup_id) from checkup_form where (health_index > 4 and health_index <= 10) and emp_id in (SELECT id FROM patient_master where bu_id = '" . $bu_row['bu_id'] . "' and status='Active' $qry_filter ORDER by id asc) $qry_date2 GROUP by emp_id";
|
|
|
|
$health_index_result = mysqli_query($conn, $count_health_index);
|
|
error_log("count_health_index::" . $count_health_index);
|
|
|
|
if (mysqli_num_rows($health_index_result)) {
|
|
$record['second'][$bu_row['bu_name']]['>4-10'] = mysqli_num_rows($health_index_result);
|
|
} else {
|
|
$record['second'][$bu_row['bu_name']]['>4-10'] = 0;
|
|
}
|
|
}
|
|
|
|
// for >10
|
|
|
|
$bu_query = "select bu_id, bu_name from bussiness_unit";
|
|
|
|
$result_bu = mysqli_query($conn, $bu_query);
|
|
$total = 0;
|
|
while ($bu_row = mysqli_fetch_assoc($result_bu)) {
|
|
|
|
$count_health_index = "SELECT max(checkup_id) from checkup_form where health_index > 10 and emp_id in (SELECT id FROM patient_master where bu_id = '" . $bu_row['bu_id'] . "' and status='Active' $qry_filter ORDER by id asc) $qry_date2 GROUP by emp_id";
|
|
|
|
$health_index_result = mysqli_query($conn, $count_health_index);
|
|
error_log("count_health_index::" . $count_health_index);
|
|
|
|
if (mysqli_num_rows($health_index_result)) {
|
|
$record['second'][$bu_row['bu_name']]['>10'] = mysqli_num_rows($health_index_result);
|
|
} else {
|
|
$record['second'][$bu_row['bu_name']]['>10'] = 0;
|
|
}
|
|
|
|
}
|
|
}
|
|
|
|
// $data = array(
|
|
// 'bu_unit' => array($business_unit),
|
|
// 'health_index' => array($record),
|
|
// );
|
|
error_log("data after " . print_r($record, true));
|
|
echo json_encode($record);
|