59 lines
2.0 KiB
PHP
59 lines
2.0 KiB
PHP
![]() |
<?php
|
||
|
|
||
|
include('includes/config/config.php');
|
||
|
include('includes/functions.php');
|
||
|
begin();
|
||
|
$status_code = 200;
|
||
|
$drug_allergy_ids = $_REQUEST['drug_allergies'];
|
||
|
$patient_id = $_REQUEST['emp_id'];
|
||
|
|
||
|
error_log("drug " . print_r($drug_allergies, true));
|
||
|
$pid = getFieldFromTable('pid', 'problem_master', 'pcode', 'ALG');
|
||
|
$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 {
|
||
|
for ($i = 0; $i < sizeof($drug_allergy_ids); $i++) {
|
||
|
$insert = "insert into problem_response_details set rid='" . $rid . "', rvalue='" . $drug_allergy_ids[$i] . "'";
|
||
|
error_log("inserting in drug allergies " . $insert);
|
||
|
if (!$insert_result = mysqli_query($conn, $insert)) {
|
||
|
$status_code = 400;
|
||
|
error_log("error in inserting in drug allergies " . $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);
|
||
|
|
||
|
for ($i = 0; $i < sizeof($drug_allergy_ids); $i++) {
|
||
|
$insert = "insert into problem_response_details set rid='" . $rid . "', rvalue='" . $drug_allergy_ids[$i] . "'";
|
||
|
error_log("inserting in drug allergies " . $insert);
|
||
|
if (!$insert_result = mysqli_query($conn, $insert)) {
|
||
|
$status_code = 400;
|
||
|
error_log("error in inserting in drug allergies " . $insert);
|
||
|
rollback();
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
|
||
|
commit();
|
||
|
echo json_encode($status_code);
|