Initial import

This commit is contained in:
sas.fajri
2026-04-27 10:26:26 +07:00
commit bf9b9097ee
2388 changed files with 3002242 additions and 0 deletions

View File

@@ -0,0 +1,15 @@
POST https://{{host}}/cpone/masterdata/fisiktemplate/index
Content-Type: "application/json"
{
}
###
POST https://{{host}}/cpone/masterdata/fisiktemplate/lookupfisikbyname
Content-Type: "application/json"
{
"lookupfisikbyname": "",
"token":"eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJNX1VzZXJJRCI6IjIiLCJNX1VzZXJFbWFpbCI6Impva29AZ21haWwuY29tIiwiTV9Vc2VyR3JvdXBEYXNoYm9hcmQiOiJvbmUtdWlcL3Rlc3RcL3Z1ZXhcL29uZS1mby1yZWdpc3RyYXRpb24tdjI3IiwiTV9Vc2VyRGVmYXVsdFRfU2FtcGxlU3RhdGlvbklEIjoiMSIsIk1fU3RhZmZOYW1lIjpudWxsLCJpc19jb3VyaWVyIjoiTiIsInRpbWVfYXV0b2xvZ291dCI6IjE1IiwiaXAiOiIxMzkuMTkyLjE3My42MiIsImFnZW50IjoiTW96aWxsYVwvNS4wIChXaW5kb3dzIE5UIDEwLjA7IFdpbjY0OyB4NjQpIEFwcGxlV2ViS2l0XC81MzcuMzYgKEtIVE1MLCBsaWtlIEdlY2tvKSBDaHJvbWVcLzEyNS4wLjAuMCBTYWZhcmlcLzUzNy4zNiIsInZlcnNpb24iOiJ2MiIsImxhc3QtbG9naW4iOiIyMDI0LTA2LTA2IDE2OjQ3OjAwIn0.5S84dVOQbpET7_L7vN-DZMr2uSWuhsxPZYtq-HvzKkI"
}

View File

@@ -0,0 +1,906 @@
<?php
class Fisiktemplate extends MY_Controller
{
var $db;
public function index()
{
echo "PATIENT API";
}
public function __construct()
{
parent::__construct();
// $this->db_onedev = $this->load->database("onedev", true);
}
function lookupfisikbyname()
{
try {
//# cek token valid
if (!$this->isLogin) {
$this->sys_error("Invalid Token");
exit;
}
$prm = $this->sys_input;
$fisikname = $prm['fisikname'];
$filter = '';
if (isset($sexid)) {
$filter .= "AND ($sexid = 0 or ($sexid > 0 and Nat_SexID = $sexid)) ";
}
if (isset($flagid)) {
$filter .= "AND ($flagid = 0 or ($flagid > 0 and Nat_FlagID = $flagid))";
}
$limit = '';
if ($all == 'N') {
$limit = ' LIMIT 10';
}
$number_limit = 10;
$number_offset = ($prm['current_page'] - 1) * $number_limit;
$sql = "SELECT COUNT(*) as total FROM
(SELECT *
FROM fisik_template_mapping
WHERE FisikTemplateMappingIsActive = 'Y' AND
FisikTemplateMappingName LIKE '%{$fisikname}%'
GROUP BY FisikTemplateMappingID) x";
// $total = $this->db_onedev->query($sql,$sql_param)->row()->total;
$query = $this->db->query($sql);
//echo $this->db->last_query();
$tot_count = 0;
$tot_page = 0;
if ($query) {
$tot_count = $query->result_array()[0]["total"];
$tot_page = ceil($tot_count / $number_limit);
} else {
$this->sys_error_db("fisik_template_mapping count", $this->db);
exit;
}
$sql = "SELECT FisikTemplateMappingID as id,
FisikTemplateMappingID,
FisikTemplateMappingName
FROM fisik_template_mapping
WHERE FisikTemplateMappingIsActive = 'Y' AND
FisikTemplateMappingName LIKE '%{$fisikname}%'
GROUP BY FisikTemplateMappingID
ORDER BY FisikTemplateMappingName ASC
limit $number_limit offset $number_offset";
// $sql_param = array($search);
$query = $this->db->query($sql);
// echo $this->db->last_query();
if ($query) {
$rows = $query->result_array();
} else {
$this->sys_error_db("fisik_template_mapping select");
exit;
}
$result = array("total" => $tot_page, "total_filter" => count($rows), "records" => $rows);
$this->sys_ok($result);
} catch (Exception $exc) {
$message = $exc->getMessage();
$this->sys_error($message);
}
}
function addfisik()
{
try {
//# cek token valid
if (!$this->isLogin) {
$this->sys_error("Invalid Token");
exit;
}
$this->db->trans_begin();
$prm = $this->sys_input;
$userid = $this->sys_user['M_UserID'];
$name = "";
if (isset($prm["name"])) {
$name = trim($prm["name"]);
}
$sql = "INSERT INTO fisik_template_mapping(
FisikTemplateMappingName,
FisikTemplateMappingCreated,
FisikTemplateMappingCreatedUserID,
FisikTemplateMappingLastUpdated
) VALUES(?,NOW(),?,NOW())";
$qry = $this->db->query($sql, array($name, $userid));
if (!$qry) {
$this->db->trans_rollback();
$this->sys_error_db("save fisik_template_mapping error", $this->db);
exit;
}
$this->db->trans_commit();
$result = array(
"total" => 1,
"affected_rows" => $this->db->affected_rows()
);
$this->sys_ok($result);
} catch (Exception $exc) {
$message = $exc->getMessage();
$this->sys_error($message);
}
}
function lookupfisikdetailbyid()
{
try {
//# cek token valid
if (!$this->isLogin) {
$this->sys_error("Invalid Token");
exit;
}
$prm = $this->sys_input;
$id = $prm['id'];
$code = $prm['code'];
$name = $prm['name'];
$all = $prm['all'];
// $filter = '';
// if ($status != 'A') {
// $filter .= "AND status = '{$status}' ";
// } else {
// $filter .= "";
// }
$limit = '';
if ($all == 'N') {
$limit = ' LIMIT 10';
}
$number_limit = 10;
$number_offset = ($prm['current_page'] - 1) * $number_limit;
$sql = "SELECT COUNT(*) as total
FROM (
SELECT *, IF(IFNULL(FisikTemplateMappingDetailID, 0) > 0, 'Y', 'N') AS status
FROM fisik_template
LEFT JOIN fisik_template_mapping_detail ON FisikTemplateID = FisikTemplateMappingDetailFisikTemplateID
AND FisikTemplateMappingDetailFisikTemplateMappingID = $id AND FisikTemplateMappingDetailIsActive = 'Y'
) x
WHERE
FisikTemplateCode LIKE '%{$code}%' AND
FisikTemplateTitle LIKE '%{$name}%'";
// $total = $this->db->query($sql,$sql_param)->row()->total;
$query = $this->db->query($sql);
//echo $this->db->last_query();
$tot_count = 0;
$tot_page = 0;
if ($query) {
$tot_count = $query->result_array()[0]["total"];
$tot_page = ceil($tot_count / $number_limit);
} else {
$this->sys_error_db("fisik_template count", $this->db);
exit;
}
$sql = "SELECT FisikTemplateID as id,
FisikTemplateJSON as xjson,
FisikTemplateID,
FisikTemplateType,
FisikTemplateCode,
FisikTemplateTableName,
FisikTemplateTitle,
FisikTemplateMappingDetailID,
FisikTemplateMappingDetailFisikTemplateMappingID,
FisikTemplateMappingDetailFisikTemplateID,
FisikTemplateIsActive,
IF(IFNULL(FisikTemplateMappingDetailID, 0) > 0, 'Y', 'N') AS status
FROM fisik_template
LEFT JOIN fisik_template_mapping_detail ON FisikTemplateID = FisikTemplateMappingDetailFisikTemplateID
AND FisikTemplateMappingDetailFisikTemplateMappingID = $id AND FisikTemplateMappingDetailIsActive = 'Y'
WHERE FisikTemplateIsActive = 'Y' AND
FisikTemplateCode LIKE '%{$code}%' AND
FisikTemplateTitle LIKE '%{$name}%'
GROUP BY FisikTemplateID
ORDER BY FisikTemplateCode ASC
limit $number_limit offset $number_offset";
$query = $this->db->query($sql);
//echo $this->db->last_query();
if ($query) {
$rows = $query->result_array();
foreach ($rows as $key => $value) {
$rows[$key]['xjson'] = json_decode($value['xjson']);
}
} else {
$this->sys_error_db("fisik_template select");
exit;
}
$result = array("total" => $tot_page, "total_filter" => count($rows), "records" => $rows);
$this->sys_ok($result);
} catch (Exception $exc) {
$message = $exc->getMessage();
$this->sys_error($message);
}
}
public function saveaddeditfisikdetail()
{
try {
//# cek token valid
if (!$this->isLogin) {
$this->sys_error("Invalid Token");
exit;
}
//# ambil parameter input
$prm = $this->sys_input;
$mappingdetailid = $prm['FisikTemplateMappingDetailID'];
$templatemappingID = $prm['templatemappingID'];
$templateID = $prm['FisikTemplateID'];
$status = $prm['status'];
$userid = $this->sys_user["M_UserID"];
if ($status == 'Y') {
$sql = "INSERT INTO fisik_template_mapping_detail(
FisikTemplateMappingDetailFisikTemplateMappingID,
FisikTemplateMappingDetailFisikTemplateID,
FisikTemplateMappingDetailCreated,
FisikTemplateMappingDetailCreatedUserID,
FisikTemplateMappingDetailLastUpdated) VALUES(?,?,NOW(),?,NOW())";
$query = $this->db->query(
$sql,
array(
$templatemappingID,
$templateID,
$userid
)
);
if (!$query) {
$this->sys_error_db("fisik_template_mapping_detail insert", $this->db);
exit;
}
$last_id = $this->db->insert_id();
$result = array("total" => 1, "records" => array("xid" => 0));
$this->sys_ok($result);
} else {
$sql = "UPDATE fisik_template_mapping_detail SET
FisikTemplateMappingDetailIsActive = 'N',
FisikTemplateMappingDetailLastUpdated = NOW(),
FisikTemplateMappingDetailLastUpdatedUserID = ?
WHERE FisikTemplateMappingDetailID = ?";
$query = $this->db->query(
$sql,
array(
$userid,
$mappingdetailid,
)
);
if (!$query) {
$this->sys_error_db("fisik_template_mapping_detail insert", $this->db);
exit;
}
$last_id = $this->db->insert_id();
$result = array("total" => 1, "records" => array("xid" => 0));
$this->sys_ok($result);
}
} catch (Exception $exc) {
$message = $exc->getMessage();
$this->sys_error($message);
}
}
function lookupuserbyname()
{
try {
//# cek token valid
if (!$this->isLogin) {
$this->sys_error("Invalid Token");
exit;
}
$prm = $this->sys_input;
$groupname = $prm['groupname'];
$filter = '';
if (isset($sexid)) {
$filter .= "AND ($sexid = 0 or ($sexid > 0 and Nat_SexID = $sexid)) ";
}
if (isset($flagid)) {
$filter .= "AND ($flagid = 0 or ($flagid > 0 and Nat_FlagID = $flagid))";
}
$limit = '';
if ($all == 'N') {
$limit = ' LIMIT 10';
}
$number_limit = 10;
$number_offset = ($prm['current_page'] - 1) * $number_limit;
$sql = "select COUNT(*) as total
FROM(SELECT *
from m_usergroup
WHERE
M_UserGroupIsActive = 'Y' AND
M_UserGroupName like '%{$groupname}%'
$filter GROUP BY M_UserGroupID) a";
// $total = $this->db_onedev->query($sql,$sql_param)->row()->total;
$query = $this->db_onedev->query($sql);
//echo $this->db_onedev->last_query();
$tot_count = 0;
$tot_page = 0;
if ($query) {
$tot_count = $query->result_array()[0]["total"];
$tot_page = ceil($tot_count / $number_limit);
} else {
$this->sys_error_db("m_usergroup count", $this->db_onedev);
exit;
}
$sql = "SELECT m_usergroup.*,
M_UserGroupID as id,
M_UserGroupID,
M_UserGroupName
FROM m_usergroup
WHERE
M_UserGroupIsActive = 'Y' AND
M_UserGroupName like '%{$groupname}%'
$filter
GROUP BY M_UserGroupID
ORDER BY M_UserGroupName ASC
limit $number_limit offset $number_offset";
$sql_param = array($search);
$query = $this->db_onedev->query($sql);
// echo $this->db_onedev->last_query();
if ($query) {
$rows = $query->result_array();
} else {
$this->sys_error_db("m_usergroup select");
exit;
}
$result = array("total" => $tot_page, "total_filter" => count($rows), "records" => $rows);
$this->sys_ok($result);
} catch (Exception $exc) {
$message = $exc->getMessage();
$this->sys_error($message);
}
}
function lookupreportbyid()
{
try {
//# cek token valid
if (!$this->isLogin) {
$this->sys_error("Invalid Token");
exit;
}
$prm = $this->sys_input;
$id = $prm['id'];
$reportgroup = $prm['reportgroup'];
$reportcode = $prm['reportcode'];
$reportname = $prm['reportname'];
$status = $prm['status'];
$all = $prm['all'];
$filter = '';
if ($status != 'A') {
$filter .= "AND status = '{$status}' ";
} else {
$filter .= "";
}
$limit = '';
if ($all == 'N') {
$limit = ' LIMIT 10';
}
$number_limit = 10;
$number_offset = ($prm['current_page'] - 1) * $number_limit;
$sql = "select COUNT(*) as total
FROM(SELECT *, IF(IFNULL(UserGroupReportID,0) > 0 , 'Y', 'N') as status
from r_report
LEFT JOIN usergroup_report ON R_ReportID = UserGroupReportR_ReportID AND UserGroupReportM_UserGroupID = $id AND UserGroupReportIsActive = 'Y'
LEFT JOIN m_usergroup ON UserGroupReportM_UserGroupID = M_UserGroupID AND M_UserGroupIsActive = 'Y'
LEFT JOIN r_reportgroup ON R_ReportR_ReportGroupID = R_ReportGroupID
WHERE
R_ReportIsActive = 'Y') a
WHERE
R_ReportGroupName like '%{$reportgroup}%' AND
R_ReportCode like '%{$reportcode}%' AND
R_ReportName like '%{$reportname}%' $filter";
// $total = $this->db_onedev->query($sql,$sql_param)->row()->total;
$query = $this->db_onedev->query($sql);
//echo $this->db_onedev->last_query();
$tot_count = 0;
$tot_page = 0;
if ($query) {
$tot_count = $query->result_array()[0]["total"];
$tot_page = ceil($tot_count / $number_limit);
} else {
$this->sys_error_db("r_report count", $this->db_onedev);
exit;
}
$sql = "SELECT * FROM(select R_ReportID as id,
R_ReportID,
R_ReportCode,
R_ReportName,
R_ReportGroupName,
UserGroupReportID,
UserGroupReportM_UserGroupID,
UserGroupReportR_ReportID,
IF(IFNULL(UserGroupReportID,0) > 0 , 'Y', 'N') as status
from r_report
LEFT JOIN usergroup_report ON R_ReportID = UserGroupReportR_ReportID AND UserGroupReportM_UserGroupID = $id AND UserGroupReportIsActive = 'Y'
LEFT JOIN m_usergroup ON UserGroupReportM_UserGroupID = M_UserGroupID AND M_UserGroupIsActive = 'Y'
LEFT JOIN r_reportgroup ON R_ReportR_ReportGroupID = R_ReportGroupID
WHERE
R_ReportIsActive = 'Y') a
WHERE
R_ReportGroupName like '%{$reportgroup}%' AND
R_ReportCode like '%{$reportcode}%' AND
R_ReportName like '%{$reportname}%' $filter
GROUP BY R_ReportID
ORDER BY R_ReportGroupName ASC, R_ReportName ASC
limit $number_limit offset $number_offset";
$sql_param = array($search);
$query = $this->db_onedev->query($sql);
//echo $this->db_onedev->last_query();
if ($query) {
$rows = $query->result_array();
} else {
$this->sys_error_db("r_report select");
exit;
}
$result = array("total" => $tot_page, "total_filter" => count($rows), "records" => $rows);
$this->sys_ok($result);
} catch (Exception $exc) {
$message = $exc->getMessage();
$this->sys_error($message);
}
}
function getsexreg()
{
if (!$this->isLogin) {
$this->sys_error("Invalid Token");
exit;
}
$rows = [];
$query = "
SELECT 'A' as M_StatusID, 'Semua' as M_StatusName
UNION
SELECT 'Y' as M_StatusID, 'Terpilih' as M_StatusName
UNION
SELECT 'N' as M_StatusID, 'Belum Terpilih' as M_StatusName
";
//echo $query;
$rows['f_statuss'] = $this->db_onedev->query($query)->result_array();
$result = array(
"total" => count($rows),
"records" => $rows,
);
$this->sys_ok($result);
exit;
}
function getstatus()
{
if (!$this->isLogin) {
$this->sys_error("Invalid Token");
exit;
}
$rows = [];
$query = "
SELECT 'A' as M_StatusID, 'Semua' as M_StatusName
UNION
SELECT 'Y' as M_StatusID, 'Terpilih' as M_StatusName
UNION
SELECT 'N' as M_StatusID, 'Belum Terpilih' as M_StatusName
";
//echo $query;
$rows['f_statuss'] = $this->db_onedev->query($query)->result_array();
$result = array(
"total" => count($rows),
"records" => $rows,
);
$this->sys_ok($result);
exit;
}
public function addnewreport()
{
try {
//# cek token valid
if (!$this->isLogin) {
$this->sys_error("Invalid Token");
exit;
}
//# ambil parameter input
$prm = $this->sys_input;
$userid = $prm['userid'];
$reportcode = $prm['reportcode'];
$reportname = $prm['reportname'];
$userid = $this->sys_user["M_UserID"];
$sql = "insert into r_report(
R_ReportCode,
R_ReportName,
R_ReportUserID,
R_ReportCreated,
R_ReportLastUpdated
)
values(?,?,?,now(),now())";
$query = $this->db_onedev->query(
$sql,
array(
$reportcode,
$reportname,
$userid
)
);
if (!$query) {
$this->sys_error_db("m_usergroup insert", $this->db_onedev);
exit;
}
$last_id = $this->db_onedev->insert_id();
$result = array("total" => 1, "records" => array("xid" => 0));
$this->sys_ok($result);
} catch (Exception $exc) {
$message = $exc->getMessage();
$this->sys_error($message);
}
}
public function saveaddeditreport()
{
try {
//# cek token valid
if (!$this->isLogin) {
$this->sys_error("Invalid Token");
exit;
}
//# ambil parameter input
$prm = $this->sys_input;
$usergroupid = $prm['userid'];
$reportid = $prm['R_ReportID'];
$reportuserid = $prm['UserGroupReportID'];
$status = $prm['status'];
$userid = $this->sys_user["M_UserID"];
if ($status == 'Y') {
$sql = "insert into usergroup_report(
UserGroupReportM_UserGroupID,
UserGroupReportR_ReportID,
UserGroupUserID,
UserGroupReportCreated,
UserGroupReportLastUpdated
)
values(?,?,?,now(),now())";
$query = $this->db_onedev->query(
$sql,
array(
$usergroupid,
$reportid,
$userid
)
);
if (!$query) {
$this->sys_error_db("usergroup_report insert", $this->db_onedev);
exit;
}
$last_id = $this->db_onedev->insert_id();
$result = array("total" => 1, "records" => array("xid" => 0));
$this->sys_ok($result);
} else {
$sql = "UPDATE usergroup_report SET
UserGroupReportIsActive = 'N',
UserGroupUserID = ?,
UserGroupReportCreated = now(),
UserGroupReportLastUpdated = now()
WHERE UserGroupReportID = ?";
$query = $this->db_onedev->query(
$sql,
array(
$userid,
$reportuserid
)
);
if (!$query) {
$this->sys_error_db("usergroup_report insert", $this->db_onedev);
exit;
}
$last_id = $this->db_onedev->insert_id();
$result = array("total" => 1, "records" => array("xid" => 0));
$this->sys_ok($result);
}
} catch (Exception $exc) {
$message = $exc->getMessage();
$this->sys_error($message);
}
}
function saveallreport()
{
if (!$this->isLogin) {
$this->sys_error("Invalid Token");
exit;
}
$prm = $this->sys_input;
$details = $prm['details'];
$userid = $this->sys_user["M_UserID"];
foreach ($details as $k => $v) {
$query = "UPDATE usergroup_report SET
UserGroupReportM_UserGroupID = '{$v['UserGroupReportM_UserGroupID']}',
UserGroupReportAdviceIna = '{$v['UserGroupReportAdviceIna']}',
UserGroupReportAdviceEng = '{$v['UserGroupReportAdviceEng']}',
UserGroupReportUserID = {$userid},
UserGroupReportCreated = now(),
UserGroupReportLastUpdated = now()
WHERE UserGroupReportID = {$v['UserGroupReportID']}";
//echo $query;
$action = $this->db_onedev->query($query);
}
if ($action) {
$result = array(
"total" => 1,
"records" => array(),
);
$this->sys_ok($result);
exit;
} else {
$this->sys_error_db($this->db_onedev->last_query(), $this->db_onedev);
exit;
}
}
public function deleteuser()
{
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"];
$sql = "update nat_methode SET
Nat_MethodeIsActive = 'N'
WHERE
Nat_MethodeID = ?
";
$query = $this->db_onedev->query(
$sql,
array(
$prm['id']
)
);
// echo $query;
if (!$query) {
$this->sys_error_db("nat_methode delete");
exit;
}
$sql = "update m_usergroup SET
M_UserGroupIsActive = 'N'
WHERE
M_UserGroupNat_MethodeID = ?
";
$query = $this->db_onedev->query(
$sql,
array(
$prm['id']
)
);
// echo $query;
if (!$query) {
$this->sys_error_db("m_usergroup 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 deletereport()
{
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"];
$sql = "update m_usergroup SET
M_UserGroupIsActive = 'N'
WHERE
M_UserGroupID = ?
";
$query = $this->db_onedev->query(
$sql,
array(
$prm['id']
)
);
// echo $query;
if (!$query) {
$this->sys_error_db("m_usergroup delete");
exit;
}
$result = array("total" => 1, "records" => array("xid" => 0));
$this->sys_ok($result);
} catch (Exception $exc) {
$message = $exc->getMessage();
$this->sys_error($message);
}
}
function searchuser()
{
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 nat_methode
WHERE
Nat_MethodeName like ?
AND Nat_MethodeIsActive = '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("nat_methode count", $this->db_onedev);
exit;
}
$sql = "
SELECT Nat_MethodeID, Nat_MethodeName
FROM nat_methode
WHERE
Nat_MethodeName like ?
AND Nat_MethodeIsActive = 'Y'
ORDER BY Nat_MethodeName 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("nat_methode rows", $this->db_onedev);
exit;
}
}
function searchuserbyname()
{
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 nat_methode
WHERE
Nat_MethodeName like ?
AND Nat_MethodeIsActive = '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("nat_methode count", $this->db_onedev);
exit;
}
$sql = "
SELECT Nat_MethodeID, Nat_MethodeName
FROM nat_methode
WHERE
Nat_MethodeName like ?
AND Nat_MethodeIsActive = 'Y'
ORDER BY Nat_MethodeName 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("nat_methode 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'] != '') {
$q['search'] = "%{$prm['search']}%";
}
// QUERY TOTAL
$sql = "SELECT count(*) as total
FROM t_test
WHERE
T_TestName like ?
AND T_TestIsActive = 'Y' AND T_TestIsResult = '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("t_test count", $this->db_onedev);
exit;
}
$sql = "
SELECT *
FROM t_test
WHERE
T_TestName like ?
AND T_TestIsActive = 'Y' AND T_TestIsResult = 'Y'
ORDER BY T_TestName 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("t_test rows", $this->db_onedev);
exit;
}
}
}

View File

@@ -0,0 +1,882 @@
<?php
class Maplocaltest extends MY_Controller
{
var $db;
public function index()
{
echo "PATIENT API";
}
public function __construct()
{
parent::__construct();
// $this->db_onedev = $this->load->database("onedev", true);
}
function lookupbranchbyname()
{
try {
//# cek token valid
if (!$this->isLogin) {
$this->sys_error("Invalid Token");
exit;
}
$prm = $this->sys_input;
$branchname = $prm['branchname'];
$filter = '';
$limit = '';
if ($all == 'N') {
$limit = ' LIMIT 50';
}
$number_limit = 50;
$number_offset = ($prm['current_page'] - 1) * $number_limit;
$sql = "SELECT COUNT(*) as total FROM
(SELECT *
FROM m_branch
WHERE M_BranchIsActive = 'Y' AND
M_BranchName LIKE CONCAT('%', ?, '%')
GROUP BY M_BranchID) x";
// $total = $this->db_onedev->query($sql,$sql_param)->row()->total;
$query = $this->db->query($sql, array($branchname));
//echo $this->db->last_query();
$tot_count = 0;
$tot_page = 0;
if ($query) {
$tot_count = $query->result_array()[0]["total"];
$tot_page = ceil($tot_count / $number_limit);
} else {
$this->sys_error_db("m_branch count", $this->db);
exit;
}
$sql = "SELECT M_BranchID as id,
M_BranchID,
M_BranchCode,
M_BranchName,
M_BranchCodeBridging
FROM m_branch
WHERE M_BranchIsActive = 'Y' AND
M_BranchName LIKE CONCAT('%', ?, '%')
GROUP BY M_BranchID
ORDER BY M_BranchName ASC
limit $number_limit offset $number_offset";
// $sql_param = array($search);
$query = $this->db->query($sql, array($branchname));
// echo $this->db->last_query();
if ($query) {
$rows = $query->result_array();
} else {
$this->sys_error_db("m_branch select");
exit;
}
$result = array("total" => $tot_page, "total_filter" => count($rows), "records" => $rows);
$this->sys_ok($result);
} catch (Exception $exc) {
$message = $exc->getMessage();
$this->sys_error($message);
}
}
function addfisik()
{
try {
//# cek token valid
if (!$this->isLogin) {
$this->sys_error("Invalid Token");
exit;
}
$this->db->trans_begin();
$prm = $this->sys_input;
$userid = $this->sys_user['M_UserID'];
$name = "";
if (isset($prm["name"])) {
$name = trim($prm["name"]);
}
$sql = "INSERT INTO fisik_template_mapping(
FisikTemplateMappingName,
FisikTemplateMappingCreated,
FisikTemplateMappingCreatedUserID,
FisikTemplateMappingLastUpdated
) VALUES(?,NOW(),?,NOW())";
$qry = $this->db->query($sql, array($name, $userid));
if (!$qry) {
$this->db->trans_rollback();
$this->sys_error_db("save fisik_template_mapping error", $this->db);
exit;
}
$this->db->trans_commit();
$result = array(
"total" => 1,
"affected_rows" => $this->db->affected_rows()
);
$this->sys_ok($result);
} catch (Exception $exc) {
$message = $exc->getMessage();
$this->sys_error($message);
}
}
function lookupdetailbyid()
{
try {
//# cek token valid
if (!$this->isLogin) {
$this->sys_error("Invalid Token");
exit;
}
$prm = $this->sys_input;
$id = $prm['id'];
$code = $prm['code'];
$name = $prm['name'];
$status = $prm['status'];
// $filter = '';
// if ($status != 'A') {
// $filter .= "AND status = '{$status}' ";
// } else {
// $filter .= "";
// }
$limit = '';
if ($all == 'N') {
$limit = ' LIMIT 50';
}
$number_limit = 50;
$number_offset = ($prm['current_page'] - 1) * $number_limit;
$sql = "SELECT COUNT(*) as total
FROM (
SELECT DISTINCT Nat_TestID as id,
Nat_TestID,
Nat_TestCode,
Nat_TestName,
IF(IFNULL(Nat_TestReferID, 0) > 0, 'Y', 'N') AS status
FROM nat_test
LEFT JOIN nat_testrefer ON Nat_TestReferNat_TestID = Nat_TestID AND
Nat_TestReferM_BranchID = ? AND Nat_TestReferIsActive = 'Y'
WHERE Nat_TestIsActive = 'Y' AND
(? = 'A' OR ((? = 'Y') AND Nat_TestReferID IS NOT NULL) OR (? = 'N' AND Nat_TestReferID IS NULL)) AND
Nat_TestCode LIKE CONCAT('%', ?, '%') AND
Nat_TestName LIKE CONCAT('%', ?, '%')
ORDER BY Nat_TestCode ASC
) x";
// $total = $this->db->query($sql,$sql_param)->row()->total;
$query = $this->db->query($sql, array($id, $status, $status, $status, $code, $name));
//echo $this->db->last_query();
$tot_count = 0;
$tot_page = 0;
if ($query) {
$tot_count = $query->result_array()[0]["total"];
$tot_page = ceil($tot_count / $number_limit);
} else {
$this->sys_error_db("fisik_template count", $this->db);
exit;
}
$sql = "SELECT DISTINCT Nat_TestID as id,
Nat_TestID,
Nat_TestCode,
Nat_TestName,
IF(IFNULL(Nat_TestReferID, 0) > 0, 'Y', 'N') AS status
FROM nat_test
LEFT JOIN nat_testrefer ON Nat_TestReferNat_TestID = Nat_TestID AND
Nat_TestReferM_BranchID = ? AND Nat_TestReferIsActive = 'Y'
WHERE Nat_TestIsActive = 'Y' AND
(? = 'A' OR ((? = 'Y') AND Nat_TestReferID IS NOT NULL) OR (? = 'N' AND Nat_TestReferID IS NULL)) AND
Nat_TestCode LIKE CONCAT('%', ?, '%') AND
Nat_TestName LIKE CONCAT('%', ?, '%')
ORDER BY Nat_TestCode ASC
limit $number_limit offset $number_offset";
$query = $this->db->query($sql, array($id, $status, $status, $status, $code, $name));
//echo $this->db->last_query();
if ($query) {
$rows = $query->result_array();
foreach ($rows as $key => $value) {
$rows[$key]['xjson'] = json_decode($value['xjson']);
}
} else {
$this->sys_error_db("fisik_template select");
exit;
}
$result = array("total" => $tot_page, "total_filter" => count($rows), "records" => $rows);
$this->sys_ok($result);
} catch (Exception $exc) {
$message = $exc->getMessage();
$this->sys_error($message);
}
}
public function saveaddeditfisikdetail()
{
try {
//# cek token valid
if (!$this->isLogin) {
$this->sys_error("Invalid Token");
exit;
}
//# ambil parameter input
$prm = $this->sys_input;
$id = $prm['id'];
$nat_testid = $prm['nat_testid'];
$new_status = $prm['new_status'];
$userid = $this->sys_user['M_UserID'];
$sql = "UPDATE nat_testrefer SET
Nat_TestReferIsActive = 'N',
Nat_TestReferDeleted = NOW(),
Nat_TestReferDeletedUserID = ?
WHERE Nat_TestReferNat_TestID = ?AND Nat_TestReferM_BranchID = ? AND Nat_TestReferIsActive = 'Y'";
$query = $this->db->query($sql, array($userid, $nat_testid, $id));
if (!$query) {
$this->sys_error_db("nat_testrefer update", $this->db);
exit;
}
if($new_status == 'Y'){
$sql = "INSERT INTO nat_testrefer(
Nat_TestReferNat_TestID,
Nat_TestReferM_BranchID,
Nat_TestReferCreated,
Nat_TestReferCreatedUserID
) VALUES(?,?,NOW(),?)";
$query = $this->db->query($sql, array($nat_testid, $id, $userid));
if (!$query) {
$this->sys_error_db("nat_testrefer insert", $this->db);
exit;
}
}
$result = array("total" => 1, "records" => array("xid" => 0));
$this->sys_ok($result);
} catch (Exception $exc) {
$message = $exc->getMessage();
$this->sys_error($message);
}
}
function lookupuserbyname()
{
try {
//# cek token valid
if (!$this->isLogin) {
$this->sys_error("Invalid Token");
exit;
}
$prm = $this->sys_input;
$groupname = $prm['groupname'];
$filter = '';
if (isset($sexid)) {
$filter .= "AND ($sexid = 0 or ($sexid > 0 and Nat_SexID = $sexid)) ";
}
if (isset($flagid)) {
$filter .= "AND ($flagid = 0 or ($flagid > 0 and Nat_FlagID = $flagid))";
}
$limit = '';
if ($all == 'N') {
$limit = ' LIMIT 10';
}
$number_limit = 10;
$number_offset = ($prm['current_page'] - 1) * $number_limit;
$sql = "select COUNT(*) as total
FROM(SELECT *
from m_usergroup
WHERE
M_UserGroupIsActive = 'Y' AND
M_UserGroupName like '%{$groupname}%'
$filter GROUP BY M_UserGroupID) a";
// $total = $this->db_onedev->query($sql,$sql_param)->row()->total;
$query = $this->db_onedev->query($sql);
//echo $this->db_onedev->last_query();
$tot_count = 0;
$tot_page = 0;
if ($query) {
$tot_count = $query->result_array()[0]["total"];
$tot_page = ceil($tot_count / $number_limit);
} else {
$this->sys_error_db("m_usergroup count", $this->db_onedev);
exit;
}
$sql = "SELECT m_usergroup.*,
M_UserGroupID as id,
M_UserGroupID,
M_UserGroupName
FROM m_usergroup
WHERE
M_UserGroupIsActive = 'Y' AND
M_UserGroupName like '%{$groupname}%'
$filter
GROUP BY M_UserGroupID
ORDER BY M_UserGroupName ASC
limit $number_limit offset $number_offset";
$sql_param = array($search);
$query = $this->db_onedev->query($sql);
// echo $this->db_onedev->last_query();
if ($query) {
$rows = $query->result_array();
} else {
$this->sys_error_db("m_usergroup select");
exit;
}
$result = array("total" => $tot_page, "total_filter" => count($rows), "records" => $rows);
$this->sys_ok($result);
} catch (Exception $exc) {
$message = $exc->getMessage();
$this->sys_error($message);
}
}
function lookupreportbyid()
{
try {
//# cek token valid
if (!$this->isLogin) {
$this->sys_error("Invalid Token");
exit;
}
$prm = $this->sys_input;
$id = $prm['id'];
$reportgroup = $prm['reportgroup'];
$reportcode = $prm['reportcode'];
$reportname = $prm['reportname'];
$status = $prm['status'];
$all = $prm['all'];
$filter = '';
if ($status != 'A') {
$filter .= "AND status = '{$status}' ";
} else {
$filter .= "";
}
$limit = '';
if ($all == 'N') {
$limit = ' LIMIT 10';
}
$number_limit = 10;
$number_offset = ($prm['current_page'] - 1) * $number_limit;
$sql = "select COUNT(*) as total
FROM(SELECT *, IF(IFNULL(UserGroupReportID,0) > 0 , 'Y', 'N') as status
from r_report
LEFT JOIN usergroup_report ON R_ReportID = UserGroupReportR_ReportID AND UserGroupReportM_UserGroupID = $id AND UserGroupReportIsActive = 'Y'
LEFT JOIN m_usergroup ON UserGroupReportM_UserGroupID = M_UserGroupID AND M_UserGroupIsActive = 'Y'
LEFT JOIN r_reportgroup ON R_ReportR_ReportGroupID = R_ReportGroupID
WHERE
R_ReportIsActive = 'Y') a
WHERE
R_ReportGroupName like '%{$reportgroup}%' AND
R_ReportCode like '%{$reportcode}%' AND
R_ReportName like '%{$reportname}%' $filter";
// $total = $this->db_onedev->query($sql,$sql_param)->row()->total;
$query = $this->db_onedev->query($sql);
//echo $this->db_onedev->last_query();
$tot_count = 0;
$tot_page = 0;
if ($query) {
$tot_count = $query->result_array()[0]["total"];
$tot_page = ceil($tot_count / $number_limit);
} else {
$this->sys_error_db("r_report count", $this->db_onedev);
exit;
}
$sql = "SELECT * FROM(select R_ReportID as id,
R_ReportID,
R_ReportCode,
R_ReportName,
R_ReportGroupName,
UserGroupReportID,
UserGroupReportM_UserGroupID,
UserGroupReportR_ReportID,
IF(IFNULL(UserGroupReportID,0) > 0 , 'Y', 'N') as status
from r_report
LEFT JOIN usergroup_report ON R_ReportID = UserGroupReportR_ReportID AND UserGroupReportM_UserGroupID = $id AND UserGroupReportIsActive = 'Y'
LEFT JOIN m_usergroup ON UserGroupReportM_UserGroupID = M_UserGroupID AND M_UserGroupIsActive = 'Y'
LEFT JOIN r_reportgroup ON R_ReportR_ReportGroupID = R_ReportGroupID
WHERE
R_ReportIsActive = 'Y') a
WHERE
R_ReportGroupName like '%{$reportgroup}%' AND
R_ReportCode like '%{$reportcode}%' AND
R_ReportName like '%{$reportname}%' $filter
GROUP BY R_ReportID
ORDER BY R_ReportGroupName ASC, R_ReportName ASC
limit $number_limit offset $number_offset";
$sql_param = array($search);
$query = $this->db_onedev->query($sql);
//echo $this->db_onedev->last_query();
if ($query) {
$rows = $query->result_array();
} else {
$this->sys_error_db("r_report select");
exit;
}
$result = array("total" => $tot_page, "total_filter" => count($rows), "records" => $rows);
$this->sys_ok($result);
} catch (Exception $exc) {
$message = $exc->getMessage();
$this->sys_error($message);
}
}
function getsexreg()
{
if (!$this->isLogin) {
$this->sys_error("Invalid Token");
exit;
}
$rows = [];
$query = "
SELECT 'A' as M_StatusID, 'Semua' as M_StatusName
UNION
SELECT 'Y' as M_StatusID, 'Terpilih' as M_StatusName
UNION
SELECT 'N' as M_StatusID, 'Belum Terpilih' as M_StatusName
";
//echo $query;
$rows['f_statuss'] = $this->db_onedev->query($query)->result_array();
$result = array(
"total" => count($rows),
"records" => $rows,
);
$this->sys_ok($result);
exit;
}
function getstatus()
{
if (!$this->isLogin) {
$this->sys_error("Invalid Token");
exit;
}
$rows = [];
$query = "
SELECT 'A' as M_StatusID, 'Semua' as M_StatusName
UNION
SELECT 'Y' as M_StatusID, 'Terpilih' as M_StatusName
UNION
SELECT 'N' as M_StatusID, 'Belum Terpilih' as M_StatusName
";
//echo $query;
$rows['f_statuss'] = $this->db_onedev->query($query)->result_array();
$result = array(
"total" => count($rows),
"records" => $rows,
);
$this->sys_ok($result);
exit;
}
public function addnewreport()
{
try {
//# cek token valid
if (!$this->isLogin) {
$this->sys_error("Invalid Token");
exit;
}
//# ambil parameter input
$prm = $this->sys_input;
$userid = $prm['userid'];
$reportcode = $prm['reportcode'];
$reportname = $prm['reportname'];
$userid = $this->sys_user["M_UserID"];
$sql = "insert into r_report(
R_ReportCode,
R_ReportName,
R_ReportUserID,
R_ReportCreated,
R_ReportLastUpdated
)
values(?,?,?,now(),now())";
$query = $this->db_onedev->query(
$sql,
array(
$reportcode,
$reportname,
$userid
)
);
if (!$query) {
$this->sys_error_db("m_usergroup insert", $this->db_onedev);
exit;
}
$last_id = $this->db_onedev->insert_id();
$result = array("total" => 1, "records" => array("xid" => 0));
$this->sys_ok($result);
} catch (Exception $exc) {
$message = $exc->getMessage();
$this->sys_error($message);
}
}
public function saveaddeditreport()
{
try {
//# cek token valid
if (!$this->isLogin) {
$this->sys_error("Invalid Token");
exit;
}
//# ambil parameter input
$prm = $this->sys_input;
$usergroupid = $prm['userid'];
$reportid = $prm['R_ReportID'];
$reportuserid = $prm['UserGroupReportID'];
$status = $prm['status'];
$userid = $this->sys_user["M_UserID"];
if ($status == 'Y') {
$sql = "insert into usergroup_report(
UserGroupReportM_UserGroupID,
UserGroupReportR_ReportID,
UserGroupUserID,
UserGroupReportCreated,
UserGroupReportLastUpdated
)
values(?,?,?,now(),now())";
$query = $this->db_onedev->query(
$sql,
array(
$usergroupid,
$reportid,
$userid
)
);
if (!$query) {
$this->sys_error_db("usergroup_report insert", $this->db_onedev);
exit;
}
$last_id = $this->db_onedev->insert_id();
$result = array("total" => 1, "records" => array("xid" => 0));
$this->sys_ok($result);
} else {
$sql = "UPDATE usergroup_report SET
UserGroupReportIsActive = 'N',
UserGroupUserID = ?,
UserGroupReportCreated = now(),
UserGroupReportLastUpdated = now()
WHERE UserGroupReportID = ?";
$query = $this->db_onedev->query(
$sql,
array(
$userid,
$reportuserid
)
);
if (!$query) {
$this->sys_error_db("usergroup_report insert", $this->db_onedev);
exit;
}
$last_id = $this->db_onedev->insert_id();
$result = array("total" => 1, "records" => array("xid" => 0));
$this->sys_ok($result);
}
} catch (Exception $exc) {
$message = $exc->getMessage();
$this->sys_error($message);
}
}
function saveallreport()
{
if (!$this->isLogin) {
$this->sys_error("Invalid Token");
exit;
}
$prm = $this->sys_input;
$details = $prm['details'];
$userid = $this->sys_user["M_UserID"];
foreach ($details as $k => $v) {
$query = "UPDATE usergroup_report SET
UserGroupReportM_UserGroupID = '{$v['UserGroupReportM_UserGroupID']}',
UserGroupReportAdviceIna = '{$v['UserGroupReportAdviceIna']}',
UserGroupReportAdviceEng = '{$v['UserGroupReportAdviceEng']}',
UserGroupReportUserID = {$userid},
UserGroupReportCreated = now(),
UserGroupReportLastUpdated = now()
WHERE UserGroupReportID = {$v['UserGroupReportID']}";
//echo $query;
$action = $this->db_onedev->query($query);
}
if ($action) {
$result = array(
"total" => 1,
"records" => array(),
);
$this->sys_ok($result);
exit;
} else {
$this->sys_error_db($this->db_onedev->last_query(), $this->db_onedev);
exit;
}
}
public function deleteuser()
{
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"];
$sql = "update nat_methode SET
Nat_MethodeIsActive = 'N'
WHERE
Nat_MethodeID = ?
";
$query = $this->db_onedev->query(
$sql,
array(
$prm['id']
)
);
// echo $query;
if (!$query) {
$this->sys_error_db("nat_methode delete");
exit;
}
$sql = "update m_usergroup SET
M_UserGroupIsActive = 'N'
WHERE
M_UserGroupNat_MethodeID = ?
";
$query = $this->db_onedev->query(
$sql,
array(
$prm['id']
)
);
// echo $query;
if (!$query) {
$this->sys_error_db("m_usergroup 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 deletereport()
{
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"];
$sql = "update m_usergroup SET
M_UserGroupIsActive = 'N'
WHERE
M_UserGroupID = ?
";
$query = $this->db_onedev->query(
$sql,
array(
$prm['id']
)
);
// echo $query;
if (!$query) {
$this->sys_error_db("m_usergroup delete");
exit;
}
$result = array("total" => 1, "records" => array("xid" => 0));
$this->sys_ok($result);
} catch (Exception $exc) {
$message = $exc->getMessage();
$this->sys_error($message);
}
}
function searchuser()
{
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 nat_methode
WHERE
Nat_MethodeName like ?
AND Nat_MethodeIsActive = '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("nat_methode count", $this->db_onedev);
exit;
}
$sql = "
SELECT Nat_MethodeID, Nat_MethodeName
FROM nat_methode
WHERE
Nat_MethodeName like ?
AND Nat_MethodeIsActive = 'Y'
ORDER BY Nat_MethodeName 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("nat_methode rows", $this->db_onedev);
exit;
}
}
function searchuserbyname()
{
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 nat_methode
WHERE
Nat_MethodeName like ?
AND Nat_MethodeIsActive = '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("nat_methode count", $this->db_onedev);
exit;
}
$sql = "
SELECT Nat_MethodeID, Nat_MethodeName
FROM nat_methode
WHERE
Nat_MethodeName like ?
AND Nat_MethodeIsActive = 'Y'
ORDER BY Nat_MethodeName 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("nat_methode 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'] != '') {
$q['search'] = "%{$prm['search']}%";
}
// QUERY TOTAL
$sql = "SELECT count(*) as total
FROM t_test
WHERE
T_TestName like ?
AND T_TestIsActive = 'Y' AND T_TestIsResult = '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("t_test count", $this->db_onedev);
exit;
}
$sql = "
SELECT *
FROM t_test
WHERE
T_TestName like ?
AND T_TestIsActive = 'Y' AND T_TestIsResult = 'Y'
ORDER BY T_TestName 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("t_test rows", $this->db_onedev);
exit;
}
}
}

View File

@@ -0,0 +1,16 @@
POST https://{{host}}/cpone/masterdata/nattestmap/index
Content-Type: "application/json"
{
}
###
POST https://{{host}}/cpone/masterdata/nattestmap/search
Content-Type: "application/json"
{
"search":"",
"current_page":1,
"token":"eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJNX1VzZXJJRCI6IjIiLCJNX1VzZXJFbWFpbCI6Impva29AZ21haWwuY29tIiwiTV9Vc2VyR3JvdXBEYXNoYm9hcmQiOiJvbmUtdWlcL3Rlc3RcL3Z1ZXhcL29uZS1mby1yZWdpc3RyYXRpb24tdjI3IiwiTV9Vc2VyRGVmYXVsdFRfU2FtcGxlU3RhdGlvbklEIjoiMSIsIk1fU3RhZmZOYW1lIjpudWxsLCJpc19jb3VyaWVyIjoiTiIsInRpbWVfYXV0b2xvZ291dCI6IjE1IiwiaXAiOiIxMzkuMTkyLjE3My42MiIsImFnZW50IjoiTW96aWxsYVwvNS4wIChXaW5kb3dzIE5UIDEwLjA7IFdpbjY0OyB4NjQpIEFwcGxlV2ViS2l0XC81MzcuMzYgKEtIVE1MLCBsaWtlIEdlY2tvKSBDaHJvbWVcLzEyNS4wLjAuMCBTYWZhcmlcLzUzNy4zNiIsInZlcnNpb24iOiJ2MiIsImxhc3QtbG9naW4iOiIyMDI0LTA2LTA2IDE2OjQ3OjAwIn0.5S84dVOQbpET7_L7vN-DZMr2uSWuhsxPZYtq-HvzKkI"
}

View File

@@ -0,0 +1,300 @@
<?php
class Nattestmap extends MY_Controller
{
var $db;
public function index()
{
echo "NAT TEST MAP API";
}
public function __construct()
{
parent::__construct();
// $this->db_onedev = $this->load->database("onedev", true);
}
function search()
{
try {
if (!$this->isLogin) {
$this->sys_error("Invalid Token");
exit;
}
$prm = $this->sys_input;
$search = "";
if (isset($prm['search'])) {
$search = trim($prm["search"]);
if ($search != "") {
$search = '%' . $prm['search'] . '%';
} else {
$search = '%%';
}
}
$status = $prm['status'];
// $all = $prm['all'];
$filter = '';
if ($status != 'A') {
$filter .= "AND status = '{$status}' ";
} else {
$filter .= "";
}
$number_offset = 0;
$number_limit = 10;
if ($prm["current_page"] > 0) {
$number_offset = ($prm["current_page"] - 1) * $number_limit;
}
$total_result = 0;
$total_belum_result = 0;
$total_price = 0;
$total_belum_price = 0;
$sql_result = "SELECT COUNT(*) AS total FROM
(SELECT
IF(ISNULL(Nat_TestMapID),'N','Y') as status,
Nat_TestID,
Nat_TestCode,
Nat_TestName,
Nat_TestMapID,
Nat_TestMapNat_TestID,
Nat_TestMapCode,
IFNULL(Nat_TestMapCode, '') AS TestMapCode
FROM nat_test
LEFT JOIN nat_testmap ON Nat_TestID = Nat_TestMapNat_TestID
AND Nat_TestMapIsActive = 'Y'
WHERE Nat_TestIsActive = 'Y'
AND Nat_TestIsResult = 'Y') x";
$qry_result = $this->db->query($sql_result);
if ($qry_result) {
$total_result = $qry_result->result_array()[0]["total"];
} else {
$this->sys_error_db("nat_test count", $this->db);
exit;
}
$sql_belum_result = "SELECT COUNT(*) AS total FROM
(SELECT
IF(ISNULL(Nat_TestMapID),'N','Y') as status,
Nat_TestID,
Nat_TestCode,
Nat_TestName,
Nat_TestMapID,
Nat_TestMapNat_TestID,
Nat_TestMapCode,
IFNULL(Nat_TestMapCode, '') AS TestMapCode
FROM nat_test
LEFT JOIN nat_testmap ON Nat_TestID = Nat_TestMapNat_TestID
AND Nat_TestMapIsActive = 'Y'
WHERE Nat_TestIsActive = 'Y'
AND Nat_TestIsResult = 'Y') x
WHERE status = 'N'";
$qry_belum_result = $this->db->query($sql_belum_result);
if ($qry_belum_result) {
$total_belum_result = $qry_belum_result->result_array()[0]["total"];
} else {
$this->sys_error_db("nat_test count", $this->db);
exit;
}
$sql_price = "SELECT COUNT(*) AS total FROM
(SELECT
IF(ISNULL(Nat_TestMapID),'N','Y') as status,
Nat_TestID,
Nat_TestCode,
Nat_TestName,
Nat_TestMapID,
Nat_TestMapNat_TestID,
Nat_TestMapCode,
IFNULL(Nat_TestMapCode, '') AS TestMapCode
FROM nat_test
LEFT JOIN nat_testmap ON Nat_TestID = Nat_TestMapNat_TestID
AND Nat_TestMapIsActive = 'Y'
WHERE Nat_TestIsActive = 'Y'
AND Nat_TestIsPrice = 'Y') x";
$qry_price = $this->db->query($sql_price);
if ($qry_price) {
$total_price = $qry_price->result_array()[0]["total"];
} else {
$this->sys_error_db("nat_test count", $this->db);
exit;
}
$sql_belum_price = "SELECT COUNT(*) AS total FROM
(SELECT
IF(ISNULL(Nat_TestMapID),'N','Y') as status,
Nat_TestID,
Nat_TestCode,
Nat_TestName,
Nat_TestMapID,
Nat_TestMapNat_TestID,
Nat_TestMapCode,
IFNULL(Nat_TestMapCode, '') AS TestMapCode
FROM nat_test
LEFT JOIN nat_testmap ON Nat_TestID = Nat_TestMapNat_TestID
AND Nat_TestMapIsActive = 'Y'
WHERE Nat_TestIsActive = 'Y'
AND Nat_TestIsPrice = 'Y') x
WHERE status = 'N'";
$qry_belum_price = $this->db->query($sql_belum_price);
if ($qry_belum_price) {
$total_belum_price = $qry_belum_price->result_array()[0]["total"];
} else {
$this->sys_error_db("nat_test count", $this->db);
exit;
}
$sql_tot = "SELECT COUNT(*) AS total FROM
(SELECT
IF(ISNULL(Nat_TestMapID),'N','Y') as status,
Nat_TestID,
Nat_TestCode,
Nat_TestName,
Nat_TestMapID,
Nat_TestMapNat_TestID,
Nat_TestMapCode,
IFNULL(Nat_TestMapCode, '') AS TestMapCode
FROM nat_test
LEFT JOIN nat_testmap ON Nat_TestID = Nat_TestMapNat_TestID
AND Nat_TestMapIsActive = 'Y'
WHERE Nat_TestIsActive = 'Y'
AND (Nat_TestIsResult = 'Y'
OR Nat_TestIsPrice = 'Y')) x
WHERE (Nat_TestCode LIKE ? OR Nat_TestName LIKE ? OR TestMapCode LIKE ?) $filter
";
$qry_tot = $this->db->query($sql_tot, [$search, $search, $search]);
$tot_count = 0;
$tot_page = 0;
if ($qry_tot) {
$tot_count = $qry_tot->result_array()[0]["total"];
$tot_page = ceil($tot_count / $number_limit);
} else {
$this->sys_error_db("nat_test count", $this->db);
exit;
}
$sql = "SELECT * FROM
(SELECT
IF(ISNULL(Nat_TestMapID),'N','Y') as status,
Nat_TestID,
Nat_TestCode,
Nat_TestName,
Nat_TestMapID,
Nat_TestMapNat_TestID,
Nat_TestMapCode,
IFNULL(Nat_TestMapCode, '') AS TestMapCode
FROM nat_test
LEFT JOIN nat_testmap ON Nat_TestID = Nat_TestMapNat_TestID
AND Nat_TestMapIsActive = 'Y'
WHERE Nat_TestIsActive = 'Y'
AND (Nat_TestIsResult = 'Y'
OR Nat_TestIsPrice = 'Y')) x
WHERE (Nat_TestCode LIKE ? OR Nat_TestName LIKE ? OR TestMapCode LIKE ?)
$filter
ORDER BY Nat_TestCode ASC
LIMIT ? OFFSET ?";
$qry = $this->db->query($sql, [$search, $search, $search, $number_limit, $number_offset]);
// echo $this->db->last_query();
// exit;
if ($qry) {
$rows = $qry->result_array();
} else {
$this->sys_error_db("select nat_test error", $this->db);
exit;
}
$result = array(
"total_result" => $total_result,
"total_belum_result" => $total_belum_result,
"total_price" => $total_price,
"total_belum_price" => $total_belum_price,
"total_page" => $tot_page,
"total_filter" => $tot_count,
"records" => $rows
);
$this->sys_ok($result);
} catch (Exception $exc) {
$message = $exc->getMessage();
$this->sys_error($message);
}
}
function saverow()
{
try {
if (!$this->isLogin) {
$this->sys_error("Invalid Token");
exit;
}
$this->db->trans_begin();
$prm = $this->sys_input;
$userid = $this->sys_user["M_UserID"];
if ($prm["Nat_TestMapID"]) {
// print_r("sudah ada sample id");
// exit;
$sql = "UPDATE nat_testmap SET
Nat_TestMapCode = '{$prm["codeMapping"]}',
Nat_TestMapLastUpdated = NOW(),
Nat_TestMapUserID = '{$userid}'
WHERE Nat_TestMapID = {$prm["Nat_TestMapID"]}";
$qry = $this->db->query($sql);
if (!$qry) {
$this->db->trans_rollback();
$this->sys_error_db("update nat_testmap error", $this->db);
exit;
}
$sql_selec_del = "SELECT Nat_TestMapID,
Nat_TestMapCode
FROM nat_testmap
WHERE Nat_TestMapIsActive = 'Y'
AND Nat_TestMapID = {$prm["Nat_TestMapID"]}";
$row = $this->db->query($sql_selec_del)->row_array();
if ($row["Nat_TestMapCode"] == "") {
$sql_del = "DELETE FROM nat_testmap
WHERE Nat_TestMapID = {$prm["Nat_TestMapID"]}";
$qry_del = $this->db->query($sql_del);
if (!$qry_del) {
$this->db->trans_rollback();
$this->sys_error_db("delete nat_testmap error", $this->db);
exit;
}
}
} else {
// print_r("belum ada sample id");
// exit;
$sql = "INSERT INTO nat_testmap(
Nat_TestMapNat_TestID,
Nat_TestMapCode,
Nat_TestMapCreated,
Nat_TestMapLastUpdated,
Nat_TestMapUserID
) VALUES(
{$prm["Nat_TestID"]},
'{$prm["codeMapping"]}',
NOW(),
NOW(),
{$userid})";
$qry = $this->db->query($sql);
if (!$qry) {
$this->db->trans_rollback();
$this->sys_error_db("nat_testmap insert error", $this->db);
exit;
}
}
$this->db->trans_commit();
$result = array(
"total" => 1,
"records" => array("xid" => 0)
);
$this->sys_ok($result);
} catch (Exception $exc) {
$message = $exc->getMessage();
$this->sys_error($message);
}
}
}

View File

@@ -0,0 +1,19 @@
POST https://{{host}}/cpone/masterdata/nonlabtemplate/search
Content-Type: "application/json"
{
"search":"",
"current_page":1,
"token":"eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJNX1VzZXJJRCI6IjIiLCJNX1VzZXJFbWFpbCI6Impva29AZ21haWwuY29tIiwiTV9Vc2VyR3JvdXBEYXNoYm9hcmQiOiJvbmUtdWlcL3Rlc3RcL3Z1ZXhcL29uZS1mby1yZWdpc3RyYXRpb24tdjI3IiwiTV9Vc2VyRGVmYXVsdFRfU2FtcGxlU3RhdGlvbklEIjoiMSIsIk1fU3RhZmZOYW1lIjpudWxsLCJpc19jb3VyaWVyIjoiTiIsInRpbWVfYXV0b2xvZ291dCI6IjE1IiwiaXAiOiIxMzkuMTkyLjE3My42MiIsImFnZW50IjoiTW96aWxsYVwvNS4wIChXaW5kb3dzIE5UIDEwLjA7IFdpbjY0OyB4NjQpIEFwcGxlV2ViS2l0XC81MzcuMzYgKEtIVE1MLCBsaWtlIEdlY2tvKSBDaHJvbWVcLzEyNS4wLjAuMCBTYWZhcmlcLzUzNy4zNiIsInZlcnNpb24iOiJ2MiIsImxhc3QtbG9naW4iOiIyMDI0LTA2LTA2IDE2OjQ3OjAwIn0.5S84dVOQbpET7_L7vN-DZMr2uSWuhsxPZYtq-HvzKkI"
}
###
POST https://{{host}}/cpone/masterdata/nonlabtemplate/searchdetail
Content-Type: "application/json"
{
"nonlabID": 2,
"search":"",
"current_page":1,
"token":"eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJNX1VzZXJJRCI6IjIiLCJNX1VzZXJFbWFpbCI6Impva29AZ21haWwuY29tIiwiTV9Vc2VyR3JvdXBEYXNoYm9hcmQiOiJvbmUtdWlcL3Rlc3RcL3Z1ZXhcL29uZS1mby1yZWdpc3RyYXRpb24tdjI3IiwiTV9Vc2VyRGVmYXVsdFRfU2FtcGxlU3RhdGlvbklEIjoiMSIsIk1fU3RhZmZOYW1lIjpudWxsLCJpc19jb3VyaWVyIjoiTiIsInRpbWVfYXV0b2xvZ291dCI6IjE1IiwiaXAiOiIxMzkuMTkyLjE3My42MiIsImFnZW50IjoiTW96aWxsYVwvNS4wIChXaW5kb3dzIE5UIDEwLjA7IFdpbjY0OyB4NjQpIEFwcGxlV2ViS2l0XC81MzcuMzYgKEtIVE1MLCBsaWtlIEdlY2tvKSBDaHJvbWVcLzEyNS4wLjAuMCBTYWZhcmlcLzUzNy4zNiIsInZlcnNpb24iOiJ2MiIsImxhc3QtbG9naW4iOiIyMDI0LTA2LTA2IDE2OjQ3OjAwIn0.5S84dVOQbpET7_L7vN-DZMr2uSWuhsxPZYtq-HvzKkI"
}

View File

@@ -0,0 +1,486 @@
<?php
class Nonlabtemplate extends MY_Controller
{
var $db;
public function index()
{
echo "NON LAN TEMPLATE API";
}
public function __construct()
{
parent::__construct();
}
function search()
{
try {
if (!$this->isLogin) {
$this->sys_error("Invalid Token");
exit;
}
$prm = $this->sys_input;
$search = "";
if (isset($prm['search'])) {
$search = trim($prm["search"]);
if ($search != "") {
$search = '%' . $prm['search'] . '%';
} else {
$search = '%%';
}
}
$number_offset = 0;
$number_limit = 10;
if ($prm["current_page"] > 0) {
$number_offset = ($prm["current_page"] - 1) * $number_limit;
}
$sql_tot = "SELECT COUNT(*) as total
FROM nonlab_template
WHERE NonlabTemplateIsActive = 'Y'
AND (NonlabTemplateName LIKE ?)";
$qry_tot = $this->db->query($sql_tot, [$search]);
$tot_count = 0;
$tot_page = 0;
if ($qry_tot) {
$tot_count = $qry_tot->result_array()[0]["total"];
$tot_page = ceil($tot_count / $number_limit);
} else {
$this->sys_error_db("nonlab template count", $this->db);
exit;
}
$sql = "SELECT
NonlabTemplateID,
NonlabTemplateName,
NonlabTemplateFlagOther,
NonlabTemplateIsActive,
NonlabTemplateCreated,
NonlabTemplateLastUpdated
FROM nonlab_template
WHERE NonlabTemplateIsActive = 'Y'
AND (NonlabTemplateName LIKE ?)
ORDER BY NonlabTemplateID ASC
LIMIT ? OFFSET ?";
$qry = $this->db->query($sql, [$search, $number_limit, $number_offset]);
if ($qry) {
$rows = $qry->result_array();
} else {
$this->sys_error_db("select nonlab template", $this->db);
exit;
}
$result = array(
"total_page" => $tot_page,
"total_filter" => $tot_count,
"records" => $rows
);
$this->sys_ok($result);
} catch (Exception $exc) {
$message = $exc->getMessage();
$this->sys_error($message);
}
}
function addnonlab()
{
try {
if (!$this->isLogin) {
$this->sys_error("Invalid Token");
exit;
}
$this->db->trans_begin();
$prm = $this->sys_input;
$userid = $this->sys_user['M_UserID'];
$name = "";
if (isset($prm["name"])) {
$name = trim($prm["name"]);
}
$isfisik = "";
if (isset($prm["isfisik"])) {
$isfisik = trim($prm["isfisik"]);
}
$sql = "INSERT INTO nonlab_template(
NonlabTemplateName,
NonlabTemplateFlagOther,
NonlabTemplateCreated,
NonlabTemplateCreatedUserID,
NonlabTemplateLastUpdated,
NonlabTemplateLastUpdatedUserID
) VALUES(?,?,NOW(),?,NOW(),?)";
$qry = $this->db->query($sql, array(
$name,
$isfisik,
$userid,
$userid
));
$last_qry = $this->db->last_query();
if (!$qry) {
$this->db->trans_rollback();
$error = array(
"message" => $this->db->error()["message"],
"sql" => $last_qry
);
$this->sys_error_db($error, $this->db);
exit;
}
$this->db->trans_commit();
$result = array(
"total" => 1,
"affected_rows" => $this->db->affected_rows()
);
$this->sys_ok($result);
} catch (Exception $exc) {
$message = $exc->getMessage();
$this->sys_error($message);
}
}
function editnonlab()
{
try {
if (!$this->isLogin) {
$this->sys_error("Invalid Token");
exit;
}
$this->db->trans_begin();
$prm = $this->sys_input;
$userid = $this->sys_user['M_UserID'];
$name = "";
if (isset($prm["name"])) {
$name = trim($prm["name"]);
}
$isfisik = "";
if (isset($prm["isfisik"])) {
$isfisik = trim($prm["isfisik"]);
}
$id = "";
if (isset($prm["id"])) {
$id = trim($prm["id"]);
}
$sql = "UPDATE nonlab_template
SET NonlabTemplateName = ?,
NonlabTemplateFlagOther = ?,
NonlabTemplateLastUpdated = NOW(),
NonlabTemplateLastUpdatedUserID = ?
WHERE NonlabTemplateID = ?";
$qry = $this->db->query($sql, array($name, $isfisik, $userid, $id));
$last_qry = $this->db->last_query();
if (!$qry) {
$this->db->trans_rollback();
$error = array(
"message" => $this->db->error()["message"],
"sql" => $last_qry
);
$this->sys_error_db($error, $this->db);
exit;
}
$this->db->trans_commit();
$result = array(
"total" => 1,
"affected_rows" => $this->db->affected_rows()
);
$this->sys_ok($result);
} catch (Exception $exc) {
$message = $exc->getMessage();
$this->sys_error($message);
}
}
function deletenonlab()
{
try {
if (!$this->isLogin) {
$this->sys_error("Invalid Token");
exit;
}
$this->db->trans_begin();
$prm = $this->sys_input;
$userid = $this->sys_user['M_UserID'];
$id = "";
if (isset($prm["id"])) {
$id = trim($prm["id"]);
}
$sql = "UPDATE nonlab_template
SET NonlabTemplateIsActive = 'N',
NonlabTemplateDelete = NOW(),
NonlabTemplateDeleteUserID = ?
WHERE NonlabTemplateID = ?";
$qry = $this->db->query($sql, array($userid, $id));
$last_qry = $this->db->last_query();
if (!$qry) {
$this->db->trans_rollback();
$error = array(
"message" => $this->db->error()["message"],
"sql" => $last_qry
);
$this->sys_error_db($error, $this->db);
exit;
}
$this->db->trans_commit();
$result = array(
"total" => 1,
"affected_rows" => $this->db->affected_rows()
);
$this->sys_ok($result);
} catch (Exception $exc) {
$message = $exc->getMessage();
$this->sys_error($message);
}
}
function searchdetail()
{
try {
if (!$this->isLogin) {
$this->sys_error("Invalid Token");
exit;
}
$prm = $this->sys_input;
$search = "";
if (isset($prm['search'])) {
$search = trim($prm["search"]);
if ($search != "") {
$search = '%' . $prm['search'] . '%';
} else {
$search = '%%';
}
}
$nonlabID = $prm["nonlabID"];
$number_offset = 0;
$number_limit = 10;
if ($prm["current_page"] > 0) {
$number_offset = ($prm["current_page"] - 1) * $number_limit;
}
$sql_total = "SELECT COUNT(*) as total
FROM nonlab_template_detail
WHERE NonlabTemplateDetailNonlabTemplateID = ?
AND NonlabTemplateDetailIsActive = 'Y'
AND (NonlabTemplateDetailCode LIKE ? OR NonlabTemplateDetailName LIKE ?)";
$qry_total = $this->db->query($sql_total, [$nonlabID, $search, $search]);
$tot_count = 0;
$tot_page = 0;
if ($qry_total) {
$tot_count = $qry_total->result_array()[0]["total"];
$tot_page = ceil($tot_count / $number_limit);
} else {
$this->sys_error_db("nonlab template detail count", $this->db);
exit;
}
$sql = "SELECT
NonlabTemplateDetailID,
NonlabTemplateDetailNonlabTemplateID,
NonlabTemplateDetailCode,
NonlabTemplateDetailName,
NonlabTemplateDetaiNat_UnitID,
NonlabTemplateDetailFlagActive,
NonlabTemplateDetaiM_LangID,
NonlabTemplateDetailIsActive
FROM nonlab_template_detail
WHERE NonlabTemplateDetailNonlabTemplateID = ?
AND NonlabTemplateDetailIsActive = 'Y'
AND (NonlabTemplateDetailCode LIKE ? OR NonlabTemplateDetailName LIKE ?)
limit ? offset ?";
$qry = $this->db->query($sql, [$nonlabID, $search, $search, $number_limit, $number_offset]);
if ($qry) {
$rows = $qry->result_array();
} else {
$this->sys_error_db("select nonlab template detail", $this->db);
exit;
}
$result = array(
"total_page" => $tot_page,
"total_filter" => $tot_count,
"records" => $rows
);
$this->sys_ok($result);
} catch (Exception $exc) {
$message = $exc->getMessage();
$this->sys_error($message);
}
}
function adddetail()
{
try {
if (!$this->isLogin) {
$this->sys_error("Invalid Token");
exit;
}
$this->db->trans_begin();
$prm = $this->sys_input;
$userid = $this->sys_user['M_UserID'];
$name = "";
if (isset($prm["name"])) {
$name = trim($prm["name"]);
}
$code = "";
if (isset($prm["code"])) {
$code = trim($prm["code"]);
}
$nonlabid = "";
if (isset($prm["nonlabid"])) {
$nonlabid = trim($prm["nonlabid"]);
}
$sql = "INSERT INTO nonlab_template_detail(
NonlabTemplateDetailNonlabTemplateID,
NonlabTemplateDetailCode,
NonlabTemplateDetailName,
NonlabTemplateDetailCreated,
NonlabTemplateDetailCreatedUserID,
NonlabTemplateDetailLastUpdated,
NonlabTemplateDetailLastUpdatedUserID
) VALUES(?,?,?,NOW(),?,NOW(),?)";
$qry = $this->db->query($sql, array(
$nonlabid,
$code,
$name,
$userid,
$userid
));
$last_qry = $this->db->last_query();
if (!$qry) {
$this->db->trans_rollback();
$error = array(
"message" => $this->db->error()["message"],
"sql" => $last_qry
);
$this->sys_error_db($error, $this->db);
exit;
}
$this->db->trans_commit();
$result = array(
"total" => 1,
"affected_rows" => $this->db->affected_rows()
);
$this->sys_ok($result);
} catch (Exception $exc) {
$message = $exc->getMessage();
$this->sys_error($message);
}
}
function deletedetail()
{
try {
if (!$this->isLogin) {
$this->sys_error("Invalid Token");
exit;
}
$this->db->trans_begin();
$prm = $this->sys_input;
$userid = $this->sys_user['M_UserID'];
$id = "";
if (isset($prm["id"])) {
$id = trim($prm["id"]);
}
$sql = "UPDATE nonlab_template_detail
SET NonlabTemplateDetailIsActive = 'N',
NonlabTemplateDetailDelete = NOW(),
NonlabTemplateDetailDeleteUserID = ?
WHERE NonlabTemplateDetailID = ?";
$qry = $this->db->query($sql, array($userid, $id));
$last_qry = $this->db->last_query();
if (!$qry) {
$this->db->trans_rollback();
$error = array(
"message" => $this->db->error()["message"],
"sql" => $last_qry
);
$this->sys_error_db($error, $this->db);
exit;
}
$this->db->trans_commit();
$result = array(
"total" => 1,
"affected_rows" => $this->db->affected_rows()
);
$this->sys_ok($result);
} catch (Exception $exc) {
$message = $exc->getMessage();
$this->sys_error($message);
}
}
function saveeditflag()
{
try {
if (!$this->isLogin) {
$this->sys_error("Invalid Token");
exit;
}
$this->db->trans_begin();
$prm = $this->sys_input;
$userid = $this->sys_user['M_UserID'];
$flagstatus = $prm['flagstatus'];
$templatedetailid = $prm['templatedetailid'];
if ($flagstatus == "Y") {
$sql = "UPDATE nonlab_template_detail
SET NonlabTemplateDetailFlagActive = 'Y',
NonlabTemplateDetailLastUpdated = NOW(),
NonlabTemplateDetailLastUpdatedUserID = ?
WHERE NonlabTemplateDetailID = ?";
$qry = $this->db->query($sql, array(
$userid,
$templatedetailid
));
// echo $this->db->last_query();
// exit;
if (!$qry) {
$this->sys_error_db("nonlab template detail avtive", $this->db);
exit;
}
$this->db->trans_commit();
$result = array("total" => 1, "records" => array("xid" => 0));
$this->sys_ok($result);
} else {
$sql = "UPDATE nonlab_template_detail
SET NonlabTemplateDetailFlagActive = 'N',
NonlabTemplateDetailLastUpdated = NOW(),
NonlabTemplateDetailLastUpdatedUserID = ?
WHERE NonlabTemplateDetailID = ?";
$qry = $this->db->query($sql, array(
$userid,
$templatedetailid
));
// echo $this->db->last_query();
// exit;
if (!$qry) {
$this->sys_error_db("nonlab template detail no avtive", $this->db);
exit;
}
$this->db->trans_commit();
$result = array("total" => 1, "records" => array("xid" => 0));
$this->sys_ok($result);
}
} catch (Exception $exc) {
$message = $exc->getMessage();
$this->sys_error($message);
}
}
}

View File

@@ -0,0 +1,716 @@
<?php
class Nonlabtemplatev2 extends MY_Controller
{
var $db;
public function index()
{
echo "NON LAN TEMPLATE API";
}
public function __construct()
{
parent::__construct();
}
function search()
{
try {
if (!$this->isLogin) {
$this->sys_error("Invalid Token");
exit;
}
$prm = $this->sys_input;
$search = "";
if (isset($prm['search'])) {
$search = trim($prm["search"]);
if ($search != "") {
$search = '%' . $prm['search'] . '%';
} else {
$search = '%%';
}
}
$number_offset = 0;
$number_limit = 10;
if ($prm["current_page"] > 0) {
$number_offset = ($prm["current_page"] - 1) * $number_limit;
}
$sql_tot = "SELECT COUNT(*) as total
FROM nonlab_template
WHERE NonlabTemplateIsActive = 'Y'
AND (NonlabTemplateName LIKE ?)";
$qry_tot = $this->db->query($sql_tot, [$search]);
$tot_count = 0;
$tot_page = 0;
if ($qry_tot) {
$tot_count = $qry_tot->result_array()[0]["total"];
$tot_page = ceil($tot_count / $number_limit);
} else {
$this->sys_error_db("nonlab template count", $this->db);
exit;
}
$sql = "SELECT
NonlabTemplateID,
NonlabTemplateName,
NonlabTemplateFlagOther,
NonlabTemplateIsActive,
NonlabTemplateCreated,
NonlabTemplateLastUpdated
FROM nonlab_template
WHERE NonlabTemplateIsActive = 'Y'
AND (NonlabTemplateName LIKE ?)
ORDER BY NonlabTemplateID ASC
LIMIT ? OFFSET ?";
$qry = $this->db->query($sql, [$search, $number_limit, $number_offset]);
if ($qry) {
$rows = $qry->result_array();
} else {
$this->sys_error_db("select nonlab template", $this->db);
exit;
}
$result = array(
"total_page" => $tot_page,
"total_filter" => $tot_count,
"records" => $rows
);
$this->sys_ok($result);
} catch (Exception $exc) {
$message = $exc->getMessage();
$this->sys_error($message);
}
}
function addnonlab()
{
try {
if (!$this->isLogin) {
$this->sys_error("Invalid Token");
exit;
}
$this->db->trans_begin();
$prm = $this->sys_input;
$userid = $this->sys_user['M_UserID'];
$name = "";
if (isset($prm["name"])) {
$name = trim($prm["name"]);
}
$isfisik = "";
if (isset($prm["isfisik"])) {
$isfisik = trim($prm["isfisik"]);
}
$sql = "INSERT INTO nonlab_template(
NonlabTemplateName,
NonlabTemplateFlagOther,
NonlabTemplateCreated,
NonlabTemplateCreatedUserID,
NonlabTemplateLastUpdated,
NonlabTemplateLastUpdatedUserID
) VALUES(?,?,NOW(),?,NOW(),?)";
$qry = $this->db->query($sql, array(
$name,
$isfisik,
$userid,
$userid
));
$last_qry = $this->db->last_query();
if (!$qry) {
$this->db->trans_rollback();
$error = array(
"message" => $this->db->error()["message"],
"sql" => $last_qry
);
$this->sys_error_db($error, $this->db);
exit;
}
$this->db->trans_commit();
$result = array(
"total" => 1,
"affected_rows" => $this->db->affected_rows()
);
$this->sys_ok($result);
} catch (Exception $exc) {
$message = $exc->getMessage();
$this->sys_error($message);
}
}
function editnonlab()
{
try {
if (!$this->isLogin) {
$this->sys_error("Invalid Token");
exit;
}
$this->db->trans_begin();
$prm = $this->sys_input;
$userid = $this->sys_user['M_UserID'];
$name = "";
if (isset($prm["name"])) {
$name = trim($prm["name"]);
}
$isfisik = "";
if (isset($prm["isfisik"])) {
$isfisik = trim($prm["isfisik"]);
}
$id = "";
if (isset($prm["id"])) {
$id = trim($prm["id"]);
}
$sql = "UPDATE nonlab_template
SET NonlabTemplateName = ?,
NonlabTemplateFlagOther = ?,
NonlabTemplateLastUpdated = NOW(),
NonlabTemplateLastUpdatedUserID = ?
WHERE NonlabTemplateID = ?";
$qry = $this->db->query($sql, array($name, $isfisik, $userid, $id));
$last_qry = $this->db->last_query();
if (!$qry) {
$this->db->trans_rollback();
$error = array(
"message" => $this->db->error()["message"],
"sql" => $last_qry
);
$this->sys_error_db($error, $this->db);
exit;
}
$this->db->trans_commit();
$result = array(
"total" => 1,
"affected_rows" => $this->db->affected_rows()
);
$this->sys_ok($result);
} catch (Exception $exc) {
$message = $exc->getMessage();
$this->sys_error($message);
}
}
function deletenonlab()
{
try {
if (!$this->isLogin) {
$this->sys_error("Invalid Token");
exit;
}
$this->db->trans_begin();
$prm = $this->sys_input;
$userid = $this->sys_user['M_UserID'];
$id = "";
if (isset($prm["id"])) {
$id = trim($prm["id"]);
}
$sql = "UPDATE nonlab_template
SET NonlabTemplateIsActive = 'N',
NonlabTemplateDelete = NOW(),
NonlabTemplateDeleteUserID = ?
WHERE NonlabTemplateID = ?";
$qry = $this->db->query($sql, array($userid, $id));
$last_qry = $this->db->last_query();
if (!$qry) {
$this->db->trans_rollback();
$error = array(
"message" => $this->db->error()["message"],
"sql" => $last_qry
);
$this->sys_error_db($error, $this->db);
exit;
}
$this->db->trans_commit();
$result = array(
"total" => 1,
"affected_rows" => $this->db->affected_rows()
);
$this->sys_ok($result);
} catch (Exception $exc) {
$message = $exc->getMessage();
$this->sys_error($message);
}
}
function searchdetail()
{
try {
if (!$this->isLogin) {
$this->sys_error("Invalid Token");
exit;
}
$prm = $this->sys_input;
$search = "";
if (isset($prm['search'])) {
$search = trim($prm["search"]);
if ($search != "") {
$search = '%' . $prm['search'] . '%';
} else {
$search = '%%';
}
}
$nonlabID = $prm["nonlabID"];
$number_offset = 0;
$number_limit = 10;
if ($prm["current_page"] > 0) {
$number_offset = ($prm["current_page"] - 1) * $number_limit;
}
$sql_total = "SELECT COUNT(*) as total
FROM nonlab_template_detail
WHERE NonlabTemplateDetailNonlabTemplateID = ?
AND NonlabTemplateDetailIsActive = 'Y'
AND (NonlabTemplateDetailCode LIKE ? OR NonlabTemplateDetailName LIKE ?)";
$qry_total = $this->db->query($sql_total, [$nonlabID, $search, $search]);
$tot_count = 0;
$tot_page = 0;
if ($qry_total) {
$tot_count = $qry_total->result_array()[0]["total"];
$tot_page = ceil($tot_count / $number_limit);
} else {
$this->sys_error_db("nonlab template detail count", $this->db);
exit;
}
$sql = "SELECT
NonlabTemplateDetailID,
NonlabTemplateDetailNonlabTemplateID,
NonlabTemplateDetailCode,
NonlabTemplateDetailName,
NonlabTemplateDetaiNat_UnitID,
NonlabTemplateDetailFlagActive,
NonlabTemplateDetaiM_LangID,
NonlabTemplateDetailIsActive
FROM nonlab_template_detail
WHERE NonlabTemplateDetailNonlabTemplateID = ?
AND NonlabTemplateDetailIsActive = 'Y'
AND (NonlabTemplateDetailCode LIKE ? OR NonlabTemplateDetailName LIKE ?)
limit ? offset ?";
$qry = $this->db->query($sql, [$nonlabID, $search, $search, $number_limit, $number_offset]);
if ($qry) {
$rows = $qry->result_array();
} else {
$this->sys_error_db("select nonlab template detail", $this->db);
exit;
}
$result = array(
"total_page" => $tot_page,
"total_filter" => $tot_count,
"records" => $rows
);
$this->sys_ok($result);
} catch (Exception $exc) {
$message = $exc->getMessage();
$this->sys_error($message);
}
}
function adddetail()
{
try {
if (!$this->isLogin) {
$this->sys_error("Invalid Token");
exit;
}
$this->db->trans_begin();
$prm = $this->sys_input;
$userid = $this->sys_user['M_UserID'];
$nonlabid = intval($prm["nonlabid"]);
if ($nonlabid === 0) {
$this->sys_error("Anda belum memilih nonlab template, silahkan pilih nonlab template dulu");
exit;
}
$name = "";
if (isset($prm["name"])) {
$name = trim($prm["name"]);
}
$code = "";
if (isset($prm["code"])) {
$code = trim($prm["code"]);
}
// $nonlabid = "";
// if (isset($prm["nonlabid"])) {
// $nonlabid = trim($prm["nonlabid"]);
// }
$sql = "INSERT INTO nonlab_template_detail(
NonlabTemplateDetailNonlabTemplateID,
NonlabTemplateDetailCode,
NonlabTemplateDetailName,
NonlabTemplateDetailCreated,
NonlabTemplateDetailCreatedUserID,
NonlabTemplateDetailLastUpdated,
NonlabTemplateDetailLastUpdatedUserID
) VALUES(?,?,?,NOW(),?,NOW(),?)";
$qry = $this->db->query($sql, array(
$nonlabid,
$code,
$name,
$userid,
$userid
));
$last_qry = $this->db->last_query();
if (!$qry) {
$this->db->trans_rollback();
$error = array(
"message" => $this->db->error()["message"],
"sql" => $last_qry
);
$this->sys_error_db($error, $this->db);
exit;
}
$this->db->trans_commit();
$result = array(
"total" => 1,
"affected_rows" => $this->db->affected_rows()
);
$this->sys_ok($result);
} catch (Exception $exc) {
$message = $exc->getMessage();
$this->sys_error($message);
}
}
function deletedetail()
{
try {
if (!$this->isLogin) {
$this->sys_error("Invalid Token");
exit;
}
$this->db->trans_begin();
$prm = $this->sys_input;
$userid = $this->sys_user['M_UserID'];
$id = "";
if (isset($prm["id"])) {
$id = trim($prm["id"]);
}
$sql = "UPDATE nonlab_template_detail
SET NonlabTemplateDetailIsActive = 'N',
NonlabTemplateDetailDelete = NOW(),
NonlabTemplateDetailDeleteUserID = ?
WHERE NonlabTemplateDetailID = ?";
$qry = $this->db->query($sql, array($userid, $id));
$last_qry = $this->db->last_query();
if (!$qry) {
$this->db->trans_rollback();
$error = array(
"message" => $this->db->error()["message"],
"sql" => $last_qry
);
$this->sys_error_db($error, $this->db);
exit;
}
$this->db->trans_commit();
$result = array(
"total" => 1,
"affected_rows" => $this->db->affected_rows()
);
$this->sys_ok($result);
} catch (Exception $exc) {
$message = $exc->getMessage();
$this->sys_error($message);
}
}
function saveeditflag()
{
try {
if (!$this->isLogin) {
$this->sys_error("Invalid Token");
exit;
}
$this->db->trans_begin();
$prm = $this->sys_input;
$userid = $this->sys_user['M_UserID'];
$flagstatus = $prm['flagstatus'];
$templatedetailid = $prm['templatedetailid'];
if ($flagstatus == "Y") {
$sql = "UPDATE nonlab_template_detail
SET NonlabTemplateDetailFlagActive = 'Y',
NonlabTemplateDetailLastUpdated = NOW(),
NonlabTemplateDetailLastUpdatedUserID = ?
WHERE NonlabTemplateDetailID = ?";
$qry = $this->db->query($sql, array(
$userid,
$templatedetailid
));
// echo $this->db->last_query();
// exit;
if (!$qry) {
$this->sys_error_db("nonlab template detail avtive", $this->db);
exit;
}
$this->db->trans_commit();
$result = array("total" => 1, "records" => array("xid" => 0));
$this->sys_ok($result);
} else {
$sql = "UPDATE nonlab_template_detail
SET NonlabTemplateDetailFlagActive = 'N',
NonlabTemplateDetailLastUpdated = NOW(),
NonlabTemplateDetailLastUpdatedUserID = ?
WHERE NonlabTemplateDetailID = ?";
$qry = $this->db->query($sql, array(
$userid,
$templatedetailid
));
// echo $this->db->last_query();
// exit;
if (!$qry) {
$this->sys_error_db("nonlab template detail no avtive", $this->db);
exit;
}
$this->db->trans_commit();
$result = array("total" => 1, "records" => array("xid" => 0));
$this->sys_ok($result);
}
} catch (Exception $exc) {
$message = $exc->getMessage();
$this->sys_error($message);
}
}
function editdetail()
{
try {
if (!$this->isLogin) {
$this->sys_error("Invalid Token");
exit;
}
$this->db->trans_begin();
$prm = $this->sys_input;
$userid = $this->sys_user['M_UserID'];
$name = "";
if (isset($prm["name"])) {
$name = trim($prm["name"]);
}
$code = "";
if (isset($prm["code"])) {
$code = trim($prm["code"]);
}
$id = "";
if (isset($prm["id"])) {
$id = trim($prm["id"]);
}
$sql = "UPDATE nonlab_template_detail SET
NonlabTemplateDetailCode = ?,
NonlabTemplateDetailName = ?,
NonlabTemplateDetailLastUpdated = NOW(),
NonlabTemplateDetailLastUpdatedUserID = ?
WHERE NonlabTemplateDetailID = ?";
$qry = $this->db->query($sql, array($code, $name, $userid, $id));
$last_qry = $this->db->last_query();
if (!$qry) {
$this->db->trans_rollback();
$error = array(
"message" => $this->db->error()["message"],
"sql" => $last_qry
);
$this->sys_error_db($error, $this->db);
exit;
}
$this->db->trans_commit();
$result = array(
"total" => 1,
"affected_rows" => $this->db->affected_rows()
);
$this->sys_ok($result);
} catch (Exception $exc) {
$message = $exc->getMessage();
$this->sys_error($message);
}
}
function lookuptest()
{
try {
if (!$this->isLogin) {
$this->sys_error("Invalid Token");
exit;
}
$prm = $this->sys_input;
$search = "";
if (isset($prm["search"])) {
$search = trim($prm["search"]);
if ($search != "") {
$search = "%" . $prm["search"] . "%";
} else {
$search = "%%";
}
}
$nonlabtemplate_id = 0;
if (isset($prm['nonlabtemplate_id'])) {
$nonlabtemplate_id = trim($prm["nonlabtemplate_id"]);
}
$status = $prm['status'];
$filter = '';
if ($status == 'Y') {
$filter .= "AND ntm.NonlabTemplateMappingNonlabTemplateID IS NOT NULL ";
} else {
if ($status == 'N') {
$filter .= "AND ntm.NonlabTemplateMappingNonlabTemplateID IS NULL ";
} else {
$filter .= "";
}
}
$number_offset = 0;
$number_limit = 10;
if ($prm["current_page"] > 0) {
$number_offset = ($prm["current_page"] - 1) * $number_limit;
}
$sql_dasar = "SELECT
n.Nat_TestID,
IF(ntm.NonlabTemplateMappingNonlabTemplateID IS NULL, 'N', 'Y') AS status,
ntm.NonlabTemplateMappingNat_TestID,
n.Nat_TestCode,
n.Nat_TestName,
n.Nat_TestShortName
FROM nat_test as n
LEFT JOIN nonlab_template_mapping as ntm ON n.Nat_TestID = ntm.NonlabTemplateMappingNat_TestID
AND ntm.NonlabTemplateMappingIsActive = 'Y'
LEFT JOIN nonlab_template as nt ON ntm.NonlabTemplateMappingNonlabTemplateID = nt.NonlabTemplateID
AND nt.NonlabTemplateIsActive = 'Y'
WHERE n.Nat_TestIsActive = 'Y'
AND n.Nat_TestIsNonLab <> ''
AND n.Nat_TestIsResult = 'Y'
AND (n.Nat_TestCode LIKE '{$search}' OR n.Nat_TestName LIKE '{$search}')
AND (nt.NonlabTemplateID = {$nonlabtemplate_id} OR nt.NonlabTemplateID IS NULL)
$filter";
$qry_filter = "SELECT COUNT(*) as total FROM ($sql_dasar) as x";
$qry_filter = $this->db->query($qry_filter);
$tot_count = 0;
$tot_page = 0;
if ($qry_filter) {
$tot_count = $qry_filter->result_array()[0]["total"];
$tot_page = ceil($tot_count / $number_limit);
} else {
$this->sys_error_db("test count error", $this->db);
}
$sql = $sql_dasar . " ORDER BY n.Nat_TestCode LIMIT $number_limit OFFSET $number_offset";
$qry = $this->db->query($sql);
// echo $this->db->last_query();
// exit;
if ($qry) {
$rows = $qry->result_array();
} else {
$this->sys_error_db("test select error", $this->db);
exit;
}
$result = array(
"total" => $tot_page,
"total_filter" => count($rows),
"records" => $rows,
"sql" => $this->db->last_query()
);
$this->sys_ok($result);
} catch (Exception $exc) {
$message = $exc->getMessage();
$this->sys_error($message);
}
}
function saveedittestmap()
{
try {
if (!$this->isLogin) {
$this->sys_error("Invalid Token");
exit;
}
$prm = $this->sys_input;
$userid = $this->sys_user['M_UserID'];
$nonlabtemplate_id = 0;
if (isset($prm['nonlabtemplate_id'])) {
$nonlabtemplate_id = trim($prm["nonlabtemplate_id"]);
}
$test_id = 0;
if (isset($prm['test_id'])) {
$test_id = trim($prm["test_id"]);
}
$status = $prm["status"];
$sql = "SELECT NonlabTemplateMappingID,
NonlabTemplateMappingNonlabTemplateID,
NonlabTemplateMappingNat_TestID
FROM nonlab_template_mapping
WHERE NonlabTemplateMappingNonlabTemplateID = ?
AND NonlabTemplateMappingNat_TestID = ?";
$qry = $this->db->query($sql, [$nonlabtemplate_id, $test_id]);
if ($qry) {
$rows = $qry->result_array();
} else {
$this->sys_error_db("nonlab template error", $this->db);
exit;
}
if (count($rows) > 0) {
$nonlabtemplatemapid = $rows[0]["NonlabTemplateMappingID"];
$sql_update = "UPDATE nonlab_template_mapping SET
NonlabTemplateMappingLastUpdated = NOW(),
NonlabTemplateMappingLastUpdatedUserID = ?,
NonlabTemplateMappingDeleted = NOW(),
NonlabTemplateMappingIsActive = ?
WHERE NonlabTemplateMappingID = ?";
$qry_update = $this->db->query($sql_update, [$userid, $status, $nonlabtemplatemapid]);
if (!$qry_update) {
$this->sys_error_db("map test update", $this->db);
exit;
}
} else {
$sql_insert = "INSERT INTO nonlab_template_mapping(
NonlabTemplateMappingNonlabTemplateID,
NonlabTemplateMappingNat_TestID,
NonlabTemplateMappingCreated,
NonlabTemplateMappingCreatedUserID,
NonlabTemplateMappingIsActive) VALUES(?,?,NOW(),?,'Y')";
$qry_insert = $this->db->query($sql_insert, [$nonlabtemplate_id, $test_id, $userid]);
if (!$qry_insert) {
$this->sys_error_db("nonlab_template_mapping test insert", $this->db);
exit;
}
}
$result = array(
"total" => 1,
"affected_rows" => $this->db->affected_rows()
);
$this->sys_ok($result);
} catch (Exception $exc) {
$message = $exc->getMessage();
$this->sys_error($message);
}
}
}

View File

@@ -0,0 +1,879 @@
<?php
class Nonlabtemplatev3 extends MY_Controller
{
var $db;
public function index()
{
echo "NON LAN TEMPLATE API";
}
public function __construct()
{
parent::__construct();
}
function search()
{
try {
if (!$this->isLogin) {
$this->sys_error("Invalid Token");
exit;
}
$prm = $this->sys_input;
$search = "";
if (isset($prm['search'])) {
$search = trim($prm["search"]);
if ($search != "") {
$search = '%' . $prm['search'] . '%';
} else {
$search = '%%';
}
}
$number_offset = 0;
$number_limit = 10;
if ($prm["current_page"] > 0) {
$number_offset = ($prm["current_page"] - 1) * $number_limit;
}
$sql_tot = "SELECT COUNT(*) as total
FROM nonlab_template
WHERE NonlabTemplateIsActive = 'Y'
AND (NonlabTemplateName LIKE ?)";
$qry_tot = $this->db->query($sql_tot, [$search]);
$tot_count = 0;
$tot_page = 0;
if ($qry_tot) {
$tot_count = $qry_tot->result_array()[0]["total"];
$tot_page = ceil($tot_count / $number_limit);
} else {
$this->sys_error_db("nonlab template count", $this->db);
exit;
}
$sql = "SELECT
NonlabTemplateID,
NonlabTemplateName,
NonlabTemplateFlagOther,
NonlabTemplateIsActive,
NonlabTemplateCreated,
NonlabTemplateLastUpdated
FROM nonlab_template
WHERE NonlabTemplateIsActive = 'Y'
AND (NonlabTemplateName LIKE ?)
ORDER BY NonlabTemplateID ASC
LIMIT ? OFFSET ?";
$qry = $this->db->query($sql, [$search, $number_limit, $number_offset]);
if ($qry) {
$rows = $qry->result_array();
} else {
$this->sys_error_db("select nonlab template", $this->db);
exit;
}
$result = array(
"total_page" => $tot_page,
"total_filter" => $tot_count,
"records" => $rows
);
$this->sys_ok($result);
} catch (Exception $exc) {
$message = $exc->getMessage();
$this->sys_error($message);
}
}
function addnonlab()
{
try {
if (!$this->isLogin) {
$this->sys_error("Invalid Token");
exit;
}
$this->db->trans_begin();
$prm = $this->sys_input;
$userid = $this->sys_user['M_UserID'];
$name = "";
if (isset($prm["name"])) {
$name = trim($prm["name"]);
}
$isfisik = "";
if (isset($prm["isfisik"])) {
$isfisik = trim($prm["isfisik"]);
}
$sql = "INSERT INTO nonlab_template(
NonlabTemplateName,
NonlabTemplateFlagOther,
NonlabTemplateCreated,
NonlabTemplateCreatedUserID,
NonlabTemplateLastUpdated,
NonlabTemplateLastUpdatedUserID
) VALUES(?,?,NOW(),?,NOW(),?)";
$qry = $this->db->query($sql, array(
$name,
$isfisik,
$userid,
$userid
));
$last_qry = $this->db->last_query();
if (!$qry) {
$this->db->trans_rollback();
$error = array(
"message" => $this->db->error()["message"],
"sql" => $last_qry
);
$this->sys_error_db($error, $this->db);
exit;
}
$this->db->trans_commit();
$result = array(
"total" => 1,
"affected_rows" => $this->db->affected_rows()
);
$this->sys_ok($result);
} catch (Exception $exc) {
$message = $exc->getMessage();
$this->sys_error($message);
}
}
function editnonlab()
{
try {
if (!$this->isLogin) {
$this->sys_error("Invalid Token");
exit;
}
$this->db->trans_begin();
$prm = $this->sys_input;
$userid = $this->sys_user['M_UserID'];
$name = "";
if (isset($prm["name"])) {
$name = trim($prm["name"]);
}
$isfisik = "";
if (isset($prm["isfisik"])) {
$isfisik = trim($prm["isfisik"]);
}
$id = "";
if (isset($prm["id"])) {
$id = trim($prm["id"]);
}
$sql = "UPDATE nonlab_template
SET NonlabTemplateName = ?,
NonlabTemplateFlagOther = ?,
NonlabTemplateLastUpdated = NOW(),
NonlabTemplateLastUpdatedUserID = ?
WHERE NonlabTemplateID = ?";
$qry = $this->db->query($sql, array($name, $isfisik, $userid, $id));
$last_qry = $this->db->last_query();
if (!$qry) {
$this->db->trans_rollback();
$error = array(
"message" => $this->db->error()["message"],
"sql" => $last_qry
);
$this->sys_error_db($error, $this->db);
exit;
}
$this->db->trans_commit();
$result = array(
"total" => 1,
"affected_rows" => $this->db->affected_rows()
);
$this->sys_ok($result);
} catch (Exception $exc) {
$message = $exc->getMessage();
$this->sys_error($message);
}
}
function deletenonlab()
{
try {
if (!$this->isLogin) {
$this->sys_error("Invalid Token");
exit;
}
$this->db->trans_begin();
$prm = $this->sys_input;
$userid = $this->sys_user['M_UserID'];
$id = "";
if (isset($prm["id"])) {
$id = trim($prm["id"]);
}
$sql = "UPDATE nonlab_template
SET NonlabTemplateIsActive = 'N',
NonlabTemplateDelete = NOW(),
NonlabTemplateDeleteUserID = ?
WHERE NonlabTemplateID = ?";
$qry = $this->db->query($sql, array($userid, $id));
$last_qry = $this->db->last_query();
if (!$qry) {
$this->db->trans_rollback();
$error = array(
"message" => $this->db->error()["message"],
"sql" => $last_qry
);
$this->sys_error_db($error, $this->db);
exit;
}
$this->db->trans_commit();
$result = array(
"total" => 1,
"affected_rows" => $this->db->affected_rows()
);
$this->sys_ok($result);
} catch (Exception $exc) {
$message = $exc->getMessage();
$this->sys_error($message);
}
}
function searchdetail()
{
try {
if (!$this->isLogin) {
$this->sys_error("Invalid Token");
exit;
}
$prm = $this->sys_input;
$search = "";
if (isset($prm['search'])) {
$search = trim($prm["search"]);
if ($search != "") {
$search = '%' . $prm['search'] . '%';
} else {
$search = '%%';
}
}
$nonlabID = $prm["nonlabID"];
$number_offset = 0;
$number_limit = 10;
if ($prm["current_page"] > 0) {
$number_offset = ($prm["current_page"] - 1) * $number_limit;
}
$sql_total = "SELECT COUNT(*) as total
FROM nonlab_template_detail
WHERE NonlabTemplateDetailNonlabTemplateID = ?
AND NonlabTemplateDetailIsActive = 'Y'
AND (NonlabTemplateDetailCode LIKE ? OR NonlabTemplateDetailName LIKE ?)";
$qry_total = $this->db->query($sql_total, [$nonlabID, $search, $search]);
$tot_count = 0;
$tot_page = 0;
if ($qry_total) {
$tot_count = $qry_total->result_array()[0]["total"];
$tot_page = ceil($tot_count / $number_limit);
} else {
$this->sys_error_db("nonlab template detail count", $this->db);
exit;
}
$sql = "SELECT
NonlabTemplateDetailID,
NonlabTemplateDetailNonlabTemplateID,
NonlabTemplateDetailCode,
NonlabTemplateDetailGender,
CASE
WHEN NonlabTemplateDetailGender = 'male' THEN 'Laki-laki'
WHEN NonlabTemplateDetailGender = 'female' THEN 'Perempuan'
ELSE 'Semua'
END AS NonlabTemplateDetailGenderText,
NonlabTemplateDetailName,
IFNULL(NonlabTemplateDetailLangName, NonlabTemplateDetailName) AS NonlabTemplateDetailNameLangEng,
NonlabTemplateDetaiNat_UnitID as unit_id,
unit.Nat_UnitName as unit_name,
IFNULL(NonlabTemplateDetailLangNat_UnitID,0) as unit_eng_id,
uniteng.Nat_UnitName AS unit_eng_name,
NonlabTemplateDetailFlagActive,
NonlabTemplateDetaiM_LangID,
NonlabTemplateDetailIsActive
FROM nonlab_template_detail
LEFT JOIN nonlab_template_detail_lang ON NonlabTemplateDetailLangNonlabTemplateDetailID = NonlabTemplateDetailID AND
NonlabTemplateDetailLangM_LangID = '2' AND NonlabTemplateDetailLangIsActive = 'Y'
LEFT JOIN nat_unit unit ON unit.Nat_UnitID = NonlabTemplateDetaiNat_UnitID AND unit.Nat_UnitIsActive = 'Y'
LEFT JOIN nat_unit uniteng ON uniteng.Nat_UnitID = NonlabTemplateDetailLangNat_UnitID AND uniteng.Nat_UnitIsActive = 'Y'
WHERE NonlabTemplateDetailNonlabTemplateID = ?
AND NonlabTemplateDetailIsActive = 'Y'
AND (NonlabTemplateDetailCode LIKE ? OR NonlabTemplateDetailName LIKE ?)
limit ? offset ?";
$qry = $this->db->query($sql, [$nonlabID, $search, $search, $number_limit, $number_offset]);
if ($qry) {
$rows = $qry->result_array();
} else {
$this->sys_error_db("select nonlab template detail", $this->db);
exit;
}
$result = array(
"total_page" => $tot_page,
"total_filter" => $tot_count,
"records" => $rows
);
$this->sys_ok($result);
} catch (Exception $exc) {
$message = $exc->getMessage();
$this->sys_error($message);
}
}
function getunits()
{
try {
$rst = array(
array('id' => '0', 'value' => 'Tanpa Satuan'),
);
$sql = "SELECT Nat_UnitID, Nat_UnitName FROM nat_unit WHERE Nat_UnitIsActive = 'Y'";
$qry = $this->db->query($sql);
$rows = $qry->result_array();
foreach ($rows as $row) {
$rst[] = array('id' => $row['Nat_UnitID'], 'value' => $row['Nat_UnitName']);
}
$this->sys_ok($rst);
} catch (Exception $exc) {
$message = $exc->getMessage();
$this->sys_error($message);
}
}
function adddetail()
{
try {
if (!$this->isLogin) {
$this->sys_error("Invalid Token");
exit;
}
$this->db->trans_begin();
$prm = $this->sys_input;
$userid = $this->sys_user['M_UserID'];
$nonlabid = intval($prm["nonlabid"]);
if ($nonlabid === 0) {
$this->sys_error("Anda belum memilih nonlab template, silahkan pilih nonlab template dulu");
exit;
}
$name = "";
if (isset($prm["name"])) {
$name = trim($prm["name"]);
}
if($name == ""){
$this->sys_error("Anda belum mengisi nama");
exit;
}
$name_eng = "";
if (isset($prm["name_eng"])) {
$name_eng = trim($prm["name_eng"]);
}
$code = "";
if (isset($prm["code"])) {
$code = trim($prm["code"]);
}
if($code == ""){
$this->sys_error("Anda belum mengisi kode");
exit;
}
$gender = "";
if (isset($prm["gender"])) {
$gender = trim($prm["gender"]);
}
if($gender == ""){
$this->sys_error("Anda belum mengisi gender");
exit;
}
$unit = "";
if (isset($prm["unit"])) {
$unit = trim($prm["unit"]);
}
$uniteng = "";
if (isset($prm["uniteng"])) {
$uniteng = trim($prm["uniteng"]);
}
// $nonlabid = "";
// if (isset($prm["nonlabid"])) {
// $nonlabid = trim($prm["nonlabid"]);
// }
$sql = "INSERT INTO nonlab_template_detail(
NonlabTemplateDetailNonlabTemplateID,
NonlabTemplateDetailGender,
NonlabTemplateDetaiNat_UnitID,
NonlabTemplateDetailCode,
NonlabTemplateDetailName,
NonlabTemplateDetailCreated,
NonlabTemplateDetailCreatedUserID,
NonlabTemplateDetailLastUpdated,
NonlabTemplateDetailLastUpdatedUserID
) VALUES(?,?,?,?,?,NOW(),?,NOW(),?)";
$qry = $this->db->query($sql, array(
$nonlabid,
$gender,
$unit,
$code,
$name,
$userid,
$userid
));
$last_qry = $this->db->last_query();
if (!$qry) {
$this->db->trans_rollback();
$error = array(
"message" => $this->db->error()["message"],
"sql" => $last_qry
);
$this->sys_error_db($error, $this->db);
exit;
}
$last_id = $this->db->insert_id();
$sql_lang = "INSERT INTO nonlab_template_detail_lang(
NonlabTemplateDetailLangNonlabTemplateDetailID,
NonlabTemplateDetailLangGender,
NonlabTemplateDetailLangM_LangID,
NonlabTemplateDetailLangName,
NonlabTemplateDetailLangNat_UnitID,
NonlabTemplateDetailLangCreated,
NonlabTemplateDetailLangCreatedUserID,
NonlabTemplateDetailLangLastUpdated,
NonlabTemplateDetailLangLastUpdatedUserID
) VALUES(?,?,?,?,?,NOW(),?,NOW(),?)";
$qry_lang = $this->db->query($sql_lang, array(
$last_id,
$gender,
"2",
$name_eng,
$uniteng,
$userid,
$userid
));
$this->db->trans_commit();
$result = array(
"total" => 1,
"affected_rows" => $this->db->affected_rows()
);
$this->sys_ok($result);
} catch (Exception $exc) {
$message = $exc->getMessage();
$this->sys_error($message);
}
}
function deletedetail()
{
try {
if (!$this->isLogin) {
$this->sys_error("Invalid Token");
exit;
}
$this->db->trans_begin();
$prm = $this->sys_input;
$userid = $this->sys_user['M_UserID'];
$id = "";
if (isset($prm["id"])) {
$id = trim($prm["id"]);
}
$sql = "UPDATE nonlab_template_detail
SET NonlabTemplateDetailIsActive = 'N',
NonlabTemplateDetailDelete = NOW(),
NonlabTemplateDetailDeleteUserID = ?
WHERE NonlabTemplateDetailID = ?";
$qry = $this->db->query($sql, array($userid, $id));
$last_qry = $this->db->last_query();
if (!$qry) {
$this->db->trans_rollback();
$error = array(
"message" => $this->db->error()["message"],
"sql" => $last_qry
);
$this->sys_error_db($error, $this->db);
exit;
}
$this->db->trans_commit();
$result = array(
"total" => 1,
"affected_rows" => $this->db->affected_rows()
);
$this->sys_ok($result);
} catch (Exception $exc) {
$message = $exc->getMessage();
$this->sys_error($message);
}
}
function saveeditflag()
{
try {
if (!$this->isLogin) {
$this->sys_error("Invalid Token");
exit;
}
$this->db->trans_begin();
$prm = $this->sys_input;
$userid = $this->sys_user['M_UserID'];
$flagstatus = $prm['flagstatus'];
$templatedetailid = $prm['templatedetailid'];
if ($flagstatus == "Y") {
$sql = "UPDATE nonlab_template_detail
SET NonlabTemplateDetailFlagActive = 'Y',
NonlabTemplateDetailLastUpdated = NOW(),
NonlabTemplateDetailLastUpdatedUserID = ?
WHERE NonlabTemplateDetailID = ?";
$qry = $this->db->query($sql, array(
$userid,
$templatedetailid
));
// echo $this->db->last_query();
// exit;
if (!$qry) {
$this->sys_error_db("nonlab template detail avtive", $this->db);
exit;
}
$this->db->trans_commit();
$result = array("total" => 1, "records" => array("xid" => 0));
$this->sys_ok($result);
} else {
$sql = "UPDATE nonlab_template_detail
SET NonlabTemplateDetailFlagActive = 'N',
NonlabTemplateDetailLastUpdated = NOW(),
NonlabTemplateDetailLastUpdatedUserID = ?
WHERE NonlabTemplateDetailID = ?";
$qry = $this->db->query($sql, array(
$userid,
$templatedetailid
));
// echo $this->db->last_query();
// exit;
if (!$qry) {
$this->sys_error_db("nonlab template detail no avtive", $this->db);
exit;
}
$this->db->trans_commit();
$result = array("total" => 1, "records" => array("xid" => 0));
$this->sys_ok($result);
}
} catch (Exception $exc) {
$message = $exc->getMessage();
$this->sys_error($message);
}
}
function editdetail()
{
try {
if (!$this->isLogin) {
$this->sys_error("Invalid Token");
exit;
}
$this->db->trans_begin();
$prm = $this->sys_input;
$userid = $this->sys_user['M_UserID'];
$name = "";
if (isset($prm["name"])) {
$name = trim($prm["name"]);
}
if($name == ""){
$this->sys_error("Anda belum mengisi nama");
exit;
}
$name_eng = "";
if (isset($prm["name_eng"])) {
$name_eng = trim($prm["name_eng"]);
}
if($name_eng == ""){
$this->sys_error("Anda belum mengisi nama inggris");
exit;
}
$code = "";
if (isset($prm["code"])) {
$code = trim($prm["code"]);
}
if($code == ""){
$this->sys_error("Anda belum mengisi kode");
exit;
}
$id = "";
if (isset($prm["id"])) {
$id = trim($prm["id"]);
}
$gender = "";
if (isset($prm["gender"])) {
$gender = trim($prm["gender"]);
}
if($gender == ""){
$this->sys_error("Anda belum mengisi gender");
exit;
}
$unit = "";
if (isset($prm["unit"])) {
$unit = trim($prm["unit"]);
}
$uniteng = "";
if (isset($prm["uniteng"])) {
$uniteng = trim($prm["uniteng"]);
}
$sql = "UPDATE nonlab_template_detail SET
NonlabTemplateDetailGender = ?,
NonlabTemplateDetaiNat_UnitID = ?,
NonlabTemplateDetailCode = ?,
NonlabTemplateDetailName = ?,
NonlabTemplateDetailLastUpdated = NOW(),
NonlabTemplateDetailLastUpdatedUserID = ?
WHERE NonlabTemplateDetailID = ?";
$qry = $this->db->query($sql, array($gender, $unit, $code, $name, $userid, $id));
$last_qry = $this->db->last_query();
if (!$qry) {
$this->db->trans_rollback();
$error = array(
"message" => $this->db->error()["message"],
"sql" => $last_qry
);
$this->sys_error_db($error, $this->db);
exit;
}
$sql = "SELECT NonlabTemplateDetailLangID
FROM nonlab_template_detail_lang
WHERE
NonlabTemplateDetailLangNonlabTemplateDetailID = ?
AND NonlabTemplateDetailLangM_LangID = '2' AND
NonlabTemplateDetailLangIsActive = 'Y'
";
$qry = $this->db->query($sql, array($id));
if (!$qry) {
$this->sys_error_db("nonlab template detail lang", $this->db);
exit;
}
$rows = $qry->result_array();
if (count($rows) > 0) {
$langid = $rows[0]["NonlabTemplateDetailLangID"];
}
$sql = "UPDATE nonlab_template_detail_lang SET
NonlabTemplateDetailLangGender = ?,
NonlabTemplateDetailLangNat_UnitID = ?,
NonlabTemplateDetailLangName = ?,
NonlabTemplateDetailLangLastUpdated = NOW(),
NonlabTemplateDetailLangLastUpdatedUserID = ?
WHERE NonlabTemplateDetailLangID = ?";
$qry = $this->db->query($sql, array($gender, $uniteng, $name_eng, $userid, $langid));
if (!$qry) {
$this->sys_error_db("nonlab template detail lang", $this->db);
exit;
}
$this->db->trans_commit();
$result = array(
"total" => 1,
"affected_rows" => $this->db->affected_rows()
);
$this->sys_ok($result);
} catch (Exception $exc) {
$message = $exc->getMessage();
$this->sys_error($message);
}
}
function lookuptest()
{
try {
if (!$this->isLogin) {
$this->sys_error("Invalid Token");
exit;
}
$prm = $this->sys_input;
$search = "";
if (isset($prm["search"])) {
$search = trim($prm["search"]);
if ($search != "") {
$search = "%" . $prm["search"] . "%";
} else {
$search = "%%";
}
}
$nonlabtemplate_id = 0;
if (isset($prm['nonlabtemplate_id'])) {
$nonlabtemplate_id = trim($prm["nonlabtemplate_id"]);
}
$status = $prm['status'];
$filter = '';
if ($status == 'Y') {
$filter .= "AND ntm.NonlabTemplateMappingNonlabTemplateID IS NOT NULL ";
} else {
if ($status == 'N') {
$filter .= "AND ntm.NonlabTemplateMappingNonlabTemplateID IS NULL ";
} else {
$filter .= "";
}
}
$number_offset = 0;
$number_limit = 10;
if ($prm["current_page"] > 0) {
$number_offset = ($prm["current_page"] - 1) * $number_limit;
}
$sql_dasar = "SELECT
n.Nat_TestID,
IF(ntm.NonlabTemplateMappingNonlabTemplateID IS NULL, 'N', 'Y') AS status,
ntm.NonlabTemplateMappingNat_TestID,
n.Nat_TestCode,
n.Nat_TestName,
n.Nat_TestShortName
FROM nat_test as n
LEFT JOIN nonlab_template_mapping as ntm ON n.Nat_TestID = ntm.NonlabTemplateMappingNat_TestID
AND ntm.NonlabTemplateMappingIsActive = 'Y'
LEFT JOIN nonlab_template as nt ON ntm.NonlabTemplateMappingNonlabTemplateID = nt.NonlabTemplateID
AND nt.NonlabTemplateIsActive = 'Y'
WHERE n.Nat_TestIsActive = 'Y'
AND n.Nat_TestIsNonLab <> ''
AND n.Nat_TestIsResult = 'Y'
AND (n.Nat_TestCode LIKE '{$search}' OR n.Nat_TestName LIKE '{$search}')
AND (nt.NonlabTemplateID = {$nonlabtemplate_id} OR nt.NonlabTemplateID IS NULL)
$filter";
$qry_filter = "SELECT COUNT(*) as total FROM ($sql_dasar) as x";
$qry_filter = $this->db->query($qry_filter);
$tot_count = 0;
$tot_page = 0;
if ($qry_filter) {
$tot_count = $qry_filter->result_array()[0]["total"];
$tot_page = ceil($tot_count / $number_limit);
} else {
$this->sys_error_db("test count error", $this->db);
}
$sql = $sql_dasar . " ORDER BY n.Nat_TestCode LIMIT $number_limit OFFSET $number_offset";
$qry = $this->db->query($sql);
// echo $this->db->last_query();
// exit;
if ($qry) {
$rows = $qry->result_array();
} else {
$this->sys_error_db("test select error", $this->db);
exit;
}
$result = array(
"total" => $tot_page,
"total_filter" => count($rows),
"records" => $rows,
"sql" => $this->db->last_query()
);
$this->sys_ok($result);
} catch (Exception $exc) {
$message = $exc->getMessage();
$this->sys_error($message);
}
}
function saveedittestmap()
{
try {
if (!$this->isLogin) {
$this->sys_error("Invalid Token");
exit;
}
$prm = $this->sys_input;
$userid = $this->sys_user['M_UserID'];
$nonlabtemplate_id = 0;
if (isset($prm['nonlabtemplate_id'])) {
$nonlabtemplate_id = trim($prm["nonlabtemplate_id"]);
}
$test_id = 0;
if (isset($prm['test_id'])) {
$test_id = trim($prm["test_id"]);
}
$status = $prm["status"];
$sql = "SELECT NonlabTemplateMappingID,
NonlabTemplateMappingNonlabTemplateID,
NonlabTemplateMappingNat_TestID
FROM nonlab_template_mapping
WHERE NonlabTemplateMappingNonlabTemplateID = ?
AND NonlabTemplateMappingNat_TestID = ?";
$qry = $this->db->query($sql, [$nonlabtemplate_id, $test_id]);
if ($qry) {
$rows = $qry->result_array();
} else {
$this->sys_error_db("nonlab template error", $this->db);
exit;
}
if (count($rows) > 0) {
$nonlabtemplatemapid = $rows[0]["NonlabTemplateMappingID"];
$sql_update = "UPDATE nonlab_template_mapping SET
NonlabTemplateMappingLastUpdated = NOW(),
NonlabTemplateMappingLastUpdatedUserID = ?,
NonlabTemplateMappingDeleted = NOW(),
NonlabTemplateMappingIsActive = ?
WHERE NonlabTemplateMappingID = ?";
$qry_update = $this->db->query($sql_update, [$userid, $status, $nonlabtemplatemapid]);
if (!$qry_update) {
$this->sys_error_db("map test update", $this->db);
exit;
}
} else {
$sql_insert = "INSERT INTO nonlab_template_mapping(
NonlabTemplateMappingNonlabTemplateID,
NonlabTemplateMappingNat_TestID,
NonlabTemplateMappingCreated,
NonlabTemplateMappingCreatedUserID,
NonlabTemplateMappingIsActive) VALUES(?,?,NOW(),?,'Y')";
$qry_insert = $this->db->query($sql_insert, [$nonlabtemplate_id, $test_id, $userid]);
if (!$qry_insert) {
$this->sys_error_db("nonlab_template_mapping test insert", $this->db);
exit;
}
}
$result = array(
"total" => 1,
"affected_rows" => $this->db->affected_rows()
);
$this->sys_ok($result);
} catch (Exception $exc) {
$message = $exc->getMessage();
$this->sys_error($message);
}
}
}

File diff suppressed because it is too large Load Diff