1998 lines
66 KiB
PHP
1998 lines
66 KiB
PHP
<?php
|
|
|
|
class Sotemplateresultv2 extends MY_Controller
|
|
{
|
|
var $db_onedev;
|
|
public function index()
|
|
{
|
|
echo "SO TEMPLATE RESULT API";
|
|
}
|
|
public function __construct()
|
|
{
|
|
parent::__construct();
|
|
$this->db_onedev = $this->load->database("onedev", true);
|
|
}
|
|
|
|
|
|
public function lookupsovalue()
|
|
{
|
|
try {
|
|
//# 1. Cek Token Valid
|
|
if (! $this->isLogin) {
|
|
$this->sys_error("Invalid Token");
|
|
exit;
|
|
}
|
|
|
|
//# 2. Ambil Parameter
|
|
$prm = $this->sys_input;
|
|
|
|
// Casting ke Integer untuk keamanan (SQL Injection Prevention)
|
|
$idlabel = isset($prm['idlabel']) ? (int)$prm['idlabel'] : 0;
|
|
$idso = isset($prm['idso']) ? (int)$prm['idso'] : 0;
|
|
|
|
// Kita escape lagi menggunakan driver DB agar lebih aman
|
|
// Pastikan variable ini masuk ke string SQL
|
|
$safe_idlabel = $this->db_onedev->escape($idlabel);
|
|
$safe_idso = $this->db_onedev->escape($idso);
|
|
|
|
//# 3. Query Utama
|
|
// Perubahan: Tanda tanya (?) diganti langsung dengan variable $safe_idlabel & $safe_idso
|
|
$sql = "SELECT
|
|
-- Penanda Input
|
|
IF(R.NonlabTemplateResultDetailID IS NULL, 'N', 'Y') as isinput,
|
|
|
|
-- ID Unik Frontend
|
|
IFNULL(R.NonlabTemplateResultDetailID, T.NonlabTemplateDetailID + 999999) as id,
|
|
|
|
-- Alias untuk Frontend
|
|
T.NonlabTemplateDetailID as So_TemplateDetailID,
|
|
|
|
-- LOGIKA BAHASA
|
|
CASE
|
|
WHEN (L.Nat_LangName = 'English' OR L.Nat_LangID = 2) THEN
|
|
IF(T.NonlabTemplateDetailNameEng IS NOT NULL AND T.NonlabTemplateDetailNameEng != '', T.NonlabTemplateDetailNameEng, T.NonlabTemplateDetailName)
|
|
ELSE
|
|
T.NonlabTemplateDetailName
|
|
END as So_TemplateDetailName,
|
|
|
|
R.NonlabTemplateResultDetailID as So_TemplateValueID,
|
|
R.NonlabTemplateResultDetailResult as So_TemplateValueText,
|
|
|
|
-- Info Tambahan
|
|
L.Nat_LangName as M_LangName,
|
|
H.Nonlab_TemplateResultName as So_TemplateLabelName,
|
|
|
|
-- Data Detail & Master
|
|
R.*,
|
|
T.*
|
|
|
|
FROM
|
|
nonlab_template_detail T
|
|
|
|
-- JOIN ke Detail Hasil (Result Detail)
|
|
-- Perhatikan: Parameter langsung ditempel di sini
|
|
JOIN
|
|
nonlab_template_result_detail R ON
|
|
T.NonlabTemplateDetailID = R.NonlabTemplateResultDetailNonlabTemplateDetailID
|
|
AND R.NonlabTemplateResultDetailNonlab_TemplateResultID = $safe_idlabel
|
|
AND R.NonlabTemplateResultDetailIsActive = 'Y'
|
|
|
|
-- JOIN ke Bahasa (Nat Lang)
|
|
LEFT JOIN
|
|
nat_lang L ON (CASE WHEN IFNULL(R.NonlabTemplateResultNat_LangID, 0) > 0 THEN R.NonlabTemplateResultNat_LangID ELSE T.NonlabTemplateDetaiM_LangID END) = L.Nat_LangID
|
|
|
|
-- JOIN ke Header Result
|
|
LEFT JOIN
|
|
nonlab_template_result H ON H.Nonlab_TemplateResultID = $safe_idlabel
|
|
|
|
WHERE
|
|
T.NonlabTemplateDetailNonlabTemplateID = $safe_idso
|
|
AND T.NonlabTemplateDetailIsActive = 'Y'
|
|
|
|
ORDER BY
|
|
T.NonlabTemplateDetailID ASC";
|
|
|
|
//# 4. Eksekusi Query
|
|
// Hapus array parameter kedua karena variabel sudah masuk di string $sql
|
|
$query = $this->db_onedev->query($sql);
|
|
|
|
$rows = array();
|
|
if ($query) {
|
|
$rows = $query->result_array();
|
|
} else {
|
|
$error = $this->db_onedev->error();
|
|
// Tampilkan error asli database untuk debugging
|
|
throw new Exception("Database Error: " . $error['message']);
|
|
}
|
|
|
|
// Output JSON
|
|
$result = array("total" => count($rows), "records" => $rows);
|
|
$this->sys_ok($result);
|
|
|
|
} catch(Exception $exc) {
|
|
$message = $exc->getMessage();
|
|
$this->sys_error($message);
|
|
}
|
|
}
|
|
|
|
public function lookup()
|
|
{
|
|
try {
|
|
# cek token valid
|
|
if (! $this->isLogin) {
|
|
$this->sys_error("Invalid Token");
|
|
exit;
|
|
}
|
|
|
|
$prm = $this->sys_input;
|
|
$search = $prm['search'];
|
|
$all = $prm['all'];
|
|
$limit = '';
|
|
if($all == 'N'){
|
|
$limit = ' LIMIT 10';
|
|
}
|
|
$sql = "select COUNT(*) as total
|
|
from nonlab_template_result tr
|
|
where
|
|
tr.Nonlab_TemplateResultIsActive = 'Y'";
|
|
$sql_param = array($search);
|
|
$total = $this->db_onedev->query($sql,$sql_param)->row()->total;
|
|
|
|
|
|
$sql = "select tr.Nonlab_TemplateResultID as id, tr.Nonlab_TemplateResultID as idlabel, tr.Nonlab_TemplateResultNonlabTemplateID as idso,
|
|
tr.Nonlab_TemplateResultName as name,
|
|
tr.Nonlab_TemplateResultName,
|
|
tr.Nonlab_TemplateResultM_DoctorID,
|
|
tr.Nonlab_TemplateResultNat_TestID,
|
|
tr.Nonlab_TemplateResultNonlabTemplateID,
|
|
IF(tr.Nonlab_TemplateResultM_DoctorID = 0, '',CONCAT(IFNULL(d.M_DoctorPrefix,''),' ',IFNULL(d.M_DoctorName,''),' ',IFNULL(d.M_DoctorSufix,''))) as M_DoctorName,
|
|
nt.Nat_TestName,
|
|
t.NonlabTemplateName,
|
|
tr.*
|
|
from nonlab_template_result tr
|
|
LEFT JOIN nonlab_template t ON tr.Nonlab_TemplateResultNonlabTemplateID = t.NonlabTemplateID
|
|
LEFT JOIN m_doctor d ON tr.Nonlab_TemplateResultM_DoctorID = d.M_DoctorID
|
|
LEFT JOIN nat_test nt ON tr.Nonlab_TemplateResultNat_TestID = nt.Nat_TestID
|
|
where
|
|
( tr.Nonlab_TemplateResultName LIKE CONCAT('%','{$search}','%')
|
|
)AND
|
|
tr.Nonlab_TemplateResultIsActive = 'Y'
|
|
GROUP BY tr.Nonlab_TemplateResultID
|
|
ORDER BY tr.Nonlab_TemplateResultID DESC $limit";
|
|
$sql_param = array($search);
|
|
$query = $this->db_onedev->query($sql);
|
|
//echo $this->db_onedev->last_query();
|
|
if ($query) {
|
|
$rows = $query->result_array();
|
|
|
|
|
|
} else {
|
|
$this->sys_error_db("so_templatelabel select");
|
|
exit;
|
|
}
|
|
|
|
$result = array ("total" => $total, "total_filter"=>count($rows),"records" => $rows);
|
|
$this->sys_ok($result);
|
|
|
|
} catch(Exception $exc) {
|
|
$message = $exc->getMessage();
|
|
$this->sys_error($message);
|
|
}
|
|
}
|
|
|
|
|
|
public function addnewsolabel()
|
|
{
|
|
try {
|
|
// 1. Cek Token (JANGAN DI-COMMENT agar User ID terbaca)
|
|
if (! $this->isLogin) {
|
|
$this->sys_error("Invalid Token");
|
|
exit;
|
|
}
|
|
|
|
// 2. Ambil parameter
|
|
$prm = $this->sys_input;
|
|
|
|
if(empty($prm['labelname']) || empty($prm['testid']) || empty($prm['nonlabtemplateid'])){
|
|
$this->sys_error("Data input tidak lengkap");
|
|
exit;
|
|
}
|
|
|
|
$labelname = $prm['labelname'];
|
|
$doctorid = isset($prm['doctorid']) && $prm['doctorid'] !== '' ? $prm['doctorid'] : 0;
|
|
$testid = $prm['testid'];
|
|
$nonlabtemplateid = $prm['nonlabtemplateid'];
|
|
|
|
// Pastikan User ID ada. Jika testing tanpa login, hardcode sementara (misal: $userid = 1;)
|
|
$userid = isset($this->sys_user["M_UserID"]) ? $this->sys_user["M_UserID"] : 0;
|
|
|
|
// 3. Query Insert
|
|
$sql = "INSERT INTO nonlab_template_result (
|
|
Nonlab_TemplateResultName,
|
|
Nonlab_TemplateResultM_DoctorID,
|
|
Nonlab_TemplateResultNat_TestID,
|
|
Nonlab_TemplateResultNonlabTemplateID,
|
|
Nonlab_TemplateResultCreatedUserID,
|
|
Nonlab_TemplateResultCreated,
|
|
Nonlab_TemplateResultLastUpdatedUserID,
|
|
Nonlab_TemplateResultLastUpdated
|
|
)
|
|
VALUES (?, ?, ?, ?, ?, NOW(), ?, NOW())";
|
|
|
|
$query = $this->db_onedev->query($sql, array(
|
|
$labelname,
|
|
$doctorid,
|
|
$testid,
|
|
$nonlabtemplateid,
|
|
$userid,
|
|
$userid
|
|
));
|
|
|
|
// 4. Cek Error Database
|
|
if (!$query) {
|
|
// Ambil error asli dari DB driver untuk debugging
|
|
$error = $this->db_onedev->error();
|
|
// Tampilkan pesan error spesifik jika mode development
|
|
$msg = "Insert Failed: " . ($error['message'] ? $error['message'] : "Unknown DB Error");
|
|
|
|
$this->sys_error($msg);
|
|
exit;
|
|
}
|
|
|
|
// 5. Ambil Last Insert ID (SEBELUM sys_ok)
|
|
$last_id = $this->db_onedev->insert_id();
|
|
|
|
$result = array(
|
|
"total" => 1,
|
|
"records" => array("xid" => $last_id) // Kembalikan ID yang baru dibuat
|
|
);
|
|
|
|
$this->sys_ok($result);
|
|
|
|
} catch(Exception $exc) {
|
|
$message = $exc->getMessage();
|
|
$this->sys_error($message);
|
|
}
|
|
}
|
|
|
|
public function editsolabel()
|
|
{
|
|
try {
|
|
//# cek token valid
|
|
if (! $this->isLogin) {
|
|
$this->sys_error("Invalid Token");
|
|
exit;
|
|
}
|
|
|
|
//# ambil parameter input
|
|
$prm = $this->sys_input;
|
|
$id = $prm['id'];
|
|
$labelname = $prm['labelname'];
|
|
$doctorid = $prm['doctorid'];
|
|
$testid = $prm['testid'];
|
|
$nonlabtemplateid = $prm['nonlabtemplateid'];
|
|
$userid = $this->sys_user["M_UserID"];
|
|
|
|
$sqlcompany = "update nonlab_template_result SET
|
|
Nonlab_TemplateResultName = ?,
|
|
Nonlab_TemplateResultM_DoctorID = ?,
|
|
Nonlab_TemplateResultNat_TestID = ?,
|
|
Nonlab_TemplateResultNonlabTemplateID = ?,
|
|
Nonlab_TemplateResultLastUpdatedUserID = ?,
|
|
Nonlab_TemplateResultLastUpdated = now()
|
|
where
|
|
Nonlab_TemplateResultID = ?
|
|
";
|
|
$querycompany = $this->db_onedev->query($sqlcompany,
|
|
array(
|
|
$labelname,
|
|
$doctorid,
|
|
$testid,
|
|
$nonlabtemplateid,
|
|
$userid,
|
|
$id
|
|
)
|
|
);
|
|
// echo $query;
|
|
if (!$querycompany) {
|
|
$this->sys_error_db("nonlab_template_result update");
|
|
exit;
|
|
}
|
|
$result = array ("total" => 1, "records" => array("xid" => $id));
|
|
$this->sys_ok($result);
|
|
|
|
|
|
|
|
|
|
} catch(Exception $exc) {
|
|
$message = $exc->getMessage();
|
|
$this->sys_error($message);
|
|
}
|
|
}
|
|
public function addnewcompanytype()
|
|
{
|
|
try {
|
|
//# cek token valid
|
|
if (! $this->isLogin) {
|
|
$this->sys_error("Invalid Token");
|
|
exit;
|
|
}
|
|
|
|
//# ambil parameter input
|
|
$prm = $this->sys_input;
|
|
$name_companytype = $prm['name'];
|
|
$userid = $this->sys_user["M_UserID"];
|
|
$sql = "insert into m_companytype(
|
|
M_CompanyTypeName,
|
|
M_CompanyTypeUserID,
|
|
M_CompanyTypeCreated,
|
|
M_CompanyTypeLastUpdated
|
|
)
|
|
values(?,?,now(),now())";
|
|
$query = $this->db_onedev->query($sql,
|
|
array(
|
|
$name_companytype,
|
|
$userid
|
|
)
|
|
);
|
|
//echo $query;
|
|
if (!$query) {
|
|
$this->sys_error_db("m_companytype insert");
|
|
exit;
|
|
}
|
|
$rows = [];
|
|
$query =" SELECT *, COUNT(M_CompanyID) as used
|
|
FROM (SELECT m_companytype.*,M_CompanyID
|
|
FROM
|
|
m_companytype
|
|
LEFT JOIN m_company ON M_CompanyTypeID = M_CompanyM_CompanyTypeID AND M_CompanyIsActive = 'Y'
|
|
WHERE M_CompanyTypeIsActive = 'Y') a
|
|
GROUP BY M_CompanyTypeID
|
|
";
|
|
//echo $query;
|
|
$rows['companytypes'] = $this->db_onedev->query($query)->result_array();
|
|
$result = array ("total" => 1, "records" => $rows);
|
|
$this->sys_ok($result);
|
|
$last_id = $this->db_onedev->insert_id();
|
|
|
|
} catch(Exception $exc) {
|
|
$message = $exc->getMessage();
|
|
$this->sys_error($message);
|
|
}
|
|
}
|
|
public function editcompanytype()
|
|
{
|
|
try {
|
|
//# cek token valid
|
|
if (! $this->isLogin) {
|
|
$this->sys_error("Invalid Token");
|
|
exit;
|
|
}
|
|
//# ambil parameter input
|
|
$prm = $this->sys_input;
|
|
$id_company = $prm['id'];
|
|
$name_company = $prm['name'];
|
|
$userid = $this->sys_user["M_UserID"];
|
|
$sqlcompany = "update m_companytype SET
|
|
M_CompanyTypeName = ?,
|
|
M_CompanyTypeUserID = ?,
|
|
M_CompanyTypeLastUpdated = now()
|
|
where
|
|
M_CompanyTypeID = ?
|
|
";
|
|
$querycompany = $this->db_onedev->query($sqlcompany,
|
|
array(
|
|
$name_company,
|
|
$userid,
|
|
$id_company
|
|
)
|
|
);
|
|
// echo $query;
|
|
if (!$querycompany) {
|
|
$this->sys_error_db("m_companytype update");
|
|
exit;
|
|
}
|
|
$rows = [];
|
|
$query =" SELECT *, COUNT(M_CompanyID) as used
|
|
FROM (SELECT m_companytype.*,M_CompanyID
|
|
FROM
|
|
m_companytype
|
|
LEFT JOIN m_company ON M_CompanyTypeID = M_CompanyM_CompanyTypeID AND M_CompanyIsActive = 'Y'
|
|
WHERE M_CompanyTypeIsActive = 'Y') a
|
|
GROUP BY M_CompanyTypeID";
|
|
//echo $query;
|
|
$rows['companytypes'] = $this->db_onedev->query($query)->result_array();
|
|
$result = array ("total" => 1, "records" => $rows);
|
|
$this->sys_ok($result);
|
|
} catch(Exception $exc) {
|
|
$message = $exc->getMessage();
|
|
$this->sys_error($message);
|
|
}
|
|
}
|
|
public function deletecompanytype()
|
|
{
|
|
try {
|
|
//# cek token valid
|
|
if (! $this->isLogin) {
|
|
$this->sys_error("Invalid Token");
|
|
exit;
|
|
}
|
|
//# ambil parameter input
|
|
$prm = $this->sys_input;
|
|
$id_company = $prm['id'];
|
|
$userid = $this->sys_user["M_UserID"];
|
|
$sqlcompany = "update m_companytype SET
|
|
M_CompanyTypeIsActive = 'N',
|
|
M_CompanyTypeUserID = ?,
|
|
M_CompanyTypeLastUpdated = now()
|
|
where
|
|
M_CompanyTypeID = ?
|
|
";
|
|
$querycompany = $this->db_onedev->query($sqlcompany,
|
|
array(
|
|
$userid,
|
|
$id_company
|
|
)
|
|
);
|
|
// echo $query;
|
|
if (!$querycompany) {
|
|
$this->sys_error_db("m_companytype update");
|
|
exit;
|
|
}
|
|
$rows = [];
|
|
$query =" SELECT *
|
|
FROM m_companytype
|
|
WHERE
|
|
M_CompanyTypeIsActive = 'Y'
|
|
";
|
|
//echo $query;
|
|
$rows['companytypes'] = $this->db_onedev->query($query)->result_array();
|
|
$result = array ("total" => 1, "records" => $rows);
|
|
$this->sys_ok($result);
|
|
} catch(Exception $exc) {
|
|
$message = $exc->getMessage();
|
|
$this->sys_error($message);
|
|
}
|
|
}
|
|
public function addnewcompanybusiness()
|
|
{
|
|
try {
|
|
//# cek token valid
|
|
if (! $this->isLogin) {
|
|
$this->sys_error("Invalid Token");
|
|
exit;
|
|
}
|
|
|
|
//# ambil parameter input
|
|
$prm = $this->sys_input;
|
|
$name_companytype = $prm['name'];
|
|
$userid = $this->sys_user["M_UserID"];
|
|
$sql = "insert into m_companybusiness(
|
|
M_CompanyBusinessName,
|
|
M_CompanyBusinessUserID,
|
|
M_CompanyBusinessCreated,
|
|
M_CompanyBusinessLastUpdated
|
|
)
|
|
values(?,?,now(),now())";
|
|
$query = $this->db_onedev->query($sql,
|
|
array(
|
|
$name_companytype,
|
|
$userid
|
|
)
|
|
);
|
|
//echo $query;
|
|
if (!$query) {
|
|
$this->sys_error_db("m_companybusiness insert");
|
|
exit;
|
|
}
|
|
$rows = [];
|
|
$query =" SELECT *, COUNT(M_CompanyID) as used
|
|
FROM (SELECT m_companybusiness.*,M_CompanyID
|
|
FROM
|
|
m_companybusiness
|
|
LEFT JOIN m_company ON M_CompanyBusinessID = M_CompanyM_CompanyBusinessID AND M_CompanyIsActive = 'Y'
|
|
WHERE M_CompanyBusinessIsActive = 'Y') a
|
|
GROUP BY M_CompanyBusinessID
|
|
";
|
|
//echo $query;
|
|
$rows['companybusinesss'] = $this->db_onedev->query($query)->result_array();
|
|
$result = array ("total" => 1, "records" => $rows);
|
|
$this->sys_ok($result);
|
|
$last_id = $this->db_onedev->insert_id();
|
|
|
|
} catch(Exception $exc) {
|
|
$message = $exc->getMessage();
|
|
$this->sys_error($message);
|
|
}
|
|
}
|
|
public function editcompanybusiness()
|
|
{
|
|
try {
|
|
//# cek token valid
|
|
if (! $this->isLogin) {
|
|
$this->sys_error("Invalid Token");
|
|
exit;
|
|
}
|
|
//# ambil parameter input
|
|
$prm = $this->sys_input;
|
|
$id_company = $prm['id'];
|
|
$name_company = $prm['name'];
|
|
$userid = $this->sys_user["M_UserID"];
|
|
$sqlcompany = "update m_companybusiness SET
|
|
M_CompanyBusinessName = ?,
|
|
M_CompanyBusinessUserID = ?,
|
|
M_CompanyBusinessLastUpdated = now()
|
|
where
|
|
M_CompanyBusinessID = ?
|
|
";
|
|
$querycompany = $this->db_onedev->query($sqlcompany,
|
|
array(
|
|
$name_company,
|
|
$userid,
|
|
$id_company
|
|
)
|
|
);
|
|
// echo $query;
|
|
if (!$querycompany) {
|
|
$this->sys_error_db("m_companybusiness update");
|
|
exit;
|
|
}
|
|
$rows = [];
|
|
$query =" SELECT *, COUNT(M_CompanyID) as used
|
|
FROM (SELECT m_companybusiness.*,M_CompanyID
|
|
FROM
|
|
m_companybusiness
|
|
LEFT JOIN m_company ON M_CompanyBusinessID = M_CompanyM_CompanyBusinessID AND M_CompanyIsActive = 'Y'
|
|
WHERE M_CompanyBusinessIsActive = 'Y') a
|
|
GROUP BY M_CompanyBusinessID";
|
|
//echo $query;
|
|
$rows['companybusinesss'] = $this->db_onedev->query($query)->result_array();
|
|
$result = array ("total" => 1, "records" => $rows);
|
|
$this->sys_ok($result);
|
|
} catch(Exception $exc) {
|
|
$message = $exc->getMessage();
|
|
$this->sys_error($message);
|
|
}
|
|
}
|
|
public function deletecompanybusiness()
|
|
{
|
|
try {
|
|
//# cek token valid
|
|
if (! $this->isLogin) {
|
|
$this->sys_error("Invalid Token");
|
|
exit;
|
|
}
|
|
//# ambil parameter input
|
|
$prm = $this->sys_input;
|
|
$id_company = $prm['id'];
|
|
$userid = $this->sys_user["M_UserID"];
|
|
$sqlcompany = "update m_companybusiness SET
|
|
M_CompanyBusinessIsActive = 'N',
|
|
M_CompanyBusinessUserID = ?,
|
|
M_CompanyBusinessLastUpdated = now()
|
|
where
|
|
M_CompanyBusinessID = ?
|
|
";
|
|
$querycompany = $this->db_onedev->query($sqlcompany,
|
|
array(
|
|
$userid,
|
|
$id_company
|
|
)
|
|
);
|
|
// echo $query;
|
|
if (!$querycompany) {
|
|
$this->sys_error_db("m_companybusiness update");
|
|
exit;
|
|
}
|
|
$rows = [];
|
|
$query =" SELECT *
|
|
FROM m_companybusiness
|
|
WHERE
|
|
M_CompanyBusinessIsActive = 'Y'
|
|
";
|
|
//echo $query;
|
|
$rows['companybusinesss'] = $this->db_onedev->query($query)->result_array();
|
|
$result = array ("total" => 1, "records" => $rows);
|
|
$this->sys_ok($result);
|
|
} catch(Exception $exc) {
|
|
$message = $exc->getMessage();
|
|
$this->sys_error($message);
|
|
}
|
|
}
|
|
public function addnewsovalue()
|
|
{
|
|
try {
|
|
//# cek token valid
|
|
// if (! $this->isLogin) {
|
|
// $this->sys_error("Invalid Token");
|
|
// exit;
|
|
// }
|
|
|
|
//# ambil parameter input
|
|
$prm = $this->sys_input;
|
|
$solabelid = $prm['solabelid'];
|
|
$sovaluedetailid = $prm['sovaluedetailid'];
|
|
$sovaluetext = $prm['sovaluetext'];
|
|
$userid = isset($this->sys_user["M_UserID"]) ? $this->sys_user["M_UserID"] : 0;
|
|
|
|
if($prm['xid'] == 0){
|
|
|
|
$sql = "INSERT INTO nonlab_template_result_detail(
|
|
NonlabTemplateResultDetailNonlab_TemplateResultID,
|
|
NonlabTemplateResultDetailNonlabTemplateDetailID,
|
|
NonlabTemplateResultDetailResult,
|
|
NonlabTemplateResultDetailCreatedUserID,
|
|
NonlabTemplateResultDetailLastUpdatedUserID,
|
|
NonlabTemplateResultDetailCreated,
|
|
NonlabTemplateResultDetailLastUpdated
|
|
)
|
|
VALUES( ?,?,?,?,?,NOW(),NOW())";
|
|
$query = $this->db_onedev->query($sql,
|
|
array(
|
|
$solabelid,
|
|
$sovaluedetailid,
|
|
$sovaluetext,
|
|
$userid,
|
|
$userid
|
|
)
|
|
);
|
|
if (!$query) {
|
|
$this->sys_error_db("nonlab_template_result_detail insert",$this->db_onedev);
|
|
exit;
|
|
}
|
|
$last_id = $this->db_onedev->insert_id();
|
|
$result = array ("total" => 1, "records" => array("xid" => $last_id));
|
|
$this->sys_ok($result);
|
|
}else{
|
|
|
|
//echo $query;
|
|
$sql = "UPDATE nonlab_template_result_detail SET
|
|
NonlabTemplateResultDetailNonlab_TemplateResultID = ?,
|
|
NonlabTemplateResultDetailNonlabTemplateDetailID = ?,
|
|
NonlabTemplateResultDetailResult = ?,
|
|
NonlabTemplateResultDetailLastUpdatedUserID = ?,
|
|
NonlabTemplateResultDetailLastUpdated = NOW()
|
|
WHERE NonlabTemplateResultDetailID = ?";
|
|
|
|
$query = $this->db_onedev->query($sql, array(
|
|
$solabelid,
|
|
$sovaluedetailid,
|
|
$sovaluetext,
|
|
$userid,
|
|
$prm['xid']
|
|
));
|
|
|
|
if (!$query) {
|
|
$this->sys_error_db("nonlab_template_result_detail update",$this->db_onedev);
|
|
exit;
|
|
}
|
|
|
|
$result = array ("total" => 1, "records" => array("xid" => $prm['xid']));
|
|
$this->sys_ok($result);
|
|
|
|
}
|
|
|
|
|
|
|
|
} catch(Exception $exc) {
|
|
$message = $exc->getMessage();
|
|
$this->sys_error($message);
|
|
}
|
|
}
|
|
|
|
public function deletesovalue()
|
|
{
|
|
try {
|
|
//# cek token valid
|
|
// if (! $this->isLogin) {
|
|
// $this->sys_error("Invalid Token");
|
|
// exit;
|
|
// }
|
|
|
|
//# ambil parameter input
|
|
$prm = $this->sys_input;
|
|
$userid = isset($this->sys_user["M_UserID"]) ? $this->sys_user["M_UserID"] : 0;
|
|
|
|
$sql = "UPDATE nonlab_template_result_detail SET
|
|
NonlabTemplateResultDetailIsActive = 'N',
|
|
NonlabTemplateResultDetailLastUpdatedUserID = ?,
|
|
NonlabTemplateResultDetailLastUpdated = NOW()
|
|
WHERE
|
|
NonlabTemplateResultDetailID = ?";
|
|
|
|
$query = $this->db_onedev->query($sql, array($userid, $prm['id']));
|
|
if (!$query) {
|
|
$this->sys_error_db("nonlab_template_result_detail delete");
|
|
exit;
|
|
}
|
|
$result = array ("total" => 1, "records" => array("xid" => 0));
|
|
$this->sys_ok($result);
|
|
|
|
} catch(Exception $exc) {
|
|
$message = $exc->getMessage();
|
|
$this->sys_error($message);
|
|
}
|
|
}
|
|
|
|
public function addnewconvert()
|
|
{
|
|
try {
|
|
//# cek token valid
|
|
if (! $this->isLogin) {
|
|
$this->sys_error("Invalid Token");
|
|
exit;
|
|
}
|
|
|
|
//# ambil parameter input
|
|
$prm = $this->sys_input;
|
|
$instrumentid = $prm['instrumentid'];
|
|
$resultorigin = $prm['resultorigin'];
|
|
$resultconvert = $prm['resultconvert'];
|
|
$userid = $this->sys_user["M_UserID"];
|
|
if($prm['xid'] == 0){
|
|
|
|
$sql = "insert into m_instrumentconvert(
|
|
M_InstrumentConvertNat_InstrumentID,
|
|
M_InstrumentConvertResultOrigin,
|
|
M_InstrumentConvertResultConvert,
|
|
M_InstrumentConvertUserID,
|
|
M_InstrumentConvertCreated,
|
|
M_InstrumentConvertLastUpdated
|
|
|
|
)
|
|
values( ?,?,?,?,now(),now())";
|
|
$query = $this->db_onedev->query($sql,
|
|
array(
|
|
$instrumentid,
|
|
$resultorigin,
|
|
$resultconvert,
|
|
$userid
|
|
)
|
|
);
|
|
if (!$query) {
|
|
$this->sys_error_db("m_instrumentconvert insert",$this->db_onedev);
|
|
exit;
|
|
}
|
|
$result = array ("total" => 1, "records" => array("xid" => 0));
|
|
$this->sys_ok($result);
|
|
}else{
|
|
|
|
//echo $query;
|
|
$sql = "UPDATE m_instrumentconvert SET M_InstrumentConvertResultOrigin = '{$resultorigin}',
|
|
M_InstrumentConvertResultConvert = '{$resultconvert}',
|
|
M_InstrumentConvertUserID = '{$userid}' WHERE M_InstrumentConvertID = '{$prm['xid']}'";
|
|
//echo $sql;
|
|
$query = $this->db_onedev->query($sql);
|
|
$result = array ("total" => 1, "records" => array("xid" => 0));
|
|
$this->sys_ok($result);
|
|
|
|
}
|
|
|
|
|
|
|
|
} catch(Exception $exc) {
|
|
$message = $exc->getMessage();
|
|
$this->sys_error($message);
|
|
}
|
|
}
|
|
public function deleteuser()
|
|
{
|
|
try {
|
|
//# cek token valid
|
|
if (! $this->isLogin) {
|
|
$this->sys_error("Invalid Token");
|
|
exit;
|
|
}
|
|
|
|
//# ambil parameter input
|
|
$prm = $this->sys_input;
|
|
|
|
$sql = "update m_user SET
|
|
M_UserIsActive = 'N',
|
|
M_UserLastUpdated = now()
|
|
WHERE
|
|
M_UserID = ?
|
|
|
|
";
|
|
|
|
$query = $this->db_onedev->query($sql,
|
|
array(
|
|
$prm['id']
|
|
)
|
|
);
|
|
// echo $query;
|
|
if (!$query) {
|
|
$this->sys_error_db("m_user delete");
|
|
exit;
|
|
}
|
|
$result = array ("total" => 1, "records" => array("xid" => 0));
|
|
$this->sys_ok($result);
|
|
|
|
} catch(Exception $exc) {
|
|
$message = $exc->getMessage();
|
|
$this->sys_error($message);
|
|
}
|
|
}
|
|
public function confirmmou()
|
|
{
|
|
try {
|
|
//# cek token valid
|
|
if (! $this->isLogin) {
|
|
$this->sys_error("Invalid Token");
|
|
exit;
|
|
}
|
|
|
|
//# ambil parameter input
|
|
$prm = $this->sys_input;
|
|
|
|
$sql = "update m_mou SET
|
|
M_MouIsApproved = 'Y',
|
|
M_MouLastUpdated = now()
|
|
WHERE
|
|
M_MouID = ?
|
|
|
|
";
|
|
|
|
$query = $this->db_onedev->query($sql,
|
|
array(
|
|
$prm['id']
|
|
)
|
|
);
|
|
// echo $query;
|
|
if (!$query) {
|
|
$this->sys_error_db("m_mou update");
|
|
exit;
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
$result = array ("total" => 1, "records" => array("xid" => 0));
|
|
$this->sys_ok($result);
|
|
|
|
} catch(Exception $exc) {
|
|
$message = $exc->getMessage();
|
|
$this->sys_error($message);
|
|
}
|
|
}
|
|
public function verifymou()
|
|
{
|
|
try {
|
|
//# cek token valid
|
|
if (! $this->isLogin) {
|
|
$this->sys_error("Invalid Token");
|
|
exit;
|
|
}
|
|
|
|
//# ambil parameter input
|
|
$prm = $this->sys_input;
|
|
$userid = $this->sys_user["M_UserID"];
|
|
$id = $prm['id'];
|
|
$sql = "update m_mou SET
|
|
M_MouIsVerified = 'Y',
|
|
M_MouVerifyDate = now(),
|
|
M_MouStatus = 'V',
|
|
M_MouVerifyUserID = '{$userid}',
|
|
M_MouLastUpdated = now()
|
|
WHERE
|
|
M_MouID = ?
|
|
|
|
";
|
|
|
|
$query = $this->db_onedev->query($sql,
|
|
array(
|
|
$prm['id']
|
|
)
|
|
);
|
|
// echo $query;
|
|
if (!$query) {
|
|
$this->sys_error_db("m_mou update");
|
|
exit;
|
|
}
|
|
|
|
$querystatus ="INSERT g_moustatuslog
|
|
(G_MouStatusLogDate,
|
|
G_MouStatusLogM_MouID,
|
|
G_MouStatusLogStatus,
|
|
G_MouStatusLogUserID,
|
|
G_MouStatusLogCreated,
|
|
G_MouStatusLogLastUpdated)
|
|
VALUES(
|
|
date(now()),
|
|
'{$id}',
|
|
'V',
|
|
'{$userid}',
|
|
now(),
|
|
now())
|
|
";
|
|
$rows = $this->db_onedev->query($querystatus);
|
|
|
|
|
|
|
|
$result = array ("total" => 1, "records" => array("xid" => 0));
|
|
$this->sys_ok($result);
|
|
|
|
} catch(Exception $exc) {
|
|
$message = $exc->getMessage();
|
|
$this->sys_error($message);
|
|
}
|
|
}
|
|
public function unverifymou()
|
|
{
|
|
try {
|
|
//# cek token valid
|
|
if (! $this->isLogin) {
|
|
$this->sys_error("Invalid Token");
|
|
exit;
|
|
}
|
|
|
|
//# ambil parameter input
|
|
$prm = $this->sys_input;
|
|
$userid = $this->sys_user["M_UserID"];
|
|
$id = $prm['id'];
|
|
$sql = "update m_mou SET
|
|
M_MouIsVerified = 'N',
|
|
M_MouStatus = 'UV',
|
|
M_MouVerifyDate = now(),
|
|
M_MouVerifyUserID = '{$userid}',
|
|
M_MouLastUpdated = now()
|
|
WHERE
|
|
M_MouID = ?
|
|
|
|
";
|
|
|
|
$query = $this->db_onedev->query($sql,
|
|
array(
|
|
$prm['id']
|
|
)
|
|
);
|
|
// echo $query;
|
|
if (!$query) {
|
|
$this->sys_error_db("m_mou update");
|
|
exit;
|
|
}
|
|
$querystatus ="INSERT g_moustatuslog
|
|
(G_MouStatusLogDate,
|
|
G_MouStatusLogM_MouID,
|
|
G_MouStatusLogStatus,
|
|
G_MouStatusLogUserID,
|
|
G_MouStatusLogCreated,
|
|
G_MouStatusLogLastUpdated)
|
|
VALUES(
|
|
date(now()),
|
|
'{$id}',
|
|
'UV',
|
|
'{$userid}',
|
|
now(),
|
|
now())
|
|
";
|
|
$rows = $this->db_onedev->query($querystatus);
|
|
|
|
|
|
|
|
|
|
$result = array ("total" => 1, "records" => array("xid" => 0));
|
|
$this->sys_ok($result);
|
|
|
|
} catch(Exception $exc) {
|
|
$message = $exc->getMessage();
|
|
$this->sys_error($message);
|
|
}
|
|
}
|
|
public function releasemou()
|
|
{
|
|
try {
|
|
//# cek token valid
|
|
if (! $this->isLogin) {
|
|
$this->sys_error("Invalid Token");
|
|
exit;
|
|
}
|
|
|
|
//# ambil parameter input
|
|
$prm = $this->sys_input;
|
|
$userid = $this->sys_user["M_UserID"];
|
|
$id = $prm['id'];
|
|
$sql = "update m_mou SET
|
|
M_MouIsReleased = 'Y',
|
|
M_MouStatus = 'R',
|
|
M_MouReleaseDate = now(),
|
|
M_MouReleaseUserID = '{$userid}',
|
|
M_MouIsApproved = 'Y',
|
|
M_MouLastUpdated = now()
|
|
WHERE
|
|
M_MouID = ?
|
|
|
|
";
|
|
|
|
$query = $this->db_onedev->query($sql,
|
|
array(
|
|
$prm['id']
|
|
)
|
|
);
|
|
// echo $query;
|
|
if (!$query) {
|
|
$this->sys_error_db("m_mou update");
|
|
exit;
|
|
}
|
|
$querystatus ="INSERT g_moustatuslog
|
|
(G_MouStatusLogDate,
|
|
G_MouStatusLogM_MouID,
|
|
G_MouStatusLogStatus,
|
|
G_MouStatusLogUserID,
|
|
G_MouStatusLogCreated,
|
|
G_MouStatusLogLastUpdated)
|
|
VALUES(
|
|
date(now()),
|
|
'{$id}',
|
|
'R',
|
|
'{$userid}',
|
|
now(),
|
|
now())
|
|
";
|
|
$rows = $this->db_onedev->query($querystatus);
|
|
|
|
|
|
|
|
|
|
$result = array ("total" => 1, "records" => array("xid" => 0));
|
|
$this->sys_ok($result);
|
|
|
|
} catch(Exception $exc) {
|
|
$message = $exc->getMessage();
|
|
$this->sys_error($message);
|
|
}
|
|
}
|
|
public function unreleasemou()
|
|
{
|
|
try {
|
|
//# cek token valid
|
|
if (! $this->isLogin) {
|
|
$this->sys_error("Invalid Token");
|
|
exit;
|
|
}
|
|
|
|
//# ambil parameter input
|
|
$prm = $this->sys_input;
|
|
$userid = $this->sys_user["M_UserID"];
|
|
$id = $prm['id'];
|
|
$sql = "update m_mou SET
|
|
M_MouIsReleased = 'N',
|
|
M_MouStatus = 'UR',
|
|
M_MouReleaseDate = now(),
|
|
M_MouReleaseUserID = '{$userid}',
|
|
M_MouIsApproved = 'N',
|
|
M_MouLastUpdated = now()
|
|
WHERE
|
|
M_MouID = ?
|
|
|
|
";
|
|
|
|
$query = $this->db_onedev->query($sql,
|
|
array(
|
|
$prm['id']
|
|
)
|
|
);
|
|
// echo $query;
|
|
if (!$query) {
|
|
$this->sys_error_db("m_mou update");
|
|
exit;
|
|
}
|
|
$querystatus ="INSERT g_moustatuslog
|
|
(G_MouStatusLogDate,
|
|
G_MouStatusLogM_MouID,
|
|
G_MouStatusLogStatus,
|
|
G_MouStatusLogUserID,
|
|
G_MouStatusLogCreated,
|
|
G_MouStatusLogLastUpdated)
|
|
VALUES(
|
|
date(now()),
|
|
'{$id}',
|
|
'UR',
|
|
'{$userid}',
|
|
now(),
|
|
now())
|
|
";
|
|
$rows = $this->db_onedev->query($querystatus);
|
|
|
|
|
|
|
|
|
|
$result = array ("total" => 1, "records" => array("xid" => 0));
|
|
$this->sys_ok($result);
|
|
|
|
} catch(Exception $exc) {
|
|
$message = $exc->getMessage();
|
|
$this->sys_error($message);
|
|
}
|
|
}
|
|
|
|
public function deletesolabel()
|
|
{
|
|
try {
|
|
//# cek token valid
|
|
if (! $this->isLogin) {
|
|
$this->sys_error("Invalid Token");
|
|
exit;
|
|
}
|
|
|
|
//# ambil parameter input
|
|
$prm = $this->sys_input;
|
|
$id = $prm['id'];
|
|
$userid = $this->sys_user["M_UserID"];
|
|
|
|
// Mulai Transaksi Database (Agar aman, update header & detail harus sukses semua)
|
|
$this->db_onedev->trans_start();
|
|
|
|
// ======================================================
|
|
// 1. SOFT DELETE HEADER (Tabel nonlab_template_result)
|
|
// ======================================================
|
|
$sql = "UPDATE nonlab_template_result SET
|
|
Nonlab_TemplateResultIsActive = 'N',
|
|
Nonlab_TemplateResultDeleted = NOW(), -- Catat waktu hapus
|
|
Nonlab_TemplateResultDeletedUserID = ? -- Catat user yang menghapus
|
|
WHERE
|
|
Nonlab_TemplateResultID = ?";
|
|
|
|
$this->db_onedev->query($sql, array($userid, $id));
|
|
|
|
// ======================================================
|
|
// 2. SOFT DELETE DETAIL (Tabel nonlab_template_result_detail)
|
|
// ======================================================
|
|
// Menghapus semua detail yang terhubung dengan Header ID tersebut
|
|
$sql_detail = "UPDATE nonlab_template_result_detail SET
|
|
NonlabTemplateResultDetailIsActive = 'N',
|
|
NonlabTemplateResultDetailDeleted = NOW(),
|
|
NonlabTemplateResultDetailDeletedUserID = ?
|
|
WHERE
|
|
NonlabTemplateResultDetailNonlab_TemplateResultID = ?";
|
|
|
|
$this->db_onedev->query($sql_detail, array($userid, $id));
|
|
|
|
// Selesaikan Transaksi
|
|
$this->db_onedev->trans_complete();
|
|
|
|
// Cek Status Transaksi
|
|
if ($this->db_onedev->trans_status() === FALSE) {
|
|
// Jika ada yang gagal
|
|
$this->sys_error_db("Gagal menghapus data (Transaction Failed)");
|
|
exit;
|
|
} else {
|
|
// Jika sukses semua
|
|
$result = array ("total" => 1, "records" => array("xid" => $id, "status" => "Deleted"));
|
|
$this->sys_ok($result);
|
|
}
|
|
|
|
} catch(Exception $exc) {
|
|
$message = $exc->getMessage();
|
|
$this->sys_error($message);
|
|
}
|
|
}
|
|
|
|
function selectcompanytype(){
|
|
|
|
try {
|
|
//# cek token valid
|
|
if (! $this->isLogin) {
|
|
$this->sys_error("Invalid Token");
|
|
exit;
|
|
}
|
|
$rows = [];
|
|
$query =" SELECT *, COUNT(M_CompanyID) as used
|
|
FROM (SELECT m_companytype.*,M_CompanyID
|
|
FROM
|
|
m_companytype
|
|
LEFT JOIN m_company ON M_CompanyTypeID = M_CompanyM_CompanyTypeID AND M_CompanyIsActive = 'Y'
|
|
WHERE M_CompanyTypeIsActive = 'Y') a
|
|
GROUP BY M_CompanyTypeID
|
|
";
|
|
//echo $query;
|
|
$rows['companytypes'] = $this->db_onedev->query($query)->result_array();
|
|
|
|
|
|
$result = array(
|
|
"total" => count($rows) ,
|
|
"records" => $rows,
|
|
);
|
|
$this->sys_ok($result);
|
|
|
|
|
|
} catch(Exception $exc) {
|
|
$message = $exc->getMessage();
|
|
$this->sys_error($message);
|
|
}
|
|
|
|
}
|
|
function selectcompanybusiness(){
|
|
|
|
try {
|
|
//# cek token valid
|
|
if (! $this->isLogin) {
|
|
$this->sys_error("Invalid Token");
|
|
exit;
|
|
}
|
|
$rows = [];
|
|
$query =" SELECT *, COUNT(M_CompanyID) as used
|
|
FROM (SELECT m_companybusiness.*,M_CompanyID
|
|
FROM
|
|
m_companybusiness
|
|
LEFT JOIN m_company ON M_CompanyBusinessID = M_CompanyM_CompanyBusinessID AND M_CompanyIsActive = 'Y'
|
|
WHERE M_CompanyBusinessIsActive = 'Y') a
|
|
GROUP BY M_CompanyBusinessID
|
|
";
|
|
//echo $query;
|
|
$rows['companybusinesss'] = $this->db_onedev->query($query)->result_array();
|
|
|
|
|
|
$result = array(
|
|
"total" => count($rows) ,
|
|
"records" => $rows,
|
|
);
|
|
$this->sys_ok($result);
|
|
|
|
|
|
} catch(Exception $exc) {
|
|
$message = $exc->getMessage();
|
|
$this->sys_error($message);
|
|
}
|
|
|
|
}
|
|
function selectcompanylevel(){
|
|
|
|
try {
|
|
//# cek token valid
|
|
if (! $this->isLogin) {
|
|
$this->sys_error("Invalid Token");
|
|
exit;
|
|
}
|
|
$prm = $this->sys_input;
|
|
$id = $prm['id'];
|
|
$rows = [];
|
|
$query =" SELECT *,CONCAT(Nat_CompanyLevelName,' [',M_CompanyName,']') as Nat_CompanyLevelName, COUNT(M_CompanyID) as used
|
|
FROM (SELECT nat_companylevel.*,M_CompanyID,M_CompanyName
|
|
FROM
|
|
nat_companylevel
|
|
LEFT JOIN m_company ON Nat_CompanyLevelNat_CompanyID = M_CompanyID AND M_CompanyIsActive = 'Y'
|
|
WHERE Nat_CompanyLevelIsActive = 'Y') a
|
|
GROUP BY Nat_CompanyLevelID
|
|
";
|
|
//echo $query;
|
|
$rows['companylevels'] = $this->db_onedev->query($query)->result_array();
|
|
|
|
|
|
$result = array(
|
|
"total" => count($rows) ,
|
|
"records" => $rows,
|
|
);
|
|
$this->sys_ok($result);
|
|
|
|
|
|
} catch(Exception $exc) {
|
|
$message = $exc->getMessage();
|
|
$this->sys_error($message);
|
|
}
|
|
|
|
}
|
|
function selecthierarchy(){
|
|
|
|
try {
|
|
//# cek token valid
|
|
if (! $this->isLogin) {
|
|
$this->sys_error("Invalid Token");
|
|
exit;
|
|
}
|
|
$rows = [];
|
|
$query =" SELECT *, COUNT(M_CompanyID) as used
|
|
FROM (SELECT nat_hierarchy.*,M_CompanyID
|
|
FROM
|
|
nat_hierarchy
|
|
LEFT JOIN m_company ON Nat_HierarchyID = M_CompanyNat_HierarchyID AND M_CompanyIsActive = 'Y'
|
|
WHERE Nat_HierarchyIsActive = 'Y') a
|
|
GROUP BY Nat_HierarchyID
|
|
";
|
|
//echo $query;
|
|
$rows['hierarchys'] = $this->db_onedev->query($query)->result_array();
|
|
|
|
|
|
$result = array(
|
|
"total" => count($rows) ,
|
|
"records" => $rows,
|
|
);
|
|
$this->sys_ok($result);
|
|
|
|
|
|
} catch(Exception $exc) {
|
|
$message = $exc->getMessage();
|
|
$this->sys_error($message);
|
|
}
|
|
|
|
}
|
|
function selectdoctor(){
|
|
|
|
try {
|
|
//# cek token valid
|
|
if (! $this->isLogin) {
|
|
$this->sys_error("Invalid Token");
|
|
exit;
|
|
}
|
|
$rows = [];
|
|
$query =" SELECT *
|
|
FROM m_doctor
|
|
WHERE
|
|
M_DoctorIsActive = 'Y'
|
|
";
|
|
//echo $query;
|
|
$rows['doctors'] = $this->db_onedev->query($query)->result_array();
|
|
|
|
|
|
$result = array(
|
|
"total" => count($rows) ,
|
|
"records" => $rows,
|
|
);
|
|
$this->sys_ok($result);
|
|
|
|
|
|
} catch(Exception $exc) {
|
|
$message = $exc->getMessage();
|
|
$this->sys_error($message);
|
|
}
|
|
|
|
}
|
|
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'] != '')
|
|
{
|
|
$q['search'] = "%{$prm['search']}%";
|
|
}
|
|
|
|
// QUERY TOTAL
|
|
$sql = "SELECT count(*) as total
|
|
FROM
|
|
m_doctor
|
|
WHERE
|
|
M_DoctorName like ?
|
|
AND M_DoctorIsActive = 'Y'";
|
|
$query = $this->db_onedev->query($sql,$q['search']);
|
|
//echo $query;
|
|
if ($query) {
|
|
$tot_count = $query->result_array()[0]["total"];
|
|
}
|
|
else {
|
|
$this->sys_error_db("m_doctor count",$this->db_onedev);
|
|
exit;
|
|
}
|
|
|
|
$sql = "
|
|
SELECT * FROM(
|
|
SELECT 0 as M_DoctorID, 'Semua Dokter' as M_DoctorName, 'Semua Dokter' as M_DoctorNames
|
|
UNION
|
|
SELECT M_DoctorID, M_DoctorName, CONCAT(IFNULL(M_DoctorPrefix,''),IFNULL(M_DoctorPrefix2,''),' ',M_DoctorName,' ',IFNULL(M_DoctorSufix,''),IFNULL(M_DoctorSufix2,''),IFNULL(M_DoctorSufix3,'')) as M_DoctorNames
|
|
FROM m_doctor
|
|
WHERE M_DoctorIsActive = 'Y') a
|
|
WHERE
|
|
M_DoctorNames like ?
|
|
ORDER BY M_DoctorName DESC
|
|
";
|
|
$query = $this->db_onedev->query($sql, array($q['search']));
|
|
|
|
if ($query) {
|
|
$rows = $query->result_array();
|
|
//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_doctor rows",$this->db_onedev);
|
|
exit;
|
|
}
|
|
}
|
|
|
|
|
|
function searchtestheader(){
|
|
try {
|
|
if (! $this->isLogin) {
|
|
$this->sys_error("Invalid Token");
|
|
exit;
|
|
}
|
|
$prm = $this->sys_input;
|
|
|
|
$template_id = '';
|
|
$search_val = '';
|
|
|
|
// Handle jika parameter terbungkus dalam key 'search' (nested object dari FE)
|
|
if (isset($prm['search']) && is_array($prm['search'])) {
|
|
$template_id = isset($prm['search']['template_id']) ? $prm['search']['template_id'] : '';
|
|
$search_val = isset($prm['search']['search']) ? $prm['search']['search'] : '';
|
|
} else {
|
|
$template_id = isset($prm['template_id']) ? $prm['template_id'] : '';
|
|
$search_val = isset($prm['search']) ? $prm['search'] : '';
|
|
}
|
|
|
|
if (empty($template_id)) {
|
|
$this->sys_error("Template ID is required");
|
|
exit;
|
|
}
|
|
|
|
$tot_count = 0;
|
|
$q = ['search' => '%'];
|
|
if ($search_val != '') {
|
|
$q['search'] = "%{$search_val}%";
|
|
}
|
|
|
|
// 2. QUERY TOTAL (COUNT)
|
|
// Perhatikan urutan parameter (?) harus sesuai dengan urutan array di bawahnya
|
|
$sql = "SELECT count(DISTINCT Nat_TestID) as total
|
|
FROM nonlab_template_mapping
|
|
JOIN nat_test ON NonlabTemplateMappingNat_TestID = Nat_TestID
|
|
WHERE
|
|
NonlabTemplateMappingIsActive = 'Y'
|
|
AND NonlabTemplateMappingNonlabTemplateID = ?
|
|
AND Nat_TestIsActive = 'Y'
|
|
AND Nat_TestName LIKE ?";
|
|
|
|
// Masukkan $template_id ke dalam array parameter
|
|
$query = $this->db_onedev->query($sql, array($template_id, $q['search']));
|
|
|
|
if ($query) {
|
|
$tot_count = $query->row()->total;
|
|
} else {
|
|
$this->sys_error_db("nonlab_template_mapping count", $this->db_onedev);
|
|
exit;
|
|
}
|
|
|
|
// 3. QUERY DATA
|
|
$sql = "SELECT
|
|
Nat_TestID,
|
|
CONCAT(IFNULL(Nat_TestCode,''), ' ', Nat_TestName) as Nat_TestName,
|
|
Nat_TestID as id,
|
|
CONCAT(IFNULL(Nat_TestCode,''), ' ', Nat_TestName) as text
|
|
FROM nonlab_template_mapping
|
|
JOIN nat_test ON NonlabTemplateMappingNat_TestID = Nat_TestID
|
|
WHERE
|
|
NonlabTemplateMappingIsActive = 'Y'
|
|
AND NonlabTemplateMappingNonlabTemplateID = ?
|
|
AND Nat_TestIsActive = 'Y'
|
|
AND Nat_TestName LIKE ?
|
|
GROUP BY Nat_TestID
|
|
ORDER BY Nat_TestName ASC";
|
|
|
|
// Masukkan $template_id ke dalam array parameter
|
|
$query = $this->db_onedev->query($sql, array($template_id, $q['search']));
|
|
|
|
if ($query) {
|
|
$rows = $query->result_array();
|
|
$result = array(
|
|
"total" => $tot_count,
|
|
"records" => $rows,
|
|
"total_display" => count($rows)
|
|
);
|
|
$this->sys_ok($result);
|
|
} else {
|
|
$this->sys_error_db("nonlab_template_mapping rows", $this->db_onedev);
|
|
exit;
|
|
}
|
|
} catch (Exception $e) {
|
|
$this->sys_error($e->getMessage());
|
|
}
|
|
}
|
|
|
|
function searchtemplate(){
|
|
if (! $this->isLogin) {
|
|
$this->sys_error("Invalid Token");
|
|
exit;
|
|
}
|
|
$prm = $this->sys_input;
|
|
|
|
$max_rst = 12;
|
|
$tot_count =0;
|
|
|
|
$q = [
|
|
'search' => '%'
|
|
];
|
|
|
|
if ($prm['search'] != '')
|
|
{
|
|
$q['search'] = "%{$prm['search']}%";
|
|
}
|
|
|
|
// QUERY TOTAL
|
|
$sql = "SELECT count(*) as total
|
|
FROM nonlab_template
|
|
WHERE
|
|
NonlabTemplateName like ?
|
|
AND NonlabTemplateIsActive = 'Y'";
|
|
$query = $this->db_onedev->query($sql,$q['search']);
|
|
//echo $query;
|
|
if ($query) {
|
|
$tot_count = $query->result_array()[0]["total"];
|
|
}
|
|
else {
|
|
$this->sys_error_db("nonlab_template count",$this->db_onedev);
|
|
exit;
|
|
}
|
|
|
|
$sql = "
|
|
SELECT NonlabTemplateID, NonlabTemplateName
|
|
FROM nonlab_template
|
|
WHERE
|
|
NonlabTemplateName like ?
|
|
AND NonlabTemplateIsActive = 'Y'
|
|
GROUP BY NonlabTemplateID
|
|
ORDER BY NonlabTemplateName ASC
|
|
";
|
|
$query = $this->db_onedev->query($sql, array($q['search']));
|
|
|
|
if ($query) {
|
|
$rows = $query->result_array();
|
|
//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("nonlab_template rows",$this->db_onedev);
|
|
exit;
|
|
}
|
|
}
|
|
function searchcompanylevel(){
|
|
if (! $this->isLogin) {
|
|
$this->sys_error("Invalid Token");
|
|
exit;
|
|
}
|
|
$prm = $this->sys_input;
|
|
|
|
$max_rst = 12;
|
|
$tot_count =0;
|
|
|
|
|
|
$name = $prm['name'];
|
|
$hirarkiid = intval($prm['id']) - 1;
|
|
|
|
// QUERY TOTAL
|
|
$sql = "SELECT count(*) as total
|
|
FROM nat_companylevel
|
|
WHERE
|
|
Nat_CompanyLevelName like '%{$name}%'
|
|
AND
|
|
Nat_CompanyLevelNat_HierarchyID = '{$hirarkiid}'
|
|
AND Nat_CompanyLevelIsActive = 'Y'";
|
|
$query = $this->db_onedev->query($sql);
|
|
//echo $query;
|
|
if ($query) {
|
|
$tot_count = $query->result_array()[0]["total"];
|
|
}
|
|
else {
|
|
$this->sys_error_db("nat_companylevel count",$this->db_onedev);
|
|
exit;
|
|
}
|
|
|
|
$sql = "
|
|
SELECT * FROM(SELECT *, CONCAT(Nat_CompanyLevelName, ' [',M_CompanyName,']') as Nat_CompanyLevelNames
|
|
FROM nat_companylevel
|
|
LEFT JOIN m_company ON Nat_CompanyLevelNat_CompanyID = M_CompanyID
|
|
WHERE Nat_CompanyLevelIsActive = 'Y') a
|
|
WHERE
|
|
Nat_CompanyLevelName like '%{$name}%'
|
|
AND
|
|
Nat_CompanyLevelNat_HierarchyID = '{$hirarkiid}'
|
|
AND Nat_CompanyLevelIsActive = 'Y'
|
|
ORDER BY Nat_CompanyLevelName DESC
|
|
";
|
|
$query = $this->db_onedev->query($sql);
|
|
|
|
if ($query) {
|
|
$rows = $query->result_array();
|
|
//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_companylevel rows",$this->db_onedev);
|
|
exit;
|
|
}
|
|
}
|
|
function searchcity(){
|
|
if (! $this->isLogin) {
|
|
$this->sys_error("Invalid Token");
|
|
exit;
|
|
}
|
|
$prm = $this->sys_input;
|
|
|
|
$max_rst = 12;
|
|
$tot_count =0;
|
|
|
|
$q = [
|
|
'search' => '%'
|
|
];
|
|
|
|
if ($prm['search'] != '')
|
|
{
|
|
$q['search'] = "%{$prm['search']}%";
|
|
}
|
|
|
|
// QUERY TOTAL
|
|
$sql = "SELECT count(*) as total
|
|
FROM m_city
|
|
WHERE
|
|
M_CityName like ?
|
|
AND M_CityIsActive = 'Y'";
|
|
$query = $this->db_onedev->query($sql,$q['search']);
|
|
//echo $query;
|
|
if ($query) {
|
|
$tot_count = $query->result_array()[0]["total"];
|
|
}
|
|
else {
|
|
$this->sys_error_db("m_city count",$this->db_onedev);
|
|
exit;
|
|
}
|
|
|
|
$sql = "
|
|
SELECT *
|
|
FROM m_city
|
|
WHERE
|
|
M_CityName like ?
|
|
AND M_CityIsActive = 'Y'
|
|
ORDER BY M_CityName DESC
|
|
";
|
|
$query = $this->db_onedev->query($sql, array($q['search']));
|
|
|
|
if ($query) {
|
|
$rows = $query->result_array();
|
|
//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_city rows",$this->db_onedev);
|
|
exit;
|
|
}
|
|
}
|
|
function getstaff(){
|
|
$prm = $this->sys_input;
|
|
$query =" SELECT *
|
|
FROM m_staff
|
|
WHERE
|
|
M_StaffIsActive = 'Y' AND M_StaffM_PositionID = 2";
|
|
//echo $query;
|
|
$rows = $this->db_onedev->query($query,array($prm['id']))->result_array();
|
|
|
|
$result = array(
|
|
"total" => count($rows) ,
|
|
"records" => $rows,
|
|
);
|
|
$this->sys_ok($result);
|
|
exit;
|
|
}
|
|
function getprovince(){
|
|
$prm = $this->sys_input;
|
|
$query =" SELECT *
|
|
FROM m_province
|
|
WHERE
|
|
M_ProvinceIsActive = 'Y'";
|
|
//echo $query;
|
|
$rows = $this->db_onedev->query($query,array($prm['id']))->result_array();
|
|
|
|
$result = array(
|
|
"total" => count($rows) ,
|
|
"records" => $rows,
|
|
);
|
|
$this->sys_ok($result);
|
|
exit;
|
|
}
|
|
function getcity(){
|
|
$prm = $this->sys_input;
|
|
$query =" SELECT *
|
|
FROM m_city
|
|
WHERE
|
|
M_CityIsActive = 'Y' AND M_CityM_ProvinceID = ?
|
|
";
|
|
//echo $query;
|
|
$rows = $this->db_onedev->query($query,array($prm['id']))->result_array();
|
|
|
|
$result = array(
|
|
"total" => count($rows) ,
|
|
"records" => $rows,
|
|
);
|
|
$this->sys_ok($result);
|
|
exit;
|
|
}
|
|
function getdistrict(){
|
|
$prm = $this->sys_input;
|
|
$query =" SELECT *
|
|
FROM m_district
|
|
WHERE
|
|
M_DistrictIsActive = 'Y' AND M_DistrictM_CityID = ?
|
|
";
|
|
//echo $query;
|
|
$rows = $this->db_onedev->query($query,array($prm['id']))->result_array();
|
|
|
|
$result = array(
|
|
"total" => count($rows) ,
|
|
"records" => $rows,
|
|
);
|
|
$this->sys_ok($result);
|
|
exit;
|
|
}
|
|
|
|
function getkelurahan(){
|
|
$prm = $this->sys_input;
|
|
$query =" SELECT *
|
|
FROM m_kelurahan
|
|
WHERE
|
|
M_KelurahanIsActive = 'Y' AND M_KelurahanM_DistrictID = ?
|
|
";
|
|
//echo $query;
|
|
$rows = $this->db_onedev->query($query,array($prm['id']))->result_array();
|
|
|
|
$result = array(
|
|
"total" => count($rows) ,
|
|
"records" => $rows,
|
|
);
|
|
$this->sys_ok($result);
|
|
exit;
|
|
}
|
|
function selectbase(){
|
|
|
|
try {
|
|
//# cek token valid
|
|
if (! $this->isLogin) {
|
|
$this->sys_error("Invalid Token");
|
|
exit;
|
|
}
|
|
$rows = [];
|
|
$query =" SELECT 'SPK' as baseid, 'SPK' as basename
|
|
UNION SELECT 'MOU' as baseid, 'MOU' as basename
|
|
";
|
|
//echo $query;
|
|
$rows['bases'] = $this->db_onedev->query($query)->result_array();
|
|
|
|
|
|
$result = array(
|
|
"total" => count($rows) ,
|
|
"records" => $rows,
|
|
);
|
|
$this->sys_ok($result);
|
|
|
|
|
|
} catch(Exception $exc) {
|
|
$message = $exc->getMessage();
|
|
$this->sys_error($message);
|
|
}
|
|
|
|
}
|
|
function selectomzettype(){
|
|
|
|
try {
|
|
//# cek token valid
|
|
if (! $this->isLogin) {
|
|
$this->sys_error("Invalid Token");
|
|
exit;
|
|
}
|
|
$rows = [];
|
|
$query =" SELECT *
|
|
FROM m_omzettype
|
|
WHERE
|
|
M_OmzetTypeIsActive = 'Y'
|
|
";
|
|
//echo $query;
|
|
$rows['omzettypes'] = $this->db_onedev->query($query)->result_array();
|
|
|
|
|
|
$result = array(
|
|
"total" => count($rows) ,
|
|
"records" => $rows,
|
|
);
|
|
$this->sys_ok($result);
|
|
|
|
|
|
} catch(Exception $exc) {
|
|
$message = $exc->getMessage();
|
|
$this->sys_error($message);
|
|
}
|
|
|
|
}
|
|
function selectmoutype(){
|
|
|
|
try {
|
|
//# cek token valid
|
|
if (! $this->isLogin) {
|
|
$this->sys_error("Invalid Token");
|
|
exit;
|
|
}
|
|
$rows = [];
|
|
$query =" SELECT *
|
|
FROM m_moutype
|
|
WHERE
|
|
M_MouTypeIsActive = 'Y'
|
|
";
|
|
//echo $query;
|
|
$rows['moutypes'] = $this->db_onedev->query($query)->result_array();
|
|
|
|
|
|
$result = array(
|
|
"total" => count($rows) ,
|
|
"records" => $rows,
|
|
);
|
|
$this->sys_ok($result);
|
|
|
|
|
|
} catch(Exception $exc) {
|
|
$message = $exc->getMessage();
|
|
$this->sys_error($message);
|
|
}
|
|
|
|
}
|
|
function selectagingtype(){
|
|
|
|
try {
|
|
//# cek token valid
|
|
if (! $this->isLogin) {
|
|
$this->sys_error("Invalid Token");
|
|
exit;
|
|
}
|
|
$rows = [];
|
|
$query =" SELECT *
|
|
FROM m_agingtype
|
|
WHERE
|
|
M_AgingIsActive = 'Y'
|
|
";
|
|
//echo $query;
|
|
$rows['agingtypes'] = $this->db_onedev->query($query)->result_array();
|
|
|
|
|
|
$result = array(
|
|
"total" => count($rows) ,
|
|
"records" => $rows,
|
|
);
|
|
$this->sys_ok($result);
|
|
|
|
|
|
} catch(Exception $exc) {
|
|
$message = $exc->getMessage();
|
|
$this->sys_error($message);
|
|
}
|
|
|
|
}
|
|
|
|
function getnatlanguage(){
|
|
try {
|
|
//# cek token valid
|
|
if (! $this->isLogin) {
|
|
$this->sys_error("Invalid Token");
|
|
exit;
|
|
}
|
|
$query =" SELECT Nat_LangID, Nat_LangName
|
|
FROM nat_lang
|
|
WHERE
|
|
Nat_LangIsActive = 'Y'
|
|
";
|
|
$rows = $this->db_onedev->query($query)->result_array();
|
|
|
|
$result = array(
|
|
"total" => count($rows) ,
|
|
"records" => $rows,
|
|
);
|
|
$this->sys_ok($result);
|
|
|
|
} catch(Exception $exc) {
|
|
$message = $exc->getMessage();
|
|
$this->sys_error($message);
|
|
}
|
|
}
|
|
|
|
public function addnewsovaluebatch()
|
|
{
|
|
try {
|
|
//# cek token valid
|
|
if (! $this->isLogin) {
|
|
$this->sys_error("Invalid Token");
|
|
exit;
|
|
}
|
|
|
|
//# ambil parameter input
|
|
$prm = $this->sys_input;
|
|
$solabelid = $prm['solabelid'];
|
|
$nonlabtemplateid = $prm['nonlabtemplateid'];
|
|
$langid = $prm['langid'];
|
|
$userid = isset($this->sys_user["M_UserID"]) ? $this->sys_user["M_UserID"] : 0;
|
|
|
|
// Ambil semua detail template berdasarkan ID Template
|
|
$sql_master = "SELECT NonlabTemplateDetailID
|
|
FROM nonlab_template_detail
|
|
WHERE NonlabTemplateDetailNonlabTemplateID = ?
|
|
AND NonlabTemplateDetailIsActive = 'Y'";
|
|
$master_rows = $this->db_onedev->query($sql_master, array($nonlabtemplateid))->result_array();
|
|
|
|
$this->db_onedev->trans_start();
|
|
|
|
foreach ($master_rows as $row) {
|
|
$detail_id = $row['NonlabTemplateDetailID'];
|
|
|
|
// Cek apakah data sudah ada di result detail
|
|
$sql_check = "SELECT NonlabTemplateResultDetailID
|
|
FROM nonlab_template_result_detail
|
|
WHERE NonlabTemplateResultDetailNonlab_TemplateResultID = ?
|
|
AND NonlabTemplateResultDetailNonlabTemplateDetailID = ?
|
|
AND NonlabTemplateResultNat_LangID = ?
|
|
AND NonlabTemplateResultDetailIsActive = 'Y'";
|
|
$check_query = $this->db_onedev->query($sql_check, array($solabelid, $detail_id, $langid));
|
|
if(!$check_query){
|
|
$this->sys_error_db("nonlab_template_result_detail check", $this->db_onedev);
|
|
exit;
|
|
}
|
|
|
|
if ($check_query->num_rows() == 0) {
|
|
// Jika belum ada, insert baru
|
|
$sql_insert = "INSERT INTO nonlab_template_result_detail (
|
|
NonlabTemplateResultDetailNonlab_TemplateResultID,
|
|
NonlabTemplateResultDetailNonlabTemplateDetailID,
|
|
NonlabTemplateResultNat_LangID,
|
|
NonlabTemplateResultDetailResult,
|
|
NonlabTemplateResultDetailCreatedUserID,
|
|
NonlabTemplateResultDetailCreated,
|
|
NonlabTemplateResultDetailLastUpdatedUserID,
|
|
NonlabTemplateResultDetailLastUpdated
|
|
) VALUES (?, ?, ?, '', ?, NOW(), ?, NOW())";
|
|
$this->db_onedev->query($sql_insert, array($solabelid, $detail_id, $langid, $userid, $userid));
|
|
}
|
|
}
|
|
|
|
$this->db_onedev->trans_complete();
|
|
|
|
if ($this->db_onedev->trans_status() === FALSE) {
|
|
$this->sys_error_db("Batch Insert Failed");
|
|
exit;
|
|
}
|
|
|
|
$result = array("total" => 1, "records" => array("status" => "OK"));
|
|
$this->sys_ok($result);
|
|
|
|
} catch (Exception $exc) {
|
|
$message = $exc->getMessage();
|
|
$this->sys_error($message);
|
|
}
|
|
}
|
|
|
|
public function gettemplatedetail()
|
|
{
|
|
try {
|
|
// 1. Cek Token
|
|
if (! $this->isLogin) {
|
|
$this->sys_error("Invalid Token");
|
|
exit;
|
|
}
|
|
|
|
// 2. Ambil Parameter
|
|
$prm = $this->sys_input;
|
|
$template_id = isset($prm['NonlabTemplateDetailNonlabTemplateID']) ? $prm['NonlabTemplateDetailNonlabTemplateID'] : 0;
|
|
|
|
// 3. Query Utama
|
|
$sql = "SELECT *
|
|
FROM nonlab_template_detail
|
|
WHERE NonlabTemplateDetailNonlabTemplateID = ?
|
|
AND NonlabTemplateDetailIsActive = 'Y'
|
|
ORDER BY NonlabTemplateDetailID ASC";
|
|
|
|
$query = $this->db_onedev->query($sql, array($template_id));
|
|
|
|
$rows = $query->result_array();
|
|
$result = array("total" => count($rows), "records" => $rows);
|
|
$this->sys_ok($result);
|
|
|
|
} catch(Exception $exc) {
|
|
$message = $exc->getMessage();
|
|
$this->sys_error($message);
|
|
}
|
|
}
|
|
} |