ESH/save_appointment.php

102 lines
3.2 KiB
PHP
Raw Normal View History

2024-10-23 18:28:06 +05:30
<?php
use Com\Tecnick\Barcode\Type\Square\QrCode\Split;
include('includes/config/config.php');
include('includes/functions.php');
error_reporting(E_ALL & ~E_NOTICE & ~E_DEPRECATED & ~E_WARNING);
// include log entry header file
include('log_entry.php');
error_log("Start Printing Request Attributes");
$requestStr = "";
foreach ($_REQUEST as $key => $value) {
$requestStr .= $key . " : " . $value . "\n";
error_log($key . " : " . $value . "<br />\r\n");
}
error_log("End Printing Request Attributes");
save_log($requestStr, 'Save_appointment', 'SAVE', 'save_appointment.php');
$appointment_book_id= $_POST['appointment_book_id'];
$app_id=0;
$doctor_name= $_POST['doctor_name'];
$appointment_book_date= $_POST['appointment_book_date'];
$patient_name_cc= $_POST['patient_name_cc'];
$app_type = $_POST['appointment_booking_type'];
$slot = $_POST['doctor_slot'];
$in='';
$end='';
if(!empty($appointment_book_id)){
$in="update";
$end=" where id='".$appointment_book_id."'";
$old_slot= getTableFieldValue('appointment_details','time','id',$appointment_book_id);
if($slot!=$old_slot){
$sql_old_slot = "update doc_slots set status='' where emp_id='$doctor_name' and slot_date=str_to_date('$appointment_book_date','%Y-%m-%d') and slot_id='$old_slot' and ohc_type_id='".$_SESSION['current_ohcttype']."' ";
error_log("sql_old_slot " . $sql_old_slot);
@mysqli_query($conn,$sql_old_slot);
}
}
else {
$in= "insert into ";
}
$sql = $in." appointment_details set emp_id = '$patient_name_cc',doctor_id='$doctor_name',date=str_to_date('$appointment_book_date','%Y-%m-%d'),time='$slot',app_type='$app_type',modified_by = '".$_SESSION['user_id']."' ,ohc_type_id='".$_SESSION['current_ohcttype']."',status='BOOKED' ".$end;
error_log("emp appointment " . $sql);
if (!$result_app = mysqli_query($conn, $sql)) {
error_log("Exception:" . mysqli_error($conn));
rollback();
error_log("Followup Save: " . $sql);
exit(error_log(mysqli_error($conn)));
} else{
if(!empty($appointment_book_id)){
$app_id=$appointment_book_id;
}else{
$query_id = "select max(id) id from appointment_details ";
// echo $query;
error_log("max appointment_id query: " . $query_id);
if (!$result_id = @mysqli_query($conn, $query_id)) {
rollback();
exit(error_log(mysqli_error($conn)));
}
if (mysqli_num_rows($result_id) > 0) {
while ($row_id = mysqli_fetch_assoc($result_id)) {
$app_id= $row_id['id'];
}
}
}
$sql_remarks = "update doc_slots set status='BOOKED' where emp_id='$doctor_name' and slot_date=str_to_date('$appointment_book_date','%Y-%m-%d') and slot_id='$slot' and ohc_type_id='".$_SESSION['current_ohcttype']."' ";
error_log("sql_remarks " . $sql_remarks);
if (!$result = @mysqli_query($conn, $sql_remarks)) {
error_log ("Exception saving save_app_indent_vendor:".mysqli_error($conn)." failing query:".$sql_remarks);
rollback();
exit(mysqli_error($conn));
}
}
$data['app_id']=$app_id;
echo json_encode($data);
?>