355 lines
12 KiB
PHP
355 lines
12 KiB
PHP
<?php
|
|
class Receiveruploadlog extends MY_Controller
|
|
{
|
|
var $max_limit = 20;
|
|
public function __construct()
|
|
{
|
|
parent::__construct();
|
|
// db wilayah contoh surabaya
|
|
// $this->db = $this->load->database("regional", true);
|
|
|
|
// string database
|
|
$this->db_str_doctor = 'one_doctor';
|
|
}
|
|
|
|
|
|
public function index()
|
|
{
|
|
echo "RECEIVER UPLOAD LOG API";
|
|
}
|
|
|
|
function get_param_z()
|
|
{
|
|
$body_z = file_get_contents("php://input");
|
|
$body = gzuncompress($body_z);
|
|
return json_decode($body, true);
|
|
}
|
|
|
|
function reply($resp)
|
|
{
|
|
echo json_encode($resp);
|
|
}
|
|
|
|
function reply_gz($resp)
|
|
{
|
|
//echo json_encode($resp);
|
|
echo gzcompress(json_encode($resp));
|
|
}
|
|
|
|
public function r_upload_log()
|
|
{
|
|
$this->db->trans_begin();
|
|
$param = $this->get_param_z();
|
|
// print_r($param);
|
|
// print_r;
|
|
|
|
// echo json_decode($param);
|
|
|
|
// print_r($prm);
|
|
|
|
$order_patient_id_array = [];
|
|
$data_json_result = [];
|
|
$data_json = [];
|
|
|
|
$str_order_patient_id = "";
|
|
|
|
foreach($param['data'] as $key)
|
|
{
|
|
$order_patient_id_array[] = intval($key['order_patient_id']);
|
|
}
|
|
|
|
// $implode_order_patient_id = implode(",",$order_patient_id_array);
|
|
$str_order_patient_id = implode(",",$order_patient_id_array);
|
|
if($str_order_patient_id == ""){
|
|
$str_order_patient_id = "0";
|
|
}
|
|
|
|
$sql_cek_one_result = "select oneResultOrderPatientID,
|
|
oneResultOrderM_BranchID,
|
|
oneResultOrderM_BranchCode,
|
|
oneResultJson
|
|
from $this->db_str_doctor.one_result
|
|
WHERE oneResultOrderPatientID IN ($str_order_patient_id)";
|
|
|
|
// echo $sql_cek_one_result;
|
|
$query_cek = $this->db->query($sql_cek_one_result);
|
|
|
|
if(!$query_cek){
|
|
$this->db->trans_rollback();
|
|
$this->sys_error_db(["status" => "ERR", "message" => "select cek one_result | " .
|
|
$this->db->error()["message"], "debug" => $this->db->last_query()]);
|
|
exit;
|
|
}
|
|
|
|
$rows_cek = $query_cek->result_array();
|
|
$index = 0;
|
|
// if(count($rows_cek) == 0)
|
|
// {
|
|
// insert one_result
|
|
|
|
$data_order_patient_id_one_result = [];
|
|
foreach($rows_cek as $key => $val)
|
|
{
|
|
$data_order_patient_id_one_result[] = $val['oneResultOrderPatientID'];
|
|
}
|
|
|
|
// foreach($result['data'] as $key)
|
|
|
|
$order_patient_result = [];
|
|
// $index = 0;
|
|
|
|
// print_r($param['data']);
|
|
// print_r($data_order_patient_id_one_result);
|
|
foreach($param['data'] as $key)
|
|
{
|
|
if(in_array($key['order_patient_id'], $data_order_patient_id_one_result)){
|
|
// $order_patient_result[] = $key['order_patient_id'];
|
|
// continue;
|
|
|
|
// jk sudah ada data di one_result maka update
|
|
|
|
$data_json_update =
|
|
[
|
|
"order_patient_id" => $key['order_patient_id'],
|
|
"T_OrderHeaderLabNumberExt" => $key['T_OrderHeaderLabNumberExt'],
|
|
"T_OrderHeaderDate" => $key['T_OrderHeaderDate'],
|
|
"T_OrderHeaderID" => $key['T_OrderHeaderID'],
|
|
"T_OrderHeaderSenderM_DoctorID" => $key['T_OrderHeaderSenderM_DoctorID'],
|
|
"M_BranchID" => $key['M_BranchID'],
|
|
"M_BranchCode" => $key['M_BranchCode'],
|
|
"patient" => $key['patient'],
|
|
"result" => $key['result'],
|
|
"sample" => $key['sample']
|
|
];
|
|
|
|
$this->update_one_result_by_order_patient_id(
|
|
$key['order_patient_id'],
|
|
$key['M_BranchID'],
|
|
$key['M_BranchCode'],
|
|
$data_json_update,
|
|
$key['patient'][0]
|
|
);
|
|
|
|
$order_patient_result[] = $key['order_patient_id'];
|
|
|
|
}
|
|
|
|
// jk tidak ada mk insert baru
|
|
else
|
|
{
|
|
$data_json =
|
|
[
|
|
"order_patient_id" => $key['order_patient_id'],
|
|
"T_OrderHeaderLabNumberExt" => $key['T_OrderHeaderLabNumberExt'],
|
|
"T_OrderHeaderDate" => $key['T_OrderHeaderDate'],
|
|
"T_OrderHeaderID" => $key['T_OrderHeaderID'],
|
|
"T_OrderHeaderSenderM_DoctorID" => $key['T_OrderHeaderSenderM_DoctorID'],
|
|
"M_BranchID" => $key['M_BranchID'],
|
|
"M_BranchCode" => $key['M_BranchCode'],
|
|
"patient" => $key['patient'],
|
|
"result" => $key['result'],
|
|
"sample" => $key['sample']
|
|
];
|
|
|
|
$this->insert_one_result(
|
|
$key['order_patient_id'],
|
|
$key['M_BranchID'],
|
|
$key['M_BranchCode'],
|
|
$data_json,
|
|
$key['patient'][0]
|
|
);
|
|
|
|
$order_patient_result[] = $key['order_patient_id'];
|
|
}
|
|
|
|
|
|
// $index++;
|
|
}
|
|
|
|
$this->db->trans_commit();
|
|
// $this->db->trans_rollback();
|
|
$this->reply(
|
|
[
|
|
"status" => "OK",
|
|
"message" => "Data berhasil ditambahkan ke one_result",
|
|
"order_patient_id" => $order_patient_result,
|
|
]);
|
|
|
|
// return json_encode(
|
|
// array(
|
|
// "status" => "OK",
|
|
// "message" => "Data berhasil ditambahkan ke one_result",
|
|
// "order_patient_id" => $str_order_patient_id
|
|
// )
|
|
// );
|
|
// }
|
|
|
|
// else
|
|
// {
|
|
// // sudah ditambahkan
|
|
// // return json_encode(
|
|
// // array(
|
|
// // 'status' => 'ERR',
|
|
// // 'message' => 'Data Sudah Ditambahkan'
|
|
// // )
|
|
// // );
|
|
|
|
// $this->db->trans_rollback();
|
|
// $this->reply(
|
|
// [
|
|
// "status" => "ERR",
|
|
// "message" => "Data sudah ditambahkan ke one_result",
|
|
// "order_patient_id" => $str_order_patient_id
|
|
// ]);
|
|
// }
|
|
|
|
}
|
|
|
|
function insert_one_result($order_patient_id, $m_branch_id, $m_branch_code, $result, $patient)
|
|
{
|
|
// insert
|
|
$sql_insert_one_result = "INSERT INTO $this->db_str_doctor.one_result(
|
|
oneResultOrderPatientID,
|
|
oneResultOrderM_BranchID,
|
|
oneResultOrderM_BranchCode,
|
|
oneResultJson
|
|
) VALUES (?, ?, ?, ?)";
|
|
|
|
$query_insert = $this->db->query($sql_insert_one_result, [
|
|
intval($order_patient_id),
|
|
intval($m_branch_id),
|
|
$m_branch_code,
|
|
json_encode($result)
|
|
]);
|
|
|
|
// echo $this->db->last_query();
|
|
if (!$query_insert) {
|
|
// print_r($this->db->last_query());
|
|
$this->db->trans_rollback();
|
|
$this->sys_error_db(["status" => "ERR", "message" => "insert one result log | " .
|
|
$this->db->error()["message"], "debug" => $this->db->last_query()]);
|
|
exit;
|
|
}
|
|
|
|
// print_r($patient['patient'][0]['PatientFullName']);
|
|
// update order patient
|
|
$sql_update = "Update
|
|
$this->db_str_doctor.order_patient
|
|
set OrderPatientFullName = ?,
|
|
OrderPatientDOB = ?,
|
|
OrderPatientNIK = ?,
|
|
OrderPatientHp = ?,
|
|
OrderPatientAddress = ?,
|
|
OrderPatientIsConfirmed = 'Y'
|
|
where OrderPatientID = ?
|
|
";
|
|
|
|
$query_update = $this->db->query($sql_update,[
|
|
$patient['PatientFullName'],
|
|
$patient['M_PatientDOB'],
|
|
$patient['M_PatientIDNumber'],
|
|
$patient['M_PatientHP'],
|
|
$patient['M_PatientAddressDescription'],
|
|
$order_patient_id
|
|
]);
|
|
|
|
if (!$query_update) {
|
|
// print_r($this->db->last_query());
|
|
$this->db->trans_rollback();
|
|
$this->sys_error_db(["status" => "ERR", "message" => "update order patient | " .
|
|
$this->db->error()["message"], "debug" => $this->db->last_query()]);
|
|
exit;
|
|
}
|
|
|
|
// return json_encode(
|
|
// array(
|
|
// 'status' => 'OK',
|
|
// )
|
|
// );
|
|
|
|
// $this->reply(["status" => "OK", "message" => "Data berhasil ditambahkan ke one_result"]);
|
|
}
|
|
|
|
function update_one_result_by_order_patient_id($order_patient_id, $m_branch_id, $m_branch_code, $result, $patient)
|
|
{
|
|
// update
|
|
$sql_update_one_result = "UPDATE $this->db_str_doctor.one_result
|
|
SET
|
|
oneResultOrderM_BranchID = ?,
|
|
oneResultOrderM_BranchCode = ?,
|
|
oneResultJson = ?
|
|
WHERE oneResultOrderPatientID = ?";
|
|
|
|
// echo $sql_update_one_result;
|
|
|
|
$query_update = $this->db->query($sql_update_one_result, [
|
|
intval($m_branch_id),
|
|
$m_branch_code,
|
|
json_encode($result),
|
|
intval($order_patient_id)
|
|
]);
|
|
|
|
// echo $this->db->last_query();
|
|
if (!$query_update) {
|
|
// print_r($this->db->last_query());
|
|
$this->db->trans_rollback();
|
|
$this->sys_error_db(["status" => "ERR", "message" => "update one result log | " .
|
|
$this->db->error()["message"], "debug" => $this->db->last_query()]);
|
|
exit;
|
|
}
|
|
|
|
// print_r($patient['patient'][0]['PatientFullName']);
|
|
// update order patient
|
|
|
|
// old
|
|
// $sql_update = "Update
|
|
// $this->db_str_doctor.order_patient
|
|
// set OrderPatientFullName = ?,
|
|
// OrderPatientDOB = ?,
|
|
// OrderPatientNIK = ?,
|
|
// OrderPatientHp = ?,
|
|
// OrderPatientAddress = ?,
|
|
// OrderPatientIsConfirmed = 'Y'
|
|
// where OrderPatientID = ?
|
|
// ";
|
|
|
|
// new
|
|
$sql_update = "Update
|
|
$this->db_str_doctor.order_patient
|
|
set OrderPatientFullName = ?,
|
|
OrderPatientDOB = ?,
|
|
OrderPatientNIK = ?,
|
|
OrderPatientHp = ?,
|
|
OrderPatientAddress = ?,
|
|
OrderPatientIsConfirmed = 'Y'
|
|
where OrderPatientID = ?
|
|
";
|
|
|
|
$query_update = $this->db->query($sql_update,[
|
|
$patient['PatientFullName'],
|
|
$patient['M_PatientDOB'],
|
|
$patient['M_PatientIDNumber'],
|
|
$patient['M_PatientHP'],
|
|
$patient['M_PatientAddressDescription'],
|
|
$order_patient_id
|
|
]);
|
|
|
|
if (!$query_update) {
|
|
// print_r($this->db->last_query());
|
|
$this->db->trans_rollback();
|
|
$this->sys_error_db(["status" => "ERR", "message" => "update order patient | " .
|
|
$this->db->error()["message"], "debug" => $this->db->last_query()]);
|
|
exit;
|
|
}
|
|
|
|
// return json_encode(
|
|
// array(
|
|
// 'status' => 'OK',
|
|
// )
|
|
// );
|
|
|
|
// $this->reply(["status" => "OK", "message" => "Data berhasil ditambahkan ke one_result"]);
|
|
}
|
|
|
|
}
|
|
?>
|