Initial import

This commit is contained in:
sas.fajri
2026-05-25 20:01:37 +07:00
commit 710d7c1b97
10371 changed files with 2381698 additions and 0 deletions

View File

@@ -0,0 +1,88 @@
<?php
class Confirmorder extends MY_Controller
{
var $max_limit = 20;
public function __construct()
{
parent::__construct();
// db wilayah contoh surabaya
$this->db_regional = $this->load->database("regional", true);
// string database
$this->db_str_doctor = 'one_doctor';
}
public function index()
{
echo "CONFIRM ORDER 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 get_confirm_order($M_BranchCode)
{
$sql_get_confirm_order = "select
oneResultOrderPatientID
from $this->db_str_doctor.one_result
where oneResultDate < DATE_SUB(NOW(), INTERVAL 5 DAY)
AND oneResultOrderM_BranchCode <> ?";
// echo $sql_get_confirm_order;
$query_confirm_order = $this->db_regional->query($sql_get_confirm_order,[
$M_BranchCode
]);
if(!$query_confirm_order){
$this->db->trans_rollback();
$this->sys_error_db(["status" => "ERR", "message" => "select query_confirm_order one_result | " .
$this->db->error()["message"], "debug" => $this->db_regional->last_query()]);
exit;
}
$oneResultOrderPatientID_array = [];
$rows_query_confirm_order = $query_confirm_order->result_array();
if(count($rows_query_confirm_order) == 0){
echo json_encode(
[
"status" => "OK",
"message" => "Data Tidak Ditemukan",
"oneResultOrderPatientID" => $oneResultOrderPatientID_array,
]
);
}else{
foreach($rows_query_confirm_order as $key => $val)
{
$oneResultOrderPatientID_array[] = intval($val['oneResultOrderPatientID']);
}
echo json_encode(
[
"status" => "OK",
"message" => "Data Ditemukan",
"oneResultOrderPatientID" => $oneResultOrderPatientID_array,
]
);
}
}
}

View File

@@ -0,0 +1,318 @@
<?php
class DownloadOrderPatient extends MY_Controller
{
var $db;
function __construct()
{
parent::__construct();
}
function index()
{
echo "Api: Download Patient";
}
function download()
{
try {
$prm = $this->get_param();
$limit = 10;
if (isset($prm['limit'])) {
$limit = trim($prm['limit']);
}
$branchId = $prm['branchId'];
$branchCode = $prm['branchCode'];
$sql = "SELECT OrderPatientID,
downloadLogM_BranchID,
downloadLogM_BranchCode,
downloadLogIsDownloaded,
downloadLogRetry
FROM one_doctor.order_patient
JOIN one_doctor.order_patient_details ON OrderPatientID = OrderPatientDetailsOrderPatientID
AND OrderPatientDetailsIsActive = 'Y'
JOIN m_mou on OrderPatientM_MouID = M_MouID
AND M_MouIsActive = 'Y'
LEFT JOIN one_doctor.download_log ON OrderPatientID = downloadLogOrderPatientID
WHERE OrderPatientIsActive = 'Y'
AND (ISNULL(downloadLogM_BranchID)
OR (downloadLogM_BranchID = ? AND downloadLogIsDownloaded = 'N')
OR (downloadLogM_BranchID <> ? ))
AND (ISNULL(downloadLogRetry) OR downloadLogRetry < 10)
GROUP BY OrderPatientID, downloadLogM_BranchID
ORDER BY OrderPatientID LIMIT ? ";
$qry = $this->db->query($sql, [intval($branchId), intval($branchId), intval($limit)]);
if (!$qry) {
$response = ["status" => "ERR", "message" => "select order patient | " .
$this->db->error()["message"], "debug" => $this->db->last_query()];
$this->reply_gz($response);
exit;
}
$rows = $qry->result_array();
$arrOrderPatientId = array();
foreach ($rows as $key => $val) {
$orderPatientId = $val['OrderPatientID'];
if (in_array($orderPatientId, $arrOrderPatientId)) {
continue;
}
$arrOrderPatientId[] = $orderPatientId;
$this->insertDownloadLog($branchId, $branchCode, $orderPatientId);
}
if (count($arrOrderPatientId) > 0) {
$orderPatientIdAll = implode(',', $arrOrderPatientId);
$sqlData = "SELECT order_patient.* , M_MouM_CompanyID FROM one_doctor.order_patient
JOIN m_mou ON OrderPatientM_MouID = M_MouID
AND M_MouIsActive = 'Y'
WHERE OrderPatientID IN ($orderPatientIdAll)
AND OrderPatientIsActive = 'Y'";
$qryData = $this->db->query($sqlData);
if (!$qryData) {
$response = ["status" => "ERR", "message" => "select order patient | " .
$this->db->error()["message"], "debug" => $this->db->last_query()];
$this->reply_gz($response);
exit;
}
$rowsData = $qryData->result_array();
foreach ($rowsData as $key => $value) {
$orderPatientId = $value['OrderPatientID'];
$sqlGetDetail = "SELECT * FROM one_doctor.order_patient_details
WHERE OrderPatientDetailsOrderPatientID = ?
AND OrderPatientDetailsIsActive = 'Y' ";
$qryGetDetail = $this->db->query($sqlGetDetail, [intval($orderPatientId)]);
if (!$qryGetDetail) {
$response = ["status" => "ERR", "message" => "select order patient detail | " .
$this->db->error()["message"], "debug" => $this->db->last_query()];
$this->reply_gz($response);
exit;
}
$rowsgetDetail = $qryGetDetail->result_array();
$rowsData[$key]['details'] = $rowsgetDetail;
// $sqlGetSaran = "SELECT *
// FROM one_doctor.order_saran
// WHERE OrderSaranOrderPatientID = ?
// AND OrderSaranIsActive = 'Y'";
// $qryGetSaran = $this->db->query($sqlGetSaran, [intval($orderPatientId)]);
// if (!$qryGetSaran) {
// $response = ["status" => "ERR", "message" => "select order saran | " .
// $this->db->error()["message"], "debug" => $this->db->last_query()];
// $this->reply_gz($response);
// exit;
// }
// $rowsgetSaran = $qryGetSaran->result_array();
// $rowsData[$key]['saran'] = $rowsgetSaran;
}
$result = array(
'status' => 'OK',
"data" => $rowsData,
);
$this->reply_gz($result);
// $this->reply($result);
} else {
$this->reply_gz("Tidak ada data terbaru");
}
} catch (Exception $exc) {
$message = $exc->getMessage();
$result = array(
'status' => 'err',
"message" => $message,
);
$this->reply_gz($result);
}
}
function insertDownloadLog($branchId, $branchCode, $patientId)
{
$sql = "INSERT INTO one_doctor.download_log
(downloadLogM_BranchID,
downloadLogM_BranchCode,
downloadLogOrderPatientID,
downloadLogRetry)
VALUES
(?,?,?,0) ON DUPLICATE KEY UPDATE downloadLogRetry = downloadLogRetry + 1";
$qry = $this->db->query($sql, [intval($branchId), $branchCode, intval($patientId)]);
if (!$qry) {
$this->sys_error_db(["status" => "ERR", "message" => "select order patient | " .
$this->db->error()["message"], "debug" => $this->db->last_query()]);
exit;
}
}
function updateLog()
{
try {
$prm = $this->get_param_z();
$branchId = $prm['branchId'];
// $branchCde = $prm['branchCode'];
$arrOrderPatientId = $prm['arrOrderPatientId'];
foreach ($arrOrderPatientId as $key => $value) {
$sqlUpdate = "UPDATE one_doctor.download_log SET
downloadLogIsDownloaded = 'Y'
WHERE downloadLogOrderPatientID = ?
AND downloadLogM_BranchID = ?";
$qry = $this->db->query($sqlUpdate, [intval($value), intval($branchId)]);
if (!$qry) {
$this->sys_error_db(["status" => "ERR", "message" => "Insert Log | " .
$this->db->error()["message"], "debug" => $this->db->last_query()]);
exit;
}
}
$result = array(
"message" => 'Berhasil',
"sql" => $this->db->last_query()
);
$this->sys_ok($result);
} catch (Exception $exc) {
$message = $exc->getMessage();
$this->sys_error($message);
}
}
function downloadSaran()
{
try {
$prm = $this->get_param();
$limit = 10;
if (isset($prm['limit'])) {
$limit = trim($prm['limit']);
}
$branchId = $prm['branchId'];
$branchCode = $prm['branchCode'];
$sql = "SELECT * FROM one_doctor.order_saran
LEFT JOIN one_doctor.download_saran_log ON OrderSaranID = downloadSaranLogOrderSaranID
AND downloadSaranLogM_BranchID = ?
WHERE OrderSaranIsActive = 'Y'
AND (
(downloadSaranLogIsDownloaded = 'N' AND downloadSaranLogRetry < 10)
OR ISNULL(downloadSaranLogM_BranchID)
)
LIMIT ?";
$qry = $this->db->query($sql, [intval($branchId), intval($limit)]);
if (!$qry) {
$response = ["status" => "ERR", "message" => "select order saran | " .
$this->db->error()["message"], "debug" => $this->db->last_query()];
// $this->reply_gz($response);
$this->reply($response);
exit;
}
$rows = $qry->result_array();
$arrOrderSaran = array();
// print_r(json_encode($rows));
// exit;
foreach ($rows as $key => $val) {
$orderSaran = $val['OrderSaranID'];
if (in_array($orderSaran, $arrOrderSaran)) {
continue;
}
$arrOrderSaran[] = $orderSaran;
$this->insertDownloadSaranLog($branchId, $branchCode, $orderSaran);
}
if (count($arrOrderSaran) > 0) {
$orderSaranIdAll = implode(',', $arrOrderSaran);
$sqlData = "SELECT * FROM one_doctor.order_saran
WHERE OrderSaranIsActive ='Y'
AND OrderSaranID IN ($orderSaranIdAll)";
$qryData = $this->db->query($sqlData);
if (!$qryData) {
$response = ["status" => "ERR", "message" => "select order saran | " .
$this->db->error()["message"], "debug" => $this->db->last_query()];
// $this->reply($response);
$this->reply_gz($response);
exit;
}
$rowsData = $qryData->result_array();
$result = array(
'status' => 'OK',
"data" => $rowsData,
);
$this->reply_gz($result);
// $this->reply($result);
} else {
$this->reply_gz("Tidak ada data terbaru");
// $this->reply("Tidak ada data terbaru");
}
} catch (Exception $exc) {
$message = $exc->getMessage();
$result = array(
'status' => 'err',
"message" => $message,
);
$this->reply_gz($result);
}
}
function insertDownloadSaranLog($branchId, $branchCode, $saranId)
{
$sql = "INSERT INTO one_doctor.download_saran_log
(downloadSaranLogM_BranchID,
downloadSaranLogM_BranchCode,
downloadSaranLogOrderSaranID,
downloadSaranLogRetry)
VALUES (?, ?, ?,0) ON DUPLICATE KEY UPDATE downloadSaranLogRetry = downloadSaranLogRetry + 1";
$qry = $this->db->query($sql, [intval($branchId), $branchCode, intval($saranId)]);
if (!$qry) {
$resp = ["status" => "ERR", "message" => "insert download saran log | " .
$this->db->error()["message"], "debug" => $this->db->last_query()];
$this->reply_gz($resp);
exit;
}
}
function updateSaranLog()
{
try {
// $prm = $this->get_param();
$prm = $this->get_param_z();
$branchId = $prm['branchId'];
// $branchCde = $prm['branchCode'];
$arrOrderSaranId = $prm['arrOrderSaranId'];
foreach ($arrOrderSaranId as $key => $value) {
$sqlUpdate = "UPDATE one_doctor.download_saran_log
SET downloadSaranLogIsDownloaded = 'Y'
WHERE downloadSaranLogOrderSaranID = ?
AND downloadSaranLogM_BranchID = ?";
$qry = $this->db->query($sqlUpdate, [intval($value), intval($branchId)]);
if (!$qry) {
$this->sys_error_db(["status" => "ERR", "message" => "Insert Log | " .
$this->db->error()["message"], "debug" => $this->db->last_query()]);
exit;
}
}
$result = array(
"message" => 'Berhasil',
"sql" => $this->db->last_query()
);
$this->sys_ok($result);
} catch (Exception $exc) {
$message = $exc->getMessage();
$this->sys_error($message);
}
}
function reply($resp)
{
echo json_encode($resp);
}
function reply_gz($resp)
{
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);
}
}

View File

@@ -0,0 +1,371 @@
<?php
class DownloadOrderPatient extends MY_Controller
{
var $db;
function __construct()
{
parent::__construct();
$this->db_regional = $this->load->database("regional", true);
}
function index()
{
echo "Api: Download Patient";
}
function download()
{
try {
$prm = $this->get_param();
// $limit = 20;
$limit = 100;
if (isset($prm['limit'])) {
$limit = trim($prm['limit']);
}
$branchId = $prm['branchId'];
$branchCode = $prm['branchCode'];
// tidak order nasional
// $sql = "SELECT distinct OrderPatientID,
// downloadLogM_BranchID,
// downloadLogM_BranchCode,
// downloadLogIsDownloaded,
// downloadLogRetry
// FROM one_doctor.order_patient
// JOIN one_doctor.order_patient_details ON OrderPatientID = OrderPatientDetailsOrderPatientID
// AND OrderPatientDetailsIsActive = 'Y'
// JOIN m_mou on OrderPatientM_MouID = M_MouID
// AND M_MouIsActive = 'Y'
// LEFT JOIN one_doctor.download_log ON OrderPatientID = downloadLogOrderPatientID
// WHERE OrderPatientIsActive = 'Y'
// AND (ISNULL(downloadLogM_BranchID)
// OR (downloadLogM_BranchID = ? AND downloadLogIsDownloaded = 'N')
// OR (downloadLogM_BranchID <> ? ))
// AND (ISNULL(downloadLogRetry) OR downloadLogRetry < 10)
// AND OrderPatientID NOT IN (
// SELECT downloadLogOrderPatientID
// from one_doctor.download_log
// WHERE downloadLogM_BranchID = ?
// )
// GROUP BY OrderPatientID, downloadLogM_BranchID
// ORDER BY OrderPatientID
// LIMIT ?";
// pakai order nasional
$sql = "SELECT distinct OrderPatientID,
downloadLogM_BranchID,
downloadLogM_BranchCode,
downloadLogIsDownloaded,
downloadLogRetry
FROM one_doctor.order_patient
JOIN one_doctor.order_patient_details
ON OrderPatientID = OrderPatientDetailsOrderPatientID
AND OrderPatientDetailsIsActive = 'Y'
JOIN m_mou
ON (OrderPatientM_MouID = M_MouID AND M_MouIsActive = 'Y' OR OrderPatientM_MouID = 0)
LEFT JOIN one_doctor.download_log
ON OrderPatientID = downloadLogOrderPatientID
WHERE OrderPatientIsActive = 'Y'
AND (ISNULL(downloadLogM_BranchID)
OR (downloadLogM_BranchID = ? AND downloadLogIsDownloaded = 'N')
OR (downloadLogM_BranchID <> ? ))
AND (ISNULL(downloadLogRetry) OR downloadLogRetry < 10)
AND OrderPatientID NOT IN (
SELECT downloadLogOrderPatientID
from one_doctor.download_log
WHERE downloadLogM_BranchID = ?
)
GROUP BY OrderPatientID, downloadLogM_BranchID
ORDER BY OrderPatientID
LIMIT ?";
$qry = $this->db_regional->query($sql, [
intval($branchId),
intval($branchId),
intval($branchId),
intval($limit)
]);
if (!$qry) {
$response = ["status" => "ERR", "message" => "select order patient | " .
$this->db_regional->error()["message"], "debug" => $this->db_regional->last_query()];
$this->reply_gz($response);
exit;
}
$rows = $qry->result_array();
$arrOrderPatientId = array();
foreach ($rows as $key => $val) {
$orderPatientId = $val['OrderPatientID'];
if (in_array($orderPatientId, $arrOrderPatientId)) {
continue;
}
$arrOrderPatientId[] = $orderPatientId;
$this->insertDownloadLog($branchId, $branchCode, $orderPatientId);
}
if (count($arrOrderPatientId) > 0) {
$orderPatientIdAll = implode(',', $arrOrderPatientId);
// tnp order nasional
// $sqlData = "SELECT order_patient.* , M_MouM_CompanyID FROM one_doctor.order_patient
// JOIN m_mou ON OrderPatientM_MouID = M_MouID
// AND M_MouIsActive = 'Y'
// WHERE OrderPatientID IN ($orderPatientIdAll)
// AND OrderPatientIsActive = 'Y'";
// pake order nasional
$sqlData = "SELECT order_patient.* , IFNULL(M_MouM_CompanyID,0) as M_MouM_CompanyID
FROM one_doctor.order_patient
LEFT JOIN m_mou
ON (OrderPatientM_MouID = M_MouID AND M_MouIsActive = 'Y')
WHERE OrderPatientID IN ($orderPatientIdAll)
AND OrderPatientIsActive = 'Y'";
$qryData = $this->db_regional->query($sqlData);
if (!$qryData) {
$response = ["status" => "ERR", "message" => "select order patient | " .
$this->db_regional->error()["message"], "debug" => $this->db_regional->last_query()];
$this->reply_gz($response);
exit;
}
$rowsData = $qryData->result_array();
foreach ($rowsData as $key => $value) {
$orderPatientId = $value['OrderPatientID'];
$sqlGetDetail = "SELECT * FROM one_doctor.order_patient_details
WHERE OrderPatientDetailsOrderPatientID = ?
AND OrderPatientDetailsIsActive = 'Y' ";
$qryGetDetail = $this->db_regional->query($sqlGetDetail, [intval($orderPatientId)]);
if (!$qryGetDetail) {
$response = ["status" => "ERR", "message" => "select order patient detail | " .
$this->db_regional->error()["message"], "debug" => $this->db_regional->last_query()];
$this->reply_gz($response);
exit;
}
$rowsgetDetail = $qryGetDetail->result_array();
$rowsData[$key]['details'] = $rowsgetDetail;
// $sqlGetSaran = "SELECT *
// FROM one_doctor.order_saran
// WHERE OrderSaranOrderPatientID = ?
// AND OrderSaranIsActive = 'Y'";
// $qryGetSaran = $this->db->query($sqlGetSaran, [intval($orderPatientId)]);
// if (!$qryGetSaran) {
// $response = ["status" => "ERR", "message" => "select order saran | " .
// $this->db->error()["message"], "debug" => $this->db->last_query()];
// $this->reply_gz($response);
// exit;
// }
// $rowsgetSaran = $qryGetSaran->result_array();
// $rowsData[$key]['saran'] = $rowsgetSaran;
}
$result = array(
'status' => 'OK',
"data" => $rowsData,
);
$this->reply_gz($result);
// $this->reply($result);
} else {
$this->reply_gz("Tidak ada data terbaru");
}
} catch (Exception $exc) {
$message = $exc->getMessage();
$result = array(
'status' => 'err',
"message" => $message,
);
$this->reply_gz($result);
}
}
function insertDownloadLog($branchId, $branchCode, $patientId)
{
$sql = "INSERT INTO one_doctor.download_log
(downloadLogM_BranchID,
downloadLogM_BranchCode,
downloadLogOrderPatientID,
downloadLogRetry)
VALUES
(?,?,?,0) ON DUPLICATE KEY UPDATE downloadLogRetry = downloadLogRetry + 1";
$qry = $this->db_regional->query($sql, [intval($branchId), $branchCode, intval($patientId)]);
if (!$qry) {
$this->sys_error_db(["status" => "ERR", "message" => "select order patient | " .
$this->db_regional->error()["message"], "debug" => $this->db_regional->last_query()]);
exit;
}
}
function updateLog()
{
try {
$prm = $this->get_param_z();
$branchId = $prm['branchId'];
// $branchCde = $prm['branchCode'];
$arrOrderPatientId = $prm['arrOrderPatientId'];
foreach ($arrOrderPatientId as $key => $value) {
$sqlUpdate = "UPDATE one_doctor.download_log SET
downloadLogIsDownloaded = 'Y'
WHERE downloadLogOrderPatientID = ?
AND downloadLogM_BranchID = ?";
$qry = $this->db_regional->query($sqlUpdate, [intval($value), intval($branchId)]);
if (!$qry) {
$this->sys_error_db(["status" => "ERR", "message" => "Insert Log | " .
$this->db_regional->error()["message"], "debug" => $this->db_regional->last_query()]);
exit;
}
}
$result = array(
"message" => 'Berhasil',
"sql" => $this->db_regional->last_query()
);
$this->sys_ok($result);
} catch (Exception $exc) {
$message = $exc->getMessage();
$this->sys_error($message);
}
}
function downloadSaran()
{
try {
$prm = $this->get_param();
$limit = 10;
if (isset($prm['limit'])) {
$limit = trim($prm['limit']);
}
$branchId = $prm['branchId'];
$branchCode = $prm['branchCode'];
$sql = "SELECT * FROM one_doctor.order_saran
LEFT JOIN one_doctor.download_saran_log ON OrderSaranID = downloadSaranLogOrderSaranID
AND downloadSaranLogM_BranchID = ?
WHERE OrderSaranIsActive = 'Y'
AND (
(downloadSaranLogIsDownloaded = 'N' AND downloadSaranLogRetry < 10)
OR ISNULL(downloadSaranLogM_BranchID)
)
LIMIT ?";
$qry = $this->db_regional->query($sql, [intval($branchId), intval($limit)]);
if (!$qry) {
$response = ["status" => "ERR", "message" => "select order saran | " .
$this->db_regional->error()["message"], "debug" => $this->db_regional->last_query()];
// $this->reply_gz($response);
$this->reply($response);
exit;
}
$rows = $qry->result_array();
$arrOrderSaran = array();
// print_r(json_encode($rows));
// exit;
foreach ($rows as $key => $val) {
$orderSaran = $val['OrderSaranID'];
if (in_array($orderSaran, $arrOrderSaran)) {
continue;
}
$arrOrderSaran[] = $orderSaran;
$this->insertDownloadSaranLog($branchId, $branchCode, $orderSaran);
}
if (count($arrOrderSaran) > 0) {
$orderSaranIdAll = implode(',', $arrOrderSaran);
$sqlData = "SELECT * FROM one_doctor.order_saran
WHERE OrderSaranIsActive ='Y'
AND OrderSaranID IN ($orderSaranIdAll)";
$qryData = $this->db_regional->query($sqlData);
if (!$qryData) {
$response = ["status" => "ERR", "message" => "select order saran | " .
$this->db_regional->error()["message"], "debug" => $this->db_regional->last_query()];
// $this->reply($response);
$this->reply_gz($response);
exit;
}
$rowsData = $qryData->result_array();
$result = array(
'status' => 'OK',
"data" => $rowsData,
);
$this->reply_gz($result);
// $this->reply($result);
} else {
$this->reply_gz("Tidak ada data terbaru");
// $this->reply("Tidak ada data terbaru");
}
} catch (Exception $exc) {
$message = $exc->getMessage();
$result = array(
'status' => 'err',
"message" => $message,
);
$this->reply_gz($result);
}
}
function insertDownloadSaranLog($branchId, $branchCode, $saranId)
{
$sql = "INSERT INTO one_doctor.download_saran_log
(downloadSaranLogM_BranchID,
downloadSaranLogM_BranchCode,
downloadSaranLogOrderSaranID,
downloadSaranLogRetry)
VALUES (?, ?, ?,0) ON DUPLICATE KEY UPDATE downloadSaranLogRetry = downloadSaranLogRetry + 1";
$qry = $this->db_regional->query($sql, [intval($branchId), $branchCode, intval($saranId)]);
if (!$qry) {
$resp = ["status" => "ERR", "message" => "insert download saran log | " .
$this->db_regional->error()["message"], "debug" => $this->db_regional->last_query()];
$this->reply_gz($resp);
exit;
}
}
function updateSaranLog()
{
try {
// $prm = $this->get_param();
$prm = $this->get_param_z();
$branchId = $prm['branchId'];
// $branchCde = $prm['branchCode'];
$arrOrderSaranId = $prm['arrOrderSaranId'];
foreach ($arrOrderSaranId as $key => $value) {
$sqlUpdate = "UPDATE one_doctor.download_saran_log
SET downloadSaranLogIsDownloaded = 'Y'
WHERE downloadSaranLogOrderSaranID = ?
AND downloadSaranLogM_BranchID = ?";
$qry = $this->db_regional->query($sqlUpdate, [intval($value), intval($branchId)]);
if (!$qry) {
$this->sys_error_db(["status" => "ERR", "message" => "Insert Log | " .
$this->db_regional->error()["message"], "debug" => $this->db->last_query()]);
exit;
}
}
$result = array(
"message" => 'Berhasil',
"sql" => $this->db_regional->last_query()
);
$this->sys_ok($result);
} catch (Exception $exc) {
$message = $exc->getMessage();
$this->sys_error($message);
}
}
function reply($resp)
{
echo json_encode($resp);
}
function reply_gz($resp)
{
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);
}
}

View File

@@ -0,0 +1,330 @@
<?php
class DownloadOrderPatient extends MY_Controller
{
var $db;
function __construct()
{
parent::__construct();
$this->db_regional = $this->load->database("regional", true);
}
function index()
{
echo "Api: Download Patient";
}
function download()
{
try {
$prm = $this->get_param();
$limit = 20;
if (isset($prm['limit'])) {
$limit = trim($prm['limit']);
}
$branchId = $prm['branchId'];
$branchCode = $prm['branchCode'];
$sql = "SELECT distinct OrderPatientID,
downloadLogM_BranchID,
downloadLogM_BranchCode,
downloadLogIsDownloaded,
downloadLogRetry
FROM one_doctor.order_patient
JOIN one_doctor.order_patient_details ON OrderPatientID = OrderPatientDetailsOrderPatientID
AND OrderPatientDetailsIsActive = 'Y'
JOIN m_mou on OrderPatientM_MouID = M_MouID
AND M_MouIsActive = 'Y'
LEFT JOIN one_doctor.download_log ON OrderPatientID = downloadLogOrderPatientID
WHERE OrderPatientIsActive = 'Y'
AND (ISNULL(downloadLogM_BranchID)
OR (downloadLogM_BranchID = ? AND downloadLogIsDownloaded = 'N')
OR (downloadLogM_BranchID <> ? ))
AND (ISNULL(downloadLogRetry) OR downloadLogRetry < 10)
AND OrderPatientID NOT IN (
SELECT downloadLogOrderPatientID
from one_doctor.download_log
WHERE downloadLogM_BranchID = ?
)
GROUP BY OrderPatientID, downloadLogM_BranchID
ORDER BY OrderPatientID
LIMIT ?";
$qry = $this->db_regional->query($sql, [
intval($branchId),
intval($branchId),
intval($branchId),
intval($limit)
]);
if (!$qry) {
$response = ["status" => "ERR", "message" => "select order patient | " .
$this->db_regional->error()["message"], "debug" => $this->db_regional->last_query()];
$this->reply_gz($response);
exit;
}
$rows = $qry->result_array();
$arrOrderPatientId = array();
foreach ($rows as $key => $val) {
$orderPatientId = $val['OrderPatientID'];
if (in_array($orderPatientId, $arrOrderPatientId)) {
continue;
}
$arrOrderPatientId[] = $orderPatientId;
$this->insertDownloadLog($branchId, $branchCode, $orderPatientId);
}
if (count($arrOrderPatientId) > 0) {
$orderPatientIdAll = implode(',', $arrOrderPatientId);
$sqlData = "SELECT order_patient.* , M_MouM_CompanyID FROM one_doctor.order_patient
JOIN m_mou ON OrderPatientM_MouID = M_MouID
AND M_MouIsActive = 'Y'
WHERE OrderPatientID IN ($orderPatientIdAll)
AND OrderPatientIsActive = 'Y'";
$qryData = $this->db_regional->query($sqlData);
if (!$qryData) {
$response = ["status" => "ERR", "message" => "select order patient | " .
$this->db_regional->error()["message"], "debug" => $this->db_regional->last_query()];
$this->reply_gz($response);
exit;
}
$rowsData = $qryData->result_array();
foreach ($rowsData as $key => $value) {
$orderPatientId = $value['OrderPatientID'];
$sqlGetDetail = "SELECT * FROM one_doctor.order_patient_details
WHERE OrderPatientDetailsOrderPatientID = ?
AND OrderPatientDetailsIsActive = 'Y' ";
$qryGetDetail = $this->db_regional->query($sqlGetDetail, [intval($orderPatientId)]);
if (!$qryGetDetail) {
$response = ["status" => "ERR", "message" => "select order patient detail | " .
$this->db_regional->error()["message"], "debug" => $this->db_regional->last_query()];
$this->reply_gz($response);
exit;
}
$rowsgetDetail = $qryGetDetail->result_array();
$rowsData[$key]['details'] = $rowsgetDetail;
// $sqlGetSaran = "SELECT *
// FROM one_doctor.order_saran
// WHERE OrderSaranOrderPatientID = ?
// AND OrderSaranIsActive = 'Y'";
// $qryGetSaran = $this->db->query($sqlGetSaran, [intval($orderPatientId)]);
// if (!$qryGetSaran) {
// $response = ["status" => "ERR", "message" => "select order saran | " .
// $this->db->error()["message"], "debug" => $this->db->last_query()];
// $this->reply_gz($response);
// exit;
// }
// $rowsgetSaran = $qryGetSaran->result_array();
// $rowsData[$key]['saran'] = $rowsgetSaran;
}
$result = array(
'status' => 'OK',
"data" => $rowsData,
);
$this->reply_gz($result);
// $this->reply($result);
} else {
$this->reply_gz("Tidak ada data terbaru");
}
} catch (Exception $exc) {
$message = $exc->getMessage();
$result = array(
'status' => 'err',
"message" => $message,
);
$this->reply_gz($result);
}
}
function insertDownloadLog($branchId, $branchCode, $patientId)
{
$sql = "INSERT INTO one_doctor.download_log
(downloadLogM_BranchID,
downloadLogM_BranchCode,
downloadLogOrderPatientID,
downloadLogRetry)
VALUES
(?,?,?,0) ON DUPLICATE KEY UPDATE downloadLogRetry = downloadLogRetry + 1";
$qry = $this->db_regional->query($sql, [intval($branchId), $branchCode, intval($patientId)]);
if (!$qry) {
$this->sys_error_db(["status" => "ERR", "message" => "select order patient | " .
$this->db_regional->error()["message"], "debug" => $this->db_regional->last_query()]);
exit;
}
}
function updateLog()
{
try {
$prm = $this->get_param_z();
$branchId = $prm['branchId'];
// $branchCde = $prm['branchCode'];
$arrOrderPatientId = $prm['arrOrderPatientId'];
foreach ($arrOrderPatientId as $key => $value) {
$sqlUpdate = "UPDATE one_doctor.download_log SET
downloadLogIsDownloaded = 'Y'
WHERE downloadLogOrderPatientID = ?
AND downloadLogM_BranchID = ?";
$qry = $this->db_regional->query($sqlUpdate, [intval($value), intval($branchId)]);
if (!$qry) {
$this->sys_error_db(["status" => "ERR", "message" => "Insert Log | " .
$this->db_regional->error()["message"], "debug" => $this->db_regional->last_query()]);
exit;
}
}
$result = array(
"message" => 'Berhasil',
"sql" => $this->db_regional->last_query()
);
$this->sys_ok($result);
} catch (Exception $exc) {
$message = $exc->getMessage();
$this->sys_error($message);
}
}
function downloadSaran()
{
try {
$prm = $this->get_param();
$limit = 10;
if (isset($prm['limit'])) {
$limit = trim($prm['limit']);
}
$branchId = $prm['branchId'];
$branchCode = $prm['branchCode'];
$sql = "SELECT * FROM one_doctor.order_saran
LEFT JOIN one_doctor.download_saran_log ON OrderSaranID = downloadSaranLogOrderSaranID
AND downloadSaranLogM_BranchID = ?
WHERE OrderSaranIsActive = 'Y'
AND (
(downloadSaranLogIsDownloaded = 'N' AND downloadSaranLogRetry < 10)
OR ISNULL(downloadSaranLogM_BranchID)
)
LIMIT ?";
$qry = $this->db_regional->query($sql, [intval($branchId), intval($limit)]);
if (!$qry) {
$response = ["status" => "ERR", "message" => "select order saran | " .
$this->db_regional->error()["message"], "debug" => $this->db_regional->last_query()];
// $this->reply_gz($response);
$this->reply($response);
exit;
}
$rows = $qry->result_array();
$arrOrderSaran = array();
// print_r(json_encode($rows));
// exit;
foreach ($rows as $key => $val) {
$orderSaran = $val['OrderSaranID'];
if (in_array($orderSaran, $arrOrderSaran)) {
continue;
}
$arrOrderSaran[] = $orderSaran;
$this->insertDownloadSaranLog($branchId, $branchCode, $orderSaran);
}
if (count($arrOrderSaran) > 0) {
$orderSaranIdAll = implode(',', $arrOrderSaran);
$sqlData = "SELECT * FROM one_doctor.order_saran
WHERE OrderSaranIsActive ='Y'
AND OrderSaranID IN ($orderSaranIdAll)";
$qryData = $this->db_regional->query($sqlData);
if (!$qryData) {
$response = ["status" => "ERR", "message" => "select order saran | " .
$this->db_regional->error()["message"], "debug" => $this->db_regional->last_query()];
// $this->reply($response);
$this->reply_gz($response);
exit;
}
$rowsData = $qryData->result_array();
$result = array(
'status' => 'OK',
"data" => $rowsData,
);
$this->reply_gz($result);
// $this->reply($result);
} else {
$this->reply_gz("Tidak ada data terbaru");
// $this->reply("Tidak ada data terbaru");
}
} catch (Exception $exc) {
$message = $exc->getMessage();
$result = array(
'status' => 'err',
"message" => $message,
);
$this->reply_gz($result);
}
}
function insertDownloadSaranLog($branchId, $branchCode, $saranId)
{
$sql = "INSERT INTO one_doctor.download_saran_log
(downloadSaranLogM_BranchID,
downloadSaranLogM_BranchCode,
downloadSaranLogOrderSaranID,
downloadSaranLogRetry)
VALUES (?, ?, ?,0) ON DUPLICATE KEY UPDATE downloadSaranLogRetry = downloadSaranLogRetry + 1";
$qry = $this->db_regional->query($sql, [intval($branchId), $branchCode, intval($saranId)]);
if (!$qry) {
$resp = ["status" => "ERR", "message" => "insert download saran log | " .
$this->db_regional->error()["message"], "debug" => $this->db_regional->last_query()];
$this->reply_gz($resp);
exit;
}
}
function updateSaranLog()
{
try {
// $prm = $this->get_param();
$prm = $this->get_param_z();
$branchId = $prm['branchId'];
// $branchCde = $prm['branchCode'];
$arrOrderSaranId = $prm['arrOrderSaranId'];
foreach ($arrOrderSaranId as $key => $value) {
$sqlUpdate = "UPDATE one_doctor.download_saran_log
SET downloadSaranLogIsDownloaded = 'Y'
WHERE downloadSaranLogOrderSaranID = ?
AND downloadSaranLogM_BranchID = ?";
$qry = $this->db_regional->query($sqlUpdate, [intval($value), intval($branchId)]);
if (!$qry) {
$this->sys_error_db(["status" => "ERR", "message" => "Insert Log | " .
$this->db_regional->error()["message"], "debug" => $this->db->last_query()]);
exit;
}
}
$result = array(
"message" => 'Berhasil',
"sql" => $this->db_regional->last_query()
);
$this->sys_ok($result);
} catch (Exception $exc) {
$message = $exc->getMessage();
$this->sys_error($message);
}
}
function reply($resp)
{
echo json_encode($resp);
}
function reply_gz($resp)
{
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);
}
}

View File

@@ -0,0 +1,250 @@
<?php
class DownloadPesanKhusus extends MY_Controller
{
var $db;
function __construct()
{
parent::__construct();
$this->db_regional = $this->load->database("regional", true);
}
function index()
{
echo "Api: Download Pesan Khusus";
}
function download()
{
try {
$prm = $this->get_param();
$limit = 20;
if (isset($prm['limit'])) {
$limit = trim($prm['limit']);
}
$branchId = $prm['branchId'];
$branchCode = $prm['branchCode'];
// $sql = "SELECT distinct
// DoctorMessageOrderPatientID as OrderPatientID,
// downloadDoctorMessageLogM_BranchID,
// downloadDoctorMessageLogM_BranchCode,
// downloadDoctorMessageLogIsDownloaded,
// downloadDoctorMessageLogRetry
// from one_doctor.doctor_message
// join one_doctor.order_patient
// ON DoctorMessageOrderPatientID = OrderPatientID
// AND DoctorMessageIsActive = 'Y'
// AND DoctorMessageStatusDownload = 'N'
// JOIN one_doctor.order_patient_details
// ON OrderPatientID = OrderPatientDetailsOrderPatientID
// AND OrderPatientDetailsIsActive = 'Y'
// JOIN m_mou on OrderPatientM_MouID = M_MouID
// AND M_MouIsActive = 'Y'
// LEFT JOIN one_doctor.download_doctor_message_log
// ON OrderPatientID = downloadDoctorMessageLogOrderPatientID
// WHERE OrderPatientIsActive = 'Y'
// AND (
// ISNULL(downloadDoctorMessageLogM_BranchID)
// OR (downloadDoctorMessageLogM_BranchID = ? AND downloadDoctorMessageLogIsDownloaded = 'N')
// OR (downloadDoctorMessageLogM_BranchID <> ? )
// )
// AND (ISNULL(downloadDoctorMessageLogRetry) OR downloadDoctorMessageLogRetry < 10)
// GROUP BY DoctorMessageOrderPatientID, downloadDoctorMessageLogM_BranchID
// ORDER BY DoctorMessageOrderPatientID
// LIMIT ?";
$sql = "SELECT distinct
DoctorMessageOrderPatientID as OrderPatientID,
downloadDoctorMessageLogM_BranchID,
downloadDoctorMessageLogM_BranchCode,
downloadDoctorMessageLogIsDownloaded,
downloadDoctorMessageLogRetry
from one_doctor.doctor_message
join one_doctor.order_patient
ON DoctorMessageOrderPatientID = OrderPatientID
AND DoctorMessageIsActive = 'Y'
AND DoctorMessageStatusDownload = 'N'
JOIN one_doctor.order_patient_details
ON OrderPatientID = OrderPatientDetailsOrderPatientID
AND OrderPatientDetailsIsActive = 'Y'
JOIN m_mou
ON (OrderPatientM_MouID = M_MouID AND M_MouIsActive = 'Y' OR OrderPatientM_MouID = 0)
LEFT JOIN one_doctor.download_doctor_message_log
ON OrderPatientID = downloadDoctorMessageLogOrderPatientID
WHERE OrderPatientIsActive = 'Y'
AND (
ISNULL(downloadDoctorMessageLogM_BranchID)
OR (downloadDoctorMessageLogM_BranchID = ? AND downloadDoctorMessageLogIsDownloaded = 'N')
OR (downloadDoctorMessageLogM_BranchID <> ? )
)
AND (ISNULL(downloadDoctorMessageLogRetry) OR downloadDoctorMessageLogRetry < 10)
GROUP BY DoctorMessageOrderPatientID, downloadDoctorMessageLogM_BranchID
ORDER BY DoctorMessageOrderPatientID
LIMIT ?";
$qry = $this->db_regional->query($sql, [
intval($branchId),
intval($branchId),
intval($limit)
]);
if (!$qry) {
$response = ["status" => "ERR", "message" => "select doctor message | " .
$this->db_regional->error()["message"], "debug" => $this->db_regional->last_query()];
$this->reply_gz($response);
exit;
}
// echo $this->db_regional->last_query();
// exit;
$rows = $qry->result_array();
$arrOrderPatientId = array();
foreach ($rows as $key => $val) {
$orderPatientId = $val['OrderPatientID'];
if (in_array($orderPatientId, $arrOrderPatientId)) {
continue;
}
$arrOrderPatientId[] = $orderPatientId;
$this->insertDownloadLog($branchId, $branchCode, $orderPatientId);
}
if (count($arrOrderPatientId) > 0) {
$orderPatientIdAll = implode(',', $arrOrderPatientId);
// tnp order nasional
$sqlData = "SELECT doctor_message.* , IFNULL(M_MouM_CompanyID,0) as M_MouM_CompanyID
from one_doctor.doctor_message
join one_doctor.order_patient
ON DoctorMessageOrderPatientID = OrderPatientID
AND DoctorMessageIsActive = 'Y'
LEFT JOIN m_mou
ON (OrderPatientM_MouID = M_MouID AND M_MouIsActive = 'Y')
WHERE OrderPatientID IN ($orderPatientIdAll)
AND OrderPatientIsActive = 'Y'";
// $sqlData = "SELECT doctor_message.* , M_MouM_CompanyID
// from one_doctor.doctor_message
// join one_doctor.order_patient
// ON DoctorMessageOrderPatientID = OrderPatientID
// AND DoctorMessageIsActive = 'Y'
// JOIN m_mou ON OrderPatientM_MouID = M_MouID
// AND M_MouIsActive = 'Y'
// WHERE OrderPatientID IN ($orderPatientIdAll)
// AND OrderPatientIsActive = 'Y'";
$qryData = $this->db_regional->query($sqlData);
if (!$qryData) {
$response = ["status" => "ERR", "message" => "select doctor message | " .
$this->db_regional->error()["message"], "debug" => $this->db_regional->last_query()];
$this->reply_gz($response);
exit;
}
$rowsData = $qryData->result_array();
// print_r($rowsData);
// exit;
$result = array(
'status' => 'OK',
"data" => $rowsData,
);
$this->reply_gz($result);
// $this->reply($result);
} else {
$this->reply_gz("Tidak ada data terbaru");
}
} catch (Exception $exc) {
$message = $exc->getMessage();
$result = array(
'status' => 'err',
"message" => $message,
);
$this->reply_gz($result);
}
}
function insertDownloadLog($branchId, $branchCode, $patientId)
{
$sql = "INSERT INTO one_doctor.download_doctor_message_log
(downloadDoctorMessageLogM_BranchID,
downloadDoctorMessageLogM_BranchCode,
downloadDoctorMessageLogOrderPatientID,
downloadDoctorMessageLogRetry)
VALUES
(?,?,?,0) ON DUPLICATE
KEY UPDATE downloadDoctorMessageLogRetry = downloadDoctorMessageLogRetry + 1";
$qry = $this->db_regional->query($sql, [intval($branchId), $branchCode, intval($patientId)]);
if (!$qry) {
$this->sys_error_db(["status" => "ERR", "message" => "select doctor message | " .
$this->db_regional->error()["message"], "debug" => $this->db_regional->last_query()]);
exit;
}
}
function updateLog()
{
try {
$prm = $this->get_param_z();
$branchId = $prm['branchId'];
// $branchCde = $prm['branchCode'];
$arrOrderPatientId = $prm['arrOrderPatientId'];
foreach ($arrOrderPatientId as $key => $value) {
$sqlUpdate = "UPDATE one_doctor.download_doctor_message_log SET
downloadDoctorMessageLogIsDownloaded = 'Y'
WHERE downloadDoctorMessageLogOrderPatientID = ?
AND downloadDoctorMessageLogM_BranchID = ?";
$qry = $this->db_regional->query($sqlUpdate, [intval($value), intval($branchId)]);
if (!$qry) {
$this->sys_error_db(["status" => "ERR", "message" => "Insert download doctor message Log | " .
$this->db_regional->error()["message"], "debug" => $this->db_regional->last_query()]);
exit;
}
// UPDATE doctor_message status_download jadi Y
$sql_update_doctor_message = "UPDATE
one_doctor.doctor_message SET
DoctorMessageStatusDownload = 'Y'
WHERE DoctorMessageOrderPatientID = ?";
$qry_doctor_message = $this->db_regional->query($sql_update_doctor_message, [intval($value)]);
if (!$qry_doctor_message) {
$this->sys_error_db(["status" => "ERR", "message" => "update doctor message status download N | " .
$this->db_regional->error()["message"], "debug" => $this->db_regional->last_query()]);
exit;
}
}
$result = array(
"message" => 'Berhasil',
"sql" => $this->db_regional->last_query()
);
$this->sys_ok($result);
} catch (Exception $exc) {
$message = $exc->getMessage();
$this->sys_error($message);
}
}
function reply($resp)
{
echo json_encode($resp);
}
function reply_gz($resp)
{
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);
}
}

View File

@@ -0,0 +1,204 @@
<?php
class DownloadPesanKhusus extends MY_Controller
{
var $db;
function __construct()
{
parent::__construct();
$this->db_regional = $this->load->database("regional", true);
}
function index()
{
echo "Api: Download Pesan Khusus";
}
function download()
{
try {
$prm = $this->get_param();
$limit = 20;
if (isset($prm['limit'])) {
$limit = trim($prm['limit']);
}
$branchId = $prm['branchId'];
$branchCode = $prm['branchCode'];
$sql = "SELECT distinct
DoctorMessageOrderPatientID as OrderPatientID,
downloadDoctorMessageLogM_BranchID,
downloadDoctorMessageLogM_BranchCode,
downloadDoctorMessageLogIsDownloaded,
downloadDoctorMessageLogRetry
from one_doctor.doctor_message
join one_doctor.order_patient
ON DoctorMessageOrderPatientID = OrderPatientID
AND DoctorMessageIsActive = 'Y'
AND DoctorMessageStatusDownload = 'N'
JOIN one_doctor.order_patient_details
ON OrderPatientID = OrderPatientDetailsOrderPatientID
AND OrderPatientDetailsIsActive = 'Y'
JOIN m_mou on OrderPatientM_MouID = M_MouID
AND M_MouIsActive = 'Y'
LEFT JOIN one_doctor.download_doctor_message_log
ON OrderPatientID = downloadDoctorMessageLogOrderPatientID
WHERE OrderPatientIsActive = 'Y'
AND (
ISNULL(downloadDoctorMessageLogM_BranchID)
OR (downloadDoctorMessageLogM_BranchID = ? AND downloadDoctorMessageLogIsDownloaded = 'N')
OR (downloadDoctorMessageLogM_BranchID <> ? )
)
AND (ISNULL(downloadDoctorMessageLogRetry) OR downloadDoctorMessageLogRetry < 10)
GROUP BY DoctorMessageOrderPatientID, downloadDoctorMessageLogM_BranchID
ORDER BY DoctorMessageOrderPatientID
LIMIT ?";
$qry = $this->db_regional->query($sql, [
intval($branchId),
intval($branchId),
intval($limit)
]);
if (!$qry) {
$response = ["status" => "ERR", "message" => "select doctor message | " .
$this->db_regional->error()["message"], "debug" => $this->db_regional->last_query()];
$this->reply_gz($response);
exit;
}
// echo $this->db_regional->last_query();
// exit;
$rows = $qry->result_array();
$arrOrderPatientId = array();
foreach ($rows as $key => $val) {
$orderPatientId = $val['OrderPatientID'];
if (in_array($orderPatientId, $arrOrderPatientId)) {
continue;
}
$arrOrderPatientId[] = $orderPatientId;
$this->insertDownloadLog($branchId, $branchCode, $orderPatientId);
}
if (count($arrOrderPatientId) > 0) {
$orderPatientIdAll = implode(',', $arrOrderPatientId);
$sqlData = "SELECT doctor_message.* , M_MouM_CompanyID
from one_doctor.doctor_message
join one_doctor.order_patient
ON DoctorMessageOrderPatientID = OrderPatientID
AND DoctorMessageIsActive = 'Y'
JOIN m_mou ON OrderPatientM_MouID = M_MouID
AND M_MouIsActive = 'Y'
WHERE OrderPatientID IN ($orderPatientIdAll)
AND OrderPatientIsActive = 'Y'";
$qryData = $this->db_regional->query($sqlData);
if (!$qryData) {
$response = ["status" => "ERR", "message" => "select doctor message | " .
$this->db_regional->error()["message"], "debug" => $this->db_regional->last_query()];
$this->reply_gz($response);
exit;
}
$rowsData = $qryData->result_array();
$result = array(
'status' => 'OK',
"data" => $rowsData,
);
$this->reply_gz($result);
// $this->reply($result);
} else {
$this->reply_gz("Tidak ada data terbaru");
}
} catch (Exception $exc) {
$message = $exc->getMessage();
$result = array(
'status' => 'err',
"message" => $message,
);
$this->reply_gz($result);
}
}
function insertDownloadLog($branchId, $branchCode, $patientId)
{
$sql = "INSERT INTO one_doctor.download_doctor_message_log
(downloadDoctorMessageLogM_BranchID,
downloadDoctorMessageLogM_BranchCode,
downloadDoctorMessageLogOrderPatientID,
downloadDoctorMessageLogRetry)
VALUES
(?,?,?,0) ON DUPLICATE
KEY UPDATE downloadDoctorMessageLogRetry = downloadDoctorMessageLogRetry + 1";
$qry = $this->db_regional->query($sql, [intval($branchId), $branchCode, intval($patientId)]);
if (!$qry) {
$this->sys_error_db(["status" => "ERR", "message" => "select doctor message | " .
$this->db_regional->error()["message"], "debug" => $this->db_regional->last_query()]);
exit;
}
}
function updateLog()
{
try {
$prm = $this->get_param_z();
$branchId = $prm['branchId'];
// $branchCde = $prm['branchCode'];
$arrOrderPatientId = $prm['arrOrderPatientId'];
foreach ($arrOrderPatientId as $key => $value) {
$sqlUpdate = "UPDATE one_doctor.download_doctor_message_log SET
downloadDoctorMessageLogIsDownloaded = 'Y'
WHERE downloadDoctorMessageLogOrderPatientID = ?
AND downloadDoctorMessageLogM_BranchID = ?";
$qry = $this->db_regional->query($sqlUpdate, [intval($value), intval($branchId)]);
if (!$qry) {
$this->sys_error_db(["status" => "ERR", "message" => "Insert download doctor message Log | " .
$this->db_regional->error()["message"], "debug" => $this->db_regional->last_query()]);
exit;
}
// UPDATE doctor_message status_download jadi Y
$sql_update_doctor_message = "UPDATE
one_doctor.doctor_message SET
DoctorMessageStatusDownload = 'Y'
WHERE DoctorMessageOrderPatientID = ?";
$qry_doctor_message = $this->db_regional->query($sql_update_doctor_message, [intval($value)]);
if (!$qry_doctor_message) {
$this->sys_error_db(["status" => "ERR", "message" => "update doctor message status download N | " .
$this->db_regional->error()["message"], "debug" => $this->db_regional->last_query()]);
exit;
}
}
$result = array(
"message" => 'Berhasil',
"sql" => $this->db_regional->last_query()
);
$this->sys_ok($result);
} catch (Exception $exc) {
$message = $exc->getMessage();
$this->sys_error($message);
}
}
function reply($resp)
{
echo json_encode($resp);
}
function reply_gz($resp)
{
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);
}
}

View File

@@ -0,0 +1,296 @@
<?php
class R_xfer_doctormessage_nasional extends MY_Controller
{
var $db;
function __construct()
{
parent::__construct();
$this->db_regional = $this->load->database("regional", true);
}
function index()
{
echo "Api: R_xfer_order_nasional";
}
function get($url, $timeout = 60, $c_timeout = 5)
{
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, $c_timeout);
curl_setopt($ch, CURLOPT_TIMEOUT, $timeout);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$result = curl_exec($ch);
$err_msg = curl_error($ch);
if ($err_msg != "") {
return json_encode(["status" => "ERR", "message" => $err_msg]);
}
return $result;
}
function reply_err($message)
{
echo json_encode(["status" => "ERR", "data" => $message]);
exit();
}
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;
}
function log($msg)
{
// $dt = Date("Y-m-d H:i:s");
// echo "$dt $msg \n";
echo $msg;
}
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));
}
function get_param()
{
$body = file_get_contents("php://input");
return json_decode($body, true);
}
//
function receive_order()
{
$receive_data_order = $this->sys_input;
try {
// echo json_encode([
// "status" => "OK",
// "data" => $receive_data_order['order'],
// "msg" => "123"
// ]);
if (count($receive_data_order) > 0) {
$not_exists_map_rx_order = 0;
$originIpAddress = "";
$originRegionalID = "";
$S_RegionalIPAddress_Tujuan = "";
$proses = "";
$M_DoctorNasCode = "";
// untuk order_patient_new
$order_id = "";
$originIpAddress = ($receive_data_order['originIpAddress'] !== null || $receive_data_order['originIpAddress'] !== "null" || $receive_data_order['originIpAddress'] !== "") ? "{$receive_data_order['originIpAddress']}" : "";
$originRegionalID = ($receive_data_order['originRegionalID'] !== null || $receive_data_order['originRegionalID'] !== "null" || $receive_data_order['originRegionalID'] !== "") ? "{$receive_data_order['originRegionalID']}" : "";
$S_RegionalIPAddress_Tujuan = ($receive_data_order['S_RegionalIPAddress'] !== null || $receive_data_order['S_RegionalIPAddress'] !== "null" || $receive_data_order['S_RegionalIPAddress'] !== "") ? "{$receive_data_order['S_RegionalIPAddress']}" : "";
$M_DoctorNasCode = ($receive_data_order['M_DoctorNasCode'] !== null || $receive_data_order['M_DoctorNasCode'] !== "null" || $receive_data_order['M_DoctorNasCode'] !== "") ? "{$receive_data_order['M_DoctorNasCode']}" : "";
// // echo json_encode(
// // [
// // "status" => "OK",
// // "data" => $OrderPatientDOB
// // ]
// // );
// table order_patient dan table order_patient_details
if ($receive_data_order['order'] && count($receive_data_order['order']) > 0) {
foreach ($receive_data_order['order'] as $key => $vx) {
// cek sudah ada order di order_patient blm (lookup dari map_rx_order)
$sql_get_map_rx_order = "
SELECT
mapRxOrderOriginOrderPatientID,
mapRxOrderOriginRegionalID,
mapRxOrderOriginIPAddress,
mapRxOrderNewOrderPatientID
from one_doctor.map_rx_order
WHERE
mapRxOrderOriginOrderPatientID = '{$vx['OrderPatientID']}'
AND mapRxOrderOriginRegionalID = '$originRegionalID'
AND mapRxOrderOriginIPAddress = '$originIpAddress'
AND mapRxOrderIsActive = 'Y'
AND mapRxOrderIsSent = 'Y'
";
$qry_get_map_rx_order = $this->db_regional->query($sql_get_map_rx_order);
if (!$qry_get_map_rx_order) {
$response = ["status" => "ERR", "message" => "select map_rx_order | " .
$this->db_regional->error()["message"], "debug" => $this->db_regional->last_query()];
$this->sys_error($response);
exit;
}
$last_query = $this->db_regional->last_query();
$rows_get_map_rx_order = $qry_get_map_rx_order->result_array();
// 1. sudah ada map_rx_order
if (count($rows_get_map_rx_order) > 0) {
// update doctor_message
if ($receive_data_order['order'][$key]['doctor_message'] && count($receive_data_order['order'][$key]['doctor_message']) > 0) {
foreach ($receive_data_order['order'][$key]['doctor_message'] as $keys => $value) {
$DoctorMessagePesan = $value['DoctorMessagePesan'];
$DoctorMessageStatusDownload = $value['DoctorMessageStatusDownload'];
$DoctorMessageIsActive = $value['DoctorMessageIsActive'];
$DoctorMessageUserID = $value['DoctorMessageUserID'];
$DoctorMessageCreated = $value['DoctorMessageCreated'];
$sql_cek_doctor_msg = "
SELECT *
from one_doctor.doctor_message
WHERE DoctorMessageIsActive = 'Y'
AND DoctorMessageOrderPatientID = ?
";
$qry_cek_doctor_msg = $this->db_regional->query($sql_cek_doctor_msg, [
$rows_get_map_rx_order[0]['mapRxOrderNewOrderPatientID']
]);
if (!$qry_cek_doctor_msg) {
$this->db_regional->trans_rollback();
$this->sys_error("Error select doctor_message");
exit;
}
$last_query = $this->db_regional->last_query();
$rows_cek_doctor_msg = $qry_cek_doctor_msg->result_array();
// print_r($rows_cek_doctor_msg);
// exit;
// sudah ada update
if (count($rows_cek_doctor_msg) > 0) {
$proses = "Diperbaharui";
// update doctor message
$sql = "UPDATE
one_doctor.doctor_message
SET
DoctorMessageOrderPatientID = ?,
DoctorMessagePesan = ?,
DoctorMessageStatusDownload = ?,
DoctorMessageIsActive = ?,
DoctorMessageUserID = ?,
DoctorMessageCreated = ?
WHERE
DoctorMessageOrderPatientID = '{$rows_get_map_rx_order[0]['mapRxOrderNewOrderPatientID']}'
AND DoctorMessageIsActive = 'Y'";
$query = $this->db_regional->query($sql, [
$rows_get_map_rx_order[0]['mapRxOrderNewOrderPatientID'],
$DoctorMessagePesan,
$DoctorMessageStatusDownload,
$DoctorMessageIsActive,
$DoctorMessageUserID,
$DoctorMessageCreated
]);
if (!$query) {
$this->db_regional->trans_rollback();
$this->sys_error("Error update doctor_message");
exit;
}
} else {
// insert doctor_message
$order_id = $rows_get_map_rx_order[0]['mapRxOrderNewOrderPatientID'];
$proses = "Ditambahkan";
$sql = "INSERT INTO one_doctor.doctor_message (
DoctorMessageOrderPatientID,
DoctorMessagePesan,
DoctorMessageStatusDownload,
DoctorMessageIsActive,
DoctorMessageUserID,
DoctorMessageCreated
)
VALUES(
?,
?,
?,
?,
?,
NOW()
)";
$query = $this->db_regional->query(
$sql,
array(
$order_id,
$value['DoctorMessagePesan'],
$value['DoctorMessageStatusDownload'],
$value['DoctorMessageIsActive'],
$value['DoctorMessageUserID']
)
);
if (!$query) {
$this->db_regional->trans_rollback();
$this->sys_error("Error insert doctor_message");
exit;
}
}
}
}
}
// 2. belum ada map_rx_order
else {
$not_exists_map_rx_order++;
}
}
}
if($not_exists_map_rx_order == 0){
echo json_encode(
[
"status" => "OK",
"data" => $receive_data_order,
"message" => "Data Doctor Message Berhasil $proses dan dikirim dari $originIpAddress ke $S_RegionalIPAddress_Tujuan"
]
);
}else{
echo json_encode(
[
"status" => "ERR",
"data" => $receive_data_order,
"message" => "Belum Ada Mapping Order ID New Map Rx Order"
]
);
}
}
} catch (Exception $exc) {
$message = $exc->getMessage();
$this->sys_error($message);
}
}
}

View File

@@ -0,0 +1,484 @@
<?php
class R_xfer_order_nasional extends MY_Controller
{
var $db;
function __construct()
{
parent::__construct();
$this->db_regional = $this->load->database("regional", true);
}
function index()
{
echo "Api: R_xfer_order_nasional";
}
function get($url, $timeout = 60, $c_timeout = 5)
{
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, $c_timeout);
curl_setopt($ch, CURLOPT_TIMEOUT, $timeout);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$result = curl_exec($ch);
$err_msg = curl_error($ch);
if ($err_msg != "") {
return json_encode(["status" => "ERR", "message" => $err_msg]);
}
return $result;
}
function reply_err($message)
{
echo json_encode(["status" => "ERR", "data" => $message]);
exit();
}
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;
}
function log($msg)
{
// $dt = Date("Y-m-d H:i:s");
// echo "$dt $msg \n";
echo $msg;
}
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));
}
function get_param()
{
$body = file_get_contents("php://input");
return json_decode($body, true);
}
//
function receive_order()
{
$receive_data_order = $this->sys_input;
try {
// echo json_encode([
// "status" => "OK",
// "data" => $receive_data_order['order'],
// "msg" => "123"
// ]);
if (count($receive_data_order) > 0) {
$originIpAddress = "";
$originRegionalID = "";
$S_RegionalIPAddress_Tujuan = "";
$proses = "";
$M_DoctorNasCode = "";
// untuk order_patient_new
$order_id = "";
$originIpAddress = ($receive_data_order['originIpAddress'] !== null || $receive_data_order['originIpAddress'] !== "null" || $receive_data_order['originIpAddress'] !== "") ? "{$receive_data_order['originIpAddress']}" : "";
$originRegionalID = ($receive_data_order['originRegionalID'] !== null || $receive_data_order['originRegionalID'] !== "null" || $receive_data_order['originRegionalID'] !== "") ? "{$receive_data_order['originRegionalID']}" : "";
$S_RegionalIPAddress_Tujuan = ($receive_data_order['S_RegionalIPAddress'] !== null || $receive_data_order['S_RegionalIPAddress'] !== "null" || $receive_data_order['S_RegionalIPAddress'] !== "") ? "{$receive_data_order['S_RegionalIPAddress']}" : "";
$M_DoctorNasCode = ($receive_data_order['M_DoctorNasCode'] !== null || $receive_data_order['M_DoctorNasCode'] !== "null" || $receive_data_order['M_DoctorNasCode'] !== "") ? "{$receive_data_order['M_DoctorNasCode']}" : "";
// // echo json_encode(
// // [
// // "status" => "OK",
// // "data" => $OrderPatientDOB
// // ]
// // );
// table order_patient dan table order_patient_details
if ($receive_data_order['order'] && count($receive_data_order['order']) > 0) {
foreach ($receive_data_order['order'] as $key => $vx) {
$OrderPatientM_DoctorID_Receiver = "";
// di set 0 karena aggrement tiap regional bisa beda-beda
$OrderPatientM_MouID = "0";
$OrderPatientDate = $vx['OrderPatientDate'];
$OrderPatientQrCode = $vx['OrderPatientQrCode'];
$OrderPatientFullName = $vx['OrderPatientFullName'];
$OrderPatientDOB = $vx['OrderPatientDOB'];
$OrderPatientAddress = $vx['OrderPatientAddress'];
$OrderPatientNIK = $vx['OrderPatientNIK'];
$OrderPatientHp = $vx['OrderPatientHp'];
$OrderPatientDiagnosa = $vx['OrderPatientDiagnosa'];
$OrderPatientNote = $vx['OrderPatientNote'];
$OrderPatientIsConfirmed = $vx['OrderPatientIsConfirmed'];
$OrderPatientIsActive = $vx['OrderPatientIsActive'];
$OrderPatientUserID = $vx['OrderPatientUserID'];
$OrderPatientCreated = $vx['OrderPatientCreated'];
$sql_get_doctor_receive = "
SELECT M_DoctorNasM_DoctorID
from m_doctornas
WHERE M_DoctorNasCode = '$M_DoctorNasCode'
AND M_DoctorNasIsActive = 'Y'
";
$qry_get_doctor_receive = $this->db_regional->query($sql_get_doctor_receive);
if (!$qry_get_doctor_receive) {
$response = ["status" => "ERR", "message" => "select order patient | " .
$this->db_regional->error()["message"], "debug" => $this->db_regional->last_query()];
$this->sys_error($response);
exit;
}
$last_query = $this->db_regional->last_query();
$rows_get_doctor_receive = $qry_get_doctor_receive->result_array();
// print_r($rows_get_doctor_receive);
// exit;
if (count($rows_get_doctor_receive) > 0) {
$OrderPatientM_DoctorID_Receiver = $rows_get_doctor_receive[0]['M_DoctorNasM_DoctorID'];
}
// cek sudah ada order di order_patient blm (lookup dari map_rx_order)
$sql_get_map_rx_order = "
SELECT
mapRxOrderOriginOrderPatientID,
mapRxOrderOriginRegionalID,
mapRxOrderOriginIPAddress,
mapRxOrderNewOrderPatientID
from one_doctor.map_rx_order
WHERE
mapRxOrderOriginOrderPatientID = '{$vx['OrderPatientID']}'
AND mapRxOrderOriginRegionalID = '$originRegionalID'
AND mapRxOrderOriginIPAddress = '$originIpAddress'
AND mapRxOrderIsActive = 'Y'
AND mapRxOrderIsSent = 'N'
";
$qry_get_map_rx_order = $this->db_regional->query($sql_get_map_rx_order);
if (!$qry_get_map_rx_order) {
$response = ["status" => "ERR", "message" => "select map_rx_order | " .
$this->db_regional->error()["message"], "debug" => $this->db_regional->last_query()];
$this->sys_error($response);
exit;
}
$last_query = $this->db_regional->last_query();
$rows_get_map_rx_order = $qry_get_map_rx_order->result_array();
// 1. sudah ada map_rx_order
if (count($rows_get_map_rx_order) > 0) {
$proses = "Diperbaharui";
$sql_update_order_patient = "UPDATE
one_doctor.order_patient
SET
OrderPatientM_DoctorID = ?,
OrderPatientDate = ?,
OrderPatientM_MouID = ?,
OrderPatientQrCode = ?,
OrderPatientFullName = ?,
OrderPatientDOB = ?,
OrderPatientAddress = ?,
OrderPatientNIK = ?,
OrderPatientHp = ?,
OrderPatientDiagnosa = ?,
OrderPatientNote = ?,
OrderPatientIsConfirmed = ?,
OrderPatientIsActive = ?,
OrderPatientUserID = ?,
OrderPatientCreated = ?
WHERE
OrderPatientID = '{$rows_get_map_rx_order[0]['mapRxOrderNewOrderPatientID']}'
AND OrderPatientIsActive = 'Y'
";
$qry_update_order_patient = $this->db_regional->query($sql_update_order_patient, [
$OrderPatientM_DoctorID_Receiver,
$OrderPatientDate,
$OrderPatientM_MouID,
$OrderPatientQrCode,
$OrderPatientFullName,
$OrderPatientDOB,
$OrderPatientAddress,
$OrderPatientNIK,
$OrderPatientHp,
$OrderPatientDiagnosa,
$OrderPatientNote,
$OrderPatientIsConfirmed,
$OrderPatientIsActive,
$OrderPatientUserID,
$OrderPatientCreated
]);
if (!$qry_update_order_patient) {
$response = ["status" => "ERR", "message" => "update order patient | " .
$this->db_regional->error()["message"], "debug" => $this->db_regional->last_query()];
$this->sys_error($response);
exit;
}
// update order_details
if ($receive_data_order['order']['details'] && count($receive_data_order['order']['details']) > 0) {
foreach ($receive_data_order['order']['details'] as $key => $value) {
$sql = "UPDATE
one_doctor.order_patient_details
SET
OrderPatientDetailsT_TestID = '{$value['OrderPatientDetailsT_TestID']}',
OrderPatientDetailsT_TestName = '{$value['OrderPatientDetailsT_TestName']}',
OrderPatientDetailsPrice = '{$value['prOrderPatientDetailsPriceice']}',
OrderPatientDetailsUserID = '{$value['OrderPatientDetailsUserID']}',
OrderPatientDetailsCreated = '{$value['OrderPatientDetailsCreated']}',
WHERE
OrderPatientDetailsOrderPatientID = '{$rows_get_map_rx_order[0]['mapRxOrderNewOrderPatientID']}'
AND OrderPatientDetailsIsActive = 'Y'";
$query = $this->db_regional->query($sql, array());
if (!$query) {
$this->db_regional->trans_rollback();
$this->sys_error("Error update order_detail");
exit;
}
}
}
// insert or update order saran jk OrderPatientID sudah ada
if ($receive_data_order['order']['order_saran'] && count($receive_data_order['order']['order_saran']) > 0) {
foreach ($receive_data_order['order']['order_saran'] as $key => $value) {
$sql_cek_order_saran = "
SELECT *
FROM one_doctor.order_saran
WHERE OrderSaranOrderPatientID ='{$rows_get_map_rx_order[0]['mapRxOrderNewOrderPatientID']}'
AND OrderSaranIsActive = 'Y'";
$qry_cek_order_saran = $this->db_regional->query($sql_cek_order_saran);
if (!$qry_cek_order_saran) {
$this->db_regional->trans_rollback();
$this->sys_error("Error cek order_saran");
exit;
}
$rows_cek_order_saran = $qry_cek_order_saran->result_array();
if(count($rows_cek_order_saran) == 0){
// insert
$sql = "INSERT INTO one_doctor.order_saran (
OrderSaranOrderPatientID,
OrderKesimpulan,
OrderSaran,
OrderSaranIsActive,
OrderSaranUserID,
OrderSaranCreated
)
VALUES(
?,?,?,?,?,NOW()
)";
$query = $this->db_regional->query($sql, array(
$order_id,
$value['OrderKesimpulan'],
$value['OrderSaran'],
$value['OrderSaranIsActive'],
$value['OrderSaranUserID']
));
if (!$query) {
$this->db_regional->trans_rollback();
$this->sys_error("Error insert order_saran");
exit;
}
}
else
{
// update saran
$sql = "UPDATE
one_doctor.order_saran
SET
OrderKesimpulan = '{$value['OrderKesimpulan']}',
OrderSaran = '{$value['OrderSaran']}',
OrderSaranIsActive = '{$value['OrderSaranIsActive']}',
OrderSaranUserID = '{$value['OrderSaranUserID']}',
OrderSaranCreated = '{$value['OrderSaranCreated']}'
WHERE
OrderSaranOrderPatientID = '{$rows_get_map_rx_order[0]['mapRxOrderNewOrderPatientID']}'
AND OrderSaranIsActive = 'Y'";
$query = $this->db_regional->query($sql, array());
if (!$query) {
$this->db_regional->trans_rollback();
$this->sys_error("Error update order_saran");
exit;
}
}
}
}
}
// 2. belum ada map_rx_order
else {
$proses = "Ditambahkan";
// insert ke order_patient
$sql_insert_order_patient = "INSERT INTO one_doctor.order_patient(
OrderPatientM_DoctorID,
OrderPatientDate,
OrderPatientM_MouID,
OrderPatientQrCode,
OrderPatientFullName,
OrderPatientDOB,
OrderPatientAddress,
OrderPatientNIK,
OrderPatientHp,
OrderPatientDiagnosa,
OrderPatientNote,
OrderPatientIsConfirmed,
OrderPatientIsActive,
OrderPatientUserID,
OrderPatientCreated
) VALUES (
?,
?,
?,
?,
?,
?,
?,
?,
?,
?,
?,
?,
?,
?,
?
)
";
$qry_insert_order_patient = $this->db_regional->query($sql_insert_order_patient, [
$OrderPatientM_DoctorID_Receiver,
$OrderPatientDate,
$OrderPatientM_MouID,
$OrderPatientQrCode,
$OrderPatientFullName,
$OrderPatientDOB,
$OrderPatientAddress,
$OrderPatientNIK,
$OrderPatientHp,
$OrderPatientDiagnosa,
$OrderPatientNote,
$OrderPatientIsConfirmed,
$OrderPatientIsActive,
$OrderPatientUserID,
$OrderPatientCreated
]);
if (!$qry_insert_order_patient) {
$response = ["status" => "ERR", "message" => "insert order patient | " .
$this->db_regional->error()["message"], "debug" => $this->db_regional->last_query()];
$this->sys_error($response);
exit;
}
$order_id = $this->db_regional->insert_id();
// insert ke order_details
if ($receive_data_order['order'][$key]['details'] && count($receive_data_order['order'][$key]['details']) > 0) {
foreach ($receive_data_order['order'][$key]['details'] as $keys => $value) {
$sql = "INSERT INTO one_doctor.order_patient_details (
OrderPatientDetailsOrderPatientID,
OrderPatientDetailsT_TestID,
OrderPatientDetailsT_TestName,
OrderPatientDetailsPrice,
OrderPatientDetailsUserID,
OrderPatientDetailsCreated
)
VALUES(
?,?,?,?,?,NOW()
)";
$query = $this->db_regional->query($sql, array(
$order_id,
$value['OrderPatientDetailsT_TestID'],
$value['OrderPatientDetailsT_TestName'],
$value['OrderPatientDetailsPrice'],
$value['OrderPatientDetailsUserID']
));
if (!$query) {
$this->db_regional->trans_rollback();
$this->sys_error("Error insert order_detail");
exit;
}
}
}
// insert ke map_rx_order
$sql_insert_map_rx_order = "INSERT INTO one_doctor.map_rx_order(
mapRxOrderOriginOrderPatientID,
mapRxOrderNewOrderPatientID,
mapRxOrderOriginRegionalID,
mapRxOrderOriginIPAddress,
mapRxOrderIsSent,
mapRxOrderCreated
) VALUES (
'{$vx['OrderPatientID']}',
'$order_id',
'$originRegionalID',
'$originIpAddress',
'N',
NOW()
)
";
$qry_insert_map_rx_order = $this->db_regional->query($sql_insert_map_rx_order);
if (!$qry_insert_map_rx_order) {
$response = ["status" => "ERR", "message" => "insert map_rx_order | " .
$this->db_regional->error()["message"], "debug" => $this->db_regional->last_query()];
$this->sys_error($response);
exit;
}
}
}
}
echo json_encode(
[
"status" => "OK",
"data" => $receive_data_order,
"message" => "Data Berhasil $proses dan dikirim dari $originIpAddress ke $S_RegionalIPAddress_Tujuan"
]
);
}
} catch (Exception $exc) {
$message = $exc->getMessage();
$this->sys_error($message);
}
}
}

View File

@@ -0,0 +1,166 @@
<?php
class R_xfer_result_nasional extends MY_Controller
{
var $db;
function __construct()
{
parent::__construct();
}
function index()
{
echo "Api: REGIONAL SEND RESULT RECEIVE DATA ";
}
function receive()
{
try {
$this->db->trans_begin();
// $prm = $this->sys_input;
$prm = $this->get_param_z();
// $this->reply_gz($prm);
// echo json_encode($prm);
// exit;
$ipAddress = $prm['IP'];
$order_success = array();
if ($prm['status'] == 'OK') {
$order = $prm['order'];
for ($i = 0; $i < count($order); $i++) {
//cek
$sql_cek = "SELECT *
FROM one_doctor.one_result
WHERE oneResultOrderPatientID = ?";
$qry_cek = $this->db->query($sql_cek, [
$order[$i]['mapRxOrderOriginOrderPatientID'],
]);
if (!$qry_cek) {
$message = $this->db->error();
$err = array(
"status" => "ERR",
"IP" => $ipAddress,
"message" => $message
);
$this->reply_gz($err);
$this->db->trans_rollback();
exit;
}
$rst_cek = $qry_cek->result_array();
$lastqry = [];
// $this->sys_ok(count($rst_cek));
// exit;
//insert
if (count($rst_cek) == 0) {
$sql = "INSERT INTO one_doctor.one_result(
oneResultOrderPatientID,
oneResultOrderM_BranchCode,
oneResultOrderM_BranchID,
oneResultJson,
oneResultDate,
oneResultLastUpdated
)VALUES(?, ?, ?, ?, ?, ?)";
$qry = $this->db->query($sql, [
$order[$i]['mapRxOrderOriginOrderPatientID'],
$order[$i]['oneResultOrderM_BranchCode'],
$order[$i]['oneResultOrderM_BranchID'],
$order[$i]['oneResultJson'],
$order[$i]['oneResultDate'],
$order[$i]['oneResultLastUpdated'],
]);
if (!$qry) {
$message = $this->db->error();
$err = array(
"status" => "ERR",
"IP" => $ipAddress,
"message" => $message
);
$this->reply_gz($err);
$this->db->trans_rollback();
exit;
}
$order_success[] = $order[$i]['mapRxOrderNewOrderPatientID'];
} else {
$sql_update = "UPDATE one_doctor.one_result
SET oneResultJson = ?
WHERE oneResultOrderPatientID = ?";
$qry_update = $this->db->query($sql_update, [
$order[$i]['oneResultJson'],
$order[$i]['mapRxOrderOriginOrderPatientID'],
]);
if (!$qry_update) {
$message = $this->db->error();
$err = array(
"status" => "ERR",
"IP" => $ipAddress,
"message" => $message
);
$this->reply_gz($err);
$this->db->trans_rollback();
exit;
}
$order_success[] = $order[$i]['mapRxOrderNewOrderPatientID'];
}
// update order
$sql_update = "UPDATE
one_doctor.order_patient
SET OrderPatientFullName = ?,
OrderPatientDOB = ?,
OrderPatientNIK = ?,
OrderPatientHp = ?,
OrderPatientAddress = ?,
OrderPatientIsConfirmed = 'Y'
WHERE OrderPatientID = ?
";
$query_update = $this->db->query($sql_update, [
$order[$i]['OrderPatientFullName'],
$order[$i]['OrderPatientDOB'],
$order[$i]['OrderPatientNIK'],
$order[$i]['OrderPatientHp'],
$order[$i]['OrderPatientAddress'],
$order[$i]['mapRxOrderOriginOrderPatientID']
]);
if (!$query_update) {
$message = $this->db->error();
$err = array(
"status" => "ERR",
"IP" => $ipAddress,
"message" => $message
);
$this->reply_gz($err);
$this->db->trans_rollback();
exit;
}
}
}
$this->db->trans_commit();
$rst = array(
"status" => "OK",
"order_success" => $order_success,
"message" => "Berhasil di proses di {$ipAddress}"
);
$this->reply_gz($rst);
// echo json_encode($prm);
} 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($resp)
{
echo json_encode($resp);
}
function reply_gz($resp)
{
//echo json_encode($resp);
echo gzcompress(json_encode($resp));
}
}

View File

@@ -0,0 +1,392 @@
<?php
class R_xfer_saran_nasional extends MY_Controller
{
var $db;
function __construct()
{
parent::__construct();
$this->db_regional = $this->load->database("regional", true);
}
function index()
{
echo "Api: R_xfer_saran_nasional";
}
function get($url, $timeout = 60, $c_timeout = 5)
{
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, $c_timeout);
curl_setopt($ch, CURLOPT_TIMEOUT, $timeout);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$result = curl_exec($ch);
$err_msg = curl_error($ch);
if ($err_msg != "") {
return json_encode(["status" => "ERR", "message" => $err_msg]);
}
return $result;
}
function reply_err($message)
{
echo json_encode(["status" => "ERR", "data" => $message]);
exit();
}
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;
}
function log($msg)
{
// $dt = Date("Y-m-d H:i:s");
// echo "$dt $msg \n";
echo $msg;
}
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));
}
function get_param()
{
$body = file_get_contents("php://input");
return json_decode($body, true);
}
//
function receive_order()
{
$receive_data_order = $this->sys_input;
try {
// echo json_encode([
// "status" => "OK",
// "data" => $receive_data_order['order'],
// "msg" => "123"
// ]);
if (count($receive_data_order) > 0) {
$not_exists_map_rx_order = 0;
$originIpAddress = "";
$originRegionalID = "";
$S_RegionalIPAddress_Tujuan = "";
$proses = "";
$M_DoctorNasCode = "";
// untuk order_patient_new
$order_id = "";
$originIpAddress = ($receive_data_order['originIpAddress'] !== null || $receive_data_order['originIpAddress'] !== "null" || $receive_data_order['originIpAddress'] !== "") ? "{$receive_data_order['originIpAddress']}" : "";
$originRegionalID = ($receive_data_order['originRegionalID'] !== null || $receive_data_order['originRegionalID'] !== "null" || $receive_data_order['originRegionalID'] !== "") ? "{$receive_data_order['originRegionalID']}" : "";
$S_RegionalIPAddress_Tujuan = ($receive_data_order['S_RegionalIPAddress'] !== null || $receive_data_order['S_RegionalIPAddress'] !== "null" || $receive_data_order['S_RegionalIPAddress'] !== "") ? "{$receive_data_order['S_RegionalIPAddress']}" : "";
$M_DoctorNasCode = ($receive_data_order['M_DoctorNasCode'] !== null || $receive_data_order['M_DoctorNasCode'] !== "null" || $receive_data_order['M_DoctorNasCode'] !== "") ? "{$receive_data_order['M_DoctorNasCode']}" : "";
// // echo json_encode(
// // [
// // "status" => "OK",
// // "data" => $OrderPatientDOB
// // ]
// // );
// table order_patient dan table order_patient_details
if ($receive_data_order['order'] && count($receive_data_order['order']) > 0) {
foreach ($receive_data_order['order'] as $key => $vx) {
// cek sudah ada order di order_patient blm (lookup dari map_rx_order)
$sql_get_map_rx_order = "
SELECT
mapRxOrderOriginOrderPatientID,
mapRxOrderOriginRegionalID,
mapRxOrderOriginIPAddress,
mapRxOrderNewOrderPatientID
from one_doctor.map_rx_order
WHERE
mapRxOrderOriginOrderPatientID = '{$vx['OrderPatientID']}'
AND mapRxOrderOriginRegionalID = '$originRegionalID'
AND mapRxOrderOriginIPAddress = '$originIpAddress'
AND mapRxOrderIsActive = 'Y'
AND mapRxOrderIsSent = 'Y'
";
$qry_get_map_rx_order = $this->db_regional->query($sql_get_map_rx_order);
if (!$qry_get_map_rx_order) {
$response = ["status" => "ERR", "message" => "select map_rx_order | " .
$this->db_regional->error()["message"], "debug" => $this->db_regional->last_query()];
$this->sys_error($response);
exit;
}
$last_query = $this->db_regional->last_query();
$rows_get_map_rx_order = $qry_get_map_rx_order->result_array();
// 1. sudah ada map_rx_order
if (count($rows_get_map_rx_order) > 0) {
// update order_saran
if ($receive_data_order['order'][$key]['order_saran'] && count($receive_data_order['order'][$key]['order_saran']) > 0) {
foreach ($receive_data_order['order'][$key]['order_saran'] as $keys => $value) {
$OrderKesimpulan = $value['OrderKesimpulan'];
$OrderSaran = $value['OrderSaran'];
$OrderSaranIsActive = $value['OrderSaranIsActive'];
$OrderSaranUserID = $value['OrderSaranUserID'];
$OrderSaranCreated = $value['OrderSaranCreated'];
$sql_cek_order_saran = "
SELECT *
from one_doctor.order_saran
WHERE OrderSaranIsActive = 'Y'
AND OrderSaranOrderPatientID = ?
";
$qry_cek_order_saran = $this->db_regional->query($sql_cek_order_saran, [
$rows_get_map_rx_order[0]['mapRxOrderNewOrderPatientID']
]);
if (!$qry_cek_order_saran) {
$this->db_regional->trans_rollback();
$this->sys_error("Error select doctor_message");
exit;
}
$last_query = $this->db_regional->last_query();
$rows_order_saran = $qry_cek_order_saran->result_array();
// print_r($rows_order_saran);
// exit;
// sudah ada update
if (count($rows_order_saran) > 0) {
$proses = "Diperbaharui";
// update saran
$sql = "UPDATE
one_doctor.order_saran
SET
OrderSaranOrderPatientID = ?,
OrderKesimpulan = ?,
OrderSaran = ?,
OrderSaranIsActive = ?,
OrderSaranUserID = ?,
OrderSaranCreated = ?
WHERE
OrderSaranOrderPatientID = '{$rows_get_map_rx_order[0]['mapRxOrderNewOrderPatientID']}'
AND OrderSaranIsActive = 'Y'";
$query = $this->db_regional->query($sql, [
$rows_get_map_rx_order[0]['mapRxOrderNewOrderPatientID'],
$OrderKesimpulan,
$OrderSaran,
$OrderSaranIsActive,
$OrderSaranUserID,
$OrderSaranCreated
]);
if (!$query) {
$this->db_regional->trans_rollback();
$this->sys_error("Error update order_saran");
exit;
}
if (
$receive_data_order['order'][$key]['order_saran'][$keys]['saran_log']
&& count($receive_data_order['order'][$key]['order_saran'][$keys]['saran_log']) > 0
) {
foreach ($receive_data_order['order'][$key]['order_saran'][$keys]['saran_log'] as $keyslog => $valuelog) {
$saran_id = $rows_order_saran[0]['OrderSaranID'];
// download saran log
$downloadSaranLogM_BranchID = $valuelog['downloadSaranLogM_BranchID'];
$downloadSaranLogM_BranchCode = $valuelog['downloadSaranLogM_BranchCode'];
$downloadSaranLogIsDownloaded = $valuelog['downloadSaranLogIsDownloaded'];
$downloadSaranLogRetry = $valuelog['downloadSaranLogRetry'];
// update saran log
$sql_update_saran_log = "UPDATE
one_doctor.download_saran_log
SET
downloadSaranLogOrderSaranID = ?,
downloadSaranLogM_BranchID = ?,
downloadSaranLogM_BranchCode = ?,
downloadSaranLogIsDownloaded = ?,
downloadSaranLogRetry = ?
WHERE
downloadSaranLogOrderSaranID = $saran_id
";
$query = $this->db_regional->query($sql_update_saran_log, [
$saran_id,
$downloadSaranLogM_BranchID,
$downloadSaranLogM_BranchCode,
$downloadSaranLogIsDownloaded,
$downloadSaranLogRetry
]);
if (!$query) {
$this->db_regional->trans_rollback();
// $this->sys_error("Error update order_saran_log");
$response = ["status" => "ERR", "message" => "Error update order_saran_log | " .
$this->db_regional->error()["message"], "debug" => $this->db_regional->last_query()];
$this->sys_error($response);
exit;
}
}
}
} else {
// insert order_saran
$order_id = $rows_get_map_rx_order[0]['mapRxOrderNewOrderPatientID'];
$proses = "Ditambahkan";
$sql = "INSERT INTO one_doctor.order_saran (
OrderSaranOrderPatientID,
OrderKesimpulan,
OrderSaran,
OrderSaranIsActive,
OrderSaranUserID,
OrderSaranCreated
)
VALUES(
?,
?,
?,
?,
?,
NOW()
)";
$query = $this->db_regional->query(
$sql,
array(
$order_id,
$value['OrderKesimpulan'],
$value['OrderSaran'],
$value['OrderSaranIsActive'],
$value['OrderSaranUserID']
)
);
if (!$query) {
$this->db_regional->trans_rollback();
$this->sys_error("Error insert order_saran");
exit;
}
$saran_id_new = $this->db_regional->insert_id();
// insert download_saran_log
if (
$receive_data_order['order'][$key]['order_saran'][$keys]['saran_log']
&&
count($receive_data_order['order'][$key]['order_saran'][$keys]['saran_log']) > 0
) {
foreach ($receive_data_order['order'][$key]['order_saran'][$keys]['saran_log'] as $keyslog => $valuelog) {
// $saran_id = $rows_order_saran[0]['OrderSaranID'];
// download saran log
$downloadSaranLogM_BranchID = $valuelog['downloadSaranLogM_BranchID'];
$downloadSaranLogM_BranchCode = $valuelog['downloadSaranLogM_BranchCode'];
$downloadSaranLogIsDownloaded = $valuelog['downloadSaranLogIsDownloaded'];
$downloadSaranLogRetry = $valuelog['downloadSaranLogRetry'];
$sql_insert_saran_log = "INSERT INTO one_doctor.download_saran_log
(
downloadSaranLogM_BranchID,
downloadSaranLogM_BranchCode,
downloadSaranLogOrderSaranID,
downloadSaranLogIsDownloaded,
downloadSaranLogRetry
)
VALUES
(
?, ?, ?, ?, ?
)";
$query = $this->db_regional->query(
$sql_insert_saran_log,
array(
$downloadSaranLogM_BranchID,
$downloadSaranLogM_BranchCode,
$saran_id_new,
$downloadSaranLogIsDownloaded,
$downloadSaranLogRetry
)
);
if (!$query) {
$this->db_regional->trans_rollback();
// $this->sys_error("Error update order_saran_log");
$response = ["status" => "ERR", "message" => "Error insert order_saran_log | " .
$this->db_regional->error()["message"], "debug" => $this->db_regional->last_query()];
$this->sys_error($response);
exit;
}
}
}
}
}
}
}
// 2. belum ada map_rx_order
else {
$not_exists_map_rx_order++;
}
}
}
if ($not_exists_map_rx_order == 0) {
echo json_encode(
[
"status" => "OK",
"data" => $receive_data_order,
"message" => "Data Saran Berhasil $proses dan dikirim dari $originIpAddress ke $S_RegionalIPAddress_Tujuan"
]
);
} else {
echo json_encode(
[
"status" => "ERR",
"data" => $receive_data_order,
"message" => "Belum Ada Mapping Order ID New Map Rx Order"
]
);
}
}
} catch (Exception $exc) {
$message = $exc->getMessage();
$this->sys_error($message);
}
}
}

View File

@@ -0,0 +1,355 @@
<?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"]);
}
}
?>

View File

@@ -0,0 +1,357 @@
<?php
class Receiveruploadlog extends MY_Controller
{
var $max_limit = 20;
public function __construct()
{
parent::__construct();
// db wilayah contoh surabaya
$this->db_regional = $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_regional->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_regional->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'],
"result_nonlab" => $key['result_nonlab'],
"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'],
"result_nonlab" => $key['result_nonlab'],
"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_regional->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_regional->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_regional->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_regional->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_regional->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_regional->last_query()]);
exit;
}
// return json_encode(
// array(
// 'status' => 'OK',
// )
// );
// $this->reply(["status" => "OK", "message" => "Data berhasil ditambahkan ke one_result"]);
}
}
?>

View File

@@ -0,0 +1,341 @@
<?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
$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"]);
}
}
?>

View File

@@ -0,0 +1,272 @@
<?php
class Receiveruploadlogconfirm 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_confirm()
{
$this->db->trans_begin();
$param = $this->get_param_z();
if(count($param['data']) > 0){
$order_patient_id_array = [];
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);
// print_r($str_order_patient_id);
// exit;
// update isconfirmed di orderpatient
// sql_update
$sql_update_is_confirm_Y = "UPDATE $this->db_str_doctor.order_patient
SET OrderPatientIsConfirmed = 'Y'
WHERE OrderPatientID IN ($str_order_patient_id)";
// print_r($sql_update_is_confirm_Y);
// exit;
$qry_update = $this->db->query($sql_update_is_confirm_Y);
if(!$qry_update){
$this->db->trans_rollback();
$this->sys_error_db(["status" => "ERR", "message" => "update data order_patient Y error | " .
$this->db->error()["message"], "debug" => $this->db->last_query()]);
exit;
}
$this->db->trans_commit();
// $this->db->trans_rollback();
$this->reply(
[
"status" => "OK",
"message" => "update",
"order_patient_id" => $order_patient_id_array,
"sql" => $sql_update_is_confirm
]
);
}
else
{
$this->reply(
[
"status" => "ERR",
"message" => "".$this->db->last_query(),
"order_patient_id" => $order_patient_id_array,
"sql" => $sql_update_is_confirm
]
);
}
// foreach($param['data'] as $key)
// {
// $order_patient_id_array[] = intval($key['order_patient_id']);
// }
// print_r($param);
// exit;
// 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
// // ]);
// // }
}
}
?>

View File

@@ -0,0 +1,272 @@
<?php
class Receiveruploadlogconfirm extends MY_Controller
{
var $max_limit = 20;
public function __construct()
{
parent::__construct();
// db wilayah contoh surabaya
$this->db_regional = $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_confirm()
{
$this->db->trans_begin();
$param = $this->get_param_z();
if(count($param['data']) > 0){
$order_patient_id_array = [];
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);
// print_r($str_order_patient_id);
// exit;
// update isconfirmed di orderpatient
// sql_update
$sql_update_is_confirm_Y = "UPDATE $this->db_str_doctor.order_patient
SET OrderPatientIsConfirmed = 'Y'
WHERE OrderPatientID IN ($str_order_patient_id)";
// print_r($sql_update_is_confirm_Y);
// exit;
$qry_update = $this->db_regional->query($sql_update_is_confirm_Y);
if(!$qry_update){
$this->db->trans_rollback();
$this->sys_error_db(["status" => "ERR", "message" => "update data order_patient Y error | " .
$this->db->error()["message"], "debug" => $this->db_regional->last_query()]);
exit;
}
$this->db->trans_commit();
// $this->db->trans_rollback();
$this->reply(
[
"status" => "OK",
"message" => "update",
"order_patient_id" => $order_patient_id_array,
"sql" => $sql_update_is_confirm
]
);
}
else
{
$this->reply(
[
"status" => "ERR",
"message" => "".$this->db_regional->last_query(),
"order_patient_id" => $order_patient_id_array,
"sql" => $sql_update_is_confirm
]
);
}
// foreach($param['data'] as $key)
// {
// $order_patient_id_array[] = intval($key['order_patient_id']);
// }
// print_r($param);
// exit;
// 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
// // ]);
// // }
}
}
?>

View File

@@ -0,0 +1,72 @@
<?php
class Result extends MY_Controller
{
function __construct()
{
parent::__construct();
}
function getResult()
{
try {
if (!$this->isLogin) {
$this->sys_error("Invalid Token");
exit;
}
$prm = $this->sys_input;
$userid = $this->sys_user['M_UserM_DoctorID'];
$patientId = "";
if (isset($prm['patientId'])) {
$patientId = trim($prm["patientId"]);
} else {
echo json_encode([
"status" => "ERR", "message" => 'Patient id is mandatory',
]);
exit;
}
$sqlCek = "SELECT * FROM one_doctor.order_patient
WHERE OrderPatientID = ?
AND OrderPatientM_DoctorID = ?";
$qryCek =
$this->db->query($sqlCek, [intval($patientId), intval($userid)]);
if (!$qryCek) {
$this->sys_error_db("Error Matching Data");
exit;
}
$resCek = $qryCek->result_array();
if (count($resCek) >= 1) {
$sql = "SELECT oneResultJson FROM one_doctor.one_result
WHERE oneResultOrderPatientID = ?
";
$qry = $this->db->query($sql, [intval($patientId)]);
if (!$qry) {
$this->sys_error_db(
"Error Get Result "
);
exit;
}
$result = $qry->result_array();
$arrResult = array();
if (count($result) > 0) {
foreach ($result as $key => $value) {
$jsonResult = json_decode($value['oneResultJson']);
$arrResult[] = $jsonResult;
}
}
// $result = array(
// $arrResult
// );
// "sql" => $this->db->last_query()
$this->sys_ok($arrResult);
} else {
$this->sys_error_db(
"Not Your Patient " . $userid
);
}
} catch (Exception $exc) {
$message = $exc->getMessage();
$this->sys_error($message);
}
}
}

View File

@@ -0,0 +1,75 @@
<?php
class Result extends MY_Controller
{
function __construct()
{
parent::__construct();
// $this->db = $this->load->database("regional", true);
$this->db_regional = $this->load->database("regional", true);
}
function getResult()
{
try {
if (!$this->isLogin) {
$this->sys_error("Invalid Token");
exit;
}
$prm = $this->sys_input;
$userid = $this->sys_user['M_UserM_DoctorID'];
$patientId = "";
if (isset($prm['patientId'])) {
$patientId = trim($prm["patientId"]);
} else {
echo json_encode([
"status" => "ERR", "message" => 'Patient id is mandatory',
]);
exit;
}
$sqlCek = "SELECT * FROM one_doctor.order_patient
WHERE OrderPatientID = ?
AND OrderPatientM_DoctorID = ?";
$qryCek =
$this->db_regional->query($sqlCek, [intval($patientId), intval($userid)]);
if (!$qryCek) {
$this->sys_error_db("Error Matching Data");
exit;
}
$resCek = $qryCek->result_array();
if (count($resCek) >= 1) {
$sql = "SELECT oneResultJson FROM one_doctor.one_result
WHERE oneResultOrderPatientID = ?
";
$qry = $this->db_regional->query($sql, [intval($patientId)]);
if (!$qry) {
$this->sys_error_db(
"Error Get Result "
);
exit;
}
$result = $qry->result_array();
$arrResult = array();
if (count($result) > 0) {
foreach ($result as $key => $value) {
$jsonResult = json_decode($value['oneResultJson']);
$arrResult[] = $jsonResult;
}
}
// $result = array(
// $arrResult
// );
// "sql" => $this->db->last_query()
$this->sys_ok($arrResult);
} else {
$this->sys_error_db(
"Not Your Patient " . $userid
);
}
} catch (Exception $exc) {
$message = $exc->getMessage();
$this->sys_error($message);
}
}
}

View File

@@ -0,0 +1,362 @@
<?php
class Xfer_doctormessage_nasional extends MY_Controller
{
var $db;
function __construct()
{
parent::__construct();
$this->db_regional = $this->load->database("regional", true);
}
function index()
{
echo "Api: Dokter Nasional Download Patient";
}
function get($url, $timeout = 60, $c_timeout = 5)
{
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, $c_timeout);
curl_setopt($ch, CURLOPT_TIMEOUT, $timeout);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$result = curl_exec($ch);
$err_msg = curl_error($ch);
if ($err_msg != "") {
return json_encode(["status" => "ERR", "message" => $err_msg]);
}
return $result;
}
function reply_err($message)
{
echo json_encode(["status" => "ERR", "data" => $message]);
exit();
}
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;
}
function log($msg)
{
// $dt = Date("Y-m-d H:i:s");
// echo "$dt $msg \n";
echo $msg;
}
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));
}
function get_param()
{
$body = file_get_contents("php://input");
return json_decode($body, true);
}
// getOrderPatient
function getOrderPatient(
$OrderPatientM_DoctorID,
$M_DoctorNasCode
) {
$limit = 20;
$sql_get_order_patient = "SELECT
OrderPatientID,
OrderPatientM_DoctorID,
OrderPatientDate,
OrderPatientM_MouID,
OrderPatientQrCode,
OrderPatientFullName,
OrderPatientDOB,
OrderPatientAddress,
OrderPatientNIK,
OrderPatientHp,
OrderPatientDiagnosa,
OrderPatientNote,
OrderPatientIsConfirmed,
OrderPatientIsActive,
OrderPatientUserID,
OrderPatientCreated,
OrderPatientLastUpdated,
'' as doctor_message
FROM one_doctor.order_patient
JOIN m_doctornas
ON OrderPatientM_DoctorID = M_DoctorNasM_DoctorID
AND M_DoctorNasIsActive = 'Y'
AND OrderPatientIsActive = 'Y'
AND OrderPatientM_DoctorID = $OrderPatientM_DoctorID
AND M_DoctorNasCode = '$M_DoctorNasCode'
ORDER BY OrderPatientID DESC
LIMIT $limit";
// echo $sql_get_order_patient;
// exit;
$qry_get_order_patient = $this->db_regional->query($sql_get_order_patient);
if (!$qry_get_order_patient) {
$response = ["status" => "ERR", "message" => "select order_patient | " .
$this->db_regional->error()["message"], "debug" => $this->db_regional->last_query()];
$this->sys_error($response);
exit;
}
$rows_get_order_patient = $qry_get_order_patient->result_array();
if (count($rows_get_order_patient) > 0) {
// return $rows_get_order_patient;
foreach ($rows_get_order_patient as $key => $vx) {
$order_patient_id = $vx['OrderPatientID'];
// doctor_message
$sql_doctor_message = "SELECT
DoctorMessageID,
DoctorMessageOrderPatientID,
DoctorMessagePesan,
DoctorMessageStatusDownload,
DoctorMessageIsActive,
DoctorMessageUserID,
DoctorMessageCreated,
DoctorMessageUpdated
FROM one_doctor.doctor_message
WHERE DoctorMessageIsActive = 'Y'
AND DoctorMessageOrderPatientID = '$order_patient_id'";
$qry_doctor_message = $this->db_regional->query($sql_doctor_message);
if (!$qry_doctor_message) {
$response = ["status" => "ERR", "message" => "select doctor_message | " .
$this->db_regional->error()["message"], "debug" => $this->db_regional->last_query()];
$this->sys_error($response);
exit;
}
$rows_doctor_message = $qry_doctor_message->result_array();
if (count($rows_doctor_message) > 0) {
$rows_get_order_patient[$key]['doctor_message'] = $rows_doctor_message;
}
else {
$rows_get_order_patient[$key]['doctor_message'] = [];
}
return $rows_get_order_patient;
}
} else {
return [];
}
}
function get_doctormessage_nasional()
{
try {
$prm = $this->get_param();
$limit = 20;
if (isset($prm['limit'])) {
$limit = trim($prm['limit']);
}
// get regional
$sql_get_regional = "SELECT *
FROM s_regional
WHERE S_RegionalIsActive = 'Y'
AND S_RegionalIsDefault = 'Y'";
$qry_get_regional = $this->db_regional->query($sql_get_regional);
if (!$qry_get_regional) {
$response = ["status" => "ERR", "message" => "select s_regional | " .
$this->db_regional->error()["message"], "debug" => $this->db_regional->last_query()];
$this->sys_error($response);
exit;
}
$rows_get_regional = $qry_get_regional->result_array();
$originalRegionalID = $rows_get_regional[0]['S_RegionalID'];
// $originalRegionalIpAddress = "devbandungraya.aplikasi.web.id";
// print_r($originalRegionalID);
// exit;
$sql_order_doknas = "SELECT
M_DoctorNasM_DoctorID,
M_DoctorNasCode,
OrderPatientM_DoctorID
FROM one_doctor.order_patient
JOIN m_doctornas
ON OrderPatientM_DoctorID = M_DoctorNasM_DoctorID
AND M_DoctorNasIsActive = 'Y'
AND OrderPatientIsActive = 'Y'
ORDER BY OrderPatientID DESC
LIMIT $limit";
$qry_order_doknas = $this->db_regional->query($sql_order_doknas);
if (!$qry_order_doknas) {
$response = ["status" => "ERR", "message" => "select order patient | " .
$this->db_regional->error()["message"], "debug" => $this->db_regional->last_query()];
$this->sys_error($response);
exit;
}
$rows_order_doknas = $qry_order_doknas->result_array();
$orderNasional = [];
if (count($rows_order_doknas) > 0) {
foreach ($rows_order_doknas as $key => $vx) {
$M_DoctorNasCodeRegional = $vx['M_DoctorNasCode'];
$OrderPatientM_DoctorID = $vx['OrderPatientM_DoctorID'];
// print_r($this->getOrderPatient($OrderPatientM_DoctorID));
// exit;
// $tabel_order_patient = $this->getOrderPatient($OrderPatientM_DoctorID);
// nembak ke 192.168.250.73
// http://192.168.250.73/one-api/nat_klinisi/Doctorcek/getDoctorRegional
$j_param = json_encode(array(
"nascode" => $M_DoctorNasCodeRegional
));
$size = round(strlen($j_param) / 1024, 2);
$z_param = gzcompress($j_param, 9);
$size_z = round(strlen($z_param) / 1024, 2);
$url = "http://192.168.250.73/one-api/nat_klinisi/Doctorcek/getDoctorRegional";
// $this->log("Post to $url | size : $size k | comprezzed $size_z k");
// $resp = $this->post($url, $z_param);
$resp = $this->post($url, $j_param);
$j_resp = json_decode($resp, true);
// $j_resp_x = $this->get_param_z();
// print_r($resp);
// print_r($j_resp_x);
if ($j_resp["status"] == "OK") {
if (count($j_resp['data']) > 0) {
// $j_resp['data'] merupakan data dari .73
foreach ($j_resp['data'] as $key => $vk) {
$M_DoctorNasCode_ip_73 = $vk['M_DoctorNasCode'];
$regionalTujuanIpAddress = "devkedungdororaya.aplikasi.web.id";
// klu doctor nas nya di regional beda dengan di .73 di continue
if ($M_DoctorNasCode_ip_73 !== $M_DoctorNasCodeRegional) {
continue;
}
if($originalRegionalID == $vk['M_DoctorNasS_RegionalID']){
// $originalRegionalIpAddress = "devbandungraya.aplikasi.web.id";
$originalRegionalIpAddress = $vk['S_RegionalIPAddress'];
}
// yg dikirim hny order tujuan yg bukan dari origin regional id
if ($originalRegionalID != $vk['M_DoctorNasS_RegionalID']) {
$orderNasional[] = array(
"M_DoctorNasCode" => $vk['M_DoctorNasCode'],
"originIpAddress" => $originalRegionalIpAddress,
"originRegionalID" => $originalRegionalID,
"M_DoctorNasS_RegionalID" => $vk['M_DoctorNasS_RegionalID'],
"S_RegionalName" => $vk['S_RegionalName'],
"S_RegionalIPAddress" => $vk['S_RegionalIPAddress'],
// "S_RegionalIPAddress" => $regionalTujuanIpAddress,
"order" => $this->getOrderPatient($OrderPatientM_DoctorID, $M_DoctorNasCode_ip_73)
);
}
}
}
} else {
$this->db->trans_rollback();
// print_r($j_resp['status']);
$this->reply([
"status" => "ERR",
'message' => "Gagal get Data untuk cek dokter nasional",
'debug' => print_r($resp, true)
]);
}
}
// echo json_encode([
// "status" => "OK",
// "orderNasional" => $orderNasional
// ]);
if (count($orderNasional) > 0) {
// sent order ke regional yang bukan origin regional id
foreach ($orderNasional as $key => $vx) {
$j_param = json_encode(array(
"M_DoctorNasCode" => $vx['M_DoctorNasCode'],
"originIpAddress" => $vx['originIpAddress'],
"originRegionalID" => $vx['originRegionalID'],
"M_DoctorNasS_RegionalID" => $vx['M_DoctorNasS_RegionalID'],
"S_RegionalName" => $vx['S_RegionalName'],
// "S_RegionalIPAddress" => $vk['S_RegionalIPAddress'],
"S_RegionalIPAddress" => $vx['S_RegionalIPAddress'],
"order" => $vx['order']
));
// print_r($vx['order']);
// exit;
$url = "http://{$vx['S_RegionalIPAddress']}/one-api/app_doctor/R_xfer_doctormessage_nasional/receive_order";
$resp = $this->post($url, $j_param);
$j_resp = json_decode($resp, true);
// print_r($resp);
// exit;
if ($j_resp["status"] == "OK") {
// print_r($j_resp['data']);
// exit;
echo json_encode($j_resp);
}
}
}
} else {
}
} catch (Exception $exc) {
$message = $exc->getMessage();
$result = array(
'status' => 'err',
"message" => $message,
);
$this->reply_gz($result);
}
}
}

View File

@@ -0,0 +1,423 @@
<?php
class Xfer_order_nasional extends MY_Controller
{
var $db;
function __construct()
{
parent::__construct();
$this->db_regional = $this->load->database("regional", true);
}
function index()
{
echo "Api: Dokter Nasional Download Patient";
}
function get($url, $timeout = 60, $c_timeout = 5)
{
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, $c_timeout);
curl_setopt($ch, CURLOPT_TIMEOUT, $timeout);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$result = curl_exec($ch);
$err_msg = curl_error($ch);
if ($err_msg != "") {
return json_encode(["status" => "ERR", "message" => $err_msg]);
}
return $result;
}
function reply_err($message)
{
echo json_encode(["status" => "ERR", "data" => $message]);
exit();
}
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;
}
function log($msg)
{
// $dt = Date("Y-m-d H:i:s");
// echo "$dt $msg \n";
echo $msg;
}
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));
}
function get_param()
{
$body = file_get_contents("php://input");
return json_decode($body, true);
}
// getOrderPatient
function getOrderPatient(
$OrderPatientM_DoctorID,
$M_DoctorNasCode
) {
$limit = 20;
$sql_get_order_patient = "SELECT
OrderPatientID,
OrderPatientM_DoctorID,
OrderPatientDate,
OrderPatientM_MouID,
OrderPatientQrCode,
OrderPatientFullName,
OrderPatientDOB,
OrderPatientAddress,
OrderPatientNIK,
OrderPatientHp,
OrderPatientDiagnosa,
OrderPatientNote,
OrderPatientIsConfirmed,
OrderPatientIsActive,
OrderPatientUserID,
OrderPatientCreated,
OrderPatientLastUpdated,
'' as details
FROM one_doctor.order_patient
JOIN m_doctornas
ON OrderPatientM_DoctorID = M_DoctorNasM_DoctorID
AND M_DoctorNasIsActive = 'Y'
AND OrderPatientIsActive = 'Y'
AND OrderPatientM_DoctorID = $OrderPatientM_DoctorID
AND M_DoctorNasCode = '$M_DoctorNasCode'
ORDER BY OrderPatientID DESC
LIMIT $limit";
// echo $sql_get_order_patient;
// exit;
$qry_get_order_patient = $this->db_regional->query($sql_get_order_patient);
if (!$qry_get_order_patient) {
$response = ["status" => "ERR", "message" => "select order_patient | " .
$this->db_regional->error()["message"], "debug" => $this->db_regional->last_query()];
$this->sys_error($response);
exit;
}
$rows_get_order_patient = $qry_get_order_patient->result_array();
if (count($rows_get_order_patient) > 0) {
// return $rows_get_order_patient;
foreach ($rows_get_order_patient as $key => $vx) {
$order_patient_id = $vx['OrderPatientID'];
// details untuk order_details
$sql_order_details = "SELECT
OrderPatientDetailsID,
OrderPatientDetailsOrderPatientID,
OrderPatientDetailsT_TestID,
OrderPatientDetailsT_TestName,
OrderPatientDetailsPrice,
OrderPatientDetailsIsActive,
OrderPatientDetailsUserID,
OrderPatientDetailsCreated,
OrderPatientDetailsLastUpdated
FROM one_doctor.order_patient_details
WHERE OrderPatientDetailsOrderPatientID = $order_patient_id
AND OrderPatientDetailsIsActive = 'Y'";
$qry_order_detail = $this->db_regional->query($sql_order_details);
if (!$qry_order_detail) {
$response = ["status" => "ERR", "message" => "select order_details | " .
$this->db_regional->error()["message"], "debug" => $this->db_regional->last_query()];
$this->sys_error($response);
exit;
}
$rows_order_detail = $qry_order_detail->result_array();
if (count($rows_order_detail) > 0){
$rows_get_order_patient[$key]['details'] = $rows_order_detail;
}
else {
$rows_get_order_patient[$key]['details'] = [];
}
// order_saran
// $sql_order_saran = "SELECT
// OrderSaranID,
// OrderSaranOrderPatientID,
// OrderKesimpulan,
// OrderSaran,
// OrderSaranIsActive,
// OrderSaranUserID,
// OrderSaranCreated,
// OrderSaranLastUpdated
// FROM one_doctor.order_saran
// WHERE OrderSaranOrderPatientID = $order_patient_id
// AND OrderSaranIsActive = 'Y'";
// $qry_order_saran = $this->db_regional->query($sql_order_saran);
// if (!$qry_order_saran) {
// $response = ["status" => "ERR", "message" => "select order_saran | " .
// $this->db_regional->error()["message"], "debug" => $this->db_regional->last_query()];
// $this->sys_error($response);
// exit;
// }
// $rows_order_saran = $qry_order_saran->result_array();
// if (count($rows_order_saran) > 0) {
// $rows_get_order_patient[$key]['order_saran'] = $rows_order_saran;
// }
// else {
// $rows_get_order_patient[$key]['order_saran'] = [];
// }
// doctor_message
// $sql_doctor_message = "SELECT
// DoctorMessageID,
// DoctorMessageOrderPatientID,
// DoctorMessagePesan,
// DoctorMessageStatusDownload,
// DoctorMessageIsActive,
// DoctorMessageUserID,
// DoctorMessageCreated,
// DoctorMessageUpdated
// FROM one_doctor.doctor_message
// WHERE DoctorMessageIsActive = 'Y'
// AND DoctorMessageOrderPatientID = '$order_patient_id'";
// $qry_doctor_message = $this->db_regional->query($sql_doctor_message);
// if (!$qry_doctor_message) {
// $response = ["status" => "ERR", "message" => "select doctor_message | " .
// $this->db_regional->error()["message"], "debug" => $this->db_regional->last_query()];
// $this->sys_error($response);
// exit;
// }
// $rows_doctor_message = $qry_doctor_message->result_array();
// if (count($rows_doctor_message) > 0) {
// $rows_get_order_patient[$key]['doctor_message'] = $rows_doctor_message;
// }
// else {
// $rows_get_order_patient[$key]['doctor_message'] = [];
// }
return $rows_get_order_patient;
}
} else {
return [];
}
}
function get_order_nasional()
{
try {
$prm = $this->get_param();
$limit = 20;
if (isset($prm['limit'])) {
$limit = trim($prm['limit']);
}
// get regional
$sql_get_regional = "SELECT *
FROM s_regional
WHERE S_RegionalIsActive = 'Y'
AND S_RegionalIsDefault = 'Y'";
$qry_get_regional = $this->db_regional->query($sql_get_regional);
if (!$qry_get_regional) {
$response = ["status" => "ERR", "message" => "select s_regional | " .
$this->db_regional->error()["message"], "debug" => $this->db_regional->last_query()];
$this->sys_error($response);
exit;
}
$rows_get_regional = $qry_get_regional->result_array();
$originalRegionalID = $rows_get_regional[0]['S_RegionalID'];
// $originalRegionalIpAddress = "devbandungraya.aplikasi.web.id";
// print_r($originalRegionalID);
// exit;
$sql_order_doknas = "SELECT
M_DoctorNasM_DoctorID,
M_DoctorNasCode,
OrderPatientM_DoctorID
FROM one_doctor.order_patient
JOIN m_doctornas
ON OrderPatientM_DoctorID = M_DoctorNasM_DoctorID
AND M_DoctorNasIsActive = 'Y'
AND OrderPatientIsActive = 'Y'
ORDER BY OrderPatientID DESC
LIMIT $limit";
$qry_order_doknas = $this->db_regional->query($sql_order_doknas);
if (!$qry_order_doknas) {
$response = ["status" => "ERR", "message" => "select order patient | " .
$this->db_regional->error()["message"], "debug" => $this->db_regional->last_query()];
$this->sys_error($response);
exit;
}
$rows_order_doknas = $qry_order_doknas->result_array();
$orderNasional = [];
if (count($rows_order_doknas) > 0) {
foreach ($rows_order_doknas as $key => $vx) {
$M_DoctorNasCodeRegional = $vx['M_DoctorNasCode'];
$OrderPatientM_DoctorID = $vx['OrderPatientM_DoctorID'];
// print_r($this->getOrderPatient($OrderPatientM_DoctorID));
// exit;
// $tabel_order_patient = $this->getOrderPatient($OrderPatientM_DoctorID);
// nembak ke 192.168.250.73
// http://192.168.250.73/one-api/nat_klinisi/Doctorcek/getDoctorRegional
$j_param = json_encode(array(
"nascode" => $M_DoctorNasCodeRegional
));
$size = round(strlen($j_param) / 1024, 2);
$z_param = gzcompress($j_param, 9);
$size_z = round(strlen($z_param) / 1024, 2);
$url = "http://192.168.250.73/one-api/nat_klinisi/Doctorcek/getDoctorRegional";
// $this->log("Post to $url | size : $size k | comprezzed $size_z k");
// $resp = $this->post($url, $z_param);
$resp = $this->post($url, $j_param);
$j_resp = json_decode($resp, true);
// $j_resp_x = $this->get_param_z();
// print_r($resp);
// print_r($j_resp_x);
if ($j_resp["status"] == "OK") {
if (count($j_resp['data']) > 0) {
// $j_resp['data'] merupakan data dari .73
foreach ($j_resp['data'] as $key => $vk) {
$M_DoctorNasCode_ip_73 = $vk['M_DoctorNasCode'];
$regionalTujuanIpAddress = "devkedungdororaya.aplikasi.web.id";
// klu doctor nas nya di regional beda dengan di .73 di continue
if ($M_DoctorNasCode_ip_73 !== $M_DoctorNasCodeRegional) {
continue;
}
if($originalRegionalID == $vk['M_DoctorNasS_RegionalID']){
// $originalRegionalIpAddress = "devbandungraya.aplikasi.web.id";
$originalRegionalIpAddress = $vk['S_RegionalIPAddress'];
}
// yg dikirim hny order tujuan yg bukan dari origin regional id
if ($originalRegionalID != $vk['M_DoctorNasS_RegionalID']) {
$orderNasional[] = array(
"M_DoctorNasCode" => $vk['M_DoctorNasCode'],
"originIpAddress" => $originalRegionalIpAddress,
"originRegionalID" => $originalRegionalID,
"M_DoctorNasS_RegionalID" => $vk['M_DoctorNasS_RegionalID'],
"S_RegionalName" => $vk['S_RegionalName'],
"S_RegionalIPAddress" => $vk['S_RegionalIPAddress'],
// "S_RegionalIPAddress" => $regionalTujuanIpAddress,
"order" => $this->getOrderPatient($OrderPatientM_DoctorID, $M_DoctorNasCode_ip_73)
);
}
}
}
} else {
$this->db->trans_rollback();
// print_r($j_resp['status']);
$this->reply([
"status" => "ERR",
'message' => "Gagal get Data untuk cek dokter nasional",
'debug' => print_r($resp, true)
]);
}
}
// echo json_encode([
// "status" => "OK",
// "orderNasional" => $orderNasional
// ]);
if (count($orderNasional) > 0) {
// sent order ke regional yang bukan origin regional id
foreach ($orderNasional as $key => $vx) {
$j_param = json_encode(array(
"M_DoctorNasCode" => $vx['M_DoctorNasCode'],
"originIpAddress" => $vx['originIpAddress'],
"originRegionalID" => $vx['originRegionalID'],
"M_DoctorNasS_RegionalID" => $vx['M_DoctorNasS_RegionalID'],
"S_RegionalName" => $vx['S_RegionalName'],
// "S_RegionalIPAddress" => $vk['S_RegionalIPAddress'],
"S_RegionalIPAddress" => $vx['S_RegionalIPAddress'],
"order" => $vx['order']
));
// print_r($vx['order']);
// exit;
$url = "http://{$vx['S_RegionalIPAddress']}/one-api/app_doctor/R_xfer_order_nasional/receive_order";
$resp = $this->post($url, $j_param);
$j_resp = json_decode($resp, true);
// print_r($resp);
// exit;
if ($j_resp["status"] == "OK") {
// print_r($j_resp['data']);
// exit;
echo json_encode($j_resp);
}
}
}
} else {
}
} catch (Exception $exc) {
$message = $exc->getMessage();
$result = array(
'status' => 'err',
"message" => $message,
);
$this->reply_gz($result);
}
}
}

View File

@@ -0,0 +1,140 @@
<?php
class Xfer_result_nasional extends MY_Controller
{
var $db;
function __construct()
{
parent::__construct();
}
function index()
{
echo "Api: REGIONAL SEND RESULT ";
}
function getresult()
{
try {
$sql_order = "SELECT
map_rx_order.*,
one_result.*,
order_patient.*
FROM one_doctor.order_patient
JOIN one_doctor.one_result ON OrderPatientID = oneResultOrderPatientID
AND OrderPatientIsActive = 'Y'
JOIN one_doctor.map_rx_order
ON OrderPatientID = mapRxOrderNewOrderPatientID
AND mapRxOrderIsActive = 'Y'
AND oneResultDate > mapRxOrderSendDate";
$qry_order = $this->db->query($sql_order, []);
if (!$qry_order) {
$message = $this->db->error();
$this->sys_error($message);
exit;
}
$order = $qry_order->result_array();
$arrRegionalIP = [];
$arrOrderSend = array();
for ($i = 0; $i < count($order); $i++) {
if (!in_array($order[$i]['mapRxOrderOriginIPAddress'], $arrRegionalIP)) {
$arrRegionalIP[] = $order[$i]['mapRxOrderOriginIPAddress'];
}
}
for ($i = 0; $i < count($arrRegionalIP); $i++) {
$arrData = [];
for ($k = 0; $k < count($order); $k++) {
if ($arrRegionalIP[$i] == $order[$k]['mapRxOrderOriginIPAddress']) {
$arrData[] = $order[$k];
}
}
$arrOrderSend[] = $arrData;
}
$arrResp = [];
$resp = array(
"status" => "OK",
"order" => $arrOrderSend
);
// echo json_encode($resp);
// exit;
for ($i = 0; $i < count($arrOrderSend); $i++) {
$resp = array(
"status" => "OK",
"IP" => $arrOrderSend[$i][0]['mapRxOrderOriginIPAddress'],
"order" => $arrOrderSend[$i]
);
$rawResp = $this->post("http://{$arrOrderSend[$i][0]['mapRxOrderOriginIPAddress']}/one-api/app_doctor/R_xfer_result_nasional/receive", gzcompress(json_encode($resp)));
// $rawResp = $this->post("http://{$arrOrderSend[$i][0]['mapRxOrderOriginIPAddress']}/one-api/app_doctor/R_xfer_result_nasional/receive", json_encode($resp));
$rst = gzuncompress($rawResp);
// $rst = json_decode($rawResp, true);
$dcdRst = json_decode($rst, true);
$arrResp[] = $dcdRst;
for ($q = 0; $q < count($dcdRst["order_success"]); $q++) {
$sql_update = "UPDATE one_doctor.map_rx_order
SET mapRxOrderSendDate = NOW()
, mapRxOrderIsSent = 'Y'
WHERE mapRxOrderNewOrderPatientID = ?";
$qry_update = $this->db->query($sql_update, [$dcdRst["order_success"][$q]]);
if (!$qry_update) {
$message = $this->db->error();
$this->sys_error($message);
exit;
}
}
}
// $this->reply_gz($resp);
// echo json_encode($resp);
$finalResult = array(
"status" => "OK",
"message" => $arrResp
);
echo json_encode($finalResult);
} 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($resp)
{
echo json_encode($resp);
}
function reply_gz($resp)
{
//echo json_encode($resp);
echo gzcompress(json_encode($resp));
}
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;
}
}

View File

@@ -0,0 +1,389 @@
<?php
class Xfer_saran_nasional extends MY_Controller
{
var $db;
function __construct()
{
parent::__construct();
$this->db_regional = $this->load->database("regional", true);
}
function index()
{
echo "Api: Dokter Nasional Download Patient";
}
function get($url, $timeout = 60, $c_timeout = 5)
{
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, $c_timeout);
curl_setopt($ch, CURLOPT_TIMEOUT, $timeout);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$result = curl_exec($ch);
$err_msg = curl_error($ch);
if ($err_msg != "") {
return json_encode(["status" => "ERR", "message" => $err_msg]);
}
return $result;
}
function reply_err($message)
{
echo json_encode(["status" => "ERR", "data" => $message]);
exit();
}
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;
}
function log($msg)
{
// $dt = Date("Y-m-d H:i:s");
// echo "$dt $msg \n";
echo $msg;
}
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));
}
function get_param()
{
$body = file_get_contents("php://input");
return json_decode($body, true);
}
// getOrderPatient
function getOrderPatient(
$OrderPatientM_DoctorID,
$M_DoctorNasCode
) {
$limit = 20;
$sql_get_order_patient = "SELECT
OrderPatientID,
OrderPatientM_DoctorID,
OrderPatientDate,
OrderPatientM_MouID,
OrderPatientQrCode,
OrderPatientFullName,
OrderPatientDOB,
OrderPatientAddress,
OrderPatientNIK,
OrderPatientHp,
OrderPatientDiagnosa,
OrderPatientNote,
OrderPatientIsConfirmed,
OrderPatientIsActive,
OrderPatientUserID,
OrderPatientCreated,
OrderPatientLastUpdated,
'' as order_saran
FROM one_doctor.order_patient
JOIN m_doctornas
ON OrderPatientM_DoctorID = M_DoctorNasM_DoctorID
AND M_DoctorNasIsActive = 'Y'
AND OrderPatientIsActive = 'Y'
AND OrderPatientM_DoctorID = $OrderPatientM_DoctorID
AND M_DoctorNasCode = '$M_DoctorNasCode'
ORDER BY OrderPatientID DESC
LIMIT $limit";
// echo $sql_get_order_patient;
// exit;
$qry_get_order_patient = $this->db_regional->query($sql_get_order_patient);
if (!$qry_get_order_patient) {
$response = ["status" => "ERR", "message" => "select order_patient | " .
$this->db_regional->error()["message"], "debug" => $this->db_regional->last_query()];
$this->sys_error($response);
exit;
}
$rows_get_order_patient = $qry_get_order_patient->result_array();
if (count($rows_get_order_patient) > 0) {
// return $rows_get_order_patient;
foreach ($rows_get_order_patient as $key => $vx) {
$order_patient_id = $vx['OrderPatientID'];
// order saran
$sql_order_saran = "SELECT
OrderSaranID,
OrderSaranOrderPatientID,
OrderKesimpulan,
OrderSaran,
OrderSaranIsActive,
OrderSaranUserID,
OrderSaranCreated,
OrderSaranLastUpdated,
'' as saran_log
FROM one_doctor.order_saran
WHERE OrderSaranOrderPatientID = $order_patient_id
AND OrderSaranIsActive = 'Y'";
$qry_order_saran = $this->db_regional->query($sql_order_saran);
if (!$qry_order_saran) {
$response = ["status" => "ERR", "message" => "select order_saran | " .
$this->db_regional->error()["message"], "debug" => $this->db_regional->last_query()];
$this->sys_error($response);
exit;
}
$rows_order_saran = $qry_order_saran->result_array();
if (count($rows_order_saran) > 0) {
$rows_get_order_patient[$key]['order_saran'] = $rows_order_saran;
foreach($rows_order_saran as $ks => $val){
$order_saran_id = $val['OrderSaranID'];
$sql_saran_log = "SELECT *
FROM one_doctor.download_saran_log
WHERE downloadSaranLogOrderSaranID = $order_saran_id";
$qry_order_saran_log = $this->db_regional->query($sql_saran_log);
if (!$qry_order_saran_log) {
$response = ["status" => "ERR", "message" => "select order_saran_log | " .
$this->db_regional->error()["message"], "debug" => $this->db_regional->last_query()];
$this->sys_error($response);
exit;
}
$rows_order_saran_log = $qry_order_saran_log->result_array();
if(count($rows_order_saran_log) > 0){
$rows_get_order_patient[$key]['order_saran'][$ks]['saran_log'] = $rows_order_saran_log;
}else{
$rows_get_order_patient[$key]['order_saran'][$ks]['saran_log'] = [];
}
}
}
else {
$rows_get_order_patient[$key]['order_saran'] = [];
}
return $rows_get_order_patient;
}
} else {
return [];
}
}
function get_saran_nasional()
{
try {
$prm = $this->get_param();
$limit = 20;
if (isset($prm['limit'])) {
$limit = trim($prm['limit']);
}
// get regional
$sql_get_regional = "SELECT *
FROM s_regional
WHERE S_RegionalIsActive = 'Y'
AND S_RegionalIsDefault = 'Y'";
$qry_get_regional = $this->db_regional->query($sql_get_regional);
if (!$qry_get_regional) {
$response = ["status" => "ERR", "message" => "select s_regional | " .
$this->db_regional->error()["message"], "debug" => $this->db_regional->last_query()];
$this->sys_error($response);
exit;
}
$rows_get_regional = $qry_get_regional->result_array();
$originalRegionalID = $rows_get_regional[0]['S_RegionalID'];
// $originalRegionalIpAddress = "devbandungraya.aplikasi.web.id";
// print_r($originalRegionalID);
// exit;
$sql_order_doknas = "SELECT
M_DoctorNasM_DoctorID,
M_DoctorNasCode,
OrderPatientM_DoctorID
FROM one_doctor.order_patient
JOIN m_doctornas
ON OrderPatientM_DoctorID = M_DoctorNasM_DoctorID
AND M_DoctorNasIsActive = 'Y'
AND OrderPatientIsActive = 'Y'
ORDER BY OrderPatientID DESC
LIMIT $limit";
$qry_order_doknas = $this->db_regional->query($sql_order_doknas);
if (!$qry_order_doknas) {
$response = ["status" => "ERR", "message" => "select order patient | " .
$this->db_regional->error()["message"], "debug" => $this->db_regional->last_query()];
$this->sys_error($response);
exit;
}
$rows_order_doknas = $qry_order_doknas->result_array();
$orderNasional = [];
if (count($rows_order_doknas) > 0) {
foreach ($rows_order_doknas as $key => $vx) {
$M_DoctorNasCodeRegional = $vx['M_DoctorNasCode'];
$OrderPatientM_DoctorID = $vx['OrderPatientM_DoctorID'];
// print_r($this->getOrderPatient($OrderPatientM_DoctorID));
// exit;
// $tabel_order_patient = $this->getOrderPatient($OrderPatientM_DoctorID);
// nembak ke 192.168.250.73
// http://192.168.250.73/one-api/nat_klinisi/Doctorcek/getDoctorRegional
$j_param = json_encode(array(
"nascode" => $M_DoctorNasCodeRegional
));
$size = round(strlen($j_param) / 1024, 2);
$z_param = gzcompress($j_param, 9);
$size_z = round(strlen($z_param) / 1024, 2);
$url = "http://192.168.250.73/one-api/nat_klinisi/Doctorcek/getDoctorRegional";
// $this->log("Post to $url | size : $size k | comprezzed $size_z k");
// $resp = $this->post($url, $z_param);
$resp = $this->post($url, $j_param);
$j_resp = json_decode($resp, true);
// $j_resp_x = $this->get_param_z();
// print_r($resp);
// print_r($j_resp_x);
if ($j_resp["status"] == "OK") {
if (count($j_resp['data']) > 0) {
// $j_resp['data'] merupakan data dari .73
foreach ($j_resp['data'] as $key => $vk) {
$M_DoctorNasCode_ip_73 = $vk['M_DoctorNasCode'];
$regionalTujuanIpAddress = "devkedungdororaya.aplikasi.web.id";
// klu doctor nas nya di regional beda dengan di .73 di continue
if ($M_DoctorNasCode_ip_73 !== $M_DoctorNasCodeRegional) {
continue;
}
if($originalRegionalID == $vk['M_DoctorNasS_RegionalID']){
// $originalRegionalIpAddress = "devbandungraya.aplikasi.web.id";
$originalRegionalIpAddress = $vk['S_RegionalIPAddress'];
}
// yg dikirim hny order tujuan yg bukan dari origin regional id
if ($originalRegionalID != $vk['M_DoctorNasS_RegionalID']) {
$orderNasional[] = array(
"M_DoctorNasCode" => $vk['M_DoctorNasCode'],
"originIpAddress" => $originalRegionalIpAddress,
"originRegionalID" => $originalRegionalID,
"M_DoctorNasS_RegionalID" => $vk['M_DoctorNasS_RegionalID'],
"S_RegionalName" => $vk['S_RegionalName'],
"S_RegionalIPAddress" => $vk['S_RegionalIPAddress'],
// "S_RegionalIPAddress" => $regionalTujuanIpAddress,
"order" => $this->getOrderPatient($OrderPatientM_DoctorID, $M_DoctorNasCode_ip_73)
);
}
}
}
} else {
$this->db->trans_rollback();
// print_r($j_resp['status']);
$this->reply([
"status" => "ERR",
'message' => "Gagal get Data untuk cek dokter nasional",
'debug' => print_r($resp, true)
]);
}
}
// echo json_encode([
// "status" => "OK",
// "orderNasional" => $orderNasional
// ]);
if (count($orderNasional) > 0) {
// sent order ke regional yang bukan origin regional id
foreach ($orderNasional as $key => $vx) {
$j_param = json_encode(array(
"M_DoctorNasCode" => $vx['M_DoctorNasCode'],
"originIpAddress" => $vx['originIpAddress'],
"originRegionalID" => $vx['originRegionalID'],
"M_DoctorNasS_RegionalID" => $vx['M_DoctorNasS_RegionalID'],
"S_RegionalName" => $vx['S_RegionalName'],
// "S_RegionalIPAddress" => $vk['S_RegionalIPAddress'],
"S_RegionalIPAddress" => $vx['S_RegionalIPAddress'],
"order" => $vx['order']
));
// print_r($vx['order']);
// exit;
$url = "http://{$vx['S_RegionalIPAddress']}/one-api/app_doctor/R_xfer_saran_nasional/receive_order";
$resp = $this->post($url, $j_param);
$j_resp = json_decode($resp, true);
// print_r($resp);
// exit;
if ($j_resp["status"] == "OK") {
// print_r($j_resp['data']);
// exit;
echo json_encode($j_resp);
}
}
}
} else {
}
} catch (Exception $exc) {
$message = $exc->getMessage();
$result = array(
'status' => 'err',
"message" => $message,
);
$this->reply_gz($result);
}
}
}