Files
BE_IBL/application/controllers/mockup/masterdata/Abnormal.php
2026-04-15 15:24:12 +07:00

735 lines
24 KiB
PHP

<?php
class Abnormal extends MY_Controller
{
var $db_onedev;
public function index()
{
echo "ABNORMAL API";
}
public function __construct()
{
parent::__construct();
$this->db_onedev = $this->load->database("onedev", true);
}
function lookupabnormalbyname(){
try {
//# cek token valid
if (! $this->isLogin) {
$this->sys_error("Invalid Token");
exit;
}
$prm = $this->sys_input;
$methodename = $prm['methodename'];
$sexid = $prm['sexid'];
$flagid = $prm['flagid'];
$filter = '';
if(isset($sexid)){
$filter .= "AND ($sexid = 0 or ($sexid > 0 and Nat_SexID = $sexid)) ";
}
if(isset($flagid)){
$filter .= "AND ($flagid = 0 or ($flagid > 0 and Nat_FlagID = $flagid))";
}
$limit = '';
if($all == 'N'){
$limit = ' LIMIT 10';
}
$number_limit = 10;
$number_offset = ($prm['current_page'] - 1) * $number_limit ;
$sql = "select COUNT(*) as total
FROM(SELECT *
from nat_normalvalue
LEFT JOIN nat_advice_abnormal ON Nat_NormalValueID = Nat_AdviceAbnormalNat_NormalValueID AND Nat_AdviceAbnormalIsActive = 'Y'
LEFT JOIN nat_sex ON Nat_NormalValueNat_SexID = Nat_SexID
JOIN nat_test ON Nat_NormalValueNat_TestID = Nat_TestID
JOIN nat_methode ON Nat_NormalValueNat_MethodeID = Nat_MethodeID AND Nat_MethodeIsActive = 'Y'
JOIN nat_normalvaluetype ON Nat_NormalValueNat_NormalValueTypeID = Nat_NormalValueTypeID
LEFT JOIN nat_flag ON Nat_NormalValueNat_FlagID = Nat_FlagID
WHERE
Nat_NormalValueIsActive = 'Y' AND Nat_NormalValueIsAbnormal = 'Y' AND
Nat_MethodeName like '%{$methodename}%'
$filter GROUP BY Nat_NormalValueID) a";
// $total = $this->db_onedev->query($sql,$sql_param)->row()->total;
$query = $this->db_onedev->query($sql);
//echo $this->db_onedev->last_query();
$tot_count = 0;
$tot_page = 0;
if ($query) {
$tot_count = $query->result_array()[0]["total"];
$tot_page = ceil($tot_count/$number_limit);
} else {
$this->sys_error_db("nat_normalvalue count", $this->db_onedev);
exit;
}
$sql = "SELECT nat_normalvalue.*,
Nat_NormalValueID as id,
Nat_NormalValueID,
IFNULL(Nat_AdviceAbnormalID,0) as Nat_AdviceAbnormalID,
IFNULL(Nat_AdviceAbnormalAdviceIna,'') as Nat_AdviceAbnormalAdviceIna,
IFNULL(Nat_AdviceAbnormalAdviceEng,'') as Nat_AdviceAbnormalAdviceEng,
Nat_TestName,
Nat_SexID,
Nat_SexName,
Nat_MethodeID,
Nat_MethodeName,
Nat_NormalValueTypeID,
Nat_NormalValueTypeName,
Nat_FlagID,
Nat_FlagName,
IFNULL(Nat_NormalValueMinAgeV2, Nat_NormalValueMinAge) as Nat_NormalValueMinAge,
IFNULL(Nat_NormalValueMaxAgeV2, Nat_NormalValueMaxAge) as Nat_NormalValueMaxAge,
CASE
WHEN Nat_NormalValueMinAgeInclusive = 'Y' AND Nat_NormalValueMaxAgeInclusive = 'Y' THEN CONCAT(Nat_NormalValueMinAge,' - ',Nat_NormalValueMaxAge,' (',Nat_NormalValueAgeUnit,')')
WHEN Nat_NormalValueMinAgeInclusive = 'Y' AND Nat_NormalValueMaxAgeInclusive = 'N' THEN CONCAT(Nat_NormalValueMinAge,' > ',Nat_NormalValueMaxAge,' (',Nat_NormalValueAgeUnit,')')
WHEN Nat_NormalValueMinAgeInclusive = 'N' AND Nat_NormalValueMaxAgeInclusive = 'Y' THEN CONCAT(Nat_NormalValueMinAge,' < ',Nat_NormalValueMaxAge,' (',Nat_NormalValueAgeUnit,')')
ELSE '-'
END as Nat_NormalValueAge,
CASE
WHEN Nat_NormalValueMinValueInclusive = 'Y' AND Nat_NormalValueMaxValueInclusive = 'Y' THEN CONCAT(Nat_NormalValueMinValue,' - ',Nat_NormalValueMaxValue)
WHEN Nat_NormalValueMinValueInclusive = 'Y' AND Nat_NormalValueMaxValueInclusive = 'N' THEN CONCAT(Nat_NormalValueMinValue,' > ',Nat_NormalValueMaxValue)
WHEN Nat_NormalValueMinValueInclusive = 'N' AND Nat_NormalValueMaxValueInclusive = 'Y' THEN CONCAT(Nat_NormalValueMinValue,' < ',Nat_NormalValueMaxValue)
ELSE '-'
END as Nat_NormalValueValue,
CASE
WHEN Nat_NormalValueAgeUnit = 'HARI' THEN '1'
WHEN Nat_NormalValueAgeUnit = 'BULAN' THEN '2'
WHEN Nat_NormalValueAgeUnit = 'TAHUN' THEN '3'
ELSE '4'
END as ageunit,
CASE
WHEN Nat_NormalValueMinAgeUnit = 'HARI' THEN '1'
WHEN Nat_NormalValueMinAgeUnit = 'BULAN' THEN '2'
WHEN Nat_NormalValueMinAgeUnit = 'TAHUN' THEN '3'
ELSE '4'
END as minageunit,
CASE
WHEN Nat_NormalValueMaxAgeUnit = 'HARI' THEN '1'
WHEN Nat_NormalValueMaxAgeUnit = 'BULAN' THEN '2'
WHEN Nat_NormalValueMaxAgeUnit = 'TAHUN' THEN '3'
ELSE '4'
END as maxageunit,
IF(Nat_NormalValueIsAbnormal = 'N',Nat_NormalValueID,Nat_NormalValueParentID) as parentid
FROM nat_normalvalue
LEFT JOIN nat_advice_abnormal ON Nat_NormalValueID = Nat_AdviceAbnormalNat_NormalValueID AND Nat_AdviceAbnormalIsActive = 'Y'
LEFT JOIN nat_sex ON Nat_NormalValueNat_SexID = Nat_SexID
JOIN nat_test ON Nat_NormalValueNat_TestID = Nat_TestID
JOIN nat_methode ON Nat_NormalValueNat_MethodeID = Nat_MethodeID AND Nat_MethodeIsActive = 'Y'
JOIN nat_normalvaluetype ON Nat_NormalValueNat_NormalValueTypeID = Nat_NormalValueTypeID
LEFT JOIN nat_flag ON Nat_NormalValueNat_FlagID = Nat_FlagID
WHERE
Nat_NormalValueIsActive = 'Y' AND Nat_NormalValueIsAbnormal = 'Y' AND
Nat_MethodeName like '%{$methodename}%'
$filter
GROUP BY Nat_NormalValueID
ORDER BY Nat_NormalValueNat_SexID ASC, ageunit ASC, Nat_NormalValueMinAge ASC, Nat_NormalValueMaxAge ASC, parentid ASC
limit $number_limit offset $number_offset";
$sql_param = array($search);
$query = $this->db_onedev->query($sql);
//echo $this->db_onedev->last_query();
if ($query) {
$rows = $query->result_array();
} else {
$this->sys_error_db("nat_normalvalue 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 lookupadvicebyid(){
try {
//# cek token valid
if (! $this->isLogin) {
$this->sys_error("Invalid Token");
exit;
}
$prm = $this->sys_input;
$id = $prm['id'];
$name = $prm['name'];;
$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 nat_advice_abnormal
JOIN nat_normalvalue ON Nat_AdviceAbnormalNat_NormalValueID = Nat_NormalValueID AND Nat_NormalValueIsActive = 'Y'
WHERE
Nat_AdviceAbnormalNat_NormalValueID = $id AND
Nat_AdviceAbnormalIsActive = 'Y' GROUP BY Nat_AdviceAbnormalID) a";
// $total = $this->db_onedev->query($sql,$sql_param)->row()->total;
$query = $this->db_onedev->query($sql);
//echo $this->db_onedev->last_query();
$tot_count = 0;
$tot_page = 0;
if ($query) {
$tot_count = $query->result_array()[0]["total"];
$tot_page = ceil($tot_count/$number_limit);
} else {
$this->sys_error_db("nat_advice_abnormalcount", $this->db_onedev);
exit;
}
$sql = "select Nat_AdviceAbnormalID as id,
nat_advice_abnormal.*
from nat_advice_abnormal
JOIN nat_normalvalue ON Nat_AdviceAbnormalNat_NormalValueID = Nat_NormalValueID AND Nat_NormalValueIsActive = 'Y'
WHERE
Nat_AdviceAbnormalNat_NormalValueID = $id AND
Nat_AdviceAbnormalIsActive = 'Y'
GROUP BY Nat_AdviceAbnormalID
ORDER BY Nat_AdviceAbnormalID ASC
limit $number_limit offset $number_offset";
$sql_param = array($search);
$query = $this->db_onedev->query($sql);
//echo $this->db_onedev->last_query();
if ($query) {
$rows = $query->result_array();
} else {
$this->sys_error_db("nat_advice_abnormalselect");
exit;
}
$result = array ("total" => $tot_page, "total_filter"=>count($rows),"records" => $rows);
$this->sys_ok($result);
} catch(Exception $exc) {
$message = $exc->getMessage();
$this->sys_error($message);
}
}
function getsexreg(){
if (! $this->isLogin) {
$this->sys_error("Invalid Token");
exit;
}
$rows = [];
$query =" SELECT *
FROM nat_sex
WHERE
Nat_SexIsActive = 'Y'
";
//echo $query;
$rows['sexes'] = $this->db_onedev->query($query)->result_array();
$query =" SELECT *
FROM nat_normalvaluetype
WHERE
Nat_NormalValueTypeIsActive = 'Y'
";
//echo $query;
$rows['normalvaluetypees'] = $this->db_onedev->query($query)->result_array();
$query =" SELECT *
FROM nat_flag
WHERE
Nat_FlagIsActive = 'Y'
";
//echo $query;
$rows['flages'] = $this->db_onedev->query($query)->result_array();
$query =" SELECT 'HARI' as Nat_AgeUnitID,'HARI' as Nat_AgeUnitName
UNION SELECT 'BULAN' as Nat_AgeUnitID, 'BULAN' as Nat_AgeUnitName
UNION SELECT 'TAHUN' as Nat_AgeUnitID, 'TAHUN' as Nat_AgeUnitName
";
//echo $query;
$rows['ageunites'] = $this->db_onedev->query($query)->result_array();
$query =" SELECT 'HARI' as Nat_AgeUnitID,'HARI' as Nat_AgeUnitName
UNION SELECT 'BULAN' as Nat_AgeUnitID, 'BULAN' as Nat_AgeUnitName
UNION SELECT 'TAHUN' as Nat_AgeUnitID, 'TAHUN' as Nat_AgeUnitName
";
//echo $query;
$rows['minageunites'] = $this->db_onedev->query($query)->result_array();
$query =" SELECT 'HARI' as Nat_AgeUnitID,'HARI' as Nat_AgeUnitName
UNION SELECT 'BULAN' as Nat_AgeUnitID, 'BULAN' as Nat_AgeUnitName
UNION SELECT 'TAHUN' as Nat_AgeUnitID, 'TAHUN' as Nat_AgeUnitName
";
//echo $query;
$rows['maxageunites'] = $this->db_onedev->query($query)->result_array();
$query ="
SELECT 0 as Nat_SexID, 'Semua' as Nat_SexName
UNION
SELECT Nat_SexID, Nat_SexName
FROM nat_sex
WHERE
Nat_SexIsActive = 'Y'
";
//echo $query;
$rows['f_sexs'] = $this->db_onedev->query($query)->result_array();
$query ="
SELECT 0 as Nat_FlagID, 'Semua' as Nat_FlagName
UNION
SELECT Nat_FlagID, Nat_FlagName
FROM nat_flag
WHERE
Nat_FlagIsActive = 'Y'";
//echo $query;
$rows['f_flags'] = $this->db_onedev->query($query)->result_array();
$result = array(
"total" => count($rows) ,
"records" => $rows,
);
$this->sys_ok($result);
exit;
}
public function addnewabnormal()
{
try {
//# cek token valid
if (! $this->isLogin) {
$this->sys_error("Invalid Token");
exit;
}
//# ambil parameter input
$prm = $this->sys_input;
$name = $prm['name'];
$ispertest = $prm['ispertest'];
$isnonlab = $prm['isnonlab'];
$sql = "insert into nat_methode(
Nat_MethodeName,
Nat_MethodeFlagPerTest,
Nat_MethodeFlagNonLab
)
values( ?, ?, ?)";
$query = $this->db_onedev->query($sql,
array(
$name,
$ispertest,
$isnonlab
)
);
//echo $query;
if (!$query) {
$this->sys_error_db("nat_methode insert");
exit;
}
$last_id = $this->db_onedev->insert_id();
$result = array ("total" => 1, "records" => array("xid" => 0));
$this->sys_ok($result);
$last_id = $this->db_onedev->insert_id();
} catch(Exception $exc) {
$message = $exc->getMessage();
$this->sys_error($message);
}
}
public function editabnormal()
{
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'];
$ispertest = $prm['ispertest'];
$isnonlab = $prm['isnonlab'];
$userid = $this->sys_user["M_UserID"];
$sqlcompany = "update nat_methode SET
Nat_MethodeName = ?,
Nat_MethodeFlagPerTest = ?,
Nat_MethodeFlagNonLab = ?
where
Nat_MethodeID = ?
";
$querycompany = $this->db_onedev->query($sqlcompany,
array(
$name,
$ispertest,
$isnonlab,
$id
)
);
// echo $query;
if (!$querycompany) {
$this->sys_error_db("nat_methode 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 addnewadvice()
{
try {
//# cek token valid
if (! $this->isLogin) {
$this->sys_error("Invalid Token");
exit;
}
//# ambil parameter input
$prm = $this->sys_input;
$abnormalid = $prm['abnormalid'];
$advice = $prm['value'];
$userid = $this->sys_user["M_UserID"];
$sql = "insert into nat_advice_abnormal(
Nat_AdviceAbnormalNat_NormalValueID,
Nat_AdviceAbnormalAdviceIna,
Nat_AdviceAbnormalUserID,
Nat_AdviceAbnormalCreated,
Nat_AdviceAbnormalLastUpdated
)
values(?,?,?,now(),now())";
$query = $this->db_onedev->query($sql,
array(
$abnormalid,
$advice,
$userid
)
);
if (!$query) {
$this->sys_error_db("nat_normalvalue insert",$this->db_onedev);
exit;
}
$last_id = $this->db_onedev->insert_id();
$result = array ("total" => 1, "records" => array("xid" => 0));
$this->sys_ok($result);
} catch(Exception $exc) {
$message = $exc->getMessage();
$this->sys_error($message);
}
}
function savealladvice(){
if (! $this->isLogin) {
$this->sys_error("Invalid Token");
exit;
}
$prm = $this->sys_input;
$details = $prm['details'];
$userid = $this->sys_user["M_UserID"];
foreach($details as $k => $v){
$query = "UPDATE nat_advice_abnormal SET
Nat_AdviceAbnormalNat_NormalValueID = '{$v['Nat_AdviceAbnormalNat_NormalValueID']}',
Nat_AdviceAbnormalAdviceIna = '{$v['Nat_AdviceAbnormalAdviceIna']}',
Nat_AdviceAbnormalAdviceEng = '{$v['Nat_AdviceAbnormalAdviceEng']}',
Nat_AdviceAbnormalUserID = {$userid},
Nat_AdviceAbnormalCreated = now(),
Nat_AdviceAbnormalLastUpdated = now()
WHERE Nat_AdviceAbnormalID = {$v['Nat_AdviceAbnormalID']}";
//echo $query;
$action = $this->db_onedev->query($query);
}
if($action){
$result = array(
"total" => 1 ,
"records" => array(),
);
$this->sys_ok($result);
exit;
}
else{
$this->sys_error_db($this->db_onedev->last_query(), $this->db_onedev);
exit;
}
}
public function deleteabnormal()
{
try {
//# cek token valid
if (! $this->isLogin) {
$this->sys_error("Invalid Token");
exit;
}
//# ambil parameter input
$prm = $this->sys_input;
$userid = $this->sys_user["M_UserID"];
$sql = "update nat_methode SET
Nat_MethodeIsActive = 'N'
WHERE
Nat_MethodeID = ?
";
$query = $this->db_onedev->query($sql,
array(
$prm['id']
)
);
// echo $query;
if (!$query) {
$this->sys_error_db("nat_methode delete");
exit;
}
$sql = "update nat_normalvalue SET
Nat_NormalValueIsActive = 'N'
WHERE
Nat_NormalValueNat_MethodeID = ?
";
$query = $this->db_onedev->query($sql,
array(
$prm['id']
)
);
// echo $query;
if (!$query) {
$this->sys_error_db("nat_normalvalue 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 deleteadvice()
{
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_normalvalue SET
Nat_NormalValueIsActive = 'N'
WHERE
Nat_NormalValueID = ?
";
$query = $this->db_onedev->query($sql,
array(
$prm['id']
)
);
// echo $query;
if (!$query) {
$this->sys_error_db("nat_normalvalue 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 searchabnormal(){
if (! $this->isLogin) {
$this->sys_error("Invalid Token");
exit;
}
$prm = $this->sys_input;
$max_rst = 12;
$tot_count =0;
$q = [
'search' => '%'
];
if ($prm['search'] != '')
{
$q['search'] = "%{$prm['search']}%";
}
// QUERY TOTAL
$sql = "SELECT count(*) as total
FROM nat_methode
WHERE
Nat_MethodeName like ?
AND Nat_MethodeIsActive = 'Y'";
$query = $this->db_onedev->query($sql,$q['search']);
//echo $query;
if ($query) {
$tot_count = $query->result_array()[0]["total"];
}
else {
$this->sys_error_db("nat_methode count",$this->db_onedev);
exit;
}
$sql = "
SELECT Nat_MethodeID, Nat_MethodeName
FROM nat_methode
WHERE
Nat_MethodeName like ?
AND Nat_MethodeIsActive = 'Y'
ORDER BY Nat_MethodeName ASC
";
$query = $this->db_onedev->query($sql, array($q['search']));
if ($query) {
$rows = $query->result_array();
//echo $this->db_onedev->last_query();
$result = array("total" => $tot_count, "records" => $rows, "total_display" => sizeof($rows));
$this->sys_ok($result);
}
else {
$this->sys_error_db("nat_methode rows",$this->db_onedev);
exit;
}
}
function searchabnormalbyname(){
if (! $this->isLogin) {
$this->sys_error("Invalid Token");
exit;
}
$prm = $this->sys_input;
$max_rst = 12;
$tot_count =0;
$q = [
'search' => '%'
];
if ($prm['search'] != '')
{
$q['search'] = "%{$prm['search']}%";
}
// QUERY TOTAL
$sql = "SELECT count(*) as total
FROM nat_methode
WHERE
Nat_MethodeName like ?
AND Nat_MethodeIsActive = 'Y'";
$query = $this->db_onedev->query($sql,$q['search']);
//echo $query;
if ($query) {
$tot_count = $query->result_array()[0]["total"];
}
else {
$this->sys_error_db("nat_methode count",$this->db_onedev);
exit;
}
$sql = "
SELECT Nat_MethodeID, Nat_MethodeName
FROM nat_methode
WHERE
Nat_MethodeName like ?
AND Nat_MethodeIsActive = 'Y'
ORDER BY Nat_MethodeName ASC
";
$query = $this->db_onedev->query($sql, array($q['search']));
if ($query) {
$rows = $query->result_array();
//echo $this->db_onedev->last_query();
$result = array("total" => $tot_count, "records" => $rows, "total_display" => sizeof($rows));
$this->sys_ok($result);
}
else {
$this->sys_error_db("nat_methode rows",$this->db_onedev);
exit;
}
}
function searchtest(){
if (! $this->isLogin) {
$this->sys_error("Invalid Token");
exit;
}
$prm = $this->sys_input;
$max_rst = 12;
$tot_count =0;
$q = [
'search' => '%'
];
if ($prm['search'] != '')
{
$q['search'] = "%{$prm['search']}%";
}
// QUERY TOTAL
$sql = "SELECT count(*) as total
FROM t_test
WHERE
T_TestName like ?
AND T_TestIsActive = 'Y' AND T_TestIsResult = 'Y'";
$query = $this->db_onedev->query($sql,$q['search']);
//echo $query;
if ($query) {
$tot_count = $query->result_array()[0]["total"];
}
else {
$this->sys_error_db("t_test count",$this->db_onedev);
exit;
}
$sql = "
SELECT *
FROM t_test
WHERE
T_TestName like ?
AND T_TestIsActive = 'Y' AND T_TestIsResult = 'Y'
ORDER BY T_TestName ASC
";
$query = $this->db_onedev->query($sql, array($q['search']));
if ($query) {
$rows = $query->result_array();
//echo $this->db_onedev->last_query();
$result = array("total" => $tot_count, "records" => $rows, "total_display" => sizeof($rows));
$this->sys_ok($result);
}
else {
$this->sys_error_db("t_test rows",$this->db_onedev);
exit;
}
}
}