402 lines
19 KiB
PHP
402 lines
19 KiB
PHP
<?php
|
|
include('includes/config/config.php');
|
|
include('includes/auth/auth.php');
|
|
include('includes/functions.php');
|
|
include 'log_entry.php';
|
|
include('access.php');
|
|
error_reporting(E_ERROR | E_PARSE);
|
|
?>
|
|
<?php
|
|
// Connect to mysqli database
|
|
$page = 1; // The current page
|
|
$sortname = 'appointment_date'; // 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
|
|
// Setup paging
|
|
if (!isset($rp)) {
|
|
$rp = 20;
|
|
}
|
|
$sortSql = "order by $sortname $sortorder";
|
|
$pageStart = ($page - 1) * $rp;
|
|
$limitSql = " limit $pageStart, $rp";
|
|
$searchSql = ($qtype != '' && $query != '') ? "where upper($qtype) like upper('%" . trim($query) . "%')" : '';
|
|
// Get total count of records
|
|
if ($searchSql != '') {
|
|
if ($qtype == 'appointment_date') {
|
|
$searchSql = " and date_format(date(appointment_date),'%Y-%m-%d')=str_to_date('$query','%d/%m/%Y') ";
|
|
// $searchSql = " and date_format(date(appointment_date),'%Y-%m-%d')=str_to_date('$query','%d-%m-%Y') ";
|
|
} else if ($qtype == 'appointment_date_between') {
|
|
$dates = explode("-", $query);
|
|
// $qtype=" due_date between ";
|
|
$searchSql = " and appointment_date between str_to_date('" . trim($dates[0]) . "','%d/%m/%Y') and str_to_date('" . trim($dates[1]) . "','%d/%m/%Y') ";
|
|
} elseif ($qtype == 'case_type') {
|
|
if ($query == 'NEW CASE') {
|
|
$searchSql = "and ep.case_type = 'NEW'";
|
|
} elseif ($query == 'REPEAT') {
|
|
$searchSql = "and ep.case_type = 'REP'";
|
|
} elseif ($query == strtoupper('Follow up') || $query == strtoupper('Followup')) {
|
|
$searchSql = "and ep.case_type = 'FUP'";
|
|
} elseif ($query == strtoupper('Executive Follow up') || $query == strtoupper('Executive')) {
|
|
$searchSql = "and ep.case_type = 'EFUP'";
|
|
} elseif ($query == strtoupper('Medication')) {
|
|
$searchSql = "and ep.case_type = 'MED'";
|
|
} else {
|
|
$searchSql = "and ep.case_type = ''";
|
|
}
|
|
} else if ($qtype == 'complaints') {
|
|
$query = '"' . $query . '"';
|
|
$dates = getTableFieldValue("complaints", "complaint_id", "complaint", $query);
|
|
// $qtype=" due_date between ";
|
|
$searchSql = "and FIND_IN_SET('$dates',complaints)";
|
|
} else if ($qtype == 'IsEmergency') {
|
|
if ($query == "Y" || $query == "y") {
|
|
$dates = 1;
|
|
} else {
|
|
$dates = 0;
|
|
}
|
|
// $qtype=" due_date between ";
|
|
$searchSql = "and $qtype=$dates";
|
|
} else if ($qtype == 'examination_remarks') {
|
|
$query = '"' . $query . '"';
|
|
$dates = getTableFieldValue("examination_findings", "id", "examination_finding", trim($query));
|
|
// $qtype=" due_date between ";
|
|
$searchSql = "and FIND_IN_SET('$dates',examination_remarks)";
|
|
} else if ($qtype == 'emp_code') {
|
|
$emp_id = getFieldFromTable('id', 'patient_master', 'emp_code', trim($query));
|
|
$searchSql = ($qtype != '' && $query != '' && trim($query) != '') ? " and emp_id = '" . $emp_id . "' " : '';
|
|
} else {
|
|
$searchSql = ($qtype != '' && $query != '') ? "and upper($qtype) like upper('%" . trim($query) . "%')" : '';
|
|
}
|
|
}
|
|
// error_log("date:".$searchSql);
|
|
/*
|
|
* elseif($qtype!=''){
|
|
* if($qtype=='ailment_name'){
|
|
* $searchSql =" and a.ailment_id in (select ailment_id from ailment where upper(ailment_name) like upper('%".trim($query)."%')) ";
|
|
* $searchSql=preg_replace('/and/', 'where', $searchSql, 1);
|
|
* }
|
|
* }
|
|
*/
|
|
// echo "read access:".$hasReadAccess;
|
|
// echo "write access:".$hasWriteAccess;
|
|
if ($searchSql != '') {
|
|
if ($qtype != '') {
|
|
if ($qtype == 'ailment_name') {
|
|
$searchSql = " and upper(ailments_new) like upper(trim('%$query%') ) ";
|
|
}
|
|
}
|
|
// echo $searchSql;
|
|
}
|
|
|
|
if ($searchSql != '') {
|
|
if ($qtype != '') {
|
|
if ($qtype == 'doctor_last_attended') {
|
|
|
|
$sql_name = "select b.user_id from patient_master a left join tbl_users b on a.id = b.emp_id where patient_name like upper(trim('%$query%') )";
|
|
|
|
$result_name = mysqli_query($conn, $sql_name);
|
|
|
|
$row_name = mysqli_fetch_array($result_name);
|
|
|
|
$searchSql = " and doctor_last_attended = '" . $row_name['user_id'] . "' ";
|
|
}
|
|
}
|
|
// echo $searchSql;
|
|
}
|
|
$sql = "select count(*) from employee_appointment ep inner join patient_master e on e.id=ep.emp_id and ep.ohc_type_id='" . $_SESSION['current_ohcttype'] . "' $searchSql ";
|
|
// echo $sql;
|
|
// echo $sql;
|
|
$result = mysqli_query($conn, $sql);
|
|
$row = mysqli_fetch_array($result);
|
|
$total = $row[0];
|
|
// Return JSON data
|
|
$data = array();
|
|
$data['page'] = $page;
|
|
$data['total'] = $total;
|
|
$data['rows'] = array();
|
|
$sql_employee_appointment = "select case_type,followup_remarks, patient_name,dept_id,emp_code ,e.id,appointment_id,ep.* ,ep.modified_by as mod_by from employee_appointment ep inner join patient_master e on e.id=ep.emp_id and ep.ohc_type_id='" . $_SESSION['current_ohcttype'] . "' ";
|
|
// echo $sql_employee_appointment;
|
|
|
|
$sql_export = $sql_employee_appointment;
|
|
$sql_employee_appointment .= " $searchSql $sortSql $limitSql ";
|
|
error_log("sql_employee_appointment ID::" . $sql_employee_appointment);
|
|
// echo $sql_employee_appointment;
|
|
$sql_export .= " $searchSql $sortSql ";
|
|
// echo $sql_employee_appointment;
|
|
$results_employee_appointment = mysqli_query($conn, $sql_employee_appointment);
|
|
$count = ($page - 1) * $rp + 1;
|
|
// echo $sql_ailment;
|
|
// echo $access_level;
|
|
while ($row_employee_appointment = mysqli_fetch_assoc($results_employee_appointment)) {
|
|
extract($row_employee_appointment);
|
|
$diagnosis = "";
|
|
// $complaints = "";
|
|
$findings = "";
|
|
$appointment_type = $row_employee_appointment['appointment_type'];
|
|
$appointment_id = $row_employee_appointment['appointment_id'];
|
|
// error_log("APPOINTMENT ID::".$appointment_id);
|
|
$appointment_status = $row_employee_appointment['attended_status'];
|
|
$emp_id = $row_employee_appointment['id'];
|
|
$dept_id = $row_employee_appointment['dept_id'];
|
|
$doc_id = $row_employee_appointment['doctor_last_attended'];
|
|
$mod_id = $row_employee_appointment['mod_by'];
|
|
$case_type = $row_employee_appointment['case_type'];
|
|
$ref_to = $row_employee_appointment['referral'];
|
|
|
|
|
|
|
|
|
|
if ($case_type == 'NEW') {
|
|
$case_type = 'New Case';
|
|
} elseif ($case_type == 'REP') {
|
|
$case_type = 'Repeat';
|
|
} elseif ($case_type == 'FUP') {
|
|
$case_type = 'Follow up';
|
|
} elseif ($case_type == 'EFUP') {
|
|
$case_type = 'Executive Follow up';
|
|
} elseif ($case_type == 'MED') {
|
|
$case_type = 'Medication';
|
|
} else {
|
|
$case_type = 'None';
|
|
}
|
|
|
|
$followup_remarks = $row_employee_appointment['followup_remarks'];
|
|
// error_log("dept_email".$dept_id);
|
|
// error_log("doc_id:".$doc_id);
|
|
// error_log("mod_by:".$mod_id);
|
|
$dept_email = getTableFieldValue('department', 'dept_email', 'dept_id', $dept_id, '');
|
|
if ($doc_id != 0) {
|
|
|
|
$doc_emp_id = getTableFieldValue('tbl_users', 'emp_id', 'user_id', $doc_id);
|
|
$doc_name = getTableFieldValue('patient_master', 'patient_name', 'id', $doc_emp_id);
|
|
// error_log("if:".$doc_id);
|
|
} else {
|
|
$doc_emp_id = getTableFieldValue('tbl_users', 'emp_id', 'user_id', $mod_id);
|
|
$doc_name = getTableFieldValue('patient_master', 'patient_name', 'id', $doc_emp_id);
|
|
// error_log("else:".$mod_id);
|
|
}
|
|
// error_log("dept_email".$dept_email);
|
|
//if ($appointment_type == 'O') {
|
|
$diagnosis = getCommaSeperatedValuesForInClause("select ailment_name from ailment ", "ailment_id", $row_employee_appointment['ailments_new']);
|
|
$complaint_ids = $row_employee_appointment['complaints'];
|
|
$complaint_ids_array = array();
|
|
$complaint_ids_array = explode(",", $complaint_ids);
|
|
$complaints = "";
|
|
for ($i = 0; $i < count($complaint_ids_array); $i++) {
|
|
if ($i == 0) {
|
|
if (is_numeric($complaint_ids_array[$i])) {
|
|
$complaints = getTableFieldValue('complaints', 'complaint', 'complaint_id', $complaint_ids_array[$i]);
|
|
} else {
|
|
$complaints = $complaint_ids_array[$i];
|
|
}
|
|
} else {
|
|
if (is_numeric($complaint_ids_array[$i])) {
|
|
$complaints = $complaints . "," . getTableFieldValue('complaints', 'complaint', 'complaint_id', $complaint_ids_array[$i]);
|
|
} else {
|
|
$complaints = $complaints . "," . $complaint_ids_array[$i];
|
|
}
|
|
}
|
|
}
|
|
$referral = getCommaSeperatedValuesForInClause("select referral_point_name from referral_point ", "referral_point_id ", $row_employee_appointment['referral']);
|
|
|
|
$findings = getCommaSeperatedValuesForInClause("select examination_finding from examination_findings ", "id", $row_employee_appointment['examination_remarks']);
|
|
|
|
// $diagnosis =$row_employee_appointment['ailments_new'];
|
|
// } else if ($appointment_type == 'I') {
|
|
// $diagnosis=$row_employee_appointment['injury_types_new'];
|
|
// $diagnosis = getCommaSeperatedValuesForInClause("select injury_type_name from //injury_type", "injury_type_id", $row_employee_appointment['injury_types_new']);
|
|
//}
|
|
$view_link = "";
|
|
$edit_link = "";
|
|
$pdf_link = "";
|
|
$short_pdf_link = "";
|
|
$inc_link = "";
|
|
$links = "";
|
|
$delete_link = "";
|
|
$dashboard_link = "";
|
|
$lab_pdf_link = "";
|
|
$referral_letter = '';
|
|
$followups = '';
|
|
$space = " ";
|
|
$treatment_text = getTreatmentText($row_employee_appointment['appointment_id']);
|
|
if (isAccessible($_SESSION['RoleId'], $menu_key, 'R')) {
|
|
|
|
if ($appointment_type == 'I') {
|
|
$inc_link = $space . "<a target=\"_blank\" class=\"blue\" onclick=\"exporttopdf_common_form24('" . $appointment_id . "');\" data-toggle=\"tooltip\" data-placement=\"top\" title=\"Form 24\" ><i class=\"fa fa-file-pdf-o\" style=\"font-size: 15px;\"></i></a>";
|
|
} else {
|
|
$inc_link = "";
|
|
}
|
|
|
|
|
|
|
|
$pdf_link = $space . "<a href=\"#\" title='Treatments Details' class=\"red\" onclick=\"exporttopdf_common('" . $appointment_type . "','" . $appointment_id . "');\"><i class=\"fa fa-file-pdf-o\" style=\"font-size: 15px;\"></i></a>";
|
|
|
|
$short_pdf_link = $space . "<a href=\"#\" title='Prescriptions Only' class=\"orange\" onclick=\"exporttoSortpdf_common('" . $appointment_type . "','" . $appointment_id . "');\"><i class=\"fa fa-file-pdf-o\" style=\"font-size: 15px;\"></i></a>";
|
|
|
|
$lab_record_exist = "select checkup_id from checkup_form where appointment_id='" . $appointment_id . "' and current_status='MRA'";
|
|
$result_lab = mysqli_query($conn, $lab_record_exist);
|
|
// $num_rows = mysqli_fetch_assoc($result_lab);
|
|
$row_lab = mysqli_fetch_assoc($result_lab);
|
|
error_log("lab sql " . $lab_record_exist);
|
|
// error_log("lab record exists " . $lab_record_exist);
|
|
if ($row_lab['checkup_id'] != null && $row_lab['checkup_id'] != '') {
|
|
$lab_pdf_link = $space . "<a target=\"_blank\" title='Lab Report' href=\"lab_report_pdf.php?checkup_id=" . $row_lab['checkup_id'] . "\"class=\"green\" title=\"Lab Pdf\" ><i class=\"ace-icon fa fa-file-pdf-o\" style=\"font-size: 15px;\"></i></a>";
|
|
} else {
|
|
$lab_pdf_link = "";
|
|
}
|
|
|
|
if ($ref_to != '' || $ref_to != null) {
|
|
$referral_letter = $space . "<a target=\"_blank\" title='Referral Letter' href=\"referral_latter_pdf.php?appointment_id=" . $appointment_id . "\"class=\"aqua\" title=\"Referral Letter\" ><i class=\"ace-icon fa fa-file-pdf-o\" style=\"font-size: 15px;\"></i></a>";
|
|
}
|
|
|
|
|
|
|
|
// $view_link = $space . "<a id='appointment_id_" . $appointment_id . "' href=\"#\"class=\"grey\" onclick=\"open_employee_appointment('" . $appointment_id . "','" . $appointment_type . "','" . $emp_id . "','V');\"><i class=\"ace-icon fa fa-eye\" style=\"font-size: 15px;\"></i></a>";
|
|
$dashboard_link = $space . "<a href=\"#\" class=\"purple\" onclick=\"open_dashboard('" . $emp_id . "');\"><i style=\"font-size: 15px;\" class=\"glyphicon glyphicon-user\"></i></a>";
|
|
$email_link = $space . "<a id='appointment_id_" . $appointment_id . "' href=\"#\" class=\"blue\" onclick=\"open_item('" . $appointment_id . "','" . $appointment_type . "','" . $dept_email . "',this);\"><i class=\"fa fa-envelope\" style=\"font-size: 15px;\"></i></a>";
|
|
}
|
|
if (isAccessible($_SESSION['RoleId'], $menu_key, 'W')) {
|
|
$edit_link = $space . "<a href=\"#\" class=\"blue\" onclick=\"open_employee_appointment('" . $appointment_id . "','" . $appointment_type . "','" . $emp_id . "','E','0');\"><i class=\"ace-icon fa fa-edit\" style=\"font-size: 15px;\"></i></a>";
|
|
}
|
|
if (isAccessible($_SESSION['RoleId'], $menu_key, 'E') && $treatment_text == '' && $row_employee_appointment['doctor_attended_flag'] != 'Y') {
|
|
$delete_link = $space . "<a href=\"#\" class=\"red\" onclick=\"delete_employee_appointment_history('" . $appointment_id . "');\"><i class=\"ace-icon fa fa-trash-o\" style=\"font-size: 15px;\"></i></a>";
|
|
}
|
|
|
|
|
|
|
|
|
|
$query_followup = "select * from followup_details where appointment_id='" . $row_employee_appointment['appointment_id'] . "' and ohc_type_id='" . $_SESSION['current_ohcttype'] . "' ";
|
|
error_log("Patient_Search_followup:" . $query_followup);
|
|
if (!$result_followup = @mysqli_query($conn, $query_followup)) {
|
|
exit(mysqli_error($conn));
|
|
}
|
|
|
|
if (mysqli_num_rows($result_followup) > 0) {
|
|
while ($row_followup = mysqli_fetch_assoc($result_followup)) {
|
|
|
|
if (isAccessible($_SESSION['RoleId'], $menu_key, 'W')) {
|
|
$followups .= $space . "<a href=\"#\" title='Followup Details' class=\"red\" onclick=\"exporttopdf_common_followup('" . $appointment_type . "','" . $row_followup['followup_id'] . "');\"><i class=\"fa fa-file-pdf-o\" style=\"font-size: 15px;\"></i></a>";
|
|
$followups .= $space . "<a href=\"#\" title='Edit Followup Details' class=\"green\" onclick=\"open_employee_appointment('" . $appointment_id . "','" . $appointment_type . "','" . $emp_id . "','F','" . $row_followup['followup_id'] . "');\">" . $row_followup["ticket_no"] . "</a><br>";
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// if($row_employee_appointment['doctor_attended_flag'] != 'Y'){
|
|
// $pdf_link="";
|
|
// }
|
|
$links = $view_link . $edit_link . $delete_link . $pdf_link . $short_pdf_link . $email_link . $inc_link . $dashboard_link . $lab_pdf_link . $referral_letter;
|
|
$isEmergency = "";
|
|
$isInjury = "";
|
|
$isDetention = "";
|
|
if ($appointment_type == 'I') {
|
|
$isInjury = "<span class='red'>Yes</i></span>";
|
|
} else {
|
|
$isInjury = "<span class='green'>No</i></span>";
|
|
}
|
|
if ($row_employee_appointment['IsEmergency'] == 1) {
|
|
$isEmergency = "<span class=' lighter red'>Yes</i></span>";
|
|
} else {
|
|
$isEmergency = "<span class='green'>No</i></span>";
|
|
}
|
|
|
|
if ($row_employee_appointment['attended_status'] == 'DET') {
|
|
$isDetention = $space . "<span class=' lighter red'>Yes</i></span> (<a href=\"#\" class=\"red\" onclick=\"exporttopdf_common_ipd('" . $appointment_type . "','" . $appointment_id . "','" . $appointment_status . "');\"><i class=\"fa fa-file-pdf-o\" style=\"font-size: 15px;\"></i></a>)";
|
|
} else {
|
|
$isDetention = "<span class='green'>No</i></span>";
|
|
}
|
|
|
|
$doctor_attended_flag = "No";
|
|
if ($row_employee_appointment['doctor_attended_flag'] == 'Y') {
|
|
$doctor_attended_flag = "<span class=' lighter red'>Yes</i></span>";
|
|
} else {
|
|
$doctor_attended_flag = "<span class='green'>No</i></span>";
|
|
}
|
|
$issue_by = '';
|
|
$doc_emp_id = getTableFieldValue("tbl_users", "emp_id", "user_id", '"' . $row['doctor_last_attended'] . '"');
|
|
$issue_by = getTableFieldValue('patient_master', "patient_name", 'id', '"' . $doc_emp_id . '"');
|
|
|
|
error_log('trtr' . $issueing_user);
|
|
$check_results = "SBP:" . $row_employee_appointment['bp_sbp'] . ", DBP:" . $row_employee_appointment['bp_dbp'] . ", FBS:" . $row_employee_appointment['blood_sugar_fbs'] . ", RBS:" . $row_employee_appointment['blood_sugar_rbs'] . ",Temp:" . $row_employee_appointment['temperature'] . ",SPOC2%:" . $row_employee_appointment['spo2_percent'] . ",WEIGHT:" . $row_employee_appointment['weight'] . ",HEIGHT:" . $row_employee_appointment['height'] . ",BMI:" . $row_employee_appointment['bmi'] . ",RESPIARATORY RATE:" . $row_employee_appointment['respiratory_rate'] . ",HEART RATE:" . $row_employee_appointment['heart_rate'] . ",URINE OUTPUT:" . $row_employee_appointment['urine_output'] . ",OXYGEN SUPPLY:" . $row_employee_appointment['oxygen_supply'] . ",AVPU" . $row_employee_appointment['avpu'] . ", MOBILITY:" . $row_employee_appointment['mobility'] . ",TRAMA:" . $row_employee_appointment['trama'] . ", GLASGOW COMA SCALE:" . $row_employee_appointment['glasgow_coma_scale'];
|
|
$data['rows'][] = array(
|
|
'id' => $row_employee_appointment['appointment_id'],
|
|
'cell' => array(
|
|
$count++,
|
|
$links,
|
|
getFieldFromTable('ohc_type_name', 'ohc_type', 'ohc_type_id', $row_employee_appointment['ohc_type_id']),
|
|
date_format(date_create($row_employee_appointment['appointment_date']), "d-M-Y h:i a"),
|
|
$row_employee_appointment['ticket_no'],
|
|
$followups,
|
|
$row_employee_appointment['emp_code'],
|
|
$row_employee_appointment['patient_name'],
|
|
$case_type,
|
|
$followup_remarks,
|
|
$isEmergency,
|
|
$isInjury,
|
|
$isDetention,
|
|
$doctor_attended_flag,
|
|
$issue_by,
|
|
$complaints,
|
|
$findings,
|
|
$diagnosis,
|
|
$treatment_text,
|
|
$doc_name,
|
|
$referral,
|
|
$row_employee_appointment['followup'],
|
|
$check_results
|
|
)
|
|
);
|
|
}
|
|
$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=\"" . base64_encode($paramlist) . "\">",
|
|
'',
|
|
'',
|
|
'',
|
|
'',
|
|
'',
|
|
'',
|
|
'',
|
|
'',
|
|
'',
|
|
'',
|
|
'',
|
|
'',
|
|
'',
|
|
'',
|
|
'',
|
|
'',
|
|
'',
|
|
'',
|
|
'',
|
|
)
|
|
);
|
|
echo json_encode($data);
|
|
?>
|