db_onedev = $this->load->database("onedev", true); $this->load->helper(array('form', 'url')); } public function search() { $prm = $this->sys_input; if (! $this->isLogin) { $this->sys_error("Invalid Token"); exit; } $code = $prm["McuOfflinePrepareCode"]; $limit = ''; $number_limit = 10; $number_offset = ($prm['current_page'] - 1) * $number_limit ; $sql = " SELECT count(*) as total FROM mcu_map_order WHERE Mcu_MapOrderMcuOfflinePrepareCode = '{$code}' "; //echo $sql; $query = $this->db_onedev->query($sql, $sql_param); //echo $this->db_onedev->last_query(); $tot_count = 0; $tot_page = 0; if ($query) { $tot_count = $query->result_array()[0]["total"]; $tot_page = ceil($tot_count/$number_limit); } else { $this->sys_error_db("m_patient count", $this->db_onedev); exit; } $sql = "SELECT mcu_map_order.*, '' as info,concat(M_TitleName,'. ',M_PatientName) as M_PatientName FROM mcu_map_order JOIN t_orderheader ON Mcu_MapOrderT_OrderHeaderNewID = T_OrderHeaderID JOIN m_patient ON T_OrderHeaderM_PatientID = M_PatientID JOIN m_title ON M_PatientM_TitleID = M_TitleID WHERE Mcu_MapOrderMcuOfflinePrepareCode = '{$code}' ORDER BY Mcu_MapOrderID DESC limit $number_limit offset $number_offset "; //echo $sql; $query = $this->db_onedev->query($sql, $sql_param); $rows = $query->result_array(); if ($rows) { foreach ($rows as $k => $v) { $rows[$k]['info'] = json_decode($v['Mcu_MapOrderInfo']); } } //$this->_add_address($rows); $result = array("total" => $tot_page, "records" => $rows, "setup"=> $xrow); $this->sys_ok($result); exit; } public function search_left() { $prm = $this->sys_input; if (! $this->isLogin) { $this->sys_error("Invalid Token"); exit; } $sql_where = ""; $sql_param = array(); $where = ''; if (isset($prm['name'])) { $where = " AND McuOfflinePrepareCode LIKE '%{$prm['name']}%'"; } $number_limit = 10; $number_offset = ($prm['current_page'] - 1) * $number_limit ; $sql = " SELECT count(*) as total FROM mcu_offline_prepare WHERE McuOfflinePrepareIsActive = 'Y' $where "; //echo $sql; $query = $this->db_onedev->query($sql, $sql_param); //echo $this->db_onedev->last_query(); $tot_count = 0; $tot_page = 0; if ($query) { $tot_count = $query->result_array()[0]["total"]; $tot_page = ceil($tot_count/$number_limit); } else { $this->sys_error_db("mcu_offline_prepare count", $this->db_onedev); exit; } $sql = "SELECT mcu_offline_prepare.*, DATE_FORMAT(McuOfflinePrepareStartDate, '%d-%m-%Y') as start_date, DATE_FORMAT(McuOfflinePrepareEndDate, '%d-%m-%Y') as end_date, M_CompanyName FROM mcu_offline_prepare JOIN m_company ON McuOfflinePrepareM_CompanyID = M_CompanyID WHERE McuOfflinePrepareIsActive = 'Y' $where LIMIT $number_limit offset $number_offset "; //echo $sql; $query = $this->db_onedev->query($sql); $rows = $query->result_array(); $result = array("total" => $tot_page, "records" => $rows, "setup"=> $xrow); $this->sys_ok($result); exit; } public function savedata() { //print_r($_FILES['file']); $filename = $_FILES['file']['name']; $path = '/home/one/project/one/one-media/one-image-nonlab/'; //unlink($path.$filename); if (!file_exists($path.$filename)) { $check = is_uploaded_file($_FILES["file"]["tmp_name"]); if ($check) { if (move_uploaded_file($_FILES["file"]["tmp_name"], $path . $filename)) { $userID = $this->sys_user["M_UserID"]; $mcuCode = substr($filename, 0, 9); $sql = "select * from mcu_offline_prepare where McuOfflinePrepareCode = ?"; $qry = $this->db->query($sql, array($mcuCode)); if (!$qry) { unlink($path.$filename); $this->sys_error($this->db->error()["message"] . "|" . $this->db->last_query()); exit; } $rows = $qry->result_array(); if (count($rows) == 0) { unlink($path.$filename); $this->sys_error("Invalid MCU Code : $mcuCode file uploaded."); exit; } $sql = "select * from m_branch where M_BranchIsActive = 'Y' and M_BranchIsDefault = 'Y'"; $qry = $this->db->query($sql); if (!$qry) { unlink($path.$filename); $this->sys_error($this->db->error()["message"] . "|" . $this->db->last_query()); exit; } $rows = $qry->result_array(); if (count($rows) == 0) { unlink($path.$filename); $this->sys_error("Invalid Branch file uploaded."); exit; } $branchID = $rows[0]["M_BranchID"]; $data = array( "McuOfflineUploadName" => $filename, "McuOfflineUploadFullName" => $path . $filename, "McuOfflineUploadMcuOfflinePrepareCode" => $mcuCode, "McuOfflineUploadM_UserID" => $userID, "McuOfflineUploadM_BranchID" => $branchID ); $qry = $this->db->insert("mcu_offline_upload_v2", $data); if (! $qry) { unlink($path.$filename); $this->sys_error($this->db->error()["message"] . "|" . $this->db->last_query()); exit; } $status = array("status" => "OK"); $this->sys_ok($status); } else { $error = "File : $filename error moving to $path !!"; $this->sys_error($error); } } else { $error = "File : $filename corrupt : check size = $check !!"; $this->sys_error($error); } } else { $error = "File : $filename already uploaded!!"; $this->sys_error($error); } } public function uncompress($srcName, $dstName) { $sfp = gzopen($srcName, "rb"); $fp = fopen($dstName, "w"); while (!gzeof($sfp)) { $string = gzread($sfp, 10000); fwrite($fp, $string, strlen($string)); } gzclose($sfp); fclose($fp); } public function db() { $xdb = $this->load->database("onedev", true); $pwd = $xdb->password; $sql = "SELECT McuOfflinePrepareID as xid, McuOfflinePrepareCode as xcode FROM temp_mcu.mcu_offline_prepare WHERE McuOfflinePrepareIsActive = 'Y' AND McuOfflinePrepareIsDownloaded = 'Y' LIMIT 1"; $xrow = $this->db->query($sql)->row_array(); if ($xrow) { $prepare_id = $xrow['xid']; $xcode = date('YmdHis')."-".$xrow['xcode']; $sql = "INSERT INTO mcu_session.mcu_session ( McuSessionCode, McuSessionMcuOfflinePrepareID ) VALUES( '{$xcode}', {$prepare_id} )"; //echo $sql; $this->db->query($sql); $mcu_sessionID = $this->db->insert_id(); //echo $mcu_sessionID ; $sql = "show tables"; $rows = $this->db->query($sql)->result_array(); if ($rows) { foreach ($rows as $k => $v) { $query = " SELECT * FROM information_schema.tables WHERE table_schema = 'temp_mcu' AND table_name = '{$v['Tables_in_one']}' LIMIT 1"; //echo $query; $row = $this->db->query($query)->row_array(); if ($row) { $sql = "INSERT INTO mcu_session.{$v['Tables_in_one']} SELECT temp_mcu.{$v['Tables_in_one']}.*, {$mcu_sessionID} FROM temp_mcu.{$v['Tables_in_one']} "; //echo $sql; $this->db->query($sql); if ($v['Tables_in_one'] == 'so_resultentry') { //echo $sql; } } } } $this->generate_orders($mcu_sessionID); } } public function generate_orders($mcu_sessionID) { $sql = "SELECT * FROM mcu_session.mcu_screening WHERE Mcu_ScreeningIsExport = 'V' AND Mcu_ScreeningMcuSessionID = {$mcu_sessionID}"; //echo $sql; $export_data = $this->db->query($sql)->result(); if (export_data) { //print_r($export_data); foreach ($export_data as $k => $v) { $header_id = 0; /*check sdh pernah dibuat order atau belum*/ $sql = "SELECT * FROM one.mcu_map_order JOIN one.t_orderheader one_order ON one_order.T_OrderHeaderID = Mcu_MapOrderT_OrderHeaderNewID WHERE Mcu_MapOrderT_OrderHeaderID = {$v->Mcu_ScreeningT_OrderHeaderID}"; //echo $sql; $xrow = $this->db->query($sql)->row_array(); //print_r($xrow); if ($xrow) { /*pernah dibuat order*/ $header_id = $xrow['Mcu_MapOrderT_OrderHeaderNewID']; $header_labno = $xrow['T_OrderHeaderLabNumber']; } else { /*belum pernah dibuat order*/ $this->db->trans_start(); /**begin membuat order baru**/ /***insert tabel orderheader dan rentetannya***/ $sql = "SELECT * FROM mcu_session.t_orderheader WHERE T_OrderHeaderID = {$v->Mcu_ScreeningT_OrderHeaderID} AND T_OrderHeaderMcuSessionID = {$v->Mcu_ScreeningMcuSessionID}"; $data_header = $this->db->query($sql)->row_array(); //print_r($data_header); unset($data_header['T_OrderHeaderID']); unset($data_header['T_OrderHeaderMcuSessionID']); //print_r($data_header); $this->db->insert('one.t_orderheader', $data_header); //echo $this->db->last_query(); $header_id = $this->db->insert_id(); $sql = "UPDATE one.t_orderheader SET T_OrderHeaderLabNumber = '{$data_header['T_OrderHeaderLabNumber']}', T_OrderHeaderLabNumberExt = '{$data_header['T_OrderHeaderLabNumberExt']}' WHERE T_OrderHeaderID = {$header_id}"; $this->db->query($sql); //echo $sql; $sql = "SELECT * FROM one.t_orderheader WHERE T_OrderHeaderID = {$header_id}"; $data_one_order = $this->db->query($sql)->row_array(); $header_labno = $data_one_order['T_OrderHeaderLabNumber']; $sql = "DELETE FROM one.t_orderheaderaddon WHERE T_OrderHeaderAddOnT_OrderHeaderID = {$header_id}"; $this->db->query($sql); $sql = "SELECT * FROM mcu_session.t_orderheaderaddon WHERE T_OrderHeaderAddOnT_OrderHeaderID = {$v->Mcu_ScreeningT_OrderHeaderID} AND T_OrderHeaderAddOnMcuSessionID = {$v->Mcu_ScreeningMcuSessionID}"; $data_header_addon = $this->db->query($sql)->row_array(); $data_header_addon['T_OrderHeaderAddOnT_OrderHeaderID'] = $header_id; unset($data_header_addon['T_OrderHeaderAddOnID']); unset($data_header_addon['T_OrderHeaderAddOnMcuSessionID']); $this->db->insert('one.t_orderheaderaddon', $data_header_addon); $sql = "DELETE FROM one.fo_status WHERE Fo_StatusT_OrderHeaderID = {$header_id}"; $this->db->query($sql); $sql = "SELECT * FROM mcu_session.fo_status WHERE Fo_StatusT_OrderHeaderID = {$v->Mcu_ScreeningT_OrderHeaderID} AND Fo_StatusMcuSessionID = {$v->Mcu_ScreeningMcuSessionID}"; $datas_fo_status = $this->db->query($sql)->result_array(); foreach ($datas_fo_status as $kx => $vx) { $datas_fo_status[$kx]['Fo_StatusT_OrderHeaderID'] = $header_id; unset($datas_fo_status[$kx]['Fo_StatusID']); unset($datas_fo_status[$kx]['Fo_StatusMcuSessionID']); } $this->db->insert_batch('one.fo_status', $datas_fo_status); //echo $this->db->last_query(); $sql = "SELECT * FROM mcu_session.t_orderdetail WHERE T_OrderDetailT_OrderHeaderID = {$v->Mcu_ScreeningT_OrderHeaderID} AND T_OrderDetailMcuSessionID = {$v->Mcu_ScreeningMcuSessionID} GROUP BY T_OrderDetailID"; //echo $sql; $datas_details = $this->db->query($sql)->result_array(); foreach ($datas_details as $k_detail => $v_detail) { $v_detail['T_OrderDetailT_OrderHeaderID'] = $header_id; unset($v_detail['T_OrderDetailID']); unset($v_detail['T_OrderDetailMcuSessionID']); $this->db->insert('one.t_orderdetail', $v_detail); //if($k_detail == 0) //echo $this->db->last_query(); $detail_id = $this->db->insert_id(); $sql = "DELETE FROM one.t_orderdetailaddon WHERE T_OrderDetailAddOnT_OrderDetailID = {$detail_id}"; $this->db->query($sql); $sql = "SELECT t_orderdetailaddon.* FROM mcu_session.t_orderdetail JOIN mcu_session.t_orderdetailaddon ON T_OrderDetailAddOnT_OrderDetailID = T_OrderDetailID WHERE T_OrderDetailT_OrderHeaderID = {$v->Mcu_ScreeningT_OrderHeaderID} AND T_OrderDetailT_TestID = {$v_detail['T_OrderDetailT_TestID']} AND T_OrderDetailCreated = '{$v_detail['T_OrderDetailCreated']}' AND T_OrderDetailMcuSessionID = {$v->Mcu_ScreeningMcuSessionID} LIMIT 1"; //echo $sql; $data_detail_addon = $this->db->query($sql)->row_array(); unset($data_detail_addon['T_OrderDetailAddOnID']); unset($data_detail_addon['T_OrderDetailAddOnMcuSessionID']); $data_detail_addon['T_OrderDetailAddOnT_OrderDetailID'] = $detail_id; $this->db->insert('one.t_orderdetailaddon', $data_detail_addon); } /**end membuat order baru**/ $this->db->trans_complete(); $sql = "SELECT * FROM mcu_session.last_master_id WHERE LastMasterMcuSessionID = {$v->Mcu_ScreeningMcuSessionID}"; $last_master = $this->db->query($sql)->row_array(); $sql = "SELECT * FROM mcu_session.t_orderdelivery WHERE T_OrderDeliveryT_OrderHeaderID = {$v->Mcu_ScreeningT_OrderHeaderID} AND T_OrderDeliveryMcuSessionID = {$v->Mcu_ScreeningMcuSessionID} "; //echo $sql; $deliveries = $this->db->query($sql)->result_array(); if ($deliveries) { foreach ($deliveries as $k_delivery => $v_delivery) { //print_r($v_delivery); unset($v_delivery['T_OrderDeliveryID']); unset($v_delivery['T_OrderDeliveryMcuSessionID']); $v_delivery['T_OrderDeliveryT_OrderHeaderID'] = $header_id; $this->db->insert('one.t_orderdelivery', $v_delivery); //echo $this->db->last_query(); } } $sql = "SELECT mcu_session.t_orderdeliverynote.* FROM mcu_session.t_orderdelivery JOIN mcu_session.t_orderdeliverynote ON T_OrderDeliveryNoteT_OrderDeliveryID = T_OrderDeliveryID AND T_OrderDeliveryNoteIsActive = 'Y' WHERE T_OrderDeliveryT_OrderHeaderID = {$v->Mcu_ScreeningT_OrderHeaderID} AND T_OrderDeliveryMcuSessionID = {$v->Mcu_ScreeningMcuSessionID}"; //echo $sql; $deliveries_note = $this->db->query($sql)->result_array(); if ($deliveries_note) { foreach ($deliveries_note as $k_deliverynote => $v_deliverynote) { unset($v_delivery['T_OrderDeliveryNoteID']); unset($v_delivery['T_OrderDeliveryNoteMcuSessionID']); $v_delivery['T_OrderDeliveryNoteT_OrderHeaderID'] = $header_id; $this->db->insert('one.t_orderdeliverynote', $v_delivery); } } $sql = "SELECT * FROM mcu_session.t_orderpromise WHERE T_OrderPromiseT_OrderHeaderID = {$v->Mcu_ScreeningT_OrderHeaderID} AND T_OrderPromiseMcuSessionID = {$v->Mcu_ScreeningMcuSessionID}"; $promises = $this->db->query($sql)->result_array(); if ($promises) { foreach ($promises as $k_promise => $v_promise) { unset($v_promise['T_OrderPromiseID']); unset($v_promise['T_OrderPromiseMcuSessionID']); $v_promise['T_OrderPromiseT_OrderHeaderID'] = $header_id; $this->db->insert('one.t_orderpromise', $v_promise); } } /*****order_log****/ $sql = "SELECT * FROM mcu_session.order_log WHERE OrderLogT_OrderHeaderID = {$v->Mcu_ScreeningT_OrderHeaderID} AND OrderLogT_OrderHeaderMcuSessionID = {$v->Mcu_ScreeningMcuSessionID}"; $order_log = $this->db->query($sql)->result_array(); if ($order_log) { foreach ($order_log as $k_order_log => $v_order_log) { unset($v_order_log['OrderLogID']); unset($v_order_log['OrderLogT_OrderHeaderMcuSessionID']); $v_order_log['OrderLogT_OrderHeaderID'] = $header_id; $this->db->insert('one.order_log', $v_order_log); } } $sql = "SELECT * FROM mcu_session.order_attr WHERE orderAttrT_OrderHeaderID = {$v->Mcu_ScreeningT_OrderHeaderID} AND orderAttrMcuSessionID = {$v->Mcu_ScreeningMcuSessionID}"; $order_attr = $this->db->query($sql)->result_array(); if ($order_attr) { foreach ($order_attr as $k_order_attr => $v_order_attr) { unset($v_order_attr['orderAttrID']); unset($v_order_attr['orderAttrMcuSessionID']); $v_order_attr['orderAttrT_OrderHeaderID'] = $header_id; $this->db->insert('one.order_attr', $v_order_attr); } } $sql = "SELECT * FROM mcu_session.order_delivery WHERE Order_DeliveryT_OrdeheaderID = {$v->Mcu_ScreeningT_OrderHeaderID} AND Order_DeliveryMcuSessionID = {$v->Mcu_ScreeningMcuSessionID}"; $order_delivery = $this->db->query($sql)->result_array(); if ($order_delivery) { foreach ($order_delivery as $k_order_delivery => $v_order_delivery) { unset($v_order_delivery['Order_DeliveryID']); unset($v_order_delivery['Order_DeliveryMcuSessionID']); $v_order_delivery['Order_DeliveryT_OrdeheaderID'] = $header_id; $this->db->insert('one.order_delivery', $order_delivery); } } $sql = "SELECT * FROM mcu_session.order_px WHERE OrderPxT_OrderHeaderID = {$v->Mcu_ScreeningT_OrderHeaderID} AND OrderPxMcuSessionID = {$v->Mcu_ScreeningMcuSessionID}"; $order_px = $this->db->query($sql)->result_array(); if ($order_px) { foreach ($order_px as $k_order_px=> $v_order_px) { unset($v_order_px['OrderPxID']); unset($v_order_px['OrderPxMcuSessionID']); $v_order_px['OrderPxT_OrderHeaderID'] = $header_id; $this->db->insert('one.order_px', $order_px); } } /*****order_log****/ } if ($header_id != 0) { $sql = "SELECT * FROM one.mcu_map_order JOIN one.t_orderheader one_order ON one_order.T_OrderHeaderID = Mcu_MapOrderT_OrderHeaderNewID WHERE Mcu_MapOrderT_OrderHeaderID = {$v->Mcu_ScreeningT_OrderHeaderID} AND Mcu_MapOrderT_SampleTypeID = {$v->Mcu_ScreeningT_SampleTypeID} AND Mcu_MapOrderT_TestID = {$v->Mcu_ScreeningT_TestID} AND Mcu_MapOrderT_OrderHeaderNewID = {$header_id}"; $map_row = $this->db->query($sql)->row_array(); if (count($map_row) == 0) { $sql = "SELECT * FROM mcu_session.mcu_offline_prepare WHERE McuOfflinePrepareIsActive = 'Y' AND McuOfflinePrepareMcuSessionID = {$mcu_sessionID}"; $prepare_offline = $this->db->query($sql)->row_array(); $sql = "SELECT mcu_screening.*, IFNULL(T_TestName,'') test_name, IFNULL(T_SampleTypeName,'') sample_name, session_order.T_OrderHeaderLabNumber mcu_nolab, McuSessionCode as session_code FROM mcu_session.mcu_screening LEFT JOIN mcu_session.mcu_session ON Mcu_ScreeningMcuSessionID = McuSessionID LEFT JOIN one.t_test ON Mcu_ScreeningT_TestID = T_TestID LEFT JOIN one.t_sampletype ON Mcu_ScreeningT_SampleTypeID = T_SampleTypeID LEFT JOIN mcu_session.t_orderheader session_order ON Mcu_ScreeningT_OrderHeaderID = session_order.T_OrderHeaderID WHERE Mcu_ScreeningID = {$v->Mcu_ScreeningID} AND Mcu_ScreeningMcuSessionID = {$v->Mcu_ScreeningMcuSessionID} "; //echo $sql; $dt_screening = $this->db->query($sql)->row_array(); //print_r($dt_screening); //echo $dt_screening['sample_name']; $dt_mcu = array( 'prepare_code'=>$prepare_offline['McuOfflinePrepareCode'], 'mcu_nolab' => $dt_screening['mcu_nolab'], 'one_nolab' => $header_labno, 'test_name' => $dt_screening['test_name'], 'sample_name' => $dt_screening['sample_name'], 'session_code' => $dt_screening['session_code'] ); $dt_mcu = json_encode($dt_mcu); $map_mcu = array( 'Mcu_MapOrderMcuOfflinePrepareCode' => $prepare_offline['McuOfflinePrepareCode'], 'Mcu_MapOrderT_OrderHeaderID' => $v->Mcu_ScreeningT_OrderHeaderID, 'Mcu_MapOrderT_SampleTypeID' => $v->Mcu_ScreeningT_SampleTypeID, 'Mcu_MapOrderT_TestID' => $v->Mcu_ScreeningT_TestID, 'Mcu_MapOrderIsNonLab' => $v->Mcu_ScreeningIsNonLab, 'Mcu_MapOrderT_OrderHeaderNewID' => $header_id, 'Mcu_MapOrderMcu_SessionID' => $v->Mcu_ScreeningMcuSessionID, 'Mcu_MapOrderMcu_SessionCode' => $dt_screening['session_code'], 'Mcu_MapOrderInfo' => $dt_mcu ); $this->db->insert('one.mcu_map_order', $map_mcu); } $sql = "SELECT * FROM mcu_session.t_barcodelab WHERE T_BarcodeLabT_OrderHeaderID = {$v->Mcu_ScreeningT_OrderHeaderID} AND T_BarcodeLabMcuSessionID = {$v->Mcu_ScreeningMcuSessionID} AND T_BarcodeLabT_SampleTypeID = {$v->Mcu_ScreeningT_SampleTypeID}"; $datas_barcode = $this->db->query($sql)->result_array(); if ($datas_barcode) { foreach ($datas_barcode as $kx => $vx) { $datas_barcode[$kx]['T_BarcodeLabT_OrderHeaderID'] = $header_id; unset($datas_barcode[$kx]['T_BarcodeLabID']); unset($datas_barcode[$kx]['T_BarcodeLabMcuSessionID']); $this->db->insert('one.t_barcodelab', $datas_barcode[$kx]); //$last_x_id = $this->db->insert_id(); } $this->db->insert_batch('one.t_barcodelab', $datas_barcode); } if ($v->Mcu_ScreeningT_SampleTypeID != 0) { $sql = "SELECT * FROM mcu_session.t_ordersample WHERE T_OrderSampleT_OrderHeaderID = {$v->Mcu_ScreeningT_OrderHeaderID} AND T_OrderSampleT_SampleTypeID = {$v->Mcu_ScreeningT_SampleTypeID} AND T_OrderSampleMcuSessionID = {$mcu_sessionID}"; //echo $sql; $datas_order_samples = $this->db->query($sql)->result_array(); if ($datas_order_samples) { foreach ($datas_order_samples as $kx => $vx) { $sql = " SELECT * FROM one.t_barcodelab WHERE T_BarcodeLabT_OrderHeaderID = {$header_id} AND T_BarcodeLabT_SampleTypeID = {$v->Mcu_ScreeningT_SampleTypeID} AND T_BarcodeLabIsActive = 'Y' LIMIT 1 "; $data_barcode = $this->db->query($sql)->row_array(); $old_x_id = $datas_order_samples[$kx]['T_OrderSampleID']; $sql = "DELETE FROM one.t_ordersample WHERE T_OrderSampleT_OrderHeaderID = {$header_id} AND T_OrderSampleT_SampleTypeID = {$v->Mcu_ScreeningT_SampleTypeID} "; $this->db->query($sql); $datas_order_samples[$kx]['T_OrderSampleT_OrderHeaderID'] = $header_id; $datas_order_samples[$kx]['T_OrderSampleT_BarcodeLabID'] = $data_barcode['T_BarcodeLabID']; unset($datas_order_samples[$kx]['T_OrderSampleID']); unset($datas_order_samples[$kx]['T_OrderSampleMcuSessionID']); $this->db->insert('one.t_ordersample', $datas_order_samples[$kx]); //echo $this->db->last_query(); $last_x_id = $this->db->insert_id(); $sql = "SELECT * FROM mcu_session.t_ordersamplereq WHERE T_OrderSampleReqT_OrderHeaderID = {$v->Mcu_ScreeningT_OrderHeaderID} AND T_OrderSampleReqT_OrderSampleID = {$old_x_id} AND T_OrderSampleReqMcuSessionID = {$mcu_sessionID}"; //echo $sql; $datas_order_samples_req = $this->db->query($sql)->result_array(); if ($datas_order_samples_req) { foreach ($datas_order_samples_req as $kx_x => $vx_x) { $datas_order_samples_req[$kx_x]['T_OrderSampleReqT_OrderSampleID'] = $last_x_id; unset($datas_order_samples_req[$kx_x]['T_OrderSampleReqID']); unset($datas_order_samples_req[$kx_x]['T_OrderSampleReqIDMcuSessionID']); $this->db->insert('one.t_ordersamplereq', $datas_order_samples_req[$kx]); } } $sql = "DELETE FROM one.sample_by_step WHERE SampleByStepT_OrderHeaderID = {$header_id} AND SampleByStepT_BarcodeLabID = {$data_barcode['T_BarcodeLabID']} AND SampleByStepMcuSessionID = {$mcu_sessionID} "; $this->db->query($sql); $sql = "SELECT * FROM mcu_session.sample_by_step WHERE SampleByStepT_OrderHeaderID = {$v->Mcu_ScreeningT_OrderHeaderID} AND SampleByStepT_BarcodeLabID = {$vx['T_OrderSampleT_BarcodeLabID']}"; $datas_log_sample = $this->db->query($sql)->result_array(); foreach ($datas_log_sample as $k_logsample => $v_logsample) { $datas_log_sample[$k_logsample]['SampleByStepT_OrderHeaderID'] = $header_id; $datas_log_sample[$k_logsample]['SampleByStepT_BarcodeLabID'] = $data_barcode['T_BarcodeLabID']; unset($datas_log_sample[$k_logsample]['SampleByStepID']); unset($datas_log_sample[$k_logsample]['SampleByStepMcuSessionID']); $this->db->insert('one.sample_by_step', $datas_log_sample[$k_logsample]); //echo $this->db->last_query(); } } $sql = "SELECT T_BahanT_SampleStationID as station_id FROM one.t_sampletype JOIN one.t_bahan ON T_SampleTypeT_BahanID = T_BahanID AND T_BahanIsActive = 'Y' WHERE T_SampleTypeID = {$v->Mcu_ScreeningT_SampleTypeID} LIMIT 1"; //echo $sql; $get_station_id = $this->db->query($sql)->row(); if ($get_station_id) { $station_id = $get_station_id->station_id; $sql = "SELECT * FROM mcu_session.t_sampling_queue_last_status WHERE T_SamplingQueueLastStatusT_OrderHeaderID = {$v->Mcu_ScreeningT_OrderHeaderID} AND T_SamplingQueueLastStatusT_SampleStationID = {$station_id} AND T_SamplingQueueLastStatusMcuSessionID = {$v->Mcu_ScreeningMcuSessionID}"; $get_last_queue = $this->db->query($sql)->row_array(); if ($get_last_queue['T_SamplingQueueLastStatusT_SamplingQueueStatusID'] = 5) { $sql = "DELETE FROM one.t_sampling_queue_last_status WHERE T_SamplingQueueLastStatusT_OrderHeaderID = {$header_id} AND T_SamplingQueueLastStatusT_SampleStationID = {$station_id_so}"; $this->db->query($sql); $get_last_queue['T_SamplingQueueLastStatusT_OrderHeaderID'] = $header_id; unset($get_last_queue['T_SamplingQueueLastStatusID']); unset($get_last_queue['T_SamplingQueueLastStatusMcuSessionID']); $this->db->insert('one.t_sampling_queue_last_status', $get_last_queue); $sql = "DELETE FROM one.t_sampling_queue_by_action WHERE T_SamplingQueueByActionT_OrderHeaderID = {$v->Mcu_ScreeningT_OrderHeaderID} AND T_SamplingQueueByActionT_SampleStationID = {$station_id} "; $this->db->query($sql); $sql = "SELECT * FROM mcu_session.t_sampling_queue_by_action WHERE T_SamplingQueueByActionT_SampleStationID = {$station_id} AND T_SamplingQueueByActionT_OrderHeaderID = {$v->Mcu_ScreeningT_OrderHeaderID} AND T_SamplingQueueByActionMcuSessionID = {$v->Mcu_ScreeningMcuSessionID}"; //echo $sql; $queue_action = $this->db->query($sql)->result_array(); foreach ($queue_action as $kx => $vx) { $queue_action[$kx]['T_SamplingQueueByActionT_OrderHeaderID'] = $header_id; unset($queue_action[$kx]['T_SamplingQueueByActionID']); unset($queue_action[$kx]['T_SamplingQueueByActionMcuSessionID']); } $this->db->insert_batch('one.t_sampling_queue_by_action', $queue_action); //echo $this->db->last_query(); } } $sql = "SELECT * FROM one.t_orderdetail JOIN one.t_test ON T_OrderDetailT_TestID = T_TestID AND T_TestT_SampleTypeID = {$v->Mcu_ScreeningT_SampleTypeID} WHERE T_OrderDetailT_OrderHeaderID = {$header_id} AND T_OrderDetailIsActive = 'Y'"; //echo $sql; $one_orderdetail = $this->db->query($sql)->result_array(); foreach ($one_orderdetail as $kx => $vx) { $sql = "DELETE FROM one.t_orderdetail WHERE T_OrderDetailID = {$vx['T_OrderDetailID']}"; $this->db->query($sql); } $sql = "SELECT t_orderdetail.* FROM mcu_session.t_orderdetail JOIN one.t_test ON T_OrderDetailT_TestID = T_TestID AND T_TestT_SampleTypeID = {$v->Mcu_ScreeningT_SampleTypeID} WHERE T_OrderDetailT_OrderHeaderID = {$v->Mcu_ScreeningT_OrderHeaderID} AND T_OrderDetailMcuSessionID = {$v->Mcu_ScreeningMcuSessionID} AND T_OrderDetailIsActive = 'Y' GROUP BY T_OrderDetailID"; //echo $sql; $mcu_orderdetail = $this->db->query($sql)->result_array(); foreach ($mcu_orderdetail as $kx => $vx) { $vx['T_OrderDetailT_OrderHeaderID'] = $header_id; unset($vx['T_OrderDetailID']); unset($vx['T_OrderDetailMcuSessionID']); $this->db->insert('one.t_orderdetail', $vx); } } } /*begin nonlab*/ if ($v->Mcu_ScreeningT_TestID != 0) { $sql = "SELECT T_BahanT_SampleStationID as station_id FROM one.t_test JOIN one.t_sampletype ON T_TestT_SampleTypeID = T_SampleTypeID JOIN one.t_bahan ON T_SampleTypeT_BahanID = T_BahanID WHERE T_TestID = {$v->Mcu_ScreeningT_TestID} LIMIT 1"; //echo $sql; $get_station_id_so = $this->db->query($sql)->row(); $station_id_so = $get_station_id_so->station_id; $sql = "SELECT * FROM mcu_session.t_samplingso WHERE T_SamplingSoT_OrderHeaderID = {$v->Mcu_ScreeningT_OrderHeaderID} AND T_SamplingSoT_TestID = {$v->Mcu_ScreeningT_TestID} AND T_SamplingSoMcuSessionID = {$v->Mcu_ScreeningMcuSessionID} AND T_SamplingSoT_SampleStationID = {$station_id_so}"; //echo $sql; $datas_order_samples_so = $this->db->query($sql)->result_array(); if ($datas_order_samples_so) { $sql = "SELECT * FROM mcu_session.t_sampling_queue_last_status WHERE T_SamplingQueueLastStatusT_OrderHeaderID = {$v->Mcu_ScreeningT_OrderHeaderID} AND T_SamplingQueueLastStatusMcuSessionID = {$v->Mcu_ScreeningMcuSessionID} AND T_SamplingQueueLastStatusT_SampleStationID = {$station_id_so}"; $get_last_queue_so = $this->db->query($sql)->row_array(); if ($get_last_queue_so['T_SamplingQueueLastStatusT_SamplingQueueStatusID'] = 5) { $sql = "DELETE FROM one.t_sampling_queue_last_status WHERE T_SamplingQueueLastStatusT_OrderHeaderID = {$header_id} AND T_SamplingQueueLastStatusT_SampleStationID = {$station_id_so}"; $this->db->query($sql); $get_last_queue_so['T_SamplingQueueLastStatusT_OrderHeaderID'] = $header_id; unset($get_last_queue_so['T_SamplingQueueLastStatusID']); unset($get_last_queue_so['T_SamplingQueueLastStatusMcuSessionID']); $this->db->insert('one.t_sampling_queue_last_status', $get_last_queue_so); $sql = "DELETE FROM one.t_sampling_queue_by_action WHERE T_SamplingQueueByActionT_OrderHeaderID = {$v->Mcu_ScreeningT_OrderHeaderID} AND T_SamplingQueueByActionT_SampleStationID = {$station_id_so} "; $this->db->query($sql); $sql = "SELECT * FROM mcu_session.t_sampling_queue_by_action WHERE T_SamplingQueueByActionT_SampleStationID = {$station_id_so} AND T_SamplingQueueByActionMcuSessionID = {$v->Mcu_ScreeningMcuSessionID} AND T_SamplingQueueByActionT_OrderHeaderID = {$v->Mcu_ScreeningT_OrderHeaderID}"; //echo $sql; $queue_action_so = $this->db->query($sql)->result_array(); //print_r($queue_action_so); foreach ($queue_action_so as $kx => $vx) { $queue_action_so[$kx]['T_SamplingQueueByActionT_OrderHeaderID'] = $header_id; unset($queue_action_so[$kx]['T_SamplingQueueByActionID']); unset($queue_action_so[$kx]['T_SamplingQueueByActionMcuSessionID']); } $this->db->insert_batch('one.t_sampling_queue_by_action', $queue_action_so); } foreach ($datas_order_samples_so as $k_so => $v_so) { $v_so['T_SamplingSoT_OrderHeaderID'] = $header_id; unset($v_so['T_SamplingSoID']); unset($v_so['T_SamplingSoMcuSessionID']); $this->db->insert('one.t_samplingso', $v_so); $last_sampling_so_id = $this->db->insert_id(); $sql = "SELECT * FROM mcu_session.t_samplingso_requirement WHERE T_SamplingSoRequirementT_SamplingSoID = {$last_sampling_so_id} AND T_SamplingSoRequirementMcuSessionID = {$v->Mcu_ScreeningMcuSessionID} AND T_SamplingSoRequirementT_OrderHeaderID = {$v->Mcu_ScreeningT_OrderHeaderID}"; $requirement_so = $this->db->query($sql)->result_array(); foreach ($requirement_so as $kx => $vx) { $requirement_so[$kx]['T_SamplingSoRequirementT_OrderHeaderID'] = $header_id; unset($requirement_so[$kx]['T_SamplingSoRequirementID']); unset($requirement_so[$kx]['T_SamplingSoRequirementMcuSessionID']); } $this->db->insert_batch('one.t_samplingso_requirement', $requirement_so); $sql = "SELECT * FROM mcu_session.t_samplingso_film WHERE T_SamplingSoFilmT_SamplingSoID = {$last_sampling_so_id}"; $film_so = $this->db->query($sql)->result_array(); foreach ($film_so as $kx => $vx) { unset($film_so[$kx]['T_SamplingSoFilmID']); unset($film_so[$kx]['T_SamplingSoFilmMcuSessionID']); } $this->db->insert_batch('one.t_samplingso_film', $film_so); $sql = "SELECT * FROM mcu_session.t_samplingso_form WHERE T_SamplingSoFormT_SamplingSOID = {$last_sampling_so_id} AND T_SamplingSoFormMcuSessionID = {$v->Mcu_ScreeningMcuSessionID} AND T_SamplingSoFormT_SampleStationID = {$station_id_so}"; $form_so = $this->db->query($sql)->result_array(); foreach ($form_so as $kx => $vx) { unset($form_so[$kx]['T_SamplingSoFormID']); unset($form_so[$kx]['T_SamplingSoFormMcuSessionID']); } $this->db->insert_batch('one.t_samplingso_form', $form_so); } $sql = "SELECT * FROM one.t_orderdetail WHERE T_OrderDetailT_OrderHeaderID = {$header_id} AND T_OrderDetailT_TestID = {$v->Mcu_ScreeningT_TestID} AND T_OrderDetailIsActive = 'Y'"; $one_orderdetail = $this->db->query($sql)->row_array(); $one_orderdetail_id = $one_orderdetail['T_OrderDetailID']; $sql = "SELECT * FROM mcu_session.t_orderdetail WHERE T_OrderDetailT_OrderHeaderID = {$v->Mcu_ScreeningT_OrderHeaderID} AND T_OrderDetailT_TestID = {$v->Mcu_ScreeningT_TestID} AND T_OrderDetailMcuSessionID = {$v->Mcu_ScreeningMcuSessionID} AND T_OrderDetailIsActive = 'Y'"; $mcu_orderdetail = $this->db->query($sql)->row_array(); $mcu_orderdetail_id = $mcu_orderdetail['T_OrderDetailID']; unset($mcu_orderdetail['T_OrderDetailID']); unset($mcu_orderdetail['T_OrderDetailMcuSessionID']); $mcu_orderdetail['T_OrderDetailT_OrderHeaderID'] = $header_id; $this->db->update('one.t_orderdetail', $mcu_orderdetail, array('T_OrderDetailID' => $one_orderdetail_id)); $sql = "DELETE FROM one.so_resultentry WHERE So_ResultEntryT_OrderHeaderID = {$v->Mcu_ScreeningT_OrderHeaderID} AND So_ResultEntryT_OrderDetailID = {$one_orderdetail_id} "; $this->db->query($sql); $sql = "SELECT * FROM mcu_session.so_resultentry WHERE So_ResultEntryT_OrderHeaderID = {$v->Mcu_ScreeningT_OrderHeaderID} AND So_ResultEntryMcuSessionID = {$v->Mcu_ScreeningMcuSessionID} AND So_ResultEntryT_OrderDetailID = {$mcu_orderdetail_id}"; //echo $sql; $resultentry_so = $this->db->query($sql)->row_array(); $resultentry_so['So_ResultEntryT_OrderHeaderID'] = $header_id; $resultentry_so['So_ResultEntryT_OrderDetailID'] = $one_orderdetail_id; $old_id = $resultentry_so['So_ResultEntryID'];/*mcu_session*/ unset($resultentry_so['So_ResultEntryID']); unset($resultentry_so['So_ResultEntryMcuSessionID']); $this->db->insert('one.so_resultentry', $resultentry_so); $last_re_so_id = $this->db->insert_id(); $sql = "DELETE FROM one.so_resultentrydetail WHERE So_ResultEntryDetailSo_ResultEntryID = {$last_re_so_id} "; $this->db->query($sql); $sql = "SELECT * FROM mcu_session.so_resultentrydetail WHERE So_ResultEntryDetailSo_ResultEntryID = {$old_id} AND So_ResultEntryDetailMcuSessionID = {$v->Mcu_ScreeningMcuSessionID}"; //echo $sql; $resultentry_detail_so = $this->db->query($sql)->result_array(); foreach ($resultentry_detail_so as $kx => $vx) { unset($resultentry_detail_so[$kx]['So_ResultEntryDetailID']); unset($resultentry_detail_so[$kx]['So_ResultEntryDetailMcuSessionID']); $resultentry_detail_so[$kx]['So_ResultEntryDetailSo_ResultEntryID'] = $last_re_so_id; } $this->db->insert_batch('one.so_resultentrydetail', $resultentry_detail_so); $sql = "SELECT * FROM mcu_session.so_resultentry_fisik_umum WHERE So_ResultEntryFisikUmumSo_ResultEntryID = {$old_id} AND So_ResultEntryFisikUmumMcuSessionID = {$v->Mcu_ScreeningMcuSessionID}"; $resultentry_fisik_so = $this->db->query($sql)->result_array(); foreach ($resultentry_fisik_so as $kx => $vx) { unset($resultentry_fisik_so[$kx]['So_ResultEntryFisikUmumSo_ResultEntryID']); unset($resultentry_fisik_so[$kx]['So_ResultEntryFisikUmumMcuSessionID']); $resultentry_fisik_so[$kx]['So_ResultEntryFisikUmumSo_ResultEntryID'] = $last_re_so_id; } $this->db->insert_batch('one.so_resultentry_fisik_umum', $resultentry_fisik_so); $sql = "SELECT * FROM mcu_session.so_resultentrydetail_other WHERE So_ResultEntryDetailOtherSo_ResultEntryID = {$old_id} AND So_ResultEntryDetailOtherMcuSessionID = {$v->Mcu_ScreeningMcuSessionID}"; $resultentry_other_so = $this->db->query($sql)->result_array(); foreach ($resultentry_other_so as $kx => $vx) { unset($resultentry_other_so[$kx]['So_ResultEntryDetailOtherID']); unset($resultentry_other_so[$kx]['So_ResultEntryDetailOtherMcuSessionID']); $resultentry_other_so[$kx]['So_ResultEntryDetailOtherSo_ResultEntryID'] = $last_re_so_id; } $this->db->insert_batch('one.so_resultentrydetail_other', $resultentry_other_so); } } //$this->db->trans_complete(); } } $sql = "SELECT * FROM mcu_session.last_master_id WHERE LastMasterMcuSessionID = {$mcu_sessionID}"; $last_master = $this->db->query($sql)->row_array(); $sql = "SELECT McuOfflinePrepareID as xid, McuOfflinePrepareCode as xcode FROM mcu_session.mcu_offline_prepare WHERE McuOfflinePrepareIsActive = 'Y' AND McuOfflinePrepareIsDownloaded = 'Y' AND McuOfflinePrepareMcuSessionID = {$mcu_sessionID} LIMIT 1"; $data_prepare = $this->db->query($sql)->row_array(); $sql = "SELECT m_patient.*, Map_McuPatientM_PatientID as xid FROM mcu_session.m_patient JOIN mcu_session.t_orderheader ON T_OrderHeaderM_PatientID = M_PatientID JOIN one.map_mcu_patient ON Map_McuPatientM_McuPatientID = M_PatientID AND Map_McuPatientMcuOfflinePrepareCode = '{$data_prepare['xcode']}' WHERE M_PatientMcuSessionID = {$mcu_sessionID}"; //echo $sql; $data_patient_update = $this->db->query($sql)->result_array(); if ($data_patient_update) { foreach ($data_patient_update as $k_dpu => $v_dpu) { $dt_x = $v_dpu; unset($dt_x['xid']); $this->db->update('one.m_patient', $dt_x, array('M_PatientID' => $v_dpu['xid'])); } } $sql = "SELECT m_patient.*,Mcu_MapOrderT_OrderHeaderNewID as xid FROM mcu_session.m_patient JOIN mcu_session.t_orderheader ON T_OrderHeaderM_PatientID = M_PatientID JOIN one.mcu_map_order ON Mcu_MapOrderT_OrderHeaderID = T_OrderHeaderID AND Mcu_MapOrderMcuOfflinePrepareCode = '{$data_prepare['xcode']}' LEFT JOIN one.map_mcu_patient ON Map_McuPatientM_McuPatientID = M_PatientID AND Map_McuPatientMcuOfflinePrepareCode = '{$data_prepare['xcode']}' WHERE M_PatientMcuSessionID = {$mcu_sessionID} AND ISNULL(Map_McuPatientID) GROUP BY Mcu_MapOrderT_OrderHeaderID"; //echo $sql; //print_r($last_master); $data_patient_insert = $this->db->query($sql)->result_array(); if ($data_patient_insert) { foreach ($data_patient_insert as $k_dpi => $v_dpi) { if (intval($v_dpi['M_PatientID']) > intval($last_master['M_PatientID'])) { $dt_x = $v_dpi; unset($dt_x['M_PatientID']); unset($dt_x['M_PatientMcuSessionID']); unset($dt_x['xid']); //print_r($dt_x); $this->db->insert('one.m_patient', $dt_x); //echo $this->db->last_query(); $new_id = $this->db->insert_id(); //echo $new_id; $sql = "UPDATE one.t_orderheader SET T_OrderHeaderM_PatientID = {$new_id} WHERE T_OrderHeaderID = {$v_dpi['xid']}"; $this->db->query($sql); //echo $sql; $sql = "INSERT INTO map_mcu_patient ( Map_McuPatientM_McuPatientID, Map_McuPatientM_PatientID, Map_McuPatientMcuOfflinePrepareCode ) VALUES( {$v_dpi['M_PatientID']}, {$new_id}, '{$data_prepare['xcode']}' ) "; $this->db->query($sql); } } } $sql = "SELECT m_patient.* FROM mcu_session.m_patient JOIN mcu_session.t_orderheader ON T_OrderHeaderM_PatientID = M_PatientID JOIN one.mcu_map_order ON Mcu_MapOrderT_OrderHeaderID = T_OrderHeaderID AND Mcu_MapOrderMcuOfflinePrepareCode = '{$data_prepare['xcode']}' WHERE M_PatientMcuSessionID = {$mcu_sessionID} GROUP BY Mcu_MapOrderT_OrderHeaderID" ; $data_patient_exist = $this->db->query($sql)->result_array(); if ($data_patient_exist) { foreach ($data_patient_exist as $k_dpe => $v_dpe) { if (intval($v_dpe['M_PatientID']) <= intval($last_master['M_PatientID'])) { $patient_id = $v_dpe['M_PatientID']; unset($dt_x['M_PatientID']); unset($dt_x['M_PatientMcuSessionID']); $dt_x = $v_dpe; $this->db->update('one.m_patient', $dt_x, array('M_PatientID' => $patient_id)); } } } $sql = "SELECT m_patientaddress.*, Map_McuPatientM_PatientID as patient_id FROM mcu_session.m_patientaddress JOIN mcu_session.t_orderheader ON T_OrderHeaderM_PatientID = M_PatientAddressM_PatientID JOIN one.mcu_map_order ON Mcu_MapOrderT_OrderHeaderID = T_OrderHeaderID AND Mcu_MapOrderMcuOfflinePrepareCode = '{$data_prepare['xcode']}' JOIN one.map_mcu_patient ON Map_McuPatientM_McuPatientID = T_OrderHeaderM_PatientID LEFT JOIN map_mcu_patient_address ON Map_McuPatientAddressM_McuPatientAddressID = M_PatientAddressID WHERE M_PatientAddressMcuSessionID = {$mcu_sessionID} AND ISNULL(Map_McuPatientAddressID) GROUP BY M_PatientAddressID"; //echo $sql; $data_patient_address_insert = $this->db->query($sql)->result_array(); if ($data_patient_address_insert) { foreach ($data_patient_address_insert as $k_dpai => $v_dpai) { if (intval($v_dpai['M_PatientAddressID']) > intval($last_master['M_PatientAddressID'])) { $dt_x = $v_dpai; unset($dt_x['M_PatientAddressID']); unset($dt_x['M_PatientAddressMcuSessionID']); unset($dt_x['patient_id']); $dt_x['M_PatientAddressM_PatientID'] = $v_dpai['patient_id']; $this->db->insert('one.m_patientaddress', $dt_x); //echo $this->db->last_query(); $new_id = $this->db->insert_id(); $sql = "INSERT INTO map_mcu_patient_address ( Map_McuPatientAddressM_McuPatientAddressID, Map_McuPatientAddressM_PatientAddressID, Map_McuPatientAddressMcuOfflinePrepareCode ) VALUES( {$v_dpai['M_PatientAddressID']}, {$new_id}, '{$data_prepare['xcode']}' ) "; $this->db->query($sql); //echo $this->db->last_query(); } } } $sql = "SELECT m_patientaddress.*, Map_McuPatientAddressM_PatientAddressID as xid FROM mcu_session.m_patientaddress JOIN mcu_session.t_orderheader ON T_OrderHeaderM_PatientID = M_PatientAddressM_PatientID JOIN one.mcu_map_order ON Mcu_MapOrderT_OrderHeaderID = T_OrderHeaderID AND Mcu_MapOrderMcuOfflinePrepareCode = '{$data_prepare['xcode']}' JOIN map_mcu_patient_address ON Map_McuPatientAddressM_McuPatientAddressID = M_PatientAddressID WHERE M_PatientAddressMcuSessionID = {$mcu_sessionID}"; //echo 4sql; $data_patient_address_update = $this->db->query($sql)->result_array(); if ($data_patient_address_update) { foreach ($data_patient_address_update as $k_dpau => $v_dpau) { if (intval($v_dpau['M_PatientAddressID']) > intval($last_master['M_PatientAddressID'])) { $dt_x = $v_dpau; unset($dt_x['xid']); $this->db->update('one.m_patientaddress', $dt_x, array('M_PatientAddressID' => $v_dpau['xid'])); } } } $sql = "SELECT m_patientaddress.* FROM mcu_session.m_patientaddress JOIN mcu_session.t_orderheader ON T_OrderHeaderM_PatientID = M_PatientAddressM_PatientID JOIN one.mcu_map_order ON Mcu_MapOrderT_OrderHeaderID = T_OrderHeaderID AND Mcu_MapOrderMcuOfflinePrepareCode = '{$data_prepare['xcode']}' WHERE M_PatientAddressMcuSessionID = {$mcu_sessionID}"; $data_patient_address_exist = $this->db->query($sql)->result_array(); if ($data_patient_address_exist) { foreach ($data_patient_address_exist as $k_dpae => $v_dpae) { if (intval($v_dpau['M_PatientAddressID']) <= intval($last_master['M_PatientAddressID'])) { $dt_x = $v_dpae; unset($dt_x['M_PatientAddressID']); unset($dt_x['M_PatientAddressMcuSessionID']); $this->db->update('one.m_patientaddress', $dt_x, array('M_PatientAddressID' => $v_dpae['M_PatientAddressID'])); } } } $result = array("status"=> "OK"); $this->sys_ok($result); exit; } else { echo "sudah terupdate semua"; } } }