db_smartone = $this->load->database("onedev", true); } function listmou(){ $prm = $this->sys_input; $query ="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, 'PATIENT' 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 = 'PATIENT' AND M_DeliveryIsActive = 'Y' JOIN m_deliverytype ON M_DeliveryTypeCode = 'ADDRESS' AND M_DeliveryM_DeliveryTypeID = M_DeliveryTypeID WHERE M_PatientID = ? GROUP BY M_PatientAddressID "; //echo $query; $rows = $this->db_smartone->query($query,array($prm['id']))->result_array(); $result = array( "total" => count($rows) , "records" => $rows, ); $this->sys_ok($result); exit; } function add_new() { $userid = $this->sys_user["M_UserID"]; $prm = $this->sys_input; $addhs = [ 'M_PatientAddressNote' => $prm['label'], 'M_PatientAddressM_PatientID' => $prm['patientid'], 'M_PatientAddressDescription' => $prm['address'], 'M_PatientAddressUserID'=> $userid, 'M_PatientAddressM_KelurahanID' => $prm['kelurahan'] ]; $this->db_smartone->insert('m_patientaddress', $addhs); $addhs = json_encode($addhs); // INSERT HS // get $r = $this->db_smartone->where('M_PatientID', $prm['patientid']) ->get('m_patient') ->row(); $rst = array("id" => $id,"idhs" => $idhs, 'noreg'=>$r->M_PatientNoReg); $this->sys_ok($rst); } public function search() { $prm = $this->sys_input; $q = [ "patient_id" => 0, "doctor_id" => 0, "mou_id" => 0, "company_id" => 0 ]; if (isset($prm['patient_id'])) $q["patient_id"] = $prm['patient_id']; if (isset($prm['doctor_id'])) $q["doctor_id"] = $prm['doctor_id']; if (isset($prm['mou_id'])) $q["mou_id"] = $prm['mou_id']; if (isset($prm['c_id'])) $q["company_id"] = $prm['c_id']; $sql = "CALL sp_fo_delivery_address_v3_bandung('', '{$q['patient_id']}', '{$q['doctor_id']}', '{$q['mou_id']}','{$q["company_id"]}')"; $query = $this->db_smartone->query($sql); if ($query) { $rows= $query->row(); $data = json_decode($rows->x); $result = array("records" => $data); $this->sys_ok($result); exit; } else { $this->sys_error_db("delivery address",$this->db_smartone); exit; } // $rows = array(); // $rows[] = array("id" =>1, "name" => "Ambil Sendiri", "selected" => false, "note" => ""); // $rows[] = array("id" =>2, "name" => "Kirim ke dokter", "selected" => false, "note" => ""); // $rows[] = array("id" =>3, "name" => "Kirim ke email pasien", "selected" => false, "note" => ""); // $rows[] = array("id" =>4, "name" => "Kirim ke email dokter", "selected" => false, "note" => ""); // $rows[] = array("id" =>5, "name" => "Kirim ke alamat utama pasien", "selected" => false, "note" => ""); // $rows[] = array("id" =>6, "name" => "Kirim ke alamat utama dokter", "selected" => false, "note" => ""); // $rows[] = array("id" =>7, "name" => "Kirim ke rekanan"); } public function search_deliveries() { if (! $this->isLogin) { $this->sys_error("Invalid Token"); exit; } $prm = $this->sys_input; $type = $prm['type']; $id = $prm['id']; if($type == 'patient'){ $sql = " 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, '' 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 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 == '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}"; } $query = $this->db_smartone->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; } } $result = array("records" => $rows); $this->sys_ok($result); exit; } else { $this->sys_error_db("delivery address",$this->db_smartone); exit; } } }