161 lines
6.6 KiB
PHP
161 lines
6.6 KiB
PHP
<?php
|
|
include('includes/config/config.php');
|
|
include('includes/functions.php');
|
|
// $agencyId = $_REQUEST['agencyId'];
|
|
$section_ids = $_POST['section_id'];
|
|
error_log("sections id " . $section_ids);
|
|
$section_id = implode(",", $section_ids);
|
|
$checkup_id = $_REQUEST['checkup_id'];
|
|
$appointment_lab_id = trim($_REQUEST['appointment_lab_id']);
|
|
$followup_lab_id = trim($_REQUEST['followup_lab_id']);
|
|
|
|
error_log("appointment id for lab " . $appointment_lab_id . " followup lab id " . $followup_lab_id . " checkup id " . $checkup_id);
|
|
|
|
$query = "";
|
|
|
|
if ($appointment_lab_id != '' && $appointment_lab_id > 0 && $followup_lab_id == 0) {
|
|
$test_param_ids = getFieldFromTable('recommended_test_param_new', 'employee_appointment', 'appointment_id', $appointment_lab_id);
|
|
} else if ($appointment_lab_id != '' && $followup_lab_id != '' && $appointment_lab_id > 0 && $followup_lab_id > 0) {
|
|
$test_param_ids = getFieldFromTable('recommended_test_param_new', 'followup_details', 'followup_id', $followup_lab_id);
|
|
}
|
|
$paras = array();
|
|
$data = array();
|
|
|
|
if ($test_param_ids != null && $test_param_ids != '' && !empty($test_param_ids)) {
|
|
$count = 0;
|
|
$i = 0;
|
|
$section_arr = [];
|
|
foreach ($section_ids as $ids) {
|
|
|
|
error_log("section ids " . $ids);
|
|
|
|
// this query if doc has selected the parameters
|
|
$query = "select a.checkup_parameter_id,b.device_param_code,b.device_id,a.checkup_form_section_id from checkup_parameter a left join device_param_map b on a.checkup_parameter_id=b.checkup_parameter_id where checkup_form_section_id = '" . $ids . "' and b.device_param_code!='' and b.device_id!='' and a.checkup_parameter_id in ($test_param_ids)";
|
|
|
|
|
|
error_log("CHECKUP PARAMETERS::1" . $query);
|
|
if (!$result = @mysqli_query($conn, $query)) {
|
|
die(mysqli_error($conn));
|
|
}
|
|
|
|
$count += mysqli_num_rows($result);
|
|
if (mysqli_num_rows($result) > 0) {
|
|
if ($i == 0) $i = 0;
|
|
while ($row = mysqli_fetch_assoc($result)) {
|
|
$data[$i]['checkup_parameter_id'] = $row['checkup_parameter_id'];
|
|
$data[$i]['device_param_code'] = $row['device_param_code'];
|
|
$data[$i]['device_id'] = $row['device_id'];
|
|
array_push($paras, $row['checkup_parameter_id']);
|
|
$i++;
|
|
}
|
|
|
|
array_push($section_arr, $ids);
|
|
|
|
$data['paras'] = $paras;
|
|
} else {
|
|
|
|
// this query if doc has not selected the parameters
|
|
$query = "select a.checkup_parameter_id,b.device_param_code,b.device_id,a.checkup_form_section_id from checkup_parameter a left join device_param_map b on a.checkup_parameter_id=b.checkup_parameter_id where checkup_form_section_id = '" . $ids . "' and b.device_param_code!='' and b.device_id!='' ";
|
|
|
|
|
|
error_log("CHECKUP PARAMETERS::2" . $query);
|
|
if (!$result = @mysqli_query($conn, $query)) {
|
|
die(mysqli_error($conn));
|
|
}
|
|
|
|
$count += mysqli_num_rows($result);
|
|
if (mysqli_num_rows($result) > 0) {
|
|
if ($i == 0) $i = 0;
|
|
while ($row = mysqli_fetch_assoc($result)) {
|
|
$data[$i]['checkup_parameter_id'] = $row['checkup_parameter_id'];
|
|
$data[$i]['device_param_code'] = $row['device_param_code'];
|
|
$data[$i]['device_id'] = $row['device_id'];
|
|
array_push($paras, $row['checkup_parameter_id']);
|
|
$i++;
|
|
}
|
|
|
|
array_push($section_arr, $ids);
|
|
|
|
$data['paras'] = $paras;
|
|
} else {
|
|
$data['status'] = 200;
|
|
$data['message'] = "Data not found!";
|
|
}
|
|
}
|
|
}
|
|
$data['count'] = $count;
|
|
$data['sections'] = $section_arr;
|
|
} else {
|
|
|
|
$section_arr = [];
|
|
|
|
error_log("section ids " . $section_id);
|
|
|
|
$values_array = explode(',', $section_id);
|
|
|
|
$isPresent = false;
|
|
$query_part = "";
|
|
if (in_array('add_section', $values_array)) {
|
|
|
|
|
|
$isPresent = true;
|
|
$values_array = array_diff($values_array, ['add_section']);
|
|
|
|
$new_section_id = implode(',', $values_array);
|
|
|
|
$add_param_id_sql = "select add_param_ids from checkup_form where checkup_id = '" . $checkup_id . "'";
|
|
$result_add_param_id_sql = mysqli_query($conn, $add_param_id_sql);
|
|
$row_result_param_id_sql = mysqli_fetch_assoc($result_add_param_id_sql);
|
|
$add_param_ids = $row_result_param_id_sql['add_param_ids'];
|
|
$add_param_ids_array = explode(',', $add_param_ids);
|
|
$add_param_ids_array = array_filter(array_map('trim', $add_param_ids_array));
|
|
$add_param_ids_in_clause = implode(',', $add_param_ids_array);
|
|
|
|
if (empty($new_section_id)) {
|
|
array_push($section_arr, 'add_section');
|
|
$query_part = " and a.checkup_parameter_id in ($add_param_ids_in_clause)";
|
|
} else {
|
|
array_push($section_arr, 'add_section');
|
|
array_push($section_arr, $new_section_id);
|
|
$query_part = " and (checkup_form_section_id in ($new_section_id) or a.checkup_parameter_id in ($add_param_ids_in_clause))";
|
|
}
|
|
} else {
|
|
$isPresent = false;
|
|
$new_section_id = $section_id;
|
|
}
|
|
|
|
if ($isPresent == true) {
|
|
|
|
$query = "select a.checkup_parameter_id,b.device_param_code,b.device_id from checkup_parameter a left join device_param_map b on a.checkup_parameter_id=b.checkup_parameter_id where b.device_param_code!='' and b.device_id!=''" . $query_part;
|
|
} else {
|
|
$query = "select a.checkup_parameter_id,b.device_param_code,b.device_id,a.checkup_form_section_id from checkup_parameter a left join device_param_map b on a.checkup_parameter_id=b.checkup_parameter_id where checkup_form_section_id in ($new_section_id) and b.device_param_code!='' and b.device_id!='' ";
|
|
}
|
|
|
|
error_log("CHECKUP PARAMETERS::3" . $query);
|
|
if (!$result = @mysqli_query($conn, $query)) {
|
|
die(mysqli_error($conn));
|
|
}
|
|
|
|
$count = mysqli_num_rows($result);
|
|
if (mysqli_num_rows($result) > 0) {
|
|
$i = 0;
|
|
while ($row = mysqli_fetch_assoc($result)) {
|
|
$data[$i]['checkup_parameter_id'] = $row['checkup_parameter_id'];
|
|
$data[$i]['device_param_code'] = $row['device_param_code'];
|
|
$data[$i]['device_id'] = $row['device_id'];
|
|
array_push($paras, $row['checkup_parameter_id']);
|
|
$i++;
|
|
}
|
|
|
|
$data['paras'] = $paras;
|
|
$data['count'] = $count;
|
|
$data['sections'] = $section_arr;
|
|
} else {
|
|
$data['status'] = 200;
|
|
$data['message'] = "Data not found!";
|
|
}
|
|
}
|
|
|
|
error_log('paras' . print_r($data, true));
|
|
echo json_encode($data);
|