55 lines
2.2 KiB
PHP
55 lines
2.2 KiB
PHP
|
<?php
|
||
|
include('includes/config/config.php');
|
||
|
include('includes/functions.php');
|
||
|
include('log_entry.php');
|
||
|
|
||
|
// Debug logging for request attributes
|
||
|
$requestStr = "Start Printing Request Attributes\n";
|
||
|
foreach ($_REQUEST as $key => $value) {
|
||
|
$requestStr .= $key . " : " . $value . "\n";
|
||
|
}
|
||
|
$requestStr .= "End Printing Request Attributes\n";
|
||
|
error_log($requestStr);
|
||
|
save_log($requestStr, 'Disease Master', 'SAVE', 'save_disease_list.php');
|
||
|
|
||
|
|
||
|
if (isset($_POST['count_items'])) {
|
||
|
$noOfRows = intval($_POST['count_items']);
|
||
|
|
||
|
begin();
|
||
|
|
||
|
$prescription_id = $_POST['prescription_id'];
|
||
|
$diseases = $_POST['chronic_illness'];
|
||
|
$diagnosis = $_POST['diagnosis'];
|
||
|
|
||
|
for ($i = 0; $i < $noOfRows; $i++) {
|
||
|
$medicine_name = $_POST["medicine_name$i"];
|
||
|
$medicine_frequency = $_POST["medicine_frequency$i"];
|
||
|
|
||
|
if (!empty($medicine_name)) {
|
||
|
$health_advice_ids = implode(",", $_POST["health_advice_name_new$i"]);
|
||
|
|
||
|
if (!empty($prescription_id)) {
|
||
|
$query = "UPDATE prescription_master set diseases = '" . $diseases . "',diagnosis='" . $diagnosis . "', medicine_name = '" . ${"medicine_name$i"} . "', medicine_frequency = '" . ${"medicine_frequency$i"} . "',medicine_timing = '" . ${"medicine_timing$i"} . "' , admin_route = '" . ${"admin_route$i"} . "' , duration = '" . ${"duration$i"} . "' ,health_advices='" . $health_advice_ids . "', dose_qty = '" . ${"dose_qty$i"} . "'WHERE prescription_id = '$prescription_id'";
|
||
|
} else {
|
||
|
$query = "INSERT INTO prescription_master set diseases = '" . $diseases . "', diagnosis='" . $diagnosis . "',medicine_name = '" . ${"medicine_name$i"} . "', medicine_frequency = '" . ${"medicine_frequency$i"} . "',medicine_timing = '" . ${"medicine_timing$i"} . "' , admin_route = '" . ${"admin_route$i"} . "' , duration = '" . ${"duration$i"} . "' ,health_advices='" . $health_advice_ids . "', dose_qty = '" . ${"dose_qty$i"} . "'";
|
||
|
}
|
||
|
|
||
|
error_log("Query: $query");
|
||
|
|
||
|
// Execute query
|
||
|
$result = mysqli_query($conn, $query);
|
||
|
|
||
|
if (!$result) {
|
||
|
rollback(); // Rollback transaction in case of error
|
||
|
error_log("Error executing query: " . mysqli_error($conn));
|
||
|
exit;
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
|
||
|
commit(); // Commit transaction if all queries were successful
|
||
|
} else {
|
||
|
error_log("Required data not present");
|
||
|
}
|