154 lines
7.1 KiB
PHP
154 lines
7.1 KiB
PHP
<?php
|
|
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");
|
|
foreach ($_REQUEST as $key => $value) {
|
|
error_log($key . " : " . $value . "<br />\r\n");
|
|
}
|
|
error_log("End Printing Request Attributes");
|
|
// error_reporting(E_ERROR | E_PARSE);
|
|
$appointment_id = $_REQUEST['appointment_id'];
|
|
$is_discharge = $_REQUEST['is_discharge'];
|
|
if($is_discharge=='Y'){
|
|
$ipd=0;
|
|
}else {
|
|
$ipd=1;
|
|
}
|
|
error_log('is_dir' . $is_discharge);
|
|
// echo $appointment_id;
|
|
$data = array();
|
|
|
|
$query = "";
|
|
$query_initial = "";
|
|
$query_end = " ";
|
|
begin();
|
|
|
|
$sql_update_discharge_status = "UPDATE `employee_appointment` SET `is_discharge` = '" . $is_discharge . "' ,`ipd` = '" . $ipd . "' WHERE `employee_appointment`.`appointment_id` = '" . $appointment_id . "'";
|
|
$result_sql_update_discharge_status = @mysqli_query($conn, $sql_update_discharge_status);
|
|
|
|
$row_existing = runSqlGenericSingleRow("select * from detention_master where opd_id='" . $appointment_id . "' ");
|
|
if ($row_existing != null) {
|
|
$detention_id = $row_existing['opd_id'];
|
|
$data['message'] = "update";
|
|
$query_initial = " update detention_master ";
|
|
$query_end = " where opd_id = '" . $detention_id . "' ";
|
|
} else {
|
|
$query_initial = "insert into detention_master ";
|
|
$data['message'] = "save";
|
|
}
|
|
// echo "yyyyyyyyyyyyyyy".$query_initial;
|
|
$query = " set opd_id = '$appointment_id', reporting_time= STR_TO_DATE('" . $_POST['appointment_date'] . "', '%d/%m/%Y %h:%i %p') ,disposal_time=STR_TO_DATE('" . $_POST['disposal_time'] . "', '%d/%m/%Y %h:%i %p'),modified_by='" . $_SESSION['user_id'] . "'";
|
|
$query = $query_initial . " " . $query . " " . $query_end;
|
|
if (!$result = @mysqli_query($conn, $query)) {
|
|
error_log("Exception while saving detention:" . mysqli_error($conn));
|
|
error_log("Failing Query: " . $query);
|
|
rollback();
|
|
exit(error_log(mysqli_error($conn)));
|
|
} else {
|
|
error_log("save/update successfull." . $query);
|
|
/* for reset Item Stock At Dispensary Level */
|
|
if (!@mysqli_query($conn, "delete from detention_observation where det_id='" . $appointment_id . "' ")) {
|
|
error_log("No records found for deletion:" . mysqli_error($conn));
|
|
}
|
|
for ($i = 0; $i < $_REQUEST['count_items']; $i++) {
|
|
if (${"observation_time$i"} != null && ${"observation_time$i"} != "") {
|
|
$query_observation = "insert into detention_observation SET det_id='" . $appointment_id . "',observation_time = STR_TO_DATE('" . ${"observation_time$i"} . "', '%d/%m/%Y %h:%i %p') ,
|
|
bp='" . addslashes(${"bp$i"}) . "',pulse='" . addslashes(${"pulse$i"}) . "',
|
|
spo2='" . ${"spo2$i"} . "',ecg='" . ${"ecg$i"} . "',temp='" . ${"temp$i"} . "' ,modified_by='" . $_SESSION['user_id'] . "' ";
|
|
if (!$result = @mysqli_query($conn, $query_observation)) {
|
|
error_log("Error Saving observation data: " . mysqli_error($conn) . " Failed Query:" . $query_observation);
|
|
rollback();
|
|
exit(mysqli_error($conn));
|
|
}
|
|
}
|
|
}
|
|
|
|
$sql_select_existing = "select * from detention_intake where det_id='" . $appointment_id . "' ";
|
|
error_log("EXISTING RECORD::" . $sql_select_existing);
|
|
$results = @mysqli_query($GLOBALS['conn'], $sql_select_existing);
|
|
$num_rows_existing = mysqli_num_rows($results);
|
|
|
|
error_log("NUMBER OF ROWS::" . $num_rows_existing);
|
|
//if update case found
|
|
if ($num_rows_existing != 0) {
|
|
//add back to the dispensary stock the existing qty
|
|
resetIPDDispensaryItemsStock($appointment_id, $_SESSION['current_ohcttype']);
|
|
//then delete the record
|
|
if (!@mysqli_query($GLOBALS['conn'], "delete from detention_intake where det_id='" . $appointment_id . "' ")) {
|
|
error_log("No records found for deletion:" . mysqli_error($conn));
|
|
//rollback ();
|
|
// exit ( mysqli_error($conn) );
|
|
}
|
|
}
|
|
|
|
for ($i = 0; $i < $_REQUEST['count_items1']; $i++) {
|
|
if (${"medicine$i"} != null && ${"medicine$i"} != "") {
|
|
$query_intake = "insert into detention_intake SET det_id='" . $appointment_id . "',intake_time = STR_TO_DATE('" . ${"intake_time$i"} . "', '%d/%m/%Y %h:%i %p') ,
|
|
medicine='" . addslashes(${"medicine$i"}) . "',administration_route='" . addslashes(${"administration_route$i"}) . "',issued_qty='" . ${"issued_qty$i"} . "',modified_by='" . $_SESSION['user_id'] . "' ";
|
|
|
|
if (!$result = @mysqli_query($conn, $query_intake)) {
|
|
error_log("Error Saving intake data: " . mysqli_error($conn) . " Failed Query:" . $query_intake);
|
|
rollback();
|
|
exit(mysqli_error($conn));
|
|
} else {
|
|
error_log("Done Saving intake data: " . $query_intake);
|
|
|
|
|
|
|
|
// insert or update the cost details start
|
|
$past_detention_id = getTableFieldValue('treatment_cost_master', 'detention_id', 'item_id', ${"medicine$i"}, 'detention_id', $appointment_id);
|
|
|
|
if ($past_detention_id != "" || $past_detention_id != null) {
|
|
error_log("update case for cost saving for detention ");
|
|
$initquery = "update ";
|
|
$endquery = " where item_id='" . ${"medicine$i"} . "' and detention_id='" . $appointment_id . "'";
|
|
} else {
|
|
$initquery = "insert into ";
|
|
$endquery = "";
|
|
}
|
|
|
|
|
|
$present_per_unit_cost = getTableFieldValue('item_cost', 'item_rate_latest', 'ohc_type_id', $_SESSION['current_ohcttype'], 'item_id', ${"medicine$i"});
|
|
|
|
$total_cost = round($present_per_unit_cost * ${"issued_qty$i"});
|
|
|
|
error_log("latest rate for item id " . getItemWithFormName(${"medicine$i"}) . " " . $present_per_unit_cost . " total sum for this item " . $total_cost);
|
|
|
|
$insert_treatment_cost = $initquery . " treatment_cost_master set detention_id='" . $appointment_id . "',ohc_type_id='" . $_SESSION['current_ohcttype'] . "',issued_item_cost='" . $total_cost . "',item_id='" . ${"medicine$i"} . "' $endquery";
|
|
|
|
error_log("cost saving query for opd detention" . $insert_treatment_cost);
|
|
|
|
if (!$insert_treatment_cost_result = mysqli_query($conn, $insert_treatment_cost)) {
|
|
error_log("error in cost saving query for opd detention" . mysqli_error($conn));
|
|
}
|
|
|
|
|
|
// insert or update the cost details end
|
|
}
|
|
//reduce the new stock qty from the dispensary stock
|
|
updateItemStockAtDispensaryLevel($_SESSION['current_ohcttype'], addslashes(${"medicine$i"}), ${"issued_qty$i"});
|
|
}
|
|
}
|
|
if (!@mysqli_query($conn, "delete from detention_output where det_id='" . $appointment_id . "' ")) {
|
|
error_log("No records found for deletion:" . mysqli_error($conn));
|
|
}
|
|
for ($i = 0; $i < $_REQUEST['count_items2']; $i++) {
|
|
if (${"output_route$i"} != null && ${"output_route$i"} != "") {
|
|
$query_output = "insert into detention_output SET det_id='" . $appointment_id . "',output_time =STR_TO_DATE('" . ${"output_time$i"} . "', '%d/%m/%Y %h:%i %p') ,
|
|
output_route='" . addslashes(${"output_route$i"}) . "',output_qty='" . addslashes(${"output_qty$i"}) . "',modified_by='" . $_SESSION['user_id'] . "' ";
|
|
if (!$result = @mysqli_query($conn, $query_output)) {
|
|
error_log("Error Saving output data: " . mysqli_error($conn) . " Failed Query:" . $query_output);
|
|
rollback();
|
|
exit(mysqli_error($conn));
|
|
} else {
|
|
error_log("Done Saving output data: " . $query_output);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
commit();
|
|
$data['appointment_id'] = $appointment_id;
|
|
echo json_encode($data); |