ohctech_p8/mock_drill_script.php
2024-10-16 19:18:52 +05:30

158 lines
6.1 KiB
PHP

<?php
include('includes/config/config.php');
include('includes/auth/auth.php');
include('includes/functions.php');
include('access.php');
include('log_entry.php');
error_reporting(E_ERROR | E_PARSE);
?>
<?php
// Connect to MySQL database
$page = 1; // The current page
$sortname = 'mockdril_id'; // Sort column
$sortorder = 'desc'; // Sort order
$qtype = ''; // Search column
$query = ''; // Search string
// Get posted data
if (isset($_POST['page'])) {
$page = mysqli_real_escape_string($conn, $_POST['page']);
}
if (isset($_POST['sortname'])) {
$sortname = mysqli_real_escape_string($conn, $_POST['sortname']);
}
if (isset($_POST['sortorder'])) {
$sortorder = mysqli_real_escape_string($conn, $_POST['sortorder']);
}
if (isset($_POST['qtype'])) {
$qtype = mysqli_real_escape_string($conn, $_POST['qtype']);
}
if (isset($_POST['query'])) {
$query = mysqli_real_escape_string($conn, $_POST['query']);
}
if (isset($_POST['rp'])) {
$rp = mysqli_real_escape_string($conn, $_POST['rp']);
}
// Setup sort and search SQL using posted data
$sortSql = "order by $sortname $sortorder";
//$sortSql = "order by patient_master.$sortname $sortorder";
// $searchSql = " where patient_master.email_id LIKE '%@%' and patient_id!='0' and patient_id is not null";
// if($qtype=='patient_attending_doctor_name'){
// $searchSql = ($qtype != '' && $query != '') ? "where upper($qtype) like upper('%" . trim ( $query ) . "%')" : '';
// }
// else if($qtype=='patient_attending_staff_name'){
// $searchSql = ($qtype != '' && $query != '') ? "where upper($qtype) like upper('%" . trim ( $query ) . "%')" : '';
// }
if ($qtype == 'location') {
$searchSql = ($qtype != '' && $query != '') ? "where upper($qtype) like upper('%" . trim($query) . "%')" : '';
} else if ($qtype == 'given_treatment') {
$searchSql = ($qtype != '' && $query != '') ? "where upper($qtype) like upper('%" . trim($query) . "%')" : '';
}
// else{
// $searchSql = ($qtype != '' && $query != '') ? "where upper($qtype) like upper('%" . trim ( $query ) . "%')" : '';
// }
// Get total count of records
$sql = "select count(*) from mockdril $searchSql";
$result = mysqli_query($conn, $sql);
$CountRow = mysqli_fetch_array($result);
$total = $CountRow[0];
// Setup paging SQL
$pageStart = ($page - 1) * $rp;
$limitSql = "limit $pageStart, $rp";
// Setup sort and search SQL using posted data
$hasReadAccess = isAccessible($_SESSION['RoleId'], $menu_key, 'R');
$hasWriteAccess = isAccessible($_SESSION['RoleId'], $menu_key, 'W');
$hasExecuteAccess = isAccessible($_SESSION['RoleId'], $menu_key, 'E');
// error_log($_SESSION['RoleId']);
// error_log($menu_key);
// Return JSON data
$data = array();
$data['page'] = $page;
$data['total'] = $total;
$data['rows'] = array();
$sql = "SELECT * from mockdril $searchSql $sortSql $limitSql";
$sql_export = $sql;
error_log("sq 71 " . $sql);
$results = mysqli_query($conn, $sql);
$count = 1;
while ($row = mysqli_fetch_assoc($results)) {
$user_id = $row['mockdril_id'];
//$company = getFieldFromTable('client_name', 'client_master', 'client_id', $row['client_id']);
$view_link = "";
$edit_link = "";
$delete_link = "";
$links = "";
if ($hasReadAccess) {
$view_link = "<a href=\"#\"class=\"green\" onclick=\"open_client_appointment('" . $user_id . "','V');\"><i class=\"ace-icon fa fa-search-plus bigger-130\"></i></a>";
}
if ($hasWriteAccess) {
$edit_link = "<a href=\"#\" class=\"blue\" onclick=\"open_client_appointment('" . $user_id . "','E');\"><i class=\"ace-icon fa fa-pencil bigger-130\"></i></a>";
}
if ($hasExecuteAccess) {
$delete_link = "<a href=\"#\" class=\"blue\" onclick=\"delete_client_appointment('" . $user_id . "');\"><i class=\"ace-icon fa fa-trash-o bigger-130\"></i></a>";
}
$space = "&nbsp;&nbsp;&nbsp;";
$links = $assign_link . $space . $view_link . $space . $edit_link . $space . $delete_link;
// $assign_link . $space .
//$links="<div class=\"hidden-sm hidden-xs btn-group\">".$links."</div>";
$filled = $row['id'];
$box2 = "select patient_name from patient_master where id='" . $filled . "'";
error_log("filled" . $box2);
$result1 = mysqli_query($conn, $box2);
$row3 = mysqli_fetch_assoc($result1);
$box3 = "SELECT dob,employer_contractor_name from patient_master p, employer_contractor ec where p.employer_contractor_id=ec.id and p.id='$filled'";
$result2 = mysqli_query($conn, $box3);
$row4 = mysqli_fetch_assoc($result2);
$dob = $row4['dob'];
$birthdate = new DateTime($dob);
$today = new DateTime('today');
$age = $birthdate->diff($today)->y;
$data['rows'][] = array(
'id' => $row['id'],
'cell' => array(
$count++,
$links,
$row3['patient_name'],
$age,
$row4['employer_contractor_name'],
$row['location'],
date_format(date_create($row['date_of_mockdrill']), "d-M-Y"),
$row['patient_attending_doctor_name'],
$row['patient_attending_staff_name'],
$row['amb_sen_t'],
$row['inf_rec_time'],
$row['patients_in_hospital'],
$row['given_treatment'],
$row['patient_condition_on_discharge_time'],
$row['dis_time'],
$row['bp'],
$row['pulse'],
$row['Spo2'],
$row['RBS'],
$row['temp']
)
);
}
commit();
$data['rows'][] = array(
'id' => $row['filterkey'],
'cell' => array('', "<input type=hidden name='filterkey' id='filterkey' value=\"" . base64_encode($sql_export) . "\">", "<input type=hidden name=paramlist id=paramlist value=\"" . ($qtype . ':' . $query) . "\">", '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '')
);
echo json_encode($data);
?>