Initial import
This commit is contained in:
79
application/controllers/etl/Admin.http
Normal file
79
application/controllers/etl/Admin.http
Normal file
@@ -0,0 +1,79 @@
|
||||
GET http://{{host}}/etl/admin/index
|
||||
Content-Type: application/json
|
||||
|
||||
###
|
||||
GET http://{{host}}/etl/admin/search
|
||||
Content-Type: application/json
|
||||
|
||||
{
|
||||
"search": "",
|
||||
"token": "eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJNX1VzZXJJRCI6IjI4NiIsIk1fVXNlclVzZXJuYW1lIjoiYWRtaW5mbyIsIk1fVXNlckdyb3VwRGFzaGJvYXJkIjoib25lLXVpXC90ZXN0XC92dWV4XC9vbmUtZm8tcmVnaXN0cmF0aW9uLXYyNyIsIk1fVXNlckRlZmF1bHRUX1NhbXBsZVN0YXRpb25JRCI6IjAiLCJNX1N0YWZmTmFtZSI6IlJJWUFOIEFNSU5VTEFIIFBSQUtPU08iLCJpc19jb3VyaWVyIjoiTiIsInRpbWVfYXV0b2xvZ291dCI6IjE1IiwiaXAiOiIxOTIuMTY4LjI1MC4zOCIsImFnZW50IjoiTW96aWxsYVwvNS4wIChXaW5kb3dzIE5UIDEwLjA7IFdpbjY0OyB4NjQpIEFwcGxlV2ViS2l0XC81MzcuMzYgKEtIVE1MLCBsaWtlIEdlY2tvKSBDaHJvbWVcLzEyMy4wLjAuMCBTYWZhcmlcLzUzNy4zNiIsInZlcnNpb24iOiJ2MiIsImxhc3QtbG9naW4iOiIyMDI0LTA0LTE2IDA4OjIyOjExIiwiTV9TYXRlbGxpdGVJRCI6MH0.4QRciSA4V3dHhFt1hsIboSZxzWY3DJou4pCAv3LNlxM"
|
||||
}
|
||||
|
||||
###
|
||||
GET http://{{host}}/etl/admin/list_mcu_order
|
||||
Content-Type: application/json
|
||||
|
||||
{
|
||||
"search": "",
|
||||
"mgmmcuid": 1,
|
||||
"token": "eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJNX1VzZXJJRCI6IjI4NiIsIk1fVXNlclVzZXJuYW1lIjoiYWRtaW5mbyIsIk1fVXNlckdyb3VwRGFzaGJvYXJkIjoib25lLXVpXC90ZXN0XC92dWV4XC9vbmUtZm8tcmVnaXN0cmF0aW9uLXYyNyIsIk1fVXNlckRlZmF1bHRUX1NhbXBsZVN0YXRpb25JRCI6IjAiLCJNX1N0YWZmTmFtZSI6IlJJWUFOIEFNSU5VTEFIIFBSQUtPU08iLCJpc19jb3VyaWVyIjoiTiIsInRpbWVfYXV0b2xvZ291dCI6IjE1IiwiaXAiOiIxOTIuMTY4LjI1MC4zOCIsImFnZW50IjoiTW96aWxsYVwvNS4wIChXaW5kb3dzIE5UIDEwLjA7IFdpbjY0OyB4NjQpIEFwcGxlV2ViS2l0XC81MzcuMzYgKEtIVE1MLCBsaWtlIEdlY2tvKSBDaHJvbWVcLzEyMy4wLjAuMCBTYWZhcmlcLzUzNy4zNiIsInZlcnNpb24iOiJ2MiIsImxhc3QtbG9naW4iOiIyMDI0LTA0LTE2IDA4OjIyOjExIiwiTV9TYXRlbGxpdGVJRCI6MH0.4QRciSA4V3dHhFt1hsIboSZxzWY3DJou4pCAv3LNlxM"
|
||||
}
|
||||
|
||||
###
|
||||
GET http://{{host}}/etl/admin/search_company
|
||||
Content-Type: application/json
|
||||
|
||||
{
|
||||
"search": "PERTAMINA",
|
||||
"token": "eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJNX1VzZXJJRCI6IjI4NiIsIk1fVXNlclVzZXJuYW1lIjoiYWRtaW5mbyIsIk1fVXNlckdyb3VwRGFzaGJvYXJkIjoib25lLXVpXC90ZXN0XC92dWV4XC9vbmUtZm8tcmVnaXN0cmF0aW9uLXYyNyIsIk1fVXNlckRlZmF1bHRUX1NhbXBsZVN0YXRpb25JRCI6IjAiLCJNX1N0YWZmTmFtZSI6IlJJWUFOIEFNSU5VTEFIIFBSQUtPU08iLCJpc19jb3VyaWVyIjoiTiIsInRpbWVfYXV0b2xvZ291dCI6IjE1IiwiaXAiOiIxOTIuMTY4LjI1MC4zOCIsImFnZW50IjoiTW96aWxsYVwvNS4wIChXaW5kb3dzIE5UIDEwLjA7IFdpbjY0OyB4NjQpIEFwcGxlV2ViS2l0XC81MzcuMzYgKEtIVE1MLCBsaWtlIEdlY2tvKSBDaHJvbWVcLzEyMy4wLjAuMCBTYWZhcmlcLzUzNy4zNiIsInZlcnNpb24iOiJ2MiIsImxhc3QtbG9naW4iOiIyMDI0LTA0LTE2IDA4OjIyOjExIiwiTV9TYXRlbGxpdGVJRCI6MH0.4QRciSA4V3dHhFt1hsIboSZxzWY3DJou4pCAv3LNlxM"
|
||||
}
|
||||
|
||||
###
|
||||
GET http://{{host}}/etl/admin/search_mou_multiple
|
||||
Content-Type: application/json
|
||||
|
||||
{
|
||||
"companyId": 1222,
|
||||
"token": "eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJNX1VzZXJJRCI6IjI4NiIsIk1fVXNlclVzZXJuYW1lIjoiYWRtaW5mbyIsIk1fVXNlckdyb3VwRGFzaGJvYXJkIjoib25lLXVpXC90ZXN0XC92dWV4XC9vbmUtZm8tcmVnaXN0cmF0aW9uLXYyNyIsIk1fVXNlckRlZmF1bHRUX1NhbXBsZVN0YXRpb25JRCI6IjAiLCJNX1N0YWZmTmFtZSI6IlJJWUFOIEFNSU5VTEFIIFBSQUtPU08iLCJpc19jb3VyaWVyIjoiTiIsInRpbWVfYXV0b2xvZ291dCI6IjE1IiwiaXAiOiIxOTIuMTY4LjI1MC4zOCIsImFnZW50IjoiTW96aWxsYVwvNS4wIChXaW5kb3dzIE5UIDEwLjA7IFdpbjY0OyB4NjQpIEFwcGxlV2ViS2l0XC81MzcuMzYgKEtIVE1MLCBsaWtlIEdlY2tvKSBDaHJvbWVcLzEyMy4wLjAuMCBTYWZhcmlcLzUzNy4zNiIsInZlcnNpb24iOiJ2MiIsImxhc3QtbG9naW4iOiIyMDI0LTA0LTE2IDA4OjIyOjExIiwiTV9TYXRlbGxpdGVJRCI6MH0.4QRciSA4V3dHhFt1hsIboSZxzWY3DJou4pCAv3LNlxM"
|
||||
}
|
||||
|
||||
###
|
||||
GET http://{{host}}/etl/admin/addMcu
|
||||
Content-Type: application/json
|
||||
|
||||
{
|
||||
"companyId": "1222",
|
||||
"nationalNumber": "MCUN0002",
|
||||
"startdate": "2024-05-13",
|
||||
"enddate": "2024-05-13",
|
||||
"selectedMou": [
|
||||
3,
|
||||
12
|
||||
],
|
||||
"participant": "50",
|
||||
"token": "eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJNX1VzZXJJRCI6IjM0MCIsIk1fVXNlclVzZXJuYW1lIjoiYWRtaW5zYXMgIiwiTV9Vc2VyR3JvdXBEYXNoYm9hcmQiOiJvbmUtdWlcL3Rlc3RcL3Z1ZXhcL29uZS1mby1yZWdpc3RyYXRpb24tdjI1IiwiTV9Vc2VyRGVmYXVsdFRfU2FtcGxlU3RhdGlvbklEIjoiMCIsIk1fU3RhZmZOYW1lIjoiQURNSU4iLCJpc19jb3VyaWVyIjoiTiIsInRpbWVfYXV0b2xvZ291dCI6IjEyMCIsImlwIjoiMTM5LjE5Mi4xNzAuNzciLCJhZ2VudCI6Ik1vemlsbGFcLzUuMCAoV2luZG93cyBOVCAxMC4wOyBXaW42NDsgeDY0KSBBcHBsZVdlYktpdFwvNTM3LjM2IChLSFRNTCwgbGlrZSBHZWNrbykgQ2hyb21lXC8xMjIuMC4wLjAgU2FmYXJpXC81MzcuMzYgRWRnXC8xMjIuMC4wLjAiLCJ2ZXJzaW9uIjoidjIiLCJsYXN0LWxvZ2luIjoiMjAyNC0wMy0yOCAwODoxOToxMSIsIk1fU2F0ZWxsaXRlSUQiOjB9.I5GrVzvfn1Puhszy5rSCIk0hTwsGXm7GtmoSXhLhp8A"
|
||||
}
|
||||
|
||||
###
|
||||
GET http://{{host}}/etl/admin/insert_mcu_order
|
||||
Content-Type: application/json
|
||||
|
||||
{
|
||||
"mgmmcuid": 4,
|
||||
"token": "eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJNX1VzZXJJRCI6IjI4NiIsIk1fVXNlclVzZXJuYW1lIjoiYWRtaW5mbyIsIk1fVXNlckdyb3VwRGFzaGJvYXJkIjoib25lLXVpXC90ZXN0XC92dWV4XC9vbmUtZm8tcmVnaXN0cmF0aW9uLXYyNyIsIk1fVXNlckRlZmF1bHRUX1NhbXBsZVN0YXRpb25JRCI6IjAiLCJNX1N0YWZmTmFtZSI6IlJJWUFOIEFNSU5VTEFIIFBSQUtPU08iLCJpc19jb3VyaWVyIjoiTiIsInRpbWVfYXV0b2xvZ291dCI6IjE1IiwiaXAiOiIxOTIuMTY4LjI1MC4zOCIsImFnZW50IjoiTW96aWxsYVwvNS4wIChXaW5kb3dzIE5UIDEwLjA7IFdpbjY0OyB4NjQpIEFwcGxlV2ViS2l0XC81MzcuMzYgKEtIVE1MLCBsaWtlIEdlY2tvKSBDaHJvbWVcLzEyMy4wLjAuMCBTYWZhcmlcLzUzNy4zNiIsInZlcnNpb24iOiJ2MiIsImxhc3QtbG9naW4iOiIyMDI0LTA0LTE2IDA4OjIyOjExIiwiTV9TYXRlbGxpdGVJRCI6MH0.4QRciSA4V3dHhFt1hsIboSZxzWY3DJou4pCAv3LNlxM"
|
||||
}
|
||||
|
||||
###
|
||||
GET http://{{host}}/etl/admin/editMcu
|
||||
Content-Type: application/json
|
||||
|
||||
{
|
||||
"mgmmcuid": 3,
|
||||
"selectedMou": [
|
||||
"12322",
|
||||
"12323",
|
||||
"2367"
|
||||
],
|
||||
"token": "eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJNX1VzZXJJRCI6IjI4NiIsIk1fVXNlclVzZXJuYW1lIjoiYWRtaW5mbyIsIk1fVXNlckdyb3VwRGFzaGJvYXJkIjoib25lLXVpXC90ZXN0XC92dWV4XC9vbmUtZm8tcmVnaXN0cmF0aW9uLXYyNyIsIk1fVXNlckRlZmF1bHRUX1NhbXBsZVN0YXRpb25JRCI6IjAiLCJNX1N0YWZmTmFtZSI6IlJJWUFOIEFNSU5VTEFIIFBSQUtPU08iLCJpc19jb3VyaWVyIjoiTiIsInRpbWVfYXV0b2xvZ291dCI6IjE1IiwiaXAiOiIxOTIuMTY4LjI1MC4zOCIsImFnZW50IjoiTW96aWxsYVwvNS4wIChXaW5kb3dzIE5UIDEwLjA7IFdpbjY0OyB4NjQpIEFwcGxlV2ViS2l0XC81MzcuMzYgKEtIVE1MLCBsaWtlIEdlY2tvKSBDaHJvbWVcLzEyMy4wLjAuMCBTYWZhcmlcLzUzNy4zNiIsInZlcnNpb24iOiJ2MiIsImxhc3QtbG9naW4iOiIyMDI0LTA0LTE2IDA4OjIyOjExIiwiTV9TYXRlbGxpdGVJRCI6MH0.4QRciSA4V3dHhFt1hsIboSZxzWY3DJou4pCAv3LNlxM"
|
||||
}
|
||||
793
application/controllers/etl/Admin.php
Normal file
793
application/controllers/etl/Admin.php
Normal file
@@ -0,0 +1,793 @@
|
||||
<?php
|
||||
class Admin extends MY_Controller
|
||||
{
|
||||
var $db;
|
||||
public function index()
|
||||
{
|
||||
// $cek = $this->db->query("select database() as current_db")->result();
|
||||
// print_r($cek);
|
||||
echo "ADMIN MCU API";
|
||||
}
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
parent::__construct();
|
||||
}
|
||||
|
||||
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 = "SELECT
|
||||
Mgm_McuID,
|
||||
Mgm_McuM_CompanyID,
|
||||
Mgm_McuNumber,
|
||||
Mgm_McuNumberNational,
|
||||
Mgm_McuStartDate,
|
||||
Mgm_McuEndDate,
|
||||
Mgm_McuTotalParticipant,
|
||||
Mgm_MouID,
|
||||
GROUP_CONCAT(M_MouID SEPARATOR ', ') AS M_MouID,
|
||||
GROUP_CONCAT(Mgm_MouM_MouID SEPARATOR ', ') AS Mgm_MouM_MouID,
|
||||
M_CompanyName,
|
||||
M_CompanyID,
|
||||
GROUP_CONCAT(M_MouName SEPARATOR ', ') AS M_MouName,
|
||||
'N' as readyconfirm
|
||||
FROM
|
||||
(SELECT
|
||||
Mgm_McuID,
|
||||
Mgm_McuM_CompanyID,
|
||||
Mgm_McuNumber,
|
||||
Mgm_McuNumberNational,
|
||||
Mgm_McuStartDate,
|
||||
Mgm_McuEndDate,
|
||||
Mgm_McuTotalParticipant,
|
||||
Mgm_MouID,
|
||||
Mgm_MouM_MouID,
|
||||
M_MouName,
|
||||
M_CompanyName,
|
||||
M_CompanyID,
|
||||
M_MouID
|
||||
FROM one_etl.mgm_mcu
|
||||
JOIN one_etl.mgm_mou ON Mgm_McuID = Mgm_MouMgm_McuID
|
||||
AND Mgm_MouIsActive = 'Y'
|
||||
JOIN m_company ON Mgm_McuM_CompanyID = M_CompanyID
|
||||
AND M_CompanyIsActive = 'Y'
|
||||
JOIN m_mou ON Mgm_MouM_MouID = M_MouID
|
||||
AND M_MouIsActive = 'Y'
|
||||
WHERE
|
||||
Mgm_McuIsActive = 'Y'
|
||||
AND (Mgm_McuNumber LIKE '{$search}' OR M_CompanyName LIKE '{$search}' OR M_MouName LIKE '{$search}')
|
||||
GROUP BY Mgm_MouID, Mgm_McuID) AS subquery
|
||||
GROUP BY Mgm_McuID, M_CompanyName
|
||||
ORDER BY Mgm_McuID DESC";
|
||||
|
||||
$sql_total = "SELECT COUNT(*) as total FROM ($sql) as x";
|
||||
$qry_total = $this->db->query($sql_total);
|
||||
|
||||
$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("mgm_mcu count error", $this->db);
|
||||
exit;
|
||||
}
|
||||
|
||||
$sql_select = $sql . " LIMIT $number_limit OFFSET $number_offset";
|
||||
$qry_select = $this->db->query($sql_select);
|
||||
$last_qry = $this->db->last_query();
|
||||
if (!$qry_select) {
|
||||
$message = $this->db->error();
|
||||
$message['last_qry'] = $last_qry;
|
||||
$this->sys_error($message);
|
||||
exit;
|
||||
}
|
||||
$rows = $qry_select->result_array();
|
||||
|
||||
foreach ($rows as $k => $v) {
|
||||
$sql = $this->db_onedev->query("SELECT count(*) as x FROM one_etl.mcu_order
|
||||
WHERE Mcu_OrderMgm_McuID = '{$v['Mgm_McuID']}' AND Mcu_OrderStatus = 'N'")->row();
|
||||
$svalue = $sql->x;
|
||||
if($svalue > 0){
|
||||
$rows[$k]['readyconfirm'] = 'Y';
|
||||
}else{
|
||||
$rows[$k]['readyconfirm'] = 'N';
|
||||
}
|
||||
}
|
||||
|
||||
$result = [
|
||||
"records" => $rows,
|
||||
"total_page" => $tot_page,
|
||||
"total" => $tot_count,
|
||||
"last_qry" => $last_qry
|
||||
];
|
||||
$this->sys_ok($result);
|
||||
} catch (Exception $exc) {
|
||||
$message = $exc->getMessage();
|
||||
$this->sys_error($message);
|
||||
}
|
||||
}
|
||||
|
||||
function list_mcu_order()
|
||||
{
|
||||
try {
|
||||
if (!$this->isLogin) {
|
||||
$this->sys_error("Invalid Token");
|
||||
exit;
|
||||
}
|
||||
$prm = $this->sys_input;
|
||||
$userid = $this->sys_user['M_UserID'];
|
||||
|
||||
$mgmmcuid = 0;
|
||||
if (isset($prm['mgmmcuid'])) {
|
||||
$mgmmcuid = trim($prm["mgmmcuid"]);
|
||||
}
|
||||
|
||||
$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_order
|
||||
JOIN one_etl.mgm_mcu ON Mcu_OrderMgm_McuID = Mgm_McuID
|
||||
JOIN t_orderheader ON Mcu_OrderT_OrderHeaderID = T_OrderHeaderID
|
||||
AND T_OrderHeaderIsActive = 'Y'
|
||||
JOIN m_patient ON T_OrderHeaderM_PatientID = M_PatientID
|
||||
JOIN m_title ON M_PatientM_TitleID = M_TitleID
|
||||
JOIN m_sex ON M_PatientM_SexID = M_SexID
|
||||
WHERE Mgm_McuID = ?
|
||||
AND (T_OrderHeaderLabNumber LIKE ? OR concat(M_TitleName,'. ',M_PatientName) LIKE ?)";
|
||||
$qry_total = $this->db->query($sql_total, [$mgmmcuid, $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("mgm_order count error", $this->db);
|
||||
exit;
|
||||
}
|
||||
|
||||
$sql = "SELECT Mcu_OrderID,
|
||||
Mcu_OrderMgm_McuID,
|
||||
Mcu_OrderT_OrderHeaderID,
|
||||
Mcu_OrderStatus,
|
||||
Mcu_OrderIsError,
|
||||
Mcu_OrderRetry,
|
||||
T_OrderHeaderID,
|
||||
T_OrderHeaderDate,
|
||||
T_OrderHeaderLabNumber,
|
||||
concat(M_TitleName,'. ',M_PatientName) as M_PatientName,
|
||||
M_PatientNoReg
|
||||
FROM one_etl.mcu_order
|
||||
JOIN one_etl.mgm_mcu ON Mcu_OrderMgm_McuID = Mgm_McuID
|
||||
JOIN t_orderheader ON Mcu_OrderT_OrderHeaderID = T_OrderHeaderID
|
||||
AND T_OrderHeaderIsActive = 'Y'
|
||||
JOIN m_patient ON T_OrderHeaderM_PatientID = M_PatientID
|
||||
JOIN m_title ON M_PatientM_TitleID = M_TitleID
|
||||
JOIN m_sex ON M_PatientM_SexID = M_SexID
|
||||
WHERE Mgm_McuID = ?
|
||||
AND (T_OrderHeaderLabNumber LIKE ? OR concat(M_TitleName,'. ',M_PatientName) LIKE ?)
|
||||
limit ? offset ?";
|
||||
$qry = $this->db->query($sql, [$mgmmcuid, $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($message);
|
||||
exit;
|
||||
}
|
||||
$rows = $qry->result_array();
|
||||
$result = [
|
||||
"records" => $rows,
|
||||
"total_page" => $tot_page,
|
||||
"total" => $tot_count,
|
||||
"last_qry" => $last_qry
|
||||
];
|
||||
$this->sys_ok($result);
|
||||
} catch (Exception $exc) {
|
||||
$message = $exc->getMessage();
|
||||
$this->sys_error($message);
|
||||
}
|
||||
}
|
||||
|
||||
function search_company()
|
||||
{
|
||||
try {
|
||||
if (!$this->isLogin) {
|
||||
$this->sys_error("Invalid Token");
|
||||
exit;
|
||||
}
|
||||
$prm = $this->sys_input;
|
||||
|
||||
$search = "";
|
||||
$number_limit = 10;
|
||||
$tot_count = 0;
|
||||
|
||||
if (isset($prm['search'])) {
|
||||
$search = trim($prm["search"]);
|
||||
if ($search != "") {
|
||||
$search = '%' . $prm['search'] . '%';
|
||||
} else {
|
||||
$search = '%%';
|
||||
}
|
||||
}
|
||||
|
||||
$sql_filter = "SELECT count(*) as total
|
||||
FROM m_company
|
||||
WHERE M_CompanyIsActive = 'Y'
|
||||
AND (M_CompanyName LIKE ?)
|
||||
LIMIT ?";
|
||||
$qry_filter = $this->db->query($sql_filter, [$search, $number_limit]);
|
||||
if ($qry_filter) {
|
||||
$tot_count = $qry_filter->result_array()[0]["total"];
|
||||
} else {
|
||||
$this->sys_error_db("company count");
|
||||
exit;
|
||||
}
|
||||
|
||||
$sql_search = "SELECT M_CompanyID,
|
||||
M_CompanyName,
|
||||
M_CompanyNumber
|
||||
FROM m_company
|
||||
WHERE M_CompanyIsActive = 'Y'
|
||||
AND (M_CompanyName 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("company 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 search_mou_multiple()
|
||||
{
|
||||
try {
|
||||
if (!$this->isLogin) {
|
||||
$this->sys_error("Invalid Token");
|
||||
exit;
|
||||
}
|
||||
$prm = $this->sys_input;
|
||||
|
||||
$companyId = $prm['companyId'];
|
||||
$number_limit = 10;
|
||||
$tot_count = 0;
|
||||
|
||||
$sql_filter = "SELECT count(*) as total
|
||||
FROM m_mou
|
||||
JOIN m_company ON M_MouM_CompanyID = M_CompanyID
|
||||
AND M_CompanyIsActive = 'Y'
|
||||
AND M_MouM_CompanyID = ?
|
||||
WHERE M_MouIsActive = 'Y'
|
||||
AND M_MouIsReleased = 'Y'";
|
||||
$qry_filter = $this->db->query($sql_filter, [$companyId]);
|
||||
if ($qry_filter) {
|
||||
$tot_count = $qry_filter->result_array()[0]["total"];
|
||||
} else {
|
||||
$this->sys_error_db("mou count");
|
||||
exit;
|
||||
}
|
||||
|
||||
$sql_search = "SELECT M_CompanyID,
|
||||
M_MouID,
|
||||
M_MouName,
|
||||
M_MouNumber
|
||||
FROM m_mou
|
||||
JOIN m_company ON M_MouM_CompanyID = M_CompanyID
|
||||
AND M_CompanyIsActive = 'Y'
|
||||
AND M_MouM_CompanyID = ?
|
||||
WHERE M_MouIsActive = 'Y'
|
||||
AND M_MouIsReleased = 'Y'";
|
||||
$qry_search = $this->db->query($sql_search, [$companyId]);
|
||||
if ($qry_search) {
|
||||
$rows = $qry_search->result_array();
|
||||
} else {
|
||||
$this->db->trans_rollback();
|
||||
$this->sys_error_db("mou 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 addMcu()
|
||||
{
|
||||
try {
|
||||
if (!$this->isLogin) {
|
||||
$this->sys_error("Invalid Token");
|
||||
exit;
|
||||
}
|
||||
$this->db->trans_begin();
|
||||
$prm = $this->sys_input;
|
||||
$userid = $this->sys_user['M_UserID'];
|
||||
$selectedMou = $prm['selectedMou'];
|
||||
|
||||
$sql_mcu = "INSERT INTO one_etl.mgm_mcu(
|
||||
Mgm_McuM_CompanyID,
|
||||
Mgm_McuNumber,
|
||||
Mgm_McuNumberNational,
|
||||
Mgm_McuStartDate,
|
||||
Mgm_McuEndDate,
|
||||
Mgm_McuIsActive,
|
||||
Mgm_McuCreated,
|
||||
Mgm_McuLastUpdated,
|
||||
Mgm_McuUserID,
|
||||
Mgm_McuTotalParticipant
|
||||
) VALUES(
|
||||
'{$prm['companyId']}',
|
||||
`fn_numbering`('ETL.MCU'),
|
||||
'{$prm['nationalNumber']}',
|
||||
'{$prm['startdate']}',
|
||||
'{$prm['enddate']}',
|
||||
'Y',
|
||||
NOW(),
|
||||
NOW(),
|
||||
'{$userid}',
|
||||
'{$prm['participant']}')";
|
||||
$qry_mcu = $this->db->query($sql_mcu);
|
||||
$last_qry = $this->db->last_query();
|
||||
if (!$qry_mcu) {
|
||||
$this->db->trans_rollback();
|
||||
$error = array(
|
||||
"message" => $this->db->error()["message"],
|
||||
"sql" => $last_qry
|
||||
);
|
||||
$this->sys_error_db($error, $this->db);
|
||||
exit;
|
||||
}
|
||||
|
||||
$last_id = $this->db->insert_id();
|
||||
|
||||
foreach ($selectedMou as $key => $value) {
|
||||
$sql_mou = "INSERT INTO one_etl.mgm_mou(
|
||||
Mgm_MouM_MouID,
|
||||
Mgm_MouMgm_McuID,
|
||||
Mgm_MouIsActive,
|
||||
Mgm_MouCreated,
|
||||
Mgm_MouLastUpdated,
|
||||
Mgm_MouUserID) VALUES(?, ?, 'Y',NOW(),NOW(),?)";
|
||||
$qry_mou = $this->db->query($sql_mou, array(
|
||||
$value,
|
||||
$last_id,
|
||||
$userid
|
||||
));
|
||||
$last_qry = $this->db->last_query();
|
||||
if (!$qry_mou) {
|
||||
$this->db->trans_rollback();
|
||||
$error = array(
|
||||
"message" => $this->db->error()["message"],
|
||||
"sql" => $last_qry
|
||||
);
|
||||
$this->sys_error_db($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 insert_mcu_order()
|
||||
{
|
||||
try {
|
||||
if (!$this->isLogin) {
|
||||
$this->sys_error("Invalid Token");
|
||||
exit;
|
||||
}
|
||||
$this->db->trans_begin();
|
||||
$prm = $this->sys_input;
|
||||
|
||||
$mgmmcuid = $prm['mgmmcuid'];
|
||||
// $orderheaderid = $prm['orderheaderid'];
|
||||
|
||||
$sql_select = "SELECT Mgm_McuID,
|
||||
T_OrderHeaderID
|
||||
FROM one_etl.mgm_mcu
|
||||
JOIN one_etl.mgm_mou ON Mgm_McuID = ?
|
||||
AND Mgm_McuID = Mgm_MouMgm_McuID
|
||||
AND Mgm_McuIsActive = 'Y'
|
||||
AND Mgm_MouIsActive = 'Y'
|
||||
JOIN t_orderheader ON T_OrderHeaderM_MouID = Mgm_MouM_MouID
|
||||
AND T_OrderHeaderDate >= Mgm_McuStartDate
|
||||
AND T_OrderHeaderDate <= Mgm_McuEndDate
|
||||
AND T_OrderHeaderIsActive = 'Y'
|
||||
AND T_OrderHeaderID NOT IN (
|
||||
SELECT Mcu_OrderT_OrderHeaderID
|
||||
FROM one_etl.mcu_order
|
||||
WHERE Mcu_OrderMgm_McuID = ?)";
|
||||
$qry_select = $this->db->query($sql_select, array($mgmmcuid, $mgmmcuid));
|
||||
if ($qry_select) {
|
||||
$rows = $qry_select->result_array();
|
||||
} else {
|
||||
$this->db->trans_rollback();
|
||||
$this->sys_error_db("orderheader select error", $this->db);
|
||||
exit;
|
||||
}
|
||||
|
||||
if (count($rows) > 0) {
|
||||
foreach ($rows as $key => $value) {
|
||||
// print_r($value);
|
||||
$orderheaderid = $value['T_OrderHeaderID'];
|
||||
// print_r($orderheaderid);
|
||||
$sql = "INSERT INTO one_etl.mcu_order(
|
||||
Mcu_OrderMgm_McuID,
|
||||
Mcu_OrderT_OrderHeaderID,
|
||||
Mcu_OrderCreated,
|
||||
Mcu_OrderLastUpdated) VALUES(?,?,NOW(),NOW())";
|
||||
$qry = $this->db->query($sql, array(
|
||||
$mgmmcuid,
|
||||
$orderheaderid
|
||||
));
|
||||
$last_qry = $this->db->last_query();
|
||||
if (!$qry) {
|
||||
$this->db->trans_rollback();
|
||||
$error = array(
|
||||
"message" => $this->db->error()["message"],
|
||||
"sql" => $last_qry
|
||||
);
|
||||
$this->sys_error_db($error, $this->db);
|
||||
exit;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$this->db->trans_commit();
|
||||
$result = array(
|
||||
"total" => count($rows),
|
||||
"affected_rows" => $this->db->affected_rows()
|
||||
);
|
||||
$this->sys_ok($result);
|
||||
} catch (Exception $exc) {
|
||||
$message = $exc->getMessage();
|
||||
$this->sys_error($message);
|
||||
}
|
||||
}
|
||||
function confirm_mcu_order()
|
||||
{
|
||||
try {
|
||||
if (!$this->isLogin) {
|
||||
$this->sys_error("Invalid Token");
|
||||
exit;
|
||||
}
|
||||
$this->db->trans_begin();
|
||||
$prm = $this->sys_input;
|
||||
$mgmmcuid = $prm['mgmmcuid'];
|
||||
|
||||
$sql = "UPDATE one_etl.mcu_order SET
|
||||
Mcu_OrderStatus = 'C',
|
||||
Mcu_OrderLastUpdated = NOW()
|
||||
WHERE Mcu_OrderMgm_McuID = ?";
|
||||
$res = $this->db->query($sql, array($mgmmcuid));
|
||||
if (!$res) {
|
||||
$this->db->trans_rollback();
|
||||
$this->sys_error_db('error', 'Error confirm: ' . $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 editMcu()
|
||||
{
|
||||
try {
|
||||
if (!$this->isLogin) {
|
||||
$this->sys_error("Invalid Token");
|
||||
exit;
|
||||
}
|
||||
$this->db->trans_begin();
|
||||
$prm = $this->sys_input;
|
||||
$userid = $this->sys_user['M_UserID'];
|
||||
$selectedMou = $prm['selectedMou'];
|
||||
$mgmmcuid = $prm['mgmmcuid'];
|
||||
|
||||
$sql_order = "SELECT Mcu_OrderID,
|
||||
Mcu_OrderMgm_McuID,
|
||||
Mcu_OrderT_OrderHeaderID
|
||||
FROM one_etl.mcu_order
|
||||
WHERE Mcu_OrderMgm_McuID = ?";
|
||||
$qry_order = $this->db->query($sql_order, [$mgmmcuid]);
|
||||
if ($qry_order) {
|
||||
$rows = $qry_order->result_array();
|
||||
} else {
|
||||
$this->db->trans_rollback();
|
||||
$this->sys_error_db("mcu_order select error", $this->db);
|
||||
exit;
|
||||
}
|
||||
|
||||
if (count($rows) > 0) {
|
||||
$result = json_encode(["status" => "OK", "message" => "Tidak bisa di edit karena sudah melakukan generate order!"]);
|
||||
echo $result;
|
||||
exit;
|
||||
}
|
||||
|
||||
$sql_update = "UPDATE one_etl.mgm_mcu SET
|
||||
Mgm_McuM_CompanyID = ?,
|
||||
Mgm_McuNumberNational = ?,
|
||||
Mgm_McuStartDate = ?,
|
||||
Mgm_McuEndDate = ?,
|
||||
Mgm_McuLastUpdated = NOW(),
|
||||
Mgm_McuUserID = ?,
|
||||
Mgm_McuTotalParticipant = ?
|
||||
WHERE Mgm_McuID = ?";
|
||||
$qry_update = $this->db->query($sql_update, [
|
||||
$prm['companyId'],
|
||||
$prm['nationalNumber'],
|
||||
$prm['startdate'],
|
||||
$prm['enddate'],
|
||||
$userid,
|
||||
$prm['participant'],
|
||||
$mgmmcuid
|
||||
]);
|
||||
if (!$qry_update) {
|
||||
$this->db->trans_rollback();
|
||||
$this->sys_error_db("update mgm_mcu error", $this->db);
|
||||
exit;
|
||||
}
|
||||
|
||||
// Ambil data Mgm_MouM_MouID
|
||||
$q = "SELECT Mgm_MouM_MouID
|
||||
FROM one_etl.mgm_mou
|
||||
WHERE Mgm_MouMgm_McuID = ?";
|
||||
$qry_mou = $this->db->query($q, array($mgmmcuid));
|
||||
|
||||
if (!$qry_mou) {
|
||||
$this->db->trans_rollback();
|
||||
$this->sys_error_db('error', 'Error select mgm_mou: ' . $this->db);
|
||||
exit;
|
||||
}
|
||||
$rows = $qry_mou->result_array();
|
||||
|
||||
$all = array();
|
||||
foreach ($rows as $row) {
|
||||
$all[] = $row['Mgm_MouM_MouID'];
|
||||
}
|
||||
|
||||
// print_r($all);
|
||||
// print_r($selectedMou);
|
||||
// exit;
|
||||
// Cek dan tambahkan data yang baru
|
||||
foreach ($selectedMou as $v) {
|
||||
|
||||
// print_r($v);
|
||||
// print_r($all);
|
||||
|
||||
// echo "\n status : ";
|
||||
// print_r(in_array($v, $all));
|
||||
|
||||
if (!in_array($v, $all)) {
|
||||
// Jika data belum ada, tambahkan ke database
|
||||
$q = "SELECT Mgm_MouMgm_McuID
|
||||
FROM one_etl.mgm_mou
|
||||
WHERE Mgm_MouMgm_McuID = ? AND Mgm_MouM_MouID = ?";
|
||||
$res = $this->db->query($q, array($mgmmcuid, $v));
|
||||
|
||||
if (!$res) {
|
||||
$this->db->trans_rollback();
|
||||
$this->sys_error_db('error', 'Error Select count: ' . $this->db);
|
||||
exit;
|
||||
}
|
||||
|
||||
$rows = $res->result_array();
|
||||
// echo $this->db->last_query();
|
||||
// print_r($rows);
|
||||
// exit;
|
||||
|
||||
if (count($rows) > 0) {
|
||||
$q = "UPDATE one_etl.mgm_mou SET
|
||||
Mgm_MouIsActive = 'Y',
|
||||
Mgm_MouLastUpdated = NOW(),
|
||||
Mgm_MouUserID = $userid
|
||||
WHERE Mgm_MouMgm_McuID = ? AND Mgm_MouM_MouID = ?";
|
||||
$res = $this->db->query($q, array($mgmmcuid, $v));
|
||||
|
||||
if (!$res) {
|
||||
$this->db->trans_rollback();
|
||||
$this->sys_error_db('error', 'Error update: ' . $this->db);
|
||||
exit;
|
||||
}
|
||||
} else {
|
||||
$q = "INSERT INTO one_etl.mgm_mou(
|
||||
Mgm_MouM_MouID,
|
||||
Mgm_MouMgm_McuID,
|
||||
Mgm_MouCreated,
|
||||
Mgm_MouUserID
|
||||
) VALUES(?,?,NOW(),?)";
|
||||
|
||||
$res = $this->db->query($q, array($v, $mgmmcuid, $userid));
|
||||
|
||||
if (!$res) {
|
||||
$this->db->trans_rollback();
|
||||
$this->sys_error_db('error', 'Error insert: ' . $this->db);
|
||||
exit;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
$q = "UPDATE one_etl.mgm_mou SET
|
||||
Mgm_MouIsActive = 'Y',
|
||||
Mgm_MouLastUpdated = NOW(),
|
||||
Mgm_MouUserID = $userid
|
||||
WHERE Mgm_MouMgm_McuID = ? and Mgm_MouM_MouID = ? and Mgm_MouIsActive = 'N'";
|
||||
$res = $this->db->query($q, array($mgmmcuid, $v));
|
||||
|
||||
// echo $this->db->last_query();
|
||||
if (!$res) {
|
||||
$this->db->trans_rollback();
|
||||
$this->sys_error_db('error', 'Error update active: ' . $this->db);
|
||||
exit;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// update yang gak ada di selectedmou
|
||||
$select = implode(",", $selectedMou);
|
||||
// print_r($select);
|
||||
|
||||
if ($select != "") {
|
||||
$q = "UPDATE one_etl.mgm_mou SET
|
||||
Mgm_MouIsActive = 'N',
|
||||
Mgm_MouLastUpdated = NOW(),
|
||||
Mgm_MouUserID = $userid
|
||||
WHERE Mgm_MouMgm_McuID = ? and Mgm_MouM_MouID NOT IN ($select)";
|
||||
$res = $this->db->query($q, array($mgmmcuid));
|
||||
if (!$res) {
|
||||
$this->db->trans_rollback();
|
||||
$this->sys_error_db('error', 'Error update delete: ' . $this->db);
|
||||
exit;
|
||||
}
|
||||
}
|
||||
|
||||
// $this->db->last_query();
|
||||
|
||||
|
||||
$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 deleteMcu()
|
||||
{
|
||||
try {
|
||||
if (!$this->isLogin) {
|
||||
$this->sys_error("Invalid Token");
|
||||
exit;
|
||||
}
|
||||
$this->db->trans_begin();
|
||||
$prm = $this->sys_input;
|
||||
$userid = $this->sys_user['M_UserID'];
|
||||
$mgmmcuid = $prm['mgmmcuid'];
|
||||
|
||||
$sql_order = "SELECT Mcu_OrderID,
|
||||
Mcu_OrderMgm_McuID,
|
||||
Mcu_OrderT_OrderHeaderID
|
||||
FROM one_etl.mcu_order
|
||||
WHERE Mcu_OrderMgm_McuID = ?";
|
||||
$qry_order = $this->db->query($sql_order, [$mgmmcuid]);
|
||||
if ($qry_order) {
|
||||
$rows = $qry_order->result_array();
|
||||
} else {
|
||||
$this->db->trans_rollback();
|
||||
$this->sys_error_db("mcu_order select error", $this->db);
|
||||
exit;
|
||||
}
|
||||
|
||||
if (count($rows) > 0) {
|
||||
$result = json_encode(["status" => "OK", "message" => "Tidak bisa di hapus karena sudah melakukan generate order!"]);
|
||||
echo $result;
|
||||
exit;
|
||||
}
|
||||
|
||||
$sql = "UPDATE one_etl.mgm_mcu SET
|
||||
Mgm_McuIsActive = 'N',
|
||||
Mgm_McuLastUpdated = NOW(),
|
||||
Mgm_McuUserID = ?
|
||||
WHERE Mgm_McuID = ?";
|
||||
$res = $this->db->query($sql, array($userid, $mgmmcuid));
|
||||
if (!$res) {
|
||||
$this->db->trans_rollback();
|
||||
$this->sys_error_db('error', 'Error delete: ' . $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);
|
||||
}
|
||||
}
|
||||
}
|
||||
748
application/controllers/etl/Admin_v2.php
Normal file
748
application/controllers/etl/Admin_v2.php
Normal file
@@ -0,0 +1,748 @@
|
||||
<?php
|
||||
class Admin_v2 extends MY_Controller
|
||||
{
|
||||
var $db;
|
||||
public function index()
|
||||
{
|
||||
// $cek = $this->db->query("select database() as current_db")->result();
|
||||
// print_r($cek);
|
||||
echo "ADMIN MCU API";
|
||||
}
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
parent::__construct();
|
||||
}
|
||||
|
||||
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 = "SELECT
|
||||
Mgm_McuID,
|
||||
Mgm_McuCorporateID,
|
||||
Mgm_McuNumber,
|
||||
Mgm_McuNumberNational,
|
||||
Mgm_McuStartDate,
|
||||
Mgm_McuEndDate,
|
||||
Mgm_McuTotalParticipant,
|
||||
M_CompanyName ,
|
||||
M_CompanyID,
|
||||
'N' as readyconfirm
|
||||
FROM
|
||||
(SELECT
|
||||
Mgm_McuID,
|
||||
Mgm_McuCorporateID,
|
||||
Mgm_McuNumber,
|
||||
Mgm_McuNumberNational,
|
||||
Mgm_McuStartDate,
|
||||
Mgm_McuEndDate,
|
||||
Mgm_McuTotalParticipant,
|
||||
CorporateName AS M_CompanyName,
|
||||
CorporateID AS M_CompanyID
|
||||
FROM mgm_mcu
|
||||
JOIN corporate ON Mgm_McuCorporateID = CorporateID
|
||||
AND CorporateIsActive = 'Y'
|
||||
AND Mgm_McuIsActive = 'Y'
|
||||
AND (Mgm_McuNumber LIKE '{$search}' OR CorporateName LIKE '{$search}')
|
||||
GROUP BY Mgm_McuID) AS subquery
|
||||
GROUP BY Mgm_McuID, M_CompanyName
|
||||
ORDER BY Mgm_McuID DESC";
|
||||
|
||||
$sql_total = "SELECT COUNT(*) as total FROM ($sql) as x";
|
||||
$qry_total = $this->db->query($sql_total);
|
||||
|
||||
$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("mgm_mcu count error", $this->db);
|
||||
exit;
|
||||
}
|
||||
|
||||
$sql_select = $sql . " LIMIT $number_limit OFFSET $number_offset";
|
||||
$qry_select = $this->db->query($sql_select);
|
||||
$last_qry = $this->db->last_query();
|
||||
if (!$qry_select) {
|
||||
$message = $this->db->error();
|
||||
$message['last_qry'] = $last_qry;
|
||||
$this->sys_error($message);
|
||||
exit;
|
||||
}
|
||||
$rows = $qry_select->result_array();
|
||||
|
||||
foreach ($rows as $k => $v) {
|
||||
$sql = $this->db_onedev->query("SELECT count(*) as x FROM mcu_order
|
||||
WHERE Mcu_OrderMgm_McuID = '{$v['Mgm_McuID']}' AND Mcu_OrderStatus = 'N'")->row();
|
||||
$svalue = $sql->x;
|
||||
if($svalue > 0){
|
||||
$rows[$k]['readyconfirm'] = 'Y';
|
||||
}else{
|
||||
$rows[$k]['readyconfirm'] = 'N';
|
||||
}
|
||||
}
|
||||
|
||||
$result = [
|
||||
"records" => $rows,
|
||||
"total_page" => $tot_page,
|
||||
"total" => $tot_count,
|
||||
"last_qry" => $last_qry
|
||||
];
|
||||
$this->sys_ok($result);
|
||||
} catch (Exception $exc) {
|
||||
$message = $exc->getMessage();
|
||||
$this->sys_error($message);
|
||||
}
|
||||
}
|
||||
|
||||
function list_mcu_order()
|
||||
{
|
||||
try {
|
||||
if (!$this->isLogin) {
|
||||
$this->sys_error("Invalid Token");
|
||||
exit;
|
||||
}
|
||||
$prm = $this->sys_input;
|
||||
$userid = $this->sys_user['M_UserID'];
|
||||
|
||||
$mgmmcuid = 0;
|
||||
if (isset($prm['mgmmcuid'])) {
|
||||
$mgmmcuid = trim($prm["mgmmcuid"]);
|
||||
}
|
||||
|
||||
$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_order
|
||||
JOIN mgm_mcu ON Mcu_OrderMgm_McuID = Mgm_McuID
|
||||
AND Mcu_OrderIsactive = 'Y'
|
||||
JOIN t_orderheader ON Mcu_OrderT_OrderHeaderID = T_OrderHeaderID
|
||||
AND T_OrderHeaderIsActive = 'Y'
|
||||
JOIN m_patient ON T_OrderHeaderM_PatientID = M_PatientID
|
||||
JOIN m_title ON M_PatientM_TitleID = M_TitleID
|
||||
-- JOIN m_sex ON M_PatientM_SexID = M_SexID
|
||||
WHERE Mgm_McuID = ?
|
||||
AND (T_OrderHeaderLabNumber LIKE ? OR concat(M_TitleName,'. ',M_PatientName) LIKE ?)";
|
||||
$qry_total = $this->db->query($sql_total, [$mgmmcuid, $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("mgm_order count error", $this->db);
|
||||
exit;
|
||||
}
|
||||
|
||||
$sql = "SELECT Mcu_OrderID,
|
||||
Mcu_OrderMgm_McuID,
|
||||
Mcu_OrderT_OrderHeaderID,
|
||||
Mcu_OrderStatus,
|
||||
Mcu_OrderIsError,
|
||||
Mcu_OrderRetry,
|
||||
T_OrderHeaderID,
|
||||
T_OrderHeaderDate,
|
||||
T_OrderHeaderLabNumber,
|
||||
concat(M_TitleName,'. ',M_PatientName) as M_PatientName,
|
||||
M_PatientNoReg
|
||||
FROM mcu_order
|
||||
JOIN mgm_mcu ON Mcu_OrderMgm_McuID = Mgm_McuID
|
||||
AND Mcu_OrderIsactive = 'Y'
|
||||
JOIN t_orderheader ON Mcu_OrderT_OrderHeaderID = T_OrderHeaderID
|
||||
AND T_OrderHeaderIsActive = 'Y'
|
||||
JOIN m_patient ON T_OrderHeaderM_PatientID = M_PatientID
|
||||
JOIN m_title ON M_PatientM_TitleID = M_TitleID
|
||||
-- JOIN m_sex ON M_PatientM_SexID = M_SexID
|
||||
WHERE Mgm_McuID = ?
|
||||
AND (T_OrderHeaderLabNumber LIKE ? OR concat(M_TitleName,'. ',M_PatientName) LIKE ?)
|
||||
limit ? offset ?";
|
||||
$qry = $this->db->query($sql, [$mgmmcuid, $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($message);
|
||||
exit;
|
||||
}
|
||||
$rows = $qry->result_array();
|
||||
$result = [
|
||||
"records" => $rows,
|
||||
"total_page" => $tot_page,
|
||||
"total" => $tot_count,
|
||||
"last_qry" => $last_qry
|
||||
];
|
||||
$this->sys_ok($result);
|
||||
} catch (Exception $exc) {
|
||||
$message = $exc->getMessage();
|
||||
$this->sys_error($message);
|
||||
}
|
||||
}
|
||||
|
||||
function search_company()
|
||||
{
|
||||
try {
|
||||
if (!$this->isLogin) {
|
||||
$this->sys_error("Invalid Token");
|
||||
exit;
|
||||
}
|
||||
$prm = $this->sys_input;
|
||||
|
||||
$search = "";
|
||||
$number_limit = 10;
|
||||
$tot_count = 0;
|
||||
|
||||
if (isset($prm['search'])) {
|
||||
$search = trim($prm["search"]);
|
||||
if ($search != "") {
|
||||
$search = '%' . $prm['search'] . '%';
|
||||
} else {
|
||||
$search = '%%';
|
||||
}
|
||||
}
|
||||
|
||||
$sql_filter = "SELECT count(*) as total
|
||||
FROM corporate
|
||||
WHERE CorporateIsActive = 'Y'
|
||||
AND (CorporateName LIKE ?)
|
||||
LIMIT ?";
|
||||
$qry_filter = $this->db->query($sql_filter, [$search, $number_limit]);
|
||||
if ($qry_filter) {
|
||||
$tot_count = $qry_filter->result_array()[0]["total"];
|
||||
} else {
|
||||
$this->sys_error_db("corporate count");
|
||||
exit;
|
||||
}
|
||||
|
||||
$sql_search = "SELECT CorporateID AS M_CompanyID,
|
||||
CorporateName AS M_CompanyName,
|
||||
CorporateCode As M_CompanyNumber
|
||||
FROM corporate
|
||||
WHERE CorporateIsActive = 'Y'
|
||||
AND (CorporateName 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("corporate 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 search_mou_multiple()
|
||||
// {
|
||||
// try {
|
||||
// if (!$this->isLogin) {
|
||||
// $this->sys_error("Invalid Token");
|
||||
// exit;
|
||||
// }
|
||||
// $prm = $this->sys_input;
|
||||
|
||||
// $companyId = $prm['companyId'];
|
||||
// $number_limit = 10;
|
||||
// $tot_count = 0;
|
||||
|
||||
// $sql_filter = "SELECT count(*) as total
|
||||
// FROM m_mou
|
||||
// JOIN m_company ON M_MouM_CompanyID = M_CompanyID
|
||||
// AND M_CompanyIsActive = 'Y'
|
||||
// AND M_MouM_CompanyID = ?
|
||||
// WHERE M_MouIsActive = 'Y'
|
||||
// AND M_MouIsReleased = 'Y'";
|
||||
// $qry_filter = $this->db->query($sql_filter, [$companyId]);
|
||||
// if ($qry_filter) {
|
||||
// $tot_count = $qry_filter->result_array()[0]["total"];
|
||||
// } else {
|
||||
// $this->sys_error_db("mou count");
|
||||
// exit;
|
||||
// }
|
||||
|
||||
// $sql_search = "SELECT M_CompanyID,
|
||||
// M_MouID,
|
||||
// M_MouName,
|
||||
// M_MouNumber
|
||||
// FROM m_mou
|
||||
// JOIN m_company ON M_MouM_CompanyID = M_CompanyID
|
||||
// AND M_CompanyIsActive = 'Y'
|
||||
// AND M_MouM_CompanyID = ?
|
||||
// WHERE M_MouIsActive = 'Y'
|
||||
// AND M_MouIsReleased = 'Y'";
|
||||
// $qry_search = $this->db->query($sql_search, [$companyId]);
|
||||
// if ($qry_search) {
|
||||
// $rows = $qry_search->result_array();
|
||||
// } else {
|
||||
// $this->db->trans_rollback();
|
||||
// $this->sys_error_db("mou 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 addMcu()
|
||||
{
|
||||
try {
|
||||
if (!$this->isLogin) {
|
||||
$this->sys_error("Invalid Token");
|
||||
exit;
|
||||
}
|
||||
$this->db->trans_begin();
|
||||
$prm = $this->sys_input;
|
||||
|
||||
$sql_mcu = "INSERT INTO mgm_mcu(
|
||||
Mgm_McuCorporateID,
|
||||
Mgm_McuNumber,
|
||||
Mgm_McuNumberNational,
|
||||
Mgm_McuStartDate,
|
||||
Mgm_McuEndDate,
|
||||
Mgm_McuIsActive,
|
||||
Mgm_McuCreated,
|
||||
Mgm_McuLastUpdated,
|
||||
Mgm_McuTotalParticipant
|
||||
) VALUES (
|
||||
'{$prm['companyId']}',
|
||||
fn_numbering('ETL.MCU'),
|
||||
'{$prm['nationalNumber']}',
|
||||
'{$prm['startdate']}',
|
||||
'{$prm['enddate']}',
|
||||
'Y',
|
||||
NOW(),
|
||||
NOW(),
|
||||
'{$prm['participant']}'
|
||||
)";
|
||||
$qry_mcu = $this->db->query($sql_mcu);
|
||||
$last_qry = $this->db->last_query();
|
||||
if (!$qry_mcu) {
|
||||
$this->db->trans_rollback();
|
||||
$error = array(
|
||||
"message" => $this->db->error()["message"],
|
||||
"sql" => $last_qry
|
||||
);
|
||||
$this->sys_error_db($error, $this->db);
|
||||
exit;
|
||||
}
|
||||
|
||||
$last_id = $this->db->insert_id();
|
||||
|
||||
$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 insert_mcu_order()
|
||||
{
|
||||
try {
|
||||
if (!$this->isLogin) {
|
||||
$this->sys_error("Invalid Token");
|
||||
exit;
|
||||
}
|
||||
$this->db->trans_begin();
|
||||
$prm = $this->sys_input;
|
||||
|
||||
$mgmmcuid = $prm['mgmmcuid'];
|
||||
// $orderheaderid = $prm['orderheaderid'];
|
||||
|
||||
$sql_select = "SELECT Mgm_McuID,
|
||||
T_OrderHeaderID
|
||||
FROM mgm_mcu
|
||||
JOIN t_orderheader ON T_OrderHeaderMgm_McuID = Mgm_McuID
|
||||
AND Mgm_McuID = ?
|
||||
AND Mgm_McuIsActive = 'Y'
|
||||
AND T_OrderHeaderDate >= Mgm_McuStartDate
|
||||
AND T_OrderHeaderDate <= Mgm_McuEndDate
|
||||
AND T_OrderHeaderIsActive = 'Y'
|
||||
AND T_OrderHeaderID NOT IN (
|
||||
SELECT Mcu_OrderT_OrderHeaderID
|
||||
FROM mcu_order
|
||||
WHERE Mcu_OrderMgm_McuID = ?
|
||||
AND Mcu_OrderIsActive = 'Y')";
|
||||
$qry_select = $this->db->query($sql_select, array($mgmmcuid, $mgmmcuid));
|
||||
if ($qry_select) {
|
||||
$rows = $qry_select->result_array();
|
||||
} else {
|
||||
$this->db->trans_rollback();
|
||||
$this->sys_error_db("orderheader select error", $this->db);
|
||||
exit;
|
||||
}
|
||||
|
||||
if (count($rows) > 0) {
|
||||
foreach ($rows as $key => $value) {
|
||||
// print_r($value);
|
||||
$orderheaderid = $value['T_OrderHeaderID'];
|
||||
// print_r($orderheaderid);
|
||||
$sql = "INSERT INTO mcu_order(
|
||||
Mcu_OrderMgm_McuID,
|
||||
Mcu_OrderT_OrderHeaderID,
|
||||
Mcu_OrderCreated,
|
||||
Mcu_OrderLastUpdated) VALUES(?,?,NOW(),NOW())";
|
||||
$qry = $this->db->query($sql, array(
|
||||
$mgmmcuid,
|
||||
$orderheaderid
|
||||
));
|
||||
$last_qry = $this->db->last_query();
|
||||
if (!$qry) {
|
||||
$this->db->trans_rollback();
|
||||
$error = array(
|
||||
"message" => $this->db->error()["message"],
|
||||
"sql" => $last_qry
|
||||
);
|
||||
$this->sys_error_db($error, $this->db);
|
||||
exit;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$this->db->trans_commit();
|
||||
$result = array(
|
||||
"total" => count($rows),
|
||||
"affected_rows" => $this->db->affected_rows()
|
||||
);
|
||||
$this->sys_ok($result);
|
||||
} catch (Exception $exc) {
|
||||
$message = $exc->getMessage();
|
||||
$this->sys_error($message);
|
||||
}
|
||||
}
|
||||
function confirm_mcu_order()
|
||||
{
|
||||
try {
|
||||
if (!$this->isLogin) {
|
||||
$this->sys_error("Invalid Token");
|
||||
exit;
|
||||
}
|
||||
$this->db->trans_begin();
|
||||
$prm = $this->sys_input;
|
||||
$mgmmcuid = $prm['mgmmcuid'];
|
||||
|
||||
$sql = "UPDATE mcu_order SET
|
||||
Mcu_OrderStatus = 'C',
|
||||
Mcu_OrderLastUpdated = NOW()
|
||||
WHERE Mcu_OrderMgm_McuID = ?";
|
||||
$res = $this->db->query($sql, array($mgmmcuid));
|
||||
if (!$res) {
|
||||
$this->db->trans_rollback();
|
||||
$this->sys_error_db('error', 'Error confirm: ' . $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 editMcu()
|
||||
{
|
||||
try {
|
||||
if (!$this->isLogin) {
|
||||
$this->sys_error("Invalid Token");
|
||||
exit;
|
||||
}
|
||||
$this->db->trans_begin();
|
||||
$prm = $this->sys_input;
|
||||
// $selectedMou = $prm['selectedMou'];
|
||||
$mgmmcuid = $prm['mgmmcuid'];
|
||||
|
||||
$sql_order = "SELECT Mcu_OrderID,
|
||||
Mcu_OrderMgm_McuID,
|
||||
Mcu_OrderT_OrderHeaderID
|
||||
FROM mcu_order
|
||||
WHERE Mcu_OrderMgm_McuID = ?";
|
||||
$qry_order = $this->db->query($sql_order, [$mgmmcuid]);
|
||||
if ($qry_order) {
|
||||
$rows = $qry_order->result_array();
|
||||
} else {
|
||||
$this->db->trans_rollback();
|
||||
$this->sys_error_db("mcu_order select error", $this->db);
|
||||
exit;
|
||||
}
|
||||
|
||||
if (count($rows) > 0) {
|
||||
$result = json_encode(["status" => "OK", "message" => "Tidak bisa di edit karena sudah melakukan generate order!"]);
|
||||
echo $result;
|
||||
exit;
|
||||
}
|
||||
|
||||
$sql_update = "UPDATE mgm_mcu SET
|
||||
Mgm_McuCorporateID = ?,
|
||||
Mgm_McuNumberNational = ?,
|
||||
Mgm_McuStartDate = ?,
|
||||
Mgm_McuEndDate = ?,
|
||||
Mgm_McuLastUpdated = NOW(),
|
||||
Mgm_McuTotalParticipant = ?
|
||||
WHERE Mgm_McuID = ?";
|
||||
$qry_update = $this->db->query($sql_update, [
|
||||
$prm['companyId'],
|
||||
$prm['nationalNumber'],
|
||||
$prm['startdate'],
|
||||
$prm['enddate'],
|
||||
$prm['participant'],
|
||||
$mgmmcuid
|
||||
]);
|
||||
if (!$qry_update) {
|
||||
$this->db->trans_rollback();
|
||||
$this->sys_error_db("update mgm_mcu error", $this->db);
|
||||
exit;
|
||||
}
|
||||
|
||||
// // Ambil data Mgm_MouM_MouID
|
||||
// $q = "SELECT Mgm_MouM_MouID
|
||||
// FROM one_etl.mgm_mou
|
||||
// WHERE Mgm_MouMgm_McuID = ?";
|
||||
// $qry_mou = $this->db->query($q, array($mgmmcuid));
|
||||
|
||||
// if (!$qry_mou) {
|
||||
// $this->db->trans_rollback();
|
||||
// $this->sys_error_db('error', 'Error select mgm_mou: ' . $this->db);
|
||||
// exit;
|
||||
// }
|
||||
// $rows = $qry_mou->result_array();
|
||||
|
||||
// $all = array();
|
||||
// foreach ($rows as $row) {
|
||||
// $all[] = $row['Mgm_MouM_MouID'];
|
||||
// }
|
||||
|
||||
// print_r($all);
|
||||
// print_r($selectedMou);
|
||||
// exit;
|
||||
// Cek dan tambahkan data yang baru
|
||||
// foreach ($selectedMou as $v) {
|
||||
|
||||
// // print_r($v);
|
||||
// // print_r($all);
|
||||
|
||||
// // echo "\n status : ";
|
||||
// // print_r(in_array($v, $all));
|
||||
|
||||
// if (!in_array($v, $all)) {
|
||||
// // Jika data belum ada, tambahkan ke database
|
||||
// $q = "SELECT Mgm_MouMgm_McuID
|
||||
// FROM one_etl.mgm_mou
|
||||
// WHERE Mgm_MouMgm_McuID = ? AND Mgm_MouM_MouID = ?";
|
||||
// $res = $this->db->query($q, array($mgmmcuid, $v));
|
||||
|
||||
// if (!$res) {
|
||||
// $this->db->trans_rollback();
|
||||
// $this->sys_error_db('error', 'Error Select count: ' . $this->db);
|
||||
// exit;
|
||||
// }
|
||||
|
||||
// $rows = $res->result_array();
|
||||
// // echo $this->db->last_query();
|
||||
// // print_r($rows);
|
||||
// // exit;
|
||||
|
||||
// if (count($rows) > 0) {
|
||||
// $q = "UPDATE one_etl.mgm_mou SET
|
||||
// Mgm_MouIsActive = 'Y',
|
||||
// Mgm_MouLastUpdated = NOW(),
|
||||
// Mgm_MouUserID = $userid
|
||||
// WHERE Mgm_MouMgm_McuID = ? AND Mgm_MouM_MouID = ?";
|
||||
// $res = $this->db->query($q, array($mgmmcuid, $v));
|
||||
|
||||
// if (!$res) {
|
||||
// $this->db->trans_rollback();
|
||||
// $this->sys_error_db('error', 'Error update: ' . $this->db);
|
||||
// exit;
|
||||
// }
|
||||
// } else {
|
||||
// $q = "INSERT INTO one_etl.mgm_mou(
|
||||
// Mgm_MouM_MouID,
|
||||
// Mgm_MouMgm_McuID,
|
||||
// Mgm_MouCreated,
|
||||
// Mgm_MouUserID
|
||||
// ) VALUES(?,?,NOW(),?)";
|
||||
|
||||
// $res = $this->db->query($q, array($v, $mgmmcuid, $userid));
|
||||
|
||||
// if (!$res) {
|
||||
// $this->db->trans_rollback();
|
||||
// $this->sys_error_db('error', 'Error insert: ' . $this->db);
|
||||
// exit;
|
||||
// }
|
||||
// }
|
||||
// } else {
|
||||
// $q = "UPDATE one_etl.mgm_mou SET
|
||||
// Mgm_MouIsActive = 'Y',
|
||||
// Mgm_MouLastUpdated = NOW(),
|
||||
// Mgm_MouUserID = $userid
|
||||
// WHERE Mgm_MouMgm_McuID = ? and Mgm_MouM_MouID = ? and Mgm_MouIsActive = 'N'";
|
||||
// $res = $this->db->query($q, array($mgmmcuid, $v));
|
||||
|
||||
// // echo $this->db->last_query();
|
||||
// if (!$res) {
|
||||
// $this->db->trans_rollback();
|
||||
// $this->sys_error_db('error', 'Error update active: ' . $this->db);
|
||||
// exit;
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
|
||||
|
||||
// update yang gak ada di selectedmou
|
||||
// $select = implode(",", $selectedMou);
|
||||
// // print_r($select);
|
||||
|
||||
// if ($select != "") {
|
||||
// $q = "UPDATE one_etl.mgm_mou SET
|
||||
// Mgm_MouIsActive = 'N',
|
||||
// Mgm_MouLastUpdated = NOW(),
|
||||
// Mgm_MouUserID = $userid
|
||||
// WHERE Mgm_MouMgm_McuID = ? and Mgm_MouM_MouID NOT IN ($select)";
|
||||
// $res = $this->db->query($q, array($mgmmcuid));
|
||||
// if (!$res) {
|
||||
// $this->db->trans_rollback();
|
||||
// $this->sys_error_db('error', 'Error update delete: ' . $this->db);
|
||||
// exit;
|
||||
// }
|
||||
// }
|
||||
|
||||
// $this->db->last_query();
|
||||
|
||||
|
||||
$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 deleteMcu()
|
||||
{
|
||||
try {
|
||||
if (!$this->isLogin) {
|
||||
$this->sys_error("Invalid Token");
|
||||
exit;
|
||||
}
|
||||
$this->db->trans_begin();
|
||||
$prm = $this->sys_input;
|
||||
$mgmmcuid = $prm['mgmmcuid'];
|
||||
|
||||
$sql_order = "SELECT Mcu_OrderID,
|
||||
Mcu_OrderMgm_McuID,
|
||||
Mcu_OrderT_OrderHeaderID
|
||||
FROM mcu_order
|
||||
WHERE Mcu_OrderMgm_McuID = ?";
|
||||
$qry_order = $this->db->query($sql_order, [$mgmmcuid]);
|
||||
if ($qry_order) {
|
||||
$rows = $qry_order->result_array();
|
||||
} else {
|
||||
$this->db->trans_rollback();
|
||||
$this->sys_error_db("mcu_order select error", $this->db);
|
||||
exit;
|
||||
}
|
||||
|
||||
if (count($rows) > 0) {
|
||||
$result = json_encode(["status" => "OK", "message" => "Tidak bisa di hapus karena sudah melakukan generate order!"]);
|
||||
echo $result;
|
||||
exit;
|
||||
}
|
||||
|
||||
$sql = "UPDATE mgm_mcu SET
|
||||
Mgm_McuIsActive = 'N',
|
||||
Mgm_McuLastUpdated = NOW()
|
||||
WHERE Mgm_McuID = ?";
|
||||
$res = $this->db->query($sql, array( $mgmmcuid));
|
||||
if (!$res) {
|
||||
$this->db->trans_rollback();
|
||||
$this->sys_error_db('error', 'Error delete: ' . $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);
|
||||
}
|
||||
}
|
||||
}
|
||||
250
application/controllers/etl/Danone.php
Normal file
250
application/controllers/etl/Danone.php
Normal file
@@ -0,0 +1,250 @@
|
||||
<?php
|
||||
/*
|
||||
create table danone(
|
||||
danoneID int not null auto_increment primary key,
|
||||
T_OrderHeaderID int,
|
||||
M_BranchName varchar(100),
|
||||
T_OrderHeaderLabNumber varchar(50),
|
||||
T_OrderHeaderLabNumberExt varchar(50),
|
||||
T_OrderHeaderDate varchar(50),
|
||||
NAMA varchar(50),
|
||||
shareID varchar(50),
|
||||
M_PatientNIK varchar(50),
|
||||
M_PatientIDNumber varchar(50),
|
||||
JENISKELAMIN varchar(50),
|
||||
M_PatientDOB varchar(50),
|
||||
T_OrderHeaderM_PatientAge varchar(100),
|
||||
M_PatientJabatan varchar(200),
|
||||
M_PatientKedudukan varchar(200),
|
||||
M_PatientPJ varchar(200),
|
||||
M_PatientJob varchar(200),
|
||||
M_PatientLocation varchar(300),
|
||||
M_CompanyName varchar(300),
|
||||
M_MouName varchar(300),
|
||||
M_CompanyID int,
|
||||
M_MouID int,
|
||||
|
||||
key(T_OrderHeaderID)
|
||||
);
|
||||
create table danone_detail(
|
||||
danoneDetailID int not null auto_increment primary key,
|
||||
danoneDetailDanoneID int,
|
||||
T_OrderHeaderID int,
|
||||
T_TestSasCode varchar(50),
|
||||
T_TestName varchar(300),
|
||||
Result text,
|
||||
key(T_OrderHeaderID),
|
||||
key(danoneDetailDanoneID)
|
||||
);
|
||||
create table danone_json(
|
||||
danoneJsonID int not null auto_increment primary key,
|
||||
danoneJsonDanoneID int,
|
||||
T_OrderHeaderID int,
|
||||
title varchar(300),
|
||||
subtitle varchar(300),
|
||||
label_flag_normal varchar(10),
|
||||
flag_normal varchar(1),
|
||||
show_all varchar(1),
|
||||
type_form varchar(10),
|
||||
T_TestName varchar(300),
|
||||
So_ResultEntryFisikUmumType varchar(100),
|
||||
name varchar(100),
|
||||
table_name varchar(100),
|
||||
segment_name varchar(100),
|
||||
id_code varchar(100),
|
||||
lang_id int,
|
||||
label varchar(100),
|
||||
is_normal varchar(1),
|
||||
chx bool,
|
||||
value varchar(300),
|
||||
value_x varchar(300),
|
||||
kesimpulan varchar(300),
|
||||
is_inspected varchar(1),
|
||||
key(danoneJsonDanoneID),
|
||||
key(T_OrderHeaderID)
|
||||
);
|
||||
*/
|
||||
class Danone extends MY_Controller
|
||||
{
|
||||
function __construct()
|
||||
{
|
||||
parent::__construct();
|
||||
}
|
||||
function index()
|
||||
{
|
||||
}
|
||||
function mou($mouID,$start,$end) {
|
||||
$start = "$start 00:00:01";
|
||||
$end = "$end 23:59:59";
|
||||
|
||||
$sql = "select T_OrderHeaderID from t_orderheader where T_OrderHeaderM_MouID=? and T_OrderHeaderDate >= ?
|
||||
and T_OrderHeaderDate <= ? and T_OrderHeaderIsActive = 'Y'";
|
||||
$qry = $this->db->query($sql,[$mouID,$start,$end]);
|
||||
if (!$qry) {
|
||||
$this->log("Error Processing Mou ID : $mouID, start : $start , end : $end \n");
|
||||
return;
|
||||
}
|
||||
$h_rows = $qry->result_array();
|
||||
if (count($h_rows) == 0) {
|
||||
echo "Tidak ada Order Mou $mouID dari tanggal $start s/d $end";
|
||||
exit;
|
||||
}
|
||||
foreach($h_rows as $h) {
|
||||
$orderHeaderID = $h["T_OrderHeaderID"];
|
||||
$this->process($orderHeaderID);
|
||||
}
|
||||
}
|
||||
function json($orderHeaderID, $danoneID)
|
||||
{
|
||||
$url = "http://localhost/one-api/v1/adhi/fisik/Fisik03/json/$orderHeaderID";
|
||||
$data = file_get_contents($url);
|
||||
$dataJson = json_decode($data, true);
|
||||
$this->log("\tProcessing Json\n");
|
||||
foreach ($dataJson as $r) {
|
||||
$arr = [
|
||||
"T_OrderHeaderID" => $orderHeaderID,
|
||||
"danoneJsonDanoneID" => $danoneID,
|
||||
"title" => $r["title"],
|
||||
"subtitle" => $r["subtitle"],
|
||||
"label_flag_normal" => $r["label_flag_normal"],
|
||||
"flag_normal" => $r["flag_normal"],
|
||||
"flag_normal" => $r["flag_normal"],
|
||||
"show_all" => $r["show_all"],
|
||||
"type_form" => $r["type_form"],
|
||||
"T_TestName" => $r["T_TestName"],
|
||||
"So_ResultEntryFisikUmumType" => $r["So_ResultEntryFisikUmumType"],
|
||||
"name" => $r["name"],
|
||||
"table_name" => $r["table_name"],
|
||||
"segment_name" => $r["segment_name"],
|
||||
"id_code" => $r["id_code"],
|
||||
"lang_id" => $r["lang_id"],
|
||||
"label" => $r["label"],
|
||||
"is_normal" => $r["is_normal"],
|
||||
"chx" => $r["chx"],
|
||||
"value" => $r["value"],
|
||||
"value_x" => $r["value_x"],
|
||||
"kesimpulan" => $r["kesimpulan"],
|
||||
"is_inspected" => $r["is_inspected"],
|
||||
|
||||
];
|
||||
$qry = $this->db->insert("one_etl.danone_json", $arr);
|
||||
if (!$qry) {
|
||||
echo "Error insert one_etl.danone_json, " . $this->db->error()["message"];
|
||||
$this->db->trans_rollback();
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
function log($msg) {
|
||||
echo Date("Y-m-d H:i:s") . " " . $msg . "\n";
|
||||
}
|
||||
function process($orderHeaderID)
|
||||
{
|
||||
//get from sp
|
||||
$this->log("Processing T_OrderHeaderID : " . $orderHeaderID);
|
||||
$sql = "call sp_rpt_r_mcu_resume(?,'')";
|
||||
$qry = $this->db->query($sql, [$orderHeaderID]);
|
||||
if (!$qry) {
|
||||
$this->log("\tError Processing T_OrderHeaderID : $orderHeaderID, " . $this->db->error()["message"]);
|
||||
return;
|
||||
}
|
||||
|
||||
$this->clean_mysqli_connection($this->db->conn_id);
|
||||
$rows = $qry->result_array();
|
||||
$isFirst = true;
|
||||
$this->db->trans_begin();
|
||||
//cleaning
|
||||
$this->log("Clearing existing snapshot for T_OrderHeaderID $orderHeaderID");
|
||||
$sql = "delete from one_etl.danone where T_OrderHeaderID = ?";
|
||||
$qry = $this->db->query($sql,[$orderHeaderID]);
|
||||
if(!$qry) {
|
||||
$this->db->trans_rollback();
|
||||
$this->log("Error clean one_etl.danone " . $this->db->error()["message"]);
|
||||
return;
|
||||
}
|
||||
$sql = "delete from one_etl.danone_detail where T_OrderHeaderID = ?";
|
||||
$qry = $this->db->query($sql,[$orderHeaderID]);
|
||||
if(!$qry) {
|
||||
$this->db->trans_rollback();
|
||||
$this->log("Error clean one_etl.danone_detail" . $this->db->error()["message"]);
|
||||
return;
|
||||
}
|
||||
$sql = "delete from one_etl.danone_json where T_OrderHeaderID = ?";
|
||||
|
||||
$qry = $this->db->query($sql,[$orderHeaderID]);
|
||||
if(!$qry) {
|
||||
$this->db->trans_rollback();
|
||||
$this->log("Error clean one_etl.danone_json" . $this->db->error()["message"]);
|
||||
return;
|
||||
}
|
||||
$danoneID = 0;
|
||||
$this->log("\tProcessing : one_etl.danone_detail ");
|
||||
foreach ($rows as $r) {
|
||||
if ($isFirst) {
|
||||
$arr = [
|
||||
"T_OrderHeaderID" => $r["T_OrderHeaderID"],
|
||||
"M_BranchName" => $r["M_BranchName"],
|
||||
"T_OrderHeaderLabNumber" => $r["T_OrderHeaderLabNumber"],
|
||||
"T_OrderHeaderLabNumberExt" => $r["T_OrderHeaderLabNumberExt"],
|
||||
"T_OrderHeaderDate" => $r["T_OrderHeaderDate"],
|
||||
"NAMA" => $r["NAMA"],
|
||||
"shareID" => $r["shareID"],
|
||||
"M_PatientNIK" => $r["M_PatientNIK"],
|
||||
"M_PatientIDNumber" => $r["M_PatientIDNumber"],
|
||||
"JENISKELAMIN" => $r["JENISKELAMIN"],
|
||||
"M_PatientDOB" => $r["M_PatientDOB"],
|
||||
"T_OrderHeaderM_PatientAge" => $r["T_OrderHeaderM_PatientAge"],
|
||||
"M_PatientJabatan" => $r["M_PatientJabatan"],
|
||||
"M_PatientKedudukan" => $r["M_PatientKedudukan"],
|
||||
"M_PatientPJ" => $r["M_PatientPJ"],
|
||||
"M_PatientJob" => $r["M_PatientJob"],
|
||||
"M_PatientLocation" => $r["M_PatientLocation"],
|
||||
"M_CompanyName" => $r["M_CompanyName"],
|
||||
"M_MouName" => $r["M_MouName"],
|
||||
"M_CompanyID" => $r["M_CompanyID"],
|
||||
"M_MouID" => $r["M_MouID"]
|
||||
|
||||
];
|
||||
$qry = $this->db->insert("one_etl.danone", $arr);
|
||||
if (!$qry) {
|
||||
$this->log("Error insert one_etl.danone , " . $this->db->error()["message"]);
|
||||
$this->db->trans_rollback();
|
||||
return;
|
||||
}
|
||||
$danoneID = $this->db->insert_id();
|
||||
$isFirst = false;
|
||||
}
|
||||
$arr = [
|
||||
"danoneDetailDanoneID" => $danoneID,
|
||||
"T_OrderHeaderID" => $r["T_OrderHeaderID"],
|
||||
"T_TestSasCode" => $r["T_TestSasCode"],
|
||||
"T_TestName" => $r["T_TestName"],
|
||||
"Result" => $r["Mcu_ResumeDetailsResult"]
|
||||
];
|
||||
$qry = $this->db->insert("one_etl.danone_detail", $arr);
|
||||
if (!$qry) {
|
||||
$this->log("Error insert one_etl.danone_detail , " . $this->db->error()["message"]);
|
||||
$this->db->trans_rollback();
|
||||
return;
|
||||
}
|
||||
}
|
||||
if ($danoneID > 0) {
|
||||
$this->json($orderHeaderID, $danoneID);
|
||||
}
|
||||
$this->db->trans_commit();
|
||||
//get from json
|
||||
$this->log("Done Processing T_OrderHeaderID : " . $orderHeaderID);
|
||||
$this->log("Wait 3 second");
|
||||
sleep(3);
|
||||
}
|
||||
function demo()
|
||||
{
|
||||
$sql = "select count(distinct nik) total from stage_01";
|
||||
$qry = $this->db->query($sql);
|
||||
$total = 0;
|
||||
if ($qry) {
|
||||
$total = $qry->result_array()[0]["total"];
|
||||
}
|
||||
echo $total;
|
||||
}
|
||||
}
|
||||
6
application/controllers/etl/Fisik.http
Normal file
6
application/controllers/etl/Fisik.http
Normal file
@@ -0,0 +1,6 @@
|
||||
GET http://riau/one-api/etl/fisik/generate/600119
|
||||
|
||||
|
||||
### generate bmi
|
||||
GET http://riau/one-api/etl/fisik/generate_bmi/1/601696
|
||||
|
||||
1671
application/controllers/etl/Fisik.php
Normal file
1671
application/controllers/etl/Fisik.php
Normal file
File diff suppressed because it is too large
Load Diff
73
application/controllers/etl/Getorder.php
Normal file
73
application/controllers/etl/Getorder.php
Normal file
@@ -0,0 +1,73 @@
|
||||
<?php
|
||||
class Getorder extends MY_Controller
|
||||
{
|
||||
public function __construct()
|
||||
{
|
||||
parent::__construct();
|
||||
}
|
||||
|
||||
public function index()
|
||||
{
|
||||
echo "GET RESULT";
|
||||
}
|
||||
|
||||
public function getdata()
|
||||
{
|
||||
try {
|
||||
$prm = $this->sys_input;
|
||||
$limit = 10;
|
||||
if (isset($prm['limit'])) {
|
||||
$limit = trim($prm["limit"]);
|
||||
$limit = $prm['limit'];
|
||||
}
|
||||
//tidak ada checking payment
|
||||
$sql = "SELECT
|
||||
T_OrderHeaderID,
|
||||
Mgm_McuID,
|
||||
T_OrderHeaderLabNumber as no_reg,
|
||||
T_OrderHeaderDate,
|
||||
concat(M_TitleName, ' ',
|
||||
ifnull(M_PatientPrefix,' '),
|
||||
M_PatientName,
|
||||
ifnull(M_PatientSuffix,'')
|
||||
) as nama_pasien,
|
||||
'' as test,
|
||||
M_PatientIdentifierValue M_PatientIDNumber,
|
||||
M_PatientHP,
|
||||
IFNULL(Mcu_OrderStatus,'-') as Mcu_OrderStatus,
|
||||
Mcu_OrderRetry
|
||||
from t_orderheader
|
||||
join t_orderdetail
|
||||
ON T_OrderHeaderID = T_OrderDetailT_OrderHeaderID
|
||||
AND T_OrderDetailIsActive = 'Y'
|
||||
AND T_OrderHeaderIsActive = 'Y'
|
||||
join m_patient
|
||||
ON T_OrderHeaderM_PatientID = M_PatientID
|
||||
join m_title
|
||||
on M_PatientM_TitleID = M_TitleID
|
||||
join mcu_order
|
||||
ON T_OrderHeaderID = Mcu_OrderT_OrderHeaderID
|
||||
and (Mcu_OrderStatus = 'C' OR Mcu_OrderStatus = 'R' OR Mcu_OrderStatus = 'E') AND Mcu_OrderRetry <= 5
|
||||
join mgm_mcu
|
||||
ON Mgm_McuID = Mcu_OrderMgm_McuID AND Mgm_McuIsActive = 'Y'
|
||||
group by T_OrderHeaderID
|
||||
limit $limit";
|
||||
|
||||
$query = $this->db->query($sql);
|
||||
$last_qry = $this->db->last_query();
|
||||
if (!$query) {
|
||||
$error = array(
|
||||
"message" => $this->db->error()["message"],
|
||||
"sql" => $last_qry
|
||||
);
|
||||
$this->sys_error_db($error);
|
||||
exit;
|
||||
}
|
||||
$rows = $query->result_array();
|
||||
$this->sys_ok($rows);
|
||||
} catch (Exception $exc) {
|
||||
$message = $exc->getMessage();
|
||||
$this->sys_error($message);
|
||||
}
|
||||
}
|
||||
}
|
||||
507
application/controllers/etl/Kelainanlab.php
Normal file
507
application/controllers/etl/Kelainanlab.php
Normal file
@@ -0,0 +1,507 @@
|
||||
<?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);
|
||||
}
|
||||
}
|
||||
}
|
||||
934
application/controllers/etl/Mgmmcu.php
Normal file
934
application/controllers/etl/Mgmmcu.php
Normal file
@@ -0,0 +1,934 @@
|
||||
<?php
|
||||
class Mgmmcu extends MY_Controller
|
||||
{
|
||||
var $base_url;
|
||||
function __construct()
|
||||
{
|
||||
parent::__construct();
|
||||
$this->base_url = "/one-api/etl/mgmmcu";
|
||||
$this->db->query("use one_etl");
|
||||
}
|
||||
|
||||
//me non active kan yang existing
|
||||
function non_active_exist($orderHeaderID, $mgmMcuID, $type)
|
||||
{
|
||||
$sql = "UPDATE mgm_header SET Mgm_HeaderIsActive = 'N' WHERE Mgm_HeaderType = ? AND Mgm_HeaderMgm_McuID = ? AND Mgm_HeaderT_OrderHeaderID = ?";
|
||||
$qry = $this->db->query($sql, [$type, $mgmMcuID, $orderHeaderID]);
|
||||
//echo $this->db->last_query();
|
||||
$sql = "UPDATE mgm_detail
|
||||
JOIN mgm_header ON Mgm_DetailMgm_HeaderID = Mgm_HeaderID AND
|
||||
Mgm_HeaderMgm_McuID = ? AND
|
||||
Mgm_HeaderT_OrderHeaderID = ? AND
|
||||
Mgm_HeaderIsActive = 'N'
|
||||
SET Mgm_DetailIsActive = 'N'
|
||||
WHERE
|
||||
Mgm_DetailIsActive = 'Y'";
|
||||
$qry = $this->db->query($sql, [$mgmMcuID, $orderHeaderID]);
|
||||
//echo $this->db->last_query();
|
||||
if (!$qry) {
|
||||
echo json_encode([
|
||||
"status" => "ERR",
|
||||
"message" => "Error is active N | " . $this->db->error()["message"]
|
||||
]);
|
||||
exit;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
function lab_kelainan_xold($orderHeaderID, $mgmMcuID)
|
||||
{
|
||||
$this->non_active_exist($orderHeaderID, $mgmMcuID, 'L');
|
||||
$sql = "select
|
||||
T_OrderHeaderID,T_OrderHeaderLabNumber,
|
||||
T_TestName, T_OrderDetailResult, T_OrderDetailNat_MethodeID,
|
||||
T_OrderDetailNat_MethodeID, T_OrderDetailNat_MethodeName,
|
||||
T_OrderDetailMinValue, T_OrderDetailMaxValue, T_OrderDetailMinValueInclusive,
|
||||
T_OrderDetailMaxValueInclusive,
|
||||
Mcu_SummaryLabValue,
|
||||
Mcu_SummaryLabNat_MethodeID,
|
||||
Mcu_SummaryLabWithMethode,
|
||||
Mcu_SummaryLabType,
|
||||
Mcu_SummaryLabIsNormalValue,
|
||||
Mcu_KelainanID, Mcu_KelainanName, Mcu_KelainanClasification,
|
||||
Nat_TestCode,
|
||||
mcu_kelainangroup.*
|
||||
from t_orderdetail
|
||||
join t_orderheader on T_OrderHeaderID = ?
|
||||
and T_OrderHeaderID = T_OrderDetailT_OrderHeaderID
|
||||
and T_OrderDetailIsActive = 'Y'
|
||||
join t_test
|
||||
on T_OrderDetailT_TestID = T_TestID
|
||||
join nat_test ON T_TestNat_TestID = Nat_TestID
|
||||
join mcu_summarylab on T_TestNat_TestID = Mcu_SummaryLabNat_TestID AND Mcu_SummaryLabIsActive = 'Y'
|
||||
join mcu_kelainan on Mcu_SummaryLabMcu_KelainanID = Mcu_KelainanID
|
||||
join mcu_kelainangroup on Mcu_KelainanMcu_KelainanGroupID = Mcu_KelainanGroupID";
|
||||
|
||||
$qry = $this->db->query($sql, [$orderHeaderID]);
|
||||
//echo $this->db->last_query();
|
||||
if (!$qry) {
|
||||
echo json_encode([
|
||||
"status" => "ERR",
|
||||
"message" => "Error get order | " . $this->db->error()["message"]
|
||||
]);
|
||||
exit;
|
||||
}
|
||||
$rows = $qry->result_array();
|
||||
$results = [];
|
||||
foreach ($rows as $r) {
|
||||
//loop dan cari kelainan
|
||||
//Nat_TestID, WithMethode, terhadap NormalValue atau AdHoc Value
|
||||
//rule penentuan
|
||||
// print_r($r);
|
||||
$sql = "SELECT COUNT(*) as cnt, Mgm_HeaderID
|
||||
FROM mgm_header
|
||||
WHERE
|
||||
Mgm_HeaderMgm_McuID = ? AND
|
||||
Mgm_HeaderT_OrderHeaderID = ? AND
|
||||
Mgm_HeaderNat_TestCode = ? AND
|
||||
Mgm_HeaderType = 'L' AND
|
||||
Mgm_HeaderIsActive = 'Y'";
|
||||
$query = $this->db->query($sql, array($mgmMcuID, $orderHeaderID, $r['Nat_TestCode']));
|
||||
//echo $this->db->last_query();
|
||||
$row_header_exist = $query->row_array();
|
||||
$header_id = 0;
|
||||
|
||||
if ($row_header_exist['cnt'] == 0) {
|
||||
|
||||
$data_header = array(
|
||||
'Mgm_HeaderMgm_McuID' => $mgmMcuID,
|
||||
'Mgm_HeaderT_OrderHeaderID' => $orderHeaderID,
|
||||
'Mgm_HeaderNat_TestCode' => $r['Nat_TestCode'],
|
||||
'Mgm_HeaderType' => 'L',
|
||||
'Mgm_HeaderCreated' => date("Y-m-d H:i:s", time())
|
||||
);
|
||||
|
||||
$this->db->insert('mgm_header', $data_header);
|
||||
//echo $this->db->last_query();
|
||||
$header_id = $this->db->insert_id();
|
||||
}
|
||||
|
||||
$result_value = $r['T_OrderDetailResult'];
|
||||
|
||||
$value_comparison = 0;
|
||||
//echo $r['Mcu_SummaryLabIsNormalValue'];
|
||||
$kelainan = [];
|
||||
$notavailable = [];
|
||||
if (trim($result_value) == 'NA') {
|
||||
$notavailable = $r;
|
||||
} elseif ($r['Mcu_SummaryLabIsNormalValue'] == 'Y') {
|
||||
if ($r['Mcu_SummaryLabType'] == '<' || $r['Mcu_SummaryLabType'] == '<=') {
|
||||
$value_comparison = $r['T_OrderDetailMinValue'];
|
||||
}
|
||||
if ($r['Mcu_SummaryLabType'] == '>' || $r['Mcu_SummaryLabType'] == '>=') {
|
||||
$value_comparison = $r['T_OrderDetailMaxValue'];
|
||||
}
|
||||
//echo "Y";
|
||||
if ($r['Mcu_SummaryLabWithMethode'] == 'N' && $this->dynamic_comparison($result_value, $r['Mcu_SummaryLabType'], $value_comparison)) {
|
||||
//echo $r['T_TestName']." : ".$r['Mcu_KelainanName'].", ";
|
||||
$kelainan = $r;
|
||||
$results[] = array('test' => $r['T_TestName'], 'nat_test' => $r['Nat_TestCode'], 'kelainan' => $r['Mcu_KelainanName']);
|
||||
}
|
||||
} else {
|
||||
$value_comparison = $r['Mcu_SummaryLabValue'];
|
||||
if ($r['Mcu_SummaryLabType'] == '!=' || $r['Mcu_SummaryLabType'] == '==') {
|
||||
if ($this->dynamic_comparison($result_value, $r['Mcu_SummaryLabType'], $value_comparison)) {
|
||||
//echo $r['T_TestName']." : ".$r['Mcu_KelainanName'].", ";
|
||||
$kelainan = $r;
|
||||
$results[] = array('test' => $r['T_TestName'], 'nat_test' => $r['Nat_TestCode'], 'kelainan' => $r['Mcu_KelainanName']);
|
||||
}
|
||||
} else {
|
||||
if (is_numeric($result_value) && $this->dynamic_comparison($result_value, $r['Mcu_SummaryLabType'], $value_comparison)) {
|
||||
//echo $r['T_TestName']." : ".$r['Mcu_KelainanName'].", ";
|
||||
$kelainan = $r;
|
||||
$results[] = array('test' => $r['T_TestName'], 'nat_test' => $r['Nat_TestCode'], 'kelainan' => $r['Mcu_KelainanName']);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$kelainan_id = 0;
|
||||
$group_kelainan_id = 0;
|
||||
if (count($notavailable) > 0) {
|
||||
$kelainan_id = -1;
|
||||
} elseif (count($kelainan) > 0) {
|
||||
$kelainan_id = $r['Mcu_KelainanID'];
|
||||
$group_kelainan_id = $r['Mcu_KelainanGroupID'];
|
||||
}
|
||||
|
||||
if ($kelainan_id > 0) {
|
||||
$sql = "UPDATE mgm_header SET Mgm_HeaderIsNormal = 'N' WHERE Mgm_HeaderID = ?";
|
||||
$query = $this->db->query($sql, array($header_id));
|
||||
|
||||
$sql = "SELECT COUNT(*) as cnt, Mgm_DetailID
|
||||
FROM mgm_detail
|
||||
WHERE
|
||||
Mgm_DetailMgm_HeaderID = ? AND
|
||||
Mgm_DetailMcu_KelainanID = ? AND
|
||||
Mgm_DetailIsActive = 'Y'";
|
||||
$query = $this->db->query($sql, array($header_id, $kelainan_id));
|
||||
//echo $this->db->last_query();
|
||||
$row_exist = $query->row_array();
|
||||
if ($row_exist['cnt'] == 0) {
|
||||
$data = array(
|
||||
'Mgm_DetailMgm_HeaderID' => $header_id,
|
||||
'Mgm_DetailMcu_KelainanID' => $kelainan_id,
|
||||
'Mgm_DetailMcu_KelainanGroupID' => $group_kelainan_id,
|
||||
'Mgm_DetailCreated' => date("Y-m-d H:i:s", time())
|
||||
);
|
||||
|
||||
$this->db->insert('mgm_detail', $data);
|
||||
//echo $this->db->last_query();
|
||||
} else {
|
||||
$data = array(
|
||||
'Mgm_DetailMgm_HeaderID' => $header_id,
|
||||
'Mgm_DetailMcu_KelainanID' => $kelainan_id,
|
||||
'Mgm_DetailMcu_KelainanGroupID' => $group_kelainan_id,
|
||||
'Mgm_DetailIsActive' => 'Y',
|
||||
'Mgm_DetailLastUpdated' => date("Y-m-d H:i:s", time())
|
||||
);
|
||||
$this->db->where('Mgm_DetailID', $row_exist['Mgm_DetailID']);
|
||||
$this->db->update('mgm_detail', $data);
|
||||
}
|
||||
} else {
|
||||
if ($kelainan_id == -1) {
|
||||
$sql = "UPDATE mgm_header SET Mgm_HeaderIsNormal = 'X' WHERE Mgm_HeaderID = ?";
|
||||
$query = $this->db->query($sql, array($header_id));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$sql = "UPDATE mcu_order SET Mcu_OrderStatus = 'D' WHERE Mcu_OrderMgm_McuID = ? AND Mcu_OrderT_OrderHeaderID = ?";
|
||||
$qry = $this->db->query($sql, [$mgmMcuID, $orderHeaderID]);
|
||||
|
||||
//echo json_encode($results);
|
||||
return $results;
|
||||
}
|
||||
|
||||
|
||||
function lab_kelainan($orderHeaderID, $mgmMcuID)
|
||||
{
|
||||
$this->non_active_exist($orderHeaderID, $mgmMcuID, 'L');
|
||||
$sql = "select T_OrderDetailID,
|
||||
T_OrderHeaderID,T_OrderHeaderLabNumber,
|
||||
T_TestName, T_OrderDetailResult, T_OrderDetailNat_MethodeID,
|
||||
T_OrderDetailNat_MethodeID, T_OrderDetailNat_MethodeName,
|
||||
T_OrderDetailMinValue, T_OrderDetailMaxValue, T_OrderDetailMinValueInclusive,
|
||||
T_OrderDetailMaxValueInclusive,
|
||||
Mcu_SummaryLabValue,
|
||||
Mcu_SummaryLabNat_MethodeID,
|
||||
Mcu_SummaryLabWithMethode,
|
||||
Mcu_SummaryLabType,
|
||||
Mcu_SummaryLabIsNormalValue,
|
||||
Mcu_KelainanID, Mcu_KelainanName, Mcu_KelainanClasification,
|
||||
Nat_TestCode,
|
||||
mcu_kelainangroup.*
|
||||
from t_orderdetail
|
||||
join t_orderheader on T_OrderHeaderID = ?
|
||||
and T_OrderHeaderID = T_OrderDetailT_OrderHeaderID
|
||||
and T_OrderDetailIsActive = 'Y'
|
||||
join t_test
|
||||
on T_OrderDetailT_TestID = T_TestID
|
||||
join nat_test ON T_TestNat_TestID = Nat_TestID
|
||||
join mcu_summarylab on T_TestNat_TestID = Mcu_SummaryLabNat_TestID AND Mcu_SummaryLabIsActive = 'Y'
|
||||
join mcu_kelainan on Mcu_SummaryLabMcu_KelainanID = Mcu_KelainanID
|
||||
join mcu_kelainangroup on Mcu_KelainanMcu_KelainanGroupID = Mcu_KelainanGroupID";
|
||||
|
||||
$qry = $this->db->query($sql, [$orderHeaderID]);
|
||||
//echo $this->db->last_query();
|
||||
if (!$qry) {
|
||||
echo json_encode([
|
||||
"status" => "ERR",
|
||||
"message" => "Error get order | " . $this->db->error()["message"]
|
||||
]);
|
||||
exit;
|
||||
}
|
||||
$rows = $qry->result_array();
|
||||
$results = [];
|
||||
foreach ($rows as $r) {
|
||||
//loop dan cari kelainan
|
||||
//Nat_TestID, WithMethode, terhadap NormalValue atau AdHoc Value
|
||||
//rule penentuan
|
||||
// print_r($r);
|
||||
$sql = "SELECT COUNT(*) as cnt, Mgm_HeaderID
|
||||
FROM mgm_header
|
||||
WHERE
|
||||
Mgm_HeaderMgm_McuID = ? AND
|
||||
Mgm_HeaderT_OrderHeaderID = ? AND
|
||||
Mgm_HeaderNat_TestCode = ? AND
|
||||
Mgm_HeaderType = 'L' AND
|
||||
Mgm_HeaderIsActive = 'Y'";
|
||||
$query = $this->db->query($sql, array($mgmMcuID, $orderHeaderID, $r['Nat_TestCode']));
|
||||
//echo $this->db->last_query();
|
||||
$row_header_exist = $query->row_array();
|
||||
$header_id = 0;
|
||||
|
||||
if ($row_header_exist['cnt'] == 0) {
|
||||
|
||||
$data_header = array(
|
||||
'Mgm_HeaderMgm_McuID' => $mgmMcuID,
|
||||
'Mgm_HeaderT_OrderHeaderID' => $orderHeaderID,
|
||||
'Mgm_HeaderNat_TestCode' => $r['Nat_TestCode'],
|
||||
'Mgm_HeaderType' => 'L',
|
||||
'Mgm_HeaderCreated' => date("Y-m-d H:i:s", time())
|
||||
);
|
||||
|
||||
$this->db->insert('mgm_header', $data_header);
|
||||
//echo $this->db->last_query();
|
||||
$header_id = $this->db->insert_id();
|
||||
|
||||
}
|
||||
|
||||
|
||||
//jika belum disampling
|
||||
//$isnormal = 'X';
|
||||
//jika tidak ada kelainan dan sudah disampling
|
||||
$isnormal = 'Y';
|
||||
|
||||
$sql = "SELECT Mcu_KelainanMcu_KelainanGroupID as xgroup_id, Mcu_KelainanID as xid
|
||||
FROM t_kelainan_lab
|
||||
JOIN mcu_summarylab ON T_KelainanLabMcu_SummaryLabID = Mcu_SummaryLabID
|
||||
JOIN mcu_kelainan ON Mcu_summaryLabMcu_KelainanID = Mcu_KelainanID
|
||||
WHERE
|
||||
T_KelainanLabT_OrderDetailID = {$r['T_OrderDetailID']} AND
|
||||
T_KelainanLabIsActive = 'Y'";
|
||||
$query = $this->db->query($sql);
|
||||
if(!$query){
|
||||
echo "Gagal query ambil t_kelainan_lab";
|
||||
}
|
||||
|
||||
$kelainans = $query->result_array();
|
||||
|
||||
//jika ada kelainan dan sudah disampling
|
||||
if(count($kelainans) > 0){
|
||||
$isnormal = 'N';
|
||||
$sql = "UPDATE mgm_header SET Mgm_HeaderIsNormal = '{$isnormal}' WHERE Mgm_HeaderID = ?";
|
||||
$query = $this->db->query($sql, array($header_id));
|
||||
|
||||
foreach ($kelainans as $key => $value) {
|
||||
$group_kelainan_id = $value['xgroup_id'];
|
||||
$kelainan_id = $value['xid'];
|
||||
//insert ke detail jika ada kelainan
|
||||
$sql = "SELECT COUNT(*) as cnt, Mgm_DetailID
|
||||
FROM mgm_detail
|
||||
WHERE
|
||||
Mgm_DetailMgm_HeaderID = ? AND
|
||||
Mgm_DetailMcu_KelainanID = ? AND
|
||||
Mgm_DetailIsActive = 'Y'";
|
||||
$query = $this->db->query($sql, array($header_id, $kelainan_id));
|
||||
//echo $this->db->last_query();
|
||||
$row_exist = $query->row_array();
|
||||
if ($row_exist['cnt'] == 0) {
|
||||
$data = array(
|
||||
'Mgm_DetailMgm_HeaderID' => $header_id,
|
||||
'Mgm_DetailMcu_KelainanID' => $kelainan_id,
|
||||
'Mgm_DetailMcu_KelainanGroupID' => $group_kelainan_id,
|
||||
'Mgm_DetailCreated' => date("Y-m-d H:i:s", time())
|
||||
);
|
||||
|
||||
$this->db->insert('mgm_detail', $data);
|
||||
//echo $this->db->last_query();
|
||||
} else {
|
||||
$data = array(
|
||||
'Mgm_DetailMgm_HeaderID' => $header_id,
|
||||
'Mgm_DetailMcu_KelainanID' => $kelainan_id,
|
||||
'Mgm_DetailMcu_KelainanGroupID' => $group_kelainan_id,
|
||||
'Mgm_DetailIsActive' => 'Y',
|
||||
'Mgm_DetailLastUpdated' => date("Y-m-d H:i:s", time())
|
||||
);
|
||||
$this->db->where('Mgm_DetailID', $row_exist['Mgm_DetailID']);
|
||||
$this->db->update('mgm_detail', $data);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
$sql = "UPDATE mcu_order SET Mcu_OrderStatus = 'D' WHERE Mcu_OrderMgm_McuID = ? AND Mcu_OrderT_OrderHeaderID = ?";
|
||||
$qry = $this->db->query($sql, [$mgmMcuID, $orderHeaderID]);
|
||||
|
||||
//echo json_encode($results);
|
||||
return $results;
|
||||
}
|
||||
|
||||
function nonlab_kelainan($orderHeaderID, $mgmMcuID)
|
||||
{
|
||||
$this->non_active_exist($orderHeaderID, $mgmMcuID, 'NL');
|
||||
|
||||
|
||||
$sql = "SELECT Nat_TestID,
|
||||
Nat_TestCode,
|
||||
T_TestName,
|
||||
IFNULL(So_ResultEntryID,0) as resultentry_id,
|
||||
IFNULL(T_SamplingSoID,0) as sampling_id,
|
||||
So_ResultEntryT_OrderHeaderID as orderheader_id
|
||||
FROM t_orderdetail
|
||||
JOIN t_test ON T_TestID = T_OrderDetailT_TestID
|
||||
JOIN group_resultdetail ON Group_ResultDetailT_TestID = T_TestID
|
||||
JOIN group_result ON Group_ResultDetailGroup_ResultID = Group_ResultID AND Group_ResultResumeMcu = 'NONLAB'
|
||||
JOIN nat_test ON T_TestNat_TestID = Nat_TestID
|
||||
LEFT JOIN so_resultentry ON SO_ResultEntryT_OrderDetailID = T_OrderDetailID AND So_ResultEntryIsActive = 'Y'
|
||||
LEFT JOIN t_samplingso ON T_SamplingSoT_OrderHeaderID = So_ResultEntryT_OrderHeaderID AND T_SamplingSoT_TestID = T_TestID AND
|
||||
T_SamplingSoFlag = 'D'
|
||||
|
||||
WHERE
|
||||
T_OrderDetailT_OrderHeaderID = ? AND T_OrderDetailIsActive = 'Y'
|
||||
GROUP BY So_ResultEntryID";
|
||||
|
||||
$query = $this->db->query($sql, array($orderHeaderID));
|
||||
|
||||
if (!$query) {
|
||||
echo json_encode(
|
||||
[
|
||||
"status" => "ERR",
|
||||
"messge" => $this->db->error(),
|
||||
"sql" => $this->db->last_query()
|
||||
]
|
||||
);
|
||||
}
|
||||
// echo $this->db->last_query();
|
||||
$datas = $query->result_array();
|
||||
//print_r($datas);
|
||||
$header_id = 0;
|
||||
foreach ($datas as $key => $value) {
|
||||
$sql = "SELECT COUNT(*) as cnt, Mgm_HeaderID
|
||||
FROM mgm_header
|
||||
WHERE
|
||||
Mgm_HeaderT_OrderHeaderID = ? AND
|
||||
Mgm_HeaderMgm_McuID = ? AND
|
||||
Mgm_HeaderNat_TestCode = ? AND
|
||||
Mgm_HeaderIsActive = 'Y'";
|
||||
$query = $this->db->query($sql, array($orderHeaderID, $mgmMcuID, $value['Nat_TestCode']));
|
||||
$exist_data = $query->row_array();
|
||||
//print_r($exist_data);
|
||||
if ($exist_data['cnt'] == 0) {
|
||||
$data_header = array(
|
||||
'Mgm_HeaderMgm_McuID' => $mgmMcuID,
|
||||
'Mgm_HeaderT_OrderHeaderID' => $orderHeaderID,
|
||||
'Mgm_HeaderNat_TestCode' => $value['Nat_TestCode'],
|
||||
'Mgm_HeaderType' => 'NL',
|
||||
'Mgm_HeaderCreated' => date("Y-m-d H:i:s", time())
|
||||
);
|
||||
|
||||
$this->db->insert('mgm_header', $data_header);
|
||||
// echo $this->db->last_query();
|
||||
$header_id = $this->db->insert_id();
|
||||
} else {
|
||||
$header_id = $exist_data['Mgm_HeaderID'];
|
||||
}
|
||||
|
||||
$isnormal = "Y";
|
||||
if(intval($value['resultentry_id']) == 0){
|
||||
$isnormal = "X";
|
||||
}
|
||||
|
||||
$sql = "SELECT Mcu_KelainanMcu_KelainanGroupID as xgroup_id, Mcu_KelainanID as xid
|
||||
FROM t_kelainan_nonlab
|
||||
JOIN mcu_summarynonlab ON Mcu_SummaryNonlabNat_TestID = T_KelainanNonLabNat_TestID
|
||||
JOIN mcu_kelainan ON Mcu_SummaryNonlabMcu_KelainanID = Mcu_KelainanID
|
||||
WHERE
|
||||
T_KelainanNonLabSo_ResultEntryID = {$value['resultentry_id']} AND
|
||||
T_KelainanNonLabIsActive = 'Y'";
|
||||
// echo $sql;
|
||||
$query = $this->db->query($sql);
|
||||
if(!$query){
|
||||
echo "Gagal query ambil t_kelainan_nonlab";
|
||||
}
|
||||
|
||||
$kelainans = $query->result_array();
|
||||
if(count($kelainans) > 0){
|
||||
$isnormal = "N";
|
||||
foreach ($kelainans as $k => $v) {
|
||||
$group_kelainan_id = $v['xgroup_id'];
|
||||
$kelainan_id = $v['xid'];
|
||||
|
||||
$sql = "SELECT COUNT(*) as cnt, Mgm_DetailID
|
||||
FROM mgm_detail
|
||||
WHERE
|
||||
Mgm_DetailMgm_HeaderID = ? AND
|
||||
Mgm_DetailMcu_KelainanID = ? AND
|
||||
Mgm_DetailIsActive = 'Y'";
|
||||
$query = $this->db->query($sql, array($header_id, $kelainan_id));
|
||||
//echo $this->db->last_query();
|
||||
$row_exist = $query->row_array();
|
||||
if ($row_exist['cnt'] == 0) {
|
||||
$data = array(
|
||||
'Mgm_DetailMgm_HeaderID' => $header_id,
|
||||
'Mgm_DetailMcu_KelainanID' => $kelainan_id,
|
||||
'Mgm_DetailMcu_KelainanGroupID' => $group_kelainan_id,
|
||||
'Mgm_DetailCreated' => date("Y-m-d H:i:s", time())
|
||||
);
|
||||
|
||||
$this->db->insert('mgm_detail', $data);
|
||||
//echo $this->db->last_query();
|
||||
} else {
|
||||
$data = array(
|
||||
'Mgm_DetailMgm_HeaderID' => $header_id,
|
||||
'Mgm_DetailMcu_KelainanID' => $kelainan_id,
|
||||
'Mgm_DetailMcu_KelainanGroupID' => $group_kelainan_id,
|
||||
'Mgm_DetailIsActive' => 'Y',
|
||||
'Mgm_DetailLastUpdated' => date("Y-m-d H:i:s", time())
|
||||
);
|
||||
$this->db->where('Mgm_DetailID', $row_exist['Mgm_DetailID']);
|
||||
$this->db->update('mgm_detail', $data);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$sql = "UPDATE mgm_header SET Mgm_HeaderIsNormal = ? WHERE Mgm_HeaderID = ?";
|
||||
$query = $this->db->query($sql, array($isnormal,$header_id));
|
||||
}
|
||||
|
||||
|
||||
$sql = "UPDATE mcu_order SET Mcu_OrderStatus = 'F' WHERE Mcu_OrderMgm_McuID = ? AND Mcu_OrderT_OrderHeaderID = ?";
|
||||
$qry = $this->db->query($sql, [$mgmMcuID, $orderHeaderID]);
|
||||
|
||||
//echo json_encode($datas);
|
||||
return $datas;
|
||||
}
|
||||
|
||||
function fisik_kelainan($orderHeaderID, $mgmMcuID)
|
||||
{
|
||||
$this->non_active_exist($orderHeaderID, $mgmMcuID, 'F');
|
||||
|
||||
|
||||
$sql = "SELECT FisikTemplateID as Nat_TestID,
|
||||
FisikTemplateCode as Nat_TestCode,
|
||||
FisikTemplateTitle as T_TestName,
|
||||
IFNULL(So_ResultEntryID,0) as resultentry_id,
|
||||
IFNULL(T_SamplingSoID,0) as sampling_id,
|
||||
So_ResultEntryT_OrderHeaderID as orderheader_id,
|
||||
FisikTemplateMappingDetailFisikTemplateID as fisiktemplate_id
|
||||
FROM t_orderdetail
|
||||
JOIN t_orderheader ON T_OrderHeaderID = T_OrderDetailT_OrderHeaderID
|
||||
JOIN mgm_mcutemplate ON Mgm_McuTemplateMgm_McuID = T_OrderHeaderMgm_McuID
|
||||
JOIN fisik_template_mapping ON Mgm_McuTemplateFisikTemplateMappingID = FisikTemplateMappingID
|
||||
JOIN fisik_template_mapping_detail ON FisikTemplateMappingDetailFisikTemplateMappingID = FisikTemplateMappingID
|
||||
JOIN fisik_template ON FisikTemplateMappingDetailFisikTemplateID = FisikTemplateID AND FisikTemplateIsActive = 'Y' AND
|
||||
FisikTemplateType = 'Fisik'
|
||||
JOIN t_test ON T_TestID = T_OrderDetailT_TestID
|
||||
JOIN group_resultdetail ON Group_ResultDetailT_TestID = T_TestID
|
||||
JOIN group_result ON Group_ResultDetailGroup_ResultID = Group_ResultID AND Group_ResultResumeMcu = 'Fisik'
|
||||
JOIN nat_test ON T_TestNat_TestID = Nat_TestID
|
||||
LEFT JOIN t_samplingso ON T_SamplingSoT_OrderHeaderID = T_OrderDetailT_OrderHeaderID AND T_SamplingSoT_TestID = T_TestID AND
|
||||
T_SamplingSoFlag = 'D'
|
||||
LEFT JOIN so_resultentry ON SO_ResultEntryT_OrderDetailID = T_OrderDetailID AND So_ResultEntryIsActive = 'Y'
|
||||
WHERE
|
||||
T_OrderDetailT_OrderHeaderID = ? AND T_OrderDetailIsActive = 'Y'
|
||||
GROUP BY FisikTemplateMappingDetailFisikTemplateID
|
||||
ORDER BY FisikTemplateCode ";
|
||||
|
||||
$query = $this->db->query($sql, array($orderHeaderID));
|
||||
|
||||
if (!$query) {
|
||||
echo json_encode(
|
||||
[
|
||||
"status" => "ERR",
|
||||
"messge" => $this->db->error(),
|
||||
"sql" => $this->db->last_query()
|
||||
]
|
||||
);
|
||||
}
|
||||
// echo $this->db->last_query();
|
||||
$datas = $query->result_array();
|
||||
//print_r($datas);
|
||||
$header_id = 0;
|
||||
foreach ($datas as $key => $value) {
|
||||
$sql = "SELECT COUNT(*) as cnt, Mgm_HeaderID
|
||||
FROM mgm_header
|
||||
WHERE
|
||||
Mgm_HeaderT_OrderHeaderID = ? AND
|
||||
Mgm_HeaderMgm_McuID = ? AND
|
||||
Mgm_HeaderNat_TestCode = ? AND
|
||||
Mgm_HeaderIsActive = 'Y'";
|
||||
$query = $this->db->query($sql, array($orderHeaderID, $mgmMcuID, $value['Nat_TestCode']));
|
||||
$exist_data = $query->row_array();
|
||||
//print_r($exist_data);
|
||||
if ($exist_data['cnt'] == 0) {
|
||||
$data_header = array(
|
||||
'Mgm_HeaderMgm_McuID' => $mgmMcuID,
|
||||
'Mgm_HeaderT_OrderHeaderID' => $orderHeaderID,
|
||||
'Mgm_HeaderNat_TestCode' => $value['Nat_TestCode'],
|
||||
'Mgm_HeaderType' => 'F',
|
||||
'Mgm_HeaderCreated' => date("Y-m-d H:i:s", time())
|
||||
);
|
||||
|
||||
$this->db->insert('mgm_header', $data_header);
|
||||
// echo $this->db->last_query();
|
||||
$header_id = $this->db->insert_id();
|
||||
} else {
|
||||
$header_id = $exist_data['Mgm_HeaderID'];
|
||||
}
|
||||
|
||||
$isnormal = "Y";
|
||||
if(intval($value['resultentry_id']) == 0){
|
||||
$isnormal = "X";
|
||||
}
|
||||
|
||||
$sql = "SELECT Mcu_KelainanMcu_KelainanGroupID as xgroup_id, Mcu_KelainanID as xid
|
||||
FROM t_kelainan_fisik
|
||||
JOIN mcu_summaryfisik ON Mcu_SummaryFisikID = T_KelainanFiskMcu_SummaryFisikID
|
||||
JOIN mcu_kelainan ON Mcu_SummaryFisikMcu_KelainanID = Mcu_KelainanID
|
||||
JOIN fisik_template ON Mcu_SummaryFisikFisikTemplateID = FisikTemplateID AND FisikTemplateID = ?
|
||||
WHERE
|
||||
T_KelainanFiskSo_ResultEntryID = ? AND
|
||||
T_KelainanFiskIsActive = 'Y'";
|
||||
$query = $this->db->query($sql,array($value['fisiktemplate_id'], $value['resultentry_id']));
|
||||
if(!$query){
|
||||
echo "Gagal query ambil t_kelainan_fisik";
|
||||
}
|
||||
|
||||
$kelainans = $query->result_array();
|
||||
if(count($kelainans) > 0){
|
||||
$isnormal = "N";
|
||||
foreach ($kelainans as $k => $v) {
|
||||
$group_kelainan_id = $v['xgroup_id'];
|
||||
$kelainan_id = $v['xid'];
|
||||
|
||||
$sql = "SELECT COUNT(*) as cnt, Mgm_DetailID
|
||||
FROM mgm_detail
|
||||
WHERE
|
||||
Mgm_DetailMgm_HeaderID = ? AND
|
||||
Mgm_DetailMcu_KelainanID = ? AND
|
||||
Mgm_DetailIsActive = 'Y'";
|
||||
$query = $this->db->query($sql, array($header_id, $kelainan_id));
|
||||
//echo $this->db->last_query();
|
||||
$row_exist = $query->row_array();
|
||||
if ($row_exist['cnt'] == 0) {
|
||||
$data = array(
|
||||
'Mgm_DetailMgm_HeaderID' => $header_id,
|
||||
'Mgm_DetailMcu_KelainanID' => $kelainan_id,
|
||||
'Mgm_DetailMcu_KelainanGroupID' => $group_kelainan_id,
|
||||
'Mgm_DetailCreated' => date("Y-m-d H:i:s", time())
|
||||
);
|
||||
|
||||
$this->db->insert('mgm_detail', $data);
|
||||
//echo $this->db->last_query();
|
||||
} else {
|
||||
$data = array(
|
||||
'Mgm_DetailMgm_HeaderID' => $header_id,
|
||||
'Mgm_DetailMcu_KelainanID' => $kelainan_id,
|
||||
'Mgm_DetailMcu_KelainanGroupID' => $group_kelainan_id,
|
||||
'Mgm_DetailIsActive' => 'Y',
|
||||
'Mgm_DetailLastUpdated' => date("Y-m-d H:i:s", time())
|
||||
);
|
||||
$this->db->where('Mgm_DetailID', $row_exist['Mgm_DetailID']);
|
||||
$this->db->update('mgm_detail', $data);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$sql = "UPDATE mgm_header SET Mgm_HeaderIsNormal = ? WHERE Mgm_HeaderID = ?";
|
||||
$query = $this->db->query($sql, array($isnormal,$header_id));
|
||||
}
|
||||
|
||||
|
||||
$sql = "UPDATE mcu_order SET Mcu_OrderStatus = 'A' WHERE Mcu_OrderMgm_McuID = ? AND Mcu_OrderT_OrderHeaderID = ?";
|
||||
$qry = $this->db->query($sql, [$mgmMcuID, $orderHeaderID]);
|
||||
|
||||
//echo json_encode($datas);
|
||||
return $datas;
|
||||
}
|
||||
|
||||
function nonlab_kelainan_old_x($orderHeaderID, $mgmMcuID)
|
||||
{
|
||||
$this->non_active_exist($orderHeaderID, $mgmMcuID, 'NL');
|
||||
|
||||
|
||||
$sql = "SELECT Nat_TestID,
|
||||
Nat_TestCode,
|
||||
T_TestName,
|
||||
-- So_ResultEntryCategoryResultValue,
|
||||
IFNULL(Mcu_SummaryNonlabMcu_KelainanID,0) as Mcu_SummaryNonlabMcu_KelainanID,
|
||||
IFNULL(Mcu_KelainanGroupID,0) as Mcu_KelainanGroupID
|
||||
FROM so_resultentry_category_result
|
||||
JOIN so_resultentry ON So_ResultEntryCategoryResultSo_ResultEntryID = So_ResultEntryID AND
|
||||
So_ResultEntryT_OrderHeaderID = ?
|
||||
JOIN t_orderdetail ON T_OrderDetailID = SO_ResultENtryT_OrderDetailID AND T_OrderDetailIsActive = 'Y'
|
||||
JOIN t_test ON T_TestID = T_OrderDetailT_TestID
|
||||
JOIN nat_test ON T_TestNat_TestID = Nat_TestID
|
||||
JOIN mcu_summarynonlab ON Mcu_SummaryNonlabNat_TestID = Nat_TestID AND
|
||||
FIND_IN_SET(So_ResultEntryCategoryNonlabConclusionDetailID,Mcu_SummaryNonlabConclusionDetailIDs) <> 0
|
||||
LEFT JOIN mcu_kelainan ON Mcu_SummaryNonlabMcu_KelainanID = Mcu_KelainanID
|
||||
LEFT JOIN mcu_kelainangroup ON Mcu_KelainanMcu_KelainanGroupID = Mcu_KelainanGroupID
|
||||
WHERE
|
||||
So_ResultEntryCategoryResultIsActive = 'Y'
|
||||
GROUP BY So_ResultEntryCategoryResultID";
|
||||
|
||||
$query = $this->db->query($sql, array($orderHeaderID));
|
||||
|
||||
if (!$query) {
|
||||
echo json_encode(
|
||||
[
|
||||
"status" => "ERR",
|
||||
"messge" => $this->db->error(),
|
||||
"sql" => $this->db->last_query()
|
||||
]
|
||||
);
|
||||
}
|
||||
// echo $this->db->last_query();
|
||||
$datas = $query->result_array();
|
||||
print_r($datas);
|
||||
$header_id = 0;
|
||||
foreach ($datas as $key => $value) {
|
||||
$sql = "SELECT COUNT(*) as cnt, Mgm_HeaderID
|
||||
FROM mgm_header
|
||||
WHERE
|
||||
Mgm_HeaderT_OrderHeaderID = ? AND
|
||||
Mgm_HeaderMgm_McuID = ? AND
|
||||
Mgm_HeaderNat_TestCode = ? AND
|
||||
Mgm_HeaderIsActive = 'Y'";
|
||||
$query = $this->db->query($sql, array($orderHeaderID, $mgmMcuID, $value['Nat_TestCode']));
|
||||
$exist_data = $query->row_array();
|
||||
//print_r($exist_data);
|
||||
if ($exist_data['cnt'] == 0) {
|
||||
$data_header = array(
|
||||
'Mgm_HeaderMgm_McuID' => $mgmMcuID,
|
||||
'Mgm_HeaderT_OrderHeaderID' => $orderHeaderID,
|
||||
'Mgm_HeaderNat_TestCode' => $value['Nat_TestCode'],
|
||||
'Mgm_HeaderType' => 'NL',
|
||||
'Mgm_HeaderCreated' => date("Y-m-d H:i:s", time())
|
||||
);
|
||||
|
||||
$this->db->insert('mgm_header', $data_header);
|
||||
// echo $this->db->last_query();
|
||||
$header_id = $this->db->insert_id();
|
||||
} else {
|
||||
$header_id = $exist_data['Mgm_HeaderID'];
|
||||
}
|
||||
|
||||
$kelainan_id = $value['Mcu_SummaryNonlabMcu_KelainanID'];
|
||||
//echo $kelainan_id;
|
||||
if ($kelainan_id > 0) {
|
||||
$sql = "SELECT COUNT(*) as cnt, Mgm_DetailID
|
||||
FROM mgm_detail
|
||||
WHERE
|
||||
Mgm_DetailMgm_HeaderID = ? AND
|
||||
Mgm_DetailMcu_KelainanID = ? AND
|
||||
Mgm_DetailIsActive = 'Y'";
|
||||
$query = $this->db->query($sql, array($header_id, $kelainan_id));
|
||||
//echo $this->db->last_query();
|
||||
$row_exist = $query->row_array();
|
||||
//print_r($row_exist);
|
||||
if ($row_exist['cnt'] == 0) {
|
||||
$data = array(
|
||||
'Mgm_DetailMgm_HeaderID' => $header_id,
|
||||
'Mgm_DetailMcu_KelainanID' => $kelainan_id,
|
||||
'Mgm_DetailMcu_KelainanGroupID' => $value['Mcu_KelainanGroupID'],
|
||||
'Mgm_DetailCreated' => date("Y-m-d H:i:s", time())
|
||||
);
|
||||
|
||||
$this->db->insert('mgm_detail', $data);
|
||||
//echo $this->db->last_query();
|
||||
} else {
|
||||
$data = array(
|
||||
'Mgm_DetailMgm_HeaderID' => $header_id,
|
||||
'Mgm_DetailMcu_KelainanID' => $kelainan_id,
|
||||
'Mgm_DetailMcu_KelainanGroupID' => $value['Mcu_KelainanGroupID'],
|
||||
'Mgm_DetailIsActive' => 'Y',
|
||||
'Mgm_DetailLastUpdated' => date("Y-m-d H:i:s", time())
|
||||
);
|
||||
$this->db->where('Mgm_DetailID', $row_exist['Mgm_DetailID']);
|
||||
$this->db->update('mgm_detail', $data);
|
||||
}
|
||||
|
||||
$sql = "UPDATE mgm_header SET Mgm_HeaderIsNormal = 'N' WHERE Mgm_HeaderID = ?";
|
||||
$query = $this->db->query($sql, array($header_id));
|
||||
}
|
||||
}
|
||||
|
||||
$sql = "UPDATE mcu_order SET Mcu_OrderStatus = 'F' WHERE Mcu_OrderMgm_McuID = ? AND Mcu_OrderT_OrderHeaderID = ?";
|
||||
$qry = $this->db->query($sql, [$mgmMcuID, $orderHeaderID]);
|
||||
|
||||
//echo json_encode($datas);
|
||||
return $datas;
|
||||
}
|
||||
|
||||
function dynamic_comparison($varleft, $op, $varright)
|
||||
{
|
||||
|
||||
switch ($op) {
|
||||
case "=":
|
||||
return $varleft == $varright;
|
||||
case "!=":
|
||||
return $varleft != $varright;
|
||||
case ">=":
|
||||
return $varleft >= $varright;
|
||||
case "<=":
|
||||
return $varleft <= $varright;
|
||||
case ">":
|
||||
return $varleft > $varright;
|
||||
case "<":
|
||||
return $varleft < $varright;
|
||||
default:
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
function generate_kelainan_lab($Mgm_McuID, $limit)
|
||||
{
|
||||
$sql = "SELECT *
|
||||
FROM mcu_order
|
||||
WHERE
|
||||
Mcu_OrderStatus = 'C' AND
|
||||
Mcu_OrderMgm_McuID = ?
|
||||
LIMIT ?";
|
||||
$qry = $this->db->query($sql, [$Mgm_McuID, intval($limit)]);
|
||||
//echo $this->db->last_query();
|
||||
if (!$qry) {
|
||||
echo json_encode([
|
||||
"status" => "ERR",
|
||||
"message" => "Error proces mgm_mcu $Mgm_McuID | " . $this->db->error()["message"]
|
||||
]);
|
||||
exit;
|
||||
}
|
||||
|
||||
$rows = $qry->result_array();
|
||||
if (count($rows) == 0) {
|
||||
echo "No Pending Lab Order";
|
||||
}
|
||||
foreach ($rows as $key => $value) {
|
||||
$this->lab_kelainan($value['Mcu_OrderT_OrderHeaderID'], $Mgm_McuID);
|
||||
}
|
||||
echo "success lab";
|
||||
}
|
||||
|
||||
|
||||
function generate_kelainan_nonlab($Mgm_McuID, $limit)
|
||||
{
|
||||
$sql = "SELECT *
|
||||
FROM mcu_order
|
||||
WHERE
|
||||
Mcu_OrderStatus = 'D' AND
|
||||
Mcu_OrderMgm_McuID = ?
|
||||
LIMIT ?";
|
||||
$qry = $this->db->query($sql, [$Mgm_McuID, intval($limit)]);
|
||||
if (!$qry) {
|
||||
echo json_encode([
|
||||
"status" => "ERR",
|
||||
"message" => "Error proces mgm_mcu $Mgm_McuID | " . $this->db->error()["message"]
|
||||
]);
|
||||
exit;
|
||||
}
|
||||
|
||||
$rows = $qry->result_array();
|
||||
foreach ($rows as $key => $value) {
|
||||
$this->nonlab_kelainan($value['Mcu_OrderT_OrderHeaderID'], $Mgm_McuID);
|
||||
}
|
||||
echo "success non lab";
|
||||
}
|
||||
|
||||
|
||||
function generate_kelainan_fisik($Mgm_McuID, $limit)
|
||||
{
|
||||
$sql = "SELECT *
|
||||
FROM mcu_order
|
||||
WHERE
|
||||
Mcu_OrderStatus = 'D' AND
|
||||
Mcu_OrderMgm_McuID = ?
|
||||
LIMIT ?";
|
||||
$qry = $this->db->query($sql, [$Mgm_McuID, intval($limit)]);
|
||||
if (!$qry) {
|
||||
echo json_encode([
|
||||
"status" => "ERR",
|
||||
"message" => "Error proces mgm_mcu $Mgm_McuID | " . $this->db->error()["message"]
|
||||
]);
|
||||
exit;
|
||||
}
|
||||
|
||||
$rows = $qry->result_array();
|
||||
foreach ($rows as $key => $value) {
|
||||
$this->fisik_kelainan($value['Mcu_OrderT_OrderHeaderID'], $Mgm_McuID);
|
||||
}
|
||||
echo "success non lab";
|
||||
}
|
||||
|
||||
|
||||
function populate_order($mgmMouID)
|
||||
{
|
||||
// $sql = "select Mgm_McuStartDate,Mgm_McuEndDate
|
||||
// from mgm_mcu
|
||||
// where Mgm_McuID = ?";
|
||||
$sql = "
|
||||
select Mgm_McuID Mcu_OrderMgm_McuID,
|
||||
T_OrderHeaderID Mcu_OrderT_OrderHeaderID
|
||||
from mgm_mcu
|
||||
join t_orderheader on
|
||||
Mgm_McuID = ?
|
||||
and Mgm_McuIsActive = 'Y'
|
||||
and T_OrderHeaderMgm_McuID = Mgm_McuID
|
||||
and T_OrderHeaderDate >= Mgm_McuStartDate
|
||||
and T_OrderHeaderDate <= Mgm_McuEndDate
|
||||
and T_OrderHeaderIsActive = 'Y'
|
||||
and T_OrderHeaderID not in (
|
||||
select Mcu_OrderT_OrderHeaderID
|
||||
from mcu_order
|
||||
where Mcu_OrderMgm_McuID = ?
|
||||
)";
|
||||
$qry = $this->db->query($sql, [$mgmMouID, $mgmMouID]);
|
||||
if (!$qry) {
|
||||
echo json_encode([
|
||||
"status" => "ERR",
|
||||
"message" => "Error get mgm_mcu $mgmMouID | " . $this->db->error()["message"]
|
||||
]);
|
||||
exit;
|
||||
}
|
||||
$rows = $qry->result_array();
|
||||
if (count($rows) == 0) {
|
||||
echo json_encode([
|
||||
"status" => "OK", "message" => "No Pending Order",
|
||||
]);
|
||||
exit;
|
||||
}
|
||||
$this->db->trans_begin();
|
||||
$qry = $this->db->insert_batch("mcu_order", $rows);
|
||||
if (!$qry) {
|
||||
echo json_encode([
|
||||
"status" => "ERR",
|
||||
"message" => "Error batch insert | " . $this->db->error()["message"]
|
||||
]);
|
||||
$this->db->trans_rollback();
|
||||
exit;
|
||||
}
|
||||
$this->db->trans_commit();
|
||||
echo json_encode(["status" => "OK", "message" => count($rows) . " inserted. "]);
|
||||
}
|
||||
|
||||
// helper function
|
||||
// post
|
||||
// get
|
||||
// insert_or_update
|
||||
function post($service, $data)
|
||||
{
|
||||
$xbase_url = $this->base_url;
|
||||
$url = $xbase_url . "$service";
|
||||
$ch = curl_init($url);
|
||||
$payload = json_encode($data);
|
||||
curl_setopt($ch, CURLOPT_POSTFIELDS, $payload);
|
||||
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");
|
||||
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: application/json'));
|
||||
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
|
||||
$result = curl_exec($ch);
|
||||
curl_close($ch);
|
||||
$data_rst = json_decode($result);
|
||||
return $data_rst;
|
||||
}
|
||||
function get($service, $debug = "")
|
||||
{
|
||||
$xbase_url = $this->base_url;
|
||||
$url = $xbase_url . "$service";
|
||||
$ch = curl_init($url);
|
||||
|
||||
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "GET");
|
||||
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: application/json'));
|
||||
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
|
||||
$result = curl_exec($ch);
|
||||
curl_close($ch);
|
||||
if ($debug != "") {
|
||||
echo "url : $url \n";
|
||||
print_r($result);
|
||||
}
|
||||
$data_rst = json_decode($result);
|
||||
return $data_rst;
|
||||
}
|
||||
}
|
||||
148
application/controllers/etl/Mgmmcu_nonlab.php
Normal file
148
application/controllers/etl/Mgmmcu_nonlab.php
Normal file
@@ -0,0 +1,148 @@
|
||||
<?php
|
||||
class Mgmmcu_nonlab extends MY_Controller
|
||||
{
|
||||
var $base_url;
|
||||
function __construct()
|
||||
{
|
||||
parent::__construct();
|
||||
$this->base_url = "/one-api/etl/mgmmcu";
|
||||
$this->db->query("use one_etl");
|
||||
}
|
||||
|
||||
function nonlab_kelainan($orderHeaderID, $mgmMcuID = 0)
|
||||
{
|
||||
$resp = $this->json($orderHeaderID);
|
||||
}
|
||||
|
||||
// helper function
|
||||
// post
|
||||
// get
|
||||
// insert_or_update
|
||||
function json($orderHeaderID)
|
||||
{
|
||||
$url = "http://localhost/one-api/v1/report/fisik03/json/$orderHeaderID";
|
||||
$data = file_get_contents($url);
|
||||
$dataJson = json_decode($data, true);
|
||||
$result = [];
|
||||
foreach ($dataJson as $r) {
|
||||
$arr = [
|
||||
"T_OrderHeaderID" => $orderHeaderID,
|
||||
"title" => $r["title"],
|
||||
"subtitle" => $r["subtitle"],
|
||||
"label_flag_normal" => $r["label_flag_normal"],
|
||||
"flag_normal" => $r["flag_normal"],
|
||||
"flag_normal" => $r["flag_normal"],
|
||||
"show_all" => $r["show_all"],
|
||||
"type_form" => $r["type_form"],
|
||||
"T_TestName" => $r["T_TestName"],
|
||||
"So_ResultEntryFisikUmumType" => $r["So_ResultEntryFisikUmumType"],
|
||||
"name" => $r["name"],
|
||||
"table_name" => $r["table_name"],
|
||||
"segment_name" => $r["segment_name"],
|
||||
"id_code" => $r["id_code"],
|
||||
"lang_id" => $r["lang_id"],
|
||||
"label" => $r["label"],
|
||||
"is_normal" => $r["is_normal"],
|
||||
"chx" => $r["chx"],
|
||||
"value" => $r["value"],
|
||||
"kesimpulan" => $r["kesimpulan"],
|
||||
"value_x" => $r["value_x"],
|
||||
"standart_bmi" => $r["standart_bmi"],
|
||||
"standart" => $r["standart"],
|
||||
];
|
||||
$result[] = $arr;
|
||||
}
|
||||
header("Content-Type: application/json");
|
||||
echo json_encode($result);
|
||||
exit;
|
||||
return $result;
|
||||
}
|
||||
|
||||
|
||||
//tidak jadi di pakai
|
||||
function mcu_resume($orderHeaderID)
|
||||
{
|
||||
$sql = "call one.sp_rpt_r_mcu_resume(?,'')";
|
||||
$qry = $this->db->query($sql, [$orderHeaderID]);
|
||||
if (!$qry) {
|
||||
echo json_encode([
|
||||
"status" => "ERR",
|
||||
"message" => "Error sp_mcu_resume| " . $this->db->error()["message"]
|
||||
]);
|
||||
exit;
|
||||
}
|
||||
$rows = $qry->result_array();
|
||||
$this->clean_mysqli_connection($this->db->conn_id);
|
||||
$arr_test = [];
|
||||
$result = [];
|
||||
Header("Content-Type: application/json");
|
||||
echo json_encode($rows);
|
||||
exit;
|
||||
foreach ($rows as $r) {
|
||||
if ($r["T_TestID"] == "") continue;
|
||||
$arr_test[$r["T_TestID"]] = 1;
|
||||
}
|
||||
$s_test = "0," . implode(",", array_keys($arr_test));
|
||||
$sql = "select T_TestID,Nat_TestID,Nat_TestName
|
||||
from one.t_test
|
||||
join one.nat_test on T_TestID in ($s_test)
|
||||
and T_TestNat_TestID = Nat_TestID";
|
||||
$qry = $this->db->query($sql);
|
||||
|
||||
if (!$qry) {
|
||||
echo json_encode([
|
||||
"status" => "ERR",
|
||||
"message" => "Error get nat_test| " . $this->db->error()["message"], "sql" => $this->db->last_query()
|
||||
]);
|
||||
exit;
|
||||
}
|
||||
$xrows = $qry->result_array();
|
||||
foreach ($xrows as $r) {
|
||||
$arr_test[$r["T_TestID"]] = $r;
|
||||
}
|
||||
foreach ($rows as $r) {
|
||||
$nt = $arr_test[$r["T_TestID"]];
|
||||
$result[] = [
|
||||
"T_OrderHeaderID" => $r["T_OrderHeaderID"],
|
||||
"Nat_TestID" => $nt["Nat_TestID"],
|
||||
"Nat_TestName" => $nt["Nat_TestName"],
|
||||
"Result" => $r["Mcu_ResumeDetailsResult"]
|
||||
];
|
||||
}
|
||||
echo json_encode(["status" => "OK", "data" => $result]);
|
||||
}
|
||||
|
||||
function post($service, $data)
|
||||
{
|
||||
$xbase_url = $this->base_url;
|
||||
$url = $xbase_url . "$service";
|
||||
$ch = curl_init($url);
|
||||
$payload = json_encode($data);
|
||||
curl_setopt($ch, CURLOPT_POSTFIELDS, $payload);
|
||||
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");
|
||||
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: application/json'));
|
||||
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
|
||||
$result = curl_exec($ch);
|
||||
curl_close($ch);
|
||||
$data_rst = json_decode($result);
|
||||
return $data_rst;
|
||||
}
|
||||
function get($service, $debug = "")
|
||||
{
|
||||
$xbase_url = $this->base_url;
|
||||
$url = $xbase_url . "$service";
|
||||
$ch = curl_init($url);
|
||||
|
||||
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "GET");
|
||||
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: application/json'));
|
||||
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
|
||||
$result = curl_exec($ch);
|
||||
curl_close($ch);
|
||||
if ($debug != "") {
|
||||
echo "url : $url \n";
|
||||
print_r($result);
|
||||
}
|
||||
$data_rst = json_decode($result);
|
||||
return $data_rst;
|
||||
}
|
||||
}
|
||||
242
application/controllers/etl/Patient.php
Normal file
242
application/controllers/etl/Patient.php
Normal file
@@ -0,0 +1,242 @@
|
||||
<?php
|
||||
class Patient extends MY_Controller
|
||||
{
|
||||
function __construct()
|
||||
{
|
||||
parent::__construct();
|
||||
}
|
||||
function get_param()
|
||||
{
|
||||
$raw = file_get_contents("php://input");
|
||||
return json_decode($raw, true);
|
||||
}
|
||||
function index()
|
||||
{
|
||||
$this->last_day();
|
||||
}
|
||||
function last_day($last_days = 3)
|
||||
{
|
||||
$sql = "select distinct m_patient.*
|
||||
from t_orderheader
|
||||
join m_patient on T_OrderHeaderDate + interval ? day >= now()
|
||||
and T_OrderHeaderIsActive = 'Y'
|
||||
and T_OrderHeaderM_PatientID = M_PatientID
|
||||
and M_PatientIsActive = 'Y'
|
||||
and ( M_PatientM_IdTypeID = 1 or M_PatientM_IdTypeID = 2)
|
||||
and M_PatientIDNumber is not null
|
||||
and M_PatientIDNumber <> ''";
|
||||
$resp = $this->get_rows($sql, [$last_days]);
|
||||
if ($resp["status"] == -1) {
|
||||
$this->error_reply_gz([
|
||||
"status" => "ERR",
|
||||
"message" => $resp["message"],
|
||||
]);
|
||||
}
|
||||
$patient = $resp["data"];
|
||||
$s_ids = "-1";
|
||||
foreach ($resp["data"] as $r) {
|
||||
$s_ids .= "," . $r["M_PatientID"];
|
||||
}
|
||||
list($branchID, $branchCode) = $this->get_branch();
|
||||
$branch = ["branchID" => $branchID, "branchCode" => $branchCode];
|
||||
// address
|
||||
$sql = "select * from m_patientaddress
|
||||
where M_PatientAddressM_PatientID in ( $s_ids)
|
||||
and M_PatientAddressIsActive = 'Y'";
|
||||
|
||||
$resp = $this->get_rows($sql);
|
||||
if ($resp["status"] == -1) {
|
||||
$this->error_reply_gz([
|
||||
"status" => "ERR",
|
||||
"message" => $resp["message"],
|
||||
]);
|
||||
}
|
||||
$address = $resp["data"];
|
||||
$s_ids = "-1";
|
||||
foreach ($address as $r) {
|
||||
$s_ids .= "," . $r["M_PatientAddressM_KelurahanID"];
|
||||
}
|
||||
//kelurahan
|
||||
$sql = "select * from m_kelurahan where M_KelurahanID in ($s_ids)";
|
||||
$resp = $this->get_rows($sql);
|
||||
if ($resp["status"] == -1) {
|
||||
$this->error_reply_gz([
|
||||
"status" => "ERR",
|
||||
"message" => $resp["message"],
|
||||
]);
|
||||
}
|
||||
$kelurahan = $resp["data"];
|
||||
//district;
|
||||
$s_ids = "-1";
|
||||
foreach ($kelurahan as $r) {
|
||||
$s_ids .= "," . $r["M_KelurahanM_DistrictID"];
|
||||
}
|
||||
$sql = "select * from m_district where M_DistrictID in($s_ids)";
|
||||
$resp = $this->get_rows($sql);
|
||||
if ($resp["status"] == -1) {
|
||||
$this->error_reply_gz([
|
||||
"status" => "ERR",
|
||||
"message" => $resp["message"],
|
||||
]);
|
||||
}
|
||||
$district = $resp["data"];
|
||||
|
||||
//city;
|
||||
$s_ids = "-1";
|
||||
foreach ($district as $r) {
|
||||
$s_ids .= "," . $r["M_DistrictM_CityID"];
|
||||
}
|
||||
$sql = "select * from m_city where M_CityID in($s_ids)";
|
||||
$resp = $this->get_rows($sql);
|
||||
if ($resp["status"] == -1) {
|
||||
$this->error_reply_gz([
|
||||
"status" => "ERR",
|
||||
"message" => $resp["message"],
|
||||
]);
|
||||
}
|
||||
$city = $resp["data"];
|
||||
//province
|
||||
$s_ids = "-1";
|
||||
foreach ($city as $r) {
|
||||
$s_ids .= "," . $r["M_CityM_ProvinceID"];
|
||||
}
|
||||
$sql = "select * from m_province where M_ProvinceID in($s_ids)";
|
||||
$resp = $this->get_rows($sql);
|
||||
if ($resp["status"] == -1) {
|
||||
$this->error_reply_gz([
|
||||
"status" => "ERR",
|
||||
"message" => $resp["message"],
|
||||
]);
|
||||
}
|
||||
$province = $resp["data"];
|
||||
|
||||
foreach ($patient as $idx => $p) {
|
||||
$pa = array_filter($address,function($a) use($p) {
|
||||
return $a["M_PatientAddressM_PatientID"] == $p["M_PatientID"];
|
||||
});
|
||||
foreach($pa as $pa_idx => $addr) {
|
||||
$tmp = array_filter($kelurahan,function($k) use($addr) {
|
||||
return $k["M_KelurahanID"] == $addr["M_PatientAddressM_KelurahanID"];
|
||||
} );
|
||||
$sel_kelurahan = [];
|
||||
$sel_district = [];
|
||||
$sel_city = [];
|
||||
$sel_province = [];
|
||||
if(count($tmp) > 0) {
|
||||
$sel_kelurahan = $tmp[0];
|
||||
$tmp = array_filter($district,function($d) use($sel_kelurahan) {
|
||||
return $sel_kelurahan["M_KelurahanM_DistrictID"] = $d["M_DistrictID"];
|
||||
});
|
||||
if (count($tmp) > 0) {
|
||||
$sel_district = $tmp[0];
|
||||
$tmp = array_filter($city,function($c) use($sel_district) {
|
||||
return $sel_district["M_DistrictM_CityID"] = $c["M_CityID"];
|
||||
});
|
||||
if (count($tmp) > 0) {
|
||||
$sel_city = $tmp[0];
|
||||
$tmp = array_filter($province,function($p) use($sel_city) {
|
||||
return $sel_city["M_CityM_ProvinceID"] = $p["M_ProvinceID"];
|
||||
});
|
||||
if (count($tmp) > 0) {
|
||||
$sel_province = $tmp[0];
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
$pa[$pa_idx]["kelurahan"] = $sel_kelurahan;
|
||||
$pa[$pa_idx]["district"] = $sel_district;
|
||||
$pa[$pa_idx]["city"] = $sel_city;
|
||||
$pa[$pa_idx]["province"] = $sel_province;
|
||||
}
|
||||
$patient[$idx]["address"] = $pa;
|
||||
if ($p["M_PatientPhoto"] != "") {
|
||||
$patient[$idx]["PhotoBase64"] = $this->get_photo($p["M_PatientPhoto"]);
|
||||
}
|
||||
}
|
||||
//foto
|
||||
$this->reply_gz([
|
||||
"status" => "OK",
|
||||
"patient" => $patient,
|
||||
"branch" => $branch,
|
||||
]);
|
||||
}
|
||||
function get_photo($path)
|
||||
{
|
||||
$fname = "/home/one/project/one" . $path;
|
||||
if (file_exists($fname)) {
|
||||
$data = file_get_contents($fname);
|
||||
if (strlen($data) > 0) {
|
||||
return base64_encode($data);
|
||||
}
|
||||
}
|
||||
return "";
|
||||
}
|
||||
//Get Detail Mou
|
||||
function reply_gz($resp)
|
||||
{
|
||||
echo gzcompress(json_encode($resp));
|
||||
exit();
|
||||
}
|
||||
function get_branch()
|
||||
{
|
||||
$sql =
|
||||
"select M_BranchID,M_BranchCode from m_branch where M_BranchIsActive='Y' and M_BranchIsDefault ='Y'";
|
||||
$resp = $this->get_row($sql);
|
||||
if ($resp["status"] != 1) {
|
||||
echo json_encode($resp);
|
||||
exit();
|
||||
}
|
||||
return [$resp["data"]["M_BranchID"], $resp["data"]["M_BranchCode"]];
|
||||
}
|
||||
function log($msg)
|
||||
{
|
||||
$dt = date("Y-m-d H:i:s");
|
||||
echo "$dt $msg\n";
|
||||
}
|
||||
function error_reply_gz($msg)
|
||||
{
|
||||
echo gzcompress(json_encode(["status" => "ERR", "message" => $msg]));
|
||||
exit();
|
||||
}
|
||||
function reply($resp)
|
||||
{
|
||||
echo json_encode($resp);
|
||||
exit();
|
||||
}
|
||||
function error_reply($msg)
|
||||
{
|
||||
echo json_encode(["status" => "ERR", "message" => $msg]);
|
||||
exit();
|
||||
}
|
||||
|
||||
function get_rows($sql, $param = false)
|
||||
{
|
||||
if ($param) {
|
||||
$qry = $this->db->query($sql, $param);
|
||||
} else {
|
||||
$qry = $this->db->query($sql);
|
||||
}
|
||||
if (!$qry) {
|
||||
return [
|
||||
"status" => -1,
|
||||
"message" =>
|
||||
$this->db->last_query() .
|
||||
"|" .
|
||||
$this->db->error()["message"],
|
||||
];
|
||||
}
|
||||
return ["status" => 0, "data" => $qry->result_array()];
|
||||
}
|
||||
function get_row($sql, $param = false)
|
||||
{
|
||||
$resp = $this->get_rows($sql, $param);
|
||||
if ($resp["status"] == -1) {
|
||||
return $resp;
|
||||
}
|
||||
if (count($resp["data"]) == 0) {
|
||||
return ["status" => 0, "message" => "Not found."];
|
||||
}
|
||||
return ["status" => 1, "data" => $resp["data"][0]];
|
||||
}
|
||||
}
|
||||
?>
|
||||
Reference in New Issue
Block a user