Initial import
This commit is contained in:
416
application/controllers/lis/Trx_order.php
Normal file
416
application/controllers/lis/Trx_order.php
Normal file
@@ -0,0 +1,416 @@
|
||||
<?php
|
||||
|
||||
class Trx_order extends MY_Controller
|
||||
{
|
||||
function __construct()
|
||||
{
|
||||
parent::__construct();
|
||||
|
||||
$this->load->helper(array('form', 'url'));
|
||||
$this->db_onedev = $this->load->database("onedev", true);
|
||||
$this->db_oneklinik = $this->load->database("onedev", true);
|
||||
}
|
||||
|
||||
|
||||
function get_order() {
|
||||
$baseurl = 'https://yankes.itb.ac.id/data-services';
|
||||
$url = $baseurl.'/api/pemeriksan_mcu';
|
||||
$token = 'eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJpc3MiOiJodHRwczpcL1wveWFua2VzLml0Yi5hYy5pZFwvZGV2LXNlcnZpY2VzXC9hcGlcL2F1dGhcL2xvZ2luIiwiaWF0IjoxNzI3MDg0NTcyLCJleHAiOjE3NTg2MjA1NzIsIm5iZiI6MTcyNzA4NDU3MiwianRpIjoiOWpGc3A0TmFIbnZWQkdrVyIsInN1YiI6NzcsInBydiI6IjIzYmQ1Yzg5NDlmNjAwYWRiMzllNzAxYzQwMDg3MmRiN2E1OTc2ZjcifQ.eduGs9bz64uD8paGYxJ1zxJ0du6lQ9yTFT7BzYTFg4A';
|
||||
|
||||
$ch = curl_init();
|
||||
|
||||
curl_setopt($ch, CURLOPT_URL, $url);
|
||||
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
|
||||
curl_setopt($ch, CURLOPT_HTTPHEADER, array(
|
||||
'Authorization: Bearer ' . $token,
|
||||
'Content-Type: application/json'
|
||||
));
|
||||
|
||||
// Eksekusi request cURL
|
||||
$response = curl_exec($ch);
|
||||
|
||||
// Debug: Cek error cURL
|
||||
if (curl_errno($ch)) {
|
||||
echo 'cURL Error: ' . curl_error($ch);
|
||||
}
|
||||
|
||||
curl_close($ch);
|
||||
|
||||
// Kembalikan hasil response (jika perlu, decode JSON)
|
||||
//echo $response;
|
||||
|
||||
|
||||
/*$sql = "INSERT INTO itb_yankes.tmp_response(
|
||||
response
|
||||
)
|
||||
VALUES(?)";
|
||||
$qry = $this->db_onedev->query($sql,array($response));
|
||||
if(!$qry){
|
||||
$this->sys_error_db("save response", $this->db_onedev);
|
||||
exit;
|
||||
}*/
|
||||
$rspn = json_decode($response, true);
|
||||
if($rspn['success'] == 1){
|
||||
$datas = $rspn['response_1'];
|
||||
|
||||
if(count($datas) > 0){
|
||||
//print_r($datas);
|
||||
foreach ($datas as $key => $value) {
|
||||
if($value['nik']){
|
||||
$sql = "SELECT * FROM itb_yankes.download_order WHERE DownloadOrderNumber = ?";
|
||||
$qry = $this->db_onedev->query($sql,array($value['no_order']));
|
||||
if(!$qry){
|
||||
$this->sys_error_db("select order error", $this->db_onedev);
|
||||
exit;
|
||||
}
|
||||
//echo $this->db_onedev->last_query();
|
||||
$exist_dt = $qry->result_array();
|
||||
if(count($exist_dt) == 0){
|
||||
$sql = "INSERT INTO itb_yankes.download_order (
|
||||
DownloadOrderNumber,
|
||||
DownloadOrderDate,
|
||||
DownloadOrderNIK,
|
||||
DownloadOrderName,
|
||||
DownloadOrderGender,
|
||||
DownloadOrderDOB,
|
||||
DownloadOrderJSON,
|
||||
DownloadOrderCreated
|
||||
) VALUES(?,?,?,?,?,?,?,NOW()) ";
|
||||
$qry = $this->db_onedev->query($sql,array(
|
||||
$value['no_order'],
|
||||
$value['tanggal_pemeriksaan'],
|
||||
$value['nik'],
|
||||
$value['nama_lengkap'],
|
||||
$value['jenis_kelamin'],
|
||||
$value['tanggal_lahir'],
|
||||
json_encode($rspn)
|
||||
));
|
||||
if(!$qry){
|
||||
$this->sys_error_db("select order error", $this->db_onedev);
|
||||
exit;
|
||||
}
|
||||
//echo $this->db_onedev->last_query();
|
||||
$lastID = $this->db_onedev->insert_id();
|
||||
}else{
|
||||
$lastID = $exist_dt[0]['DownloadOrderID'];
|
||||
$sql = "UPDATE itb_yankes.download_order SET
|
||||
DownloadOrderNIK = ?,
|
||||
DownloadOrderDOB = ?,
|
||||
DownloadOrderJSON = ?
|
||||
WHERE
|
||||
DownloadOrderID = ?
|
||||
";
|
||||
$qry = $this->db_onedev->query($sql,array(
|
||||
$value['nik'],
|
||||
$value['tanggal_lahir'],
|
||||
json_encode($rspn),
|
||||
$lastID));
|
||||
if(!$qry){
|
||||
$this->sys_error_db("update download_order error", $this->db_onedev);
|
||||
exit;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
$sql = "SELECT T_OrderHeaderID, M_PatientID,M_PatientIDNumber,DownloadOrderNIK,M_PatientDOB,DownloadOrderDOB
|
||||
FROM t_orderheader
|
||||
JOIN itb_yankes.sys_config ON T_OrderHeaderM_MouID IN (SysConfigM_MouID)
|
||||
JOIN m_patient ON T_OrderHeaderM_PatientID = M_PatientID
|
||||
JOIN itb_yankes.download_order
|
||||
ON REPLACE(m_patient.M_PatientIDNumber, UNHEX('E2808C'), '') = TRIM(download_order.DownloadOrderNIK)
|
||||
AND M_PatientDOB = DownloadOrderDOB
|
||||
WHERE DownloadOrderID = ? AND T_OrderHeaderIsActive = 'Y';
|
||||
";
|
||||
$qry = $this->db_onedev->query($sql,array($lastID));
|
||||
if(!$qry){
|
||||
$this->sys_error_db("select order error", $this->db_onedev);
|
||||
exit;
|
||||
}
|
||||
|
||||
$rows_order_lab = $qry->result_array();
|
||||
if(count($rows_order_lab)> 0){
|
||||
$data_map = $rows_order_lab[0];
|
||||
$sql = "UPDATE m_patient
|
||||
SET M_PatientIDNumber = REPLACE(M_PatientIDNumber, UNHEX('E2808C'), '')
|
||||
WHERE M_PatientID = ?";
|
||||
$qry = $this->db_onedev->query($sql,array($data_map['M_PatientID']));
|
||||
if(!$qry){
|
||||
$this->sys_error_db("select order error", $this->db_onedev);
|
||||
exit;
|
||||
}
|
||||
|
||||
|
||||
$this->mapping_order($lastID,$data_map['T_OrderHeaderID'],$value['no_order'],555);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//echo json_encode($rspn);
|
||||
|
||||
|
||||
}
|
||||
$result = array(
|
||||
|
||||
"records" => json_encode($rspn['response_1'])
|
||||
);
|
||||
$this->sys_ok($result);
|
||||
exit;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
function mapping_order($orderID,$orderLabID,$noOrder,$userID){
|
||||
$sql = "INSERT INTO itb_yankes.order_map (
|
||||
orderMapDownloadOrderID,
|
||||
orderMapT_OrderHeaderID,
|
||||
orderMapCreated,
|
||||
orderMapCreatedUserID
|
||||
) VALUES(?,?,NOW(),?)";
|
||||
$qry = $this->db_onedev->query($sql,array($orderID,$orderLabID,$userID));
|
||||
if(!$qry){
|
||||
$this->sys_error_db("select order error", $this->db_onedev);
|
||||
exit;
|
||||
}
|
||||
|
||||
$this->update_status($orderID,'mapped');
|
||||
|
||||
$sql = "UPDATE t_orderheaderaddon SET T_OrderHeaderAddOnLabNumberOrigin = ?
|
||||
WHERE T_OrderHeaderAddOnT_OrderHeaderID = ?";
|
||||
$qry = $this->db_onedev->query($sql,array($noOrder,$orderLabID));
|
||||
if(!$qry){
|
||||
$this->sys_error_db("select order error", $this->db_onedev);
|
||||
exit;
|
||||
}
|
||||
}
|
||||
|
||||
function update_status($orderID,$status){
|
||||
$sql = "UPDATE itb_yankes.download_order SET DownloadOrderStatus = ?
|
||||
WHERE DownloadOrderID = ?";
|
||||
$qry = $this->db_onedev->query($sql,array($status,$orderID));
|
||||
if(!$qry){
|
||||
$this->sys_error_db("update order error", $this->db_onedev);
|
||||
exit;
|
||||
}
|
||||
}
|
||||
|
||||
function send_result_all(){
|
||||
$sql="SELECT DownloadOrderID as order_id,
|
||||
T_OrderDetailT_OrderHeaderID as order_lab_id,
|
||||
DownloadOrderNIK as nik,
|
||||
DownloadOrderName as patient_name,
|
||||
DownloadOrderNumber as order_number,
|
||||
T_OrderDetailT_TestCode as bisone_test_code,
|
||||
test_yankes_code as yenkes_test_code,
|
||||
test_name as yankes_test,
|
||||
T_OrderDetailT_TestName as bisone_test,
|
||||
T_OrderDetailResult as result
|
||||
FROM t_orderdetail
|
||||
JOIN itb_yankes.map_test ON T_OrderDetailT_TestCode = test_bisone_code
|
||||
JOIN itb_yankes.order_map ON orderMapT_OrderHeaderID = T_OrderDetailT_OrderHeaderID
|
||||
JOIN itb_yankes.download_order ON orderMapDownloadOrderID = DownloadOrderID AND
|
||||
DownloadOrderStatus = 'mapped'
|
||||
WHERE
|
||||
T_OrderDetailT_TestIsResult = 'Y' AND
|
||||
T_OrderDetailValidation = 'Y' AND
|
||||
T_OrderDetailIsActive = 'Y'
|
||||
GROUP BY T_OrderDetailT_OrderHeaderID";
|
||||
$qry = $this->db_onedev->query($sql);
|
||||
if(!$qry){
|
||||
$this->sys_error_db("select order error", $this->db_onedev);
|
||||
exit;
|
||||
}
|
||||
|
||||
$data_send = $qry->result_array();
|
||||
|
||||
}
|
||||
|
||||
function send_result($orderLabID,$userID){
|
||||
$sql="SELECT DownloadOrderID as order_id,
|
||||
T_OrderDetailT_OrderHeaderID as order_lab_id,
|
||||
DownloadOrderNIK as nik,
|
||||
DownloadOrderName as patient_name,
|
||||
DownloadOrderNumber as order_number,
|
||||
T_OrderDetailT_TestCode as bisone_test_code,
|
||||
test_yankes_code as yenkes_test_code,
|
||||
test_name as yankes_test,
|
||||
T_OrderDetailT_TestName as bisone_test,
|
||||
T_OrderDetailResult as result
|
||||
FROM t_orderdetail
|
||||
JOIN itb_yankes.map_test ON T_OrderDetailT_TestCode = test_bisone_code
|
||||
JOIN itb_yankes.order_map ON orderMapT_OrderHeaderID = T_OrderDetailT_OrderHeaderID
|
||||
JOIN itb_yankes.download_order ON orderMapDownloadOrderID = DownloadOrderID
|
||||
WHERE
|
||||
T_OrderDetailT_OrderHeaderID = ? AND
|
||||
T_OrderDetailT_TestIsResult = 'Y' AND
|
||||
T_OrderDetailValidation = 'Y' AND
|
||||
T_OrderDetailIsActive = 'Y'
|
||||
GROUP BY T_OrderDetailID
|
||||
";
|
||||
$qry = $this->db_onedev->query($sql,[$orderLabID]);
|
||||
if(!$qry){
|
||||
$this->sys_error_db("select order error", $this->db_onedev);
|
||||
exit;
|
||||
}
|
||||
$details = $qry->result_array();
|
||||
if(count($details) > 0){
|
||||
$orderID = '';
|
||||
$no_order = '';
|
||||
$results = [];
|
||||
foreach ($details as $key => $value) {
|
||||
$orderID = $value['order_id'];
|
||||
$no_order = $value['order_number'];
|
||||
$results[] = ['test_id' => $value['yenkes_test_code'],'result' => $value['result'] ];
|
||||
}
|
||||
|
||||
$json_dt = array(
|
||||
array('no_order' => $no_order,'order_test' => $results)
|
||||
);
|
||||
$this->do_send_results($orderID,$no_order,$json_dt,$userID);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
function send_lab_results($json_data, $bearer_token) {
|
||||
// Base URL
|
||||
$baseUrl = 'https://yankes.itb.ac.id/data-services';// Ganti dengan base URL Anda
|
||||
$url = $baseUrl . "/api/update_hasil_lab";
|
||||
|
||||
// Initialize cURL
|
||||
$ch = curl_init($url);
|
||||
|
||||
// Set cURL options
|
||||
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
|
||||
curl_setopt($ch, CURLOPT_HTTPHEADER, [
|
||||
'Content-Type: application/json',
|
||||
'Authorization: Bearer ' . $bearer_token
|
||||
]);
|
||||
curl_setopt($ch, CURLOPT_POST, true);
|
||||
curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($json_data));
|
||||
|
||||
// Execute cURL request
|
||||
$response = curl_exec($ch);
|
||||
|
||||
// Check for errors
|
||||
if (curl_errno($ch)) {
|
||||
echo 'cURL Error: ' . curl_error($ch);
|
||||
} else {
|
||||
// Decode the response if needed
|
||||
$response_data = json_decode($response, true);
|
||||
return $response_data;
|
||||
//echo json_encode($response_data);
|
||||
//print_r($response_data);
|
||||
}
|
||||
|
||||
// Close cURL session
|
||||
curl_close($ch);
|
||||
}
|
||||
|
||||
function do_send_results($orderID,$no_order,$datas,$userID){
|
||||
// Contoh penggunaan fungsi
|
||||
/*$json_data = [
|
||||
"params" => [
|
||||
[
|
||||
"no_order" => "B2B-ITB-a2q002687",
|
||||
"order_test" => [
|
||||
["test_id" => "A001HE", "result" => "15.2"],
|
||||
["test_id" => "A002HE", "result" => "44"],
|
||||
["test_id" => "A003HE", "result" => "3.9"],
|
||||
// ... masukkan seluruh data lainnya sesuai kebutuhan
|
||||
]
|
||||
]
|
||||
]
|
||||
];*/
|
||||
|
||||
$json_data = [
|
||||
"params" => $datas
|
||||
];
|
||||
// Bearer token
|
||||
$bearer_token = 'eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJpc3MiOiJodHRwczpcL1wveWFua2VzLml0Yi5hYy5pZFwvZGV2LXNlcnZpY2VzXC9hcGlcL2F1dGhcL2xvZ2luIiwiaWF0IjoxNzI3MDg0NTcyLCJleHAiOjE3NTg2MjA1NzIsIm5iZiI6MTcyNzA4NDU3MiwianRpIjoiOWpGc3A0TmFIbnZWQkdrVyIsInN1YiI6NzcsInBydiI6IjIzYmQ1Yzg5NDlmNjAwYWRiMzllNzAxYzQwMDg3MmRiN2E1OTc2ZjcifQ.eduGs9bz64uD8paGYxJ1zxJ0du6lQ9yTFT7BzYTFg4A';
|
||||
// Ganti dengan token yang sesuai
|
||||
|
||||
// Panggil fungsi untuk mengirim data
|
||||
$rspn = $this->send_lab_results($json_data, $bearer_token);
|
||||
if($rspn){
|
||||
$status = 'success';
|
||||
if(!$rspn['success'])
|
||||
$status = 'failed';
|
||||
|
||||
$sql = "INSERT INTO itb_yankes.send_results (
|
||||
Send_ResultsOrderNumber,
|
||||
SendResultsJsonBefore,
|
||||
SendResultsJsonAfter,
|
||||
SendResultsStatus,
|
||||
SendResultsCreated,
|
||||
SendResultsCreatedUserID
|
||||
) VALUES(?,?,?,?,NOW(),?)";
|
||||
$qry = $this->db_onedev->query($sql,[$no_order,json_encode($json_data),json_encode($rspn),$status,$userID]);
|
||||
if(!$qry){
|
||||
$this->sys_error_db("insert send result error", $this->db_onedev);
|
||||
exit;
|
||||
}
|
||||
|
||||
|
||||
$this->update_status($orderID,'send_result');
|
||||
|
||||
return $rspn;
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
function sendresultorder(){
|
||||
if (! $this->isLogin) {
|
||||
$this->sys_error("Invalid Token");
|
||||
exit;
|
||||
}
|
||||
$prm = $this->sys_input;
|
||||
$xuserid = $this->sys_user['M_UserID'];
|
||||
$rspn = $this->send_result($prm['T_OrderHeaderID'],$xuserid);
|
||||
$result = array(
|
||||
|
||||
"records" => $rspn
|
||||
);
|
||||
$this->sys_ok($result);
|
||||
exit;
|
||||
}
|
||||
|
||||
function getlogs(){
|
||||
if (! $this->isLogin) {
|
||||
$this->sys_error("Invalid Token");
|
||||
exit;
|
||||
}
|
||||
$prm = $this->sys_input;
|
||||
$sql="SELECT *
|
||||
FROM itb_yankes.send_results
|
||||
WHERE
|
||||
Send_ResultsOrderNumber = ?";
|
||||
$qry = $this->db_onedev->query($sql,$prm['order_number_yankes']);
|
||||
if(!$qry){
|
||||
$this->sys_error_db("select order error", $this->db_onedev);
|
||||
exit;
|
||||
}
|
||||
|
||||
$data_send = $qry->result_array();
|
||||
$result = array(
|
||||
"records" => $data_send
|
||||
);
|
||||
$this->sys_ok($result);
|
||||
exit;
|
||||
|
||||
}
|
||||
|
||||
function rePushOrderXXX(){
|
||||
$prm = $this->sys_input;
|
||||
$this->load->library('Apilis');
|
||||
$kesimpulan = $this->apilis->GetOrderDetail($prm['T_OrderHeaderLabNumber']);
|
||||
if($kesimpulan){
|
||||
$this->sys_ok(array("status" => "OK", "message" => "success"));
|
||||
}else{
|
||||
$this->sys_error(array("status" => "ERR", "message" => "failed"));
|
||||
}
|
||||
exit;
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user