1279 lines
42 KiB
PHP
1279 lines
42 KiB
PHP
<?php
|
|
class Patient extends MY_Controller
|
|
{
|
|
var $db_onedev;
|
|
public function index()
|
|
{
|
|
echo "Patient API";
|
|
}
|
|
public function __construct()
|
|
{
|
|
parent::__construct();
|
|
$this->db_onedev = $this->load->database("onedev", true);
|
|
$this->load->helper(array('form', 'url'));
|
|
}
|
|
|
|
public function add_notes($orderid)
|
|
{
|
|
$sql = " SELECT F_PaymentT_OrderHeaderID as note_order_id,
|
|
F_PaymentID as note_id,
|
|
F_PaymentDate as note_date,
|
|
F_PaymentNumber as note_number,
|
|
GROUP_CONCAT(M_PaymentTypeName separator ' , ') as paymenttypes_name,
|
|
SUM(F_PaymentDetailAmount) as note_amount,
|
|
M_UserUsername as note_user,
|
|
F_PaymentDetailIsActive as note_active
|
|
FROM f_payment
|
|
JOIN f_paymentdetail ON F_PaymentDetailF_PaymentID = F_PaymentID
|
|
JOIN m_paymenttype ON F_PaymentDetailM_PaymentTypeID = M_PaymentTypeID
|
|
LEFT JOIN m_user ON F_PaymentDetailUserID = M_UserID
|
|
WHERE
|
|
F_PaymentT_OrderHeaderID = {$orderid}
|
|
GROUP BY F_PaymentID";
|
|
$query = $this->db_onedev->query($sql);
|
|
if ($query) {
|
|
$rows = $query->result_array();
|
|
return $rows;
|
|
} else {
|
|
$this->sys_error_db("get notes", $this->db_onedev);
|
|
exit;
|
|
}
|
|
}
|
|
|
|
|
|
function search()
|
|
{
|
|
//# cek token valid
|
|
if (!$this->isLogin) {
|
|
$this->sys_error("Invalid Token");
|
|
exit;
|
|
}
|
|
$prm = $this->sys_input;
|
|
$doctorid = $prm['doctorid'];
|
|
$doctorcode = $prm['doctorcode'];
|
|
$companyid = $prm['companyid'];
|
|
$nattestid = isset($prm['testid']) ? $prm['testid'] : 0;
|
|
$filter_doctor = '';
|
|
$filter_doctor_code_count = '';
|
|
$filter_company = '';
|
|
$filter_branch = '';
|
|
$filter_test = '';
|
|
$join_orderdetail = '';
|
|
$startdate = $prm['startdate'];
|
|
$enddate = $prm['enddate'];
|
|
$search = $prm["search"];
|
|
$search = str_replace("'", "\\'", $search);
|
|
$status = $prm["status"];
|
|
$branchid = $prm["branchid"];
|
|
$number_limit = 20;
|
|
$number_offset = ($prm['current_page'] - 1) * $number_limit;
|
|
$filter_date = " AND DATE(T_OrderHeaderDate) BETWEEN '{$startdate}' AND '{$enddate}'";
|
|
if ($search != '' || ($doctorid != 0 || $doctorid != '0')) {
|
|
$prev_date = date('Y-m-d', strtotime('-30 day', strtotime($enddate)));
|
|
//echo $prev_date;
|
|
//$filter_date = " AND DATE(T_OrderHeaderDate) BETWEEN '{$prev_date}' AND '{$enddate}'";
|
|
}
|
|
|
|
$where = " T_OrderHeaderIsActive = 'Y' $filter_date ";
|
|
$filter_search = "";
|
|
|
|
if ($search != '')
|
|
$where .= " AND ( M_PatientName LIKE '%{$search}%' OR T_OrderHeaderLabNumber LIKE '%{$search}%' )";
|
|
|
|
if ($doctorid != 0 || $doctorid != '0') {
|
|
$filter_doctor = " ";
|
|
}
|
|
|
|
$filter_doctor_code_search = '';
|
|
|
|
|
|
if ($companyid != 0 || $companyid != '0') {
|
|
$filter_company = " AND T_OrderHeaderCorporateID = {$companyid}";
|
|
}
|
|
if ($branchid != 0 || $branchid != '0') {
|
|
$filter_branch = " AND T_OrderHeaderM_BranchID = {$branchid}";
|
|
}
|
|
|
|
if ($nattestid != 0 || $nattestid != '0') {
|
|
$filter_test = " JOIN t_orderdetail ON T_OrderDetailT_OrderHeaderID = T_OrderHeaderID AND T_OrderDetailIsActive = 'Y'
|
|
JOIN t_test ON T_OrderDetailT_TestID = T_TestID AND T_TestNat_testID = {$nattestid}
|
|
";
|
|
}
|
|
|
|
$sql = " SELECT count(*) as total
|
|
FROM (
|
|
SELECT T_OrderHeaderID
|
|
FROM t_orderheader
|
|
JOIN m_patient ON T_OrderHeaderM_PatientID = M_PatientID AND $where
|
|
$filter_company $filter_branch
|
|
JOIN corporate ON T_OrderHeaderCorporateID = CorporateID
|
|
JOIN mgm_mcu ON T_OrderHeaderMgm_McuID = Mgm_McuID
|
|
JOIN m_branch ON M_BranchID = T_OrderHeaderM_BranchID
|
|
group by T_OrderHeaderID
|
|
) x";
|
|
//echo $sql;
|
|
$query = $this->db_onedev->query($sql, $sql_param);
|
|
|
|
|
|
|
|
|
|
$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("t_samplestorage count", $this->db_onedev);
|
|
exit;
|
|
}
|
|
|
|
$sql = "SELECT * FROM (
|
|
SELECT T_OrderHeaderID, T_OrderHeaderLabNumber, '' as cito,
|
|
'' as rownumber,
|
|
M_PatientNoReg,
|
|
M_PatientPhoto,
|
|
CONCAT(IFNULL(M_TitleName, ''), IF(M_TitleName IS NULL, '', '. '), M_PatientName) AS patient_fullname,
|
|
M_CompanyName as CorporateName,
|
|
DATE_FORMAT(T_OrderHeaderDate, '%d-%m-%Y %H:%i') as order_date,
|
|
M_BranchName as branchName,
|
|
'' as orders,
|
|
M_StaffName as staff_register,
|
|
DATE_FORMAT(OrderLogCreated, '%d-%m-%Y %H:%i') as order_created,
|
|
'' as files
|
|
FROM t_orderheader
|
|
JOIN m_patient ON T_OrderHeaderM_PatientID = M_PatientID AND $where
|
|
$filter_company $filter_branch
|
|
LEFT JOIN m_company ON T_OrderHeaderM_CompanyID = M_CompanyID
|
|
LEFT JOIN m_branch ON M_BranchID = T_OrderHeaderM_BranchID
|
|
LEFT JOIN order_log ON OrderLogT_OrderHeaderID = T_OrderHeaderID AND OrderLogType = 'REGISTER'
|
|
LEFT JOIN m_user ON OrderLogUserID = M_UserID
|
|
LEFT JOIN m_staff ON M_UserM_StaffID = M_StaffID
|
|
LEFT JOIN m_title ON M_PatientM_TitleID = M_TitleID
|
|
group by T_OrderHeaderID
|
|
) x
|
|
ORDER BY T_OrderHeaderID ASC
|
|
limit $number_limit offset $number_offset
|
|
";
|
|
// echo $sql;
|
|
|
|
$query = $this->db_onedev->query($sql, $sql_param);
|
|
$querySearch = $this->db_onedev->last_query();
|
|
if (!$query) {
|
|
$message = $this->db_onedev->error();
|
|
$message['qry'] = $this->db_onedev->last_query();
|
|
$this->sys_error($message);
|
|
exit;
|
|
}
|
|
$rows = $query->result_array();
|
|
//print_r($rows);
|
|
if ($rows) {
|
|
foreach ($rows as $k => $v) {
|
|
$rows[$k]['patient_fullname'] = stripslashes($rows[$k]['patient_fullname']);
|
|
$xno = ($k + 1) + $number_offset;
|
|
$rows[$k]['rownumber'] = $xno;
|
|
$dt_test = [];
|
|
|
|
$files = [];
|
|
$sql = "SELECT File_AttachmentID as fid, File_AttachmentFileName as fname
|
|
FROM file_attachment
|
|
WHERE
|
|
File_AttachmentT_OrderHeaderID = ? AND File_AttachmentIsActive = 'Y'";
|
|
$query = $this->db_onedev->query($sql, [$v['T_OrderHeaderID']]);
|
|
//echo $this->db_onedev->last_query();
|
|
$files = $query->result_array();
|
|
$rows[$k]['files'] = $files;
|
|
}
|
|
}
|
|
//print_r($rows);
|
|
|
|
$result = array("total" => $tot_page, "total_all" => $tot_count, "total_filter" => count($rows), "records" => $rows, "sql" => $this->db_onedev->last_query(), 'qeysrc' => $querySearch);
|
|
$this->sys_ok($result);
|
|
exit;
|
|
}
|
|
|
|
function generateRandomString($length = 5) {
|
|
$characters = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ';
|
|
$charactersLength = strlen($characters);
|
|
$randomString = '';
|
|
for ($i = 0; $i < $length; $i++) {
|
|
$randomString .= $characters[rand(0, $charactersLength - 1)];
|
|
}
|
|
return $randomString;
|
|
}
|
|
|
|
function uploadattachment(){
|
|
if (!$this->isLogin) {
|
|
$this->sys_error("Invalid Token");
|
|
exit;
|
|
}
|
|
|
|
$userid = $this->sys_user["M_UserID"];
|
|
$data = [];
|
|
|
|
$prm = $this->sys_input;
|
|
$orderid = $this->input->post('orderid');
|
|
$labnumber = $this->input->post('labnumber');
|
|
$error = [];
|
|
|
|
//$path = '/home/one/project/one/one-media/one-files/';
|
|
|
|
$path = '/home/one/project/one/one-media/one-files/';;
|
|
|
|
$config['upload_path'] = $path;
|
|
$config['allowed_types'] = 'jpg|jpeg|png|gif|pdf';
|
|
|
|
$config['max_size'] = 3000; // Maksimal 3000 KB
|
|
$count = count($_FILES['files']['name']);
|
|
$this->load->library('upload',$config);
|
|
|
|
/*$sql = "SELECT COUNT(*) as xcount
|
|
FROM file_attachment
|
|
WHERE
|
|
File_AttachmentT_OrderHeaderID = ? AND File_AttachmentIsActive = 'Y'";
|
|
$query = $this->db_onedev->query($sql,array($orderid));
|
|
$count_file = $query->row()->xcount;*/
|
|
|
|
//$file_uploaded = count($_FILES['files']['name']) + $count_file;
|
|
$file_uploaded = 1;
|
|
if($file_uploaded > 2){
|
|
$error[] = "Jumlah file yang diupload maksimal 2";
|
|
}else{
|
|
for ($i = 0; $i < $count; $i++) {
|
|
if (!empty($_FILES['files']['name'][$i])) {
|
|
// Validasi ukuran file secara manual
|
|
|
|
if ($_FILES['files']['size'][$i] > 3000 * 1024) { // 3000 KB dalam byte
|
|
$error[] = "File " . $_FILES['files']['name'][$i] . " melebihi ukuran maksimal 500 KB.";
|
|
//print_r($error);
|
|
continue; // Skip file yang terlalu besar
|
|
}
|
|
|
|
//echo $_FILES['files']['name'][$i];
|
|
//exit;
|
|
|
|
$_FILES['file']['name'] = $_FILES['files']['name'][$i];
|
|
$_FILES['file']['type'] = $_FILES['files']['type'][$i];
|
|
$_FILES['file']['tmp_name'] = $_FILES['files']['tmp_name'][$i];
|
|
$_FILES['file']['error'] = $_FILES['files']['error'][$i];
|
|
$_FILES['file']['size'] = $_FILES['files']['size'][$i];
|
|
|
|
$namex = $labnumber . '_' . $this->generateRandomString(3);
|
|
$isFCI = "N";
|
|
$file_fci_ex = explode(".",$_FILES['files']['name'][$i]);
|
|
$file_fci = explode("_",$file_fci_ex[0]);
|
|
if(strtolower($file_fci[0]) == "fci"){
|
|
$isFCI = "Y";
|
|
$sql = "UPDATE file_attachment SET File_AttachmentIsActive = 'N', File_AttachmentDeleted = NOW(), File_AttachmentDeletedUserID = ?
|
|
WHERE
|
|
File_AttachmentT_OrderHeaderID = ? AND File_AttachmentIsFCI = 'Y' AND File_AttachmentIsActive = 'Y'";
|
|
$query = $this->db_onedev->query($sql,array($userid,$orderid));
|
|
$namex = $labnumber . '_FCI_' .$this->generateRandomString(3);
|
|
}
|
|
$config['file_name'] = $namex;
|
|
|
|
$this->upload->initialize($config);
|
|
|
|
if ($this->upload->do_upload('file')) {
|
|
$uploadData = $this->upload->data();
|
|
$filename = $uploadData['file_name'];
|
|
//echo $filename;
|
|
|
|
|
|
// Proses SQL atau penyimpanan data lainnya
|
|
$sql = "INSERT INTO file_attachment (
|
|
File_AttachmentIsFCI,
|
|
File_AttachmentT_OrderHeaderID,
|
|
File_AttachmentFileName,
|
|
File_AttachmentCreated,
|
|
File_AttachmentCreatedUserID
|
|
)
|
|
VALUES(?,?,?,NOW(),?)";
|
|
$query = $this->db_onedev->query($sql,array($isFCI,$orderid,$filename,$userid));
|
|
|
|
} else {
|
|
$error[] = $this->upload->display_errors();
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
$result = array("total" =>count( $data['totalFiles']), "records" => $data['totalFiles'],'errors'=>$error);
|
|
$this->sys_ok($result);
|
|
}
|
|
|
|
function searchcompany()
|
|
{
|
|
if (!$this->isLogin) {
|
|
$this->sys_error("Invalid Token");
|
|
exit;
|
|
}
|
|
$prm = $this->sys_input;
|
|
|
|
$max_rst = 12;
|
|
$tot_count = 0;
|
|
|
|
$q = [
|
|
'search' => '%'
|
|
];
|
|
|
|
if ($prm['search'] == '') {
|
|
|
|
$rows = array(array('id' => 0, 'name' => 'Semua'));
|
|
$result = array("total" => 1, "records" => $rows, "total_display" => sizeof($rows));
|
|
$this->sys_ok($result);
|
|
} else {
|
|
$q['search'] = "%{$prm['search']}%";
|
|
$sql = "
|
|
SELECT CorporateID AS id, CorporateName as name FROM corporate
|
|
WHERE CorporateName LIKE ?
|
|
AND CorporateIsActive = 'Y'
|
|
ORDER BY CorporateName DESC
|
|
";
|
|
$query = $this->db_onedev->query($sql, array($q['search']));
|
|
|
|
if ($query) {
|
|
$rows = $query->result_array();
|
|
array_push($rows, array('id' => 0, 'name' => 'Semua'));
|
|
//echo $this->db_onedev->last_query();
|
|
$result = array("total" => $tot_count, "records" => $rows, "total_display" => sizeof($rows));
|
|
$this->sys_ok($result);
|
|
} else {
|
|
$this->sys_error_db("m_company rows", $this->db_onedev);
|
|
exit;
|
|
}
|
|
}
|
|
}
|
|
|
|
function searchdoctor()
|
|
{
|
|
if (!$this->isLogin) {
|
|
$this->sys_error("Invalid Token");
|
|
exit;
|
|
}
|
|
$prm = $this->sys_input;
|
|
|
|
$max_rst = 12;
|
|
$tot_count = 0;
|
|
|
|
$q = [
|
|
'search' => '%'
|
|
];
|
|
|
|
if ($prm['search'] == '') {
|
|
|
|
$rows = array(array('id' => 0, 'name' => 'Semua'));
|
|
$result = array("total" => 1, "records" => $rows, "total_display" => sizeof($rows));
|
|
$this->sys_ok($result);
|
|
} else {
|
|
$q['search'] = "%{$prm['search']}%";
|
|
$sql = "
|
|
SELECT M_DoctorID as id, M_DoctorCode as code,CONCAT(M_DoctorPrefix,M_DoctorPrefix2,' ',M_DoctorName,' ',M_DoctorSufix,M_DoctorSufix2,M_DoctorSufix3) as name
|
|
FROM m_doctor
|
|
WHERE
|
|
M_DoctorName like ?
|
|
AND M_DoctorIsActive = 'Y'
|
|
ORDER BY M_DoctorName ASC, M_DoctorName DESC
|
|
";
|
|
//echo $sql;
|
|
$query = $this->db_onedev->query($sql, array($q['search']));
|
|
|
|
if ($query) {
|
|
$rows = $query->result_array();
|
|
array_push($rows, array('id' => 0, 'name' => 'Semua'));
|
|
//echo $this->db_onedev->last_query();
|
|
$result = array("total" => $tot_count, "records" => $rows, "total_display" => sizeof($rows));
|
|
$this->sys_ok($result);
|
|
} else {
|
|
$this->sys_error_db("m_company rows", $this->db_onedev);
|
|
exit;
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
function searchtest()
|
|
{
|
|
if (!$this->isLogin) {
|
|
$this->sys_error("Invalid Token");
|
|
exit;
|
|
}
|
|
$prm = $this->sys_input;
|
|
|
|
$max_rst = 12;
|
|
$tot_count = 0;
|
|
|
|
$q = [
|
|
'search' => '%'
|
|
];
|
|
|
|
if ($prm['search'] == '') {
|
|
|
|
$rows = array(array('id' => 0, 'name' => 'Semua'));
|
|
$result = array("total" => 1, "records" => $rows, "total_display" => sizeof($rows));
|
|
$this->sys_ok($result);
|
|
} else {
|
|
$q['search'] = "%{$prm['search']}%";
|
|
$sql = "
|
|
SELECT Nat_TestID as id, Nat_TestCode as code,Nat_TestName as name
|
|
FROM nat_test
|
|
WHERE
|
|
Nat_TestName like ?
|
|
AND Nat_TestIsActive = 'Y' AND Nat_TestIsPrice = 'Y' AND Nat_TestIsPrintNota = 'Y'
|
|
ORDER BY Nat_TestCode ASC, Nat_TestName DESC
|
|
|
|
";
|
|
//echo $sql;
|
|
$query = $this->db_onedev->query($sql, array($q['search']));
|
|
|
|
if ($query) {
|
|
$rows = $query->result_array();
|
|
array_push($rows, array('id' => 0, 'name' => 'Semua'));
|
|
//echo $this->db_onedev->last_query();
|
|
$result = array("total" => $tot_count, "records" => $rows, "total_display" => sizeof($rows));
|
|
$this->sys_ok($result);
|
|
} else {
|
|
$this->sys_error_db("nat_test rows", $this->db_onedev);
|
|
exit;
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
function removefile()
|
|
{
|
|
if (!$this->isLogin) {
|
|
$this->sys_error("Invalid Token");
|
|
exit;
|
|
}
|
|
|
|
//# ambil parameter input
|
|
$xuserid = $this->sys_user['M_UserID'];
|
|
$prm = $this->sys_input;
|
|
|
|
$sql = "
|
|
UPDATE file_attachment SET File_AttachmentIsActive = 'N', File_AttachmentDeleted = NOW(), File_AttachmentDeletedUserID = ?
|
|
WHERE
|
|
File_AttachmentID = ?
|
|
";
|
|
//echo $sql;
|
|
$query = $this->db_onedev->query($sql,[$xuserid, $prm['fid']]);
|
|
if (!$query) {
|
|
$this->sys_error_db("file_attachment delete");
|
|
exit;
|
|
}
|
|
|
|
$result = array(
|
|
"total" => 1,
|
|
"records" => 'sipp'
|
|
);
|
|
$this->sys_ok($result);
|
|
exit;
|
|
}
|
|
|
|
|
|
function lookup_promises()
|
|
{
|
|
if (!$this->isLogin) {
|
|
$this->sys_error("Invalid Token");
|
|
exit;
|
|
}
|
|
|
|
//# ambil parameter input
|
|
$xuserid = $this->sys_user['M_UserID'];
|
|
$prm = $this->sys_input;
|
|
|
|
$sql = "
|
|
SELECT T_OrderPromiseID as id,
|
|
DATE_FORMAT(T_OrderPromiseDateTime,'%d%m%Y') as xdate,
|
|
TIME_FORMAT(T_OrderPromiseDateTime,'%H%i') as xtime,
|
|
GROUP_CONCAT(T_TestName SEPARATOR ' , ') as tests
|
|
FROM t_orderdetail
|
|
JOIN t_orderpromise ON T_OrderDetailT_OrderPromiseID = T_OrderPromiseID
|
|
JOIN t_test ON T_OrderDetailT_TestID = T_TestID
|
|
WHERE
|
|
T_OrderDetailT_OrderHeaderID = {$prm['T_OrderHeaderID']} AND T_OrderDetailIsActive = 'Y'
|
|
GROUP BY T_OrderPromiseID
|
|
";
|
|
//echo $sql;
|
|
$query = $this->db_onedev->query($sql)->result_array();
|
|
if (!$query) {
|
|
$this->sys_error_db("f_paymentdetail delete");
|
|
exit;
|
|
}
|
|
|
|
$result = array(
|
|
"total" => 1,
|
|
"records" => $query
|
|
);
|
|
$this->sys_ok($result);
|
|
exit;
|
|
}
|
|
|
|
function get_data_result_log()
|
|
{
|
|
if (!$this->isLogin) {
|
|
$this->sys_error("Invalid Token");
|
|
exit;
|
|
}
|
|
|
|
//# ambil parameter input
|
|
$prm = $this->sys_input;
|
|
if($prm['isNonLab'] == 'N'){
|
|
$sql = "SELECT api_ResultID as xid,
|
|
DATE_FORMAT(api_ResultCreated,'%d-%m-%Y %H:%i') as log_date,
|
|
api_ResultVerificationUser as verification_user,
|
|
DATE_FORMAT(api_ResultVerificationDate,'%d-%m-%Y %H:%i') as verification_date,
|
|
DATE_FORMAT(api_ResultAuthorizationDate,'%d-%m-%Y %H:%i') as authorization_date,
|
|
api_ResultVerificationUser as verification_user,
|
|
api_ResultAuthorizationUser as authorization_user
|
|
FROM api_result
|
|
WHERE
|
|
api_ResultT_OrderDetailID = {$prm['xid']}
|
|
GROUP BY api_ResultID
|
|
ORDER BY api_ResultCreated
|
|
";
|
|
}else{
|
|
$exc_test = [6247, 6254, 6288, 10996, 6245];
|
|
if(!in_array(intval($prm['nt_id']),$exc_test)){
|
|
$sql = "SELECT So_REActionLogID as xid,
|
|
DATE_FORMAT(So_REActionLogDate,'%d-%m-%Y %H:%i') as log_date,
|
|
So_REActionLogAction as act,
|
|
IFNULL(re_staff.M_StaffName,'User tidak ditemukan') as re_user
|
|
FROM so_reactionlog
|
|
JOIN so_resultentry ON So_REActionLogSo_ResultEntryID = So_ResultEntryID AND
|
|
So_ResultEntryISActive = 'Y' AND
|
|
So_ResultEntryT_OrderDetailID = {$prm['xid']}
|
|
JOIN m_user re_user ON So_REActionLogUserID = re_user.M_UserID
|
|
JOIN m_staff re_staff ON re_user.M_UserM_StaffID = re_staff.M_StaffID
|
|
ORDER BY So_REActionLogDate ASC
|
|
|
|
";
|
|
}else{
|
|
$inc_fisik = [6254,6288];
|
|
if(in_array(intval($prm['nt_id']),$inc_fisik)){
|
|
$sql = "SELECT So_REActionLogID as xid,
|
|
DATE_FORMAT(So_REActionLogDate,'%d-%m-%Y %H:%i') as log_date,
|
|
So_REActionLogAction as act,
|
|
IFNULL(re_staff.M_StaffName,'User tidak ditemukan') as re_user
|
|
FROM so_resultentry
|
|
JOIN so_reactionlog ON So_REActionLogSo_ResultEntryID = So_ResultEntryID AND
|
|
So_ResultEntryISActive = 'Y' AND
|
|
JOIN m_user re_user ON So_REActionLogUserID = re_user.M_UserID
|
|
JOIN m_staff re_staff ON re_user.M_UserM_StaffID = re_staff.M_StaffID
|
|
WHERE
|
|
So_ResultEntryNonlab_TemplateID = 27 AND
|
|
So_ResultEntryT_OrderHeaderID = {$prm['h_id']} AND
|
|
So_ResultEntryIsActive = 'Y'";
|
|
}else{
|
|
$sql = "SELECT T_SamplingSoID as xid,
|
|
DATE_FORMAT(CONCAT(T_SamplingSoDoneDate,' ',T_SamplingSoDoneTime),'%d-%m-%Y %H:%i') as log_date,
|
|
'INSERT' as act,
|
|
IFNULL(re_staff.M_StaffName,'User tidak ditemukan') as re_user
|
|
FROM t_samplingso
|
|
JOIN t_orderdetail ON T_OrderDetailID = {$prm['xid']} AND
|
|
T_SamplingSoT_OrderHeaderID = T_OrderDetailT_OrderHeaderID AND
|
|
T_OrderDetailT_TestID = T_SamplingSoT_TestID AND T_OrderDetailIsActive = 'Y'
|
|
JOIN m_user re_user ON T_SamplingSoDoneUserID = re_user.M_UserID
|
|
JOIN m_staff re_staff ON re_user.M_UserM_StaffID = re_staff.M_StaffID";
|
|
|
|
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
|
|
//echo $sql;
|
|
$query = $this->db_onedev->query($sql);
|
|
|
|
if (!$query) {
|
|
$this->sys_error_db("get data activity delete");
|
|
exit;
|
|
}
|
|
|
|
$rst = $query->result_array();
|
|
|
|
$result = array(
|
|
"total" => 1,
|
|
"records" => $rst
|
|
);
|
|
$this->sys_ok($result);
|
|
exit;
|
|
}
|
|
|
|
function get_resume_individu_log()
|
|
{
|
|
if (!$this->isLogin) {
|
|
$this->sys_error("Invalid Token");
|
|
exit;
|
|
}
|
|
|
|
//# ambil parameter input
|
|
$prm = $this->sys_input;
|
|
$sql = "SELECT log_Mcu_ResumeID as xid,
|
|
log_Mcu_ResumeType as act,
|
|
DATE_FORMAT(log_Mcu_ResumeCreated,'%d-%m-%Y %H:%i') as log_date,
|
|
IFNULL(re_staff.M_StaffName,'User tidak ditemukan') as re_user
|
|
FROM cpone_log.log_mcu_resume
|
|
JOIN mcu_resume ON log_Mcu_ResumeMcu_ResumeID = Mcu_ResumeID AND
|
|
Mcu_ResumeT_OrderHeaderID = {$prm['T_OrderHeaderID']} AND
|
|
Mcu_ResumeIsActive = 'Y'
|
|
JOIN m_user re_user ON log_Mcu_ResumeUserID = re_user.M_UserID
|
|
JOIN m_staff re_staff ON re_user.M_UserM_StaffID = re_staff.M_StaffID
|
|
ORDER BY log_Mcu_ResumeCreated ASC";
|
|
|
|
//echo $sql;
|
|
$query = $this->db_onedev->query($sql);
|
|
|
|
if (!$query) {
|
|
$this->sys_error_db("get data activity delete");
|
|
exit;
|
|
}
|
|
|
|
$rst = $query->result_array();
|
|
|
|
$result = array(
|
|
"total" => 1,
|
|
"records" => $rst
|
|
);
|
|
$this->sys_ok($result);
|
|
exit;
|
|
}
|
|
|
|
function get_detail_tests(){
|
|
if (!$this->isLogin) {
|
|
$this->sys_error("Invalid Token");
|
|
exit;
|
|
}
|
|
|
|
//# ambil parameter input
|
|
$xuserid = $this->sys_user['M_UserID'];
|
|
$prm = $this->sys_input;
|
|
|
|
$sql = "SELECT T_OrderDetailT_OrderHeaderID as h_id,
|
|
T_OrderDetailID as xid,
|
|
T_TestNat_TestID as nt_id,
|
|
T_OrderDetailT_TestName as t_name,
|
|
T_OrderDetailT_TestSasCode as t_code,
|
|
Group_ResultFlagNonLab as isNonLab,
|
|
T_TestIsResult as isResult,
|
|
IF(T_OrderDetailResult IS NULL,'X','VAL1') as status,
|
|
DATE_FORMAT(T_OrderDetailLastUpdated, '%d-%m-%Y %H:%i') as last_updated,
|
|
'' as last_user
|
|
FROM t_orderdetail
|
|
JOIN t_test ON T_OrderDetailT_TestID = T_TestID
|
|
JOIN nat_test ON T_TestNat_TestID = Nat_TestID
|
|
JOIN group_resultdetail ON Group_ResultDetailT_TestID = T_OrderDetailT_TestID AND
|
|
T_OrderDetailT_OrderHeaderID = ? AND T_OrderDetailIsActive = 'Y'
|
|
JOIN group_result ON Group_ResultDetailGroup_ResultID = Group_ResultID
|
|
GROUP BY T_OrderDetailID
|
|
ORDER BY T_TestSasCode
|
|
";
|
|
//echo $sql;
|
|
$query = $this->db_onedev->query($sql,[$prm['T_OrderHeaderID']]);
|
|
if (!$query) {
|
|
$this->sys_error_db("t_orderdetail");
|
|
exit;
|
|
}
|
|
|
|
//echo $this->db_onedev->last_query();
|
|
|
|
$dt_result = $query->result_array();
|
|
foreach ($dt_result as $key => $value) {
|
|
if($value['isNonLab'] == 'N'){
|
|
|
|
$sql = "SELECT COUNT(*) as xcount
|
|
FROM api_result
|
|
WHERE
|
|
api_ResultT_OrderDetailID = ?";
|
|
$query = $this->db_onedev->query($sql,array($value['xid']));
|
|
$xcount = $query->row()->xcount;
|
|
$dt_result[$key]['status'] = 'NEW';
|
|
$dt_result[$key]['last_user'] = '';
|
|
$dt_result[$key]['last_updated'] = '';
|
|
if($xcount > 0){
|
|
$dt_result[$key]['status'] = 'VAL1';
|
|
$dt_result[$key]['last_user'] = 'Bridging LIS';
|
|
$dt_result[$key]['last_updated'] = $value['last_updated'];
|
|
}
|
|
}
|
|
else if($value['isNonLab'] == 'Y'){
|
|
$sql = "SELECT IF(So_ResultEntryStatus IS NULL,'X', IF(So_REActionLogID IS NULL, 'X',So_ResultEntryStatus)) AS status,
|
|
IFNULL(T_SamplingSoID,0) as sa_id,
|
|
DATE_FORMAT(So_ResultEntryLastUpdated, '%d-%m-%Y %H:%i') as last_updated,
|
|
DATE_FORMAT(CONCAT(T_SamplingSoDoneDate,' ',T_SamplingSoDoneTime),'%d-%m-%Y %H:%i') as sampling_date,
|
|
IFNULL(sampling_staff.M_StaffName,'') as sampling_user,
|
|
IFNULL(re_staff.M_StaffName,'') as re_user
|
|
FROM t_orderdetail
|
|
JOIN t_orderheader ON
|
|
T_OrderDetailID = ? AND
|
|
T_OrderDetailT_OrderHeaderID = T_OrderHeaderID AND
|
|
T_OrderDetailT_TestIsResult = 'Y' AND
|
|
T_OrderDetailIsActive = 'Y'
|
|
LEFT JOIN t_samplingso ON
|
|
T_SamplingSoT_OrderHeaderID = T_OrderHeaderID AND
|
|
T_SamplingSoT_TestID = T_OrderDetailT_TestID AND
|
|
T_SamplingSoIsActive = 'Y'
|
|
LEFT JOIN m_user sampling_user ON T_SamplingSoLastUpdatedUserID = sampling_user.M_UserID
|
|
LEFT JOIN m_staff sampling_staff ON sampling_user.M_UserM_StaffID = sampling_staff.M_StaffID
|
|
LEFT JOIN so_resultentry ON
|
|
So_ResultEntryT_OrderDetailID = T_OrderDetailID AND So_ResultEntryIsActive = 'Y'
|
|
LEFT JOIN m_user re_user ON T_SamplingSoLastUpdatedUserID = re_user.M_UserID
|
|
LEFT JOIN m_staff re_staff ON re_user.M_UserM_StaffID = re_staff.M_StaffID
|
|
LEFT JOIN so_reactionlog ON So_REActionLogSo_ResultEntryID = So_ResultEntryID
|
|
LIMIT 1";
|
|
$query = $this->db_onedev->query($sql,array($value['xid']));
|
|
$dt_status = $query->result_array();
|
|
|
|
$dt_result[$key]['status'] = 'X';
|
|
if(count($dt_status) > 0){
|
|
$dt_result[$key]['last_user'] = $dt_status[0]['re_user'];
|
|
$dt_result[$key]['status'] = $dt_status[0]['status'];
|
|
$dt_result[$key]['last_updated'] = $dt_status[0]['last_updated'];
|
|
$exc_test = [6247, 6254, 6288, 10996, 6245];
|
|
if(in_array(intval($value['nt_id']),$exc_test)){
|
|
$dt_result[$key]['last_user'] = $dt_status[0]['sampling_user'];
|
|
$dt_result[$key]['last_updated'] = '';
|
|
if(intval($dt_status[0]['sa_id']) == 0)
|
|
$dt_result[$key]['status'] = 'X';
|
|
else{
|
|
$dt_result[$key]['status'] = 'VAL1';
|
|
$dt_result[$key]['last_updated'] = $dt_status[0]['sampling_date'];
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
$result = array(
|
|
"records" => $dt_result
|
|
);
|
|
$this->sys_ok($result);
|
|
exit;
|
|
}
|
|
|
|
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_SampleTypeID,
|
|
T_BarcodeLabID,
|
|
T_BarcodeLabBarcode,
|
|
T_BarcodeLabT_OrderHeaderID as orderid,
|
|
T_BarcodeLabCounter,
|
|
T_SampleTypeName,
|
|
'N' as chex
|
|
FROM t_barcodelab
|
|
JOIN t_sampletype ON T_BarcodeLabT_SampleTypeID = T_SampleTypeID
|
|
JOIN t_bahan ON T_SampleTypeT_BahanID = T_BahanID
|
|
JOIN t_samplestation ON T_BahanT_SampleStationID = T_SampleStationID AND T_SampleStationIsNonLab = ''
|
|
WHERE
|
|
T_BarcodeLabT_OrderHeaderID = {$prm['T_OrderHeaderID']} AND T_BarcodeLabIsActive = 'Y'
|
|
UNION
|
|
SELECT T_OrderHeaderID as id, 'formulir' as type, 0 as T_SampleTypeID,0 as T_BarcodeLabID,T_OrderHeaderLabNumber as T_BarcodeLabBarcode,{$prm['T_OrderHeaderID']}, 1, 'Formulir' as T_SampleTypeName, 'N' as chex
|
|
FROM t_orderheader
|
|
WHERE
|
|
T_OrderHeaderID = {$prm['T_OrderHeaderID']}
|
|
UNION
|
|
SELECT T_TestID as id,
|
|
'nonlab' as type,
|
|
T_OrderDetailID as detail_id,
|
|
'' as xxx,
|
|
'-' as T_BarcodeLabBarcode,
|
|
T_OrderHeaderID as order_id,
|
|
DATE_FORMAT(T_OrderHeaderDate,'%d-%m-%Y') as order_date,
|
|
T_TestName as T_SampleTypeName,
|
|
'N' as chex
|
|
FROM t_orderheader
|
|
JOIN t_orderdetail ON T_OrderDetailT_OrderHeaderID = T_OrderHeaderID AND T_OrderDetailIsActive = 'Y'
|
|
JOIN t_test ON T_OrderDetailT_TestID = T_TestID AND T_TestIsResult = 'Y'
|
|
JOIN group_resultdetail ON Group_ResultDetailT_TestID = T_TestID
|
|
JOIN group_result ON Group_ResultDetailGroup_ResultID = Group_ResultID AND Group_ResultName <> 'lab'
|
|
WHERE
|
|
T_OrderHeaderID = {$prm['T_OrderHeaderID']}
|
|
GROUP BY T_TestID
|
|
UNION
|
|
SELECT T_OrderDetailID as id,
|
|
'nonlab_group' as type,
|
|
T_OrderDetailID as detail_id,
|
|
'' as xxx,
|
|
GROUP_CONCAT(T_TestName separator ' , ') as T_BarcodeLabBarcode,
|
|
T_OrderHeaderID as order_id,
|
|
DATE_FORMAT(T_OrderHeaderDate,'%d-%m-%Y') as order_date,
|
|
'Amplop Besar' as T_SampleTypeName,
|
|
'N' as chex
|
|
FROM t_orderheader
|
|
JOIN t_orderdetail ON T_OrderDetailT_OrderHeaderID = T_OrderHeaderID AND T_OrderDetailIsActive = 'Y'
|
|
JOIN t_test ON T_OrderDetailT_TestID = T_TestID AND T_TestIsResult = 'Y'
|
|
JOIN group_resultdetail ON Group_ResultDetailT_TestID = T_TestID
|
|
JOIN group_result ON Group_ResultDetailGroup_ResultID = Group_ResultID AND Group_ResultName<> 'lab'
|
|
WHERE
|
|
T_OrderHeaderID = {$prm['T_OrderHeaderID']}
|
|
GROUP BY T_OrderHeaderID
|
|
";*/
|
|
$sql = "SELECT T_BarcodeLabID as id,
|
|
'barcode' as type,
|
|
T_SampleTypeID,
|
|
T_BarcodeLabID,
|
|
T_BarcodeLabBarcode,
|
|
T_BarcodeLabT_OrderHeaderID as orderid,
|
|
T_BarcodeLabCounter,
|
|
T_SampleTypeName,
|
|
'N' as chex
|
|
FROM t_barcodelab
|
|
JOIN t_sampletype ON T_BarcodeLabT_SampleTypeID = T_SampleTypeID
|
|
JOIN t_bahan ON T_SampleTypeT_BahanID = T_BahanID
|
|
JOIN t_samplestation ON T_BahanT_SampleStationID = T_SampleStationID AND T_SampleStationIsNonLab = ''
|
|
WHERE
|
|
T_BarcodeLabT_OrderHeaderID = {$prm['T_OrderHeaderID']} AND T_BarcodeLabIsActive = 'Y'
|
|
UNION
|
|
SELECT T_TestID as id,
|
|
'nonlab' as type,
|
|
T_OrderDetailID as T_SampleTypeID,
|
|
'' as T_BarcodeLabID,
|
|
'-' as T_BarcodeLabBarcode,
|
|
T_OrderHeaderID as order_id,
|
|
0 as T_BarcodeLabCounter,
|
|
T_TestName as T_SampleTypeName,
|
|
'N' as chex
|
|
FROM t_orderheader
|
|
JOIN t_orderdetail ON T_OrderDetailT_OrderHeaderID = T_OrderHeaderID AND T_OrderDetailIsActive = 'Y'
|
|
JOIN t_test ON T_OrderDetailT_TestID = T_TestID AND T_TestIsResult = 'Y'
|
|
JOIN group_resultdetail ON Group_ResultDetailT_TestID = T_TestID
|
|
JOIN group_result ON Group_ResultDetailGroup_ResultID = Group_ResultID AND Group_ResultName <> 'lab'
|
|
WHERE
|
|
T_OrderHeaderID = {$prm['T_OrderHeaderID']}
|
|
GROUP BY T_TestID
|
|
|
|
";
|
|
//echo $sql;
|
|
$query = $this->db_onedev->query($sql);
|
|
if (!$query) {
|
|
$message = $this->db_onedev->error();
|
|
$message['qry'] = $this->db_onedev->last_query();
|
|
$this->sys_error($message);
|
|
exit;
|
|
}
|
|
$rows = $query->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 getdatadob()
|
|
{
|
|
try {
|
|
$prm = $this->sys_input;
|
|
//# cek token valid
|
|
if (!$this->isLogin) {
|
|
$this->sys_error("Invalid Token");
|
|
exit;
|
|
}
|
|
|
|
$status = 'N';
|
|
$sql = "SELECT COUNT(*) as xcount
|
|
FROM t_ordersample
|
|
WHERE
|
|
T_OrderSampleT_OrderHeaderID = {$prm['T_OrderHeaderID']} AND
|
|
T_OrderSampleReceive = 'Y' AND
|
|
T_OrderSampleIsActive = 'Y'";
|
|
$c_sampling = $this->db_onedev->query($sql)->row()->xcount;
|
|
if ($c_sampling > 0) {
|
|
$status = 'Y';
|
|
}
|
|
$sql = "SELECT m_patient.*, DATE_FORMAT(M_PatientDOB,'%d-%m-%Y') as dob
|
|
FROM m_patient
|
|
WHERE
|
|
M_PatientNoReg = '{$prm['M_PatientNoReg']}'";
|
|
//echo $sql;
|
|
$row = $this->db_onedev->query($sql)->row_array();
|
|
$result = array("total" => 0, "records" => $row, "status" => $status);
|
|
$this->sys_ok($result);
|
|
} catch (Exception $exc) {
|
|
$message = $exc->getMessage();
|
|
$this->sys_error($message);
|
|
}
|
|
}
|
|
function getbranch()
|
|
{
|
|
$prm = $this->sys_input;
|
|
//# cek token valid
|
|
if (!$this->isLogin) {
|
|
$this->sys_error("Invalid Token");
|
|
exit;
|
|
}
|
|
$sql = "SELECT '0' as id, '0' as code, 'Semua' as name
|
|
UNION
|
|
SELECT
|
|
M_BranchID as id,
|
|
M_BranchCode as code,
|
|
M_BranchName as name
|
|
FROM m_branch
|
|
WHERE M_BranchIsActive = 'Y'";
|
|
$row = $this->db_onedev->query($sql)->result_array();
|
|
$result = array("total" => 0, "records" => $row,);
|
|
$this->sys_ok($result);
|
|
}
|
|
|
|
function save_promises()
|
|
{
|
|
if (!$this->isLogin) {
|
|
$this->sys_error("Invalid Token");
|
|
exit;
|
|
}
|
|
|
|
//# ambil parameter input
|
|
$xuserid = $this->sys_user['M_UserID'];
|
|
$prm = $this->sys_input;
|
|
$sql = "SELECT * FROM t_orderpromise WHERE T_OrderPromiseT_OrderHeaderID = '{$prm['data']['T_OrderHeaderID']}' AND T_OrderPromiseIsActive = 'Y'";
|
|
$promiseold = $this->db_onedev->query($sql)->result_array();
|
|
//echo $sql;
|
|
//print_r($prm['data']['bahan_belum']);
|
|
foreach ($prm['data']['bahan_belum'] as $k => $v) {
|
|
if (intval($v['T_TestID']) == 0) {
|
|
$sampletype = array_unique(explode('^', $v['T_SampleTypeID']));
|
|
//print_r($sampletype);
|
|
foreach ($sampletype as $k_sample => $v_sample) {
|
|
$sql = "SELECT *
|
|
FROM t_orderdetail
|
|
JOIN t_ordersample ON T_OrderDetailT_OrderHeaderID = T_OrderSampleT_OrderHeaderID AND
|
|
T_OrderSampleIsActive = 'Y' AND
|
|
T_OrderSampleT_SampleTypeID = {$v_sample}
|
|
JOIN t_test ON T_OrderDetailT_TestID = T_TestID AND T_OrderSampleT_SampleTypeID = T_TestT_SampleTypeID
|
|
WHERE
|
|
T_OrderDetailT_OrderHeaderID = {$prm['data']['T_OrderHeaderID']} AND
|
|
T_OrderDetailIsActive = 'Y'
|
|
";
|
|
//echo $sql;
|
|
$r_sample_nas = $this->db_onedev->query($sql)->result_array();
|
|
if ($r_sample_nas) {
|
|
foreach ($r_sample_nas as $k_sample_nas => $v_sample_nas) {
|
|
$sql = "UPDATE t_orderdetail SET T_OrderDetailT_OrderPromiseID = 0
|
|
WHERE
|
|
T_OrderDetailID = {$v_sample_nas['T_OrderDetailID']}";
|
|
$this->db_onedev->query($sql);
|
|
$sql = " SELECT *
|
|
FROM t_orderdetail
|
|
WHERE
|
|
T_OrderDetailT_OrderHeaderID = {$prm['data']['T_OrderHeaderID']} AND
|
|
T_OrderDetailT_TestSasCode = LEFT('{$v_sample_nas['T_OrderDetailT_TestSasCode']}', LENGTH('{$v_sample_nas['T_OrderDetailT_TestSasCode']}') - 2) AND
|
|
T_OrderDetailIsActive = 'Y'";
|
|
//echo $sql;
|
|
$parent_x = $this->db_onedev->query($sql)->row_array();
|
|
$sql = "UPDATE t_orderdetail SET T_OrderDetailT_OrderPromiseID = 0
|
|
WHERE
|
|
T_OrderDetailID = {$parent_x['T_OrderDetailID']}";
|
|
$this->db_onedev->query($sql);
|
|
}
|
|
}
|
|
$sql = "SELECT *
|
|
FROM t_orderdetail
|
|
JOIN t_ordersample ON T_OrderDetailT_OrderHeaderID = T_OrderSampleT_OrderHeaderID AND
|
|
T_OrderSampleIsActive = 'Y' AND
|
|
T_OrderSampleT_SampleTypeID = {$v_sample}
|
|
JOIN t_specimenlocal ON T_SpecimenLocalT_SampleTypeID = T_OrderSampleT_SampleTypeID
|
|
JOIN t_test ON T_SpecimenLocalNat_TestID = T_TestNat_TestID AND
|
|
T_OrderDetailT_TestID = T_TestID
|
|
WHERE
|
|
T_OrderDetailT_OrderHeaderID = {$prm['data']['T_OrderHeaderID']} AND
|
|
T_OrderDetailIsActive = 'Y'
|
|
";
|
|
$r_sample_local = $this->db_onedev->query($sql)->result_array();
|
|
if ($r_sample_local) {
|
|
foreach ($r_sample_local as $k_sample_local => $v_sample_local) {
|
|
$sql = "UPDATE t_orderdetail SET T_OrderDetailT_OrderPromiseID = 0
|
|
WHERE
|
|
T_OrderDetailID = {$v_sample_local['T_OrderDetailID']}";
|
|
$this->db_onedev->query($sql);
|
|
$sql = " SELECT *
|
|
FROM t_orderdetail
|
|
WHERE
|
|
T_OrderDetailT_OrderHeaderID = {$prm['data']['T_OrderHeaderID']} AND
|
|
T_OrderDetailT_TestSasCode = LEFT('{$v_sample_local['T_OrderDetailT_TestSasCode']}', LENGTH('{$v_sample_local['T_OrderDetailT_TestSasCode']}') - 2) AND
|
|
T_OrderDetailIsActive = 'Y'";
|
|
$parent_y = $this->db_onedev->query($sql)->row_array();
|
|
$sql = "UPDATE t_orderdetail SET T_OrderDetailT_OrderPromiseID = 0
|
|
WHERE
|
|
T_OrderDetailID = {$parent_y['T_OrderDetailID']}";
|
|
$this->db_onedev->query($sql);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
if (intval($v['T_SampleTypeID']) == 0) {
|
|
$sql = "UPDATE t_orderdetail
|
|
SET T_OrderDetailT_OrderPromiseID = 0
|
|
WHERE
|
|
T_OrderDetailT_TestID = {$v['T_TestID']} AND
|
|
T_OrderDetailT_OrderHeaderID = {$prm['data']['T_OrderHeaderID']} AND
|
|
T_OrderDetailIsActive = 'Y'
|
|
";
|
|
$this->db_onedev->query($sql);
|
|
}
|
|
}
|
|
|
|
$sql = "CALL `sp_fo_schedule_promise_set_v2`('{$prm['data']['T_OrderHeaderID']}')";
|
|
$r_schedule_set = $this->db_onedev->query($sql);
|
|
$this->clean_mysqli_connection($this->db_onedev->conn_id);
|
|
|
|
$sql = "SELECT *
|
|
FROM t_orderpromise
|
|
WHERE
|
|
T_OrderPromiseT_OrderHeaderID = {$prm['data']['T_OrderHeaderID']} AND
|
|
T_OrderPromiseIsActive = 'Y'";
|
|
$promisenew = $this->db_onedev->query($sql)->result_array();
|
|
if ($promisenew && count($promisenew) > 0) {
|
|
foreach ($promisenew as $key_promise => $value_promise) {
|
|
$sql = "SELECT COUNT(*) as xcount
|
|
FROM t_orderdetail
|
|
WHERE
|
|
T_OrderDetailT_OrderPromiseID = {$value_promise['T_OrderPromiseID']} AND
|
|
T_OrderDetailIsActive = 'Y'
|
|
";
|
|
$check_exist_promise_detail = $this->db_onedev->query($sql)->row_array();
|
|
if ($check_exist_promise_detail['xcount'] == 0) {
|
|
$sql = "UPDATE t_orderpromise
|
|
SET T_OrderPromiseIsActive = 'N'
|
|
WHERE
|
|
T_OrderPromiseID = {$value_promise['T_OrderPromiseID']} AND
|
|
T_OrderPromiseIsActive = 'Y'";
|
|
$this->db_onedev->query($sql);
|
|
}
|
|
}
|
|
}
|
|
|
|
$x_json = json_encode(array('old' => $promiseold, 'new' => $promisenew));
|
|
$sql = "INSERT INTO order_attr (
|
|
orderAttrT_OrderHeaderID,
|
|
orderAttrType,
|
|
orderAttrJson,
|
|
orderAttrUserID
|
|
)
|
|
VALUES(
|
|
{$prm['orderid']},
|
|
'patlist_promise',
|
|
'{$x_json}',
|
|
'{$xuserid}'
|
|
)";
|
|
$this->db_onedev->query($sql);
|
|
|
|
$sql = "UPDATE t_orderheaderaddon
|
|
SET T_OrderHeaderAddonIsComing = 'Y', T_OrderHeaderAddonIsComingDate = NOW()
|
|
WHERE
|
|
T_OrderHeaderAddOnT_OrderHeaderID = {$prm['data']['T_OrderHeaderID']} AND
|
|
T_OrderHeaderAddOnIsActive = 'Y'";
|
|
$this->db_onedev->query($sql);
|
|
|
|
$result = array(
|
|
"total" => 1,
|
|
"records" => $prm
|
|
);
|
|
$this->sys_ok($result);
|
|
exit;
|
|
}
|
|
|
|
|
|
function updatedob()
|
|
{
|
|
if (!$this->isLogin) {
|
|
$this->sys_error("Invalid Token");
|
|
exit;
|
|
}
|
|
|
|
//# ambil parameter input
|
|
$xuserid = $this->sys_user['M_UserID'];
|
|
$prm = $this->sys_input;
|
|
$x_dob = $prm['dob'];
|
|
//$x_dob = str_replace("-","",$x_dob);
|
|
$updated_dob = substr($x_dob, 0, 2) . '-' . substr($x_dob, 2, 2) . '-' . substr($x_dob, 4, 4);
|
|
$xxdob = date("Y-m-d", strtotime($updated_dob));
|
|
|
|
$sql = "SELECT * FROM m_patient WHERE M_PatientID = {$prm['M_PatientID']}";
|
|
$old_patient = $this->db_onedev->query($sql)->row_array();
|
|
|
|
$old_dob = date("Y-m-d", strtotime($old_patient['M_PatientDOB']));
|
|
$x_json = json_encode(
|
|
array(
|
|
'old' => array('id' => $old_patient['M_PatientID'], 'name' => $old_dob),
|
|
'new' => array('id' => $prm['M_PatientID'], 'name' => $xxdob)
|
|
)
|
|
);
|
|
|
|
if ($prm['status'] == 'N') {
|
|
$sql = "UPDATE m_patient SET M_PatientDOB = '{$xxdob}'
|
|
WHERE
|
|
M_PatientID = {$prm['M_PatientID']}";
|
|
//echo $sql;
|
|
$this->db_onedev->query($sql);
|
|
|
|
$sql = "CALL sp_recount_age({$prm['orderid']})";
|
|
//echo $sql;
|
|
$this->db_onedev->query($sql);
|
|
|
|
$log_attr_type = 'change_dob';
|
|
} else {
|
|
$sql = "UPDATE m_patient SET M_PatientDOB = '{$xxdob}'
|
|
WHERE
|
|
M_PatientID = {$prm['M_PatientID']}";
|
|
//echo $sql;
|
|
$this->db_onedev->query($sql);
|
|
$sql = "UPDATE t_orderheaderaddon SET
|
|
T_OrderHeaderAddOnRequestDOB = '{$xxdob}',
|
|
T_OrderHeaderAddOnRequestChangeDOB = '{$prm['status']}'
|
|
WHERE
|
|
T_OrderHeaderAddOnT_OrderHeaderID = {$prm['orderid']}";
|
|
//echo $sql;
|
|
$this->db_onedev->query($sql);
|
|
|
|
$log_attr_type = 'req_change_dob';
|
|
}
|
|
|
|
$sql = "INSERT INTO order_attr (
|
|
orderAttrT_OrderHeaderID,
|
|
orderAttrType,
|
|
orderAttrJson,
|
|
orderAttrUserID
|
|
)
|
|
VALUES(
|
|
{$prm['orderid']},
|
|
'{$log_attr_type}',
|
|
'{$x_json}',
|
|
'{$xuserid}'
|
|
)";
|
|
//echo $sql;
|
|
$this->db_onedev->query($sql);
|
|
|
|
$result = array(
|
|
"total" => 1,
|
|
"records" => $prm
|
|
);
|
|
$this->sys_ok($result);
|
|
exit;
|
|
}
|
|
|
|
|
|
function gettimelinedelivery()
|
|
{
|
|
if (!$this->isLogin) {
|
|
$this->sys_error("Invalid Token");
|
|
exit;
|
|
}
|
|
|
|
|
|
//# ambil parameter input
|
|
$xuserid = $this->sys_user['M_UserID'];
|
|
$prm = $this->sys_input;
|
|
|
|
$sql = "
|
|
SELECT * FROM (
|
|
SELECT CONCAT('dibuat spk : ',Result_CourierSPKNumbering) as status,
|
|
DATE_FORMAT(Result_CourierDetailStepByStepLastUpdated,'%d.%m.%Y %H:%i') as xtime,
|
|
M_UserUsername as username,
|
|
'' as xperson,
|
|
'' as xnote,
|
|
Result_CourierSPKDetailID as xid
|
|
FROM result_courierspk_detail_step_by_step
|
|
JOIN result_courierspk_detail ON Result_CourierDetailStepByStepResult_CourierSPKDetailID = Result_CourierSPKDetailID
|
|
JOIN result_courierspk ON Result_CourierSPKDetailResult_CourierSPKID = Result_CourierSPKID
|
|
JOIN m_user ON Result_CourierDetailStepByStepUserID = M_UserID
|
|
WHERE
|
|
Result_CourierSPKDetailT_OrderDeliveryID = {$prm['xid']} AND
|
|
Result_CourierDetailStepByStepStatus = 'N'
|
|
UNION
|
|
SELECT CONCAT('dikonfirmasi spv : ',Result_CourierSPKNumbering) as status,
|
|
DATE_FORMAT(Result_CourierDetailStepByStepLastUpdated,'%d.%m.%Y %H:%i') as xtime,
|
|
M_UserUsername as username,
|
|
'' as xperson,
|
|
'' as xnote,
|
|
Result_CourierSPKDetailID as xid
|
|
FROM result_courierspk_detail_step_by_step
|
|
JOIN result_courierspk_detail ON Result_CourierDetailStepByStepResult_CourierSPKDetailID = Result_CourierSPKDetailID
|
|
JOIN result_courierspk ON Result_CourierSPKDetailResult_CourierSPKID = Result_CourierSPKID
|
|
JOIN m_user ON Result_CourierDetailStepByStepUserID = M_UserID
|
|
WHERE
|
|
Result_CourierSPKDetailT_OrderDeliveryID = {$prm['xid']} AND
|
|
Result_CourierDetailStepByStepStatus = 'O'
|
|
UNION
|
|
SELECT 'dikonfirmasi spv' as status,
|
|
DATE_FORMAT(Result_CourierDetailStepByStepLastUpdated,'%d.%m.%Y %H%i') as xtime,
|
|
M_UserUsername as username,
|
|
'' as xperson,
|
|
'' as xnote,
|
|
Result_CourierSPKDetailID as xid
|
|
FROM result_courierspk_detail_step_by_step
|
|
JOIN result_courierspk_detail ON Result_CourierDetailStepByStepResult_CourierSPKDetailID = Result_CourierSPKDetailID
|
|
JOIN result_courierspk ON Result_CourierSPKDetailResult_CourierSPKID = Result_CourierSPKID
|
|
JOIN m_user ON Result_CourierDetailStepByStepUserID = M_UserID
|
|
WHERE
|
|
Result_CourierSPKDetailT_OrderDeliveryID = {$prm['xid']} AND
|
|
Result_CourierDetailStepByStepStatus = 'X'
|
|
UNION
|
|
SELECT CONCAT('diserahkan ke kurir : ',Result_CourierSPKNumbering) as status,
|
|
DATE_FORMAT(Result_CourierDetailStepByStepLastUpdated,'%d.%m.%Y %H:%i') as xtime,
|
|
M_UserUsername as username,
|
|
'' as xperson,
|
|
'' as xnote,
|
|
Result_CourierSPKDetailID as xid
|
|
FROM result_courierspk_detail_step_by_step
|
|
JOIN result_courierspk_detail ON Result_CourierDetailStepByStepResult_CourierSPKDetailID = Result_CourierSPKDetailID
|
|
JOIN result_courierspk ON Result_CourierSPKDetailResult_CourierSPKID = Result_CourierSPKID
|
|
JOIN m_user ON Result_CourierDetailStepByStepUserID = M_UserID
|
|
WHERE
|
|
Result_CourierSPKDetailT_OrderDeliveryID = {$prm['xid']} AND
|
|
Result_CourierDetailStepByStepStatus = 'S'
|
|
UNION
|
|
SELECT CONCAT('selesai : ',Result_CourierSPKNumbering) as status,
|
|
DATE_FORMAT(Result_CourierDetailStepByStepLastUpdated,'%d.%m.%Y %H:%i') as xtime,
|
|
M_UserUsername as username,
|
|
Result_CourierComingHomeDetailsReceiver as xperson,
|
|
UPPER(M_CourierStatusReceiveName) as xnote,
|
|
Result_CourierSPKDetailID as xid
|
|
FROM result_courierspk_detail_step_by_step
|
|
JOIN result_courierspk_detail ON Result_CourierDetailStepByStepResult_CourierSPKDetailID = Result_CourierSPKDetailID
|
|
JOIN result_courierspk ON Result_CourierSPKDetailResult_CourierSPKID = Result_CourierSPKID
|
|
JOIN result_couriercominghome_details ON Result_CourierComingHomeDetailsResult_CourierSPKDetailID = Result_CourierSPKDetailID
|
|
JOIN m_user ON Result_CourierDetailStepByStepUserID = M_UserID
|
|
JOIN m_courierstatusreceive ON Result_CourierComingHomeDetailsM_CourierStatusReceiveID = M_CourierStatusReceiveID
|
|
WHERE
|
|
Result_CourierSPKDetailT_OrderDeliveryID = {$prm['xid']} AND
|
|
Result_CourierDetailStepByStepStatus = 'D'
|
|
) x
|
|
GROUP BY xid,status
|
|
ORDER BY xtime ASC
|
|
|
|
";
|
|
//echo $sql;
|
|
$rst = $this->db_onedev->query($sql)->result_array();
|
|
|
|
|
|
$result = array(
|
|
"total" => 1,
|
|
"records" => $rst
|
|
);
|
|
$this->sys_ok($result);
|
|
exit;
|
|
}
|
|
}
|