246 lines
8.6 KiB
PHP
246 lines
8.6 KiB
PHP
<?php
|
|
class Service extends MY_Controller
|
|
{
|
|
var $db;
|
|
function __construct()
|
|
{
|
|
parent::__construct();
|
|
}
|
|
|
|
function index()
|
|
{
|
|
$cek = $this->db->query("select database() as current_db")->result();
|
|
echo "API Service HIS";
|
|
// print_r($cek);
|
|
}
|
|
|
|
function search()
|
|
{
|
|
try {
|
|
if (!$this->isLogin) {
|
|
$this->sys_error("Invalid Token");
|
|
exit;
|
|
}
|
|
$prm = $this->sys_input;
|
|
|
|
$search = "";
|
|
if(isset($prm["search"])) {
|
|
$search = trim($prm["search"]);
|
|
if ($search != "") {
|
|
$search = "%" . $prm["search"] . "%";
|
|
}else{
|
|
$search = "%%";
|
|
}
|
|
}
|
|
|
|
$number_offset = 0;
|
|
$number_limit = 10;
|
|
if ($prm["current_page"] > 0) {
|
|
$number_offset = ($prm["current_page"] - 1) * $number_limit;
|
|
}
|
|
|
|
$sql_filter = "SELECT COUNT(DISTINCT c.service_id) as total
|
|
FROM one_his.service_registration a
|
|
JOIN one_his.service_registration_group b ON a.group_id = b.group_id
|
|
AND a.healthcare_service_id = b.healthcare_service_id
|
|
AND a.healthcare_service_id IN ( '100000021 ','100000022')
|
|
JOIN one_his.service c ON a.service_id = c.service_id
|
|
AND c.status_cd = 'normal'
|
|
WHERE c.service_id LIKE ? OR c.service_name LIKE ? OR group_title LIKE ?
|
|
ORDER BY b.order_no, a.order_no";
|
|
|
|
$qry_filter = $this->db->query($sql_filter, [$search, $search, $search]);
|
|
|
|
$tot_count = 0;
|
|
$tot_page = 0;
|
|
if ($qry_filter) {
|
|
$tot_count = $qry_filter->result_array()[0]["total"];
|
|
$tot_page = ceil($tot_count/$number_limit);
|
|
} else {
|
|
$this->sys_error_db("service count error", $this->db);
|
|
exit;
|
|
}
|
|
|
|
$sql = "SELECT c.service_id as code, group_title as title, c.service_id as id, c.service_name as name
|
|
FROM one_his.service_registration a
|
|
JOIN one_his.service_registration_group b ON a.group_id = b.group_id
|
|
AND a.healthcare_service_id = b.healthcare_service_id
|
|
AND a.healthcare_service_id IN ( '100000021 ','100000022')
|
|
JOIN one_his.service c ON a.service_id = c.service_id
|
|
AND c.status_cd = 'normal'
|
|
WHERE c.service_id LIKE ? OR c.service_name LIKE ? OR group_title LIKE ?
|
|
ORDER BY b.order_no, a.order_no
|
|
LIMIT ? OFFSET ?";
|
|
|
|
|
|
$qry = $this->db->query($sql, array($search, $search, $search, $number_limit, $number_offset));
|
|
if($qry){
|
|
$rows = $qry->result_array();
|
|
}else{
|
|
$this->sys_error_db("service select error", $this->db);
|
|
exit;
|
|
}
|
|
|
|
$result = array(
|
|
"total_page" => $tot_page,
|
|
"total_filter" => count($rows),
|
|
"records" => $rows
|
|
);
|
|
$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;
|
|
$search = "";
|
|
if(isset($prm["search"])) {
|
|
$search = trim($prm["search"]);
|
|
if ($search != "") {
|
|
$search = "%" . $prm["search"] . "%";
|
|
}else{
|
|
$search = "%%";
|
|
}
|
|
}
|
|
|
|
$service_id = 0;
|
|
if (isset($prm['service_id'])) {
|
|
$service_id = trim($prm["service_id"]);
|
|
}
|
|
|
|
$number_offset = 0;
|
|
$number_limit = 10;
|
|
if ($prm["current_page"] > 0) {
|
|
$number_offset = ($prm["current_page"] - 1) * $number_limit;
|
|
}
|
|
|
|
$sql_filter = "SELECT COUNT(*) as total
|
|
FROM t_test a
|
|
LEFT JOIN one_his.service_test b ON a.T_TestID = b.T_TestID
|
|
AND b.service_id = ?
|
|
AND service_testIsActive = 'Y'
|
|
WHERE T_TestIsActive = 'Y' AND (T_TestSasCode LIKE ? OR T_TestName LIKE ?)";
|
|
|
|
$qry_filter = $this->db->query($sql_filter, [$service_id, $search, $search]);
|
|
|
|
$tot_count = 0;
|
|
$tot_page = 0;
|
|
if ($qry_filter) {
|
|
$tot_count = $qry_filter->result_array()[0]["total"];
|
|
$tot_page = ceil($tot_count/$number_limit);
|
|
} else {
|
|
$this->sys_error_db("test count error", $this->db);
|
|
exit;
|
|
}
|
|
|
|
$sql = "SELECT a.T_TestID as testId, T_TestSasCode as sascode, T_TestName as testname,
|
|
IF(b.service_id IS NULL, 'N', 'Y') as status
|
|
FROM t_test a
|
|
LEFT JOIN one_his.service_test b ON a.T_TestID = b.T_TestID
|
|
AND b.service_id = ?
|
|
AND service_testIsActive = 'Y'
|
|
WHERE T_TestIsActive = 'Y' AND (T_TestSasCode LIKE ? OR T_TestName LIKE ?)
|
|
LIMIT ? OFFSET ?";
|
|
|
|
$qry = $this->db->query($sql, [$service_id, $search, $search, $number_limit, $number_offset]);
|
|
if($qry){
|
|
$rows = $qry->result_array();
|
|
}else{
|
|
$this->sys_error_db("test select error", $this->db);
|
|
exit;
|
|
}
|
|
|
|
$result = array(
|
|
"total" => $tot_page,
|
|
"total_filter" => count($rows),
|
|
"records" => $rows
|
|
);
|
|
$this->sys_ok($result);
|
|
|
|
} catch (Exception $exc) {
|
|
$message = $exc->getMessage();
|
|
$this->sys_error($message);
|
|
}
|
|
}
|
|
|
|
function saveedittest()
|
|
{
|
|
try {
|
|
if (! $this->isLogin) {
|
|
$this->sys_error("Invalid Token");
|
|
exit;
|
|
}
|
|
$prm = $this->sys_input;
|
|
$userid = $this->sys_user["M_UserID"];
|
|
$testid = $prm["testid"];
|
|
$service_id = $prm["service_id"];
|
|
$status = $prm["status"];
|
|
//cari servitest testid, service_id
|
|
$sql = "SELECT service_test_id, T_TestID, service_id, service_testIsActive
|
|
FROM one_his.service_test
|
|
WHERE T_TestID = ?
|
|
AND service_id = ?";
|
|
$qry = $this->db->query($sql, array($testid, $service_id));
|
|
if($qry){
|
|
$rows = $qry->result_array();
|
|
}else{
|
|
$this->sys_error_db("service test error", $this->db);
|
|
exit;
|
|
}
|
|
if (count($rows) > 0) {
|
|
// sudah ada
|
|
// print_r($rows);
|
|
$servicetestid = $rows[0]["service_test_id"];
|
|
$sql_update = "UPDATE one_his.service_test SET
|
|
service_testIsActive = ?,
|
|
service_testCreated = NOW(),
|
|
service_testLastUpdated = NOW(),
|
|
service_testUserID = ?
|
|
WHERE service_test_id = ?";
|
|
$qry_update = $this->db->query($sql_update, array($status, $userid, $servicetestid));
|
|
if (!$qry_update) {
|
|
$this->sys_error_db("service_test update", $this->db);
|
|
exit;
|
|
}
|
|
|
|
} else {
|
|
// belum ada
|
|
$sql_insert = "INSERT INTO one_his.service_test(
|
|
service_id,
|
|
T_TestID,
|
|
service_testCreated,
|
|
service_testLastUpdated,
|
|
service_testUserID)
|
|
VALUES(?, ?,NOW(),NOW(),?)";
|
|
$qry_insert = $this->db->query($sql_insert, array($service_id, $testid, $userid
|
|
));
|
|
if (!$qry_insert) {
|
|
$this->db->trans_rollback();
|
|
$this->sys_error_db("service_test 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);
|
|
}
|
|
}
|
|
}
|