1017 lines
43 KiB
PHP
1017 lines
43 KiB
PHP
<?php
|
|
class ReceiverOrder extends MY_Controller
|
|
{
|
|
var $db;
|
|
function __construct()
|
|
{
|
|
parent::__construct();
|
|
}
|
|
function index()
|
|
{
|
|
echo "Api: Receiver Order ";
|
|
}
|
|
|
|
public function getRegionalIPAddress()
|
|
{
|
|
$sql_get = "SELECT S_SystemIPAddressRegional
|
|
FROM conf_systems
|
|
WHERE S_SystemsIsActive = 'Y'";
|
|
|
|
$qry = $this->db->query($sql_get);
|
|
if (!$qry) {
|
|
$this->sys_error_db("get ip regional failed", $this->db);
|
|
$this->db->trans_rollback();
|
|
exit;
|
|
}
|
|
|
|
$data = $qry->result_array();
|
|
return $data[0]['S_SystemIPAddressRegional'];
|
|
}
|
|
|
|
function getBranch()
|
|
{
|
|
try {
|
|
$sql = "SELECT M_BranchID, M_BranchCode FROM m_branch
|
|
WHERE M_BranchIsDefault = 'Y' AND M_BranchIsActive = 'Y'";
|
|
$qry = $this->db->query($sql, array());
|
|
if (!$qry) {
|
|
$response = [
|
|
'status' => false,
|
|
"message" => $this->db->error()["message"],
|
|
"msg" => "error get branch data ",
|
|
'query' => $this->db->last_query()
|
|
];
|
|
return $response;
|
|
}
|
|
$result = $qry->row_array();
|
|
return [
|
|
'status' => true,
|
|
'branchId' => $result['M_BranchID'],
|
|
'branchCode' => $result['M_BranchCode']
|
|
];
|
|
} catch (Exception $exc) {
|
|
$message = $exc->getMessage();
|
|
return [
|
|
'status' => false,
|
|
'message' => $message
|
|
];
|
|
}
|
|
}
|
|
|
|
public function post($url, $data)
|
|
{
|
|
$ch = curl_init($url);
|
|
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");
|
|
curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
|
|
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
|
|
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 10);
|
|
curl_setopt($ch, CURLOPT_TIMEOUT, 10);
|
|
curl_setopt($ch, CURLOPT_HTTPHEADER, [
|
|
"Content-Type: application/text",
|
|
"Content-Length: " . strlen($data),
|
|
]);
|
|
$result = curl_exec($ch);
|
|
if (curl_error($ch) != "") {
|
|
echo json_encode([
|
|
"status" => "ERR",
|
|
"message" => "Http Error : " . curl_error($ch),
|
|
]);
|
|
curl_close($ch);
|
|
exit();
|
|
}
|
|
curl_close($ch);
|
|
return $result;
|
|
}
|
|
|
|
// 1. t_orderdelivery
|
|
function insert_t_orderdelivery($table, $arr_t_orderdelivery)
|
|
{
|
|
$sqlQuery = "";
|
|
|
|
// for ($i = 0; $i < count($arr_t_orderdelivery); $i++) {
|
|
|
|
$key = implode(',', array_keys($arr_t_orderdelivery));
|
|
$value = "'" . implode("','", array_values($arr_t_orderdelivery)) . "'";
|
|
|
|
$sqlQuery = "INSERT INTO one_mitra.$table ($key) VALUES ($value);";
|
|
$qry = $this->db->query($sqlQuery);
|
|
if (!$qry) {
|
|
$err = [
|
|
"status" => 'ERR',
|
|
"message" => $this->db->last_query() . $this->sys_error_db(
|
|
[
|
|
"insert one_mitra.$table | func insert_t_orderdelivery " .
|
|
$this->db->error()["message"], "debug" => $this->db->last_query()
|
|
]
|
|
)
|
|
];
|
|
$this->db->trans_rollback();
|
|
return $err;
|
|
}
|
|
// }
|
|
|
|
return [
|
|
"status" => "OK",
|
|
"message" => "insert one_mitra.$table | func insert_t_orderdelivery "
|
|
];
|
|
}
|
|
|
|
// 2. t_orderdetaildelivery
|
|
function insert_t_orderdetaildelivery($table, $arr_t_orderdetaildelivery)
|
|
{
|
|
$sqlQuery = "";
|
|
|
|
// for ($i = 0; $i < count($arr_t_orderdetaildelivery); $i++) {
|
|
|
|
$key = implode(',', array_keys($arr_t_orderdetaildelivery));
|
|
$value = "'" . implode("','", array_values($arr_t_orderdetaildelivery)) . "'";
|
|
|
|
$sqlQuery = "INSERT INTO one_mitra.$table ($key) VALUES ($value);";
|
|
$qry = $this->db->query($sqlQuery);
|
|
if (!$qry) {
|
|
$err = [
|
|
"status" => 'ERR',
|
|
"message" => $this->db->last_query() . $this->sys_error_db(
|
|
[
|
|
"insert one_mitra.$table | func insert_t_orderdetaildelivery " .
|
|
$this->db->error()["message"], "debug" => $this->db->last_query()
|
|
]
|
|
)
|
|
];
|
|
$this->db->trans_rollback();
|
|
return $err;
|
|
}
|
|
// }
|
|
|
|
return [
|
|
"status" => "OK",
|
|
"message" => "insert one_mitra.$table | func insert_t_orderdetaildelivery "
|
|
];
|
|
}
|
|
|
|
// 3. t_order
|
|
function insert_t_order($table, $arr_t_order)
|
|
{
|
|
$sqlQuery = "";
|
|
|
|
// for ($i = 0; $i < count($arr_t_order); $i++) {
|
|
|
|
$key = implode(',', array_keys($arr_t_order));
|
|
$value = "'" . implode("','", array_values($arr_t_order)) . "'";
|
|
|
|
$sqlQuery = "INSERT INTO one_mitra.$table ($key) VALUES ($value);";
|
|
$qry = $this->db->query($sqlQuery);
|
|
if (!$qry) {
|
|
$err = [
|
|
"status" => 'ERR',
|
|
"message" => $this->db->last_query() . $this->sys_error_db(
|
|
[
|
|
"insert one_mitra.$table | func insert_t_order " .
|
|
$this->db->error()["message"], "debug" => $this->db->last_query()
|
|
]
|
|
)
|
|
];
|
|
$this->db->trans_rollback();
|
|
return $err;
|
|
}
|
|
// }
|
|
|
|
//insert t_order
|
|
|
|
|
|
return [
|
|
"status" => "OK",
|
|
"message" => "insert one_mitra.$table | func insert_t_order "
|
|
];
|
|
}
|
|
|
|
// 4. t_orderdetail
|
|
function insert_t_orderdetail($table, $arr_t_orderdetail)
|
|
{
|
|
$sqlQuery = "";
|
|
|
|
// for ($i = 0; $i < count($arr_t_order); $i++) {
|
|
|
|
$key = implode(',', array_keys($arr_t_orderdetail));
|
|
$value = "'" . implode("','", array_values($arr_t_orderdetail)) . "'";
|
|
|
|
$sqlQuery = "INSERT INTO one_mitra.$table ($key) VALUES ($value);";
|
|
$qry = $this->db->query($sqlQuery);
|
|
if (!$qry) {
|
|
$err = [
|
|
"status" => 'ERR',
|
|
"message" => $this->db->last_query() . $this->sys_error_db(
|
|
[
|
|
"insert one_mitra.$table | func insert_t_orderdetail " .
|
|
$this->db->error()["message"], "debug" => $this->db->last_query()
|
|
]
|
|
)
|
|
];
|
|
$this->db->trans_rollback();
|
|
return $err;
|
|
}
|
|
// }
|
|
|
|
return [
|
|
"status" => "OK",
|
|
"message" => "insert one_mitra.$table | func insert_t_orderdetail "
|
|
];
|
|
}
|
|
|
|
// 5. t_orderdetailbahan
|
|
function insert_t_orderdetailbahan($table, $arr_t_orderdetailbahan)
|
|
{
|
|
$sqlQuery = "";
|
|
|
|
// for ($i = 0; $i < count($arr_t_order); $i++) {
|
|
|
|
$key = implode(',', array_keys($arr_t_orderdetailbahan));
|
|
$value = "'" . implode("','", array_values($arr_t_orderdetailbahan)) . "'";
|
|
|
|
$sqlQuery = "INSERT INTO one_mitra.$table ($key) VALUES ($value);";
|
|
$qry = $this->db->query($sqlQuery);
|
|
if (!$qry) {
|
|
$err = [
|
|
"status" => 'ERR',
|
|
"message" => $this->db->last_query() . $this->sys_error_db(
|
|
[
|
|
"insert one_mitra.$table | func insert_t_orderdetailbahan " .
|
|
$this->db->error()["message"], "debug" => $this->db->last_query()
|
|
]
|
|
)
|
|
];
|
|
$this->db->trans_rollback();
|
|
return $err;
|
|
}
|
|
// }
|
|
|
|
return [
|
|
"status" => "OK",
|
|
"message" => "insert one_mitra.$table | func insert_t_orderdetailbahan "
|
|
];
|
|
}
|
|
|
|
// 6. t_orderdetailsample
|
|
function insert_t_orderdetailsample($table, $arr_t_orderdetailsample)
|
|
{
|
|
$sqlQuery = "";
|
|
|
|
// for ($i = 0; $i < count($arr_t_order); $i++) {
|
|
|
|
$key = implode(',', array_keys($arr_t_orderdetailsample));
|
|
$value = "'" . implode("','", array_values($arr_t_orderdetailsample)) . "'";
|
|
|
|
$sqlQuery = "INSERT INTO one_mitra.$table ($key) VALUES ($value);";
|
|
$qry = $this->db->query($sqlQuery);
|
|
if (!$qry) {
|
|
$err = [
|
|
"status" => 'ERR',
|
|
"message" => $this->db->last_query() . $this->sys_error_db(
|
|
[
|
|
"insert one_mitra.$table | func insert_t_orderdetailsample " .
|
|
$this->db->error()["message"], "debug" => $this->db->last_query()
|
|
]
|
|
)
|
|
];
|
|
$this->db->trans_rollback();
|
|
return $err;
|
|
}
|
|
// }
|
|
|
|
return [
|
|
"status" => "OK",
|
|
"message" => "insert one_mitra.$table | func insert_t_orderdetailsample "
|
|
];
|
|
}
|
|
|
|
// 7. m_patient
|
|
function insert_m_patient($table, $arr_m_patient)
|
|
{
|
|
$sqlQuery = "";
|
|
|
|
// for ($i = 0; $i < count($arr_t_order); $i++) {
|
|
|
|
$key = implode(',', array_keys($arr_m_patient));
|
|
$value = "'" . implode("','", array_values($arr_m_patient)) . "'";
|
|
|
|
$sqlQuery = "INSERT INTO one_mitra.$table ($key) VALUES ($value);";
|
|
$qry = $this->db->query($sqlQuery);
|
|
if (!$qry) {
|
|
$err = [
|
|
"status" => 'ERR',
|
|
"message" => $this->db->last_query() . $this->sys_error_db(
|
|
[
|
|
"insert one_mitra.$table | func insert_m_patient " .
|
|
$this->db->error()["message"], "debug" => $this->db->last_query()
|
|
]
|
|
)
|
|
];
|
|
$this->db->trans_rollback();
|
|
return $err;
|
|
}
|
|
return [
|
|
"status" => "OK",
|
|
"message" => "insert one_mitra.$table | func insert_m_patient "
|
|
];
|
|
}
|
|
function update_m_patient($table, $dataPatient)
|
|
{
|
|
|
|
$sql = "UPDATE one_mitra.m_patient
|
|
SET M_PatientPrefix = ?,
|
|
M_PatientName = ?,
|
|
M_PatientSuffix = ?,
|
|
M_PatientDOB = ?,
|
|
M_PatientNIK = ?,
|
|
M_PatientNIP = ? ,
|
|
M_PatientIsNIK = ?,
|
|
M_PatientTitleID = ?,
|
|
M_PatientM_SexID = ?,
|
|
M_PatientHP = ? ,
|
|
M_PatientNoRM = ?,
|
|
M_PatientJabatan = ?,
|
|
M_PatientKedudukan = ?,
|
|
M_PatientLocation = ?,
|
|
M_PatientJob = ?,
|
|
M_PatientAddress = ?
|
|
WHERE M_PatientID = ?
|
|
AND M_PatientIsActive = 'Y'";
|
|
$query = $this->db->query($sql, [
|
|
$dataPatient['M_PatientPrefix'],
|
|
$dataPatient['M_PatientName'],
|
|
$dataPatient['M_PatientSuffix'],
|
|
$dataPatient['M_PatientDOB'],
|
|
$dataPatient['M_PatientNIK'],
|
|
$dataPatient['M_PatientNIP'],
|
|
$dataPatient['M_PatientIsNIK'],
|
|
$dataPatient['M_PatientTitleID'],
|
|
$dataPatient['M_PatientM_SexID'],
|
|
$dataPatient['M_PatientHP'],
|
|
$dataPatient['M_PatientNoRM'],
|
|
$dataPatient['M_PatientJabatan'],
|
|
$dataPatient['M_PatientKedudukan'],
|
|
$dataPatient['M_PatientLocation'],
|
|
$dataPatient['M_PatientJob'],
|
|
$dataPatient['M_PatientAddress'],
|
|
$dataPatient['M_PatientID']
|
|
]);
|
|
|
|
if (!$query) {
|
|
$err = [
|
|
"status" => 'ERR',
|
|
"message" => $this->db->last_query() . $this->sys_error_db(
|
|
[
|
|
"update one_mitra.$table | func update_m_patient " .
|
|
$this->db->error()["message"], "debug" => $this->db->last_query()
|
|
]
|
|
)
|
|
];
|
|
$this->db->trans_rollback();
|
|
return $err;
|
|
}
|
|
return [
|
|
"status" => "OK",
|
|
"message" => "insert one_mitra.$table | func insert_m_patient "
|
|
];
|
|
}
|
|
|
|
function insert_t_orderdetailpacket($table, $arr_packetID)
|
|
{
|
|
$sqlQuery = "";
|
|
|
|
// for ($i = 0; $i < count($arr_t_order); $i++) {
|
|
|
|
$key = implode(',', array_keys($arr_packetID));
|
|
$value = "'" . implode("','", array_values($arr_packetID)) . "'";
|
|
|
|
$sqlQuery = "INSERT INTO one_mitra.$table ($key) VALUES ($value);";
|
|
$qry = $this->db->query($sqlQuery);
|
|
if (!$qry) {
|
|
$err = [
|
|
"status" => 'ERR',
|
|
"message" => $this->db->last_query() . $this->sys_error_db(
|
|
[
|
|
"insert one_mitra.$table | func insert_t_orderdetailpacket " .
|
|
$this->db->error()["message"], "debug" => $this->db->last_query()
|
|
]
|
|
)
|
|
];
|
|
$this->db->trans_rollback();
|
|
return $err;
|
|
}
|
|
// }
|
|
|
|
return [
|
|
"status" => "OK",
|
|
"message" => "insert one_mitra.$table | func insert_m_patient "
|
|
];
|
|
}
|
|
|
|
function downloadOrder($debug = "")
|
|
{
|
|
try {
|
|
$prm = $this->sys_input;
|
|
$getBranch = $this->getBranch();
|
|
if ($getBranch['status'] = false) {
|
|
$this->sys_error($getBranch['message']);
|
|
exit;
|
|
}
|
|
$limit = 20;
|
|
if (isset($prm['limit'])) {
|
|
$limit = trim($prm['limit']);
|
|
}
|
|
$respUpdatePatient = $this->updatePatientQrConfirm();
|
|
|
|
// print_r($respUpdatePatient);
|
|
// exit;
|
|
// print_r($getBranch);
|
|
// exit;
|
|
// $branchId = $prm['branchId'];
|
|
// $branchCode = $prm['branchCode'];
|
|
$branchId = $getBranch['branchId'];
|
|
$branchCode = $getBranch['branchCode'];
|
|
$data = array(
|
|
'branchId' => $branchId,
|
|
'branchCode' => $branchCode,
|
|
'limit' => $limit
|
|
);
|
|
// print_r($data);
|
|
// exit;
|
|
|
|
$getIPRegionalAddress = $this->getRegionalIPAddress();
|
|
// $resp = $this->post("http://$getIPRegionalAddress/one-api/app_doctor/DownloadOrderPatient/downloadSaran", json_encode($data));
|
|
|
|
$resp = $this->post("http://$getIPRegionalAddress/one-api/one_mitra/DownloadOrder/reg_download/", json_encode($data));
|
|
|
|
// KLU SUDAH FIX PAKE GZUNCOMPRESS
|
|
// $respUnc = gzuncompress($resp);
|
|
$respUnc = gzuncompress($resp);
|
|
// $response = json_decode($resp, true);
|
|
|
|
$response = json_decode($respUnc, true);
|
|
|
|
$dataOrder = $response['data'];
|
|
// $dataOrder = $response->data;
|
|
|
|
// print_r($resp);
|
|
// exit;
|
|
|
|
if ($response["status"] != 'OK') {
|
|
// if ($response->status != 'OK') {
|
|
$response["update_patient"] = $respUpdatePatient;
|
|
$this->sys_error($response);
|
|
exit;
|
|
}
|
|
|
|
$this->db->trans_begin();
|
|
if (count($dataOrder) > 0) {
|
|
// print_r($dataOrder[0]['t_orderdelivery'][0]);
|
|
// exit;
|
|
|
|
// 1. t_orderdelivery
|
|
if (count($dataOrder[0]['t_orderdelivery']) > 0) {
|
|
for ($i = 0; $i < count($dataOrder[0]['t_orderdelivery']); $i++) {
|
|
$id = $dataOrder[0]['t_orderdelivery'][$i]['T_OrderDeliveryID'];
|
|
$sqlCek = "SELECT EXISTS(SELECT T_OrderDeliveryID
|
|
FROM one_mitra.t_orderdelivery
|
|
WHERE T_OrderDeliveryID = $id ) as result";
|
|
|
|
$qryCek = $this->db->query($sqlCek);
|
|
if (!$qryCek) {
|
|
$err = [
|
|
"select one_mitra.t_orderdelivery | func insert_t_orderdelivery " .
|
|
$this->db->error()["message"], "debug" => $this->db->last_query()
|
|
];
|
|
$this->db->trans_rollback();
|
|
$this->sys_error(
|
|
$err
|
|
);
|
|
exit;
|
|
}
|
|
$rows_cek = $qryCek->row_array();
|
|
// klu sudah ada data dicontinue
|
|
if (intval($rows_cek['result']) == 1) {
|
|
continue;
|
|
}
|
|
|
|
$insert_t_orderdelivery = $this->insert_t_orderdelivery('t_orderdelivery', $dataOrder[0]['t_orderdelivery'][$i]);
|
|
// print_r($insert_t_orderdelivery);
|
|
if ($insert_t_orderdelivery['status'] != 'OK') {
|
|
$this->sys_error($insert_t_orderdelivery['message']);
|
|
exit;
|
|
}
|
|
}
|
|
}
|
|
|
|
// 2. t_orderdetaildelivery
|
|
if (count($dataOrder[0]['t_orderdetaildelivery']) > 0) {
|
|
for ($i = 0; $i < count($dataOrder[0]['t_orderdetaildelivery']); $i++) {
|
|
$id = $dataOrder[0]['t_orderdetaildelivery'][$i]['T_OrderDetailDeliveryID'];
|
|
// $id = $dataOrder[0]['t_orderdetaildelivery'][$i]['T_OrderDetailDeliveryT_OrderDeliveryID'];
|
|
$sqlCek = "SELECT EXISTS(SELECT T_OrderDetailDeliveryID
|
|
FROM one_mitra.t_orderdetaildelivery
|
|
WHERE T_OrderDetailDeliveryID = $id ) as result";
|
|
|
|
$qryCek = $this->db->query($sqlCek);
|
|
if (!$qryCek) {
|
|
$err = [
|
|
"select one_mitra.t_orderdetaildelivery | func insert_t_orderdetaildelivery " .
|
|
$this->db->error()["message"], "debug" => $this->db->last_query()
|
|
];
|
|
$this->db->trans_rollback();
|
|
$this->sys_error(
|
|
$err
|
|
);
|
|
exit;
|
|
}
|
|
$rows_cek = $qryCek->row_array();
|
|
// klu sudah ada data dicontinue
|
|
if (intval($rows_cek['result']) == 1) {
|
|
continue;
|
|
}
|
|
|
|
$insert_t_orderdetaildelivery = $this->insert_t_orderdetaildelivery('t_orderdetaildelivery', $dataOrder[0]['t_orderdetaildelivery'][$i]);
|
|
// print_r($insert_t_orderdetaildelivery);
|
|
if ($insert_t_orderdetaildelivery['status'] != 'OK') {
|
|
$this->sys_error($insert_t_orderdetaildelivery['message']);
|
|
exit;
|
|
}
|
|
}
|
|
}
|
|
|
|
// 3. t_order
|
|
if (count($dataOrder[0]['t_order']) > 0) {
|
|
for ($i = 0; $i < count($dataOrder[0]['t_order']); $i++) {
|
|
$id = $dataOrder[0]['t_order'][$i]['T_OrderID'];
|
|
$sqlCek = "SELECT EXISTS(SELECT T_OrderID
|
|
FROM one_mitra.t_order
|
|
WHERE T_OrderID = $id ) as result";
|
|
|
|
$qryCek = $this->db->query($sqlCek);
|
|
if (!$qryCek) {
|
|
$err = [
|
|
"select one_mitra.t_order | func insert_t_order " .
|
|
$this->db->error()["message"], "debug" => $this->db->last_query()
|
|
];
|
|
|
|
$this->db->trans_rollback();
|
|
$this->sys_error($err);
|
|
exit;
|
|
}
|
|
$rows_cek = $qryCek->row_array();
|
|
// klu sudah ada data dicontinue
|
|
if (intval($rows_cek['result']) == 1) {
|
|
continue;
|
|
}
|
|
|
|
$insert_t_order = $this->insert_t_order('t_order', $dataOrder[0]['t_order'][$i]);
|
|
// print_r($insert_t_order);
|
|
if ($insert_t_order['status'] != 'OK') {
|
|
$this->sys_error($insert_t_order['message']);
|
|
exit;
|
|
}
|
|
}
|
|
}
|
|
|
|
// 4. t_orderdetail
|
|
if (count($dataOrder[0]['t_orderdetail']) > 0) {
|
|
for ($i = 0; $i < count($dataOrder[0]['t_orderdetail']); $i++) {
|
|
$id = $dataOrder[0]['t_orderdetail'][$i]['T_OrderDetailID'];
|
|
// $id = $dataOrder[0]['t_orderdetail'][$i]['T_OrderDetailOrderID'];
|
|
$sqlCek = "SELECT EXISTS(SELECT T_OrderDetailOrderID
|
|
FROM one_mitra.t_orderdetail
|
|
WHERE T_OrderDetailID = $id ) as result";
|
|
|
|
$qryCek = $this->db->query($sqlCek);
|
|
if (!$qryCek) {
|
|
$err = [
|
|
"select one_mitra.t_orderdetail | func insert_t_orderdetail " .
|
|
$this->db->error()["message"], "debug" => $this->db->last_query()
|
|
];
|
|
$this->db->trans_rollback();
|
|
$this->sys_error(
|
|
$err
|
|
);
|
|
exit;
|
|
}
|
|
$rows_cek = $qryCek->row_array();
|
|
// klu sudah ada data dicontinue
|
|
if (intval($rows_cek['result']) == 1) {
|
|
continue;
|
|
}
|
|
|
|
$insert_t_orderdetail = $this->insert_t_orderdetail('t_orderdetail', $dataOrder[0]['t_orderdetail'][$i]);
|
|
// print_r($insert_t_orderdetail);
|
|
if ($insert_t_orderdetail['status'] != 'OK') {
|
|
$this->sys_error($insert_t_orderdetail['message']);
|
|
exit;
|
|
}
|
|
}
|
|
}
|
|
|
|
// 5. t_orderdetailbahan
|
|
if (count($dataOrder[0]['t_orderdetailbahan']) > 0) {
|
|
for ($i = 0; $i < count($dataOrder[0]['t_orderdetailbahan']); $i++) {
|
|
// $id = $dataOrder[0]['t_orderdetailbahan'][$i]['T_OrderDetailBahanT_OrderID'];
|
|
$id = $dataOrder[0]['t_orderdetailbahan'][$i]['T_OrderDetailBahanID'];
|
|
$sqlCek = "SELECT EXISTS(SELECT T_OrderDetailBahanT_OrderID
|
|
FROM one_mitra.t_orderdetailbahan
|
|
WHERE T_OrderDetailBahanID = $id ) as result";
|
|
|
|
$qryCek = $this->db->query($sqlCek);
|
|
if (!$qryCek) {
|
|
$err = [
|
|
"select one_mitra.t_orderdetailbahan | func insert_t_orderdetailbahan " .
|
|
$this->db->error()["message"], "debug" => $this->db->last_query()
|
|
];
|
|
$this->db->trans_rollback();
|
|
$this->sys_error(
|
|
$err
|
|
);
|
|
exit;
|
|
}
|
|
$rows_cek = $qryCek->row_array();
|
|
// klu sudah ada data dicontinue
|
|
if (intval($rows_cek['result']) == 1) {
|
|
continue;
|
|
}
|
|
|
|
$insert_t_orderdetailbahan = $this->insert_t_orderdetailbahan('t_orderdetailbahan', $dataOrder[0]['t_orderdetailbahan'][$i]);
|
|
// print_r($insert_t_orderdetailbahan);
|
|
if ($insert_t_orderdetailbahan['status'] != 'OK') {
|
|
$this->sys_error($insert_t_orderdetailbahan['message']);
|
|
exit;
|
|
}
|
|
}
|
|
}
|
|
|
|
// 6. t_orderdetailsample
|
|
if (count($dataOrder[0]['t_orderdetailsample']) > 0) {
|
|
for ($i = 0; $i < count($dataOrder[0]['t_orderdetailsample']); $i++) {
|
|
// $id = $dataOrder[0]['t_orderdetailsample'][$i]['T_OrderDetailSampleT_OrderID'];
|
|
$id = $dataOrder[0]['t_orderdetailsample'][$i]['T_OrderDetailSampleID'];
|
|
$sqlCek = "SELECT EXISTS(SELECT T_OrderDetailSampleT_OrderID
|
|
FROM one_mitra.t_orderdetailsample
|
|
WHERE T_OrderDetailSampleID = $id ) as result";
|
|
|
|
$qryCek = $this->db->query($sqlCek);
|
|
if (!$qryCek) {
|
|
$err = [
|
|
"select one_mitra.t_orderdetailsample | func insert_t_orderdetailsample " .
|
|
$this->db->error()["message"], "debug" => $this->db->last_query()
|
|
];
|
|
$this->db->trans_rollback();
|
|
$this->sys_error(
|
|
$err
|
|
);
|
|
exit;
|
|
}
|
|
$rows_cek = $qryCek->row_array();
|
|
// klu sudah ada data dicontinue
|
|
if (intval($rows_cek['result']) == 1) {
|
|
continue;
|
|
}
|
|
|
|
$insert_t_orderdetailsample = $this->insert_t_orderdetailsample('t_orderdetailsample', $dataOrder[0]['t_orderdetailsample'][$i]);
|
|
// print_r($insert_t_orderdetailsample);
|
|
if ($insert_t_orderdetailsample['status'] != 'OK') {
|
|
$this->sys_error($insert_t_orderdetailsample['message']);
|
|
exit;
|
|
}
|
|
}
|
|
}
|
|
|
|
// 7. m_patient
|
|
if (count($dataOrder[0]['m_patient']) > 0) {
|
|
for ($i = 0; $i < count($dataOrder[0]['m_patient']); $i++) {
|
|
$id = $dataOrder[0]['m_patient'][$i]['M_PatientID'];
|
|
$sqlCek = "SELECT EXISTS(SELECT M_PatientID
|
|
FROM one_mitra.m_patient
|
|
WHERE M_PatientID = $id ) as result";
|
|
|
|
$qryCek = $this->db->query($sqlCek);
|
|
if (!$qryCek) {
|
|
$err = [
|
|
"select one_mitra.m_patient | func insert_m_patient " .
|
|
$this->db->error()["message"], "debug" => $this->db->last_query()
|
|
];
|
|
$this->db->trans_rollback();
|
|
$this->sys_error(
|
|
$err
|
|
);
|
|
exit;
|
|
}
|
|
$rows_cek = $qryCek->row_array();
|
|
// klu sudah ada data dicontinue
|
|
if (intval($rows_cek['result']) == 1) {
|
|
//update m_patient
|
|
$update_m_patient = $this->update_m_patient('m_patient', $dataOrder[0]['m_patient'][$i]);
|
|
// print_r($update_m_patient);
|
|
if ($update_m_patient['status'] != 'OK') {
|
|
$this->sys_error($update_m_patient['message']);
|
|
exit;
|
|
}
|
|
} else {
|
|
$insert_m_patient = $this->insert_m_patient('m_patient', $dataOrder[0]['m_patient'][$i]);
|
|
// print_r($insert_m_patient);
|
|
if ($insert_m_patient['status'] != 'OK') {
|
|
$this->sys_error($insert_m_patient['message']);
|
|
exit;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
// 8. t_orderdetailpacket
|
|
if (count($dataOrder[0]['t_orderdetailpacket']) > 0) {
|
|
for ($i = 0; $i < count($dataOrder[0]['t_orderdetailpacket']); $i++) {
|
|
$id = $dataOrder[0]['t_orderdetailpacket'][$i]['T_OrderDetailPacketID'];
|
|
$sqlCek = "SELECT EXISTS(SELECT T_OrderDetailPacketID
|
|
FROM one_mitra.t_orderdetailpacket
|
|
WHERE T_OrderDetailPacketID = $id ) as result";
|
|
|
|
$qryCek = $this->db->query($sqlCek);
|
|
if (!$qryCek) {
|
|
$err = [
|
|
"select one_mitra.t_orderdetailpacket | func insert_t_orderdetailpacket " .
|
|
$this->db->error()["message"], "debug" => $this->db->last_query()
|
|
];
|
|
$this->db->trans_rollback();
|
|
$this->sys_error(
|
|
$err
|
|
);
|
|
exit;
|
|
}
|
|
$rows_cek = $qryCek->row_array();
|
|
// klu sudah ada data dicontinue
|
|
if (intval($rows_cek['result']) == 1) {
|
|
continue;
|
|
}
|
|
|
|
$insert_m_patient = $this->insert_t_orderdetailpacket('t_orderdetailpacket', $dataOrder[0]['t_orderdetailpacket'][$i]);
|
|
// print_r($insert_m_patient);
|
|
if ($insert_m_patient['status'] != 'OK') {
|
|
$this->sys_error($insert_m_patient['message']);
|
|
exit;
|
|
}
|
|
}
|
|
}
|
|
|
|
// INSERT FUTURE ORDER
|
|
// $insert_future_order = $this->insert_future_order($dataOrder[0]['t_order'], $dataOrder[0]['t_orderdetail'], $dataOrder[0]['t_orderdetailpacket']);
|
|
}
|
|
|
|
|
|
|
|
$paramLog = array(
|
|
"branchId" => $branchId,
|
|
"data" => $dataOrder
|
|
);
|
|
|
|
// print_r(json_encode($paramLog));
|
|
// exit;
|
|
|
|
$z_param = gzcompress(json_encode($paramLog));
|
|
// $respLog = $this->post("http://$getIPRegionalAddress/one-api/one_mitra/DownloadOrder/reg_update_is_download", $z_param);
|
|
|
|
$respLog = $this->post("http://$getIPRegionalAddress/one-api/one_mitra/DownloadOrder/reg_update_is_download", $z_param);
|
|
$this->db->trans_commit();
|
|
|
|
$respLog = (array) json_decode($respLog, true);
|
|
$respLog['update_patient'] = $respUpdatePatient;
|
|
|
|
// $respUpdatePatient = $this->updatePatientQrConfirm();
|
|
// $respLog['update_patient_qr_confirm'] = $respUpdatePatient;
|
|
// print_r($respUpdatePatient);
|
|
// exit;
|
|
|
|
if ($respLog['status'] != 'OK') {
|
|
$this->sys_error($respLog);
|
|
} else {
|
|
$this->sys_ok($respLog);
|
|
}
|
|
} catch (Exception $exc) {
|
|
$message = $exc->getMessage();
|
|
$this->sys_error($message);
|
|
}
|
|
}
|
|
function get_param_z()
|
|
{
|
|
$body_z = file_get_contents("php://input");
|
|
$body = gzuncompress($body_z);
|
|
return json_decode($body, true);
|
|
}
|
|
|
|
function reply_gz($resp)
|
|
{
|
|
echo gzcompress(json_encode($resp));
|
|
}
|
|
function updatePatientQrConfirm()
|
|
{
|
|
try {
|
|
|
|
$getBranch = $this->getBranch();
|
|
if ($getBranch['status'] = false) {
|
|
$this->sys_error($getBranch['message']);
|
|
exit;
|
|
}
|
|
$branchId = $getBranch['branchId'];
|
|
$branchCode = $getBranch['branchCode'];
|
|
$getIPRegionalAddress = $this->getRegionalIPAddress();
|
|
$data = array(
|
|
'branchId' => $branchId,
|
|
'branchCode' => $branchCode,
|
|
);
|
|
$resp = $this->post("http://$getIPRegionalAddress/one-api/one_mitra/DownloadOrder/getUpdatePatient/", json_encode($data));
|
|
|
|
|
|
// $respUnc = gzuncompress($resp);
|
|
$respUnc = gzuncompress($resp);
|
|
// $response = json_decode($resp, true);
|
|
|
|
$response = json_decode($respUnc, true);
|
|
$arrDeliveryID = array();
|
|
$dataPatient = $response['data'];
|
|
if ($response['status'] == 'OK') {
|
|
for ($i = 0; $i < count($dataPatient); $i++) {
|
|
//get data patient before
|
|
$sqlCek = "SELECT * FROM one_mitra.m_patient
|
|
WHERE M_PatientID = ?";
|
|
$qryCek = $this->db->query($sqlCek, [$dataPatient[$i]['M_PatientID']]);
|
|
if (!$qryCek) {
|
|
$err = [
|
|
"ERR funct Updatepatient cek data patient| " .
|
|
$this->db->error()["message"], "debug" => $this->db->last_query()
|
|
];
|
|
// $this->db->trans_rollback();
|
|
$this->sys_error(
|
|
$err
|
|
);
|
|
exit;
|
|
}
|
|
$dataPatientBefore = $qryCek->result_array()[0];
|
|
if (
|
|
$dataPatient[$i]['M_PatientHP'] != $dataPatientBefore['M_PatientHP']
|
|
&& $dataPatient[$i]['T_OrderIsQRCode'] == 'Y'
|
|
) {
|
|
//get future order
|
|
$sqlCek = "SELECT * FROM one_mitra.t_order
|
|
WHERE T_OrderID = ?";
|
|
$qryCek = $this->db->query($sqlCek, [$dataPatient[$i]['T_OrderID']]);
|
|
if (!$qryCek) {
|
|
$err = [
|
|
"ERR funct Updatepatient cek t order| " .
|
|
$this->db->error()["message"], "debug" => $this->db->last_query()
|
|
];
|
|
// $this->db->trans_rollback();
|
|
$this->sys_error(
|
|
$err
|
|
);
|
|
exit;
|
|
}
|
|
$dataFutureOrder = $qryCek->result_array()[0];
|
|
if ($dataFutureOrder['T_OrderFutureOrderID'] != null) {
|
|
$hp = trim($dataPatient[$i]['M_PatientHP']);
|
|
if ($hp != "0" && $hp != "-" && !empty($hp)) {
|
|
$sqlCek = "SELECT * FROM future_qrcode_confirm
|
|
WHERE FutureQrCodeConfirmFutureOrderID = ?
|
|
AND FutureQrCodeConfirmIsActive = 'Y' ";
|
|
$qryCek = $this->db->query($sqlCek, [$dataFutureOrder['T_OrderFutureOrderID']]);
|
|
if (!$qryCek) {
|
|
$err = [
|
|
"ERR funct Updatepatient cek t order| " .
|
|
$this->db->error()["message"], "debug" => $this->db->last_query()
|
|
];
|
|
// $this->db->trans_rollback();
|
|
$this->sys_error(
|
|
$err
|
|
);
|
|
exit;
|
|
}
|
|
$futureQrCodeCek = $qryCek->result_array();
|
|
if (count($futureQrCodeCek) > 0) {
|
|
|
|
//update sendqrcode
|
|
$sql = "UPDATE future_qrcode_confirm
|
|
SET FutureQrCodeConfirmPhone = ?
|
|
,FutureQrCodeConfirmIsStatus = 'R'
|
|
WHERE FutureQrCodeConfirmFutureOrderID = ?
|
|
AND FutureQrCodeConfirmIsActive = 'Y'";
|
|
$qry = $this->db->query($sql, [$dataPatient[$i]['M_PatientHP'], $dataFutureOrder['T_OrderFutureOrderID']]);
|
|
if (!$qry) {
|
|
$err = [
|
|
"ERR funct Updatepatient cek t order| " .
|
|
$this->db->error()["message"], "debug" => $this->db->last_query()
|
|
];
|
|
// $this->db->trans_rollback();
|
|
$this->sys_error(
|
|
$err
|
|
);
|
|
exit;
|
|
}
|
|
} else {
|
|
$sql_insert = "INSERT INTO future_qrcode_confirm
|
|
(FutureQrCodeConfirmFutureOrderID,
|
|
FutureQrCodeConfirmPhone
|
|
)VALUES
|
|
(?,?)";
|
|
$qry_insert = $this->db->query($sql_insert, [
|
|
$dataFutureOrder['T_OrderFutureOrderID'],
|
|
$hp
|
|
]);
|
|
if (!$qry_insert) {
|
|
$message = $this->db->error();
|
|
$err = [
|
|
'msg' => $message,
|
|
'qry' => $this->db->last_query(),
|
|
];
|
|
$this->sys_error($err);
|
|
|
|
$this->db->trans_rollback();
|
|
exit;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
//update data patient
|
|
$sql = "UPDATE one_mitra.m_patient
|
|
SET M_PatientPrefix = ?,
|
|
M_PatientName = ?,
|
|
M_PatientSuffix = ?,
|
|
M_PatientDOB = ?,
|
|
M_PatientNIK = ?,
|
|
M_PatientNIP = ? ,
|
|
M_PatientIsNIK = ?,
|
|
M_PatientTitleID = ?,
|
|
M_PatientM_SexID = ?,
|
|
M_PatientHP = ? ,
|
|
M_PatientNoRM = ?,
|
|
M_PatientJabatan = ?,
|
|
M_PatientKedudukan = ?,
|
|
M_PatientLocation = ?,
|
|
M_PatientJob = ?,
|
|
M_PatientAddress = ?
|
|
WHERE M_PatientID = ?
|
|
AND M_PatientIsActive = 'Y'";
|
|
$query = $this->db->query($sql, [
|
|
$dataPatient[$i]['M_PatientPrefix'],
|
|
$dataPatient[$i]['M_PatientName'],
|
|
$dataPatient[$i]['M_PatientSuffix'],
|
|
$dataPatient[$i]['M_PatientDOB'],
|
|
$dataPatient[$i]['M_PatientNIK'],
|
|
$dataPatient[$i]['M_PatientNIP'],
|
|
$dataPatient[$i]['M_PatientIsNIK'],
|
|
$dataPatient[$i]['M_PatientTitleID'],
|
|
$dataPatient[$i]['M_PatientM_SexID'],
|
|
$dataPatient[$i]['M_PatientHP'],
|
|
$dataPatient[$i]['M_PatientNoRM'],
|
|
$dataPatient[$i]['M_PatientJabatan'],
|
|
$dataPatient[$i]['M_PatientKedudukan'],
|
|
$dataPatient[$i]['M_PatientLocation'],
|
|
$dataPatient[$i]['M_PatientJob'],
|
|
$dataPatient[$i]['M_PatientAddress'],
|
|
$dataPatient[$i]['M_PatientID']
|
|
]);
|
|
if (!$query) {
|
|
$err = [
|
|
"ERR funct Updatepatient, update patient| " .
|
|
$this->db->error()["message"], "debug" => $this->db->last_query()
|
|
];
|
|
// $this->db->trans_rollback();
|
|
$this->sys_error(
|
|
$err
|
|
);
|
|
exit;
|
|
}
|
|
$arrDeliveryID[] = $dataPatient[$i]['T_OrderDeliveryID'];
|
|
}
|
|
}
|
|
$dataUpdate = ["arrDeliveryID" => $arrDeliveryID];
|
|
|
|
$resp = $this->post("http://$getIPRegionalAddress/one-api/one_mitra/DownloadOrder/updateIsDownloadedDate/", json_encode($dataUpdate));
|
|
|
|
|
|
// $respUnc = gzuncompress($resp);
|
|
$respUnc = gzuncompress($resp);
|
|
// $response = json_decode($resp, true);
|
|
|
|
$responseUpdate = json_decode($respUnc, true);
|
|
// $this->sys_ok($responseUpdate);
|
|
if ($responseUpdate['status'] == "OK") {
|
|
return $responseUpdate['data'];
|
|
// $this->sys_ok($responseUpdate);
|
|
} else {
|
|
$this->sys_error(
|
|
$responseUpdate
|
|
);
|
|
exit;
|
|
}
|
|
} catch (Exception $exc) {
|
|
$message = $exc->getMessage();
|
|
$this->sys_error($message);
|
|
}
|
|
}
|
|
}
|