118 lines
3.2 KiB
PHP
118 lines
3.2 KiB
PHP
<?php
|
|
ini_set('max_execution_time', 120000);
|
|
include('includes/config/config.php');
|
|
include('includes/functions.php');
|
|
include('log_entry.php');
|
|
require_once('excel/vendor/php-excel-reader/excel_reader2.php');
|
|
require_once('excel/vendor/SpreadsheetReader.php');
|
|
header('Content-type: application/json');
|
|
error_reporting(E_ALL & ~E_NOTICE & ~E_DEPRECATED);
|
|
|
|
|
|
$targetPath = 'docs/allergy.xlsx';
|
|
|
|
$Reader = new SpreadsheetReader($targetPath);
|
|
|
|
$sheetCount = count($Reader->sheets());
|
|
|
|
for ($i = 0; $i < 1; $i++) {
|
|
|
|
$Reader->ChangeSheet($i);
|
|
$j = 0;
|
|
foreach ($Reader as $Row) {
|
|
if ($j == 0) {
|
|
$j = 1;
|
|
continue;
|
|
}
|
|
|
|
error_log("CURRENT ROW-> " . print_r($Row, true));
|
|
|
|
error_log("again here");
|
|
|
|
$emp_code = $Row[0];
|
|
$allergy = $Row[3];
|
|
|
|
$allergy_arr = explode("+", $allergy);
|
|
|
|
error_log("allergy " . print_r($allergy_arr, true));
|
|
|
|
$values = get_update_allergy_id($allergy_arr);
|
|
|
|
error_log("data for $row: " . $emp_code . " allergy ids " . print_r($values, true));
|
|
$rid = 0;
|
|
|
|
$rid = get_rid($emp_code);
|
|
|
|
if ($rid > 0) {
|
|
update_response_details($rid, $values);
|
|
} else {
|
|
$insert = "insert into problem_response set pid='1' ,patient_id=(select id from patient_master where emp_code='" . $emp_code . "')";
|
|
error_log("query " . $insert);
|
|
|
|
$result = mysqli_query($conn, $insert);
|
|
|
|
$rid = get_rid($emp_code);
|
|
|
|
update_response_details($rid, $values);
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
function get_update_allergy_id($val)
|
|
{
|
|
$values = [];
|
|
for ($i = 0; $i < count($val); $i++) {
|
|
|
|
$salt = get_allergy_id($val[$i]);
|
|
|
|
if ($salt > 0) {
|
|
array_push($values, $salt);
|
|
} else {
|
|
$insert = "insert into salt_master set salt_name='" . strtolower(trim($val[$i])) . "'";
|
|
error_log("query " . $insert);
|
|
$r_insert = mysqli_query($GLOBALS['conn'], $insert);
|
|
|
|
$salt = get_allergy_id($val[$i]);
|
|
|
|
array_push($values, $salt);
|
|
}
|
|
}
|
|
return $values;
|
|
}
|
|
|
|
function get_allergy_id($allergy)
|
|
{
|
|
$sql = "select salt_id from salt_master where lower(salt_name) = '" . strtolower(trim($allergy)) . "'";
|
|
error_log("query " . $sql);
|
|
$result = mysqli_query($GLOBALS['conn'], $sql);
|
|
$row = mysqli_fetch_assoc($result);
|
|
|
|
return $row['salt_id'];
|
|
}
|
|
|
|
function update_response_details($rid, $values)
|
|
{
|
|
error_log("for rid " . $rid);
|
|
for ($i = 0; $i < count($values); $i++) {
|
|
$sql = "insert into problem_response_details set rid = '" . $rid . "', rvalue='" . $values[$i] . "'";
|
|
error_log("query " . $sql);
|
|
if (!$result = mysqli_query($GLOBALS['conn'], $sql)) {
|
|
error_log("error in inserting record " . mysqli_error($GLOBALS['conn']) . " query " . $sql);
|
|
}
|
|
}
|
|
}
|
|
|
|
function get_rid($emp_code)
|
|
{
|
|
$check = "select rid from problem_response where patient_id = (select id from patient_master where emp_code = '" . $emp_code . "') and pid='1'";
|
|
error_log("query " . $check);
|
|
|
|
$res = mysqli_query($GLOBALS['conn'], $check);
|
|
$rc = mysqli_fetch_assoc($res);
|
|
|
|
$rid = $rc['rid'];
|
|
|
|
return $rid;
|
|
}
|