369 lines
13 KiB
PHP
369 lines
13 KiB
PHP
<?php
|
|
class Monitoring extends MY_Controller
|
|
{
|
|
|
|
var $db_onedev;
|
|
var $IP_ADDRESS = "192.168.250.42";
|
|
public function index()
|
|
{
|
|
echo "Resultentry API";
|
|
}
|
|
|
|
public function __construct()
|
|
{
|
|
parent::__construct();
|
|
$this->db_onedev = $this->load->database("onedev", true);
|
|
$this->load->helper(array('form', 'url'));
|
|
}
|
|
|
|
function searchcompany()
|
|
{
|
|
if (! $this->isLogin) {
|
|
$this->sys_error("Invalid Token");
|
|
exit;
|
|
}
|
|
$prm = $this->sys_input;
|
|
|
|
$max_rst = 12;
|
|
$tot_count = 0;
|
|
|
|
$q = [
|
|
'search' => '%'
|
|
];
|
|
|
|
if ($prm['search'] != '') {
|
|
$q['search'] = "%{$prm['search']}%";
|
|
}
|
|
|
|
// QUERY TOTAL
|
|
$sql = "SELECT count(DISTINCT M_CompanyID) as total
|
|
FROM m_company
|
|
JOIN m_mou ON M_MouM_CompanyID = M_CompanyID AND M_MouIsActive = 'Y'
|
|
JOIN one_etl.mgm_mcu ON Mgm_McuM_CompanyID = M_CompanyID AND Mgm_McuIsActive = 'Y'
|
|
WHERE
|
|
M_CompanyName like ?
|
|
AND M_CompanyIsActive = 'Y'";
|
|
$query = $this->db_onedev->query($sql, $q['search']);
|
|
//echo $query;
|
|
// echo $this->db_onedev->last_query();
|
|
if ($query) {
|
|
$tot_count = $query->result_array()[0]["total"];
|
|
} else {
|
|
$this->sys_error_db("m_city count", $this->db_onedev);
|
|
exit;
|
|
}
|
|
|
|
$sql = "SELECT DISTINCT M_CompanyID as id, M_CompanyName as name, '' as mous
|
|
FROM m_company
|
|
JOIN m_mou ON M_MouM_CompanyID = M_CompanyID AND M_MouIsActive = 'Y'
|
|
JOIN one_etl.mgm_mcu ON Mgm_McuM_CompanyID = M_CompanyID AND Mgm_McuIsActive = 'Y'
|
|
WHERE
|
|
M_CompanyName like ? AND
|
|
M_CompanyIsActive = 'Y'
|
|
ORDER BY M_CompanyName DESC
|
|
";
|
|
$query = $this->db_onedev->query($sql, array($q['search']));
|
|
|
|
if ($query) {
|
|
$rows = $query->result_array();
|
|
if ($rows) {
|
|
foreach ($rows as $k => $v) {
|
|
$sql = "SELECT '0' as id, 'Semua' as name
|
|
UNION
|
|
SELECT M_MouID as id, M_MouName as name
|
|
FROM m_mou
|
|
WHERE
|
|
M_MouM_CompanyID = {$v['id']} AND M_MouIsActive = 'Y'";
|
|
$details = $this->db_onedev->query($sql)->result_array();
|
|
$rows[$k]['mous'] = $details;
|
|
}
|
|
}
|
|
// echo $this->db_onedev->last_query();
|
|
$result = array("total" => $tot_count, "records" => $rows, "total_display" => sizeof($rows));
|
|
$this->sys_ok($result);
|
|
} else {
|
|
$this->sys_error_db("m_company rows", $this->db_onedev);
|
|
exit;
|
|
}
|
|
}
|
|
|
|
public function search()
|
|
{
|
|
$prm = $this->sys_input;
|
|
if (! $this->isLogin) {
|
|
$this->sys_error("Invalid Token");
|
|
exit;
|
|
}
|
|
|
|
$company = isset($prm["company"]) ? $prm["company"] : '0';
|
|
$search = $prm["search"];
|
|
|
|
$sql_where = " WHERE Mgm_McuIsActive = 'Y' AND Mgm_McuNumberNational <> ''";
|
|
|
|
if (!isset($prm['current_page']))
|
|
$prm['current_page'] = 1;
|
|
if ($company == 0 && $search !== '') {
|
|
$sql_where = "WHERE Mgm_McuNumber like '%$search%' AND Mgm_McuIsActive = 'Y' AND Mgm_McuNumberNational <> ''";
|
|
} elseif ($company != 0 && $search === '') {
|
|
$sql_where = "WHERE Mgm_McuM_CompanyID = {$company} AND Mgm_McuIsActive = 'Y' AND Mgm_McuNumberNational <> ''";
|
|
} elseif ($company != 0 && $search !== '') {
|
|
$sql_where = "WHERE Mgm_McuM_CompanyID = {$company} AND Mgm_McuNumber like '%$search%' AND Mgm_McuIsActive = 'Y' AND Mgm_McuNumberNational <> ''";
|
|
}
|
|
|
|
$number_limit = 10;
|
|
$number_offset = ($prm['current_page'] - 1) * $number_limit;
|
|
//$sql_param = array();
|
|
|
|
|
|
$sql = " SELECT count(*) as total
|
|
FROM (
|
|
SELECT Mgm_McuID
|
|
FROM
|
|
one_etl.mgm_mcu
|
|
$sql_where
|
|
GROUP BY Mgm_McuID
|
|
) x
|
|
";
|
|
//echo $sql;
|
|
$query = $this->db_onedev->query($sql);
|
|
|
|
$tot_count = 0;
|
|
$tot_page = 0;
|
|
if ($query) {
|
|
$tot_count = $query->result_array()[0]["total"];
|
|
$tot_page = ceil($tot_count / $number_limit);
|
|
} else {
|
|
$this->sys_error_db("t_samplestorageout count", $this->db_onedev);
|
|
exit;
|
|
}
|
|
|
|
|
|
$sql = "SELECT Mgm_McuID,
|
|
Mgm_McuM_CompanyID,
|
|
Mgm_McuNumber as ordernumber,
|
|
Mgm_McuNumberNational,
|
|
Mgm_McuStartDate,
|
|
Mgm_McuEndDate,
|
|
CONCAT(DATE_FORMAT(Mgm_McuStartDate,'%d-%m-%Y'), ' s/d ',DATE_FORMAT(Mgm_McuStartDate,'%d-%m-%Y')) as orderdate
|
|
FROM
|
|
one_etl.mgm_mcu
|
|
$sql_where
|
|
GROUP BY Mgm_McuID
|
|
ORDER BY Mgm_McuID ASC
|
|
limit $number_limit offset $number_offset";
|
|
//echo $sql;
|
|
$query = $this->db_onedev->query($sql);
|
|
$rows = $query->result_array();
|
|
// echo $this->db_onedev->last_query();
|
|
// exit;
|
|
/* if($rows){
|
|
foreach($rows as $k => $v){
|
|
$rows[$k]['langs'] = $this->getlangs($v['trx_id']);
|
|
$rows[$k]['doctors'] = $this->getdoctors();
|
|
}
|
|
}
|
|
*/
|
|
|
|
|
|
//$this->_add_address($rows);
|
|
$result = array("total" => $tot_page, "records" => $rows, "sql" => $this->db_onedev->last_query());
|
|
$this->sys_ok($result);
|
|
exit;
|
|
}
|
|
|
|
public function get_mcuorder()
|
|
{
|
|
$prm = $this->sys_input;
|
|
if (! $this->isLogin) {
|
|
$this->sys_error("Invalid Token");
|
|
exit;
|
|
}
|
|
|
|
$sql_mcu_order = "SELECT count(*) as total
|
|
FROM one_etl.mcu_order
|
|
WHERE Mcu_OrderMgm_McuID = ?";
|
|
$qry_mcu_order = $this->db_onedev->query($sql_mcu_order, [$prm["mgmmcuid"]]);
|
|
if ($qry_mcu_order) {
|
|
$tot_order = $qry_mcu_order->row_array()['total'];
|
|
} else {
|
|
$this->sys_error_db("select tabel mcu_order error", $this->db_onedev);
|
|
exit;
|
|
}
|
|
|
|
$sql_top3kelainan = "SELECT count(*) as total
|
|
FROM one_etl.mcu_top3_kelainan
|
|
WHERE Mcu_Top3KelainanMgm_McuID = ? AND Mcu_Top3KelainanIsActive = 'Y'";
|
|
$qry_top3kelainan = $this->db_onedev->query($sql_top3kelainan, [$prm["mgmmcuid"]]);
|
|
if ($qry_top3kelainan) {
|
|
$tot_top3kelainan = $qry_top3kelainan->row_array()['total'];
|
|
} else {
|
|
$this->sys_error_db("select tabel mcu_top3_kelainan error", $this->db_onedev);
|
|
exit;
|
|
}
|
|
|
|
$sql_snapshot_note = "SELECT count(*) as total
|
|
FROM one_etl.mcu_snapshot_note
|
|
WHERE Mcu_Snapshot_NoteMgm_McuID = ? AND Mcu_Snapshot_NoteIsActive = 'Y'";
|
|
$qry_snapshot_note = $this->db_onedev->query($sql_snapshot_note, [$prm["mgmmcuid"]]);
|
|
if ($qry_snapshot_note) {
|
|
$tot_snapshot_note = $qry_snapshot_note->row_array()['total'];
|
|
} else {
|
|
$this->sys_error_db("select tabel mcu_snapshot_note error", $this->db_onedev);
|
|
exit;
|
|
}
|
|
|
|
$sql_mou = "SELECT count(*) as total
|
|
FROM one_etl.mgm_mou
|
|
WHERE Mgm_MouMgm_McuID = ? AND Mgm_MouIsActive = 'Y'";
|
|
$qry_mou = $this->db_onedev->query($sql_mou, [$prm["mgmmcuid"]]);
|
|
if ($qry_mou) {
|
|
$tot_mou = $qry_mou->row_array()['total'];
|
|
} else {
|
|
$this->sys_error_db("select tabel mcu_snapshot_note error", $this->db_onedev);
|
|
exit;
|
|
}
|
|
|
|
$sql_antro = "SELECT count(*) as total
|
|
FROM one_etl.antropometri
|
|
WHERE AntropometriMgm_McuID = ?";
|
|
$qry_antro = $this->db_onedev->query($sql_antro, [$prm["mgmmcuid"]]);
|
|
if ($qry_antro) {
|
|
$tot_antro = $qry_antro->row_array()['total'];
|
|
} else {
|
|
$this->sys_error_db("select tabel antropometri error", $this->db_onedev);
|
|
exit;
|
|
}
|
|
|
|
$sql_header = "SELECT count(*) as total
|
|
FROM one_etl.mgm_header
|
|
WHERE Mgm_HeaderMgm_McuID = ? AND Mgm_HeaderIsActive = 'Y'";
|
|
$qry_header = $this->db_onedev->query($sql_header, [$prm["mgmmcuid"]]);
|
|
if ($qry_header) {
|
|
$tot_header = $qry_header->row_array()['total'];
|
|
} else {
|
|
$this->sys_error_db("select tabel mgm_header error", $this->db_onedev);
|
|
exit;
|
|
}
|
|
|
|
$sql_header_select = "SELECT
|
|
Mgm_HeaderID
|
|
FROM one_etl.mgm_header
|
|
WHERE Mgm_HeaderMgm_McuID = ? AND Mgm_HeaderIsActive = 'Y'";
|
|
$qry_header_select = $this->db_onedev->query($sql_header_select, [$prm["mgmmcuid"]]);
|
|
if ($qry_header_select) {
|
|
$tot_header_select = $qry_header_select->result_array();
|
|
} else {
|
|
$this->sys_error_db("select tabel header error", $this->db_onedev);
|
|
exit;
|
|
}
|
|
|
|
$total_all_details = 0;
|
|
$total_all_riwayats = 0;
|
|
if ($tot_header_select) {
|
|
foreach ($tot_header_select as $key => $value) {
|
|
$mgmheaderid = $value["Mgm_HeaderID"];
|
|
|
|
$sql_detail = "SELECT count(*) as total
|
|
FROM one_etl.mgm_detail
|
|
WHERE Mgm_DetailMgm_HeaderID = ? AND Mgm_DetailIsActive = 'Y'";
|
|
$qry_detail = $this->db_onedev->query($sql_detail, [$mgmheaderid]);
|
|
if ($qry_detail) {
|
|
$tot_mgm_detail = $qry_detail->row_array()['total'];
|
|
$total_all_details += $tot_mgm_detail;
|
|
} else {
|
|
$this->sys_error_db("select tabel mgm_detail error", $this->db_onedev);
|
|
exit;
|
|
}
|
|
|
|
$sql_riwayat = "SELECT count(*) as total
|
|
FROM one_etl.mgm_riwayat
|
|
WHERE Mgm_RiwayatMgm_HeaderID = ? AND Mgm_RiwayatIsActive = 'Y'";
|
|
$qry_riwayat = $this->db_onedev->query($sql_riwayat, [$mgmheaderid]);
|
|
if ($qry_riwayat) {
|
|
$tot_riwayat = $qry_riwayat->row_array()['total'];
|
|
$total_all_riwayats += $tot_riwayat;
|
|
} else {
|
|
$this->sys_error_db("select tabel mgm_riwayat error", $this->db_onedev);
|
|
exit;
|
|
}
|
|
}
|
|
}
|
|
|
|
$result = array(
|
|
"tot_order" => $tot_order,
|
|
"tot_top3kelainan" => $tot_top3kelainan,
|
|
"tot_snapshot_note" => $tot_snapshot_note,
|
|
"tot_mou" => $tot_mou,
|
|
"tot_antro" => $tot_antro,
|
|
"tot_header" => $tot_header,
|
|
"tot_mgm_detail" => $total_all_details,
|
|
"tot_riwayat" => $total_all_riwayats
|
|
);
|
|
$this->sys_ok($result);
|
|
}
|
|
|
|
public function post($url)
|
|
{
|
|
$ch = curl_init($url);
|
|
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");
|
|
// curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
|
|
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
|
|
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 10);
|
|
curl_setopt($ch, CURLOPT_TIMEOUT, 10);
|
|
curl_setopt($ch, CURLOPT_HTTPHEADER, [
|
|
"Content-Type: application/text",
|
|
// "Content-Length: " . strlen($data),
|
|
]);
|
|
$result = curl_exec($ch);
|
|
if (curl_error($ch) != "") {
|
|
echo json_encode([
|
|
"status" => "ERR",
|
|
"message" => "Http Error : " . curl_error($ch),
|
|
]);
|
|
curl_close($ch);
|
|
exit();
|
|
}
|
|
curl_close($ch);
|
|
return $result;
|
|
}
|
|
|
|
public function getdatamcu()
|
|
{
|
|
$prm = $this->sys_input;
|
|
if (! $this->isLogin) {
|
|
$this->sys_error("Invalid Token");
|
|
exit;
|
|
}
|
|
|
|
$mgmmcuid = $prm["mgmmcuid"];
|
|
$numbernational = $prm["numbernational"];
|
|
|
|
$sql_branch = "SELECT M_BranchID,
|
|
M_BranchCode,
|
|
M_BranchName
|
|
FROM m_branch
|
|
WHERE M_BranchIsDefault = 'Y'
|
|
AND M_BranchIsActive = 'Y'";
|
|
$qry_branch = $this->db_onedev->query($sql_branch);
|
|
if ($qry_branch) {
|
|
$row = $qry_branch->row_array();
|
|
} else {
|
|
$this->sys_error_db("select branch error", $this->db_onedev);
|
|
exit;
|
|
}
|
|
|
|
$url = "http://$this->IP_ADDRESS/one-api/mockup/monitoring/getmcutot/get_data_national/" . $row["M_BranchCode"] . "/" . $mgmmcuid . "/" . $numbernational;
|
|
|
|
$resp = $this->post($url);
|
|
$j_resp = json_decode($resp, true);
|
|
|
|
// print_r($resp);
|
|
// exit;
|
|
// $result = array(
|
|
// "data" => $j_resp
|
|
// );
|
|
|
|
$this->sys_ok($j_resp);
|
|
}
|
|
}
|