db_onedev = $this->load->database("onedev", true); } public function search() { if (! $this->isLogin) { $this->sys_error("Invalid Token"); exit; } $prm = $this->sys_input; $sql = "SELECT T_OrderHeaderID, M_DoctorIsDefaultPJ, M_DoctorIsPJ, M_DoctorNote, T_OrderHeaderSenderM_DoctorID as M_DoctorID, CONCAT( M_DoctorPrefix, M_DoctorPrefix2,' ',M_DoctorName,' ', M_DoctorSufix, M_DoctorSufix2, M_DoctorSufix3) realdoctor, CONCAT( M_DoctorPrefix, M_DoctorPrefix2,' ',M_DoctorName,' ', M_DoctorSufix, M_DoctorSufix2, M_DoctorSufix3) M_DoctorName, DATE_FORMAT(T_OrderHeaderDate,'%d-%m-%Y') xdate, T_OrderHeaderLabNumber, T_OrderHeaderLabNumberExt labnumber_ext, T_OrderHeaderSubTotal, 0 total_disc, 'N' xshow, T_OrderHeaderTotal, IF(ISNULL(T_OrderHeaderDiagnose) OR T_OrderHeaderDiagnose = '','-',T_OrderHeaderDiagnose) T_OrderHeaderDiagnose, IF(ISNULL(T_OrderHeaderFoNote) OR T_OrderHeaderFoNote = '','-',T_OrderHeaderFoNote) T_OrderHeaderFoNote, IF(ISNULL(M_PatientNote) OR M_PatientNote = '','-',M_PatientNote) M_PatientNote, M_CompanyID, M_CompanyName, M_MouID, M_MouName, M_DoctorAddressID, M_DoctorAddressDescription FROM t_orderheader JOIN m_company ON T_OrderHeaderM_CompanyID = M_CompanyID JOIN m_mou ON T_OrderHeaderM_MouID = M_MouID JOIN m_doctor ON T_OrderHeaderSenderM_DoctorID = M_DoctorID JOIN m_doctoraddress ON T_OrderHeaderSenderM_DoctorAddressID = M_DoctorAddressID JOIN m_patient ON T_OrderHeaderM_PatientID = M_PatientID JOIN t_orderdetail ON T_OrderDetailT_OrderHeaderID = T_OrderHeaderID AND T_OrderDetailIsActive = 'Y' WHERE T_OrderHeaderM_PatientID = ? AND T_OrderHeaderIsActive = 'Y' GROUP BY T_OrderHeaderID ORDER BY T_OrderHeaderDate DESC "; //echo $sql; $query = $this->db_onedev->query($sql, [$prm['patient_id']]); if ($query) { //echo $this->db_onedev->last_query(); $rows = $query->result_array(); if($rows){ foreach($rows as $k => $v){ $doctor_name = $v['M_DoctorName']; $doctor_name_len = strlen($v['M_DoctorName']); if($doctor_name_len > 45) $doctor_name = substr($doctor_name,0,45).'...'; $rows[$k]['M_DoctorName'] = $doctor_name; $sql = "SELECT T_OrderDetailT_TestName as test_name, T_OrderDetailPrice as price, T_OrderDetailPrice as str_price, T_OrderDetailDisc as disc_persen, T_OrderDetailDiscAmount as disc_rp, T_OrderDetailDiscAmount as str_disc_rp, T_OrderDetailDiscTotal as disc, T_OrderDetailDiscTotal as str_disc, T_OrderDetailTotal as total, T_OrderDetailTotal as str_total FROM t_orderdetail WHERE T_OrderDetailT_OrderHeaderID = {$v['T_OrderHeaderID']} AND T_OrderDetailIsActive = 'Y' AND T_OrderDetailT_TestIsPrice = 'Y'"; //echo $sql; $rows[$k]['details'] = $this->db_onedev->query($sql)->result_array(); $total_diskon = 0; $total_bruto = 0; foreach($rows[$k]['details'] as $kx => $vx){ $total_diskon = $total_diskon + $vx['disc']; $total_bruto = $total_bruto + $vx['price']; $str_price = number_format($vx['price'],0,',','.'); $rows[$k]['details'][$kx]['str_price'] = $str_price; $str_disc_rp = number_format($vx['disc_rp'],0,',','.'); $rows[$k]['details'][$kx]['str_disc_rp'] = $str_disc_rp; $str_disc = number_format($vx['str_disc'],0,',','.'); $rows[$k]['details'][$kx]['str_disc'] = $str_disc; $str_total = number_format($vx['total'],0,',','.'); $rows[$k]['details'][$kx]['str_total'] = $str_total; } $rows[$k]['total_disc'] = number_format($total_diskon,0,',','.'); $rows[$k]['T_OrderHeaderSubTotal'] = number_format($total_bruto,0,',','.'); $rows[$k]['T_OrderHeaderTotal'] = number_format($v['T_OrderHeaderTotal'],0,',','.'); $sql = "SELECT * , IFNULL(T_OrderDeliveryNoteValue,'-') xnote FROM t_orderdelivery JOIN m_delivery ON T_OrderDeliveryM_DeliveryID = M_DeliveryID LEFT JOIN t_orderdeliverynote ON T_OrderDeliveryNoteT_OrderDeliveryID = T_OrderDeliveryID WHERE T_OrderDeliveryT_OrderHeaderID = {$v['T_OrderHeaderID']} AND T_OrderDeliveryIsActive = 'Y'"; $rows[$k]['deliveries'] = $this->db_onedev->query($sql)->result_array(); /* $rows[$k]['selected_doctor'] = array( 'M_DoctorID'=>$v['M_DoctorID'], 'M_DoctorIsDefault'=>$v['M_DoctorIsDefault'], 'M_DoctorIsPJ'=>$v['M_DoctorIsPJ'], 'M_DoctorName'=>$v['M_DoctorName'], 'M_DoctorNote'=>$v['M_DoctorNote'] ); $rows[$k]['selected_address'] = array( 'M_DoctorAddressID'=>$v['M_DoctorAddressID'], 'M_DoctorAddressDescription'=>$v['M_DoctorAddressDescription'] ); $sql = "SELECT M_DoctorAddressID, M_DoctorAddressDescription FROM m_doctoraddress WHERE M_DoctorAddressM_DoctorID = {$v['M_DoctorID']} AND M_DoctorAddressIsActive = 'Y'"; $rows[$k]['doctor_address'] = $this->db_onedev->query($sql)->result_array(); $sql = "SELECT M_MouEmail, M_MouEmailIsDefault, M_MouEndDate, M_MouID, M_MouIsBill, M_MouIsDefault, M_MouName, M_MouNote, M_MouStartDate, '' delivery_email_code FROM m_mou WHERE "; $rows[$k]['selected_company'] = array('M_CompanyID'=>$v['M_CompanyID'],'M_CompanyName'=>$v['M_CompanyName']); $deliveries = array(); */ } } $this->sys_ok(["records"=>$rows]); } else { $this->sys_error_db("Patient History count", $this->db_onedev); } } function get_databyorder_id(){ if (! $this->isLogin) { $this->sys_error("Invalid Token"); exit; } $prm = $this->sys_input; $sql = "SELECT * FROM t_orderheader WHERE T_OrderHeaderID = {$prm['order_id']}"; $row_header = $this->db_onedev->query($sql)->row_array(); $sql = "SELECT M_MouStatus,M_MouEmail, M_MouEmailIsDefault, M_MouEndDate, M_MouID, M_MouIsBill, M_MouIsDefault, M_MouName, M_MouNote, M_MouStartDate, '' delivery_email_code FROM m_mou WHERE M_MouID = {$row_header['T_OrderHeaderM_MouID']}"; $row_mou = $this->db_onedev->query($sql)->row_array(); $status = "Y"; //print_r($row_mou); $rst = array(); if($row_mou['M_MouStatus'] != 'R' || date('Y-m-d', strtotime($row_mou['M_MouEndDate'])) < date('Y-m-d')){ $status = "N"; $xrst = array('status'=>$status,'data'=>array()); } if($status == 'Y'){ $rst['data_deliveries'] = array(); $new_delivery = array(); $new_delivery = $this->search_deliveries(array('id'=>$row_header['T_OrderHeaderM_PatientID'],'type'=>'patient')); if(count($new_delivery) > 0){ foreach($new_delivery as $knd => $vnd){ array_push($rst['data_deliveries'],$vnd); } } /*data doctor*/ $sql = "SELECT M_DoctorID, M_DoctorIsDefault, 'N' M_DoctorIsPJ, CONCAT(M_DoctorPrefix, M_DoctorPrefix2,' ',M_DoctorName,' ',M_DoctorSufix, M_DoctorSufix2, M_DoctorSufix3) as M_DoctorName, fn_fo_delivery_code('DOCTOR', 'EMAIL', 0) as delivery_email_code, IF(M_DoctorEmail IS NULL OR M_DoctorEmail = '', 'N', M_DoctorEmailIsDefault) email_default, IFNULL( concat('[', group_concat(JSON_OBJECT('M_DoctorAddressDescription', M_DoctorAddressDescription, 'M_DoctorAddressID', M_DoctorAddressID, 'delivery_default', M_DoctorAddressDeliveryDefault, 'delivery_code', fn_fo_delivery_code('DOCTOR', 'ADDRESS', M_DoctorAddressID)) SEPARATOR ','), ']'), '[]') as address, M_DoctorNote FROM t_orderheader JOIN m_doctor ON T_OrderHeaderSenderM_DoctorID = M_DoctorID AND M_DoctorIsActive = 'Y' JOIN m_doctoraddress ON M_DoctorAddressM_DoctorID = M_DoctorID AND M_DoctorAddressIsActive = 'Y' WHERE T_OrderHeaderID = {$prm['order_id']} group by M_DoctorID"; //echo $sql; $v = $this->db_onedev->query($sql)->row_array(); if($v){ $v['address'] = json_decode($v['address']); $rst['selected_doctor'] = $v; $sql = "SELECT M_DoctorAddressDescription, M_DoctorAddressID, M_DoctorAddressDeliveryDefault delivery_default, fn_fo_delivery_code('DOCTOR', 'ADDRESS', M_DoctorAddressID) delivery_code FROM t_orderheader JOIN m_doctor ON T_OrderHeaderSenderM_DoctorID = M_DoctorID AND M_DoctorIsActive = 'Y' JOIN m_doctoraddress ON T_OrderHeaderSenderM_DoctorAddressID = M_DoctorAddressID AND M_DoctorAddressIsActive = 'Y' WHERE T_OrderHeaderID = {$prm['order_id']}"; $raddr = $this->db_onedev->query($sql)->row_array(); foreach($v['address'] as $kaddr => $vaddr){ if(intval($vaddr->M_DoctorAddressID) == intval($raddr['M_DoctorAddressID'])) $rst['selected_address'] = $v['address'][$kaddr]; } //$rst['selected_address'] = $vaddr; } else{ $sql = "SELECT M_DoctorID, M_DoctorIsDefault, 'N' M_DoctorIsPJ, CONCAT(M_DoctorPrefix, M_DoctorPrefix2,' ',M_DoctorName,' ',M_DoctorSufix, M_DoctorSufix2, M_DoctorSufix3) as M_DoctorName, fn_fo_delivery_code('DOCTOR', 'EMAIL', 0) as delivery_email_code, IF(M_DoctorEmail IS NULL OR M_DoctorEmail = '', 'N', M_DoctorEmailIsDefault) email_default, IFNULL( concat('[', group_concat(JSON_OBJECT('M_DoctorAddressDescription', M_DoctorAddressDescription, 'M_DoctorAddressID', M_DoctorAddressID, 'delivery_default', M_DoctorAddressDeliveryDefault, 'delivery_code', fn_fo_delivery_code('DOCTOR', 'ADDRESS', M_DoctorAddressID)) SEPARATOR ','), ']'), '[]') as address, M_DoctorNote FROM m_doctor JOIN m_doctoraddress ON M_DoctorAddressM_DoctorID = M_DoctorID AND M_DoctorAddressIsActive = 'Y' WHERE M_DoctorName = '-' AND M_DoctorIsActive = 'Y' group by M_DoctorID"; $rst['selected_doctor'] = $this->db_onedev->query($sql)->result_array(); foreach ($rst['selected_doctor'] as $xxk => $xxv) $rst['selected_doctor'][$k]['address'] = json_decode($xxv['address']); } if(!$rst['selected_address']){ $rst['selected_address'] = $rst['address_doctor'][0]; } $new_delivery = array(); $new_delivery = $this->search_deliveries(array('id'=>$rst['selected_doctor']['M_DoctorID'],'type'=>'doctor')); if(count($new_delivery) > 0){ foreach($new_delivery as $knd => $vnd){ array_push($rst['data_deliveries'],$vnd); } } /*data company mou*/ $sql = "SELECT m_company.*, '' mou FROM m_company WHERE M_CompanyID = {$row_header['T_OrderHeaderM_CompanyID']}"; $row_company = $this->db_onedev->query($sql)->row_array(); $sql = "SELECT M_MouStatus,M_MouEmail, M_MouEmailIsDefault, M_MouEndDate, M_MouID, M_MouIsBill, M_MouIsDefault, M_MouName, M_MouNote, M_MouStartDate, '' delivery_email_code FROM m_mou WHERE M_MouM_CompanyID = {$row_company['M_CompanyID']} AND M_MouStatus = 'R' AND M_MouIsActive = 'Y'"; //echo $sql; $row_company['mou'] = $this->db_onedev->query($sql)->result_array(); //print_r($row_company); $rst['selected_company'] = $row_company; $rst['selected_mou'] = $row_mou; $rst['companies'] = array(); array_push($rst['companies'],$rst['selected_company']); $new_delivery = array(); //echo $rst['selected_mou']['M_MouID']; $new_delivery = $this->search_deliveries(array('id'=>$rst['selected_mou']['M_MouID'],'type'=>'mou')); if(count($new_delivery) > 0){ foreach($new_delivery as $knd => $vnd){ array_push($rst['data_deliveries'],$vnd); } } /*data deliveries*/ $sql = "SELECT * FROM t_orderdelivery JOIN m_deliverytype ON T_OrderDeliveryM_DeliveryTypeID = M_DeliveryTypeID JOIN m_delivery ON T_OrderDeliveryM_DeliveryID = M_DeliveryID WHERE T_OrderDeliveryT_OrderHeaderID = {$row_header['T_OrderHeaderID']} AND T_OrderDeliveryIsActive = 'Y'"; $order_deliveries = $this->db_onedev->query($sql)->result_array(); foreach($rst['data_deliveries'] as $kd => $vd){ $check_exist = $this->exist_delivery($order_deliveries,$vd); //print_r($check_exist); if($check_exist['idx'] != -1){ $rst['data_deliveries'][$kd]['chex'] = 'Y'; $idx = $check_exist['idx']; if($vd['delivery_code'] == 'PICKUP' || $vd['delivery_code'] == 'ADDRESS'){ $sql = "SELECT * FROM t_orderdeliverynote WHERE T_OrderDeliveryNoteT_OrderDeliveryID = {$order_deliveries[$idx]['T_OrderDeliveryID']} AND T_OrderDeliveryNoteIsActive = 'Y'"; //echo $sql; $dt_note = $this->db_onedev->query($sql)->row_array(); if($dt_note){ $rst['data_deliveries'][$kd]['note'] = $dt_note['T_OrderDeliveryNoteValue']; } } if($vd['delivery_code'] !== 'PICKUP' && $vd['delivery_code'] != 'ADDRESS'){ if($vd['description'] != $order_deliveries[$idx]['T_OrderDeliveryDestination']){ //echo 'YYYYYYYYY'; $rst['data_deliveries'][$kd]['note'] = $order_deliveries[$idx]['T_OrderDeliveryDestination']; } } } } $xrst = array('status'=>$status,'data'=>$rst); } $result = array("records" => $xrst); $this->sys_ok($result); exit; } function exist_delivery($arr,$row){ $rtn = array('status'=>false,'idx'=>-1); foreach($arr as $k => $v){ if($v['M_DeliveryID'] == $row['delivery_id'] && $v['T_OrderDeliveryAddressID'] == $row['address_id']){ $rtn = array('status'=>false,'idx'=>$k); } } return $rtn; } function search_deliveries($prm) { $type = $prm['type']; $id = $prm['id']; if($type == 'patient'){ $sql = " SELECT 0 as kelurahan, 0 as address_id, M_DeliveryM_DeliveryTypeID as delivery_type, M_DeliveryID as delivery_id, M_DeliveryName as delivery_name, '' as description, 'N' as chex, '' as note, 'origin' as typeform, '{$type}' as type, M_DeliveryTypeCode as delivery_code FROM m_delivery JOIN m_deliverytype ON M_DeliveryTypeCode = 'PICKUP' AND M_DeliveryM_DeliveryTypeID = M_DeliveryTypeID WHERE M_DeliverySource = '{$type}' AND M_DeliveryIsActive = 'Y' UNION SELECT M_PatientAddressM_KelurahanID as kelurahan, M_PatientAddressID as address_id, M_DeliveryM_DeliveryTypeID as delivery_type, M_DeliveryID as delivery_id, M_DeliveryName as delivery_name, CONCAT(M_PatientAddressDescription,' ',M_KelurahanName,', ',M_DistrictName,', ',M_CityName) as description, 'N' as chex, '' as note, 'origin' as typeform, '{$type}' as type, M_DeliveryTypeCode as delivery_code FROM m_patient JOIN m_patientaddress ON M_PatientAddressM_PatientID = M_PatientID AND M_PatientAddressIsActive = 'Y' JOIN m_kelurahan ON M_PatientAddressM_KelurahanID = M_KelurahanID JOIN m_district ON M_KelurahanM_DistrictID = M_DistrictID JOIN m_city ON M_DistrictM_CityID = M_CityID JOIN m_delivery ON M_DeliverySource = '{$type}' AND M_DeliveryIsActive = 'Y' JOIN m_deliverytype ON M_DeliveryTypeCode = 'ADDRESS' AND M_DeliveryM_DeliveryTypeID = M_DeliveryTypeID WHERE M_PatientID = {$id} GROUP BY M_PatientAddressID UNION SELECT 0 as kelurahan, 0 as address_id, M_DeliveryM_DeliveryTypeID as delivery_type, M_DeliveryID as delivery_id, M_DeliveryName as delivery_name, IFNULL(M_PatientEmail,'Belum ada email pasien') as description, 'N' as chex, '' as note, 'origin' as typeform, '{$type}' as type, M_DeliveryTypeCode as delivery_code FROM m_patient JOIN m_delivery ON M_DeliverySource = '{$type}' AND M_DeliveryIsActive = 'Y' JOIN m_deliverytype ON M_DeliveryTypeCode = 'EMAIL' AND M_DeliveryM_DeliveryTypeID = M_DeliveryTypeID WHERE M_PatientID = {$id} UNION SELECT 0 as kelurahan, 0 as address_id, M_DeliveryM_DeliveryTypeID as delivery_type, M_DeliveryID as delivery_id, M_DeliveryName as delivery_name, IFNULL(M_PatientEmail,'Belum ada email pasien') as description, 'N' as chex, '' as note, 'origin' as typeform, '{$type}' as type, M_DeliveryTypeCode as delivery_code FROM m_patient JOIN m_delivery ON M_DeliverySource = '{$type}' AND M_DeliveryIsActive = 'Y' JOIN m_deliverytype ON M_DeliveryTypeCode = 'EMAIL' AND M_DeliveryM_DeliveryTypeID = M_DeliveryTypeID WHERE M_PatientID = {$id} UNION SELECT 0 as kelurahan, 0 as address_id, M_DeliveryM_DeliveryTypeID as delivery_type, M_DeliveryID as delivery_id, M_DeliveryName as delivery_name, IFNULL(M_PatientHP,'Belum ada WA pasien') as description, 'N' as chex, '' as note, 'origin' as typeform, '{$type}' as type, M_DeliveryTypeCode as delivery_code FROM m_patient JOIN m_delivery ON M_DeliverySource = '{$type}' AND M_DeliveryIsActive = 'Y' JOIN m_deliverytype ON M_DeliveryTypeCode = 'WHATSAPP' AND M_DeliveryM_DeliveryTypeID = M_DeliveryTypeID WHERE M_PatientID = {$id} UNION SELECT 0 as kelurahan, 0 as address_id, M_DeliveryM_DeliveryTypeID as delivery_type, M_DeliveryID as delivery_id, M_DeliveryName as delivery_name, IFNULL(M_PatientHP,'Belum ada telegram pasien') as description, 'N' as chex, '' as note, 'origin' as typeform, '{$type}' as type, M_DeliveryTypeCode as delivery_code FROM m_patient JOIN m_delivery ON M_DeliverySource = '{$type}' AND M_DeliveryIsActive = 'Y' JOIN m_deliverytype ON M_DeliveryTypeCode = 'TELEGRAM' AND M_DeliveryM_DeliveryTypeID = M_DeliveryTypeID WHERE M_PatientID = {$id}"; } if($type == 'mou'){ //echo $id; $sql = "SELECT * FROM m_mou WHERE M_MouID = {$id}"; //echo $sql; $data_mou = $this->db_onedev->query($sql)->row_array(); //print_r($data_mou); $sql = " SELECT M_CompanyM_KelurahanID as kelurahan, M_CompanyID as address_id, M_DeliveryM_DeliveryTypeID as delivery_type, M_DeliveryID as delivery_id, M_DeliveryName as delivery_name, CONCAT(M_CompanyAddress,' ',M_KelurahanName,', ',M_DistrictName,', ',M_CityName) as description, 'N' as chex, '' as note, 'origin' as typeform, '{$type}' as type, M_DeliveryTypeCode as delivery_code FROM m_company JOIN m_delivery ON M_DeliverySource = 'COMPANY' AND M_DeliveryIsActive = 'Y' JOIN m_deliverytype ON M_DeliveryTypeCode = 'ADDRESS' AND M_DeliveryM_DeliveryTypeID = M_DeliveryTypeID JOIN m_kelurahan ON M_CompanyM_KelurahanID = M_KelurahanID JOIN m_district ON M_KelurahanM_DistrictID = M_DistrictID JOIN m_city ON M_DistrictM_CityID = M_CityID WHERE M_CompanyID = {$data_mou['M_MouM_CompanyID']} UNION SELECT 0 as kelurahan, 0 as address_id, M_DeliveryM_DeliveryTypeID as delivery_type, M_DeliveryID as delivery_id, M_DeliveryName as delivery_name, IFNULL(M_MouEmail,'Belum ada email agreement') as description, IFNULL(M_MouEmailIsDefault,'N') as chex, '' as note, 'origin' as typeform, '{$type}' as type, M_DeliveryTypeCode as delivery_code FROM m_mou JOIN m_delivery ON M_DeliverySource = '{$type}' AND M_DeliveryIsActive = 'Y' JOIN m_deliverytype ON M_DeliveryTypeCode = 'EMAIL' AND M_DeliveryM_DeliveryTypeID = M_DeliveryTypeID WHERE M_MouID = {$id}"; //echo $sql; } if($type == 'doctor'){ $sql = " SELECT M_DoctorAddressM_KelurahanID as kelurahan, M_DoctorAddressID as address_id, M_DeliveryM_DeliveryTypeID as delivery_type, M_DeliveryID as delivery_id, M_DeliveryName as delivery_name, CONCAT(M_DoctorAddressDescription,' ',M_KelurahanName,', ',M_DistrictName,', ',M_CityName) as description, M_DoctorAddressDeliveryDefault as chex, '' as note, 'origin' as typeform, '{$type}' as type, M_DeliveryTypeCode as delivery_code FROM m_doctor JOIN m_doctoraddress ON M_DoctorAddressM_DoctorID = M_DoctorID AND M_DoctorAddressIsActive = 'Y' JOIN m_kelurahan ON M_DoctorAddressM_KelurahanID = M_KelurahanID JOIN m_district ON M_KelurahanM_DistrictID = M_DistrictID JOIN m_city ON M_DistrictM_CityID = M_CityID JOIN m_delivery ON M_DeliverySource = '{$type}' AND M_DeliveryIsActive = 'Y' JOIN m_deliverytype ON M_DeliveryTypeCode = 'ADDRESS' AND M_DeliveryM_DeliveryTypeID = M_DeliveryTypeID WHERE M_DoctorID = {$id} GROUP BY M_DoctorAddressID UNION SELECT 0 as kelurahan, 0 as address_id, M_DeliveryM_DeliveryTypeID as delivery_type, M_DeliveryID as delivery_id, M_DeliveryName as delivery_name, IF(ISNULL(M_DoctorEmail) OR M_DoctorEmail = '','Belum ada email pengirim',M_DoctorEmail) as description, IF(M_DoctorEmailIsDefault = '','N',IFNULL(M_DoctorEmailIsDefault,'N')) as chex, '' as note, 'origin' as typeform, '{$type}' as type, M_DeliveryTypeCode as delivery_code FROM m_doctor JOIN m_delivery ON M_DeliverySource = '{$type}' AND M_DeliveryIsActive = 'Y' JOIN m_deliverytype ON M_DeliveryTypeCode = 'EMAIL' AND M_DeliveryM_DeliveryTypeID = M_DeliveryTypeID WHERE M_DoctorID = {$id} UNION SELECT 0 as kelurahan, 0 as address_id, M_DeliveryM_DeliveryTypeID as delivery_type, M_DeliveryID as delivery_id, M_DeliveryName as delivery_name, IF(ISNULL(M_DoctorHP) OR M_DoctorHP = '','Belum ada WA pengirim',M_DoctorHP) as description, IF(M_DoctorEmailIsDefault = '','N',IFNULL(M_DoctorEmailIsDefault,'N')) as chex, '' as note, 'origin' as typeform, '{$type}' as type, M_DeliveryTypeCode as delivery_code FROM m_doctor JOIN m_delivery ON M_DeliverySource = '{$type}' AND M_DeliveryIsActive = 'Y' JOIN m_deliverytype ON M_DeliveryTypeCode = 'WHATSAPP' AND M_DeliveryM_DeliveryTypeID = M_DeliveryTypeID WHERE M_DoctorID = {$id} UNION SELECT 0 as kelurahan, 0 as address_id, M_DeliveryM_DeliveryTypeID as delivery_type, M_DeliveryID as delivery_id, M_DeliveryName as delivery_name, IF(ISNULL(M_DoctorHP) OR M_DoctorHP = '','Belum ada telegram pengirim',M_DoctorHP) as description, IF(M_DoctorEmailIsDefault = '','N',IFNULL(M_DoctorEmailIsDefault,'N')) as chex, '' as note, 'origin' as typeform, '{$type}' as type, M_DeliveryTypeCode as delivery_code FROM m_doctor JOIN m_delivery ON M_DeliverySource = '{$type}' AND M_DeliveryIsActive = 'Y' JOIN m_deliverytype ON M_DeliveryTypeCode = 'TELEGRAM' AND M_DeliveryM_DeliveryTypeID = M_DeliveryTypeID WHERE M_DoctorID = {$id}"; } //echo $sql; $query = $this->db_onedev->query($sql); if ($query) { $rows= $query->result_array(); //$data = json_decode($rows->x); if($rows){ foreach($rows as $k => $v){ $xval = $v['chex'] === 'N'?false:true; //$rows[$k]['chex'] = $xval; } } return $rows; } else { return array(); } } } ?>