Initial import
This commit is contained in:
@@ -0,0 +1,571 @@
|
||||
<?php
|
||||
class Polakelainannonlab 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 mcu_summarynonlab
|
||||
JOIN nat_test ON Mcu_SummaryNonlabNat_TestID = Nat_TestID
|
||||
AND Nat_TestIsActive = 'Y'
|
||||
JOIN mcu_kelainan ON Mcu_SummaryNonlabMcu_KelainanID = Mcu_KelainanID
|
||||
AND Mcu_KelainanIsActive = 'Y'
|
||||
WHERE Mcu_SummaryNonlabIsActive = '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_summarynonlab count error", $this->db);
|
||||
exit;
|
||||
}
|
||||
|
||||
$sql = "SELECT Mcu_SummaryNonlabID,
|
||||
Mcu_SummaryNonlabNat_TestID,
|
||||
Mcu_SummaryNonlabNat_Code,
|
||||
Mcu_SummaryNonlabMcu_KelainanID,
|
||||
Mcu_SummaryNonlabValue,
|
||||
Mcu_SummaryNonlabConclusionDetailIDs,
|
||||
Nat_TestID,
|
||||
Nat_TestCode,
|
||||
CONCAT(Nat_TestCode,' ',Nat_TestName) AS codeNameTest,
|
||||
Mcu_KelainanID,
|
||||
Mcu_KelainanName,
|
||||
Mcu_FitnessCategoryID,
|
||||
Mcu_FitnessCategoryName,
|
||||
Mcu_FitnessCategoryEng,
|
||||
CONCAT(Mcu_FitnessCategoryName,' ','(',Mcu_FitnessCategoryEng,')') as fitnessname,
|
||||
'' as rownumber,
|
||||
'' as xvalue
|
||||
FROM mcu_summarynonlab
|
||||
JOIN nat_test ON Mcu_SummaryNonlabNat_TestID = Nat_TestID
|
||||
AND Nat_TestIsActive = 'Y'
|
||||
JOIN mcu_kelainan ON Mcu_SummaryNonlabMcu_KelainanID = Mcu_KelainanID
|
||||
AND Mcu_KelainanIsActive = 'Y'
|
||||
LEFT JOIN mcu_fitness_category ON Mcu_SummaryNonlabMcu_FitnessCategoryID = Mcu_FitnessCategoryID
|
||||
AND Mcu_FitnessCategoryIsActive = 'Y'
|
||||
WHERE Mcu_SummaryNonlabIsActive = 'Y'
|
||||
AND (CONCAT(Nat_TestCode,' ',Nat_TestName) LIKE ? OR Mcu_KelainanName LIKE ?)
|
||||
ORDER BY Mcu_SummaryNonlabID 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_summarynonlab select error", $this->db);
|
||||
exit;
|
||||
}
|
||||
|
||||
$rows = $qry->result_array();
|
||||
foreach ($rows as $k => $v) {
|
||||
$xno = ($k + 1) + $number_offset;
|
||||
$rows[$k]['rownumber'] = $xno;
|
||||
$rows[$k]['xvalue'] = $this->add_value($v['Mcu_SummaryNonlabID']);
|
||||
}
|
||||
|
||||
|
||||
$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 add_value($orderid)
|
||||
{
|
||||
$sql = $this->db->query("SELECT Mcu_SummaryNonlabConclusionDetailIDs FROM mcu_summarynonlab
|
||||
WHERE Mcu_SummaryNonlabID = {$orderid}")->row();
|
||||
$svalue = $sql->Mcu_SummaryNonlabConclusionDetailIDs;
|
||||
$pieces = explode(",", $svalue);
|
||||
|
||||
$Mcu_SummaryNonlabConclusionDetailIDs = "''";
|
||||
foreach ($pieces as $idx => $detail) {
|
||||
$Mcu_SummaryNonlabConclusionDetailIDs .= "," . "'" . $detail . "'";
|
||||
}
|
||||
|
||||
|
||||
$query = "SELECT NonlabConclusionDetailID, NonlabConclusionDetailCode, NonlabConclusionDetailName
|
||||
|
||||
FROM mcu_summarynonlab
|
||||
JOIN nonlab_conclusion_detail ON NonlabConclusionDetailID IN($Mcu_SummaryNonlabConclusionDetailIDs)
|
||||
WHERE
|
||||
Mcu_SummaryNonlabID = {$orderid}";
|
||||
//echo $query;
|
||||
$rows = $this->db->query($query)->result_array();
|
||||
if (!$rows)
|
||||
$rows = array();
|
||||
return $rows;
|
||||
}
|
||||
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 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 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 searchstatusresult()
|
||||
{
|
||||
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 nonlab_conclusion_detail
|
||||
WHERE NonlabConclusionDetailIsActive = 'Y'
|
||||
AND (NonlabConclusionDetailName 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 NonlabConclusionDetailID,
|
||||
NonlabConclusionDetailCode,
|
||||
NonlabConclusionDetailName
|
||||
FROM nonlab_conclusion_detail
|
||||
WHERE NonlabConclusionDetailIsActive = 'Y'
|
||||
AND (NonlabConclusionDetailName 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"]);
|
||||
}
|
||||
$fitnessId = 0;
|
||||
if (isset($prm["fitnessId"])) {
|
||||
$fitnessId = trim($prm["fitnessId"]);
|
||||
}
|
||||
|
||||
$codes = array_map(function ($item) {
|
||||
return $item["NonlabConclusionDetailID"];
|
||||
}, $prm["orderstatusresults"]);
|
||||
$vcode = implode(",", $codes);
|
||||
|
||||
$sql_exist = "SELECT Mcu_SummaryNonlabID,
|
||||
Mcu_SummaryNonlabNat_TestID,
|
||||
Mcu_SummaryNonlabMcu_KelainanID
|
||||
FROM mcu_summarynonlab
|
||||
WHERE Mcu_SummaryNonlabIsActive = 'Y'
|
||||
AND Mcu_SummaryNonlabNat_TestID = ?
|
||||
AND Mcu_SummaryNonlabMcu_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_summarynonlab 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;
|
||||
}
|
||||
|
||||
|
||||
|
||||
$sql = "INSERT INTO mcu_summarynonlab(
|
||||
Mcu_SummaryNonlabNat_TestID,
|
||||
Mcu_SummaryNonlabNat_Code,
|
||||
Mcu_SummaryNonlabMcu_KelainanID,
|
||||
Mcu_SummaryNonlabMcu_FitnessCategoryID,
|
||||
Mcu_SummaryNonlabConclusionDetailIDs,
|
||||
Mcu_SummaryNonlabUserID,
|
||||
Mcu_SummaryNonlabCreated,
|
||||
Mcu_SummaryNonlabLastUpdated
|
||||
) VALUES(?,?,?,?,?,?,NOW(),NOW())";
|
||||
$qry = $this->db->query($sql, array(
|
||||
$testId,
|
||||
$testCode,
|
||||
$kelainanId,
|
||||
$fitnessId,
|
||||
$vcode,
|
||||
$userid
|
||||
));
|
||||
if (!$qry) {
|
||||
$this->db->trans_rollback();
|
||||
$this->sys_error_db("save mcu_summarynonlab 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"]);
|
||||
}
|
||||
$fitnessId = 0;
|
||||
if (isset($prm["fitnessId"])) {
|
||||
$fitnessId = trim($prm["fitnessId"]);
|
||||
}
|
||||
|
||||
$codes = array_map(function ($item) {
|
||||
return $item["NonlabConclusionDetailID"];
|
||||
}, $prm["orderstatusresults"]);
|
||||
$vcode = implode(",", $codes);
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
$sql = "UPDATE mcu_summarynonlab SET
|
||||
Mcu_SummaryNonlabMcu_FitnessCategoryID = ?,
|
||||
Mcu_SummaryNonlabConclusionDetailIDs = ?,
|
||||
Mcu_SummaryNonlabUserID = ?,
|
||||
Mcu_SummaryNonlabLastUpdated = NOW()
|
||||
WHERE Mcu_SummaryNonlabID = ?";
|
||||
$qry = $this->db->query($sql, [
|
||||
$fitnessId,
|
||||
$vcode,
|
||||
$userid,
|
||||
$xid
|
||||
]);
|
||||
if (!$qry) {
|
||||
$this->db->trans_rollback();
|
||||
$this->sys_error_db("update mcu_summarynonlab 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 mcu_summarynonlab SET
|
||||
Mcu_SummaryNonlabIsActive = 'N',
|
||||
Mcu_SummaryNonlabUserID = ?,
|
||||
Mcu_SummaryNonlabLastUpdated = NOW()
|
||||
WHERE Mcu_SummaryNonlabID = ?";
|
||||
$qry = $this->db->query($sql, [
|
||||
$userid,
|
||||
$xid
|
||||
]);
|
||||
if (!$qry) {
|
||||
$this->db->trans_rollback();
|
||||
$this->sys_error_db("delete mcu_summarynonlab 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 getfitness()
|
||||
{
|
||||
try {
|
||||
if (!$this->isLogin) {
|
||||
$this->sys_error("Invalid Token");
|
||||
exit;
|
||||
}
|
||||
$this->db->trans_begin();
|
||||
$prm = $this->sys_input;
|
||||
$userid = $this->sys_user['M_UserID'];
|
||||
|
||||
$sql = "SELECT Mcu_FitnessCategoryID,
|
||||
Mcu_FitnessCategoryName,
|
||||
Mcu_FitnessCategoryEng,
|
||||
CONCAT(Mcu_FitnessCategoryName,' ','(',Mcu_FitnessCategoryEng,')') as fitnessname,
|
||||
Mcu_FitnessCategoryLevel
|
||||
FROM mcu_fitness_category
|
||||
WHERE Mcu_FitnessCategoryIsActive = 'Y'";
|
||||
$qry = $this->db->query($sql);
|
||||
if ($qry) {
|
||||
$rows = $qry->result_array();
|
||||
} else {
|
||||
$this->sys_error_db("mcu fitness error", $this->db);
|
||||
}
|
||||
|
||||
$result = array("records" => $rows, "total_display" => sizeof($rows));
|
||||
$this->sys_ok($result);
|
||||
} catch (Exception $exc) {
|
||||
$message = $exc->getMessage();
|
||||
$this->sys_error($message);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user