ohctech_p8/update_remove_habit_data.php

59 lines
2.1 KiB
PHP
Raw Normal View History

2024-10-16 19:18:52 +05:30
<?php
include('includes/config/config.php');
include('includes/functions.php');
begin();
$status_code = 200;
$habit_data_ids = $_REQUEST['habit_data'];
$patient_id = $_REQUEST['emp_id'];
error_log("habits " . print_r($habit_data_ids, true));
$pid = getFieldFromTable('pid', 'problem_master', 'pcode', 'HBT');
$checkSql = "select * from problem_response where patient_id='" . $patient_id . "' and pid ='" . $pid . "'";
error_log("present drug allergies " . $checkSql);
$result = mysqli_query($conn, $checkSql);
$row = mysqli_fetch_assoc($result);
$num_rows = mysqli_num_rows($result);
if ($num_rows > 0) {
$rid = $row['rid'];
// delete already present records
$sql = "delete from problem_response_details where rid = '" . $rid . "'";
if (!$result = mysqli_query($conn, $sql)) {
$status_code = 400;
error_log("error in deleting in drug allergies " . $sql);
rollback();
} else {
2024-11-02 18:03:13 +05:30
for ($i = 0; $i < count($habit_data_ids); $i++) {
2024-10-16 19:18:52 +05:30
$insert = "insert into problem_response_details set rid='" . $rid . "', rvalue='" . $habit_data_ids[$i] . "'";
error_log("inserting in habits" . $insert);
if (!$insert_result = mysqli_query($conn, $insert)) {
$status_code = 400;
error_log("error in inserting in habits " . $insert);
rollback();
}
}
}
} else {
$insert = "insert into problem_response set pid='" . $pid . "', patient_id='" . $patient_id . "'";
$result = mysqli_query($conn, $insert);
$rid = mysqli_insert_id($conn);
error_log("already inserted id " . $rid);
2024-11-02 18:03:13 +05:30
for ($i = 0; $i < count($habit_data_ids); $i++) {
2024-10-16 19:18:52 +05:30
$insert = "insert into problem_response_details set rid='" . $rid . "', rvalue='" . $habit_data_ids[$i] . "'";
error_log("inserting in habits " . $insert);
if (!$insert_result = mysqli_query($conn, $insert)) {
$status_code = 400;
error_log("error in inserting in habits " . $insert);
rollback();
}
}
}
commit();
echo json_encode($status_code);