";
$is_hospitalized = $row_employee_appointment['is_hospitalized'] == 'Y' ? "Yes       $hospitalization_pdf" : "No";
$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 = '';
$followups_pdf = '';
$space = " ";
$treatment_text = getTreatmentText($row_employee_appointment['appointment_id']);
if (isAccessible($_SESSION['RoleId'], $menu_key, 'R')) {
if ($appointment_type == 'I') {
$inc_link = $space . "";
} else {
$inc_link = "";
}
$pdf_link = $space . "";
$short_pdf_link = $space . "";
$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 . "";
} else {
$lab_pdf_link = "";
}
if ($ref_to != '' || $ref_to != null) {
$referral_letter = $space . "";
}
// $view_link = $space . "";
$dashboard_link = $space . "";
$email_link = $space . "";
}
$GIVE_EDIT_OPTION_AFTER_THIS_DATE = getFieldFromTable('value', 'config', 'key_name', 'GIVE_EDIT_OPTION_AFTER_THIS_DATE');
if (isAccessibleForSameDoc($_SESSION['RoleId'], $menu_key, 'W', $row_employee_appointment['doctor_last_attended'], 0)) {
// to avoid edit in old opd data of chirayu
if (date("Y-m-d", strtotime($row_employee_appointment['appointment_date'])) > date("Y-m-d", strtotime($GIVE_EDIT_OPTION_AFTER_THIS_DATE))) {
$edit_link = $space . "";
}
}
$time_difference_seconds = time() - strtotime($row_employee_appointment['appointment_date']);
$time_difference_hours = $time_difference_seconds / (60 * 60);
$deletion_config = getFieldFromTable('value', 'config', 'key_name', 'ALLOWED_DELETION_FOR_FIXED_HOURS');
if (isAccessibleForSameDoc($_SESSION['RoleId'], $menu_key, 'E', $row_employee_appointment['doctor_last_attended'], 0) && $treatment_text == '' && $time_difference_hours < $deletion_config) {
$delete_link = $space . "";
}
$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)) {
$followup_ticket = $row_followup['ticket_no'];
$followups_pdf .= $space . "";
if (isAccessibleForSameDoc($_SESSION['RoleId'], $menu_key, 'W', $row_followup['doctor_last_attended'], 0)) {
$followups_pdf .= $space . "" . $row_followup["ticket_no"] . "
";
}
}
}
// 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 = "Yes";
} else {
$isInjury = "No";
}
// if ($row_employee_appointment['IsEmergency'] == 1) {
// $isEmergency = "Yes";
// } else {
// $isEmergency = "No";
// }
if ($row_employee_appointment['attended_status'] == 'DET') {
$isDetention = $space . "Yes ()";
} else {
$isDetention = "No";
}
$doctor_attended_flag = "No";
if ($row_employee_appointment['doctor_attended_flag'] == 'Y') {
$doctor_attended_flag = "Yes";
} else {
$doctor_attended_flag = "No";
}
$issue_by = '';
$medicin_issued = "select distinct(issue_by) as issue_by from treatment where appointment_id='" . $row_employee_appointment['appointment_id'] . "'";
if (!$result_issue_by = @mysqli_query($conn, $medicin_issued)) {
exit(mysqli_error($conn));
}
if (mysqli_num_rows($result_issue_by) > 0) {
while ($row_issue_by = mysqli_fetch_assoc($result_issue_by)) {
if ($issue_by != '') {
$issue_by .= '&' . $space;
}
$doc_emp_id = getTableFieldValue("tbl_users", "emp_id", "user_id", '"' . $row_issue_by['issue_by'] . '"');
$issue_by .= getTableFieldValue('patient_master', "patient_name", 'id', '"' . $doc_emp_id . '"') . $space;
}
}
error_log('trtr' . $issueing_user);
$check_results = "SBP:" . $row_employee_appointment['bp_sbp'] . ", DBP:" . $row_employee_appointment['bp_dbp'] . ",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'] . ",RESPIRATORY RATE:" . $row_employee_appointment['respiratory_rate'] . ",HEART RATE:" . $row_employee_appointment['heart_rate'] . ",PULSE OUTPUT:" . $row_employee_appointment['pulse_output'] . ", 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_pdf,
$row_employee_appointment['emp_code'],
$row_employee_appointment['patient_name'],
$is_hospitalized,
// $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(
'',
"",
"",
'',
'',
'',
'',
'',
'',
'',
'',
'',
'',
'',
'',
'',
'',
'',
'',
'',
'',
'',
)
);
echo json_encode($data);
?>