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

247 lines
9.7 KiB
PHP

<?php
include('includes/config/config.php');
include('includes/functions.php');
include('log_entry.php');
error_log("Start Printing Request Attributes");
foreach ($_REQUEST as $key => $value) {
error_log($key . " : " . $value . "\n");
}
error_log("End Printing Request Attributes");
error_log("inside data age eval");
$arr = array();
$arr = array();
$chart_id = $_REQUEST['chart_id'];
$ohc_type_id = $_REQUEST['ohc_type_id'];
$yearwise = $_REQUEST['chart_type_id'];
error_log("yearwise " . $yearwise);
error_log("ohc_type_id " . $ohc_type_id);
error_log("chart_id " . $chart_id);
$sql0 = "select * from rule_chart where chart_id='" . $chart_id . "'";
error_log("sql0 " . $sql0);
$result0 = mysqli_query($conn, $sql0);
$row0 = mysqli_fetch_array($result0);
$checkup_section = $row0['checkup_section'];
error_log('checkup_section ' . $checkup_section);
if ($_REQUEST['rule_result'] == "") {
$sql11 = 'select distinct result_disp from rule_equation where rule_eq_id in (' . $row0['rule_equation_ids'] . ')';
error_log('sql11 ' . $sql11);
$result11 = mysqli_query($conn, $sql11);
$i = 0;
while ($row11 = mysqli_fetch_array($result11)) {
$arr['par'][$i] = $row11['result_disp'];
$arr['exposure'][$i] = 0;
$arr['newexposure'][$i] = 0;
$arr['exp'][$i] = 0;
$arr['genm'][$i] = 0;
$arr['genf'][$i] = 0;
$arr['total'][$i] = 0;
$i++;
}
$n = $i;
} else {
if ($_REQUEST['chart_type_id'] != "") {
//$sql12="select * from rule_years_range where rule_chart_id=".$chart_id."";
//$sql12="select * from rule_years_range where rule_chart_id in (".$chart_id.")";
$sql12 = "select * from rule_years_range where FIND_IN_SET('" . $chart_id . "',rule_chart_id)";
error_log('sql12' . $sql12);
$result12 = mysqli_query($conn, $sql12);
$i = 0;
while ($row12 = mysqli_fetch_array($result12)) {
$arr['yearsexprange'][$i][0] = $row12['rule_years_start'];
error_log("arr " . $arr['yearsexprange'][$i][0]);
$arr['yearsexprange'][$i][1] = $row12['rule_years_end'];
error_log("arr " . $arr['yearsexprange'][$i][1]);
$arr['genm'][$i] = 0;
$arr['genf'][$i] = 0;
$arr['total'][$i] = 0;
$i++;
}
$n = $i;
}
}
// if( $_REQUEST['duration']!=""){
// $j=0;
// error_log("checki ".$i);
// for($i=$first;$i<=$last;$i++){
// $arr['exp'][$j]=$i;
// $arr['genm'][$j]=0;
// $arr['genf'][$j]=0;
// $arr['total'][$j]=0;
// $j++;
// }
// $n=$answer;
// }
// $sql1='select TIMESTAMPDIFF(YEAR, doj, CURDATE()) AS difference from checkup_form a left join patient_master b on b.id=a.emp_id where difference >= "'.$first.'" AND difference <= "'.$last.'";';
$sql1 = 'SELECT a.* , b.* FROM (SELECT * FROM ( SELECT *, TIMESTAMPDIFF(YEAR, doj, CURDATE()) AS daysdiff FROM patient_master ) as innerTable )a LEFT JOIN checkup_form b on a.id=b.emp_id';
if (($_REQUEST['rule_start_date'] != "") && ($_REQUEST['rule_end_date'])) {
$sql1 .= ' and ((checkup_date <' . $_REQUEST['rule_end_date'] . ') and (checkup_date >' . $_REQUEST['rule_start_date'] . '))';
}
if ($_REQUEST['dept'] != "") {
$sql1 .= ' and dept_id=' . $_REQUEST['dept'] . '';
}
if ($_REQUEST['desig'] != "") {
$sql1 .= ' and designation_id=' . $_REQUEST['desig'] . '';
}
if ($_REQUEST['cli'] != "") {
$sql1 .= ' and client_id=' . $_REQUEST['cli'] . '';
}
error_log('sql1 ' . $sql1);
$result1 = mysqli_query($conn, $sql1);
$l = 0;
while ($row1 = mysqli_fetch_array($result1)) {
$checkup_section_ids = explode(",", $row1['checkup_section_ids']);
if (in_array($checkup_section, $checkup_section_ids)) {
$daysdiff = $row1['daysdiff'];
$gender = $row1['gender'];
$sql3 = 'select * from rule_equation where rule_eq_id in (' . $row0['rule_equation_ids'] . ')';
error_log('sql3 ' . $sql3);
if ($_REQUEST['rule_result'] != "") {
$sql3 .= "and result_disp='" . $_REQUEST['rule_result'] . "'";
}
error_log("sql3 " . $sql3);
$result3 = mysqli_query($conn, $sql3);
while ($row3 = mysqli_fetch_array($result3)) {
$flag = 0;
$equation = "";
$rule_eq_id = $row3['rule_eq_id'];
error_log("rule_eq_id " . $rule_eq_id);
error_log("daysdiff " . $daysdiff);
$xresult = $row3['result_disp'];
if (!(($row3['rule_gender'] == null) || ($row3['rule_gender'] == ""))) {
$a = 1;
if ($gender != $row3['rule_gender']) {
error_log("inside if gender");
continue;
}
}
// if (($row3['rule_age_start'] > $daysdiff) && ($row3['rule_age_end'] < $daysdiff)) {
// $b = 1;
// error_log("inside if daysdiff");
// continue;
// }
$sql4 = "select * from rule_save where equation_rule_id = '" . $row3['rule_eq_id'] . "'";
error_log("sql4 " . $sql4);
$result4 = mysqli_query($conn, $sql4);
while ($row4 = mysqli_fetch_array($result4)) {
$checkup_parameter = getTableFieldValue('checkup_parameter', 'column_name', 'checkup_parameter_id', $row4['checkup_parameter']);
error_log("checkup_parameter " . $checkup_parameter);
$condition = getTableFieldValue('rule_condition', 'condition_sy', 'rule_condition_id', $row4['condition_id']);
error_log("condition " . $condition);
$joiner = getTableFieldValue('rule_joiner', 'joiner_sy', 'rule_joiner_id', $row4['joiner_id']);
error_log("joiner " . $joiner);
//need change
// $abc=$_REQUEST[$checkup_parameter];
$sql5 = "select * from checkup_form_key_value where checkup_form_id = '" . $row1['checkup_id'] . "' and checkup_form_key = '" . $checkup_parameter . "'";
error_log("sql6 " . $sql5);
$result5 = mysqli_query($conn, $sql5);
$row5 = mysqli_fetch_array($result5);
$abc = $row5['checkup_form_value'];
error_log("value " . $abc);
if ($abc == "") {
$flag = 1;
break;
} else {
$equation = $equation . $joiner . $row4['op_br'] . $abc . $condition . $row4['rule_s_val'] . $row4['cl_br'];
// error_log("equation " . $equation);
}
}
if ($flag == 0) {
error_log("equation " . $equation);
error_log("arrtype " . gettype($equation));
eval('$resultr = (' . $equation . ');');
error_log("result " . $resultr);
if ($resultr == true || $resultr == 1) {
if ($_REQUEST['chart_type_id'] != "") {
for ($i = 0; $i < $n; $i++) {
if ((($arr['yearsexprange'][$i][0] <= $daysdiff) && ($arr['yearsexprange'][$i][1] >= $daysdiff))) {
error_log('age' . $age);
error_log("arr " . $arr['agerange'][$i][0]);
error_log("arr " . $arr['agerange'][$i][1]);
error_log("calculate results");
if ($gender == 'M') {
$arr['genm'][$i] += 1;
} else if ($gender == 'F') {
$arr['genf'][$i] += 1;
}
$arr['total'][$i] += 1;
}
}
}
}
}
}
}
}
// for($i=0;$i<=$n;$i++)
// {
// $counts = array_count_values($arr['exposure']);
// if(in_array($arr['exp'][$i], $arr['exposure'])){
// error_log('inside if exp');
// $arr['newexposure'][$i] = $arr['exp'][$i];
// error_log('taking care of counts ' .$counts[$arr['exp'][$i]]);
// for($p=0;$p<$counts[$arr['exp'][$i]];$p++)
// {
// if ($gender == 'M') {
// $arr['genm'][$i] += 1;
// } else if ($gender == 'F') {
// $arr['genf'][$i] += 1;
// }
// $arr['total'][$i] += 1;
// error_log('tot'.$arr['total'][$i]);
// }
// }
// }
$data = array();
if ($_REQUEST['chart_type_id'] != "") {
$sig = '-';
if ($_POST["rule_gender"] == "") {
for ($m = 0; $m < $n; $m++) {
$data[] = array(
'language' => $arr['yearsexprange'][$m][0] . $sig . $arr['yearsexprange'][$m][1],
'total' => $arr['total'][$m],
'color' => '#' . rand(100000, 999999) . ''
);
}
}
if ($_POST["rule_gender"] == "M") {
for ($m = 0; $m < $n; $m++) {
$data[] = array(
'language' => $arr['yearsexprange'][$m][0] . $sig . $arr['yearsexprange'][$m][1],
'total' => $arr['genm'][$m],
'color' => '#' . rand(100000, 999999) . ''
);
}
} else if ($_POST["rule_gender"] == "F") {
for ($m = 0; $m < $n; $m++) {
$data[] = array(
'language' => $arr['yearsexprange'][$m][0] . $sig . $arr['yearsexprange'][$m][1],
'total' => $arr['genf'][$m],
'color' => '#' . rand(100000, 999999) . ''
);
}
}
}
error_log("data-eval " . print_r($data, true));
echo json_encode($data);