353 lines
16 KiB
PHP
353 lines
16 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");
|
|
$checkup_type_id = $_REQUEST['rule_param_id_onc'];
|
|
|
|
error_log("into rele val");
|
|
$final_result = [];
|
|
$param_data = [];
|
|
$data = [];
|
|
// start steps
|
|
// select every section from checkup type id and after that select every rule that is associated in every section
|
|
|
|
$pat_dob = $_REQUEST['pat_age'];
|
|
$pat_gender = $_REQUEST['pat_gender'];
|
|
$today = date("Y-m-d");
|
|
error_log("pat_dob " . $pat_dob);
|
|
$age = ($today - $pat_dob);
|
|
error_log("age " . $age);
|
|
|
|
if ($checkup_type_id != '' && $checkup_type_id != null && !empty($checkup_type_id)) {
|
|
|
|
$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));
|
|
// $section_ids = getCommaSeperatedValuesToInClause($section_id);
|
|
// now selecting rule equations using section ids from section table
|
|
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);
|
|
|
|
|
|
//making the rule equation and running
|
|
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']."' and FIND_IN_SET('" . $checkup_type_id . "',checkup_type_ids)";
|
|
|
|
$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 " . $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 = $_REQUEST[$checkup_parameter];
|
|
|
|
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)) {
|
|
eval("\$resultr = $equation;");
|
|
|
|
error_log("result " . $resultr);
|
|
|
|
if ($resultr == 1 || $resultr == true) {
|
|
$abnormality = getFieldFromTable('abnormality_name', 'abnormality', 'abnormality_id', $row_rule['abnormality']);
|
|
error_log("abnormalities " . $abnormality);
|
|
|
|
array_push($data, $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;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
} else {
|
|
$patient_id = $_REQUEST['emp_id'];
|
|
|
|
error_log("patient id " . $patient_id);
|
|
$pat_dob = getFieldFromTable('dob', 'patient_master', 'id', $patient_id);
|
|
|
|
$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', $patient_id);
|
|
error_log("patient gender " . $pat_gender);
|
|
|
|
$sql_section = "";
|
|
if ($_REQUEST['appointment_type'] == 'O') {
|
|
$sql_section = "select * from checkup_parameter where opd_param='1' having rule_ids!= ''";
|
|
} else if ($_REQUEST['appointment_type'] == 'I') {
|
|
$sql_section = "select * from checkup_parameter where inj_param='1' having rule_ids!= ''";
|
|
}
|
|
error_log("query for rules " . $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);
|
|
|
|
|
|
//making the rule equation and running
|
|
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 = "";
|
|
|
|
|
|
if ($_REQUEST['appointment_type'] == 'O') {
|
|
$checkup_parameter_sql = "select column_name from checkup_parameter where key_health_map_name='" . $row_rule_save['checkup_parameter'] . "' and opd_param='1'";
|
|
} else if ($_REQUEST['appointment_type'] == 'I') {
|
|
$checkup_parameter_sql = "select column_name from checkup_parameter where key_health_map_name='" . $row_rule_save['checkup_parameter'] . "' and inj_param='1'";
|
|
}
|
|
|
|
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 " . $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 = $_REQUEST[$checkup_parameter];
|
|
|
|
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)) {
|
|
eval("\$resultr = $equation;");
|
|
|
|
error_log("result " . $resultr);
|
|
|
|
if ($resultr == 1 || $resultr == true) {
|
|
$abnormality = getFieldFromTable('abnormality_name', 'abnormality', 'abnormality_id', $row_rule['abnormality']);
|
|
error_log("abnormalities " . $abnormality);
|
|
|
|
array_push($data, $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
|
|
|
|
function solveMathExpression($expression)
|
|
{
|
|
// Define a regular expression pattern to match a valid math expression
|
|
// $pattern = "/^[-+]?[0-9]*\.?[0-9]+([eE][-+]?[0-9]+)?(\s*[-+*\/]\s*[-+]?[0-9]*\.?[0-9]+([eE][-+]?[0-9]+)?)*$/";
|
|
|
|
// Check if the math expression matches the pattern
|
|
// if (preg_match($pattern, $expression)) {
|
|
try {
|
|
return round(eval("return ($expression);"), 2);
|
|
} catch (ParseError $e) {
|
|
error_log("getting exception in this " . $e->getMessage());
|
|
}
|
|
// } else {
|
|
// error_log("equation is not valid");
|
|
// }
|
|
}
|
|
$final_result = array(
|
|
'data' => $data,
|
|
'result' => $param_data
|
|
);
|
|
|
|
error_log("final result data " . print_r($final_result, true));
|
|
echo json_encode($final_result);
|