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

235 lines
11 KiB
PHP

<?php
include('includes/config/config.php');
include('includes/functions.php');
include('log_entry.php');
error_log("Start Printing Request Attributes");
$requestStr = "";
foreach ($_REQUEST as $key => $value) {
$requestStr .= $key . " : " . $value . "\n";
error_log($key . " : " . $value . "<br />\r\n");
}
error_log("End Printing Request Attributes");
$status_code = 200;
$checkup_ids = $_REQUEST['checkupIds'];
for ($num = 0; $num < sizeof($checkup_ids); $num++) {
$data = [];
// rule evaluation start
$emp_id = getFieldFromTable('emp_id', 'checkup_form', 'checkup_id', $checkup_ids[$num]);
// $pat_dob = getFieldFromTable('dob', 'patient_master', 'id', $emp_id);
// $from = new DateTime($pat_dob);
// $to = new DateTime('today');
// $age = $from->diff($to)->y;
// error_log("age " . $age);
// $today = date("Y-m-d");
// error_log("pat_dob " . $pat_dob);
// $age = ($today - $pat_dob);
// error_log("age " . $age);
// $pat_gender = getFieldFromTable('gender', 'patient_master', 'id', $emp_id);
// error_log("patient gender " . $pat_gender);
// $checkup_type_id = getFieldFromTable('checkup_type_id', 'checkup_form', 'checkup_id', $checkup_ids[$num]);
// $sql = "select * from checkup_type where checkup_type_id='" . $checkup_type_id . "'";
// $result = mysqli_query($conn, $sql);
// $row = mysqli_fetch_assoc($result);
// $section_id = $row['checkup_form_section_ids'];
// $section_id = explode(",", $section_id);
// error_log("type of var " . gettype($section_id) . " values " . print_r($section_id, true));
// for ($i = 0; $i < sizeof($section_id); $i++) {
// error_log("section id is" . $section_id[$i]);
// $sql_section = "select * from checkup_form_section where section_id ='" . $section_id[$i] . "' having rule_ids!= ''";
// error_log("query for section " . $sql_section);
// $result_section = mysqli_query($conn, $sql_section);
// while ($row_section = mysqli_fetch_assoc($result_section)) {
// $rule_eq = getCommaSeperatedValuesToInClause($row_section['rule_ids']);
// $rule_sql = "select * from rule_equation where rule_eq_id in $rule_eq";
// error_log("rule sql " . $rule_sql);
// $result_rule = mysqli_query($conn, $rule_sql);
// // now running loop for every selected rule equations
// while ($row_rule = mysqli_fetch_assoc($result_rule)) {
// $rule_age_start = $row_rule['rule_age_start'];
// $rule_age_end = $row_rule['rule_age_end'];
// $rule_gender = $row_rule['rule_gender'];
// $result_id = $row_rule['result'];
// error_log("it has the result field value of " . $result_id);
// error_log("equation age gender data " . $rule_age_start . " " . $rule_age_end . " " . $rule_gender);
// if (intval($rule_age_end) != 0) {
// if (intval($rule_age_start) > intval($age)) {
// error_log("got here and continue for age mismatch" . $rule_age_start . " " . $age);
// continue;
// } else if (intval($rule_age_end) < intval($age)) {
// error_log("got here and continue for age mismatch" . $rule_age_end . " " . $age);
// continue;
// }
// }
// if (($rule_gender != "" || $rule_gender != null) && $rule_gender != $pat_gender) {
// error_log("got here and continue for gender mismatch");
// continue;
// } else {
// $equation = "";
// $rule_save = "select * from rule_save where equation_rule_id='" . $row_rule['rule_eq_id'] . "'";
// error_log("rule save " . $rule_save);
// $result_rule_save = mysqli_query($conn, $rule_save);
// while ($row_rule_save = mysqli_fetch_assoc($result_rule_save)) {
// $key_name = getFieldFromTable('kay_param_name', 'key_health_reportable_parameter_master', 'key_param_id', $row_rule_save['checkup_parameter']);
// $checkup_parameter = "";
// $checkup_parameter_sql = "select column_name from checkup_parameter where key_health_map_name='" . $row_rule_save['checkup_parameter'] . "' and checkup_form_section_id='" . $row_section['section_id'] . "'";
// error_log("to get parameter id name" . $checkup_parameter_sql);
// $result_param = mysqli_query($conn, $checkup_parameter_sql);
// while ($row_param = mysqli_fetch_assoc($result_param)) {
// $checkup_parameter = $row_param['column_name'];
// }
// error_log("checkup_parameter id: " . $checkup_parameter);
// $condition = getTableFieldValue('rule_condition', 'condition_sy', 'rule_condition_id', $row_rule_save['condition_id']);
// error_log("condition " . $condition);
// $joiner = getTableFieldValue('rule_joiner', 'joiner_sy', 'rule_joiner_id', $row_rule_save['joiner_id']);
// error_log("joiner " . $joiner);
// $user_entered_param_value_sql = "select checkup_form_value from checkup_form_key_value where checkup_form_id ='" . $checkup_ids[$num] . "' and checkup_form_key='" . $checkup_parameter . "' ";
// error_log("getting value form db " . $user_entered_param_value_sql);
// $result_param_value = mysqli_query($conn, $user_entered_param_value_sql);
// $row_user_entered_param_value = mysqli_fetch_assoc($result_param_value);
// $user_entered_param_value = $row_user_entered_param_value['checkup_form_value'];
// error_log("result_param: " . $result_id);
// error_log("value " . $user_entered_param_value);
// if ($result_id === "0" || $result_id === 0) {
// if ($user_entered_param_value == "") {
// // break;
// } else {
// $equation = $equation . $joiner . $row_rule_save['op_br'] . $user_entered_param_value . $condition . $row_rule_save['rule_s_val'] . $row_rule_save['cl_br'];
// error_log("equation " . $equation);
// }
// } else {
// if ($user_entered_param_value == "" && $row_rule_save['rule_s_val'] != '0') {
// $equation = $equation . $joiner . $row_rule_save['op_br'] . $condition . $row_rule_save['rule_s_val'] . $row_rule_save['cl_br'];
// error_log("got here equation is in else if " . $equation);
// } else {
// if ($row_rule_save['rule_s_val'] == '0') {
// $equation = $equation . $joiner . $row_rule_save['op_br'] . $user_entered_param_value . $condition . $row_rule_save['cl_br'];
// error_log("got here equation is in else in if " . $equation);
// } else {
// $equation = $equation . $joiner . $row_rule_save['op_br'] . $user_entered_param_value . $condition . $row_rule_save['rule_s_val'] . $row_rule_save['cl_br'];
// error_log("got here equation is in else in else " . $equation);
// }
// error_log("equation " . $equation);
// }
// }
// }
// if ($equation != "" && ($result_id == "" || $result_id == 0 || $result_id == null)) {
// $resultr = solveMathExpression($equation);
// error_log("result " . $resultr);
// if ($resultr == 1 || $resultr == true) {
// array_push($data, $row_rule['abnormality']);
// error_log("abnormalities " . print_r($data, true));
// }
// } else if ($equation != "" && ($result_id != "" && $result_id != 0 && $result_id != null)) {
// error_log("we got the equation " . $equation);
// $final_cal_val = solveMathExpression($equation);
// $checkup_parameter_id = getFieldFromTable('column_name', 'checkup_parameter', 'checkup_parameter_id', $result_id);
// $param_data[$checkup_parameter_id] = $final_cal_val;
// }
// }
// }
// }
// }
// end steps
// $final_result = array(
// 'data' => $data,
// 'result' => $param_data
// );
// error_log("final result data " . print_r($final_result, true));
// $abnormality_ids = join(",", $data);
// error_log("generated abnormality " . $abnormality_ids);
//end here
// updating the rule generated value into db
// if (isset($final_result['result'])) {
// foreach ($final_result['result'] as $key => $value) {
// $key_value_sql = "update checkup_form_key_value set checkup_form_value='" . $value . "' where checkup_form_id='" . $checkup_ids[$num] . "' and checkup_form_key ='" . $key . "'";
// error_log("updating key value for approval " . $key_value_sql);
// if (!$result_key_value = mysqli_query($conn, $key_value_sql)) {
// error_log("error in updating key value for approval " . mysqli_error($conn) . " query is " . $key_value_sql);
// $status_code = 400;
// rollback();
// }
// }
// }
$query = "update checkup_form set current_status='DRP',medical_attend='" . $_SESSION['logged_user_empid'] . "' where checkup_id='" . $checkup_ids[$num] . "'; ";
error_log("sending for approval " . $query);
if (!$result = mysqli_query($conn, $query)) {
error_log("error in sending for approval " . mysqli_error($conn) . " query is " . $query);
$status_code = 400;
rollback();
}
}
// function solveMathExpression($expression)
// {
// try {
// return round(eval("return ($expression);"), 2);
// } catch (ParseError $e) {
// error_log("getting exception in this " . $e->getMessage());
// }
// }
echo json_encode($status_code);