334 lines
12 KiB
PHP
334 lines
12 KiB
PHP
<?php
|
|
class Delivery extends MY_Controller
|
|
{
|
|
var $db_smartone;
|
|
public function index()
|
|
{
|
|
echo "Patient API";
|
|
}
|
|
public function __construct()
|
|
{
|
|
parent::__construct();
|
|
$this->db_smartone = $this->load->database("onedev", true);
|
|
}
|
|
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 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}
|
|
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,
|
|
'Kirim ke eHac' as description,
|
|
'N' as chex,
|
|
'' as note,
|
|
'origin' as typeform,
|
|
'EHAC' as type,
|
|
M_DeliveryTypeCode as delivery_code
|
|
FROM m_delivery
|
|
JOIN m_deliverytype ON M_DeliveryTypeCode = 'EHAC' AND M_DeliveryM_DeliveryTypeID = M_DeliveryTypeID
|
|
WHERE
|
|
M_DeliverySource = 'EHAC' AND M_DeliveryIsActive = 'Y'";
|
|
|
|
|
|
}
|
|
if($type == 'mou'){
|
|
$sql = "SELECT * FROM m_mou WHERE M_MouID = {$id}";
|
|
$data_mou = $this->db_smartone->query($sql)->row_array();
|
|
$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}";
|
|
}
|
|
|
|
$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;
|
|
}
|
|
|
|
|
|
|
|
}
|
|
}
|