db_onedev = $this->load->database("onedev", true); } function add_verifications_label($orderid){ $query = " SELECT Result_VerificationsID as id, IFNULL(Result_VerificationsValueID,0) as xid, IFNULL(Result_VerificationsValueCheck,'N') as chex, IF(ISNULL(Result_VerificationsValueID),'',Result_VerificationsValueNote) as note, Result_VerificationsLabel as label FROM result_verifications LEFT JOIN result_verifications_value ON Result_VerificationsValueResult_VerificationsID = Result_VerificationsID AND Result_VerificationsValueSo_ResultEntryID = $orderid WHERE Result_VerificationIsActive = 'Y' GROUP BY Result_VerificationsID "; $rows = $this->db_onedev->query($query)->result_array(); foreach($rows as $k => $v){ if($v['chex'] == 'N') $rows[$k]['chex'] = false; else $rows[$k]['chex'] = true; } return $rows; } public function search() { $prm = $this->sys_input; if (! $this->isLogin) { $this->sys_error("Invalid Token"); exit; } $nolab = $prm["nolab"]; $nama = $prm["name"]; $status = $prm["status"]; $datepromise = $prm["startdate"]; $filter = " AND Result_SendEmailStatus = '{$status}'"; $having = "HAVING not_ready_count = 0"; if($status == 'X'){ $filter = " AND ISNULL(Result_SendEmailID)"; $having = "HAVING not_ready_count > 0"; } if($status == 'P') $filter .= " AND Result_SendEmailActionBy = 'MANUAL'"; if(!isset($prm['current_page'])) $prm['current_page'] = 1; $sql_where = "WHERE T_OrderDetailIsActive = 'Y' "; $number_limit = 10; $number_offset = ($prm['current_page'] - 1) * $number_limit ; //$sql_param = array(); if ($nolab != "") { if ($sql_where != "") { $sql_where .=" and "; } $sql_where .= " ( T_OrderHeaderLabNumber like '%$nolab%' AND M_PatientName like '%$nolab%' ) "; //$prm['current_page'] = 1; } $sql = "SELECT COUNT(*) as total FROM ( SELECT T_OrderHeaderID, T_OrderPromiseID, T_OrderHeaderDate, T_OrderHeaderIsCito as iscito, M_CompanyName, T_OrderPromiseDateTime, T_OrderHeaderLabNumber, CONCAT(IFNULL(M_TitleName,''),' ',M_PatientName) as patient_fullname, M_PatientHP as patient_hp, M_PatientPhotoThumb as photo, fn_fo_check_status_not_ready_email(T_OrderHeaderID,T_OrderPromiseID) as not_ready_count FROM t_orderdetail JOIN t_orderheader ON T_OrderDetailT_OrderHeaderID = T_OrderHeaderID JOIN t_orderdelivery ON T_OrderDeliveryT_OrderHeaderID = T_OrderHeaderID AND T_OrderDeliveryM_DeliveryTypeID = 3 AND T_OrderDeliveryIsActive = 'Y' JOIN m_company ON T_OrderHeaderM_CompanyID = M_CompanyID JOIN m_patient ON T_OrderHeaderM_PatientID = M_PatientID LEFT JOIN m_title ON M_PatientM_TitleID = M_TitleID JOIN t_orderpromise ON T_OrderDetailT_OrderPromiseID = T_OrderPromiseID AND T_OrderPromiseDateTime < '{$datepromise} 23:59:59' LEFT JOIN result_sendemail ON Result_SendEmailT_OrderHeaderID = T_OrderHeaderID AND JSON_CONTAINS(Result_SendEmailIds,T_OrderDetailID) $sql_where $filter GROUP BY T_OrderHeaderID, T_OrderPromiseID, T_OrderDeliveryID $having )x"; //echo $sql; $query = $this->db_onedev->query($sql); $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_doctor count", $this->db_onedev); exit; } $sql = "SELECT GROUP_CONCAT(IFNULL(Result_SendEmailID,0) separator ',') as ids, T_OrderHeaderID, T_OrderPromiseID, T_OrderHeaderDate, T_OrderHeaderIsCito as iscito, M_CompanyName, DATE_FORMAT(T_OrderPromiseDateTime,'%d-%m-%Y %H:%i') as date_promise, T_OrderHeaderLabNumber, CONCAT(IFNULL(M_TitleName,''),' ',M_PatientName) as patient_fullname, M_PatientHP as patient_hp, M_PatientPhotoThumb as photo, IFNULL(Result_SendEmailStatus,'X') as status, fn_fo_check_status_not_ready_email(T_OrderHeaderID,T_OrderPromiseID) as not_ready_count, Last_StatusPaymentIsLunas as status_lunas, M_MouIsBill as status_bill FROM t_orderdetail JOIN t_orderheader ON T_OrderDetailT_OrderHeaderID = T_OrderHeaderID JOIN m_mou ON T_OrderHeaderM_MouID = M_MouID JOIN last_statuspayment ON Last_StatusPaymentT_OrderHeaderID = T_OrderHeaderID JOIN t_orderdelivery ON T_OrderDeliveryT_OrderHeaderID = T_OrderHeaderID AND T_OrderDeliveryM_DeliveryTypeID = 3 AND T_OrderDeliveryIsActive = 'Y' JOIN m_company ON T_OrderHeaderM_CompanyID = M_CompanyID JOIN m_patient ON T_OrderHeaderM_PatientID = M_PatientID LEFT JOIN m_title ON M_PatientM_TitleID = M_TitleID JOIN t_orderpromise ON T_OrderDetailT_OrderPromiseID = T_OrderPromiseID AND T_OrderPromiseDateTime < '{$datepromise} 23:59:59' LEFT JOIN result_sendemail ON Result_SendEmailT_OrderHeaderID = T_OrderHeaderID AND JSON_CONTAINS(Result_SendEmailIds,T_OrderDetailID) $sql_where $filter GROUP BY T_OrderHeaderID, T_OrderPromiseID, T_OrderDeliveryID $having limit $number_limit offset $number_offset"; //echo $sql; $query = $this->db_onedev->query($sql); $rows = $query->result_array(); //echo $this->db_onedev->last_query(); if($rows){ /*foreach($rows as $k => $v){ $rows[$k]['verifications'] = $this->add_verifications_label($v['trx_id']); }*/ } $result = array("total" => $tot_page, "records" => $rows, "sql"=> ''); $this->sys_ok($result); exit; } public function save() { try { $xprm = $this->sys_input; //# cek token valid if (! $this->isLogin) { $this->sys_error("Invalid Token"); exit; } $xuserid = $this->sys_user['M_UserID']; //# ambil parameter input //print_r($xprm); $prm = $xprm['patient']; $xstatus = $xprm['act']; $fostatusid = 3; $fologcode = 'FO.VERIFICATION.CONFIRM'; $id = $prm['T_OrderHeaderID']; echo $xstatus; if($xstatus == 'N'){ $fostatusid = 4; $fologcode = 'FO.VERIFICATION.REJECT'; }else{ $this->save_barcode_new($id); } //print_r($prm); $xverificationnote = $prm['verification_note']; //echo $xverificationnote; $sql = "update t_orderheader set T_OrderHeaderVerificationNote = '{$xverificationnote}' where T_OrderHeaderID = $id"; //echo $sql; $query = $this->db_onedev->query($sql); /*$xverification_patient = $this->saveverifications($id,$prm['verification_patient'],'PATIENT',$xuserid); $xverification_doctor = $this->saveverifications($id,$prm['verification_doctor'],'DOCTOR',$xuserid); $xverification_companymou = $this->saveverifications($id,$prm['verification_companymou'],'COMPANY',$xuserid); $xverification_payment = $this->saveverifications($id,$prm['verification_payment'],'PAYMENT',$xuserid); $xverification_info = $this->saveverifications($id,$prm['verification_info'],'INFO',$xuserid); $xverification_delivery = $this->saveverification_delivery($id,$prm['verification_delivery'],$xuserid); $xverification_px = $this->saveverification_px($id,$prm['verification_px'],$xuserid);*/ $sql = "insert into fo_status( Fo_StatusDate, Fo_StatusT_OrderHeaderID, Fo_StatusM_StatusID, Fo_StatusM_UserID, Fo_StatusCreated, Fo_StatusUpdated) values( now(), ?, ?, ?, now(),now())"; //echo $sql; $query = $this->db_onedev->query($sql, array( $id, $fostatusid, $xuserid ) ); if (!$query) { $this->sys_error_db("fo_status insert"); exit; } $data_log = array(); $data_log['orderid'] = $id; /*$data_log['verification_patient'] = $prm['verification_patient']; $data_log['verification_doctor'] = $prm['verification_doctor']; $data_log['verification_companymou'] = $prm['verification_companymou']; $data_log['verification_payment'] = $prm['verification_payment']; $data_log['verification_info'] = $prm['verification_info']; $data_log['verification_px'] = $prm['verification_px']; $data_log['verification_delivery'] = $prm['verification_delivery'];*/ $json_dt_log = json_encode($data_log); $sql = "insert into one_log.log_fo( Log_FoDate, Log_FoCode, Log_FoJson, Log_FoUserID) values( now(), ?, ?, ?)"; //echo $sql; $query = $this->db_onedev->query($sql, array( $fologcode, $json_dt_log, $xuserid ) ); if (!$query) { $this->sys_error_db("one_log.fo_log insert"); exit; } if($xstatus == 'Y'){ $msg = 'Verifikasi berhasil dilakukan'; } else{ $msg = 'Tolak Verifikasi berhasil dilakukan'; $sql = "INSERT INTO t_ordermessage ( T_OrderMessageT_OrderHeaderID, T_OrderMessageType, T_OrderMessageMessage, T_OrderMessageFromUserID, T_OrderMessageCreated, T_OrderMessageLastUpdated ) VALUES( {$id}, 'FO.VERIFICATION.REJECT', '{$xverificationnote}', {$xuserid}, NOW(), NOW() )"; //echo $sql; $query = $this->db_onedev->query($sql); if (!$query) { $this->sys_error_db("one_log.t_ordermessage insert"); exit; } } $rows = array('message'=>$msg); $result = array ("total" => 0, "records" => $rows); $this->sys_ok($result); } catch(Exception $exc) { $message = $exc->getMessage(); $this->sys_error($message); } } function save_barcode_new($orderid){ $xuserid = $this->sys_user['M_UserID']; $query =" SELECT T_SampleTypeID as id, T_SampleTypeName as name, '' as children FROM t_orderheader JOIN t_orderdetail ON T_OrderDetailT_OrderHeaderID = T_OrderHeaderID JOIN t_test ON T_OrderDetailT_TestID = T_TestID JOIN t_sampletype ON T_TestT_SampleTypeID = T_SampleTypeID WHERE T_OrderHeaderID = {$orderid} GROUP BY T_SampleTypeID "; //echo $query ; $barcodes = $this->db_onedev->query($query)->result(); foreach($barcodes as $k => $v){ $query = "SELECT T_SampleTypeID as id, IFNULL(T_BarcodeLabID,0) as xid, IF(ISNULL(T_BarcodeLabID),'Y',T_BarcodeLabIsActive) as chex, T_TestName as testname, T_SampleTypeName as samplename, IF(ISNULL(T_BarcodeLabID),CONCAT(T_OrderHeaderLabNumber,'.',T_SampleTypeID,'.',1),T_BarcodeLabBarcode) as barcodenumber FROM t_orderdetail JOIN t_orderheader ON T_OrderHeaderID = T_OrderDetailT_OrderHeaderID JOIN t_test ON T_OrderDetailT_TestID = T_TestID JOIN t_sampletype ON T_TestT_SampleTypeID = T_SampleTypeID LEFT JOIN t_barcodelab ON T_BarcodeLabT_OrderHeaderID = T_OrderDetailT_OrderHeaderID AND T_BarcodeLabT_SampleTypeID = T_TestT_SampleTypeID AND T_BarcodeLabIsActive = 'Y' WHERE T_OrderDetailT_OrderHeaderID = {$orderid} AND T_SampleTypeID = {$v->id} GROUP BY T_BarcodeLabID "; $v->children = $this->db_onedev->query($query)->result_array(); //$v->children = $barcode_data; foreach($v->children as $ki => $vi){ if($vi['chex'] == 'N') $v->children[$ki]['chex'] = false; else $v->children[$ki]['chex'] = true; $sql = "insert into t_barcodelab( T_BarcodeLabT_OrderHeaderID, T_BarcodeLabBarcode, T_BarcodeLabT_SampleTypeID, T_BarcodeLabCreated, T_BarcodeLabLastUpdated, T_BarcodeLabUserID) values( ?, ?, ?, now(),now(),?)"; $query = $this->db_onedev->query($sql, array( $orderid, $v->children[$ki]['barcodenumber'], $v->children[$ki]['id'], $xuserid ) ); // echo $this->db_onedev->last_query(); if (!$query) { $this->sys_error_db("t_barcodelab insert"); exit; } } } //insert log $supplies = array(); $query =" SELECT M_SuppliesID as id, IFNULL(T_OrderSuppliesID,0) as xid, IF(ISNULL(T_OrderSuppliesID),'N',T_OrderSuppliesIsActive) as chex, IFNULL(T_OrderSuppliesQty,1) as qty, M_SuppliesName as name, IF(ISNULL(T_OrderSuppliesID),NOW(),T_OrderSuppliesLastUpdated) as lastupdated, IF(ISNULL(T_OrderSuppliesID),NOW(),T_OrderSuppliesLastUpdated) as tx_lastupdated FROM m_supplies JOIN t_ordersupplies ON T_OrderSuppliesT_OrderHeaderID = $orderid AND T_OrderSuppliesM_SuppliesID = M_SuppliesID WHERE M_SuppliesIsActive = 'Y' "; //echo $query ; $supplies = $this->db_onedev->query($query)->result_array(); foreach($supplies as $k => $v){ if($v['chex'] == 'N') $supplies[$k]['chex'] = false; else $supplies[$k]['chex'] = true; } $dt_log = array('orderid'=>$orderid,'supplies'=>$supplies,'barcode'=>$barcodes); $fologcode = 'FO.Verification.BarcodeSupplies'; $json_dt_log = json_encode($dt_log); $sql = "insert into one_log.log_supplies_barcode( Log_SuppliesBarcodeDate, Log_SuppliesBarcodeCode, Log_SuppliesBarcodeJson, Log_SuppliesBarcodeUserID) values( now(), ?, ?, ?)"; //echo $sql; $query = $this->db_onedev->query($sql, array( $fologcode, $json_dt_log, $xuserid ) ); if (!$query) { $this->sys_error_db("one_log.log_supplies_barcode insert"); exit; } } function saveverifications($id,$verifications,$type,$userid) { try { //$xverificationtypeid = $this->db_onedev->query("SELECT * FROM fo_verificationtype WHERE Fo_VerificationTypeGroup = '{$type}' AND Fo_VerificationTypeIsActive = 'Y'")->row()->Fo_VericationTypeID; //echo $xverificationtypeid; //print_r($verifications); foreach($verifications as $k => $v){ //print_r($v); if(intval($v['xid']) == 0){ $sql = "insert into fo_verification( Fo_VerificationT_OrderHeaderID, Fo_VerificationFo_VericationTypeID, Fo_VerificationIsOK, Fo_VerificationReason, Fo_VerificationCreated, Fo_VerificationLastUpdated, Fo_VerificationUserID) values( ?, ?, ?, ?, now(),now(),?)"; //echo $sql; $query = $this->db_onedev->query($sql, array( $id, $v['id'], $v['chex'] == true ?'Y':'N', $v['note'], $userid ) ); if (!$query) { $this->sys_error_db("fo_verification insert"); exit; } } } return true; } catch(Exception $exc) { $message = $exc->getMessage(); $this->sys_error($message); } } function saveverification_delivery($id,$deliveries,$userid) { try { foreach($deliveries as $k => $v){ if($v['id'] === 0){ $sql = "insert into fo_verification_delivery_add( Fo_VerificationDeliveryAddT_OrderHeaderID, Fo_VerificationDeliveryAddM_DeliveryID, Fo_VerificationDeliveryAddM_DeliveryTypeID, Fo_VerificationDeliveryAddDestination, Fo_VerificationDeliveryAddAddressID, Fo_VerificationDeliveryAddM_KelurahanID, Fo_VerificationDeliveryAddOK, Fo_VerificationDeliveryAddReason, Fo_VerificationDeliveryAddCreated, Fo_VerificationDeliveryAddLastUpdated, Fo_VerificationDeliveryAddUserID) values( ?, ?, ?, ?,?,?,?,?, now(),now(),?)"; //echo $sql; $query = $this->db_onedev->query($sql, array( $id, $v['deliveryid'], $v['typedeliveryid'], $v['destination'], $v['addressid'], $v['vilageid'], $v['chex'] == true ?'Y':'N', $v['note'], $userid ) ); if (!$query) { echo $this->db_onedev->last_query(); $this->sys_error_db("fo_verification_delivery_add insert"); exit; } }else{ $sql = "insert into fo_verification_delivery( Fo_VerificationDeliveryT_OrderHeaderID, Fo_VerificationDeliveryT_OrderDeliveryID, Fo_VerificationDeliveryIsOK, Fo_VerificationDeliveryReason, Fo_VerificationDeliveryCreated, Fo_VerificationDeliveryLastUpdated, Fo_VerificationDeliveryUserID) values( ?, ?, ?, ?, now(),now(),?)"; //echo $sql; $query = $this->db_onedev->query($sql, array( $id, $v['id'], $v['chex'] == true ?'Y':'N', $v['note'], $userid ) ); if (!$query) { echo $this->db_onedev->last_query(); $this->sys_error_db("fo_verification_delivery insert"); exit; } //echo $this->db_onedev->last_query(); } } return true; } catch(Exception $exc) { $message = $exc->getMessage(); $this->sys_error($message); } } function lookup_barcodes() { try { $prm = $this->sys_input; //# cek token valid if (! $this->isLogin) { $this->sys_error("Invalid Token"); exit; } $sql = "SELECT T_BarcodeLabID as id, 'barcode' as type,T_BarcodeLabID,T_BarcodeLabBarcode, T_BarcodeLabCounter, T_SampleTypeName, 'N' as chex FROM t_barcodelab JOIN t_sampletype ON T_BarcodeLabT_SampleTypeID = T_SampleTypeID WHERE T_BarcodeLabT_OrderHeaderID = {$prm['ohid']} AND T_BarcodeLabIsActive = 'Y' UNION SELECT T_OrderHeaderID as id, 'formulir' as type, 0,T_OrderHeaderLabNumber as T_BarcodeLabBarcode, 1, 'Formulir' as T_SampleTypeName, 'N' as chex FROM t_orderheader WHERE T_OrderHeaderID = {$prm['ohid']} "; //echo $sql; $rows = $this->db_onedev->query($sql)->result_array(); if($rows){ foreach($rows as $k => $v){ if($v['chex'] == 'N') $rows[$k]['chex'] = false; else $rows[$k]['chex'] = true; } } $result = array ("total" => 0, "records" => $rows); $this->sys_ok($result); } catch(Exception $exc) { $message = $exc->getMessage(); $this->sys_error($message); } } function saveverification_px($id,$pxs,$userid) { try { foreach($pxs as $k => $v){ if(intval($v['id']) == 0){ $cxh = $v['chex'] == true ?'Y':'N'; $sql = "insert into fo_verification_test_add( Fo_VerificationTestAddT_OrderHeaderID, Fo_VerificationTestAddT_TestID, Fo_VerificationTestAddBruto, Fo_VerificationTestAddDiscount, Fo_VerificationTestAddTotal, Fo_VerificationTestAddIsOK, Fo_VerificationTestAddIsCito, Fo_VerificationTestAddCreated, Fo_VerificationTestAddLastUpdated, Fo_VerificationTestAddUserID) values( $id, {$v['pxid']}, {$v['bruto']}, {$v['discount']},{$v['total']},'{$cxh}','{$v['flagcito']}',now(),now(),{$userid})"; //echo $sql; $query = $this->db_onedev->query($sql); //echo $this->db_onedev->last_query(); if (!$query) { $this->sys_error_db("fo_verification_test_add insert"); exit; } }else{ $sql = "insert into fo_verification_test( Fo_VerificationTestT_OrderHeaderID, Fo_VerificationTestT_OrderDetailID, Fo_VerificationTestIsOK, Fo_VerificationTestReason, Fo_VerificationTestCreated, Fo_VerificationTestLastUpdated, Fo_VerificationTestUserID) values( ?, ?, ?, ?, now(),now(),?)"; //echo $sql; $query = $this->db_onedev->query($sql, array( $id, $v['id'], $v['chex'] == true ?'Y':'N', $v['note'], $userid ) ); //echo $this->db_onedev->last_query(); if (!$query) { $this->sys_error_db("fo_verification_test insert"); exit; } } } return true; } catch(Exception $exc) { $message = $exc->getMessage(); $this->sys_error($message); } } function verify(){ if (! $this->isLogin) { $this->sys_error("Invalid Token"); exit; } $prm = $this->sys_input; $userid = $this->sys_user["M_UserID"]; $xstatus = $prm['act']; if($xstatus == 'Y'){ $msg = "Berhasil melakukan verifikasi"; $query =" INSERT INTO result_verifications_value ( Result_VerificationsValueSo_ResultEntryID, Result_VerificationsValueResult_VerificationsID, Result_VerificationsValueCheck, Result_VerificationsValueNote, Result_VerificationsValueUserID, Result_VerificationsValueCreated ) SELECT {$prm['trx_id']}, Result_VerificationsID, 'Y', '', {$userid}, NOW() FROM result_verifications WHERE Result_VerificationIsActive = 'Y' ON DUPLICATE KEY UPDATE Result_VerificationsValueCheck = 'Y', Result_VerificationsValueNote = '', Result_VerificationsValueUserID = {$userid}, Result_VerificationsValueLastUpdated = NOW() "; //echo $query; $this->db_onedev->query($query); $sql = "UPDATE so_resultentry SET So_ResultEntryStatus = 'VAL2' , So_ResultEntryValidation2 = 'Y' WHERE So_ResultEntryID = {$prm['trx_id']}"; $this->db_onedev->query($sql); } else{ $msg = "Tolak untuk perbaikan"; $verifications = $prm['verifications']; foreach($verifications as $k => $v){ $chx = $v['chex'] == true ?'Y':'N'; $query =" INSERT INTO result_verifications_value ( Result_VerificationsValueSo_ResultEntryID, Result_VerificationsValueResult_VerificationsID, Result_VerificationsValueCheck, Result_VerificationsValueNote, Result_VerificationsValueUserID, Result_VerificationsValueCreated ) values( {$prm['trx_id']}, {$v['id']}, '{$chx}', '{$v['note']}', {$userid}, NOW() ) ON DUPLICATE KEY UPDATE Result_VerificationsValueCheck = '{$chx}', Result_VerificationsValueNote = '{$v['note']}', Result_VerificationsValueUserID = {$userid}, Result_VerificationsValueLastUpdated = NOW() "; //echo $query; $this->db_onedev->query($query); } } $result = array ("total" => 0, "records" => array('status'=>'OK','message'=>$msg)); $this->sys_ok($result); } public function getstatuspergroup() { try { //# cek token valid if (! $this->isLogin) { $this->sys_error("Invalid Token"); exit; } $prm = $this->sys_input; $rows = array(); $sql =" SELECT Last_StatusPaymentBillTotal as total_bill, Last_StatusPaymentPaid as paid, Last_StatusPaymentUnpaid as unpaid, Last_StatusPaymentIsLunas as status FROM last_statuspayment WHERE Last_StatusPaymentT_OrderHeaderID = {$prm['T_OrderHeaderID']} "; $rows['info_bill'] = $this->db_onedev->query($sql)->row_array(); $sql =" SELECT T_OrderDeliveryID as id, IFNULL(Fo_VerificationDeliveryID,0) as xid, M_DeliveryTypeCode as code, IF(ISNULL(Fo_VerificationDeliveryID),'N',Fo_VerificationDeliveryIsOK) as chex, M_DeliveryID as deliveryid, M_DeliveryTypeID as typedeliveryid, T_OrderDeliveryM_KelurahanID as vilageid, IF(ISNULL(Fo_VerificationDeliveryID),'',Fo_VerificationDeliveryReason) as note, 'reguler' as type, CASE WHEN T_OrderDeliveryM_DeliveryID = 1 THEN M_DeliveryName WHEN T_OrderDeliveryM_DeliveryID = 4 THEN CONCAT(M_DeliveryName) WHEN T_OrderDeliveryM_DeliveryID = 2 THEN CONCAT(M_DeliveryName) WHEN ( T_OrderDeliveryM_DeliveryID = 7 OR T_OrderDeliveryM_DeliveryID = 9 ) THEN CONCAT(M_DeliveryName) WHEN ( T_OrderDeliveryM_DeliveryID = 6 OR T_OrderDeliveryM_DeliveryID = 8 ) THEN CONCAT(M_DeliveryName) ELSE CONCAT(M_DeliveryName) END as label, CASE WHEN T_OrderDeliveryM_DeliveryID = 1 THEN '' WHEN T_OrderDeliveryM_DeliveryID = 4 THEN M_DoctorAddressDescription WHEN T_OrderDeliveryM_DeliveryID = 2 THEN M_PatientAddressDescription WHEN ( T_OrderDeliveryM_DeliveryID = 7 OR T_OrderDeliveryM_DeliveryID = 9 ) THEN M_DoctorHP WHEN ( T_OrderDeliveryM_DeliveryID = 6 OR T_OrderDeliveryM_DeliveryID = 8 ) THEN M_PatientHP ELSE T_OrderDeliveryDestination END as destination, CASE WHEN T_OrderDeliveryM_DeliveryID = 4 THEN M_DoctorAddressID WHEN T_OrderDeliveryM_DeliveryID = 2 THEN M_PatientAddressID ELSE 0 END as addressid FROM t_orderdelivery JOIN t_orderheader ON T_OrderDeliveryT_OrderHeaderID = T_OrderHeaderID JOIN m_delivery ON T_OrderDeliveryM_DeliveryID = M_DeliveryID JOIN m_deliverytype ON T_OrderDeliveryM_DeliveryTypeID = M_DeliveryTypeID LEFT JOIN m_doctoraddress ON T_OrderDeliveryAddressID = M_DoctorAddressID AND T_OrderDeliveryM_DeliveryID = 4 LEFT JOIN m_patientaddress ON T_OrderDeliveryAddressID = M_PatientAddressID AND T_OrderDeliveryM_DeliveryID = 2 LEFT JOIN fo_verification_delivery ON Fo_VerificationDeliveryT_OrderHeaderID = T_OrderDeliveryT_OrderHeaderID AND Fo_VerificationDeliveryIsActive = 'Y' LEFT JOIN m_doctor ON T_OrderHeaderSenderM_DoctorID = M_DoctorID AND ( T_OrderDeliveryM_DeliveryID = 7 OR T_OrderDeliveryM_DeliveryID = 9 ) LEFT JOIN m_patient ON T_OrderHeaderM_PatientID = M_PatientID AND ( T_OrderDeliveryM_DeliveryID = 6 OR T_OrderDeliveryM_DeliveryID = 8 ) WHERE T_OrderDeliveryT_OrderHeaderID = {$prm['T_OrderHeaderID']} AND T_OrderDeliveryIsActive = 'Y' GROUP BY T_OrderDeliveryID "; //echo $query ; $rows['info_deliveries'] = $this->db_onedev->query($sql)->result_array(); $sql = " SELECT T_OrderHeaderID, T_OrderPromiseID, T_OrderPromiseDateTime, T_OrderHeaderLabNumber, UPPER(DocumentationGroupName) as DocumentationGroupName, GROUP_CONCAT(CONCAT(T_TestName,'^',IFNULL(Result_SendEmailStatus,'X'))) as status_test_name, GROUP_CONCAT(IFNULL(Result_SendEmailStatus,'X')) as status, '' as status_pergroup, '' as details FROM t_orderdetail JOIN t_orderheader ON T_OrderDetailT_OrderHeaderID = T_OrderHeaderID JOIN t_orderpromise ON T_OrderDetailT_OrderPromiseID = T_OrderPromiseID JOIN t_test ON T_OrderDetailT_TestID = T_TestID AND T_TestIsResult = 'Y' LEFT JOIN result_sendemail ON Result_SendEmailT_OrderHeaderID = T_OrderHeaderID AND JSON_CONTAINS(Result_SendEmailIds,T_OrderDetailID) JOIN documentation_group_detail ON DocumentationGroupDetailNat_SubGroupID = T_TestNat_SubGroupID JOIN documentation_group ON DocumentationGroupDetailDocumentationGroupID = DocumentationGroupID WHERE T_OrderHeaderID = {$prm['T_OrderHeaderID']} AND T_OrderPromiseID = {$prm['T_OrderPromiseID']} AND T_OrderDetailIsActive = 'Y' GROUP BY DocumentationGroupID "; $rows['info_test'] = $this->db_onedev->query($sql)->result_array(); if($rows['info_test']){ foreach($rows['info_test'] as $k => $v){ $rows['info_test'][$k]['status_pergroup'] = 'R'; $x_arr = explode(',',$v['status']); if(in_array('X',$x_arr)){ $rows['info_test'][$k]['status_pergroup'] = 'X'; } if($v['DocumentationGroupName'] != 'LAB'){ $z_arr = explode(',',$v['status_test_name']); $for_details = array(); foreach($z_arr as $i => $val){ $xx_arr = explode('^',$val); array_push($for_details,array('testname'=>$xx_arr[0],'status'=>$xx_arr[1])); } $rows['info_test'][$k]['details'] = $for_details; } else{ $rows['info_test'][$k]['DocumentationGroupName'] = 'Laboratorium'; $rows['info_test'][$k]['details'] = array(array('testname'=>'Pemeriksaan Laboratorium','status'=>$rows['info_test'][$k]['status_pergroup'])); } } } $result = array ("total" => 0, "records" => $rows); $this->sys_ok($result); } catch(Exception $exc) { $message = $exc->getMessage(); $this->sys_error($message); } } }