Initial import

This commit is contained in:
sas.fajri
2026-05-25 20:01:37 +07:00
commit 710d7c1b97
10371 changed files with 2381698 additions and 0 deletions

View File

@@ -0,0 +1,922 @@
<?php
class Attribute extends MY_Controller
{
var $db_regional;
public function index()
{
echo "BRANCH API";
}
public function __construct()
{
parent::__construct();
$this->db_regional = $this->load->database("regional", true);
}
function lookupattributebyname(){
try {
//# cek token valid
if (! $this->isLogin) {
$this->sys_error("Invalid Token");
exit;
}
$prm = $this->sys_input;
$attribute = $prm['branch'];
$all = $prm['all'];
$limit = '';
if($all == 'N'){
$limit = ' LIMIT 10';
}
$number_limit = 10;
$number_offset = ($prm['current_page'] - 1) * $number_limit ;
$sql = "select COUNT(*) as total
from t_testattribute
JOIN t_test ON T_TestID = T_TestAttributeT_TestID
JOIN t_category ON T_CategoryID = T_TestAttributeT_CategoryID
JOIN t_subcategory ON T_SubCategoryID = T_TestAttributeT_SubCategoryID
WHERE
(T_TestName LIKE CONCAT('%','{$attribute}','%') OR
T_TestSasCode LIKE CONCAT('%','{$attribute}','%')) AND
T_TestAttributeIsActive = 'Y'";
// $total = $this->db_regional->query($sql,$sql_param)->row()->total;
$query = $this->db_regional->query($sql);
// echo $this->db_regional->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("t_testattribute count", $this->db_regional);
exit;
}
$sql = "select T_TestAttributeID as id,
T_TestID,
CONCAT('[',T_TestSasCode,'] ',T_TestName) as T_TestName,
T_TestSasCode,
T_CategoryID,
T_CategoryName,
T_SubCategoryID,
CONCAT(T_SubCategoryName,'[',T_CategoryName,'] ') T_SubCategoryName,
CONCAT(T_SubCategoryName,' (', T_CategoryName ,')') as category,
t_testattribute.*
from t_testattribute
JOIN t_test ON T_TestID = T_TestAttributeT_TestID
JOIN t_category ON T_CategoryID = T_TestAttributeT_CategoryID
JOIN t_subcategory ON T_SubCategoryID = T_TestAttributeT_SubCategoryID
WHERE
(T_TestName LIKE CONCAT('%','{$attribute}','%') OR
T_TestSasCode LIKE CONCAT('%','{$attribute}','%')) AND
T_TestAttributeIsActive = 'Y'
GROUP BY T_TestAttributeID
ORDER BY T_TestSasCode ASC, T_SubCategoryName ASC
limit $number_limit offset $number_offset";
$sql_param = array($search);
$query = $this->db_regional->query($sql);
//echo $this->db_regional->last_query();
if ($query) {
$rows = $query->result_array();
} else {
$this->sys_error_db("t_testattribute 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 lookupregionalbyname()
{
try {
//# cek token valid
if (! $this->isLogin) {
$this->sys_error("Invalid Token");
exit;
}
$prm = $this->sys_input;
$regional = $prm['regional'];
$attribute = $prm['attribute'];
$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 s_regional
LEFT JOIN t_testattribute ON S_RegionalID = T_TestAttributeS_RegionalID AND T_TestAttributeIsActive = 'Y'
where
S_RegionalName LIKE CONCAT('%','{$regional}','%') AND
IFNULL(T_TestAttributeName,'') LIKE CONCAT('%','{$attribute}','%') AND
S_RegionalIsActive = 'Y'
GROUP BY S_RegionalID) a";
$sql_param = array($search);
// $total = $this->db_regional->query($sql,$sql_param)->row()->total;
$query = $this->db_regional->query($sql);
$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("s_regional count", $this->db_regional);
exit;
}
$sql = "select S_RegionalID as id,
S_RegionalName as name,
S_RegionalName as namex,
s_regional.*
from s_regional
LEFT JOIN t_testattribute ON S_RegionalID = T_TestAttributeS_RegionalID AND T_TestAttributeIsActive = 'Y'
where
S_RegionalName LIKE CONCAT('%','{$regional}','%') AND
IFNULL(T_TestAttributeName,'') LIKE CONCAT('%','{$attribute}','%') AND
S_RegionalIsActive = 'Y'
GROUP BY S_RegionalID
ORDER BY S_RegionalName ASC
limit $number_limit offset $number_offset";
$sql_param = array($search);
$query = $this->db_regional->query($sql);
//echo $this->db_regional->last_query();
if ($query) {
$rows = $query->result_array();
} else {
$this->sys_error_db("s_regional 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 addnewregional()
{
try {
//# cek token valid
if (! $this->isLogin) {
$this->sys_error("Invalid Token");
exit;
}
//# ambil parameter input
$prm = $this->sys_input;
$name = $prm['name'];
$sql = "insert into s_regional(
S_RegionalName,
S_RegionalCreated,
S_RegionalLastUpdated
)
values( ?, now(), now())";
$query = $this->db_regional->query($sql,
array(
$name
)
);
//echo $query;
if (!$query) {
$this->sys_error_db("s_regional insert");
exit;
}
$last_id = $this->db_regional->insert_id();
$result = array ("total" => 1, "records" => array("xid" => 0));
$this->sys_ok($result);
$last_id = $this->db_regional->insert_id();
} catch(Exception $exc) {
$message = $exc->getMessage();
$this->sys_error($message);
}
}
public function editregional()
{
try {
//# cek token valid
if (! $this->isLogin) {
$this->sys_error("Invalid Token");
exit;
}
//# ambil parameter input
$prm = $this->sys_input;
$id = $prm['id'];
$name = $prm['name'];
$userid = $this->sys_user["M_UserID"];
$sqlcompany = "update s_regional SET
S_RegionalName = ?,
S_RegionalLastUpdated = now()
where
S_RegionalID = ?
";
$querycompany = $this->db_regional->query($sqlcompany,
array(
$name,
$id
)
);
// echo $query;
if (!$querycompany) {
$this->sys_error_db("s_regional update");
exit;
}
$result = array ("total" => 1, "records" => array("xid" => $id));
$this->sys_ok($result);
} catch(Exception $exc) {
$message = $exc->getMessage();
$this->sys_error($message);
}
}
public function addnewattribute()
{
try {
//# cek token valid
if (! $this->isLogin) {
$this->sys_error("Invalid Token");
exit;
}
//# ambil parameter input
$prm = $this->sys_input;
$T_TestAttributeT_TestID = $prm['testid'];
$T_TestAttributeT_CategoryID = $prm['categoryid'];
$T_TestAttributeT_SubCategoryID = $prm['subcategoryid'];
$userid = $this->sys_user["M_UserID"];
if($T_TestAttributeT_TestID == 0 || $T_TestAttributeT_SubCategoryID == 0){
$errors = array();
if($T_TestAttributeT_TestID == 0){
array_push($errors,array('field'=>'regional','msg'=>'Pemeriksaan dipilih dulu dong'));
}
if($T_TestAttributeT_SubCategoryID == 0){
array_push($errors,array('field'=>'subcategory','msg'=>'Kategori dipilih dulu dong'));
}
$result = array ("total" => -1,"errors" => $errors, "records" => 0);
$this->sys_ok($result);
}else{
if($prm['xid'] == 0){
$sql = "insert into t_testattribute(
T_TestAttributeT_TestID,
T_TestAttributeT_CategoryID,
T_TestAttributeT_SubCategoryID,
T_TestAttributeCreated,
T_TestAttributeLastUpdated,
T_TestAttributeUserID)
values(?,?,?,now(),now(),?)";
$query = $this->db_regional->query($sql,
array(
$T_TestAttributeT_TestID,
$T_TestAttributeT_CategoryID,
$T_TestAttributeT_SubCategoryID,
$userid)
);
if (!$query) {
$this->sys_error_db("t_testattribute insert",$this->db_regional);
exit;
}
$last_id = $this->db_regional->insert_id();
$result = array ("total" => 1, "records" => array("xid" => 0));
$this->sys_ok($result);
}else{
$sql = "UPDATE t_testattribute SET T_TestAttributeT_TestID = '{$T_TestAttributeT_TestID}',
T_TestAttributeT_CategoryID = '{$T_TestAttributeT_CategoryID}',
T_TestAttributeT_SubCategoryID = '{$T_TestAttributeT_SubCategoryID}',
T_TestAttributeUserID = '{$userid}',
T_TestAttributeLastUpdated = now()
WHERE T_TestAttributeID = '{$prm['xid']}'";
//echo $sql;
$query = $this->db_regional->query($sql);
$result = array ("total" => 1, "records" => array("xid" => 0));
$this->sys_ok($result);
}
}
} catch(Exception $exc) {
$message = $exc->getMessage();
$this->sys_error($message);
}
}
public function deleteregional()
{
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 s_regional SET
S_RegionalIsActive = 'N',
S_RegionalLastUpdated = now()
WHERE
S_RegionalID = ?
";
$query = $this->db_regional->query($sql,
array(
$prm['id']
)
);
// echo $query;
if (!$query) {
$this->sys_error_db("s_regional delete");
exit;
}
$sql = "update t_testattribute SET
T_TestAttributeIsActive = 'N',
T_TestAttributeLastUpdated = now()
WHERE
T_TestAttributeS_RegionalID = ?
";
$query = $this->db_regional->query($sql,
array(
$prm['id']
)
);
// echo $query;
if (!$query) {
$this->sys_error_db("t_testattribute 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 deleteattribute()
{
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 t_testattribute SET
T_TestAttributeIsActive = 'N',
T_TestAttributeLastUpdated = now()
WHERE
T_TestAttributeID = ?
";
$query = $this->db_regional->query($sql,
array(
$prm['id']
)
);
// echo $query;
if (!$query) {
$this->sys_error_db("t_testattribute 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 searchtest(){
if (! $this->isLogin) {
$this->sys_error("Invalid Token");
exit;
}
$prm = $this->sys_input;
$max_rst = 12;
$tot_count =0;
$q = [
'search' => '%'
];
if ($prm['tes'] != '')
{
$q['search'] = "%{$prm['tes']}%";
}
// QUERY TOTAL
$sql = "SELECT count(*) as total
FROM t_test
WHERE
CONCAT('[',T_TestSasCode,'] ',T_TestName) like ?
AND T_TestIsActive = 'Y'";
$query = $this->db_regional->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_regional);
exit;
}
$sql = "
SELECT T_TestID,CONCAT('[',T_TestSasCode,'] ',T_TestName) as T_TestName
FROM t_test
WHERE
CONCAT('[',T_TestSasCode,'] ',T_TestName) like ?
AND T_TestIsActive = 'Y'
AND T_TestIsPrice = 'Y'
AND T_TestID not in (
select T_TestAttributeT_TestID from t_testattribute where T_TestAttributeIsActive = 'Y')
ORDER BY T_TestSasCode ASC
";
$query = $this->db_regional->query($sql, array($q['search']));
if ($query) {
$rows = $query->result_array();
// echo $this->db_regional->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_regional);
exit;
}
}
function searchregionalbyname(){
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 s_regional
WHERE
S_RegionalName like ?
AND S_RegionalIsActive = 'Y'";
$query = $this->db_regional->query($sql,$q['search']);
//echo $query;
if ($query) {
$tot_count = $query->result_array()[0]["total"];
}
else {
$this->sys_error_db("s_regional count",$this->db_regional);
exit;
}
$sql = "
SELECT S_RegionalID, S_RegionalName
FROM s_regional
WHERE
S_RegionalName like ?
AND S_RegionalIsActive = 'Y'
ORDER BY S_RegionalName ASC
";
$query = $this->db_regional->query($sql, array($q['search']));
if ($query) {
$rows = $query->result_array();
//echo $this->db_regional->last_query();
$result = array("total" => $tot_count, "records" => $rows, "total_display" => sizeof($rows));
$this->sys_ok($result);
}
else {
$this->sys_error_db("s_regional rows",$this->db_regional);
exit;
}
}
function searchsubcategory(){
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_subcategory
WHERE
T_SubCategoryName like ?
AND T_SubCategoryIsActive = 'Y'";
$query = $this->db_regional->query($sql,$q['search']);
//echo $query;
if ($query) {
$tot_count = $query->result_array()[0]["total"];
}
else {
$this->sys_error_db("t_subcategory count",$this->db_regional);
exit;
}
$sql = "
SELECT T_CategoryID, T_CategoryName,T_SubCategoryID,CONCAT(T_SubCategoryName,'[',T_CategoryName,'] ') T_SubCategoryName
FROM t_subcategory
JOIN t_category ON T_CategoryID = T_SubCategoryT_CategoryID
WHERE
CONCAT(T_SubCategoryName,'[',T_CategoryName,'] ') like ?
AND T_SubCategoryIsActive = 'Y'
ORDER BY T_SubCategoryName ASC
";
$query = $this->db_regional->query($sql, array($q['search']));
if ($query) {
$rows = $query->result_array();
//echo $this->db_regional->last_query();
$result = array("total" => $tot_count, "records" => $rows, "total_display" => sizeof($rows));
$this->sys_ok($result);
}
else {
$this->sys_error_db("t_subcategory rows",$this->db_regional);
exit;
}
}
function searchdistrict(){
if (! $this->isLogin) {
$this->sys_error("Invalid Token");
exit;
}
$prm = $this->sys_input;
$id = $prm['id'];
$max_rst = 12;
$tot_count =0;
$q = [
'search' => '%'
];
if ($prm['search'] != '')
{
$q['search'] = "%{$prm['search']}%";
}
// QUERY TOTAL
$sql = "SELECT count(*) as total
FROM m_district
WHERE
M_DistrictName like ?
AND M_DistrictT_SubCategoryID = '{$id}'
AND M_DistrictIsActive = 'Y'";
$query = $this->db_regional->query($sql,$q['search']);
//echo $query;
if ($query) {
$tot_count = $query->result_array()[0]["total"];
}
else {
$this->sys_error_db("m_district count",$this->db_regional);
exit;
}
$sql = "
SELECT *
FROM m_district
WHERE
M_DistrictName like ?
AND M_DistrictT_SubCategoryID = '{$id}'
AND M_DistrictIsActive = 'Y'
ORDER BY M_DistrictName ASC
";
$query = $this->db_regional->query($sql, array($q['search']));
if ($query) {
$rows = $query->result_array();
//echo $this->db_regional->last_query();
$result = array("total" => $tot_count, "records" => $rows, "total_display" => sizeof($rows));
$this->sys_ok($result);
}
else {
$this->sys_error_db("m_district rows",$this->db_regional);
exit;
}
}
function searchkelurahan(){
if (! $this->isLogin) {
$this->sys_error("Invalid Token");
exit;
}
$prm = $this->sys_input;
$id = $prm['id'];
$max_rst = 12;
$tot_count =0;
$q = [
'search' => '%'
];
if ($prm['search'] != '')
{
$q['search'] = "%{$prm['search']}%";
}
// QUERY TOTAL
$sql = "SELECT count(*) as total
FROM m_kelurahan
WHERE
M_KelurahanName like ?
AND M_KelurahanM_DistrictID = '{$id}'
AND M_KelurahanIsActive = 'Y'";
$query = $this->db_regional->query($sql,$q['search']);
//echo $query;
if ($query) {
$tot_count = $query->result_array()[0]["total"];
}
else {
$this->sys_error_db("m_district count",$this->db_regional);
exit;
}
$sql = "
SELECT *
FROM m_kelurahan
WHERE
M_KelurahanName like ?
AND M_KelurahanM_DistrictID = '{$id}'
AND M_KelurahanIsActive = 'Y'
ORDER BY M_KelurahanName ASC
";
$query = $this->db_regional->query($sql, array($q['search']));
if ($query) {
$rows = $query->result_array();
//echo $this->db_regional->last_query();
$result = array("total" => $tot_count, "records" => $rows, "total_display" => sizeof($rows));
$this->sys_ok($result);
}
else {
$this->sys_error_db("m_district rows",$this->db_regional);
exit;
}
}
function searchcompany(){
if (! $this->isLogin) {
$this->sys_error("Invalid Token");
exit;
}
$prm = $this->sys_input;
$max_rst = 12;
$tot_count =0;
$q = [
'search' => '%'
];
if ($prm['search'] != '')
{
$q['search'] = "%{$prm['search']}%";
}
// QUERY TOTAL
$sql = "SELECT count(*) as total
FROM m_company
WHERE
M_CompanyName like ?
AND M_CompanyIsActive = 'Y'";
$query = $this->db_regional->query($sql,$q['search']);
//echo $query;
if ($query) {
$tot_count = $query->result_array()[0]["total"];
}
else {
$this->sys_error_db("m_company count",$this->db_regional);
exit;
}
$sql = "
SELECT *
FROM m_company
WHERE
M_CompanyName like ?
AND M_CompanyIsActive = 'Y'
ORDER BY M_CompanyName ASC
";
$query = $this->db_regional->query($sql, array($q['search']));
if ($query) {
$rows = $query->result_array();
//echo $this->db_regional->last_query();
$result = array("total" => $tot_count, "records" => $rows, "total_display" => sizeof($rows));
$this->sys_ok($result);
}
else {
$this->sys_error_db("m_company rows",$this->db_regional);
exit;
}
}
function searchmou(){
if (! $this->isLogin) {
$this->sys_error("Invalid Token");
exit;
}
$prm = $this->sys_input;
$id = $prm['id'];
$max_rst = 12;
$tot_count =0;
$q = [
'search' => '%'
];
if ($prm['search'] != '')
{
$q['search'] = "%{$prm['search']}%";
}
// QUERY TOTAL
$sql = "SELECT count(*) as total
FROM m_mou
WHERE
M_MouName like ?
AND M_MouM_CompanyID = '{$id}'
AND M_MouIsActive = 'Y'";
$query = $this->db_regional->query($sql,$q['search']);
//echo $query;
if ($query) {
$tot_count = $query->result_array()[0]["total"];
}
else {
$this->sys_error_db("m_mou count",$this->db_regional);
exit;
}
$sql = "SELECT *
FROM m_mou
WHERE
M_MouName like ?
AND M_MouM_CompanyID = '{$id}'
AND M_MouIsActive = 'Y'
ORDER BY M_MouName ASC
";
$query = $this->db_regional->query($sql, array($q['search']));
if ($query) {
$rows = $query->result_array();
// echo $this->db_regional->last_query();
$result = array("total" => $tot_count, "records" => $rows, "total_display" => sizeof($rows));
$this->sys_ok($result);
}
else {
$this->sys_error_db("m_mou rows",$this->db_regional);
exit;
}
}
function searchdoctor(){
if (! $this->isLogin) {
$this->sys_error("Invalid Token");
exit;
}
$prm = $this->sys_input;
$max_rst = 12;
$tot_count =0;
$q = [
'search' => '%'
];
if ($prm['search'] != '')
{
$q['search'] = "%{$prm['search']}%";
}
// QUERY TOTAL
$sql = "SELECT count(*) as total
FROM(SELECT M_DoctorID, CONCAT(M_DoctorPrefix, ' ',M_DoctorName) as M_DoctorName
FROM m_doctor
WHERE M_DoctorIsActive = 'Y') a
WHERE
M_DoctorName like ?";
$query = $this->db_regional->query($sql,$q['search']);
//echo $query;
if ($query) {
$tot_count = $query->result_array()[0]["total"];
}
else {
$this->sys_error_db("m_doctor count",$this->db_regional);
exit;
}
$sql = "SELECT * FROM(SELECT M_DoctorID, CONCAT(M_DoctorPrefix, ' ',M_DoctorName) as M_DoctorName
FROM m_doctor
WHERE M_DoctorIsActive = 'Y') a
WHERE
M_DoctorName like ?
GROUP BY M_DoctorID
ORDER BY M_DoctorName ASC";
$query = $this->db_regional->query($sql, array($q['search']));
if ($query) {
$rows = $query->result_array();
//echo $this->db_regional->last_query();
$result = array("total" => $tot_count, "records" => $rows, "total_display" => sizeof($rows));
$this->sys_ok($result);
}
else {
$this->sys_error_db("m_doctor rows",$this->db_regional);
exit;
}
}
function selectaddressdoctor(){
try {
//# cek token valid
if (! $this->isLogin) {
$this->sys_error("Invalid Token");
exit;
}
$prm = $this->sys_input;
$id = $prm['id'];
$rows = [];
$query ="SELECT M_DoctorAddressID,
CONCAT(M_DoctorAddressNote, ': ',M_DoctorAddressDescription) as M_DoctorAddressNote
FROM
m_doctoraddress
WHERE M_DoctorAddressIsActive = 'Y' AND M_DoctorAddressM_DoctorID = '{$id}'";
//echo $query;
$rows['addressdoctors'] = $this->db_regional->query($query)->result_array();
$result = array(
"total" => count($rows) ,
"records" => $rows,
);
$this->sys_ok($result);
} catch(Exception $exc) {
$message = $exc->getMessage();
$this->sys_error($message);
}
}
}

View File

@@ -0,0 +1,929 @@
<?php
class Category extends MY_Controller
{
var $db_regional;
public function index()
{
echo "CATEGORY API";
}
public function __construct()
{
parent::__construct();
$this->db_regional = $this->load->database("regional", true);
}
function lookupsubcategorybyname(){
try {
//# cek token valid
if (! $this->isLogin) {
$this->sys_error("Invalid Token");
exit;
}
$prm = $this->sys_input;
$category = $prm['category'];
$subcategory = $prm['subcategory'];;
$all = $prm['all'];
$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 t_subcategory
JOIN t_category ON T_SubCategoryT_CategoryID = T_CategoryID AND T_CategoryIsActive = 'Y'
WHERE
T_CategoryName LIKE CONCAT('%','{$category}','%') AND
T_SubCategoryName LIKE CONCAT('%','{$subcategory}','%') AND
T_SubCategoryIsActive = 'Y' GROUP BY T_SubCategoryID) a";
// $total = $this->db_regional->query($sql,$sql_param)->row()->total;
$query = $this->db_regional->query($sql);
//echo $this->db_regional->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("t_subcategory count", $this->db_regional);
exit;
}
$sql = "select T_SubCategoryID as id,
T_SubCategoryName as name,
T_CategoryID,
T_CategoryName,
t_subcategory.*
from t_subcategory
JOIN t_category ON T_SubCategoryT_CategoryID = T_CategoryID AND T_CategoryIsActive = 'Y'
WHERE
T_CategoryName LIKE CONCAT('%','{$category}','%') AND
T_SubCategoryName LIKE CONCAT('%','{$subcategory}','%') AND
T_SubCategoryIsActive = 'Y'
GROUP BY T_SubCategoryID
ORDER BY T_CategoryName ASC, T_SubCategoryName ASC
limit $number_limit offset $number_offset";
$sql_param = array($search);
$query = $this->db_regional->query($sql);
//echo $this->db_regional->last_query();
if ($query) {
$rows = $query->result_array();
} else {
$this->sys_error_db("t_subcategory 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 lookupcategorybyname()
{
try {
//# cek token valid
if (! $this->isLogin) {
$this->sys_error("Invalid Token");
exit;
}
$prm = $this->sys_input;
$category = $prm['category'];
$subcategory = $prm['subcategory'];
$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 t_category
LEFT JOIN t_subcategory ON T_CategoryID = T_SubCategoryT_CategoryID AND T_SubCategoryIsActive = 'Y'
where
T_CategoryName LIKE CONCAT('%','{$category}','%') AND
IFNULL(T_SubCategoryName,'') LIKE CONCAT('%','{$subcategory}','%') AND
T_CategoryIsActive = 'Y'
GROUP BY T_CategoryID) a";
$sql_param = array($search);
// $total = $this->db_regional->query($sql,$sql_param)->row()->total;
$query = $this->db_regional->query($sql);
$tot_count = 0;
$tot_page = 0;
if ($query) {
$tot_count = $query->result_array()[0]["total"];
$tot_page = ceil($tot_count/$number_limit);
} else {
$this->sys_error_db("t_category count", $this->db_regional);
exit;
}
$sql = "select T_CategoryID as id,
T_CategoryName as name,
T_CategoryName as namex,
t_category.*
from t_category
LEFT JOIN t_subcategory ON T_CategoryID = T_SubCategoryT_CategoryID AND T_SubCategoryIsActive = 'Y'
where
T_CategoryName LIKE CONCAT('%','{$category}','%') AND
IFNULL(T_SubCategoryName,'') LIKE CONCAT('%','{$subcategory}','%') AND
T_CategoryIsActive = 'Y'
GROUP BY T_CategoryID
ORDER BY T_CategoryName ASC
limit $number_limit offset $number_offset";
$sql_param = array($search);
$query = $this->db_regional->query($sql);
//echo $this->db_regional->last_query();
if ($query) {
$rows = $query->result_array();
} else {
$this->sys_error_db("t_category 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 addnewcategory()
{
try {
//# cek token valid
if (! $this->isLogin) {
$this->sys_error("Invalid Token");
exit;
}
//# ambil parameter input
$prm = $this->sys_input;
$name = $prm['name'];
$sql = "insert into t_category(
T_CategoryName,
T_CategoryCreated,
T_CategoryLastUpdated
)
values( ?, now(), now())";
$query = $this->db_regional->query($sql,
array(
$name
)
);
//echo $query;
if (!$query) {
$this->sys_error_db("t_category insert");
exit;
}
$last_id = $this->db_regional->insert_id();
$result = array ("total" => 1, "records" => array("xid" => 0));
$this->sys_ok($result);
$last_id = $this->db_regional->insert_id();
} catch(Exception $exc) {
$message = $exc->getMessage();
$this->sys_error($message);
}
}
public function editcategory()
{
try {
//# cek token valid
if (! $this->isLogin) {
$this->sys_error("Invalid Token");
exit;
}
//# ambil parameter input
$prm = $this->sys_input;
$id = $prm['id'];
$name = $prm['name'];
$userid = $this->sys_user["M_UserID"];
$sqlcompany = "update t_category SET
T_CategoryName = ?,
T_CategoryLastUpdated = now()
where
T_CategoryID = ?
";
$querycompany = $this->db_regional->query($sqlcompany,
array(
$name,
$id
)
);
// echo $query;
if (!$querycompany) {
$this->sys_error_db("t_category update");
exit;
}
$result = array ("total" => 1, "records" => array("xid" => $id));
$this->sys_ok($result);
} catch(Exception $exc) {
$message = $exc->getMessage();
$this->sys_error($message);
}
}
public function addnewsubcategory()
{
try {
//# cek token valid
if (! $this->isLogin) {
$this->sys_error("Invalid Token");
exit;
}
//# ambil parameter input
$prm = $this->sys_input;
$categoryid = $prm['categoryid'];
$name = $prm['name'];
$description = $prm['description'];
$userid = $this->sys_user["M_UserID"];
if($categoryid == 0){
$errors = array();
if($categoryid == 0){
array_push($errors,array('field'=>'category','msg'=>'Kategori dipilih dulu dong'));
}
$result = array ("total" => -1,"errors" => $errors, "records" => 0);
$this->sys_ok($result);
}else{
if($prm['xid'] == 0){
$query = "SELECT COUNT(*) as exist FROM t_subcategory WHERE T_SubCategoryIsActive = 'Y' AND T_SubCategoryName = '{$name}'";
$exist_code = $this->db_regional->query($query)->row()->exist;
if($exist_code == 0){
$sql = "insert into t_subcategory(
T_SubCategoryT_CategoryID,
T_SubCategoryName,
T_SubCategoryDescription,
T_SubCategoryUserID,
T_SubCategoryLastUpdate,
T_SubCategoryCreated)
values(?,?,?,?,now(),now())";
$query = $this->db_regional->query($sql,
array(
$categoryid,
$name,
$description,
$userid
)
);
if (!$query) {
$this->sys_error_db("t_subcategory insert",$this->db_regional);
exit;
}
$last_id = $this->db_regional->insert_id();
$result = array ("total" => 1, "records" => array("xid" => 0));
$this->sys_ok($result);
}else{
$errors = array();
if($exist_code != 0){
array_push($errors,array('field'=>'code','msg'=>'Nama sudah ada yang pakai dong'));
}
$result = array ("total" => -1,"errors" => $errors, "records" => 0);
$this->sys_ok($result);
}
}else{
$query = "SELECT COUNT(*) as exist FROM t_subcategory WHERE T_SubCategoryIsActive = 'Y' AND T_SubCategoryName = '{$name}' AND T_SubCategoryID <> {$prm['xid']}";
//echo $query;
$exist_code = $this->db_regional->query($query)->row()->exist;
// echo $exist_code;
if($exist_code == 0){
$sql = "UPDATE t_subcategory SET T_SubCategoryT_CategoryID = '{$categoryid}',
T_SubCategoryName = '{$name}',
T_SubCategoryDescription = '{$description}',
T_SubCategoryUserID = '{$userid}'
WHERE T_SubCategoryID = '{$prm['xid']}'";
//echo $sql;
$query = $this->db_regional->query($sql);
$result = array ("total" => 1, "records" => array("xid" => 0));
$this->sys_ok($result);
}else{
$errors = array();
if($exist_code != 0){
array_push($errors,array('field'=>'code','msg'=>'Nama sudah ada yang pakai dong'));
}
$result = array ("total" => -1,"errors" => $errors, "records" => 0);
$this->sys_ok($result);
}
}
}
} catch(Exception $exc) {
$message = $exc->getMessage();
$this->sys_error($message);
}
}
public function deletecategory()
{
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 t_category SET
T_CategoryIsActive = 'N',
T_CategoryLastUpdated = now()
WHERE
T_CategoryID = ?
";
$query = $this->db_regional->query($sql,
array(
$prm['id']
)
);
// echo $query;
if (!$query) {
$this->sys_error_db("t_category delete");
exit;
}
$sql = "update t_subcategory SET
T_SubCategoryIsActive = 'N',
T_SubCategoryLastUpdate = now()
WHERE
T_SubCategoryT_CategoryID = ?
";
$query = $this->db_regional->query($sql,
array(
$prm['id']
)
);
// echo $query;
if (!$query) {
$this->sys_error_db("t_subcategory 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 deletesubcategory()
{
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 t_subcategory SET
T_SubCategoryIsActive = 'N',
T_SubCategoryLastUpdate = now()
WHERE
T_SubCategoryID = ?
";
$query = $this->db_regional->query($sql,
array(
$prm['id']
)
);
// echo $query;
if (!$query) {
$this->sys_error_db("t_subcategory 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 searchcategory(){
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_category
WHERE
T_CategoryName like ?
AND T_CategoryIsActive = 'Y'";
$query = $this->db_regional->query($sql,$q['search']);
//echo $query;
if ($query) {
$tot_count = $query->result_array()[0]["total"];
}
else {
$this->sys_error_db("t_category count",$this->db_regional);
exit;
}
$sql = "
SELECT T_CategoryID, T_CategoryName
FROM t_category
WHERE
T_CategoryName like ?
AND T_CategoryIsActive = 'Y'
ORDER BY T_CategoryName ASC
";
$query = $this->db_regional->query($sql, array($q['search']));
if ($query) {
$rows = $query->result_array();
//echo $this->db_regional->last_query();
$result = array("total" => $tot_count, "records" => $rows, "total_display" => sizeof($rows));
$this->sys_ok($result);
}
else {
$this->sys_error_db("t_category rows",$this->db_regional);
exit;
}
}
function searchcategorybyname(){
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_category
WHERE
T_CategoryName like ?
AND T_CategoryIsActive = 'Y'";
$query = $this->db_regional->query($sql,$q['search']);
//echo $query;
if ($query) {
$tot_count = $query->result_array()[0]["total"];
}
else {
$this->sys_error_db("t_category count",$this->db_regional);
exit;
}
$sql = "
SELECT T_CategoryID, T_CategoryName
FROM t_category
WHERE
T_CategoryName like ?
AND T_CategoryIsActive = 'Y'
ORDER BY T_CategoryName ASC
";
$query = $this->db_regional->query($sql, array($q['search']));
if ($query) {
$rows = $query->result_array();
//echo $this->db_regional->last_query();
$result = array("total" => $tot_count, "records" => $rows, "total_display" => sizeof($rows));
$this->sys_ok($result);
}
else {
$this->sys_error_db("t_category rows",$this->db_regional);
exit;
}
}
function searchcity(){
if (! $this->isLogin) {
$this->sys_error("Invalid Token");
exit;
}
$prm = $this->sys_input;
$max_rst = 12;
$tot_count =0;
$q = [
'search' => '%'
];
if ($prm['search'] != '')
{
$q['search'] = "%{$prm['search']}%";
}
// QUERY TOTAL
$sql = "SELECT count(*) as total
FROM m_city
WHERE
M_CityName like ?
AND M_CityIsActive = 'Y'";
$query = $this->db_regional->query($sql,$q['search']);
//echo $query;
if ($query) {
$tot_count = $query->result_array()[0]["total"];
}
else {
$this->sys_error_db("m_city count",$this->db_regional);
exit;
}
$sql = "
SELECT *
FROM m_city
WHERE
M_CityName like ?
AND M_CityIsActive = 'Y'
ORDER BY M_CityName ASC
";
$query = $this->db_regional->query($sql, array($q['search']));
if ($query) {
$rows = $query->result_array();
//echo $this->db_regional->last_query();
$result = array("total" => $tot_count, "records" => $rows, "total_display" => sizeof($rows));
$this->sys_ok($result);
}
else {
$this->sys_error_db("m_city rows",$this->db_regional);
exit;
}
}
function searchdistrict(){
if (! $this->isLogin) {
$this->sys_error("Invalid Token");
exit;
}
$prm = $this->sys_input;
$id = $prm['id'];
$max_rst = 12;
$tot_count =0;
$q = [
'search' => '%'
];
if ($prm['search'] != '')
{
$q['search'] = "%{$prm['search']}%";
}
// QUERY TOTAL
$sql = "SELECT count(*) as total
FROM m_district
WHERE
M_DistrictName like ?
AND M_DistrictM_CityID = '{$id}'
AND M_DistrictIsActive = 'Y'";
$query = $this->db_regional->query($sql,$q['search']);
//echo $query;
if ($query) {
$tot_count = $query->result_array()[0]["total"];
}
else {
$this->sys_error_db("m_district count",$this->db_regional);
exit;
}
$sql = "
SELECT *
FROM m_district
WHERE
M_DistrictName like ?
AND M_DistrictM_CityID = '{$id}'
AND M_DistrictIsActive = 'Y'
ORDER BY M_DistrictName ASC
";
$query = $this->db_regional->query($sql, array($q['search']));
if ($query) {
$rows = $query->result_array();
//echo $this->db_regional->last_query();
$result = array("total" => $tot_count, "records" => $rows, "total_display" => sizeof($rows));
$this->sys_ok($result);
}
else {
$this->sys_error_db("m_district rows",$this->db_regional);
exit;
}
}
function searchkelurahan(){
if (! $this->isLogin) {
$this->sys_error("Invalid Token");
exit;
}
$prm = $this->sys_input;
$id = $prm['id'];
$max_rst = 12;
$tot_count =0;
$q = [
'search' => '%'
];
if ($prm['search'] != '')
{
$q['search'] = "%{$prm['search']}%";
}
// QUERY TOTAL
$sql = "SELECT count(*) as total
FROM m_kelurahan
WHERE
M_KelurahanName like ?
AND M_KelurahanM_DistrictID = '{$id}'
AND M_KelurahanIsActive = 'Y'";
$query = $this->db_regional->query($sql,$q['search']);
//echo $query;
if ($query) {
$tot_count = $query->result_array()[0]["total"];
}
else {
$this->sys_error_db("m_district count",$this->db_regional);
exit;
}
$sql = "
SELECT *
FROM m_kelurahan
WHERE
M_KelurahanName like ?
AND M_KelurahanM_DistrictID = '{$id}'
AND M_KelurahanIsActive = 'Y'
ORDER BY M_KelurahanName ASC
";
$query = $this->db_regional->query($sql, array($q['search']));
if ($query) {
$rows = $query->result_array();
//echo $this->db_regional->last_query();
$result = array("total" => $tot_count, "records" => $rows, "total_display" => sizeof($rows));
$this->sys_ok($result);
}
else {
$this->sys_error_db("m_district rows",$this->db_regional);
exit;
}
}
function searchcompany(){
if (! $this->isLogin) {
$this->sys_error("Invalid Token");
exit;
}
$prm = $this->sys_input;
$max_rst = 12;
$tot_count =0;
$q = [
'search' => '%'
];
if ($prm['search'] != '')
{
$q['search'] = "%{$prm['search']}%";
}
// QUERY TOTAL
$sql = "SELECT count(*) as total
FROM m_company
WHERE
M_CompanyName like ?
AND M_CompanyIsActive = 'Y'";
$query = $this->db_regional->query($sql,$q['search']);
//echo $query;
if ($query) {
$tot_count = $query->result_array()[0]["total"];
}
else {
$this->sys_error_db("m_company count",$this->db_regional);
exit;
}
$sql = "
SELECT *
FROM m_company
WHERE
M_CompanyName like ?
AND M_CompanyIsActive = 'Y'
ORDER BY M_CompanyName ASC
";
$query = $this->db_regional->query($sql, array($q['search']));
if ($query) {
$rows = $query->result_array();
//echo $this->db_regional->last_query();
$result = array("total" => $tot_count, "records" => $rows, "total_display" => sizeof($rows));
$this->sys_ok($result);
}
else {
$this->sys_error_db("m_company rows",$this->db_regional);
exit;
}
}
function searchmou(){
if (! $this->isLogin) {
$this->sys_error("Invalid Token");
exit;
}
$prm = $this->sys_input;
$id = $prm['id'];
$max_rst = 12;
$tot_count =0;
$q = [
'search' => '%'
];
if ($prm['search'] != '')
{
$q['search'] = "%{$prm['search']}%";
}
// QUERY TOTAL
$sql = "SELECT count(*) as total
FROM m_mou
WHERE
M_MouName like ?
AND M_MouM_CompanyID = '{$id}'
AND M_MouIsActive = 'Y'";
$query = $this->db_regional->query($sql,$q['search']);
//echo $query;
if ($query) {
$tot_count = $query->result_array()[0]["total"];
}
else {
$this->sys_error_db("m_mou count",$this->db_regional);
exit;
}
$sql = "SELECT *
FROM m_mou
WHERE
M_MouName like ?
AND M_MouM_CompanyID = '{$id}'
AND M_MouIsActive = 'Y'
ORDER BY M_MouName ASC
";
$query = $this->db_regional->query($sql, array($q['search']));
if ($query) {
$rows = $query->result_array();
// echo $this->db_regional->last_query();
$result = array("total" => $tot_count, "records" => $rows, "total_display" => sizeof($rows));
$this->sys_ok($result);
}
else {
$this->sys_error_db("m_mou rows",$this->db_regional);
exit;
}
}
function searchdoctor(){
if (! $this->isLogin) {
$this->sys_error("Invalid Token");
exit;
}
$prm = $this->sys_input;
$max_rst = 12;
$tot_count =0;
$q = [
'search' => '%'
];
if ($prm['search'] != '')
{
$q['search'] = "%{$prm['search']}%";
}
// QUERY TOTAL
$sql = "SELECT count(*) as total
FROM(SELECT M_DoctorID, CONCAT(M_DoctorPrefix, ' ',M_DoctorName) as M_DoctorName
FROM m_doctor
WHERE M_DoctorIsActive = 'Y') a
WHERE
M_DoctorName like ?";
$query = $this->db_regional->query($sql,$q['search']);
//echo $query;
if ($query) {
$tot_count = $query->result_array()[0]["total"];
}
else {
$this->sys_error_db("m_doctor count",$this->db_regional);
exit;
}
$sql = "SELECT * FROM(SELECT M_DoctorID, CONCAT(M_DoctorPrefix, ' ',M_DoctorName) as M_DoctorName
FROM m_doctor
WHERE M_DoctorIsActive = 'Y') a
WHERE
M_DoctorName like ?
ORDER BY M_DoctorName ASC
";
$query = $this->db_regional->query($sql, array($q['search']));
if ($query) {
$rows = $query->result_array();
//echo $this->db_regional->last_query();
$result = array("total" => $tot_count, "records" => $rows, "total_display" => sizeof($rows));
$this->sys_ok($result);
}
else {
$this->sys_error_db("m_doctor rows",$this->db_regional);
exit;
}
}
function selectdescriptiondoctor(){
try {
//# cek token valid
if (! $this->isLogin) {
$this->sys_error("Invalid Token");
exit;
}
$prm = $this->sys_input;
$rows = [];
$query ="SELECT M_DoctorDescriptionID,
CONCAT(M_DoctorDescriptionNote, ': ',M_DoctorDescriptionDescription) as M_DoctorDescriptionNote
FROM
m_doctordescription
WHERE M_DoctorDescriptionIsActive = 'Y' AND M_DoctorDescriptionM_DoctorID = '{$id}'";
//echo $query;
$rows['descriptiondoctors'] = $this->db_regional->query($query)->result_array();
$result = array(
"total" => count($rows) ,
"records" => $rows,
);
$this->sys_ok($result);
} catch(Exception $exc) {
$message = $exc->getMessage();
$this->sys_error($message);
}
}
}

View File

@@ -0,0 +1,913 @@
<?php
class Description extends MY_Controller
{
var $db_regional;
public function index()
{
echo "BRANCH API";
}
public function __construct()
{
parent::__construct();
$this->db_regional = $this->load->database("regional", true);
}
function lookupattributebyname(){
try {
//# cek token valid
if (! $this->isLogin) {
$this->sys_error("Invalid Token");
exit;
}
$prm = $this->sys_input;
$attribute = $prm['branch'];
$all = $prm['all'];
$limit = '';
if($all == 'N'){
$limit = ' LIMIT 10';
}
$number_limit = 10;
$number_offset = ($prm['current_page'] - 1) * $number_limit ;
$sql = "select COUNT(*) as total
from nat_ol_description
JOIN nat_test ON Nat_TestID = NatOlDescriptionNat_TestID
WHERE
(Nat_TestName LIKE CONCAT('%','{$attribute}','%') OR
Nat_TestCode LIKE CONCAT('%','{$attribute}','%') OR
Nat_TestShortNameBarcode LIKE CONCAT('%','{$attribute}','%')) AND
NatOlDescriptionIsActive = 'Y'";
// $total = $this->db_regional->query($sql,$sql_param)->row()->total;
$query = $this->db_regional->query($sql);
// echo $this->db_regional->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("nat_ol_description count", $this->db_regional);
exit;
}
$sql = "select NatOlDescriptionID as id,
Nat_TestID,
Nat_TestName as testname,
Nat_TestCode,
CONCAT('[',Nat_TestCode,'] ',Nat_TestName) as Nat_TestName,
Nat_TestShortNameBarcode,
nat_ol_description.*
from nat_ol_description
JOIN nat_test ON Nat_TestID = NatOlDescriptionNat_TestID
WHERE
(Nat_TestName LIKE CONCAT('%','{$attribute}','%') OR
Nat_TestCode LIKE CONCAT('%','{$attribute}','%') OR
Nat_TestShortNameBarcode LIKE CONCAT('%','{$attribute}','%')) AND
NatOlDescriptionIsActive = 'Y'
GROUP BY NatOlDescriptionID
ORDER BY Nat_TestCode ASC
limit $number_limit offset $number_offset";
$sql_param = array($search);
$query = $this->db_regional->query($sql);
//echo $this->db_regional->last_query();
if ($query) {
$rows = $query->result_array();
} else {
$this->sys_error_db("nat_ol_description 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 lookupregionalbyname()
{
try {
//# cek token valid
if (! $this->isLogin) {
$this->sys_error("Invalid Token");
exit;
}
$prm = $this->sys_input;
$regional = $prm['regional'];
$attribute = $prm['attribute'];
$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 s_regional
LEFT JOIN nat_ol_description ON S_RegionalID = NatOlDescriptionS_RegionalID AND NatOlDescriptionIsActive = 'Y'
where
S_RegionalName LIKE CONCAT('%','{$regional}','%') AND
IFNULL(NatOlDescriptionName,'') LIKE CONCAT('%','{$attribute}','%') AND
S_RegionalIsActive = 'Y'
GROUP BY S_RegionalID) a";
$sql_param = array($search);
// $total = $this->db_regional->query($sql,$sql_param)->row()->total;
$query = $this->db_regional->query($sql);
$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("s_regional count", $this->db_regional);
exit;
}
$sql = "select S_RegionalID as id,
S_RegionalName as name,
S_RegionalName as namex,
s_regional.*
from s_regional
LEFT JOIN nat_ol_description ON S_RegionalID = NatOlDescriptionS_RegionalID AND NatOlDescriptionIsActive = 'Y'
where
S_RegionalName LIKE CONCAT('%','{$regional}','%') AND
IFNULL(NatOlDescriptionName,'') LIKE CONCAT('%','{$attribute}','%') AND
S_RegionalIsActive = 'Y'
GROUP BY S_RegionalID
ORDER BY S_RegionalName ASC
limit $number_limit offset $number_offset";
$sql_param = array($search);
$query = $this->db_regional->query($sql);
//echo $this->db_regional->last_query();
if ($query) {
$rows = $query->result_array();
} else {
$this->sys_error_db("s_regional 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 addnewregional()
{
try {
//# cek token valid
if (! $this->isLogin) {
$this->sys_error("Invalid Token");
exit;
}
//# ambil parameter input
$prm = $this->sys_input;
$name = $prm['name'];
$sql = "insert into s_regional(
S_RegionalName,
S_RegionalCreated,
S_RegionalLastUpdated
)
values( ?, now(), now())";
$query = $this->db_regional->query($sql,
array(
$name
)
);
//echo $query;
if (!$query) {
$this->sys_error_db("s_regional insert");
exit;
}
$last_id = $this->db_regional->insert_id();
$result = array ("total" => 1, "records" => array("xid" => 0));
$this->sys_ok($result);
$last_id = $this->db_regional->insert_id();
} catch(Exception $exc) {
$message = $exc->getMessage();
$this->sys_error($message);
}
}
public function editregional()
{
try {
//# cek token valid
if (! $this->isLogin) {
$this->sys_error("Invalid Token");
exit;
}
//# ambil parameter input
$prm = $this->sys_input;
$id = $prm['id'];
$name = $prm['name'];
$userid = $this->sys_user["M_UserID"];
$sqlcompany = "update s_regional SET
S_RegionalName = ?,
S_RegionalLastUpdated = now()
where
S_RegionalID = ?
";
$querycompany = $this->db_regional->query($sqlcompany,
array(
$name,
$id
)
);
// echo $query;
if (!$querycompany) {
$this->sys_error_db("s_regional update");
exit;
}
$result = array ("total" => 1, "records" => array("xid" => $id));
$this->sys_ok($result);
} catch(Exception $exc) {
$message = $exc->getMessage();
$this->sys_error($message);
}
}
public function addnewattribute()
{
try {
//# cek token valid
if (! $this->isLogin) {
$this->sys_error("Invalid Token");
exit;
}
//# ambil parameter input
$prm = $this->sys_input;
$NatOlDescriptionNat_TestID = $prm['testid'];
$NatOlDescriptionNote = $prm['note'];
$userid = $this->sys_user["M_UserID"];
if($NatOlDescriptionNat_TestID == 0){
$errors = array();
if($NatOlDescriptionNat_TestID == 0){
array_push($errors,array('field'=>'regional','msg'=>'Pemeriksaan dipilih dulu dong'));
}
$result = array ("total" => -1,"errors" => $errors, "records" => 0);
$this->sys_ok($result);
}else{
if($prm['xid'] == 0){
$sql = "insert into nat_ol_description(
NatOlDescriptionNat_TestID,
NatOlDescriptionNote,
NatOlDescriptionCreated,
NatOlDescriptionLastUpdated,
NatOlDescriptionM_UserID)
values(?,?,now(),now(),?)";
$query = $this->db_regional->query($sql,
array(
$NatOlDescriptionNat_TestID,
$NatOlDescriptionNote,
$userid)
);
if (!$query) {
$this->sys_error_db("nat_ol_description insert",$this->db_regional);
exit;
}
$last_id = $this->db_regional->insert_id();
$result = array ("total" => 1, "records" => array("xid" => 0));
$this->sys_ok($result);
}else{
$sql = "UPDATE nat_ol_description SET NatOlDescriptionNat_TestID = '{$NatOlDescriptionNat_TestID}',
NatOlDescriptionNote = '{$NatOlDescriptionNote}',
NatOlDescriptionM_UserID = '{$userid}',
NatOlDescriptionLastUpdated = now()
WHERE NatOlDescriptionID = '{$prm['xid']}'";
//echo $sql;
$query = $this->db_regional->query($sql);
$result = array ("total" => 1, "records" => array("xid" => 0));
$this->sys_ok($result);
}
}
} catch(Exception $exc) {
$message = $exc->getMessage();
$this->sys_error($message);
}
}
public function deleteregional()
{
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 s_regional SET
S_RegionalIsActive = 'N',
S_RegionalLastUpdated = now()
WHERE
S_RegionalID = ?
";
$query = $this->db_regional->query($sql,
array(
$prm['id']
)
);
// echo $query;
if (!$query) {
$this->sys_error_db("s_regional delete");
exit;
}
$sql = "update nat_ol_description SET
NatOlDescriptionIsActive = 'N',
NatOlDescriptionLastUpdated = now()
WHERE
NatOlDescriptionS_RegionalID = ?
";
$query = $this->db_regional->query($sql,
array(
$prm['id']
)
);
// echo $query;
if (!$query) {
$this->sys_error_db("nat_ol_description 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 deleteattribute()
{
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_ol_description SET
NatOlDescriptionIsActive = 'N',
NatOlDescriptionLastUpdated = now()
WHERE
NatOlDescriptionID = ?
";
$query = $this->db_regional->query($sql,
array(
$prm['id']
)
);
// echo $query;
if (!$query) {
$this->sys_error_db("nat_ol_description 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 searchtest(){
if (! $this->isLogin) {
$this->sys_error("Invalid Token");
exit;
}
$prm = $this->sys_input;
$max_rst = 12;
$tot_count =0;
$q = [
'search' => '%'
];
if ($prm['tes'] != '')
{
$q['search'] = "%{$prm['tes']}%";
}
// QUERY TOTAL
$sql = "SELECT count(*) as total
FROM nat_test
WHERE
CONCAT('[',Nat_TestCode,'] ',Nat_TestName) like ?
AND Nat_TestIsActive = 'Y'
AND Nat_TestIsPrice = 'Y'
AND Nat_TestID not in (
select NatOlDescriptionNat_TestID from nat_ol_description where NatOlDescriptionIsActive = 'Y')";
$query = $this->db_regional->query($sql,$q['search']);
//echo $query;
if ($query) {
$tot_count = $query->result_array()[0]["total"];
}
else {
$this->sys_error_db("nat_test count",$this->db_regional);
exit;
}
$sql = "
SELECT Nat_TestID,CONCAT('[',Nat_TestCode,'] ',Nat_TestName) as Nat_TestName
FROM nat_test
WHERE
CONCAT('[',Nat_TestCode,'] ',Nat_TestName) like ?
AND Nat_TestIsActive = 'Y'
AND Nat_TestIsPrice = 'Y'
AND Nat_TestID not in (
select NatOlDescriptionNat_TestID from nat_ol_description where NatOlDescriptionIsActive = 'Y')
ORDER BY Nat_TestCode ASC
";
$query = $this->db_regional->query($sql, array($q['search']));
if ($query) {
$rows = $query->result_array();
// echo $this->db_regional->last_query();
$result = array("total" => $tot_count, "records" => $rows, "total_display" => sizeof($rows));
$this->sys_ok($result);
}
else {
$this->sys_error_db("nat_test rows",$this->db_regional);
exit;
}
}
function searchregionalbyname(){
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 s_regional
WHERE
S_RegionalName like ?
AND S_RegionalIsActive = 'Y'";
$query = $this->db_regional->query($sql,$q['search']);
//echo $query;
if ($query) {
$tot_count = $query->result_array()[0]["total"];
}
else {
$this->sys_error_db("s_regional count",$this->db_regional);
exit;
}
$sql = "
SELECT S_RegionalID, S_RegionalName
FROM s_regional
WHERE
S_RegionalName like ?
AND S_RegionalIsActive = 'Y'
ORDER BY S_RegionalName ASC
";
$query = $this->db_regional->query($sql, array($q['search']));
if ($query) {
$rows = $query->result_array();
//echo $this->db_regional->last_query();
$result = array("total" => $tot_count, "records" => $rows, "total_display" => sizeof($rows));
$this->sys_ok($result);
}
else {
$this->sys_error_db("s_regional rows",$this->db_regional);
exit;
}
}
function searchsubcategory(){
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_subcategory
WHERE
T_SubCategoryName like ?
AND T_SubCategoryIsActive = 'Y'";
$query = $this->db_regional->query($sql,$q['search']);
//echo $query;
if ($query) {
$tot_count = $query->result_array()[0]["total"];
}
else {
$this->sys_error_db("t_subcategory count",$this->db_regional);
exit;
}
$sql = "
SELECT T_CategoryID, T_CategoryName,T_SubCategoryID,CONCAT(T_SubCategoryName,'[',T_CategoryName,'] ') T_SubCategoryName
FROM t_subcategory
JOIN t_category ON T_CategoryID = T_SubCategoryT_CategoryID
WHERE
CONCAT(T_SubCategoryName,'[',T_CategoryName,'] ') like ?
AND T_SubCategoryIsActive = 'Y'
ORDER BY T_SubCategoryName ASC
";
$query = $this->db_regional->query($sql, array($q['search']));
if ($query) {
$rows = $query->result_array();
//echo $this->db_regional->last_query();
$result = array("total" => $tot_count, "records" => $rows, "total_display" => sizeof($rows));
$this->sys_ok($result);
}
else {
$this->sys_error_db("t_subcategory rows",$this->db_regional);
exit;
}
}
function searchdistrict(){
if (! $this->isLogin) {
$this->sys_error("Invalid Token");
exit;
}
$prm = $this->sys_input;
$id = $prm['id'];
$max_rst = 12;
$tot_count =0;
$q = [
'search' => '%'
];
if ($prm['search'] != '')
{
$q['search'] = "%{$prm['search']}%";
}
// QUERY TOTAL
$sql = "SELECT count(*) as total
FROM m_district
WHERE
M_DistrictName like ?
AND M_DistrictT_SubCategoryID = '{$id}'
AND M_DistrictIsActive = 'Y'";
$query = $this->db_regional->query($sql,$q['search']);
//echo $query;
if ($query) {
$tot_count = $query->result_array()[0]["total"];
}
else {
$this->sys_error_db("m_district count",$this->db_regional);
exit;
}
$sql = "
SELECT *
FROM m_district
WHERE
M_DistrictName like ?
AND M_DistrictT_SubCategoryID = '{$id}'
AND M_DistrictIsActive = 'Y'
ORDER BY M_DistrictName ASC
";
$query = $this->db_regional->query($sql, array($q['search']));
if ($query) {
$rows = $query->result_array();
//echo $this->db_regional->last_query();
$result = array("total" => $tot_count, "records" => $rows, "total_display" => sizeof($rows));
$this->sys_ok($result);
}
else {
$this->sys_error_db("m_district rows",$this->db_regional);
exit;
}
}
function searchkelurahan(){
if (! $this->isLogin) {
$this->sys_error("Invalid Token");
exit;
}
$prm = $this->sys_input;
$id = $prm['id'];
$max_rst = 12;
$tot_count =0;
$q = [
'search' => '%'
];
if ($prm['search'] != '')
{
$q['search'] = "%{$prm['search']}%";
}
// QUERY TOTAL
$sql = "SELECT count(*) as total
FROM m_kelurahan
WHERE
M_KelurahanName like ?
AND M_KelurahanM_DistrictID = '{$id}'
AND M_KelurahanIsActive = 'Y'";
$query = $this->db_regional->query($sql,$q['search']);
//echo $query;
if ($query) {
$tot_count = $query->result_array()[0]["total"];
}
else {
$this->sys_error_db("m_district count",$this->db_regional);
exit;
}
$sql = "
SELECT *
FROM m_kelurahan
WHERE
M_KelurahanName like ?
AND M_KelurahanM_DistrictID = '{$id}'
AND M_KelurahanIsActive = 'Y'
ORDER BY M_KelurahanName ASC
";
$query = $this->db_regional->query($sql, array($q['search']));
if ($query) {
$rows = $query->result_array();
//echo $this->db_regional->last_query();
$result = array("total" => $tot_count, "records" => $rows, "total_display" => sizeof($rows));
$this->sys_ok($result);
}
else {
$this->sys_error_db("m_district rows",$this->db_regional);
exit;
}
}
function searchcompany(){
if (! $this->isLogin) {
$this->sys_error("Invalid Token");
exit;
}
$prm = $this->sys_input;
$max_rst = 12;
$tot_count =0;
$q = [
'search' => '%'
];
if ($prm['search'] != '')
{
$q['search'] = "%{$prm['search']}%";
}
// QUERY TOTAL
$sql = "SELECT count(*) as total
FROM m_company
WHERE
M_CompanyName like ?
AND M_CompanyIsActive = 'Y'";
$query = $this->db_regional->query($sql,$q['search']);
//echo $query;
if ($query) {
$tot_count = $query->result_array()[0]["total"];
}
else {
$this->sys_error_db("m_company count",$this->db_regional);
exit;
}
$sql = "
SELECT *
FROM m_company
WHERE
M_CompanyName like ?
AND M_CompanyIsActive = 'Y'
ORDER BY M_CompanyName ASC
";
$query = $this->db_regional->query($sql, array($q['search']));
if ($query) {
$rows = $query->result_array();
//echo $this->db_regional->last_query();
$result = array("total" => $tot_count, "records" => $rows, "total_display" => sizeof($rows));
$this->sys_ok($result);
}
else {
$this->sys_error_db("m_company rows",$this->db_regional);
exit;
}
}
function searchmou(){
if (! $this->isLogin) {
$this->sys_error("Invalid Token");
exit;
}
$prm = $this->sys_input;
$id = $prm['id'];
$max_rst = 12;
$tot_count =0;
$q = [
'search' => '%'
];
if ($prm['search'] != '')
{
$q['search'] = "%{$prm['search']}%";
}
// QUERY TOTAL
$sql = "SELECT count(*) as total
FROM m_mou
WHERE
M_MouName like ?
AND M_MouM_CompanyID = '{$id}'
AND M_MouIsActive = 'Y'";
$query = $this->db_regional->query($sql,$q['search']);
//echo $query;
if ($query) {
$tot_count = $query->result_array()[0]["total"];
}
else {
$this->sys_error_db("m_mou count",$this->db_regional);
exit;
}
$sql = "SELECT *
FROM m_mou
WHERE
M_MouName like ?
AND M_MouM_CompanyID = '{$id}'
AND M_MouIsActive = 'Y'
ORDER BY M_MouName ASC
";
$query = $this->db_regional->query($sql, array($q['search']));
if ($query) {
$rows = $query->result_array();
// echo $this->db_regional->last_query();
$result = array("total" => $tot_count, "records" => $rows, "total_display" => sizeof($rows));
$this->sys_ok($result);
}
else {
$this->sys_error_db("m_mou rows",$this->db_regional);
exit;
}
}
function searchdoctor(){
if (! $this->isLogin) {
$this->sys_error("Invalid Token");
exit;
}
$prm = $this->sys_input;
$max_rst = 12;
$tot_count =0;
$q = [
'search' => '%'
];
if ($prm['search'] != '')
{
$q['search'] = "%{$prm['search']}%";
}
// QUERY TOTAL
$sql = "SELECT count(*) as total
FROM(SELECT M_DoctorID, CONCAT(M_DoctorPrefix, ' ',M_DoctorName) as M_DoctorName
FROM m_doctor
WHERE M_DoctorIsActive = 'Y') a
WHERE
M_DoctorName like ?";
$query = $this->db_regional->query($sql,$q['search']);
//echo $query;
if ($query) {
$tot_count = $query->result_array()[0]["total"];
}
else {
$this->sys_error_db("m_doctor count",$this->db_regional);
exit;
}
$sql = "SELECT * FROM(SELECT M_DoctorID, CONCAT(M_DoctorPrefix, ' ',M_DoctorName) as M_DoctorName
FROM m_doctor
WHERE M_DoctorIsActive = 'Y') a
WHERE
M_DoctorName like ?
GROUP BY M_DoctorID
ORDER BY M_DoctorName ASC";
$query = $this->db_regional->query($sql, array($q['search']));
if ($query) {
$rows = $query->result_array();
//echo $this->db_regional->last_query();
$result = array("total" => $tot_count, "records" => $rows, "total_display" => sizeof($rows));
$this->sys_ok($result);
}
else {
$this->sys_error_db("m_doctor rows",$this->db_regional);
exit;
}
}
function selectaddressdoctor(){
try {
//# cek token valid
if (! $this->isLogin) {
$this->sys_error("Invalid Token");
exit;
}
$prm = $this->sys_input;
$id = $prm['id'];
$rows = [];
$query ="SELECT M_DoctorAddressID,
CONCAT(M_DoctorAddressNote, ': ',M_DoctorAddressDescription) as M_DoctorAddressNote
FROM
m_doctoraddress
WHERE M_DoctorAddressIsActive = 'Y' AND M_DoctorAddressM_DoctorID = '{$id}'";
//echo $query;
$rows['addressdoctors'] = $this->db_regional->query($query)->result_array();
$result = array(
"total" => count($rows) ,
"records" => $rows,
);
$this->sys_ok($result);
} catch(Exception $exc) {
$message = $exc->getMessage();
$this->sys_error($message);
}
}
}

View File

@@ -0,0 +1,973 @@
<?php
class Resultoption extends MY_Controller
{
var $db_regional;
public function index()
{
echo "BRANCH API";
}
public function __construct()
{
parent::__construct();
$this->db_regional = $this->load->database("regional", true);
}
function lookupattributebyname(){
try {
//# cek token valid
if (! $this->isLogin) {
$this->sys_error("Invalid Token");
exit;
}
$prm = $this->sys_input;
$attribute = $prm['branch'];
$all = $prm['all'];
$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 t_testresultoption
JOIN t_test ON T_TestID = T_TestResultOptionT_TestID
JOIN t_resultoption ON T_ResultOptionID = T_TestResultOptionT_ResultOptionID
WHERE
(T_TestName LIKE CONCAT('%','{$attribute}','%') OR
T_TestSasCode LIKE CONCAT('%','{$attribute}','%')) AND
T_TestResultOptionIsActive = 'Y'
GROUP BY T_TestID) a";
// $total = $this->db_regional->query($sql,$sql_param)->row()->total;
$query = $this->db_regional->query($sql);
// echo $this->db_regional->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("t_testresultoption count", $this->db_regional);
exit;
}
$sql = "select T_TestResultOptionID as id,
T_TestID,
CONCAT('[',T_TestSasCode,'] ',T_TestName) T_TestName,
T_TestSasCode,
T_ResultOptionID,
T_ResultOptionName,
t_testresultoption.*,
'xxx' as resultoptions
from t_testresultoption
JOIN t_test ON T_TestID = T_TestResultOptionT_TestID
LEFT JOIN t_resultoption ON T_ResultOptionID = T_TestResultOptionT_ResultOptionID
WHERE
(T_TestName LIKE CONCAT('%','{$attribute}','%') OR
T_TestSasCode LIKE CONCAT('%','{$attribute}','%')) AND
T_TestResultOptionIsActive = 'Y'
GROUP BY T_TestID
ORDER BY T_TestSasCode ASC, T_ResultOptionName ASC
limit $number_limit offset $number_offset";
$sql_param = array($search);
$query = $this->db_regional->query($sql);
//echo $this->db_regional->last_query();
if ($query) {
$rows = $query->result_array();
if($rows){
foreach($rows as $k => $v){
$option = $v['T_TestResultOptionT_ResultOptionID'];
$test = $v['T_TestResultOptionT_TestID'];
$x = $this->db_regional->query("select concat( '[', group_concat( json_object('id',IFNULL(T_TestResultOptionID,T_ResultOptionID), 'optionname', T_ResultOptionName,'status', IF(IFNULL(T_ResultOptionID,0) = 0 AND T_ResultOptionDefault = 'N', 'N','Y')) separator ',' ), ']' )
as n FROM
(SELECT T_TestResultOptionID,T_TestResultOptionT_TestID,T_ResultOptionID,T_ResultOptionName,T_ResultOptionDefault
FROM t_resultoption
JOIN t_testresultoption ON T_TestResultOptionT_ResultOptionID = T_ResultOptionID AND T_TestResultOptionT_TestID = $test AND T_TestResultOptionIsActive = 'Y'
WHERE T_ResultOptionIsActive = 'Y'
GROUP BY T_ResultOptionID) a")->row();
$rows[$k]['resultoptionx'] = json_decode($x->n);
$rows[$k]['resultoptions'] = $this->add_resultoption($option,$test);
$rows[$k]['action'] = '<v-icon color="error" @click="deleteAddress(props.item)">delete</v-icon>';
$rows[$k]['action'] .= '<v-icon color="primary" @click="deleteAddress(props.item)">edit</v-icon>';
}
}
} else {
$this->sys_error_db("t_testresultoption 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 add_resultoption($option,$test){
$query =" SELECT t_testresultoption.*, t_resultoption.*,IF(T_TestResultOptionID IS NULL,'N','Y') as isresultoption, IFNULL(T_TestResultOptionID,0) as xid
FROM t_resultoption
LEFT JOIN t_testresultoption ON T_TestResultOptionT_ResultOptionID = T_ResultOptionID AND T_TestResultOptionT_TestID = $test AND T_TestResultOptionIsActive = 'Y'
WHERE T_ResultOptionIsActive = 'Y'
GROUP BY T_ResultOptionID";
//echo $query;
$rows = $this->db_regional->query($query)->result_array();
if(!$rows)
$rows = array();
return $rows;
}
function getresultoption(){
if (! $this->isLogin) {
$this->sys_error("Invalid Token");
exit;
}
$rows = [];
$query =" SELECT *,IF(T_ResultOptionDefault = 'N','N','Y') as isresultoption, 0 as xid
FROM t_resultoption
WHERE
T_ResultOptionIsActive = 'Y'
";
//echo $query;
$rows['resultoptions'] = $this->db_regional->query($query)->result_array();
$result = array(
"total" => count($rows) ,
"records" => $rows,
);
$this->sys_ok($result);
exit;
}
public function lookupregionalbyname()
{
try {
//# cek token valid
if (! $this->isLogin) {
$this->sys_error("Invalid Token");
exit;
}
$prm = $this->sys_input;
$regional = $prm['regional'];
$attribute = $prm['attribute'];
$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 s_regional
LEFT JOIN t_testresultoption ON S_RegionalID = T_TestResultOptionS_RegionalID AND T_TestResultOptionIsActive = 'Y'
where
S_RegionalName LIKE CONCAT('%','{$regional}','%') AND
IFNULL(T_TestResultOptionName,'') LIKE CONCAT('%','{$attribute}','%') AND
S_RegionalIsActive = 'Y'
GROUP BY S_RegionalID) a";
$sql_param = array($search);
// $total = $this->db_regional->query($sql,$sql_param)->row()->total;
$query = $this->db_regional->query($sql);
$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("s_regional count", $this->db_regional);
exit;
}
$sql = "select S_RegionalID as id,
S_RegionalName as name,
S_RegionalName as namex,
s_regional.*
from s_regional
LEFT JOIN t_testresultoption ON S_RegionalID = T_TestResultOptionS_RegionalID AND T_TestResultOptionIsActive = 'Y'
where
S_RegionalName LIKE CONCAT('%','{$regional}','%') AND
IFNULL(T_TestResultOptionName,'') LIKE CONCAT('%','{$attribute}','%') AND
S_RegionalIsActive = 'Y'
GROUP BY S_RegionalID
ORDER BY S_RegionalName ASC
limit $number_limit offset $number_offset";
$sql_param = array($search);
$query = $this->db_regional->query($sql);
//echo $this->db_regional->last_query();
if ($query) {
$rows = $query->result_array();
} else {
$this->sys_error_db("s_regional 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 addnewregional()
{
try {
//# cek token valid
if (! $this->isLogin) {
$this->sys_error("Invalid Token");
exit;
}
//# ambil parameter input
$prm = $this->sys_input;
$name = $prm['name'];
$sql = "insert into s_regional(
S_RegionalName,
S_RegionalCreated,
S_RegionalLastUpdated
)
values( ?, now(), now())";
$query = $this->db_regional->query($sql,
array(
$name
)
);
//echo $query;
if (!$query) {
$this->sys_error_db("s_regional insert");
exit;
}
$last_id = $this->db_regional->insert_id();
$result = array ("total" => 1, "records" => array("xid" => 0));
$this->sys_ok($result);
$last_id = $this->db_regional->insert_id();
} catch(Exception $exc) {
$message = $exc->getMessage();
$this->sys_error($message);
}
}
public function editregional()
{
try {
//# cek token valid
if (! $this->isLogin) {
$this->sys_error("Invalid Token");
exit;
}
//# ambil parameter input
$prm = $this->sys_input;
$id = $prm['id'];
$name = $prm['name'];
$userid = $this->sys_user["M_UserID"];
$sqlcompany = "update s_regional SET
S_RegionalName = ?,
S_RegionalLastUpdated = now()
where
S_RegionalID = ?
";
$querycompany = $this->db_regional->query($sqlcompany,
array(
$name,
$id
)
);
// echo $query;
if (!$querycompany) {
$this->sys_error_db("s_regional update");
exit;
}
$result = array ("total" => 1, "records" => array("xid" => $id));
$this->sys_ok($result);
} catch(Exception $exc) {
$message = $exc->getMessage();
$this->sys_error($message);
}
}
public function addnewresultoption()
{
try {
//# cek token valid
if (! $this->isLogin) {
$this->sys_error("Invalid Token");
exit;
}
//# ambil parameter input
$prm = $this->sys_input;
$T_TestResultOptionT_TestID = $prm['testid'];
$userid = $this->sys_user["M_UserID"];
if($T_TestResultOptionT_TestID == 0){
$errors = array();
if($T_TestResultOptionT_TestID == 0){
array_push($errors,array('field'=>'regional','msg'=>'Pemeriksaan dipilih dulu dong'));
}
$result = array ("total" => -1,"errors" => $errors, "records" => 0);
$this->sys_ok($result);
}else{
if($prm['xid'] == 0){
foreach($prm['orderregtimes'] as $k=>$v){
if($v['isresultoption'] === 'Y'){
$xtime = $v['T_ResultOptionID'];
$sql = "INSERT INTO t_testresultoption(
T_TestResultOptionT_TestID,
T_TestResultOptionT_ResultOptionID,
T_TestResultOptionUserID,
T_TestResultOptionLastUpdated,
T_TestResultOptionCreated)
VALUES(?,?,?,now(),now())";
$query = $this->db_regional->query($sql,array($T_TestResultOptionT_TestID,$xtime,$userid));
}
}
if (!$query) {
$this->sys_error_db("t_testresultoption insert",$this->db_regional);
exit;
}
$last_id = $this->db_regional->insert_id();
$result = array ("total" => 1, "records" => array("xid" => 0));
$this->sys_ok($result);
}else{
foreach($prm['orderregtimes'] as $k=>$v){
if($v['isresultoption'] === 'Y' && $v['xid'] == 0){
$xtime = $v['T_ResultOptionID'];
$sql = "INSERT INTO t_testresultoption(
T_TestResultOptionT_TestID,
T_TestResultOptionT_ResultOptionID,
T_TestResultOptionUserID,
T_TestResultOptionLastUpdated,
T_TestResultOptionCreated)
VALUES(?,?,?,now(),now())";
$query = $this->db_regional->query($sql,array($T_TestResultOptionT_TestID,$xtime,$userid));
}else if($v['isresultoption'] === 'N'){
$sql ="UPDATE t_testresultoption SET
T_TestResultOptionIsActive = 'N',
T_TestResultOptionUserID = '{$userid}',
T_TestResultOptionLastUpdated = now()
WHERE
T_TestResultOptionID = ?";
$query = $this->db_regional->query($sql,array($v['xid']));
}
}
$result = array ("total" => 1, "records" => array("xid" => 0));
$this->sys_ok($result);
}
}
} catch(Exception $exc) {
$message = $exc->getMessage();
$this->sys_error($message);
}
}
public function deleteregional()
{
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 s_regional SET
S_RegionalIsActive = 'N',
S_RegionalLastUpdated = now()
WHERE
S_RegionalID = ?
";
$query = $this->db_regional->query($sql,
array(
$prm['id']
)
);
// echo $query;
if (!$query) {
$this->sys_error_db("s_regional delete");
exit;
}
$sql = "update t_testresultoption SET
T_TestResultOptionIsActive = 'N',
T_TestResultOptionLastUpdated = now()
WHERE
T_TestResultOptionS_RegionalID = ?
";
$query = $this->db_regional->query($sql,
array(
$prm['id']
)
);
// echo $query;
if (!$query) {
$this->sys_error_db("t_testresultoption 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 deleteattribute()
{
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 t_testresultoption SET
T_TestResultOptionIsActive = 'N',
T_TestResultOptionLastUpdated = now()
WHERE
T_TestResultOptionID = ?
";
$query = $this->db_regional->query($sql,
array(
$prm['id']
)
);
// echo $query;
if (!$query) {
$this->sys_error_db("t_testresultoption 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 searchtest(){
if (! $this->isLogin) {
$this->sys_error("Invalid Token");
exit;
}
$prm = $this->sys_input;
$max_rst = 12;
$tot_count =0;
$q = [
'search' => '%'
];
if ($prm['tes'] != '')
{
$q['search'] = "%{$prm['tes']}%";
}
// QUERY TOTAL
$sql = "SELECT count(*) as total
FROM t_test
WHERE
T_TestName like ?
AND T_TestIsActive = 'Y'";
$query = $this->db_regional->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_regional);
exit;
}
$sql = "
SELECT T_TestID,CONCAT('[',T_TestSasCode,'] ',T_TestName) as T_TestName
FROM t_test
WHERE
CONCAT('[',T_TestSasCode,'] ',T_TestName) like ?
AND T_TestIsActive = 'Y'
ORDER BY T_TestSasCode ASC
";
$query = $this->db_regional->query($sql, array($q['search']));
if ($query) {
$rows = $query->result_array();
//echo $this->db_regional->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_regional);
exit;
}
}
function searchregionalbyname(){
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 s_regional
WHERE
S_RegionalName like ?
AND S_RegionalIsActive = 'Y'";
$query = $this->db_regional->query($sql,$q['search']);
//echo $query;
if ($query) {
$tot_count = $query->result_array()[0]["total"];
}
else {
$this->sys_error_db("s_regional count",$this->db_regional);
exit;
}
$sql = "
SELECT S_RegionalID, S_RegionalName
FROM s_regional
WHERE
S_RegionalName like ?
AND S_RegionalIsActive = 'Y'
ORDER BY S_RegionalName ASC
";
$query = $this->db_regional->query($sql, array($q['search']));
if ($query) {
$rows = $query->result_array();
//echo $this->db_regional->last_query();
$result = array("total" => $tot_count, "records" => $rows, "total_display" => sizeof($rows));
$this->sys_ok($result);
}
else {
$this->sys_error_db("s_regional rows",$this->db_regional);
exit;
}
}
function searchsubcategory(){
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_resultoption
WHERE
T_ResultOptionName like ?
AND T_ResultOptionIsActive = 'Y'";
$query = $this->db_regional->query($sql,$q['search']);
//echo $query;
if ($query) {
$tot_count = $query->result_array()[0]["total"];
}
else {
$this->sys_error_db("t_resultoption count",$this->db_regional);
exit;
}
$sql = "
SELECT T_CategoryID, T_CategoryName,T_ResultOptionID,CONCAT(T_ResultOptionName,'[',T_CategoryName,'] ') T_ResultOptionName
FROM t_resultoption
JOIN t_category ON T_CategoryID = T_ResultOptionT_CategoryID
WHERE
CONCAT(T_ResultOptionName,'[',T_CategoryName,'] ') like ?
AND T_ResultOptionIsActive = 'Y'
ORDER BY T_ResultOptionName ASC
";
$query = $this->db_regional->query($sql, array($q['search']));
if ($query) {
$rows = $query->result_array();
//echo $this->db_regional->last_query();
$result = array("total" => $tot_count, "records" => $rows, "total_display" => sizeof($rows));
$this->sys_ok($result);
}
else {
$this->sys_error_db("t_resultoption rows",$this->db_regional);
exit;
}
}
function searchdistrict(){
if (! $this->isLogin) {
$this->sys_error("Invalid Token");
exit;
}
$prm = $this->sys_input;
$id = $prm['id'];
$max_rst = 12;
$tot_count =0;
$q = [
'search' => '%'
];
if ($prm['search'] != '')
{
$q['search'] = "%{$prm['search']}%";
}
// QUERY TOTAL
$sql = "SELECT count(*) as total
FROM m_district
WHERE
M_DistrictName like ?
AND M_DistrictT_ResultOptionID = '{$id}'
AND M_DistrictIsActive = 'Y'";
$query = $this->db_regional->query($sql,$q['search']);
//echo $query;
if ($query) {
$tot_count = $query->result_array()[0]["total"];
}
else {
$this->sys_error_db("m_district count",$this->db_regional);
exit;
}
$sql = "
SELECT *
FROM m_district
WHERE
M_DistrictName like ?
AND M_DistrictT_ResultOptionID = '{$id}'
AND M_DistrictIsActive = 'Y'
ORDER BY M_DistrictName ASC
";
$query = $this->db_regional->query($sql, array($q['search']));
if ($query) {
$rows = $query->result_array();
//echo $this->db_regional->last_query();
$result = array("total" => $tot_count, "records" => $rows, "total_display" => sizeof($rows));
$this->sys_ok($result);
}
else {
$this->sys_error_db("m_district rows",$this->db_regional);
exit;
}
}
function searchkelurahan(){
if (! $this->isLogin) {
$this->sys_error("Invalid Token");
exit;
}
$prm = $this->sys_input;
$id = $prm['id'];
$max_rst = 12;
$tot_count =0;
$q = [
'search' => '%'
];
if ($prm['search'] != '')
{
$q['search'] = "%{$prm['search']}%";
}
// QUERY TOTAL
$sql = "SELECT count(*) as total
FROM m_kelurahan
WHERE
M_KelurahanName like ?
AND M_KelurahanM_DistrictID = '{$id}'
AND M_KelurahanIsActive = 'Y'";
$query = $this->db_regional->query($sql,$q['search']);
//echo $query;
if ($query) {
$tot_count = $query->result_array()[0]["total"];
}
else {
$this->sys_error_db("m_district count",$this->db_regional);
exit;
}
$sql = "
SELECT *
FROM m_kelurahan
WHERE
M_KelurahanName like ?
AND M_KelurahanM_DistrictID = '{$id}'
AND M_KelurahanIsActive = 'Y'
ORDER BY M_KelurahanName ASC
";
$query = $this->db_regional->query($sql, array($q['search']));
if ($query) {
$rows = $query->result_array();
//echo $this->db_regional->last_query();
$result = array("total" => $tot_count, "records" => $rows, "total_display" => sizeof($rows));
$this->sys_ok($result);
}
else {
$this->sys_error_db("m_district rows",$this->db_regional);
exit;
}
}
function searchcompany(){
if (! $this->isLogin) {
$this->sys_error("Invalid Token");
exit;
}
$prm = $this->sys_input;
$max_rst = 12;
$tot_count =0;
$q = [
'search' => '%'
];
if ($prm['search'] != '')
{
$q['search'] = "%{$prm['search']}%";
}
// QUERY TOTAL
$sql = "SELECT count(*) as total
FROM m_company
WHERE
M_CompanyName like ?
AND M_CompanyIsActive = 'Y'";
$query = $this->db_regional->query($sql,$q['search']);
//echo $query;
if ($query) {
$tot_count = $query->result_array()[0]["total"];
}
else {
$this->sys_error_db("m_company count",$this->db_regional);
exit;
}
$sql = "
SELECT *
FROM m_company
WHERE
M_CompanyName like ?
AND M_CompanyIsActive = 'Y'
ORDER BY M_CompanyName ASC
";
$query = $this->db_regional->query($sql, array($q['search']));
if ($query) {
$rows = $query->result_array();
//echo $this->db_regional->last_query();
$result = array("total" => $tot_count, "records" => $rows, "total_display" => sizeof($rows));
$this->sys_ok($result);
}
else {
$this->sys_error_db("m_company rows",$this->db_regional);
exit;
}
}
function searchmou(){
if (! $this->isLogin) {
$this->sys_error("Invalid Token");
exit;
}
$prm = $this->sys_input;
$id = $prm['id'];
$max_rst = 12;
$tot_count =0;
$q = [
'search' => '%'
];
if ($prm['search'] != '')
{
$q['search'] = "%{$prm['search']}%";
}
// QUERY TOTAL
$sql = "SELECT count(*) as total
FROM m_mou
WHERE
M_MouName like ?
AND M_MouM_CompanyID = '{$id}'
AND M_MouIsActive = 'Y'";
$query = $this->db_regional->query($sql,$q['search']);
//echo $query;
if ($query) {
$tot_count = $query->result_array()[0]["total"];
}
else {
$this->sys_error_db("m_mou count",$this->db_regional);
exit;
}
$sql = "SELECT *
FROM m_mou
WHERE
M_MouName like ?
AND M_MouM_CompanyID = '{$id}'
AND M_MouIsActive = 'Y'
ORDER BY M_MouName ASC
";
$query = $this->db_regional->query($sql, array($q['search']));
if ($query) {
$rows = $query->result_array();
// echo $this->db_regional->last_query();
$result = array("total" => $tot_count, "records" => $rows, "total_display" => sizeof($rows));
$this->sys_ok($result);
}
else {
$this->sys_error_db("m_mou rows",$this->db_regional);
exit;
}
}
function searchdoctor(){
if (! $this->isLogin) {
$this->sys_error("Invalid Token");
exit;
}
$prm = $this->sys_input;
$max_rst = 12;
$tot_count =0;
$q = [
'search' => '%'
];
if ($prm['search'] != '')
{
$q['search'] = "%{$prm['search']}%";
}
// QUERY TOTAL
$sql = "SELECT count(*) as total
FROM(SELECT M_DoctorID, CONCAT(M_DoctorPrefix, ' ',M_DoctorName) as M_DoctorName
FROM m_doctor
WHERE M_DoctorIsActive = 'Y') a
WHERE
M_DoctorName like ?";
$query = $this->db_regional->query($sql,$q['search']);
//echo $query;
if ($query) {
$tot_count = $query->result_array()[0]["total"];
}
else {
$this->sys_error_db("m_doctor count",$this->db_regional);
exit;
}
$sql = "SELECT * FROM(SELECT M_DoctorID, CONCAT(M_DoctorPrefix, ' ',M_DoctorName) as M_DoctorName
FROM m_doctor
WHERE M_DoctorIsActive = 'Y') a
WHERE
M_DoctorName like ?
GROUP BY M_DoctorID
ORDER BY M_DoctorName ASC";
$query = $this->db_regional->query($sql, array($q['search']));
if ($query) {
$rows = $query->result_array();
//echo $this->db_regional->last_query();
$result = array("total" => $tot_count, "records" => $rows, "total_display" => sizeof($rows));
$this->sys_ok($result);
}
else {
$this->sys_error_db("m_doctor rows",$this->db_regional);
exit;
}
}
function selectaddressdoctor(){
try {
//# cek token valid
if (! $this->isLogin) {
$this->sys_error("Invalid Token");
exit;
}
$prm = $this->sys_input;
$id = $prm['id'];
$rows = [];
$query ="SELECT M_DoctorAddressID,
CONCAT(M_DoctorAddressNote, ': ',M_DoctorAddressDescription) as M_DoctorAddressNote
FROM
m_doctoraddress
WHERE M_DoctorAddressIsActive = 'Y' AND M_DoctorAddressM_DoctorID = '{$id}'";
//echo $query;
$rows['addressdoctors'] = $this->db_regional->query($query)->result_array();
$result = array(
"total" => count($rows) ,
"records" => $rows,
);
$this->sys_ok($result);
} catch(Exception $exc) {
$message = $exc->getMessage();
$this->sys_error($message);
}
}
}

View File

@@ -0,0 +1,376 @@
<?php
class Subcategory
extends MY_Controller
{
var $db_regional;
public function index()
{
echo "Samplingverify API";
}
public function __construct()
{
parent::__construct();
$this->db_regional = $this->load->database("regional", true);
$this->load->helper(array('form', 'url'));
}
public function search()
{
$prm = $this->sys_input;
if (! $this->isLogin) {
$this->sys_error("Invalid Token");
exit;
}
$sql = "
SELECT IFNULL(T_SubCategoryID,0) as id,
T_SubCategoryID,
T_SubCategoryName,
T_SubCategoryT_CategoryID,
T_CategoryID,
T_CategoryName,
T_SubCategoryIsPCR,
T_SubCategoryIsSchedule,
T_SubCategoryIsKuota,
IF(T_SubCategoryIsPCR = 'Y','Ya','Tidak') as ispcr,
IF(T_SubCategoryIsSchedule = 'Y','Ya','Tidak') as isschedule,
IF(T_SubCategoryIsKuota = 'Y','Ya','Tidak') as iskuota
FROM t_subcategory
LEFT JOIN t_category ON T_CategoryID = T_SubCategoryT_CategoryID
WHERE
T_SubCategoryIsActive = 'Y'
GROUP BY T_SubCategoryID
";
//echo $sql;
$query = $this->db_regional->query($sql);
$rows = $query->result_array();
$result = array("total" => count($rows), "records" => $rows, "sql"=> $this->db_regional->last_query());
$this->sys_ok($result);
exit;
}
public function search_listing()
{
$prm = $this->sys_input;
if (! $this->isLogin) {
$this->sys_error("Invalid Token");
exit;
}
$sql = "SELECT IFNULL(T_SubCategoryID,0) as id,
T_SubCategoryID,
T_SubCategoryName,
T_SubCategoryT_CategoryID,
T_CategoryID,
T_CategoryName,
T_SubCategoryIsPCR,
T_SubCategoryIsSchedule,
T_SubCategoryIsKuota,
IF(T_SubCategoryIsPCR = 'Y','Ya','Tidak') as ispcr,
IF(T_SubCategoryIsSchedule = 'Y','Ya','Tidak') as isschedule,
IF(T_SubCategoryIsKuota = 'Y','Ya','Tidak') as iskuota
FROM t_subcategory
LEFT JOIN t_category ON T_CategoryID = T_SubCategoryT_CategoryID
WHERE
T_SubCategoryIsActive = 'Y'
";
//echo $sql;
$query = $this->db_regional->query($sql);
$rows = $query->result_array();
$result = array("total" => count($rows), "records" => $rows, "sql"=> $this->db_regional->last_query());
$this->sys_ok($result);
exit;
}
function selectcategory(){
try {
//# cek token valid
if (! $this->isLogin) {
$this->sys_error("Invalid Token");
exit;
}
$rows = [];
$query ="SELECT *
FROM t_category
WHERE
T_CategoryIsActive = 'Y'
ORDER BY T_CategoryName asc";
//echo $query;
$rows['categorys'] = $this->db_regional->query($query)->result_array();
$result = array(
"total" => count($rows) ,
"records" => $rows,
);
$this->sys_ok($result);
} catch(Exception $exc) {
$message = $exc->getMessage();
$this->sys_error($message);
}
}
function save(){
try {
//# cek token valid
if (! $this->isLogin) {
$this->sys_error("Invalid Token");
exit;
}
//# ambil parameter input
$prm = $this->sys_input;
$T_SubCategoryName = $prm['name'];
$T_SubCategoryIsPCR = $prm['ispcr'];
$T_SubCategoryIsSchedule = $prm['isschedule'];
$T_SubCategoryIsKuota = $prm['iskuota'];
$userid = $this->sys_user["M_UserID"];
if($prm['xid'] == 0){
$query = "SELECT COUNT(*) as exist FROM t_subcategory WHERE T_SubCategoryIsActive = 'Y' AND T_SubCategoryName = '{$T_SubCategoryName}' AND T_SubCategoryT_CategoryID = '{$T_SubCategoryT_CategoryID}'";
$exist_code = $this->db_regional->query($query)->row()->exist;
if($exist_code == 0){
$sql = "insert into t_subcategory(
T_SubCategoryName,
T_SubCategoryIsPCR,
T_SubCategoryIsSchedule,
T_SubCategoryIsKuota,
T_SubCategoryUserID,
T_SubCategoryLastUpdate,
T_SubCategoryCreated)
values(?,?,?,?,?,now(),now())";
$query = $this->db_regional->query($sql,
array(
$T_SubCategoryName,
$T_SubCategoryIsPCR,
$T_SubCategoryIsSchedule,
$T_SubCategoryIsKuota,
$userid)
);
if (!$query) {
$this->sys_error_db("t_subcategory insert",$this->db_regional);
exit;
}
$last_id = $this->db_regional->insert_id();
$result = array ("total" => 1, "records" => array("xid" => 0));
$this->sys_ok($result);
}else{
$errors = array();
if($exist_code != 0){
array_push($errors,array('field'=>'code','msg'=>'Nama sudah ada yang pakai dong'));
}
$result = array ("total" => -1,"errors" => $errors, "records" => 0);
$this->sys_ok($result);
}
}else{
$query = "SELECT COUNT(*) as exist FROM t_subcategory WHERE T_SubCategoryIsActive = 'Y' AND T_SubCategoryName = '{$T_SubCategoryName}' AND T_SubCategoryT_CategoryID = '{$T_SubCategoryT_CategoryID}' AND T_SubCategoryID <> {$prm['xid']}";
//echo $query;
$exist_code = $this->db_regional->query($query)->row()->exist;
// echo $exist_code;
if($exist_code == 0){
$sql = "UPDATE t_subcategory SET
T_SubCategoryName = '{$T_SubCategoryName}',
T_SubCategoryIsPCR = '{$T_SubCategoryIsPCR}',
T_SubCategoryIsSchedule = '{$T_SubCategoryIsSchedule}',
T_SubCategoryIsKuota = '{$T_SubCategoryIsKuota}',
T_SubCategoryUserID = '{$userid}'
WHERE T_SubCategoryID = '{$prm['xid']}'";
//echo $sql;
$query = $this->db_regional->query($sql);
$result = array ("total" => 1, "records" => array("xid" => 0));
$this->sys_ok($result);
}else{
$errors = array();
if($exist_code != 0){
array_push($errors,array('field'=>'code','msg'=>'Nama sudah ada yang pakai dong'));
}
$result = array ("total" => -1,"errors" => $errors, "records" => 0);
$this->sys_ok($result);
}
}
} catch(Exception $exc) {
$message = $exc->getMessage();
$this->sys_error($message);
}
}
public function delete()
{
try {
//# cek token valid
if (! $this->isLogin) {
$this->sys_error("Invalid Token");
exit;
}
//# ambil parameter input
$prm = $this->sys_input;
$id = $prm['xid'];
$userid = $this->sys_user["M_UserID"];
$sql = "update t_subcategory SET
T_SubCategoryIsActive = 'N',
T_SubCategoryUserID = $userid,
T_SubCategoryLastUpdate = now()
WHERE
T_SubCategoryID = $id";
$query = $this->db_regional->query($sql);
if (!$query) {
$this->sys_error_db("t_subcategory delete");
exit;
}
$sqltest = "update t_subcategory_test SET
T_SubcategoryTestIsActive = 'N',
T_SubcategoryTestUserID = $userid,
T_SubcategoryTestLastUpdated = now()
WHERE
T_SubcategoryTestT_SubcategoryID = $id";
$querytest = $this->db_regional->query($sqltest);
// echo $query;
if (!$querytest) {
$this->sys_error_db("t_subcategory_test 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 savejpagroup(){
if (! $this->isLogin) {
$this->sys_error("Invalid Token");
exit;
}
$prm = $this->sys_input;
$userid = $this->sys_user["M_UserID"];
$query = "insert into t_subcategory(
T_SubCategoryName,
T_SubCategoryUserID,
T_SubCategoryCreated
)
VALUES(
'{$prm['value']}',
{$userid},
NOW()
)";
//echo $query;
$action = $this->db_regional->query($query);
if($action){
$result = array(
"total" => 1 ,
"records" => array(),
);
$this->sys_ok($result);
exit;
}
else{
$this->sys_error_db($this->db_regional->last_query(), $this->db_regional);
exit;
}
}
function savelistingjpagroup(){
if (! $this->isLogin) {
$this->sys_error("Invalid Token");
exit;
}
$prm = $this->sys_input;
$userid = $this->sys_user["M_UserID"];
$query = " UPDATE t_subcategory SET
T_SubCategoryName = '{$prm['name']}',
T_SubCategoryIsActive = '{$prm['status']}',
T_SubCategoryUserID = {$userid}
WHERE
T_SubCategoryID = {$prm['id']}
";
//echo $query;
$action = $this->db_regional->query($query);
if($action){
$result = array(
"total" => 1 ,
"records" => array(),
);
$this->sys_ok($result);
exit;
}
else{
$this->sys_error_db($this->db_regional->last_query(), $this->db_regional);
exit;
}
}
function savealljpadetail(){
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 = "insert into t_subcategory(
Nat_JPADetailNat_JPAID,
Nat_JPADetailT_SubCategoryID,
Nat_JPADetailDiscount,
Nat_JPADetailUserID,
Nat_JPADetailCreated
)
VALUES(
'{$v['Nat_JpaID']}',
'{$v['T_SubCategoryID']}',
'{$v['Nat_JPADetailDiscount']}',
{$userid},
NOW()
) ON DUPLICATE KEY UPDATE
Nat_JPADetailDiscount = {$v['Nat_JPADetailDiscount']},
Nat_JPADetailUserID = {$userid}";
//echo $query;
$action = $this->db_regional->query($query);
}
if($action){
$result = array(
"total" => 1 ,
"records" => array(),
);
$this->sys_ok($result);
exit;
}
else{
$this->sys_error_db($this->db_regional->last_query(), $this->db_regional);
exit;
}
}
}

View File

@@ -0,0 +1,684 @@
<?php
class subcategorytest extends MY_Controller
{
var $db_regional;
public function index()
{
echo "SampleStorage API";
}
public function __construct()
{
parent::__construct();
$this->db_regional = $this->load->database("regional", true);
}
public function search()
{
$prm = $this->sys_input;
if (! $this->isLogin) {
$this->sys_error("Invalid Token");
exit;
}
$join_sql = 'LEFT ';
$status = $prm["status"];
$jpagroup = $prm["jpagroup"];
$search_code = $prm['code'];
$search_name = $prm['name'];
$number_limit = 20;
$number_offset = ($prm['current_page'] - 1) * $number_limit ;
$sql_where = '';
if($search_code != '' || $search_name != ''){
$sql_where .= ' AND (';
if($search_code != ''){
$sql_where .= " T_TestCode LIKE CONCAT('{$search_code}','%') ";
}
if($search_name != ''){
if($search_code != '')
$sql_where .= ' AND ';
$sql_where .= " T_TestName LIKE CONCAT('%','{$search_name}','%') ";
}
$sql_where .= ')';
}
$where_status = " AND T_SubcategoryTestT_SubcategoryID = {$jpagroup} ";
if($status == 'Y'){
$join_sql = '';
}
$sql_param = array($start_date,$end_date);
$sql = " SELECT count(*) as total
FROM t_test
JOIN nat_test ON T_TestNat_TestID = Nat_TestID
JOIN nat_testtype ON Nat_TestNat_TestTypeID = Nat_TestTypeID
$join_sql JOIN t_subcategory_test ON T_SubcategoryTestT_TestID = T_TestID $where_status AND T_SubcategoryTestIsActive = 'Y'
WHERE T_TestIsActive = 'Y' AND T_TestIsPrice = 'Y' $sql_where
";
//echo $sql;
$query = $this->db_regional->query($sql);
$tot_count = 0;
$tot_page = 0;
if ($query) {
$tot_count = $query->result_array()[0]["total"];
$tot_page = ceil($tot_count/$number_limit);
} else {
$this->sys_error_db("t_samplestorage count", $this->db_regional);
exit;
}
$sql = "SELECT t_test.*, IF(ISNULL(T_SubcategoryTestID),'N','Y') as status
FROM t_test
JOIN nat_test ON T_TestNat_TestID = Nat_TestID
JOIN nat_testtype ON Nat_TestNat_TestTypeID = Nat_TestTypeID
$join_sql JOIN t_subcategory_test ON T_SubcategoryTestT_TestID = T_TestID
$where_status AND T_SubcategoryTestIsActive = 'Y'
WHERE T_TestIsActive = 'Y' AND T_TestIsPrice = 'Y' $sql_where
ORDER BY T_TestCode ASC
limit $number_limit offset $number_offset";
$query = $this->db_regional->query($sql);
//echo $this->db_regional->last_query();
$rows = $query->result_array();
if($rows){
}
//$this->_add_address($rows);
$result = array("total" => $tot_page, "records" => $rows, "sql"=> $this->db_regional->last_query());
$this->sys_ok($result);
exit;
}
function getinitdatas(){
if (! $this->isLogin) {
$this->sys_error("Invalid Token");
exit;
}
$rows = [];
$query =" SELECT Nat_GroupID as id, Nat_GroupName as name
FROM nat_group
WHERE
Nat_GroupIsActive = 'Y'
";
//echo $query;
$rows['groups'] = $this->db_regional->query($query)->result_array();
/*$query =" SELECT Nat_SubGroupID as id, CONCAT('[ ',Nat_SubGroupCode,' ] ', Nat_SubGroupName) as name
FROM nat_subgroup
WHERE
Nat_SubGroupIsActive = 'Y'
";
//echo $query;
$rows['subgroups'] = $this->db_regional->query($query)->result_array();*/
$query =" SELECT T_TestTypeID as id, T_TestTypeName as name
FROM t_testtype
WHERE
T_TestTypeIsActive = 'Y'
";
//echo $query;
$rows['types'] = $this->db_regional->query($query)->result_array();
$rows['nonlabs'] = array(array("id"=>"","name"=>"LAB"),array("id"=>"XRAY","name"=>"XRAY"), array("id"=>"USG","name"=>"USG"),array("id"=>"ELECTROMEDIS","name"=>"ELECTROMEDIS"));
$result = array(
"total" => count($rows) ,
"records" => $rows,
);
$this->sys_ok($result);
exit;
}
function get_subgroups(){
if (! $this->isLogin) {
$this->sys_error("Invalid Token");
exit;
}
$prm = $this->sys_input;
$rows = [];
$query =" SELECT Nat_SubGroupID as id, Nat_SubGroupName as name
FROM nat_subgroup
WHERE
Nat_SubGroupIsActive = 'Y' AND Nat_SubGroupNat_GroupID = {$prm['id']}
";
//echo $query;
$rows = $this->db_regional->query($query)->result_array();
$result = array(
"total" => count($rows) ,
"records" => $rows,
);
$this->sys_ok($result);
exit;
}
function get_subsubgroups(){
if (! $this->isLogin) {
$this->sys_error("Invalid Token");
exit;
}
$prm = $this->sys_input;
$rows = [];
$query =" SELECT Nat_SubSubGroupID as id, Nat_SubSubGroupName as name
FROM nat_subsubgroup
WHERE
Nat_SubSubGroupIsActive = 'Y' AND Nat_SubSubGroupNat_GroupID = {$prm['id']}
";
//echo $query;
$rows = $this->db_regional->query($query)->result_array();
$result = array(
"total" => count($rows) ,
"records" => $rows,
);
$this->sys_ok($result);
exit;
}
function getracks(){
if (! $this->isLogin) {
$this->sys_error("Invalid Token");
exit;
}
$prm = $this->sys_input;
$rows = [];
$query =" SELECT Summary_SampleStorageM_AlmariID as almarid, Summary_SampleStorageM_RackID as rackid , Summary_SampleStorageRowPosition as row, Summary_SampleStorageColPosition as col
FROM summary_samplestorage
WHERE
Summary_SampleStorageStatus = 'FILLED'
";
//echo $query;
$filledrows = $this->db_regional->query($query)->result_array();
$query =" SELECT {$prm['id']} as almariid,
M_RackID as id,
CONCAT(M_RackCode,' ( ',M_RackRows,' x ',M_RackColumns,' )') as name,
M_RackCode as code,
M_RackRows as row,
M_RackColumns as col,
'' as rackcontens
FROM m_rack
WHERE
M_RackM_AlmariID = {$prm['id']} AND M_RackIsActive = 'Y'
";
//echo $query;
$datarows = $this->db_regional->query($query)->result_array();
foreach($datarows as $k => $v){
$rows = $v['row'];
$cols = $v['col'];
$rackcontens = array();
for ($x = 1; $x <= $rows; $x++) {
$children = array();
for ($i = 1; $i <= $cols; $i++) {
$content = $x.' x '.$i;
$xrow = $x;
$xcol = $i;
$status = $this->checkexistfilled($filledrows, $v['id'],$xrow,$xcol);
array_push($children,array('content'=>$content,'row'=>$xrow,'col'=>$xcol,'status'=>$status,'selected'=>'N'));
}
array_push($rackcontens,$children);
}
$datarows[$k]['rackcontens'] = $rackcontens;
}
$result = array(
"total" => count($datarows) ,
"records" => $datarows,
);
$this->sys_ok($result);
exit;
}
function checkexistfilled($datas,$rackid,$row,$col){
$rtn = 'N';
foreach($datas as $k => $v){
if($v['rackid'] == $rackid && $v['row'] == $row && $v['col'] == $col){
$rtn = 'Y';
}
}
return $rtn;
}
function searchunit(){
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_unit
WHERE
Nat_UnitName like ?
AND Nat_unitIsActive = 'Y'";
$query = $this->db_regional->query($sql,$q['search']);
//echo $query;
if ($query) {
$tot_count = $query->result_array()[0]["total"];
}
else {
$this->sys_error_db("m_city count",$this->db_regional);
exit;
}
$sql = "
SELECT Nat_UnitId as id, Nat_UnitName as name
FROM nat_unit
WHERE
Nat_UnitName like ?
AND Nat_unitIsActive = 'Y'
ORDER BY Nat_UnitName ASC
";
$query = $this->db_regional->query($sql, array($q['search']));
if ($query) {
$rows = $query->result_array();
//echo $this->db_regional->last_query();
$result = array("total" => $tot_count, "records" => $rows, "total_display" => sizeof($rows));
$this->sys_ok($result);
}
else {
$this->sys_error_db("m_city rows",$this->db_regional);
exit;
}
}
function searchsample(){
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_sampletype
WHERE
Nat_SampleTypeName like ?
AND Nat_SampleTypeIsActive = 'Y'";
$query = $this->db_regional->query($sql,$q['search']);
//echo $query;
if ($query) {
$tot_count = $query->result_array()[0]["total"];
}
else {
$this->sys_error_db("m_city count",$this->db_regional);
exit;
}
$sql = "
SELECT Nat_SampleTypeID as id, Nat_SampleTypeName as name
FROM nat_sampletype
WHERE
Nat_SampleTypeName like ?
AND Nat_SampleTypeIsActive = 'Y'
ORDER BY Nat_SampleTypeName ASC
";
$query = $this->db_regional->query($sql, array($q['search']));
if ($query) {
$rows = $query->result_array();
//echo $this->db_regional->last_query();
$result = array("total" => $tot_count, "records" => $rows, "total_display" => sizeof($rows));
$this->sys_ok($result);
}
else {
$this->sys_error_db("m_city rows",$this->db_regional);
exit;
}
}
function save(){
if (! $this->isLogin) {
$this->sys_error("Invalid Token");
exit;
}
$prm = $this->sys_input;
$userid = $this->sys_user["M_UserID"];
$sql = "INSERT INTO t_subcategory_test (
T_SubcategoryTestT_SubcategoryID,
T_SubcategoryTestT_TestID,
T_SubcategoryTestUserID,
T_SubcategoryTestCreated
)
VALUES(
{$prm['jpagroupid']},
{$prm['T_TestID']},
{$userid},
NOW()
)
on duplicate key update
T_SubcategoryTestIsActive = '{$prm['status']}',
T_SubcategoryTestUserID = {$userid}";
$this->db_regional->query($sql);
$result = array(
"total" => 1 ,
"records" => array('status'=>'OK'),
"numbering" => $data_log_header,
"id" => $last_id
);
$this->sys_ok($result);
exit;
}
function checkcodeexist(){
if (! $this->isLogin) {
$this->sys_error("Invalid Token");
exit;
}
$prm = $this->sys_input;
$rtn = 'N';
$query =" SELECT COUNT(*) as countx
FROM t_test
WHERE T_TestCode = '{$prm['code']}' AND T_TestIsActive = 'Y'
";
//echo $query;
$rst = $this->db_regional->query($query)->row()->countx;
if($rst > 0)
$rtn = 'Y';
$result = array(
"total" => 1 ,
"records" => $rtn,
);
$this->sys_ok($result);
exit;
}
function getdataselected(){
if (! $this->isLogin) {
$this->sys_error("Invalid Token");
exit;
}
$prm = $this->sys_input;
$id = $prm['T_TestID'];
$query =" SELECT
T_TestCode as code,
T_TestName as name,
T_TestShortName as shortname,
T_TestShortNameBarcode as codebarcode,
'' as xgroup,
Nat_GroupID as group_id,
Nat_GroupName as group_name,
'' as subgroup,
Nat_SubGroupID as subgroup_id,
Nat_SubGroupName as subgroup_name,
'' as subsubgroup,
Nat_SubSubGroupID as subsubgroup_id,
Nat_SubSubGroupName as subsubgroup_name,
'' as type,
T_TestT_TestTypeID as type_id,
T_TestTypeName as type_name,
'' as unit,
T_TestNat_UnitID as unit_id,
Nat_UnitName as unit_name,
'' as sample,
T_TestIsNonLab as nonlab,
T_TestNat_SampleTypeID as sample_id,
Nat_SampleTypeName as sample_name,
T_TestFontSize as fontsize,
T_TestFontColor as fontcolor,
T_TestIsBold as flagbold,
T_TestIsItalic as flagitalic,
T_TestFlagGluc as flaggluc,
T_TestIsQuantitative as flagquantitative,
T_TestIsDeltaCheck as deltacheck,
T_TestIsResult as isresult,
T_TestIsPrice as isprice,
T_TestIsPrintResult as printresult,
T_TestIsPrintNota as printnote,
T_TestIsTrendAnalysis as trendanalysis,
T_TestIsWorklist as isworklist,
T_TestWorklistName as worklistname,
T_TestFlagLow as flaglow,
T_TestFlagHigh as flaghigh
FROM t_test
JOIN nat_group ON T_TestNat_GroupID = Nat_GroupID
JOIN nat_subgroup ON T_TestNat_SubGroupID = Nat_SubGroupID
LEFT JOIN nat_subsubgroup ON T_TestNat_SubSubGroupID = Nat_SubSubGroupID
JOIN t_testtype ON T_TestT_TestTypeID = T_TestTypeID
LEFT JOIN nat_sampletype ON T_TestNat_SampleTypeID = Nat_SampleTypeID
LEFT JOIN nat_unit ON T_TestNat_UnitID = Nat_UnitID
WHERE T_TestID = '{$id}'
";
//echo $query;
$rows['xform'] = $this->db_regional->query($query)->row_array();
if($rows['xform']){
$rows['xform']['unit'] = array();
if($rows['xform']['isresult'] == 'Y')
$rows['xform']['unit'] = array('id'=>$rows['xform']['unit_id'],'name'=>$rows['xform']['unit_name']);
$rows['xform']['sample'] = array();
if($rows['xform']['isresult'] == 'Y')
$rows['xform']['sample'] = array('id'=>$rows['xform']['sample_id'],'name'=>$rows['xform']['sample_name']);
$rows['xform']['xgroup'] = array('id'=>$rows['xform']['group_id'],'name'=>$rows['xform']['group_name']);
$rows['xform']['subgroup'] = array('id'=>$rows['xform']['subgroup_id'],'name'=>$rows['xform']['subgroup_name']);
$rows['xform']['subsubgroup'] = array('id'=>$rows['xform']['subsubgroup_id'],'name'=>$rows['xform']['subsubgroup_name']);
$rows['xform']['type'] = array('id'=>$rows['xform']['type_id'],'name'=>$rows['xform']['type_name']);
if($rows['xform']['nonlab'] == '')
$rows['xform']['nonlab'] = array('id'=>'','name'=>'LAB');
else
$rows['xform']['nonlab'] = array('id'=>$rows['xform']['nonlab'],'name'=>$rows['xform']['nonlab']);
unset($rows['xform']['sample_id']);
unset($rows['xform']['unit_id']);
unset($rows['xform']['group_id']);
unset($rows['xform']['subgroup_id']);
unset($rows['xform']['subsubgroup_id']);
unset($rows['xform']['sample_name']);
unset($rows['xform']['unit_name']);
unset($rows['xform']['group_name']);
unset($rows['xform']['subgroup_name']);
unset($rows['xform']['subsubgroup_name']);
}
$sql = "SELECT Nat_SubGroupID as id, Nat_SubGroupName as name FROM nat_subgroup WHERE Nat_SubGroupNat_GroupID = {$prm['Nat_GroupID']} AND Nat_SubGroupIsActive = 'Y'";
//echo $sql;
$rows['subgroups'] = $this->db_regional->query($sql)->result_array();
$sql = "SELECT Nat_SubSubGroupID as id, Nat_SubSubGroupName as name FROM nat_subsubgroup WHERE Nat_SubSubGroupSubGroupID = {$prm['Nat_SubGroupID']} AND Nat_SubSubGroupIsActive = 'Y'";
//echo $sql;
$rows['subsubgroups'] = $this->db_regional->query($sql)->result_array();
$result = array(
"total" => 1 ,
"records" => $rows,
);
$this->sys_ok($result);
exit;
}
function doaddtest(){
if (! $this->isLogin) {
$this->sys_error("Invalid Token");
exit;
}
$rtn = true;
$prm = $this->sys_input;
$userid = $this->sys_user["M_UserID"];
$codefrom = $prm['codefrom'];
$codetoward = $prm['codetoward'];
$leng = strlen($codetoward);
$code_parent = substr($codetoward, 0,-2);
$sql = "SELECT count(*) as existtest FROM t_test WHERE T_TestSasCode LIKE '{$code_parent}%' AND T_TestCode = '{$codefrom}' AND T_TestIsActive = 'Y'";
//echo $sql;
$xcount = $this->db_regional->query($sql)->row()->existtest;
if($xcount == 0){
$sql = "
select T_TestID ,T_TestSasCode,
case
when length(T_TestSasCode) = {$leng} then T_TestSasCode + 1
else
concat( substr(T_TestSasCode,1,{$leng}) + 2 , substr(T_TestSasCode, {$leng} +1) )
end as NewCode,
T_TestName
from
t_test
where T_TestSasCode like '{$code_parent}%' AND length(T_TestSasCode) = {$leng} AND T_TestSasCode >= '{$codetoward}'
UNION
select T_TestID , T_TestSasCode,
case
when length(T_TestSasCode) = {$leng} then T_TestSasCode + 1
else
concat( substr(T_TestSasCode,1,{$leng}) + 1 , substr(T_TestSasCode, {$leng} +1) )
end as NewCode,
T_TestName
from
t_test
where ( T_TestSasCode like '{$code_parent}%' AND T_TestSasCode > '{$codetoward}' ) OR T_TestSasCode = '{$codetoward}'
";
//echo $sql;
$toupdate = $this->db_regional->query($sql)->result();
if($toupdate){
foreach($toupdate as $k => $v){
$sql = "UPDATE t_test SET T_TestSasCode = '{$v->NewCode}' WHERE T_TestID = {$v->T_TestID} ";
$this->db_regional->query($sql);
}
}
$sql = "SELECT * FROM t_test WHERE T_TestSasCode = '{$code_parent}' AND T_TestIsActive = 'Y'";
$parentid = $this->db_regional->query($sql)->row()->T_TestID;
$query ="INSERT INTO t_test (
T_TestParentT_TestID,
T_TestT_TestID,
T_TestCode,
T_TestSasCode,
T_TestName,
T_TestShortName,
T_TestShortNameBarcode,
T_TestNat_GroupID,
T_TestNat_SubGroupID,
T_TestT_SampleTypeID,
T_TestFontSize,
T_TestFontColor,
T_TestIsBold,
T_TestIsItalic,
T_TestFlagGluc,
T_TestIsQuantitative,
T_TestIsDeltaCheck,
T_TestIsResult,
T_TestIsPrice,
T_TestIsPrintResult,
T_TestIsPrintNota,
T_TestIsTrendAnalysis,
T_TestIsWorklist,
T_TestIsNonLab,
T_TestWorklistName,
T_TestFlagLow,
T_TestFlagHigh,
T_TestUserID,
T_TestCreated
)
SELECT
{$parentid},
T_TestID,
T_TestCode,
'{$codetoward}',
T_TestName,
T_TestShortName,
T_TestShortNameBarcode,
T_TestNat_GroupID,
T_TestNat_SubGroupID,
T_TestNat_SampleTypeID,
T_TestFontSize,
T_TestFontColor,
T_TestIsBold,
T_TestIsItalic,
T_TestFlagGluc,
T_TestIsQuantitative,
T_TestIsDeltaCheck,
T_TestIsResult,
T_TestIsPrice,
T_TestIsPrintResult,
T_TestIsPrintNota,
T_TestIsTrendAnalysis,
T_TestIsWorklist,
T_TestIsNonLab,
T_TestWorklistName,
T_TestFlagLow,
T_TestFlagHigh,
{$userid},
NOW()
FROM t_test
WHERE
T_TestCode = '{$codefrom}' AND T_TestIsActive = 'Y'
";
//echo $query;
$this->db_regional->query($query);
$sql = "SELECT T_TestID FROM t_test WHERE T_TestSasCode = '{$code_parent}' AND T_TestIsActive = 'Y' LIMIT 1";
$data_parent = $this->db_regional->query($sql)->row();
if($data_parent){
$testidparent = $data_parent->T_TestID;
$sql = "UPDATE t_test SET T_TestIsParent = 'Y' WHERE T_TestID = {$testidparent}";
$this->db_regional->query($sql);
}
}
$result = array(
"total" => 1 ,
"records" => $xcount,
"debug"=>$query
);
$this->sys_ok($result);
exit;
}
}