508 lines
17 KiB
PHP
508 lines
17 KiB
PHP
<?php
|
|
class Kelainanlab extends MY_Controller
|
|
{
|
|
var $db;
|
|
public function __construct()
|
|
{
|
|
parent::__construct();
|
|
}
|
|
|
|
public function index()
|
|
{
|
|
// $cek = $this->db->query("select database() as current_db")->result();
|
|
// print_r($cek);
|
|
echo "KELAINAN LAB API";
|
|
}
|
|
|
|
function search()
|
|
{
|
|
try {
|
|
if (!$this->isLogin) {
|
|
$this->sys_error("Invalid Token");
|
|
exit;
|
|
}
|
|
$prm = $this->sys_input;
|
|
$userid = $this->sys_user['M_UserID'];
|
|
|
|
$search = "";
|
|
if (isset($prm["search"])) {
|
|
$search = trim($prm["search"]);
|
|
if ($search != "") {
|
|
$search = "%" . $prm["search"] . "%";
|
|
} else {
|
|
$search = "%%";
|
|
}
|
|
}
|
|
|
|
$number_offset = 0;
|
|
$number_limit = 10;
|
|
|
|
if ($prm["current_page"] > 0) {
|
|
$number_offset = ($prm["current_page"] - 1) * $number_limit;
|
|
}
|
|
|
|
$sql_total = "SELECT count(*) as total
|
|
FROM one_etl.mcu_summarylab
|
|
JOIN nat_test ON Mcu_SummaryLabNat_TestID = Nat_TestID
|
|
AND Nat_TestIsActive = 'Y'
|
|
JOIN one_etl.mcu_kelainan ON Mcu_summaryLabMcu_KelainanID = Mcu_KelainanID
|
|
AND Mcu_KelainanIsActive = 'Y'
|
|
WHERE Mcu_SummaryLabIsActive = 'Y'
|
|
AND (CONCAT(Nat_TestCode,' ',Nat_TestName) LIKE ? OR Mcu_KelainanName LIKE ?)";
|
|
$qry_total = $this->db->query($sql_total, [$search, $search]);
|
|
$last_qry = $this->db->last_query();
|
|
$tot_count = 0;
|
|
$tot_page = 0;
|
|
if ($qry_total) {
|
|
$tot_count = $qry_total->result_array()[0]["total"];
|
|
$tot_page = ceil($tot_count / $number_limit);
|
|
} else {
|
|
$this->db->trans_rollback();
|
|
$message['last_qry'] = $last_qry;
|
|
$this->sys_error_db("mcu_summarylab count error", $this->db);
|
|
exit;
|
|
}
|
|
|
|
$sql = "SELECT Mcu_SummaryLabID,
|
|
Mcu_SummaryLabNat_TestID,
|
|
Mcu_SummaryLabNat_TestCode,
|
|
Mcu_summaryLabMcu_KelainanID,
|
|
CASE
|
|
WHEN Mcu_SummaryLabType = '<' THEN 'Kurang dari'
|
|
WHEN Mcu_SummaryLabType = '>' THEN 'Lebih dari'
|
|
WHEN Mcu_SummaryLabType = '=' THEN 'Sama dengan'
|
|
WHEN Mcu_SummaryLabType = '<=' THEN 'Kurang dari sama dengan'
|
|
WHEN Mcu_SummaryLabType = '>=' THEN 'Lebih dari sama dengan'
|
|
WHEN Mcu_SummaryLabType = '!=' THEN 'Tidak sama dengan'
|
|
ELSE ''
|
|
END as summarylabtype,
|
|
Mcu_SummaryLabType,
|
|
Mcu_SummaryLabIsNormalValue,
|
|
Mcu_SummaryLabValue,
|
|
Mcu_SummaryLabWithMethode,
|
|
Mcu_SummaryLabNat_MethodeID,
|
|
Nat_TestID,
|
|
Nat_TestCode,
|
|
CONCAT(Nat_TestCode,' ',Nat_TestName) AS codeNameTest,
|
|
Mcu_KelainanID,
|
|
Mcu_KelainanName,
|
|
'' as rownumber
|
|
FROM one_etl.mcu_summarylab
|
|
JOIN nat_test ON Mcu_SummaryLabNat_TestID = Nat_TestID
|
|
AND Nat_TestIsActive = 'Y'
|
|
JOIN one_etl.mcu_kelainan ON Mcu_summaryLabMcu_KelainanID = Mcu_KelainanID
|
|
AND Mcu_KelainanIsActive = 'Y'
|
|
WHERE Mcu_SummaryLabIsActive = 'Y'
|
|
AND (CONCAT(Nat_TestCode,' ',Nat_TestName) LIKE ? OR Mcu_KelainanName LIKE ?)
|
|
ORDER BY Mcu_SummaryLabID DESC
|
|
limit ? offset ?";
|
|
|
|
$qry = $this->db->query($sql, [$search, $search, $number_limit, $number_offset]);
|
|
$last_qry = $this->db->last_query();
|
|
if (!$qry) {
|
|
$message = $this->db->error();
|
|
$message['last_qry'] = $last_qry;
|
|
$this->sys_error_db("mcu_summarylab select error", $this->db);
|
|
exit;
|
|
}
|
|
|
|
$rows = $qry->result_array();
|
|
foreach ($rows as $k => $v) {
|
|
$xno = ($k + 1) + $number_offset;
|
|
$rows[$k]['rownumber'] = $xno;
|
|
}
|
|
|
|
|
|
$result = [
|
|
"total_page" => $tot_page,
|
|
"total" => $tot_count,
|
|
"records" => $rows,
|
|
"last_qry" => $last_qry
|
|
];
|
|
$this->sys_ok($result);
|
|
} catch (Exception $exc) {
|
|
$message = $exc->getMessage();
|
|
$this->sys_error($message);
|
|
}
|
|
}
|
|
|
|
function searchtest()
|
|
{
|
|
try {
|
|
if (!$this->isLogin) {
|
|
$this->sys_error("Invalid Token");
|
|
exit;
|
|
}
|
|
$prm = $this->sys_input;
|
|
$userid = $this->sys_user['M_UserID'];
|
|
|
|
$number_limit = 10;
|
|
$tot_count = 0;
|
|
|
|
$search = "";
|
|
if (isset($prm['search'])) {
|
|
$search = trim($prm["search"]);
|
|
if ($search != "") {
|
|
$search = '%' . $prm['search'] . '%';
|
|
} else {
|
|
$search = '%%';
|
|
}
|
|
}
|
|
|
|
$sql_total = "SELECT count(*) as total
|
|
FROM nat_test
|
|
WHERE Nat_TestIsActive = 'Y'
|
|
AND Nat_TestIsResult = 'Y'
|
|
AND (CONCAT(Nat_TestCode,' ',Nat_TestName) LIKE ?)
|
|
LIMIT ?";
|
|
$qry_total = $this->db->query($sql_total, [$search, $number_limit]);
|
|
if ($qry_total) {
|
|
$tot_count = $qry_total->result_array()[0]["total"];
|
|
} else {
|
|
$this->db->trans_rollback();
|
|
$this->sys_error_db("nat_test count");
|
|
exit;
|
|
}
|
|
|
|
$sql_search = "SELECT Nat_TestID,
|
|
Nat_TestCode,
|
|
CONCAT(Nat_TestCode,' ',Nat_TestName) as codeNameTest
|
|
FROM nat_test
|
|
WHERE Nat_TestIsActive = 'Y'
|
|
AND Nat_TestIsResult = 'Y'
|
|
AND (CONCAT(Nat_TestCode,' ',Nat_TestName) LIKE ?)
|
|
LIMIT ?";
|
|
$qry_search = $this->db->query($sql_search, [$search, $number_limit]);
|
|
if ($qry_search) {
|
|
$rows = $qry_search->result_array();
|
|
} else {
|
|
$this->db->trans_rollback();
|
|
$this->sys_error_db("nat_test select error", $this->db);
|
|
exit;
|
|
}
|
|
|
|
$result = array(
|
|
"total" => $tot_count,
|
|
"total_display" => sizeof($rows),
|
|
"records" => $rows
|
|
);
|
|
$this->sys_ok($result);
|
|
} catch (Exception $exc) {
|
|
$message = $exc->getMessage();
|
|
$this->sys_error($message);
|
|
}
|
|
}
|
|
|
|
function searchkelainan()
|
|
{
|
|
try {
|
|
if (!$this->isLogin) {
|
|
$this->sys_error("Invalid Token");
|
|
exit;
|
|
}
|
|
$prm = $this->sys_input;
|
|
$userid = $this->sys_user['M_UserID'];
|
|
|
|
$number_limit = 10;
|
|
$tot_count = 0;
|
|
|
|
$search = "";
|
|
if (isset($prm['search'])) {
|
|
$search = trim($prm["search"]);
|
|
if ($search != "") {
|
|
$search = '%' . $prm['search'] . '%';
|
|
} else {
|
|
$search = '%%';
|
|
}
|
|
}
|
|
|
|
$sql_total = "SELECT count(*) as total
|
|
FROM one_etl.mcu_kelainan
|
|
WHERE Mcu_KelainanIsActive = 'Y'
|
|
AND (Mcu_KelainanName LIKE ?)
|
|
LIMIT ?";
|
|
$qry_total = $this->db->query($sql_total, [$search, $number_limit]);
|
|
if ($qry_total) {
|
|
$tot_count = $qry_total->result_array()[0]["total"];
|
|
} else {
|
|
$this->db->trans_rollback();
|
|
$this->sys_error_db("kelainan count");
|
|
exit;
|
|
}
|
|
|
|
$sql_search = "SELECT Mcu_KelainanID,
|
|
Mcu_KelainanName,
|
|
Mcu_KelainanClasification
|
|
FROM one_etl.mcu_kelainan
|
|
WHERE Mcu_KelainanIsActive = 'Y'
|
|
AND (Mcu_KelainanName LIKE ?)
|
|
LIMIT ?";
|
|
$qry_search = $this->db->query($sql_search, [$search, $number_limit]);
|
|
if ($qry_search) {
|
|
$rows = $qry_search->result_array();
|
|
} else {
|
|
$this->db->trans_rollback();
|
|
$this->sys_error_db("kelainan select error", $this->db);
|
|
exit;
|
|
}
|
|
|
|
$result = array(
|
|
"total" => $tot_count,
|
|
"total_display" => sizeof($rows),
|
|
"records" => $rows
|
|
);
|
|
$this->sys_ok($result);
|
|
} catch (Exception $exc) {
|
|
$message = $exc->getMessage();
|
|
$this->sys_error($message);
|
|
}
|
|
}
|
|
|
|
function add()
|
|
{
|
|
try {
|
|
if (!$this->isLogin) {
|
|
$this->sys_error("Invalid Token");
|
|
exit;
|
|
}
|
|
$this->db->trans_begin();
|
|
$prm = $this->sys_input;
|
|
$userid = $this->sys_user['M_UserID'];
|
|
|
|
$testId = "";
|
|
if (isset($prm["testId"])) {
|
|
$testId = trim($prm["testId"]);
|
|
}
|
|
$kelainanId = "";
|
|
if (isset($prm["kelainanId"])) {
|
|
$kelainanId = trim($prm["kelainanId"]);
|
|
}
|
|
$testCode = "";
|
|
if (isset($prm["testCode"])) {
|
|
$testCode = trim($prm["testCode"]);
|
|
}
|
|
$type = "";
|
|
if (isset($prm["type"])) {
|
|
$type = trim($prm["type"]);
|
|
}
|
|
$normalValue = "";
|
|
if (isset($prm["normalValue"])) {
|
|
$normalValue = trim($prm["normalValue"]);
|
|
}
|
|
$value = "";
|
|
if (isset($prm["value"])) {
|
|
$value = trim($prm["value"]);
|
|
}
|
|
|
|
$sql_exist = "SELECT Mcu_SummaryLabID,
|
|
Mcu_SummaryLabNat_TestID,
|
|
Mcu_summaryLabMcu_KelainanID
|
|
FROM one_etl.mcu_summarylab
|
|
WHERE Mcu_SummaryLabIsActive = 'Y'
|
|
AND Mcu_SummaryLabNat_TestID = ?
|
|
AND Mcu_summaryLabMcu_KelainanID = ?";
|
|
$qry_exist = $this->db->query($sql_exist, [$testId, $kelainanId]);
|
|
if ($qry_exist) {
|
|
$tot_exist = $qry_exist->result_array();
|
|
} else {
|
|
$this->db->trans_rollback();
|
|
$this->sys_error_db("mcu_summarylab count");
|
|
exit;
|
|
}
|
|
|
|
if (count($tot_exist) > 0) {
|
|
echo json_encode(["status" => "OK", "flag" => true, "msg" => "Tidak bisa disimpan karena ada kelainan yang sama dengan pemeriksaan yang sudah ada, silahkan pilih kelainan lainnya!"]);
|
|
exit;
|
|
}
|
|
|
|
$datatype = "";
|
|
switch ($type) {
|
|
case "KD":
|
|
$datatype = '<';
|
|
break;
|
|
case "LD":
|
|
$datatype = '>';
|
|
break;
|
|
case "SD":
|
|
$datatype = '=';
|
|
break;
|
|
case "KDSD":
|
|
$datatype = '<=';
|
|
break;
|
|
case "LDSD":
|
|
$datatype = '>=';
|
|
break;
|
|
case "TSD":
|
|
$datatype = '!=';
|
|
break;
|
|
default:
|
|
$datatype = '';
|
|
}
|
|
|
|
$sql = "INSERT INTO one_etl.mcu_summarylab(
|
|
Mcu_SummaryLabNat_TestID,
|
|
Mcu_SummaryLabNat_TestCode,
|
|
Mcu_summaryLabMcu_KelainanID,
|
|
Mcu_SummaryLabType,
|
|
Mcu_SummaryLabIsNormalValue,
|
|
Mcu_SummaryLabValue,
|
|
Mcu_SummaryLabIsActive,
|
|
Mcu_SummaryLabUserID,
|
|
Mcu_SummaryLabCreated,
|
|
Mcu_SummaryLabLastUpdated
|
|
) VALUES(?,?,?,?,?,?,'Y',?,NOW(),NOW())";
|
|
$qry = $this->db->query($sql, array(
|
|
$testId,
|
|
$testCode,
|
|
$kelainanId,
|
|
$datatype,
|
|
$normalValue,
|
|
$value,
|
|
$userid
|
|
));
|
|
if (!$qry) {
|
|
$this->db->trans_rollback();
|
|
$this->sys_error_db("save mcu_summarylab error", $this->db);
|
|
exit;
|
|
}
|
|
|
|
$this->db->trans_commit();
|
|
$result = array(
|
|
"total" => 1,
|
|
"affected_rows" => $this->db->affected_rows()
|
|
);
|
|
$this->sys_ok($result);
|
|
} catch (Exception $exc) {
|
|
$message = $exc->getMessage();
|
|
$this->sys_error($message);
|
|
}
|
|
}
|
|
|
|
function edit()
|
|
{
|
|
try {
|
|
if (!$this->isLogin) {
|
|
$this->sys_error("Invalid Token");
|
|
exit;
|
|
}
|
|
$this->db->trans_begin();
|
|
$prm = $this->sys_input;
|
|
$userid = $this->sys_user['M_UserID'];
|
|
|
|
$xid = "";
|
|
if (isset($prm["xid"])) {
|
|
$xid = trim($prm["xid"]);
|
|
}
|
|
$type = "";
|
|
if (isset($prm["type"])) {
|
|
$type = trim($prm["type"]);
|
|
}
|
|
$normalValue = "";
|
|
if (isset($prm["normalValue"])) {
|
|
$normalValue = trim($prm["normalValue"]);
|
|
}
|
|
$value = "";
|
|
if (isset($prm["value"])) {
|
|
$value = trim($prm["value"]);
|
|
}
|
|
|
|
$datatype = "";
|
|
switch ($type) {
|
|
case "KD":
|
|
$datatype = '<';
|
|
break;
|
|
case "LD":
|
|
$datatype = '>';
|
|
break;
|
|
case "SD":
|
|
$datatype = '=';
|
|
break;
|
|
case "KDSD":
|
|
$datatype = '<=';
|
|
break;
|
|
case "LDSD":
|
|
$datatype = '>=';
|
|
break;
|
|
case "TSD":
|
|
$datatype = '!=';
|
|
break;
|
|
default:
|
|
$datatype = '';
|
|
}
|
|
|
|
$sql = "UPDATE one_etl.mcu_summarylab SET
|
|
Mcu_SummaryLabType = ?,
|
|
Mcu_SummaryLabIsNormalValue = ?,
|
|
Mcu_SummaryLabValue = ?,
|
|
Mcu_SummaryLabUserID = ?,
|
|
Mcu_SummaryLabLastUpdated = NOW()
|
|
WHERE Mcu_SummaryLabID = ?";
|
|
$qry = $this->db->query($sql, [
|
|
$datatype,
|
|
$normalValue,
|
|
$value,
|
|
$userid,
|
|
$xid
|
|
]);
|
|
if (!$qry) {
|
|
$this->db->trans_rollback();
|
|
$this->sys_error_db("update mcu_summarylab error", $this->db);
|
|
exit;
|
|
}
|
|
|
|
$this->db->trans_commit();
|
|
$result = array(
|
|
"total" => 1,
|
|
"records" => array("xid" => 0)
|
|
);
|
|
$this->sys_ok($result);
|
|
} catch (Exception $exc) {
|
|
$message = $exc->getMessage();
|
|
$this->sys_error($message);
|
|
}
|
|
}
|
|
|
|
function deleterow()
|
|
{
|
|
try {
|
|
if (!$this->isLogin) {
|
|
$this->sys_error("Invalid Token");
|
|
exit;
|
|
}
|
|
$this->db->trans_begin();
|
|
$prm = $this->sys_input;
|
|
$userid = $this->sys_user['M_UserID'];
|
|
|
|
$xid = "";
|
|
if (isset($prm["xid"])) {
|
|
$xid = trim($prm["xid"]);
|
|
}
|
|
|
|
$sql = "UPDATE one_etl.mcu_summarylab SET
|
|
Mcu_SummaryLabIsActive = 'N',
|
|
Mcu_SummaryLabUserID = ?,
|
|
Mcu_SummaryLabLastUpdated = NOW()
|
|
WHERE Mcu_SummaryLabID = ?";
|
|
$qry = $this->db->query($sql, [
|
|
$userid,
|
|
$xid
|
|
]);
|
|
if (!$qry) {
|
|
$this->db->trans_rollback();
|
|
$this->sys_error_db("delete mcu_summarylab error", $this->db);
|
|
exit;
|
|
}
|
|
|
|
$this->db->trans_commit();
|
|
$result = array(
|
|
"total" => 1,
|
|
"records" => array("xid" => 0)
|
|
);
|
|
$this->sys_ok($result);
|
|
} catch (Exception $exc) {
|
|
$message = $exc->getMessage();
|
|
$this->sys_error($message);
|
|
}
|
|
}
|
|
}
|