Files
BE_IBL/application/controllers/one-doctor/Generateorder.php
2026-04-15 15:23:57 +07:00

182 lines
7.7 KiB
PHP

<?php
class Generateorder extends MY_Controller
{
var $db_onedev;
public function index()
{
echo "CONTROL API";
}
public function __construct()
{
parent::__construct();
$this->db_onedev = $this->load->database("onedev", true);
}
function lookupbyname(){
try {
//# cek token valid
if (! $this->isLogin) {
$this->sys_error("Invalid Token");
exit;
}
$prm = $this->sys_input;
$search = $prm['search'];
$all = $prm['all'];
$sdate = $prm['sdate'];
$limit = '';
if($all == 'N'){
$limit = ' LIMIT 10';
}
$number_limit = 10;
$number_offset = ($prm['current_page'] - 1) * $number_limit ;
$sql = "select COUNT(*) as total
from one_doctor.order_patient
LEFT JOIN one_doctor.order_patient_details ON OrderPatientDetailsOrderPatientID = OrderPatientID AND OrderPatientDetailsIsActive = 'Y'
LEFT JOIN m_doctor ON M_DoctorID = OrderPatientM_DoctorID
where OrderPatientID >= 52 AND
OrderPatientIsActive = 'Y' AND OrderPatientIsConfirmed <> 'Y' AND
(OrderPatientQrCode LIKE CONCAT('%','{$search}','%') OR
M_DoctorName LIKE CONCAT('%','{$search}','%') OR
OrderPatientFullName LIKE CONCAT('%','{$search}','%'))";
// $total = $this->db_onedev->query($sql,$sql_param)->row()->total;
$query = $this->db_onedev->query($sql);
//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("order_patient count", $this->db_onedev);
exit;
}
$sql = "select one_doctor.order_patient.*,
OrderPatientID as id,
OrderPatientQrCode,
DATE_FORMAT(OrderPatientDate, '%d-%m-%Y') as xdate,
IF(OrderPatientIsConfirmed = 'N' ,'N','Y') as ishide,
OrderPatientFullName,
GROUP_CONCAT(OrderPatientDetailsT_TestName SEPARATOR ', ') as testname,
OrderPatientM_DoctorID,
`fn_get_doctor_fullname`(OrderPatientM_DoctorID) as M_DoctorName,
OrderPatientM_CompanyID,
M_CompanyName,
OrderPatientM_MouID,
M_MouName,
IFNULL( concat('[', group_concat( json_object('M_MouID', M_MouID, 'M_MouName', M_MouName, 'M_MouStartDate', M_MouStartDate, 'M_MouEndDate', M_MouEndDate, 'M_MouNote', M_MouNote, 'M_MouIsBill', M_MouIsBill, 'M_MouEmail', M_MouEmail, 'M_MouIsDefault', M_MouIsDefault, 'M_MouEmailIsDefault', M_MouEmailIsDefault, 'delivery_email_code', `fn_fo_delivery_code`('MOU', 'EMAIL', '0')) ), ']'), '[]') as mou,
'' as tests
from one_doctor.order_patient
LEFT JOIN one_doctor.order_patient_details ON OrderPatientDetailsOrderPatientID = OrderPatientID AND OrderPatientDetailsIsActive = 'Y'
LEFT JOIN m_doctor ON M_DoctorID = OrderPatientM_DoctorID
LEFT JOIN m_company ON M_CompanyID = OrderPatientM_CompanyID
LEFT JOIN m_mou ON M_MouID = OrderPatientM_MouID
where OrderPatientID >= 52 AND
OrderPatientIsActive = 'Y' AND OrderPatientIsConfirmed <> 'Y' AND
(OrderPatientQrCode LIKE CONCAT('%','{$search}','%') OR
M_DoctorName LIKE CONCAT('%','{$search}','%') OR
OrderPatientFullName LIKE CONCAT('%','{$search}','%'))
GROUP BY OrderPatientID
ORDER BY OrderPatientID ASC
limit $number_limit offset $number_offset";
$sql_param = array($search);
$query = $this->db_onedev->query($sql);
//echo $this->db_onedev->last_query();
if ($query) {
$rows = $query->result_array();
foreach($rows as $k => $v){
$id = $v['OrderPatientID'];
$x = $this->db_onedev->query("select concat( '[', group_concat( json_object('id',OrderPatientDetailsT_TestID, 'name', OrderPatientDetailsT_TestName,'status','Y') separator ',' ), ']' )
as n FROM
(SELECT OrderPatientDetailsT_TestID,OrderPatientDetailsT_TestName
FROM one_doctor.order_patient_details
WHERE OrderPatientDetailsOrderPatientID = $id ) a")->row();
$rows[$k]['tests'] = json_decode($x->n);
$rows[$k]['mou'] = json_decode($v['mou']);
}
} else {
$this->sys_error_db("order_patient select");
exit;
}
$result = array ("total" => $tot_page, "total_filter"=>count($rows),"records" => $rows);
$this->sys_ok($result);
} catch(Exception $exc) {
$message = $exc->getMessage();
$this->sys_error($message);
}
}
public function fix()
{
try {
//# cek token valid
if (! $this->isLogin) {
$this->sys_error("Invalid Token");
exit;
}
//# ambil parameter input
$prm = $this->sys_input;
$id = $prm['id'];
$nomor = md5($prm['nomor']);
$sql = $this->db_onedev->query("SELECT M_BranchIPAddress as branch_ip_address FROM m_branch WHERE M_BranchIsDefault = 'Y'")->row();
$branch_ip_address = $sql->branch_ip_address;
$param = array (
"id" => $id,
"nomor" => $nomor);
$j_param = json_encode($param);
$url = "http://$branch_ip_address/one-api/fix/pramitalabku/generate_order/".$id;
$post_rst = $this->post($url);
// echo "to $url \nresponse : $post_rst\n";
$j_rst = json_decode($post_rst,true);
$xstatus = $j_rst["status"];
$xpesan = $j_rst["message"];
$result = array ("total" => 1, "records" => array("xid" => 0),"pesan"=>$post_rst);
$this->sys_ok($result);
} catch(Exception $exc) {
$message = $exc->getMessage();
$this->sys_error($message);
}
}
function post($url) {
//$data = $data;
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$result = curl_exec($ch);
//echo "RST : $result ";
return $result;
}
function postold($url,$data) {
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");
curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_TIMEOUT, 12);
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 2);
curl_setopt($ch, CURLOPT_HTTPHEADER, array(
'Content-Type: application/json',
'Content-Length: ' . strlen($data))
);
$result = curl_exec($ch);
if (curl_errno($ch)){
return json_encode( array("status" => "ERR",
"message" => curl_error($ch)) );
}
curl_close($ch);
return $result;
}
}