db_regional = $this->load->database("regional", true); } function index() { echo "Api: Download Order Mitra DEVKEDUNGDORORAYA"; } function reply($resp) { echo json_encode($resp); } function reply_gz($resp, $debug = "") { if ($debug != "") { echo json_encode($resp); } else { echo gzcompress(json_encode($resp)); } } function get_param() { $body = file_get_contents("php://input"); return json_decode($body, true); } function get_param_z() { $body_z = file_get_contents("php://input"); $body = gzuncompress($body_z); return json_decode($body, true); } // t_orderdelivery function getData_t_orderdelivery($wherein_T_OrderDeliveryID) { $sql = "SELECT * FROM one_mitra.t_orderdelivery WHERE T_OrderDeliveryIsDownloaded = 'N' AND T_OrderDeliveryStatus = 'S' AND T_OrderDeliveryIsActive = 'Y' AND T_OrderDeliveryID IN ($wherein_T_OrderDeliveryID)"; $qry = $this->db_regional->query($sql); if (!$qry) { $response = ["status" => "ERR", "message" => "select t_orderdelivery for get data | func getData_t_orderdelivery " . $this->db_regional->error()["message"], "debug" => $this->db_regional->last_query()]; // $this->reply_gz($response); $this->reply($response); exit; } $rows_fields = $qry->result_array(); if (count($rows_fields) > 0) { return $rows_fields; } return $rows_fields; // print_r($rows_fields); } // t_orderdetaildelivery function getData_t_orderdetaildelivery($wherein_T_OrderDetailDeliveryID) { $sql = "SELECT * FROM one_mitra.t_orderdetaildelivery WHERE T_OrderDetailDeliveryIsActive = 'Y' AND T_OrderDetailDeliveryID IN ($wherein_T_OrderDetailDeliveryID)"; $qry = $this->db_regional->query($sql); if (!$qry) { $response = ["status" => "ERR", "message" => "select t_orderdetaildelivery for get data | func getData_t_orderdetaildelivery " . $this->db_regional->error()["message"], "debug" => $this->db_regional->last_query()]; // $this->reply_gz($response); $this->reply($response); exit; } $rows_fields = $qry->result_array(); if (count($rows_fields) > 0) { return $rows_fields; } return $rows_fields; } // t_order function getData_t_order($wherein_T_OrderID) { $sql = "SELECT * FROM one_mitra.t_order WHERE T_OrderIsActive = 'Y' AND T_OrderID IN ($wherein_T_OrderID)"; $qry = $this->db_regional->query($sql); if (!$qry) { $response = ["status" => "ERR", "message" => "select t_order for get data | func getData_t_order " . $this->db_regional->error()["message"], "debug" => $this->db_regional->last_query()]; // $this->reply_gz($response); $this->reply($response); exit; } $rows_fields = $qry->result_array(); if (count($rows_fields) > 0) { return $rows_fields; } return $rows_fields; } // t_orderdetail function getData_t_orderdetail($wherein_T_OrderDetailID) { $sql = "SELECT * FROM one_mitra.t_orderdetail WHERE T_OrderDetailIsActive = 'Y' AND T_OrderDetailID IN ($wherein_T_OrderDetailID)"; $qry = $this->db_regional->query($sql); if (!$qry) { $response = ["status" => "ERR", "message" => "select t_orderdetail for get data | func getData_t_orderdetail " . $this->db_regional->error()["message"], "debug" => $this->db_regional->last_query()]; // $this->reply_gz($response); $this->reply($response); exit; } $rows_fields = $qry->result_array(); if (count($rows_fields) > 0) { return $rows_fields; } return $rows_fields; } // t_orderdetailbahan function getData_t_orderdetailbahan($wherein_T_OrderDetailBahanID) { $sql = "SELECT * FROM one_mitra.t_orderdetailbahan WHERE T_OrderDetailBahanIsActive = 'Y' AND T_OrderDetailBahanID IN ($wherein_T_OrderDetailBahanID)"; $qry = $this->db_regional->query($sql); if (!$qry) { $response = ["status" => "ERR", "message" => "select t_orderdetailbahan for get data | func getData_t_orderdetailbahan " . $this->db_regional->error()["message"], "debug" => $this->db_regional->last_query()]; // $this->reply_gz($response); $this->reply($response); exit; } $rows_fields = $qry->result_array(); if (count($rows_fields) > 0) { return $rows_fields; } return $rows_fields; } // t_orderdetailsample function getData_t_orderdetailsample($wherein_T_OrderDetailSampleID) { $sql = "SELECT * FROM one_mitra.t_orderdetailsample WHERE T_OrderDetailSampleIsActive = 'Y' AND T_OrderDetailSampleID IN ($wherein_T_OrderDetailSampleID)"; $qry = $this->db_regional->query($sql); if (!$qry) { $response = ["status" => "ERR", "message" => "select t_orderdetailsample for get data | func getData_t_orderdetailsample " . $this->db_regional->error()["message"], "debug" => $this->db_regional->last_query()]; // $this->reply_gz($response); $this->reply($response); exit; } $rows_fields = $qry->result_array(); if (count($rows_fields) > 0) { return $rows_fields; } return $rows_fields; } // m_patient function getData_m_patient($wherein_M_PatientID) { $sql = "SELECT * FROM one_mitra.m_patient WHERE M_PatientIsActive = 'Y' AND M_PatientID IN ($wherein_M_PatientID)"; $qry = $this->db_regional->query($sql); if (!$qry) { $response = ["status" => "ERR", "message" => "select t_orderdetailsample for get data | func getData_t_orderdetailsample " . $this->db_regional->error()["message"], "debug" => $this->db_regional->last_query()]; // $this->reply_gz($response); $this->reply($response); exit; } $rows_fields = $qry->result_array(); if (count($rows_fields) > 0) { return $rows_fields; } return $rows_fields; } function getData_t_orderdetailpacket($packetID) { $sql = "SELECT * FROM one_mitra.t_orderdetailpacket WHERE T_OrderDetailPacketID in ($packetID) AND T_OrderDetailPacketIsActive = 'Y'"; $qry = $this->db_regional->query($sql); if (!$qry) { $response = ["status" => "ERR", "message" => "select t_orderdetailpacket for get data | func getData_t_orderdetailpacket " . $this->db_regional->error()["message"], "debug" => $this->db_regional->last_query()]; // $this->reply_gz($response); $this->reply($response); exit; } $rows_fields = $qry->result_array(); if (count($rows_fields) > 0) { return $rows_fields; } return $rows_fields; } function reg_download_old($debug = "") { try { $prm = $this->get_param(); $limit = 2; if (isset($prm['limit'])) { $limit = trim($prm['limit']); } $branchId = ($debug != "") ? 1 : $prm['branchId']; // $branchId = 1; $branchCode = $prm['branchCode']; $sql_pivot = "SELECT T_OrderDeliveryNumber, T_OrderDeliveryID from one_mitra.t_orderdelivery join one_mitra.t_orderdetaildelivery ON T_OrderDetailDeliveryT_OrderDeliveryID = T_OrderDeliveryID AND T_OrderDetailDeliveryIsActive = 'Y' AND T_OrderDeliveryIsActive = 'Y' AND T_OrderDeliveryIsDownloaded = 'N' AND T_OrderDeliveryStatus = 'S' AND T_OrderDeliveryDestination = $branchId"; // LIMIT $limit "; $qry_pivot = $this->db_regional->query($sql_pivot); if (!$qry_pivot) { $response = ["status" => "ERR", "message" => "select t_orderdelivery | func reg_download " . $this->db_regional->error()["message"], "debug" => $this->db_regional->last_query()]; // $this->reply_gz($response); $this->reply($response); exit; } $rows_pivot = $qry_pivot->result_array(); // print_r($rows_pivot); // exit; // T_Order $sql_pivot_t_order = "SELECT T_OrderID from one_mitra.t_orderdelivery join one_mitra.t_orderdetaildelivery ON T_OrderDetailDeliveryT_OrderDeliveryID = T_OrderDeliveryID AND T_OrderDetailDeliveryIsActive = 'Y' AND T_OrderDeliveryIsActive = 'Y' AND T_OrderDeliveryIsDownloaded = 'N' AND T_OrderDeliveryStatus = 'S' AND T_OrderDeliveryDestination = $branchId join one_mitra.t_order ON T_OrderDetailDeliveryT_OrderID = T_OrderID AND T_OrderIsActive = 'Y'"; $qry_pivot_t_order = $this->db_regional->query($sql_pivot_t_order); if (!$qry_pivot_t_order) { $response = ["status" => "ERR", "message" => "select t_orderdelivery | func reg_download " . $this->db_regional->error()["message"], "debug" => $this->db_regional->last_query()]; // $this->reply_gz($response); $this->reply($response); exit; } $rows_pivot_t_order = $qry_pivot_t_order->result_array(); // print_r($rows_pivot_t_order); // exit; $string_wherein_T_OrderDeliveryID = ""; $string_wherein_T_OrderID = ""; $T_OrderDeliveryID_arr = []; $T_OrderID_arr = []; if (count($rows_pivot) > 0) { foreach ($rows_pivot as $key => $vx) { $T_OrderDeliveryID_arr[] = intval($vx['T_OrderDeliveryID']); // $T_OrderID_arr[] = intval($vx['T_OrderID']); } $string_wherein_T_OrderDeliveryID = implode(",", $T_OrderDeliveryID_arr); // $string_wherein_T_OrderID = implode(",", $T_OrderID_arr); } // T_Order if (count($rows_pivot_t_order) > 0) { foreach ($rows_pivot_t_order as $key => $vx) { // $T_OrderDeliveryID_arr[] = intval($vx['T_OrderDeliveryID']); $T_OrderID_arr[] = intval($vx['T_OrderID']); } // $string_wherein_T_OrderDeliveryID = implode(",", $T_OrderDeliveryID_arr); $string_wherein_T_OrderID = implode(",", $T_OrderID_arr); } $result = [ "t_orderdelivery" => [], "t_orderdetaildelivery" => [], "t_order" => [], "t_orderdetail" => [], "t_orderdetailbahan" => [], "t_orderdetailsample" => [], ]; if (count($rows_pivot) > 0) { // ambil all data sesuai pivot // 1. t_orderdelivery $t_orderdelivery = $this->getData_t_orderdelivery($string_wherein_T_OrderDeliveryID); // 2. t_orderdetaildelivery $t_orderdetaildelivery = $this->getData_t_orderdetaildelivery($string_wherein_T_OrderDeliveryID); } if (count($rows_pivot_t_order) > 0) { // 3. t_order $t_order = $this->getData_t_order($string_wherein_T_OrderID); // 4. t_orderdetail $t_orderdetail = $this->getData_t_orderdetail($string_wherein_T_OrderID); // 5. t_orderdetailbahan $t_orderdetailbahan = $this->getData_t_orderdetailbahan($string_wherein_T_OrderID); // 6. t_orderdetailsample $t_orderdetailsample = $this->getData_t_orderdetailsample($string_wherein_T_OrderID); $result["t_orderdelivery"] = $t_orderdelivery; $result["t_orderdetaildelivery"] = $t_orderdetaildelivery; $result["t_order"] = $t_order; $result["t_orderdetail"] = $t_orderdetail; $result["t_orderdetailbahan"] = $t_orderdetailbahan; $result["t_orderdetailsample"] = $t_orderdetailsample; if ($debug != "") { echo "
";
echo print_r($result);
echo "";
exit;
}
echo json_encode(
[
"status" => "OK",
"message" => "Data Ditemukan",
"data" => [$result]
]
);
// KLU SUDAH FIX BARU REPLY GZ
// $result_x = array(
// 'status' => 'OK',
// "message" => "Tidak ada data terbaru",
// "data" => [$result]
// );
// $this->reply_gz($result_x, $debug);
} else {
// KLU SUDAH FIX BARU REPLY GZ
$result_x = array(
'status' => 'ERR',
"message" => "Tidak ada data terbaru",
"data" => []
);
// $this->reply_gz($result_x, $debug);
echo json_encode($result_x);
}
} catch (Exception $exc) {
$message = $exc->getMessage();
$result = array(
'status' => 'err',
"message" => $message,
);
$this->reply_gz($result);
}
}
function reg_download($debug = "")
{
try {
$prm = $this->get_param();
$limit = 2;
if (isset($prm['limit'])) {
$limit = trim($prm['limit']);
}
$branchId = ($debug != "") ? 1 : $prm['branchId'];
// $branchId = 1;
$branchCode = $prm['branchCode'];
$pickup_status = ($debug != "") ? "S" : $prm['pickup_status'];
$sql_pivot = "SELECT T_OrderDeliveryNumber,
T_OrderDeliveryID,
T_OrderID,
T_OrderDetailID,
T_OrderDetailBahanID,
T_OrderDetailSampleID,
M_PatientID,
T_OrderDetailDeliveryID,
T_OrderDetailPacketID
from one_mitra.t_orderdelivery
join one_mitra.t_orderdetaildelivery
ON T_OrderDetailDeliveryT_OrderDeliveryID = T_OrderDeliveryID
AND T_OrderDetailDeliveryIsActive = 'Y'
AND T_OrderDeliveryIsActive = 'Y'
AND T_OrderDeliveryIsDownloaded = 'N'
AND T_OrderDeliveryStatus = 'S'
AND T_OrderDeliveryDestination = $branchId
join one_mitra.t_order
ON T_OrderDetailDeliveryT_OrderID = T_OrderID
AND T_OrderIsActive = 'Y'
join one_mitra.m_patient
ON T_OrderM_PatientID = M_PatientID
AND M_PatientIsActive = 'Y'
LEFT join one_mitra.t_orderdetail
ON T_OrderDetailOrderID = T_OrderID
AND T_OrderDetailIsActive = 'Y'
left join one_mitra.t_orderdetailbahan
ON T_OrderDetailBahanT_OrderID = T_OrderID
AND T_OrderDetailBahanIsActive = 'Y'
left join one_mitra.t_orderdetailsample
ON T_OrderDetailSampleT_OrderID = T_OrderID
AND T_OrderDetailSampleIsActive = 'Y'
LEFT JOIN one_mitra.t_orderdetailpacket
ON T_OrderDetailPacketOrderID = T_OrderID
AND T_OrderDetailPacketIsActive = 'Y'
";
// LIMIT $limit ";
$qry_pivot = $this->db_regional->query($sql_pivot);
if (!$qry_pivot) {
$response = ["status" => "ERR", "message" => "select t_orderdelivery | func reg_download " .
$this->db_regional->error()["message"], "debug" => $this->db_regional->last_query()];
// $this->reply_gz($response);
$this->reply($response);
exit;
}
$rows_pivot = $qry_pivot->result_array();
$last_qry_pivot = $this->db_regional->last_query();
// print_r($rows_pivot_t_order);
// exit;
$string_wherein_T_OrderDeliveryID = "";
$string_wherein_T_OrderDetailDeliveryID = "";
$string_wherein_T_OrderID = "";
$string_wherein_T_OrderDetailID = "";
$string_wherein_T_OrderDetailBahanID = "";
$string_wherein_T_OrderDetailSampleID = "";
$string_wherein_M_PatientID = "";
$string_wherein_T_OrderDetailPacketID = "";
$T_OrderDeliveryID_arr = [];
$T_OrderDetailDeliveryID_arr = [];
$T_OrderID_arr = [];
$T_OrderDetailID_arr = [];
$T_OrderDetailBahanID_arr = [];
$T_OrderDetailSampleID_arr = [];
$M_PatientID_arr = [];
$T_OrderDetailPacketID_arr = [];
if (count($rows_pivot) > 0) {
foreach ($rows_pivot as $key => $vx) {
$T_OrderDeliveryID_arr[] = intval($vx['T_OrderDeliveryID']);
$T_OrderDetailDeliveryID_arr[] = intval($vx['T_OrderDetailDeliveryID']);
$T_OrderID_arr[] = intval($vx['T_OrderID']);
$T_OrderDetailID_arr[] = intval($vx['T_OrderDetailID']);
$T_OrderDetailBahanID_arr[] = intval($vx['T_OrderDetailBahanID']);
$T_OrderDetailSampleID_arr[] = intval($vx['T_OrderDetailSampleID']);
$M_PatientID_arr[] = intval($vx['M_PatientID']);
$T_OrderDetailPacketID_arr[] = intval($vx['T_OrderDetailPacketID']);
}
$string_wherein_T_OrderDeliveryID = implode(",", $T_OrderDeliveryID_arr);
$string_wherein_T_OrderDetailDeliveryID = implode(",", $T_OrderDetailDeliveryID_arr);
$string_wherein_T_OrderID = implode(",", $T_OrderID_arr);
$string_wherein_T_OrderDetailID = implode(",", $T_OrderDetailID_arr);
$string_wherein_T_OrderDetailBahanID = implode(",", $T_OrderDetailBahanID_arr);
$string_wherein_T_OrderDetailSampleID = implode(",", $T_OrderDetailSampleID_arr);
$string_wherein_M_PatientID = implode(",", $M_PatientID_arr);
$string_wherein_T_OrderDetailPacketID = implode(",", $T_OrderDetailPacketID_arr);
}
$result = [
"t_orderdelivery" => [],
"t_orderdetaildelivery" => [],
"t_order" => [],
"t_orderdetail" => [],
"t_orderdetailbahan" => [],
"t_orderdetailsample" => [],
"m_patient" => [],
"t_orderdetailpacket" => []
];
if (count($rows_pivot) > 0) {
// ambil all data sesuai pivot
// 1. t_orderdelivery
$t_orderdelivery = $this->getData_t_orderdelivery($string_wherein_T_OrderDeliveryID);
// 2. t_orderdetaildelivery
$t_orderdetaildelivery = $this->getData_t_orderdetaildelivery($string_wherein_T_OrderDetailDeliveryID);
// 3. t_order
$t_order = $this->getData_t_order($string_wherein_T_OrderID);
// 4. t_orderdetail
$t_orderdetail = $this->getData_t_orderdetail($string_wherein_T_OrderDetailID);
// 5. t_orderdetailbahan
$t_orderdetailbahan = $this->getData_t_orderdetailbahan($string_wherein_T_OrderDetailBahanID);
// 6. t_orderdetailsample
$t_orderdetailsample = $this->getData_t_orderdetailsample($string_wherein_T_OrderDetailSampleID);
// 7. m_patient
$m_patient = $this->getData_m_patient($string_wherein_M_PatientID);
// 7. getData_t_orderdetailpacket
$t_orderdetailpacket = $this->getData_t_orderdetailpacket($string_wherein_T_OrderDetailPacketID);
$result["t_orderdelivery"] = $t_orderdelivery;
$result["t_orderdetaildelivery"] = $t_orderdetaildelivery;
$result["t_order"] = $t_order;
$result["t_orderdetail"] = $t_orderdetail;
$result["t_orderdetailbahan"] = $t_orderdetailbahan;
$result["t_orderdetailsample"] = $t_orderdetailsample;
$result["m_patient"] = $m_patient;
$result["t_orderdetailpacket"] = $t_orderdetailpacket;
if ($debug != "") {
echo "";
echo print_r($result);
echo "";
exit;
}
$result = [
"status" => "OK",
"message" => "Data Ditemukan",
"data" => [$result]
];
// echo json_encode(
// [
// "status" => "OK",
// "message" => "Data Ditemukan",
// "data" => [$result]
// ]
// );
$this->reply_gz($result, $debug);
// KLU SUDAH FIX BARU REPLY GZ
// $result_x = array(
// 'status' => 'OK',
// "message" => "Tidak ada data terbaru",
// "data" => [$result]
// );
// $this->reply_gz($result_x, $debug);
} else {
// KLU SUDAH FIX BARU REPLY GZ
$result_x = array(
'status' => 'ERR',
"message" => "Tidak ada data terbaru",
// "qry_pivot" => $last_qry_pivot,
"data" => []
);
$this->reply_gz($result_x, $debug);
// echo json_encode($result_x);
// $this->reply_gz($result, $debug);
}
} catch (Exception $exc) {
$message = $exc->getMessage();
$result = array(
'status' => 'err',
"message" => $message,
);
$this->reply_gz($result);
}
}
function reg_update_is_download()
{
try {
// $prm = $this->get_param();
$prm = $this->get_param_z();
$branchId = $prm['branchId'];
// $branchCde = $prm['branchCode'];
$dataOrder = $prm['data'];
$result = [];
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'];
$sqlUpdate = "UPDATE one_mitra.t_orderdelivery
SET T_OrderDeliveryIsDownloaded = 'Y'
, T_OrderDeliveryDownloadedDate = NOW()
WHERE T_OrderDeliveryID = $id
AND T_OrderDeliveryIsDownloaded = 'N'
AND T_OrderDeliveryIsActive = 'Y'
AND T_OrderDeliveryDestination = $branchId";
$qryUpdate = $this->db->query($sqlUpdate);
if (!$qryUpdate) {
$this->sys_error_db(["status" => "ERR", "message" => "update one_mitra.t_orderdelivery | func reg_update_is_download " .
$this->db_regional->error()["message"], "debug" => $this->db->last_query()]);
exit;
}
}
$result = array(
"message" => 'Berhasil Di Proses',
// "data" => $dataOrder,
"sql" => $this->db->last_query()
);
}
$result = array(
"message" => 'Berhasil Di Proses',
// "data" => $dataOrder,
// "sql" => $this->db->last_query()
);
$this->sys_ok($result);
} catch (Exception $exc) {
$message = $exc->getMessage();
$this->sys_error($message);
}
}
function getUpdatePatient()
{
try {
$prm = $this->get_param();
$branchID = $prm['branchId'];
$sql = "SELECT T_OrderID,
T_OrderDeliveryID,
T_OrderIsQRCode,
one_mitra.m_patient.*
FROM one_mitra.m_patient
JOIN one_mitra.t_order
ON M_PatientID = T_OrderM_PatientID
AND T_OrderIsActive = 'Y'
JOIN one_mitra.t_orderdetaildelivery
ON T_OrderID = T_OrderDetailDeliveryT_OrderID
AND T_OrderDetailDeliveryIsActive = 'Y'
JOIN one_mitra.t_orderdelivery
ON T_OrderDetailDeliveryT_OrderDeliveryID = T_OrderDeliveryID
AND T_OrderDeliveryIsActive = 'Y'
AND T_OrderDeliveryStatus IN ('S', 'P')
AND T_OrderDeliveryDestination = $branchID
WHERE M_PatientLastUpdated > T_OrderDeliveryDownloadedDate";
$qry = $this->db_regional->query($sql);
if (!$qry) {
$response = ["status" => "ERR", "message" => "function get update patient data | " .
$this->db_regional->error()["message"], "debug" => $this->db_regional->last_query()];
$this->reply_gz($response);
// $this->reply($response);
exit;
}
$result = $qry->result_array();
// $this->sys_ok($result);
$this->reply_gz(["status" => "OK", "data" => $result]);
} catch (Exception $exc) {
$message = $exc->getMessage();
$this->sys_error($message);
}
}
function updateIsDownloadedDate()
{
try {
$prm = $this->get_param();
$arrDeliveryId = $prm['arrDeliveryID'];
// $this->reply_gz(["status" => "OK", "data" => $arrDeliveryId]);
// exit;
for ($i = 0; $i < count($arrDeliveryId); $i++) {
$sql = "UPDATE one_mitra.t_orderdelivery
SET T_OrderDeliveryDownloadedDate = NOW()
WHERE T_OrderDeliveryID = ?";
$qry = $this->db_regional->query($sql, [$arrDeliveryId[$i]]);
if (!$qry) {
$response = ["status" => "ERR", "message" => "function updateIsDownloadedDate | " .
$this->db_regional->error()["message"], "debug" => $this->db_regional->last_query()];
$this->reply_gz($response);
// $this->reply($response);
exit;
}
}
// $this->reply(["status" => "OK", "data" => $arrDeliveryId]);
$this->reply_gz(["status" => "OK", "data" => $arrDeliveryId]);
} catch (Exception $exc) {
$message = $exc->getMessage();
$this->sys_error($message);
}
}
}