Files
2026-04-15 15:24:12 +07:00

2440 lines
72 KiB
PHP

<?php
class Setupmcu extends MY_Controller
{
var $db_onedev;
var $load;
public function index()
{
echo "Patient API";
}
public function __construct()
{
parent::__construct();
$this->db_onedev = $this->load->database("onedev", true);
$this->db_log = $this->load->database("one_lab_log", true);
$this->load->library("SsPriceMou");
}
public function search()
{
$prm = $this->sys_input;
if (!$this->isLogin) {
$this->sys_error("Invalid Token");
exit;
}
$limit = '';
$filter_paket = $prm['searchPacket'];
// if ($all == 'N') {
// $limit = ' LIMIT 10';
// }
$number_limit = 10;
$number_offset = ($prm['current_page'] - 1) * $number_limit;
$sql_where = " WHERE mgm.Mgm_McuIsActive = 'Y'";
if ($prm['search'] != "") {
$sql_where = "
WHERE mgm.Mgm_McuIsActive = 'Y' AND (
mgm.Mgm_McuNumber LIKE '%{$prm['search']}%'
OR mcp.M_CompanyName LIKE '%{$prm['search']}%'
OR mgm.Mgm_McuLabel LIKE '%{$prm['search']}%'
)";
}
$sql = "SELECT COUNT(*) AS total
FROM (
SELECT mgm.Mgm_McuID
FROM mgm_mcu mgm
LEFT JOIN m_company mcp
ON mgm.Mgm_McuM_CompanyID = mcp.M_CompanyID
AND mcp.M_CompanyIsActive = 'Y'
LEFT JOIN m_mou mou
ON mgm.Mgm_McuM_MouID = mou.M_MouID
AND mou.M_MouIsActive = 'Y'
LEFT JOIN mgm_mcupacket packet
ON mgm.Mgm_McuID = packet.Mgm_McuPacketMgm_McuID
AND packet.Mgm_McuPacketIsActive = 'Y'
LEFT JOIN mgm_mcutemplate template
ON mgm.Mgm_McuID = template.Mgm_McuTemplateMgm_McuID
AND template.Mgm_McuTemplateIsActive = 'Y'
LEFT JOIN fisik_template_mapping fisik
ON template.Mgm_McuTemplateFisikTemplateMappingID = fisik.FisikTemplateMappingID
AND fisik.FisikTemplateMappingIsActive = 'Y'
LEFT JOIN
m_branch branch
ON mgm.Mgm_McuM_BranchID = branch.M_BranchID
AND branch.M_BranchIsActive = 'Y'
LEFT JOIN config_website ON config_website.configWebsiteMgm_McuID = mgm.Mgm_McuID AND config_website.configWebsiteIsActive = 'Y'
LEFT JOIN mgm_mcuresultpromise mp on mgm.Mgm_McuID = mp.Mgm_McuResultPromiseMgm_McuID
AND mp.Mgm_McuResultPromiseIsActive = 'Y'
$sql_where
GROUP BY mgm.Mgm_McuID
) subquery";
$sql_param = array();
$query = $this->db_onedev->query($sql, $sql_param);
// echo $this->db_onedev->last_query();
$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("mgmmcu count", $this->db_onedev);
exit;
}
// sql data
$sql = "SELECT
IFNULL(mgm.Mgm_McuID, 0) AS Mgm_McuID,
IFNULL(mgm.Mgm_McuLabel, '') AS Mgm_McuLabel,
IFNULL(mgm.Mgm_McuPicName,'') AS Mgm_McuPicName,
mgm.Mgm_McuFlagRelasiBayarSendiri,
mgm.Mgm_McuBisaTambahPemeriksaan,
mgm.Mgm_McuLowBackPainTampilSemua,
IFNULL(mgm.Mgm_McuM_CompanyID, 0) AS Mgm_McuM_CompanyID,
IFNULL(mgm.Mgm_McuNumber, '') AS Mgm_McuNumber,
IFNULL(mgm.Mgm_McuNumberNational, '') AS Mgm_McuNumberNational,
IFNULL(mgm.Mgm_McuNote, '') AS Mgm_McuNote,
IFNULL(mgm.Mgm_McuStartDate, '0000-00-00') AS Mgm_McuStartDate,
IFNULL(mgm.Mgm_McuEndDate, '0000-00-00') AS Mgm_McuEndDate,
IFNULL(DATE_FORMAT(mgm.Mgm_McuStartDate, '%d-%m-%Y'), '00-00-0000') AS Mgm_McuStartDateTxt,
IFNULL(DATE_FORMAT(mgm.Mgm_McuEndDate, '%d-%m-%Y'), '00-00-0000') AS Mgm_McuEndDateTxt,
IFNULL(mgm.Mgm_McuIsActive, '') AS Mgm_McuIsActive,
IFNULL(mgm.Mgm_McuTotalParticipant, 0) AS Mgm_McuTotalParticipant,
IFNULL(mgm.Mgm_McuPicEmail, '') AS Mgm_McuPicEmail,
IFNULL(mgm.Mgm_McuPicPassword, '') AS Mgm_McuPicPassword,
IFNULL(mgm.Mgm_McuM_MouID, 0) AS Mgm_McuM_MouID,
IFNULL(mgm.Mgm_McuReportHasil, '1') AS Mgm_McuReportHasil,
IFNULL(mgm.Mgm_McuM_BranchID, '') AS Mgm_McuM_BranchID,
IFNULL(mgm.Mgm_McuGeneratePasswordBY, '') AS generatepasswordbycode,
CASE
WHEN Mgm_McuGeneratePasswordBY = 'hrd' THEN 'Generate password pasien oleh HRD'
WHEN Mgm_McuGeneratePasswordBY = 'ibl' THEN 'Generate password pasien oleh ibl'
ELSE ''
END AS generatepasswordbyname,
-- company
IFNULL(mcp.M_CompanyID, 0) AS M_CompanyID,
IFNULL(mcp.M_CompanyNumber, '') AS M_CompanyNumber,
IFNULL(mcp.M_CompanyName, '') AS M_CompanyName,
IFNULL(mcp.M_CompanyAddress, '') AS M_CompanyAddress,
IFNULL(mcp.M_CompanyAddressRegionalCd, '') AS M_CompanyAddressRegionalCd,
IFNULL(mcp.M_CompanyEmail, '') AS M_CompanyEmail,
IFNULL(mcp.M_CompanyPhone, '') AS M_CompanyPhone,
IFNULL(mcp.M_CompanyPICName, '') AS M_CompanyPICName,
IFNULL(mcp.M_CompanyPICEmail, '') AS M_CompanyPICEmail,
IFNULL(mcp.M_CompanyPICPhone, '') AS M_CompanyPICPhone,
IFNULL(mcp.M_CompanyFlagHolding, '') AS M_CompanyFlagHolding,
IFNULL(mcp.M_CompanyHoldingM_CompanyID, 0) AS M_CompanyHoldingM_CompanyID,
IFNULL(mcp.M_CompanyPICBillName, '') AS M_CompanyPICBillName,
IFNULL(mcp.M_CompanyPICBillEmail, '') AS M_CompanyPICBillEmail,
IFNULL(mcp.M_CompanyPICBillPhone, '') AS M_CompanyPICBillPhone,
IFNULL(mcp.M_CompanyDueDate, 0) AS M_CompanyDueDate,
IFNULL(mcp.M_CompanyUsername, '') AS M_CompanyUsername,
IFNULL(mcp.M_CompanyPassword, '') AS M_CompanyPassword,
-- m_mou
'' as allmous,
'' as selected_mous,
IFNULL(mou.M_MouID, 0) AS M_MouID,
IFNULL(mou.M_MouName, '') AS M_MouName,
IFNULL(mou.M_MouNumber, '') AS M_MouNumber,
IFNULL(mou.M_MouStartDate, '0000-00-00') AS M_MouStartDate,
IFNULL(mou.M_MouEndDate, '0000-00-00') AS M_MouEndDate,
IFNULL(mou.M_MouIsActive, '') AS M_MouIsActive,
-- mgm_mcupacket
IFNULL(packet.Mgm_McuPacketID, 0) AS Mgm_McuPacketID,
IFNULL(packet.Mgm_McuPacketT_PacketID, 0) AS Mgm_McuPacketT_PacketID,
IFNULL(packet.Mgm_McuPacketIsActive, '') AS Mgm_McuPacketIsActive,
IFNULL(template.Mgm_McuTemplateID, 0) AS Mgm_McuTemplateID,
IFNULL(template.Mgm_McuTemplateFisikTemplateMappingID, 0) AS Mgm_McuTemplateFisikTemplateMappingID,
IFNULL(template.Mgm_McuTemplateIsActive, '') AS Mgm_McuTemplateIsActive,
-- fisik_template_mapping
IFNULL(fisik.FisikTemplateMappingID, 0) AS FisikTemplateMappingID,
IFNULL(fisik.FisikTemplateMappingName, '') AS FisikTemplateMappingName,
IFNULL(fisik.FisikTemplateMappingIsActive, '') AS FisikTemplateMappingIsActive,
IFNULL(fisik.FisikTemplateMappingCreated, '0000-00-00 00:00:00') AS FisikTemplateMappingCreated,
IFNULL(fisik.FisikTemplateMappingCreatedUserID, 0) AS FisikTemplateMappingCreatedUserID,
IFNULL(fisik.FisikTemplateMappingLastUpdated, '0000-00-00 00:00:00') AS FisikTemplateMappingLastUpdated,
IFNULL(fisik.FisikTemplateMappingLastUpdatedUserID, 0) AS FisikTemplateMappingLastUpdatedUserID,
IFNULL(fisik.FisikTemplateMappingDeleted, '0000-00-00 00:00:00') AS FisikTemplateMappingDeleted,
IFNULL(fisik.FisikTemplateMappingDeletedUserID, 0) AS FisikTemplateMappingDeletedUserID,
-- branch
IFNULL(branch.M_BranchID, 0) AS M_BranchID,
IFNULL(branch.M_BranchCode, '') AS M_BranchCode,
CONCAT(IFNULL(M_BranchCode, ''), ' - ', IFNULL(M_BranchName, '')) AS M_BranchName,
IFNULL(branch.M_BranchAddress, '') AS M_BranchAddress,
IFNULL(branch.M_BranchIsActive, '') AS M_BranchIsActive,
IFNULL(branch.M_BranchCreated, '0000-00-00 00:00:00') AS M_BranchCreated,
IFNULL(branch.M_BranchUserID, 0) AS M_BranchUserID,
IFNULL(branch.M_BranchLastUpdated, '0000-00-00 00:00:00') AS M_BranchLastUpdated,
'' as packets,
mgm.Mgm_McuTemplateMulti,
IF(ISNULL(config_website.configWebsiteID), 'N', 'Y') AS check_price_website,
-- promise
mp.Mgm_McuResultPromiseID,
mp.Mgm_McuResultPromiseType,
mp.Mgm_McuResultPromiseValue,
mp.Mgm_McuResultPromiseDate,
mp.Mgm_McuResultPromiseTime,
CASE
WHEN Mgm_McuResultPromiseType = 'D' THEN 'By Date'
WHEN Mgm_McuResultPromiseType = 'T' THEN 'Fix Time'
ELSE ''
END AS promisename
FROM mgm_mcu mgm
left join m_company mcp
ON mgm.Mgm_McuM_CompanyID = mcp.M_CompanyID
AND mcp.M_CompanyIsActive = 'Y'
LEFT JOIN m_mou mou
ON mgm.Mgm_McuM_MouID = mou.M_MouID
AND mou.M_MouIsActive = 'Y'
LEFT JOIN mgm_mcupacket packet
ON mgm.Mgm_McuID = packet.Mgm_McuPacketMgm_McuID
AND packet.Mgm_McuPacketIsActive = 'Y'
LEFT JOIN mgm_mcutemplate template
ON mgm.Mgm_McuID = template.Mgm_McuTemplateMgm_McuID
AND template.Mgm_McuTemplateIsActive = 'Y'
LEFT JOIN fisik_template_mapping fisik
ON template.Mgm_McuTemplateFisikTemplateMappingID = fisik.FisikTemplateMappingID
AND fisik.FisikTemplateMappingIsActive = 'Y'
LEFT JOIN m_branch branch
ON mgm.Mgm_McuM_BranchID = branch.M_BranchID
AND branch.M_BranchIsActive = 'Y'
LEFT JOIN config_website ON config_website.configWebsiteMgm_McuID = mgm.Mgm_McuID AND config_website.configWebsiteIsActive = 'Y'
LEFT JOIN mgm_mcuresultpromise mp on mgm.Mgm_McuID = mp.Mgm_McuResultPromiseMgm_McuID
AND mp.Mgm_McuResultPromiseIsActive = 'Y'
$sql_where
GROUP BY mgm.Mgm_McuID
ORDER BY mgm.Mgm_McuID DESC
limit $number_limit offset $number_offset
";
$query = $this->db_onedev->query($sql, $sql_param);
// echo $this->db_onedev->last_query();
if ($query === false) {
// If query failed, log the error and exit
$this->sys_error_db("select mgmmcu data", $this->db_onedev);
exit;
}
$rows = $query->result_array();
if (count($rows) > 0) {
foreach ($rows as $k => $v) {
if ($v['check_price_website'] == 'Y') {
$rows[$k]['check_price_website'] = true;
} else {
$rows[$k]['check_price_website'] = false;
}
if ($v['Mgm_McuTemplateMulti'] == 'Y') {
$rows[$k]['Mgm_McuTemplateMulti'] = true;
} else {
$rows[$k]['Mgm_McuTemplateMulti'] = false;
}
$rows[$k]['packets'] = array();
$sql = "SELECT
DISTINCT T_PacketID as id,
T_PacketID,
T_PacketM_MouID,
T_PacketSasCode,
T_PacketName,
M_MouStartDate,
M_MouEndDate,
T_PacketSasCode as code,
T_PacketName as name,
'Y' as T_PacketIsActive
from t_packet
JOIN mgm_mcupacket ON T_PacketID = Mgm_McuPacketT_PacketID AND
Mgm_McuPacketMgm_McuID = {$v['Mgm_McuID']} AND Mgm_McuPacketIsActive = 'Y'
join m_mou
ON T_PacketM_MouID = M_MouID
AND T_PacketIsActive = 'Y'
AND M_MouIsActive = 'Y'
";
//echo $sql;
$qry_paket_data = $this->db_onedev->query($sql);
if (!$qry_paket_data) {
$this->sys_error_db("select packet where in data", $this->db_onedev);
exit;
}
$datapaket = $qry_paket_data->result_array();
$rows[$k]['packets'] = $datapaket;
$sql = "SELECT M_MouID as id, M_MouName as name, M_MouNumber as code
FROM mgm_mou
JOIN m_mou ON Mgm_MouM_MouID = M_MouID AND M_MouIsActive = 'Y' AND M_MouIsReleased = 'Y' AND
( '{$v['Mgm_McuStartDate']}' >= M_MouStartDate) AND
( '{$v['Mgm_McuEndDate']}' <= M_MouEndDate )
WHERE
Mgm_MouMgm_McuID = {$v['Mgm_McuID']} AND
Mgm_MouIsActive = 'Y'
";
$qry_mou_data = $this->db_onedev->query($sql);
if (!$qry_mou_data) {
$this->sys_error_db("select mou where in data", $this->db_onedev);
exit;
}
$mou_data = $qry_mou_data->result_array();
$rows[$k]['selected_mous'] = $mou_data;
// cabang id 100
if (intval($v['Mgm_McuM_BranchID']) === 100) {
$rows[$k]['M_BranchID'] = '100';
$rows[$k]['M_BranchCode'] = '';
$rows[$k]['M_BranchName'] = 'Sesuai branch login';
$rows[$k]['M_BranchAddress'] = '';
$rows[$k]['M_BranchIsActive'] = 'Y';
$rows[$k]['M_BranchCreated'] = '';
$rows[$k]['M_BranchUserID'] = '';
$rows[$k]['M_BranchLastUpdated'] = '';
}
}
}
$covers = [];
$sql = "SELECT M_CoverCode as code,M_CoverName as name FROM m_cover WHERE M_CoverIsActive = 'Y'";
$qry = $this->db_onedev->query($sql);
if ($qry) {
$covers = $qry->result_array();
} else {
$this->sys_error_db("template fisik select error", $this->db_onedev);
exit;
}
$result = array(
"total" => $tot_page,
"records" => $rows,
"covers" => $covers,
"sql" => $this->db_onedev->last_query()
);
$this->sys_ok($result);
exit;
}
function getcover()
{
if (!$this->isLogin) {
$this->sys_error("Invalid Token");
exit;
}
$prm = $this->sys_input;
$sql = "SELECT
M_CoverCode as code,
M_CoverName as name
FROM mgm_cover
JOIN m_cover ON Mgm_CoverM_CoverCode = M_CoverCode
WHERE
Mgm_CoverMgm_McuID = ? AND Mgm_CoverIsActive = 'Y'
LIMIT 1";
$qry = $this->db_onedev->query($sql, array($prm['Mgm_McuID']));
if ($qry) {
$rows = $qry->result_array();
} else {
$this->sys_error_db("template fisik select error", $this->db_onedev);
exit;
}
$rows = $qry->result_array();
if (count($rows) == 0) {
$sql = "SELECT
M_CoverCode as code,
M_CoverName as name
FROM m_cover
WHERE
M_CoverCode = 'DFLT' AND M_CoverIsActive = 'Y'
LIMIT 1";
$qry = $this->db_onedev->query($sql);
if (!$qry) {
$this->sys_error_db("template fisik select error", $this->db_onedev);
exit;
}
$rows = $qry->result_array();
}
$result = array(
"total" => count($rows),
"records" => $rows[0]
);
$this->sys_ok($result);
exit;
}
function getmultitemplates()
{
if (!$this->isLogin) {
$this->sys_error("Invalid Token");
exit;
}
$prm = $this->sys_input;
$sql = "SELECT T_PacketID as packet_id,
T_PacketName as packet_name,
T_PacketSasCode as packet_code,
IFNULL(Mgm_McuTemplateMultiT_PacketID, 0) as template_id,
IFNULL(Mgm_McuTemplateMultiT_PacketID, '') as template_name
FROM mgm_mcupacket
JOIN t_packet ON Mgm_McuPacketT_PacketID = T_PacketID
LEFT JOIN mgm_mcutemplatemulti ON Mgm_McuPacketT_PacketID = Mgm_McuTemplateMultiT_PacketID AND
Mgm_McuTemplateMultiMgm_McuID = Mgm_McuPacketMgm_McuID AND Mgm_McuTemplateMultiIsActive = 'Y'
WHERE
Mgm_McuPacketIsActive = 'Y' AND Mgm_McuPacketMgm_McuID = ?";
$qry = $this->db_onedev->query($sql, array($prm['Mgm_McuID']));
if ($qry) {
$rows = $qry->result_array();
} else {
$this->sys_error_db("template fisik select error", $this->db_onedev);
exit;
}
$rows = $qry->result_array();
$result = array(
"total" => count($rows),
"records" => $rows,
"sql" => $this->db_onedev->last_query()
);
$this->sys_ok($result);
exit;
}
function getTemplateFisikMapping()
{
try {
if (!$this->isLogin) {
$this->sys_error("Invalid Token");
exit;
}
$prm = $this->sys_input;
$sql = "SELECT FisikTemplateMappingID,
FisikTemplateMappingName
FROM fisik_template_mapping
WHERE FisikTemplateMappingIsActive = 'Y'";
$qry = $this->db_onedev->query($sql);
if ($qry) {
$rows = $qry->result_array();
} else {
$this->sys_error_db("template fisik select error", $this->db_onedev);
exit;
}
$result = array(
"records" => $rows,
"sql" => $this->db_onedev->last_query()
);
$this->sys_ok($result);
} catch (Exception $exc) {
$message = $exc->getMessage();
$this->sys_error($message);
}
}
function searchcompany()
{
//# cek token valid
if (!$this->isLogin) {
$this->sys_error("Invalid Token");
exit;
}
$prm = $this->sys_input;
$tot_count = 0;
$q = [
'search' => '%'
];
if ($prm['search'] != '') {
$q['search'] = "%{$prm['search']}%";
}
// QUERY TOTAL
$sql = "SELECT count(*) as total
FROM m_company
WHERE
M_CompanyName like ?
AND M_CompanyIsActive = 'Y'";
$query = $this->db_onedev->query($sql, $q['search']);
//echo $query;
if ($query) {
$tot_count = $query->result_array()[0]["total"];
} else {
$this->sys_error_db("company count", $this->db_onedev);
exit;
}
$sql = "
SELECT M_CompanyID as id, M_CompanyName as name
FROM m_company
WHERE
M_CompanyName like ?
AND M_CompanyIsActive = 'Y'
ORDER BY M_CompanyName ASC
";
$query = $this->db_onedev->query($sql, array($q['search']));
if ($query) {
$rows = $query->result_array();
//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("company rows", $this->db_onedev);
exit;
}
}
function getPackets()
{
if (!$this->isLogin) {
$this->sys_error("Invalid Token");
exit;
}
$prm = $this->sys_input;
$search = $prm["searchPacket"];
$M_MouID = $prm["M_MouID"];
$q = [
'search' => '%'
];
if ($search != '') {
$q['search'] = "%$search%";
}
$number_limit = 10;
$number_offset = ($prm['current_page'] - 1) * $number_limit;
if (isset($prm['Mgm_McuID'])) {
$sql = "SELECT count(*) as total
FROM (
select
T_PacketID as id,
T_PacketID,
T_PacketM_MouID,
T_PacketSasCode,
T_PacketName,
M_MouStartDate,
M_MouEndDate,
T_PacketSasCode as code,
T_PacketName as name,
'N' as T_PacketIsActive
from t_packet
LEFT join mgm_mcupacket ON T_PacketID = Mgm_McuPacketT_PacketID AND Mgm_McuPacketMgm_McuID = ? AND Mgm_McuPacketIsActive = 'Y'
join m_mou
ON T_PacketM_MouID = M_MouID
AND T_PacketIsActive = 'Y'
AND M_MouIsActive = 'Y'
AND (
T_PacketSasCode LIKE ?
OR T_PacketName LIKE ?
)
AND T_PacketM_MouID = ?
) x
";
//echo $sql;
$query = $this->db_onedev->query($sql, array($prm["Mgm_McuID"], $q['search'], $q['search'], $M_MouID));
} else {
$sql = "SELECT count(*) as total
FROM (
SELECT
T_PacketID as id,
T_PacketID,
T_PacketM_MouID,
T_PacketSasCode,
T_PacketName,
M_MouStartDate,
M_MouEndDate,
T_PacketSasCode as code,
T_PacketName as name,
'N' as T_PacketIsActive
from t_packet
join m_mou
ON T_PacketM_MouID = M_MouID
AND T_PacketIsActive = 'Y'
AND M_MouIsActive = 'Y'
AND (
T_PacketSasCode LIKE ?
OR T_PacketName LIKE ?
)
AND T_PacketM_MouID = ?
) x
";
//echo $sql;
$query = $this->db_onedev->query($sql, array($q['search'], $q['search'], $M_MouID));
}
// echo $this->db_onedev->last_query();
// exit;
$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_packet count", $this->db_onedev);
exit;
}
if (isset($prm['Mgm_McuID'])) {
$query = "SELECT
T_PacketID as id,
T_PacketID,
T_PacketM_MouID,
T_PacketSasCode,
T_PacketName,
M_MouStartDate,
M_MouEndDate,
T_PacketSasCode as code,
T_PacketName as name,
IFNULL(Mgm_McuPacketIsActive, 'N') as T_PacketIsActive
from t_packet
LEFT join mgm_mcupacket ON T_PacketID = Mgm_McuPacketT_PacketID AND
Mgm_McuPacketMgm_McuID = ? AND Mgm_McuPacketIsActive = 'Y'
join m_mou
ON T_PacketM_MouID = M_MouID
AND T_PacketIsActive = 'Y'
AND M_MouIsActive = 'Y'
AND (
T_PacketSasCode LIKE ?
OR T_PacketName LIKE ?
)
AND T_PacketM_MouID = ?
ORDER BY T_PacketSasCode ASC
limit $number_limit offset $number_offset
";
//echo $query;
$rows = $this->db_onedev->query($query, array($prm["Mgm_McuID"], $q['search'], $q['search'], $M_MouID))->result_array();
} else {
$query = "SELECT
T_PacketID as id,
T_PacketID,
T_PacketM_MouID,
T_PacketSasCode,
T_PacketName,
M_MouStartDate,
M_MouEndDate,
T_PacketSasCode as code,
T_PacketName as name,
'N' as T_PacketIsActive
from t_packet
join m_mou
ON T_PacketM_MouID = M_MouID
AND T_PacketIsActive = 'Y'
AND M_MouIsActive = 'Y'
AND (
T_PacketSasCode LIKE ?
OR T_PacketName LIKE ?
)
AND T_PacketM_MouID = ?
ORDER BY T_PacketSasCode ASC
limit $number_limit offset $number_offset
";
$rows = $this->db_onedev->query($query, array($q['search'], $q['search'], $M_MouID))->result_array();
}
$result = array(
"total" => $tot_page,
"records" => $rows,
);
$this->sys_ok($result);
exit;
}
function getusermcu()
{
if (!$this->isLogin) {
$this->sys_error("Invalid Token");
exit;
}
$userid = $this->sys_user["M_UserID"];
$prm = $this->sys_input;
$Mgm_McuID = $prm["Mgm_McuID"];
$sql = "SELECT Mgm_McuUserID,
Mgm_McuUserMgm_McuID,
Mgm_McuUserEmail,
Mgm_McuUserPassword,
'N' as chex
FROM mgm_mcuuser
WHERE Mgm_McuUserIsActive = 'Y'
AND Mgm_McuUserMgm_McuID = ?";
$qry = $this->db_onedev->query($sql, array($Mgm_McuID));
if ($qry) {
$rows = $qry->result_array();
} else {
$this->sys_error_db('select mgm_mcuuser error', $this->db_onedev);
exit;
}
if ($rows) {
foreach ($rows as $k => $v) {
$rows[$k]['chex'] = $v['chex'] == 'N' ? false : true;
}
}
$result = array(
"total" => count($rows),
"records" => $rows,
"xdate" => date("Y-m-d H:i:s")
);
$this->sys_ok($result);
}
function getemailresult()
{
if (!$this->isLogin) {
$this->sys_error("Invalid Token");
exit;
}
$prm = $this->sys_input;
$Mgm_McuID = $prm["Mgm_McuID"];
$company_id = $prm["company_id"];
$sql = "SELECT *
FROM mgm_mcuemailresult
JOIN mgm_mcu ON Mgm_McuEmailResultMgm_McuID = Mgm_McuID
JOIN m_company ON Mgm_McuM_CompanyID = M_CompanyID
WHERE
Mgm_McuEmailResultMgm_McuID = ? AND
Mgm_McuEmailResultIsActive = 'Y'";
$qry = $this->db_onedev->query($sql, array($Mgm_McuID));
//echo $this->db_onedev->last_query();
//exit;
$rows = $qry->result_array();
if (count($rows) == 0) {
$sql = "SELECT * ,
0 as Mgm_McuEmailResultID,
'Y' as Mgm_McuEmailResultIsPatientEmail,
'' as Mgm_McuEmailResultValue
FROM m_company
WHERE M_CompanyIsActive = 'Y'
AND M_CompanyID = ?";
$qry = $this->db_onedev->query($sql, array($company_id));
$rows = $qry->result_array();
}
$result = array(
"total" => count($rows),
"records" => $rows[0],
);
$this->sys_ok($result);
}
function savesetup()
{
if (!$this->isLogin) {
$this->sys_error("Invalid Token");
exit;
}
$this->db_onedev->trans_begin();
$userid = $this->sys_user["M_UserID"];
$prm = $this->sys_input;
$companyID = $prm['companyID']['id'];
$Mgm_McuNumber = "";
$Mgm_McuNumberNational = "";
$Mgm_McuNote = $prm['Mgm_McuNote'];
$Mgm_McuLabel = strtoupper($prm['Mgm_McuLabel']);
$Mgm_McuStartDate = date('Y-m-d', strtotime($prm["Mgm_McuStartDate"]));
$Mgm_McuEndDate = date('Y-m-d', strtotime($prm["Mgm_McuEndDate"]));
$agreements = $prm['agreements'];
$mou_ids = [];
foreach ($agreements as $agreement) {
$mou_ids[] = $agreement["id"];
}
$promise_date = date('Y-m-d', strtotime($prm["promise_date"]));
$promise_time = date('H:i:s', strtotime($prm["promise_time"]));
$promise_day = $prm['promise_day'];
$selected_typepromise = $prm['selected_typepromise'];
$mgm_mcuemailresult = $prm['mgm_mcuemailresult'];
$last_id = 0;
$json_before = [];
$json_after = [];
if ($prm["act"] == 'new') {
$sqlCheck = "SELECT *
FROM mgm_mcu
WHERE Mgm_McuIsActive = 'Y'
AND Mgm_McuLabel = '$Mgm_McuLabel'";
$qryCheck = $this->db_onedev->query($sqlCheck);
if (!$qryCheck) {
$this->sys_error_db("mgm_mcu check", $this->db_onedev);
exit;
}
$rowCheck = $qryCheck->result_array();
if (count($rowCheck) > 0) {
$this->sys_error("Data dengan setup mcu " . $Mgm_McuLabel . " Sudah Ada");
exit;
}
// get numbering
$sql_get_numbering = "SELECT fn_numbering_ibl('SM') as numberx";
$qry_get_numbering = $this->db_onedev->query($sql_get_numbering);
if (!$qry_get_numbering) {
$this->db_onedev->trans_rollback();
$this->sys_error_db("mgm_mcu numbering error", $this->db_onedev);
exit;
}
$data_numbering = $qry_get_numbering->result_array();
$Mgm_McuNumber = $data_numbering[0]['numberx'];
// insert mgm_mcu (Mgm_McuPublicUUID = token URL form preregister, diisi saat insert)
$sql_mgmmcu = "INSERT INTO mgm_mcu (
Mgm_McuLabel,
Mgm_McuM_CompanyID,
Mgm_McuNumber,
Mgm_McuPublicUUID,
Mgm_McuStartDate,
Mgm_McuEndDate,
Mgm_McuNote,
Mgm_McuCreated,
Mgm_McuCreatedUserID
)
VALUES(?,?,?, UUID(),?,?,?,NOW(),?)
";
$qry = $this->db_onedev->query($sql_mgmmcu, array(
$Mgm_McuLabel,
$companyID,
$Mgm_McuNumber,
$Mgm_McuStartDate,
$Mgm_McuEndDate,
$Mgm_McuNote,
$userid
));
if (!$qry) {
$this->db_onedev->trans_rollback();
$this->sys_error_db("mgm_mcu insert", $this->db_onedev);
exit;
}
$last_id = $this->db_onedev->insert_id();
// promise
if ($selected_typepromise == 'D') {
$sql_promise = "INSERT INTO mgm_mcuresultpromise(
Mgm_McuResultPromiseMgm_McuID,
Mgm_McuResultPromiseType,
Mgm_McuResultPromiseValue,
Mgm_McuResultPromiseCreated,
Mgm_McuResultPromiseCreatedUserID
) VALUES(?,?,?,NOW(),?)";
$qry_promise = $this->db_onedev->query($sql_promise, array(
$last_id,
$selected_typepromise,
$promise_day,
$userid
));
if (!$qry_promise) {
$this->db_onedev->trans_rollback();
$this->sys_error_db("mgm_mcuresultpromise insert", $this->db_onedev);
exit;
}
} else if ($selected_typepromise == 'T') {
$sql_promise = "INSERT INTO mgm_mcuresultpromise(
Mgm_McuResultPromiseMgm_McuID,
Mgm_McuResultPromiseType,
Mgm_McuResultPromiseDate,
Mgm_McuResultPromiseTime,
Mgm_McuResultPromiseCreated,
Mgm_McuResultPromiseCreatedUserID
) VALUES(?,?,?,?,NOW(),?)";
$qry_promise = $this->db_onedev->query($sql_promise, array(
$last_id,
$selected_typepromise,
$promise_date,
$promise_time,
$userid
));
if (!$qry_promise) {
$this->db_onedev->trans_rollback();
$this->sys_error_db("mgm_mcuresultpromise insert", $this->db_onedev);
exit;
}
}
}
else {
// var_dump($prm);
// check data password for update
// check paket exists or not
$last_id = $prm["xid"];
$sql = "SELECT *
FROM mgm_mcu
LEFT JOIN mgm_mcupacket ON Mgm_McuID = Mgm_McuPacketMgm_McuID AND Mgm_McuPacketIsActive = 'Y'
LEFT JOIN t_packet ON Mgm_McuPacketT_PacketID = T_PacketID
LEFT JOIN mgm_mcutemplate ON Mgm_McuID = Mgm_McuTemplateMgm_McuID AND Mgm_McuTemplateIsActive = 'Y'
LEFT JOIN mgm_mcuemailresult ON Mgm_McuEmailResultMgm_McuID = Mgm_McuID AND Mgm_McuEmailResultIsActive = 'Y'
LEFT JOIN mgm_mcuduatahunan ON Mgm_McuDuaTahunanMgm_McuID = Mgm_McuID AND Mgm_McuDuaTahunanIsActive = 'Y'
LEFT JOIN mgm_mcuuser ON Mgm_McuUserMgm_McuID = Mgm_McuID AND Mgm_McuUserIsActive = 'Y'
LEFT JOIN mgm_mcudelivery ON Mgm_McuDeliveryMgm_McuID = Mgm_McuID AND Mgm_McuDeliveryIsActive = 'Y'
LEFT JOIN mgm_mcuresultpromise ON Mgm_McuResultPromiseMgm_McuID = Mgm_McuID AND Mgm_McuResultPromiseIsActive = 'Y'
WHERE
Mgm_McuID = $last_id";
$qry = $this->db_onedev->query($sql);
if (!$qry) {
$this->db_onedev->trans_rollback();
$this->sys_error_db("mgm_mcu select", $this->db_onedev);
exit;
}
$dt_before = $qry->result_array();
$json_before = json_encode($dt_before);
$sqlCheck = "SELECT *
FROM mgm_mcu
WHERE Mgm_McuIsActive = 'Y'
AND Mgm_McuLabel = '$Mgm_McuLabel'
AND Mgm_McuID <> {$prm["xid"]}";
$qryCheck = $this->db_onedev->query($sqlCheck);
if (!$qryCheck) {
$this->sys_error_db("mgm_mcu check", $this->db_onedev);
exit;
}
$rowCheck = $qryCheck->result_array();
if (count($rowCheck) > 0) {
// echo $sqlCheck;
// exit;
$this->sys_error("Data dengan setup mcu " . $Mgm_McuLabel . " Sudah Ada");
exit;
}
$sql_check = "SELECT *
FROM mgm_mcu
WHERE Mgm_McuID = {$prm["xid"]}";
$qry_check = $this->db_onedev->query($sql_check);
if (!$qry_check) {
$this->db_onedev->trans_rollback();
$this->sys_error_db("mgm_mcu select check", $this->db_onedev);
exit;
}
$rowx = $qry_check->row_array();
// update mgmmcu
$sql_mgmmcu = "UPDATE mgm_mcu
SET
Mgm_McuLabel = ?,
Mgm_McuM_CompanyID = ?,
Mgm_McuNote = ?,
Mgm_McuStartDate = ?,
Mgm_McuEndDate = ?,
Mgm_McuLastUpdated = NOW(),
Mgm_McuLastUpdatedUserID = ?
WHERE
Mgm_McuID = ?
";
$qry = $this->db_onedev->query($sql_mgmmcu, array(
$Mgm_McuLabel,
$companyID,
$Mgm_McuNote,
$Mgm_McuStartDate,
$Mgm_McuEndDate,
$userid,
$prm["xid"]
));
if (!$qry) {
$this->db_onedev->trans_rollback();
$this->sys_error_db("mgm_mcu update", $this->db_onedev);
exit;
}
$last_id = $prm["xid"];
// promise
$sql_promise = "UPDATE mgm_mcuresultpromise SET
Mgm_McuResultPromiseIsActive = 'N',
Mgm_McuResultPromiseDeleted = NOW(),
Mgm_McuResultPromiseDeletedUserID = ?
WHERE Mgm_McuResultPromiseMgm_McuID = ?";
$qry_promise = $this->db_onedev->query($sql_promise, array(
$userid,
$last_id
));
if (!$qry_promise) {
$this->db_onedev->trans_rollback();
$this->sys_error_db("mgm_mcuresultpromise update", $this->db_onedev);
exit;
}
if ($selected_typepromise == 'D') {
$sql_promise = "INSERT INTO mgm_mcuresultpromise(
Mgm_McuResultPromiseMgm_McuID,
Mgm_McuResultPromiseType,
Mgm_McuResultPromiseValue,
Mgm_McuResultPromiseCreated,
Mgm_McuResultPromiseCreatedUserID
) VALUES(?,?,?,NOW(),?)";
$qry_promise = $this->db_onedev->query($sql_promise, array(
$last_id,
$selected_typepromise,
$promise_day,
$userid
));
if (!$qry_promise) {
$this->db_onedev->trans_rollback();
$this->sys_error_db("mgm_mcuresultpromise insert", $this->db_onedev);
exit;
}
} else if ($selected_typepromise == 'T') {
$sql_promise = "INSERT INTO mgm_mcuresultpromise(
Mgm_McuResultPromiseMgm_McuID,
Mgm_McuResultPromiseType,
Mgm_McuResultPromiseDate,
Mgm_McuResultPromiseTime,
Mgm_McuResultPromiseCreated,
Mgm_McuResultPromiseCreatedUserID
) VALUES(?,?,?,?,NOW(),?)";
$qry_promise = $this->db_onedev->query($sql_promise, array(
$last_id,
$selected_typepromise,
$promise_date,
$promise_time,
$userid
));
if (!$qry_promise) {
$this->db_onedev->trans_rollback();
$this->sys_error_db("mgm_mcuresultpromise insert", $this->db_onedev);
exit;
}
}
}
if(count($prm['selected_packets']) > 0){
$sql = "SELECT * FROM mgm_mcupacket WHERE Mgm_McuPacketMgm_McuID = ? AND Mgm_McuPacketIsActive = 'Y'";
$qry = $this->db_onedev->query($sql, array($last_id));
if (!$qry) {
$this->db_onedev->trans_rollback();
$this->sys_error_db("mgm_mcupacket select", $this->db_onedev);
exit;
}
$rows_packet = $qry->result_array();
$before_packet = [];
if (count($rows_packet) > 0) {
foreach ($rows_packet as $key => $val) {
$before_packet[] = $val['Mgm_McuPacketT_PacketID'];
}
}
$after_packet = [];
// insert mgm_mcupacket
foreach ($prm['selected_packets'] as $kp => $vp) {
$Mgm_McuPacketT_PacketID = $vp['id'];
if (!in_array($Mgm_McuPacketT_PacketID, $before_packet)) {
$sql_mgm_mcupacket = "INSERT INTO mgm_mcupacket (
Mgm_McuPacketMgm_McuID,
Mgm_McuPacketT_PacketID,
Mgm_McuPacketIsActive,
Mgm_McuPacketCreated,
Mgm_McuPacketCreatedUserID
) VALUES (?,?,'Y',NOW(),?)";
$qry_mgm_mcupacket = $this->db_onedev->query($sql_mgm_mcupacket, array(
$last_id,
$Mgm_McuPacketT_PacketID,
$userid
));
if (!$qry_mgm_mcupacket) {
$this->db_onedev->trans_rollback();
$this->sys_error_db("mgm_mcupacket insert", $this->db_onedev);
exit;
}
}
$after_packet[] = $Mgm_McuPacketT_PacketID;
}
$delete_packet = array_diff($before_packet, $after_packet);
if (count($delete_packet) > 0) {
$sql_delete_packet = "UPDATE mgm_mcupacket SET
Mgm_McuPacketIsActive = 'N',
Mgm_McuPacketLastUpdated = NOW(),
Mgm_McuPacketLastUpdatedUserID = ?
WHERE Mgm_McuPacketMgm_McuID = ? AND
Mgm_McuPacketT_PacketID IN ('" . implode("','", $delete_packet) . "')";
$qry_delete_packet = $this->db_onedev->query($sql_delete_packet, array($userid, $last_id));
if (!$qry_delete_packet) {
$this->db_onedev->trans_rollback();
$this->sys_error_db("mgm_mcupacket delete", $this->db_onedev);
exit;
}
}
}
if (isset($prm['mgm_mcuemailresult'])) {
$sql = "SELECT * FROM mgm_mcuemailresult WHERE Mgm_McuEmailResultMgm_McuID = $last_id AND Mgm_McuEmailResultIsActive = 'Y'";
$qry = $this->db_onedev->query($sql);
if ($qry->num_rows() > 0) {
$sql_mgm_mcuemailresult = "UPDATE mgm_mcuemailresult SET
Mgm_McuEmailResultIsPatientEmail = ?,
Mgm_McuEmailResultValue = ?,
Mgm_McuEmailResultIsActive = 'Y',
Mgm_McuEmailResultLastUpdated = NOW(),
Mgm_McuEmailResultLastUpdatedUserID = ?
WHERE Mgm_McuEmailResultMgm_McuID = ?";
$qry = $this->db_onedev->query($sql_mgm_mcuemailresult, [
$prm['mgm_mcuemailresult']['Mgm_McuEmailResultIsPatientEmail'],
$prm['mgm_mcuemailresult']['Mgm_McuEmailResultValue'],
$userid,
$last_id
]);
//echo $this->db_onedev->last_query();
//echo "UPDATE";
//exit;
if (!$qry) {
$this->db_onedev->trans_rollback();
$this->sys_error_db("mgm_mcuemailresult update", $this->db_onedev);
exit;
}
} else {
$sql_mgm_mcuemailresult = "INSERT INTO mgm_mcuemailresult (
Mgm_McuEmailResultMgm_McuID,
Mgm_McuEmailResultIsPatientEmail,
Mgm_McuEmailResultValue,
Mgm_McuEmailResultCreated,
Mgm_McuEmailResultCreatedUserID
) VALUES (
?,
?,
?,
NOW(),
?
)";
$qry = $this->db_onedev->query($sql_mgm_mcuemailresult, [
$last_id,
$prm['mgm_mcuemailresult']['Mgm_McuEmailResultIsPatientEmail'],
$prm['mgm_mcuemailresult']['Mgm_McuEmailResultValue'],
$userid
]);
//echo $this->db_onedev->last_query();
//echo "NEW";
//exit;
}
}
if(count($mou_ids) > 0){
$sql = "UPDATE mgm_mou SET Mgm_MouIsActive = 'X'
WHERE
Mgm_MouMgm_McuID = ? AND Mgm_MouIsActive = 'Y'";
$qry = $this->db_onedev->query($sql, [$last_id]);
if (!$qry) {
$this->db_onedev->trans_rollback();
$this->sys_error_db("mgm_mou update", $this->db_onedev);
exit;
}
foreach($mou_ids as $mou_id){
$sql = "SELECT * FROM mgm_mou WHERE Mgm_MouMgm_McuID = ? AND Mgm_MouM_MouID = ? AND Mgm_MouIsActive = 'Y'";
$qry = $this->db_onedev->query($sql, [$last_id, $mou_id]);
if (!$qry) {
$this->db_onedev->trans_rollback();
$this->sys_error_db("mgm_mou select", $this->db_onedev);
exit;
}
$existing_mou = $qry->result_array();
///print_r($existing_mou);
//echo $this->db_onedev->last_query();
if(count($existing_mou) > 0){
$sql = "UPDATE mgm_mou SET Mgm_MouIsActive = 'Y'
WHERE
Mgm_MouMgm_McuID = ? AND Mgm_MouM_MouID = ? AND Mgm_MouIsActive = 'X'";
$qry = $this->db_onedev->query($sql, [$last_id, $mou_id]);
if (!$qry) {
$this->db_onedev->trans_rollback();
$this->sys_error_db("mgm_mou update", $this->db_onedev);
exit;
}
//echo $this->db_onedev->last_query();
}else{
$sql = "INSERT INTO mgm_mou (
Mgm_MouMgm_McuID,
Mgm_MouM_MouID,
Mgm_MouCreated,
Mgm_MouCreatedUserID
) VALUES (?,?,NOW(),?)";
$qry = $this->db_onedev->query($sql, [$last_id, $mou_id, $userid]);
if (!$qry) {
$this->db_onedev->trans_rollback();
$this->sys_error_db("mgm_mou insert", $this->db_onedev);
exit;
}
//echo $this->db_onedev->last_query();
}
$sql = "UPDATE mgm_mou SET Mgm_MouIsActive = 'N', Mgm_MouDeleted = NOW(), Mgm_MouDeletedUserID = ?
WHERE Mgm_MouMgm_McuID = ? AND Mgm_MouIsActive = 'X'";
$qry = $this->db_onedev->query($sql, [$userid, $last_id]);
if (!$qry) {
$this->db_onedev->trans_rollback();
$this->sys_error_db("mgm_mou update", $this->db_onedev);
exit;
}
}
}
$sql = "SELECT *
FROM mgm_mcu
LEFT JOIN mgm_mcupacket ON Mgm_McuID = Mgm_McuPacketMgm_McuID AND Mgm_McuPacketIsActive = 'Y'
LEFT JOIN t_packet ON Mgm_McuPacketT_PacketID = T_PacketID
LEFT JOIN mgm_mcuemailresult ON Mgm_McuEmailResultMgm_McuID = Mgm_McuID AND Mgm_McuEmailResultIsActive = 'Y'
LEFT JOIN mgm_mcuresultpromise ON Mgm_McuResultPromiseMgm_McuID = Mgm_McuID AND Mgm_McuResultPromiseIsActive = 'Y'
LEFT JOIN mgm_mou ON Mgm_MouMgm_McuID = Mgm_McuID AND Mgm_MouIsActive = 'Y'
WHERE
Mgm_McuID = $last_id";
$qry = $this->db_onedev->query($sql);
if (!$qry) {
$this->db_onedev->trans_rollback();
$this->sys_error_db("mgm_mcu select", $this->db_onedev);
exit;
}
$dt_after = $qry->result_array();
$json_after = json_encode($dt_after);
$sql = "INSERT INTO log_mgm_mcu (
Log_MgmMcuMgm_McuID,
Log_MgmMcuJSONBefore,
Log_MgmMcuJSONAfter,
Log_MgmMcuCreated,
Log_MgmMcuCreatedUserID
) VALUES (
$last_id,
'{$json_before}',
'{$json_after}',
NOW(),
{$userid}
)";
$qry_log = $this->db_log->query($sql);
if (!$qry_log) {
//echo $this->db_onedev->last_query();
//$this->db_onedev->trans_rollback();
$this->sys_error_db("log_mgm_mcu insert", $this->db_log);
exit;
}
$sql = "SELECT Mgm_McuNumber as xnumber
FROM mgm_mcu
WHERE Mgm_McuID = {$last_id}";
//echo $sql;
$row = $this->db_onedev->query($sql)->row_array();
$this->db_onedev->trans_commit();
$result = array(
"total" => 1,
"records" => $row,
"last_id" => $last_id
);
$this->sys_ok($result);
exit;
}
function deletemcu()
{
if (!$this->isLogin) {
$this->sys_error("Invalid Token");
exit;
}
$userid = $this->sys_user["M_UserID"];
$prm = $this->sys_input;
// mcu
$query_mgmmcu = $this->db_onedev->query("UPDATE mgm_mcu SET
Mgm_McuIsActive = 'N',
Mgm_McuLastDeletedUserID = {$userid},
Mgm_McuLastDeleted = NOW()
WHERE
Mgm_McuID = '{$prm['id']}'
");
if (!$query_mgmmcu) {
$this->db_onedev->trans_rollback();
$this->sys_error_db("mgm_mcu delete cpone eror", $this->db_onedev);
exit;
}
// packet
$query_mgmmcu_packet = $this->db_onedev->query("UPDATE mgm_mcupacket SET
Mgm_McuPacketIsActive = 'N',
Mgm_McuPacketDeleted = NOW(),
Mgm_McuPacketDeletedUserID = {$userid}
WHERE
Mgm_McuPacketMgm_McuID = '{$prm['id']}'
");
if (!$query_mgmmcu_packet) {
$this->db_onedev->trans_rollback();
$this->sys_error_db("mgm_mcu paket delete cpone eror", $this->db_onedev);
exit;
}
// template
$query_mgm_mcutemplate = $this->db_onedev->query("UPDATE
mgm_mcutemplate SET
Mgm_McuTemplateIsActive = 'N',
Mgm_McuTemplateDelete = NOW(),
Mgm_McuTemplateDeletedUserID = {$userid}
WHERE
Mgm_McuTemplateMgm_McuID = '{$prm['id']}'
");
if (!$query_mgm_mcutemplate) {
$this->db_onedev->trans_rollback();
$this->sys_error_db("mgm_mcu templete delete cpone eror", $this->db_onedev);
exit;
}
// $rows = $this->db_onedev->query($query_mgmmcu);
$result = array(
"total" => 1,
"records" => array('status' => 'OK')
);
$this->sys_ok($result);
exit;
}
function getDetailPacketByID()
{
if (!$this->isLogin) {
$this->sys_error("Invalid Token");
exit;
}
$userid = $this->sys_user["M_UserID"];
$prm = $this->sys_input;
$T_PacketID = $prm['T_PacketID'];
$sql = "SELECT
pd.T_PacketDetailID,
pd.T_PacketDetailT_PacketID,
pd.T_PacketDetailT_TestID,
pd.T_PacketDetailOriginalPrice,
pd.T_PacketDetailPrice,
pd.T_PacketDetailIsActive,
pd.T_PacketDetailCreated,
pd.T_PacketDetailLastUpdated,
pd.T_PacketDetailPriceAmount,
pd.T_PacketDetailPriceDisc,
pd.T_PacketDetailPriceDiscRp,
pd.T_PacketDetailPriceSubTotal,
t.T_TestID,
t.T_TestNat_GroupID,
t.T_TestNat_SubgroupID,
t.T_TestParentT_TestID,
t.T_TestCode,
t.T_TestSasCode,
t.T_TestName,
t.T_TestShortName,
t.T_TestShortNameBarcode,
t.T_TestWorklistName,
t.T_TestNat_TestID,
t.T_TestRequirement,
t.T_TestIsParent,
t.T_TestFontSize,
t.T_TestFontColor,
t.T_TestIsBold,
t.T_TestIsItalic,
t.T_TestT_SampleTypeID,
t.T_TestResultPosition,
t.T_TestNormalValue,
t.T_TestFlagGluc,
t.T_TestIsQuantitative,
t.T_TestIsPrintNota,
t.T_TestIsResult,
t.T_TestIsPrintResult,
t.T_TestIsPrice,
t.T_TestForceSell,
t.T_TestIsWorklist,
t.T_TestIsNonLab,
t.T_TestIsDeltaCheck,
t.T_TestIsTrendAnalysis,
t.T_TestLeftMargin,
t.T_TestCreated,
t.T_TestLastUpdated,
t.T_TestIsActive,
t.T_TestMaxDiscount,
t.T_TestFlagLow,
t.T_TestFlagHigh,
t.T_TestUserID,
t.T_TestFlagMCU,
t.T_TestNat_SubSubGroupID,
t.T_TestCreatedUserID,
t.T_TestLastUpdatedUserID,
t.T_TestDeleted,
t.T_TestDeletedUserID
FROM
t_packetdetail as pd
JOIN
t_test as t
ON
pd.T_PacketDetailT_TestID = t.T_TestID
AND t.T_TestIsActive = 'Y'
AND pd.T_PacketDetailIsActive = 'Y'
AND pd.T_PacketDetailT_PacketID = ?";
$qry = $this->db_onedev->query($sql, array($T_PacketID));
if (!$qry) {
$this->sys_error_db("list packet", $this->db_onedev);
exit;
}
$rows = $qry->result_array();
$result = array(
// "total" => $tot_page,
"records" => $rows,
);
$this->sys_ok($result);
exit;
}
function getTPriceHeaderCurrent()
{
try {
if (!$this->isLogin) {
$this->sys_error("Invalid Token");
exit;
}
$prm = $this->sys_input;
$sql = "SELECT
IFNULL(T_PriceHeaderID, 0) AS T_PriceHeaderID,
IFNULL(T_PriceHeaderName, '') AS T_PriceHeaderName,
IFNULL(T_PriceHeaderStartDate, '0000-00-00') AS T_PriceHeaderStartDate,
IFNULL(T_PriceHeaderEndDate, '0000-00-00') AS T_PriceHeaderEndDate,
IFNULL(T_PriceHeaderIsActive, 'Y') AS T_PriceHeaderIsActive,
IFNULL(T_PriceHeaderUserID, 0) AS T_PriceHeaderUserID,
IFNULL(T_PriceHeaderCreated, '0000-00-00 00:00:00') AS T_PriceHeaderCreated,
IFNULL(T_PriceHeaderCraetdUserID, 0) AS T_PriceHeaderCraetdUserID,
IFNULL(T_PriceHeaderLastUpdated, '0000-00-00 00:00:00') AS T_PriceHeaderLastUpdated,
IFNULL(T_PriceHeaderLastUpdatedUserID, 0) AS T_PriceHeaderLastUpdatedUserID,
IFNULL(T_PriceHeaderDeleted, '0000-00-00 00:00:00') AS T_PriceHeaderDeleted,
IFNULL(T_PriceHeaderDeletedUserID, 0) AS T_PriceHeaderDeletedUserID
FROM
t_priceheader
WHERE T_PriceHeaderIsActive = 'Y'
-- AND CURDATE() BETWEEN T_PriceHeaderStartDate AND T_PriceHeaderEndDate
";
$qry = $this->db_onedev->query($sql);
if (!$qry) {
$this->sys_error_db("t_priceheader select error", $this->db_onedev);
exit;
}
$rows = $qry->result_array();
$result = array(
"records" => $rows,
"sql" => $this->db_onedev->last_query()
);
$this->sys_ok($result);
} catch (Exception $exc) {
$message = $exc->getMessage();
$this->sys_error($message);
}
}
function getBranch()
{
try {
if (!$this->isLogin) {
$this->sys_error("Invalid Token");
exit;
}
$prm = $this->sys_input;
$sql = "SELECT
M_BranchID,
IFNULL(M_BranchCode, '') AS M_BranchCode,
-- IFNULL(M_BranchName, '') AS M_BranchName,
CONCAT(IFNULL(M_BranchCode, ''), ' - ', IFNULL(M_BranchName, '')) AS M_BranchName,
IFNULL(M_BranchAddress, '') AS M_BranchAddress,
IFNULL(M_BranchIsActive, 'Y') AS M_BranchIsActive,
IFNULL(M_BranchCreated, '0000-00-00 00:00:00') AS M_BranchCreated,
IFNULL(M_BranchUserID, 0) AS M_BranchUserID,
IFNULL(M_BranchLastUpdated, '0000-00-00 00:00:00') AS M_BranchLastUpdated
FROM
m_branch
WHERE
M_BranchIsActive = 'Y'";
$qry = $this->db_onedev->query($sql);
if (!$qry) {
$this->sys_error_db("m_branch select error", $this->db_onedev);
exit;
}
$rows = $qry->result_array();
$rows[] = array(
'M_BranchID' => '100',
'M_BranchCode' => '',
'M_BranchName' => 'Sesuai branch login',
'M_BranchAddress' => '',
'M_BranchIsActive' => 'Y',
'M_BranchCreated' => '',
'M_BranchUserID' => '',
'M_BranchLastUpdated' => ''
);
$result = array(
"records" => $rows,
"sql" => $this->db_onedev->last_query()
);
$this->sys_ok($result);
} catch (Exception $exc) {
$message = $exc->getMessage();
$this->sys_error($message);
}
}
function getmou()
{
//# cek token valid
if (!$this->isLogin) {
$this->sys_error("Invalid Token");
exit;
}
$prm = $this->sys_input;
//$prm['start_date'] = strtotime($prm['start_date']);
//$prm['end_date'] = strtotime($prm['end_date']);
$query = " SELECT M_MouID as id, M_MouName as name, M_MouNumber as code
FROM m_mou
WHERE
M_MouM_CompanyID = {$prm['id']} AND
M_MouIsActive = 'Y' AND
(
( '{$prm['start_date']}' BETWEEN M_MouStartDate AND M_MouEndDate ) AND
( '{$prm['end_date']}' BETWEEN M_MouStartDate AND M_MouEndDate )
) AND
M_MouIsReleased = 'Y'
";
//echo $query;
$rows = $this->db_onedev->query($query)->result_array();
$result = array(
"total" => count($rows),
"records" => $rows,
);
$this->sys_ok($result);
exit;
}
// function createSSMou()
// {
// if (! $this->isLogin) {
// $this->sys_error("Invalid Token");
// exit;
// }
// $userid = $this->sys_user["M_UserID"];
// $prm = $this->sys_input;
// $id = $prm['T_PriceHeaderID'];
// if(empty($id) || !isset($prm['T_PriceHeaderID'])){
// $this->sys_error("Belum ada price header id");
// exit;
// } else{
// $x = $this->sspricemou->create($id);
// if($x){
// $result = array(
// "records" => $id,
// "sql" => $this->db_onedev->last_query()
// );
// $this->sys_ok($result);
// exit;
// }
// }
// }
// cpone
function getdatapackets()
{
if (!$this->isLogin) {
$this->sys_error("Invalid Token");
exit;
}
$prm = $this->sys_input;
$search = $prm["searchPacket"];
$number_limit = 10;
$number_offset = ($prm['current_page'] - 1) * $number_limit;
$agreements = $prm["agreements"]?$prm["agreements"]:[];
$mou_ids = [];
foreach ($agreements as $agreement) {
$mou_ids[] = $agreement["id"];
}
$mou_string = implode(",", $mou_ids);
$sql = "SELECT count(*) as total
FROM (
SELECT T_PacketID as id, T_PacketName as name, T_PacketSasCode as code
FROM ss_price_mou
JOIN t_packet ON T_TestID = T_PacketID AND T_PacketIsActive = 'Y'
WHERE
Ss_PriceMouM_MouID IN ({$mou_string}) AND is_packet = 'Y' AND
( T_TestName LIKE CONCAT('%','{$search}','%') )
) x
";
//echo $sql;
$query = $this->db_onedev->query($sql, $sql_param);
$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("m_doctor count", $this->db_onedev);
exit;
}
$query = "SELECT T_PacketID as id, T_PacketName as name, T_PacketSasCode as code, nat_test
FROM ss_price_mou
JOIN t_packet ON T_TestID = T_PacketID AND T_PacketIsActive = 'Y'
WHERE
Ss_PriceMouM_MouID IN ({$mou_string}) AND is_packet = 'Y' AND
( T_TestName LIKE CONCAT('%','{$search}','%') OR T_PacketName LIKE CONCAT('%','{$search}','%') )
ORDER BY T_PacketSasCode ASC
limit $number_limit offset $number_offset
";
//echo $query;
$rows = $this->db_onedev->query($query)->result_array();
if ($rows) {
foreach ($rows as $kp => $vp) {
$rows[$kp]['nat_test'] = json_decode($vp['nat_test']);
}
}
$result = array(
"total" => $tot_page,
"records" => $rows,
);
$this->sys_ok($result);
exit;
}
function getdatatests()
{
if (!$this->isLogin) {
$this->sys_error("Invalid Token");
exit;
}
$prm = $this->sys_input;
$search = $prm["search"];
$number_limit = 10;
$number_offset = ($prm['current_page'] - 1) * $number_limit;
$sql = "SELECT count(*) as total
FROM (
SELECT test.T_TestID as id, test.T_TestName as name, test.T_TestSasCode as code, nat_test
FROM ss_price_mou
JOIN t_test test ON test.T_TestID = ss_price_mou.T_TestID
WHERE
Ss_PriceMouM_MouID = {$prm['id']} AND
( ss_price_mou.T_TestName LIKE CONCAT('%','{$search}','%') ) AND
T_PriceIsCito = 'N'
GROUP BY Ss_PriceMouID
) x
";
//echo $sql;
$query = $this->db_onedev->query($sql, $sql_param);
$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("m_doctor count", $this->db_onedev);
exit;
}
$query = "
SELECT test.T_TestID as id, test.T_TestName as name, test.T_TestSasCode as code, nat_test
FROM ss_price_mou
JOIN t_test test ON test.T_TestID = ss_price_mou.T_TestID AND is_packet = 'N'
WHERE
Ss_PriceMouM_MouID = {$prm['id']} AND
( ss_price_mou.T_TestName LIKE CONCAT('%','{$search}','%') ) AND
T_PriceIsCito = 'N'
GROUP BY Ss_PriceMouID
ORDER BY T_TestSasCode ASC
limit $number_limit offset $number_offset
";
//echo $query;
$rows = $this->db_onedev->query($query)->result_array();
if ($rows) {
foreach ($rows as $kp => $vp) {
$rows[$kp]['nat_test'] = json_decode($vp['nat_test']);
}
}
$result = array(
"total" => $tot_page,
"records" => $rows,
);
$this->sys_ok($result);
exit;
}
function getdeliveries()
{
//# cek token valid
if (!$this->isLogin) {
$this->sys_error("Invalid Token");
exit;
}
$prm = $this->sys_input;
$agreements = $prm['agreements'];
$mou_ids = [];
foreach ($agreements as $agreement) {
$mou_ids[] = $agreement["id"];
}
$mou_string = implode(",", $mou_ids);
$type = 'mou';
$sql = "SELECT * FROM m_mou WHERE M_MouID IN ({$mou_string}) LIMIT 1";
$data_mou = $this->db_onedev->query($sql)->row_array();
if (count($mou_ids) > 0) {
$sql = "SELECT 0 as kelurahan,
M_CompanyAddressRegionalCd as regional_cd,
M_CompanyID as address_id,
M_DeliveryM_DeliveryTypeID as delivery_type,
M_DeliveryID as delivery_id,
M_DeliveryName as delivery_name,
CONCAT(M_CompanyAddress,' ',M_CompanyAddressVillage,', ',M_CompanyAddressDistrict,', ',M_CompanyAddressCity) as description,
Mgm_McuDeliveryID,
IF(Mgm_McuDeliveryID IS NULL, 'N', 'Y') AS chex,
'' as note,
'origin' as typeform,
'{$type}' as type,
M_DeliveryTypeCode as delivery_code
FROM m_company
JOIN m_delivery ON M_DeliverySource = 'COMPANY' AND M_DeliveryIsActive = 'Y'
JOIN m_deliverytype ON M_DeliveryTypeCode = 'ADDRESS' AND M_DeliveryM_DeliveryTypeID = M_DeliveryTypeID
LEFT JOIN mgm_mcudelivery ON Mgm_McuDeliveryM_DeliveryID = M_DeliveryID
AND Mgm_McuDeliveryMgm_McuID = {$prm['Mgm_McuID']} AND Mgm_McuDeliveryIsActive = 'Y'
WHERE
M_CompanyID = {$data_mou['M_MouM_CompanyID']}
UNION
SELECT 0 as kelurahan,
'' as regional_cd,
0 as address_id,
M_DeliveryM_DeliveryTypeID as delivery_type,
M_DeliveryID as delivery_id,
M_DeliveryName as delivery_name,
IF(ISNULL(M_CompanyEmail) OR M_CompanyEmail = '', 'Belum ada email perusahaan', M_CompanyEmail) as description,
Mgm_McuDeliveryID,
IF(Mgm_McuDeliveryID IS NULL, 'N', 'Y') AS chex,
'' as note,
'origin' as typeform,
'{$type}' as type,
M_DeliveryTypeCode as delivery_code
FROM m_company
JOIN m_delivery ON M_DeliverySource = 'COMPANY' AND M_DeliveryIsActive = 'Y'
JOIN m_deliverytype ON M_DeliveryTypeCode = 'EMAIL' AND M_DeliveryM_DeliveryTypeID = M_DeliveryTypeID
LEFT JOIN mgm_mcudelivery ON Mgm_McuDeliveryM_DeliveryID = M_DeliveryID
AND Mgm_McuDeliveryMgm_McuID = {$prm['Mgm_McuID']} AND Mgm_McuDeliveryIsActive = 'Y'
WHERE
M_CompanyID = {$data_mou['M_MouM_CompanyID']}
UNION
SELECT 0 as kelurahan,
'' as regional_cd,
0 as address_id,
M_DeliveryM_DeliveryTypeID as delivery_type,
M_DeliveryID as delivery_id,
M_DeliveryName as delivery_name,
IF(ISNULL(M_MouEmail) OR M_MouEmail = '', 'Belum ada email agreement', M_MouEmail) as description,
Mgm_McuDeliveryID,
IF(Mgm_McuDeliveryID IS NULL, 'N', 'Y') AS chex,
'' as note,
'origin' as typeform,
'{$type}' as type,
M_DeliveryTypeCode as delivery_code
FROM m_mou
JOIN m_delivery ON M_DeliverySource = '{$type}' AND M_DeliveryIsActive = 'Y'
JOIN m_deliverytype ON M_DeliveryTypeCode = 'EMAIL' AND M_DeliveryM_DeliveryTypeID = M_DeliveryTypeID
LEFT JOIN mgm_mcudelivery ON Mgm_McuDeliveryM_DeliveryID = M_DeliveryID
AND Mgm_McuDeliveryMgm_McuID = {$prm['Mgm_McuID']} AND Mgm_McuDeliveryIsActive = 'Y'
WHERE
M_MouID IN ({$mou_string})";
// echo $sql;
$qry = $this->db_onedev->query($sql, []);
if (!$qry) {
$this->sys_error_db("m_delivery select error", $this->db_onedev);
exit;
}
$rows = $qry->result_array();
} else {
$sql = "SELECT 0 as kelurahan,
M_CompanyAddressRegionalCd as regional_cd,
M_CompanyID as address_id,
M_DeliveryM_DeliveryTypeID as delivery_type,
M_DeliveryID as delivery_id,
M_DeliveryName as delivery_name,
CONCAT(M_CompanyAddress,' ',M_CompanyAddressVillage,', ',M_CompanyAddressDistrict,', ',M_CompanyAddressCity) as description,
'N' as chex,
'' as note,
'origin' as typeform,
'{$type}' as type,
M_DeliveryTypeCode as delivery_code
FROM m_company
JOIN m_delivery ON M_DeliverySource = 'COMPANY' AND M_DeliveryIsActive = 'Y'
JOIN m_deliverytype ON M_DeliveryTypeCode = 'ADDRESS' AND M_DeliveryM_DeliveryTypeID = M_DeliveryTypeID
WHERE
M_CompanyID = {$data_mou['M_MouM_CompanyID']}
UNION
SELECT 0 as kelurahan,
'' as regional_cd,
0 as address_id,
M_DeliveryM_DeliveryTypeID as delivery_type,
M_DeliveryID as delivery_id,
M_DeliveryName as delivery_name,
IF(ISNULL(M_CompanyEmail) OR M_CompanyEmail = '', 'Belum ada email perusahaan', M_CompanyEmail) as description,
'N' as chex,
'' as note,
'origin' as typeform,
'{$type}' as type,
M_DeliveryTypeCode as delivery_code
FROM m_company
JOIN m_delivery ON M_DeliverySource = 'COMPANY' AND M_DeliveryIsActive = 'Y'
JOIN m_deliverytype ON M_DeliveryTypeCode = 'EMAIL' AND M_DeliveryM_DeliveryTypeID = M_DeliveryTypeID
WHERE
M_CompanyID = {$data_mou['M_MouM_CompanyID']}
UNION
SELECT 0 as kelurahan,
'' as regional_cd,
0 as address_id,
M_DeliveryM_DeliveryTypeID as delivery_type,
M_DeliveryID as delivery_id,
M_DeliveryName as delivery_name,
IF(ISNULL(M_MouEmail) OR M_MouEmail = '', 'Belum ada email agreement', M_MouEmail) as description,
IF(M_MouEmailIsDefault = '','N',IFNULL(M_MouEmailIsDefault,'N')) as chex,
'' as note,
'origin' as typeform,
'{$type}' as type,
M_DeliveryTypeCode as delivery_code
FROM m_mou
JOIN m_delivery ON M_DeliverySource = '{$type}' AND M_DeliveryIsActive = 'Y'
JOIN m_deliverytype ON M_DeliveryTypeCode = 'EMAIL' AND M_DeliveryM_DeliveryTypeID = M_DeliveryTypeID
WHERE
M_MouID IN ({$mou_string})";
// echo $sql;
$qry = $this->db_onedev->query($sql, []);
if (!$qry) {
$this->sys_error_db("m_delivery select error", $this->db_onedev);
exit;
}
$rows = $qry->result_array();
}
$result = array(
"total" => count($rows),
"records" => $rows,
);
$this->sys_ok($result);
exit;
}
function getsexreg()
{
if (!$this->isLogin) {
$this->sys_error("Invalid Token");
exit;
}
$rows = [];
$query = " SELECT *
FROM m_title
WHERE
M_TitleIsActive = 'Y'
";
//echo $query;
$rows['titles'] = $this->db_onedev->query($query)->result_array();
$query = " SELECT *
FROM m_sex
WHERE
M_SexIsActive = 'Y'
";
//echo $query;
$rows['sexes'] = $this->db_onedev->query($query)->result_array();
$query = " SELECT *
FROM m_religion
WHERE
M_ReligionIsActive = 'Y'
";
//echo $query;
$rows['religions'] = $this->db_onedev->query($query)->result_array();
$query = " SELECT *
FROM m_idtype
WHERE
M_IdTypeIsActive = 'Y'
";
//echo $query;
$rows['kartuidentitass'] = $this->db_onedev->query($query)->result_array();
$result = array(
"total" => count($rows),
"records" => $rows,
);
$this->sys_ok($result);
exit;
}
function searchcity()
{
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(*) as total
FROM m_city
WHERE
M_CityName like ?
AND M_CityIsActive = 'Y'";
$query = $this->db_onedev->query($sql, $q['search']);
//echo $query;
if ($query) {
$tot_count = $query->result_array()[0]["total"];
} else {
$this->sys_error_db("m_city count", $this->db_onedev);
exit;
}
$sql = "
SELECT *
FROM m_city
WHERE
M_CityName like ?
AND M_CityIsActive = 'Y'
ORDER BY M_CityName DESC
";
$query = $this->db_onedev->query($sql, array($q['search']));
if ($query) {
$rows = $query->result_array();
//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_city rows", $this->db_onedev);
exit;
}
}
function filtersearchcompany()
{
//# cek token valid
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(*) as total
FROM m_company
WHERE
M_CompanyName like ?
AND M_CompanyIsActive = 'Y'";
$query = $this->db_onedev->query($sql, $q['search']);
//echo $query;
if ($query) {
$tot_count = $query->result_array()[0]["total"];
} else {
$this->sys_error_db("m_company count", $this->db_onedev);
exit;
}
$sql = "
SELECT M_CompanyID as id, M_CompanyName as name
FROM m_company
WHERE
M_CompanyName like ?
AND M_CompanyIsActive = 'Y'
ORDER BY M_CompanyName ASC
";
$query = $this->db_onedev->query($sql, array($q['search']));
if ($query) {
$rows = $query->result_array();
array_push($rows, array('id' => 0, 'name' => 'Semua'));
//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;
}
}
function searchdoctor()
{
//# cek token valid
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(*) as total
FROM m_doctor
WHERE
M_DoctorName like ?
AND M_DoctorIsActive = 'Y'";
$query = $this->db_onedev->query($sql, $q['search']);
//echo $query;
if ($query) {
$tot_count = $query->result_array()[0]["total"];
} else {
$this->sys_error_db("m_doctor count", $this->db_onedev);
exit;
}
$sql = "
SELECT M_DoctorID as id, CONCAT('[ ',M_DoctorCode,' ] ',IFNULL(M_DoctorPrefix,''),'',IFNULL(M_DoctorPrefix2,''),' ',M_DoctorName,' ',IFNULL(M_DoctorSufix,''),IFNULL(M_DoctorSufix2,''),IFNULL(M_DoctorSufix3,'')) as name, '' as xaddress
FROM m_doctor
WHERE
CONCAT('[ ',M_DoctorCode,' ] ',IFNULL(M_DoctorPrefix,''),'',IFNULL(M_DoctorPrefix2,''),' ',M_DoctorName,' ',IFNULL(M_DoctorSufix,''),IFNULL(M_DoctorSufix2,''),IFNULL(M_DoctorSufix3,'')) like '{$q['search']}'
AND M_DoctorIsActive = 'Y'
group by M_DoctorID
ORDER BY M_DoctorName ASC
LIMIT 20
";
// echo $sql;
$query = $this->db_onedev->query($sql);
if ($query) {
$rows = $query->result_array();
foreach ($rows as $k => $v) {
$sql = "SELECT M_DoctorAddressID as id, M_DoctorAddressNote as label, M_DoctorAddressDescription as description FROM m_doctoraddress WHERE M_DoctorAddressM_DoctorID = {$v['id']} AND M_DoctorAddressIsActive = 'Y'";
$rows[$k]['xaddress'] = $this->db_onedev->query($sql)->result();
}
//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_doctor rows", $this->db_onedev);
exit;
}
}
function getdistrict()
{
$prm = $this->sys_input;
$query = " SELECT *
FROM m_district
WHERE
M_DistrictIsActive = 'Y' AND M_DistrictM_CityID = ?
";
//echo $query;
$rows = $this->db_onedev->query($query, array($prm['id']))->result_array();
$result = array(
"total" => count($rows),
"records" => $rows,
);
$this->sys_ok($result);
exit;
}
function getkelurahan()
{
$prm = $this->sys_input;
$query = " SELECT *
FROM m_kelurahan
WHERE
M_KelurahanIsActive = 'Y' AND M_KelurahanM_DistrictID = ?
";
//echo $query;
$rows = $this->db_onedev->query($query, array($prm['id']))->result_array();
$result = array(
"total" => count($rows),
"records" => $rows,
);
$this->sys_ok($result);
exit;
}
function save()
{
if (!$this->isLogin) {
$this->sys_error("Invalid Token");
exit;
}
$userid = $this->sys_user["M_UserID"];
$prm = $this->sys_input;
$pdob = date('Y-m-d', strtotime($prm['M_PatientDOB']));
$query = "UPDATE m_patient SET
M_PatientM_TitleID = '{$prm['M_PatientM_TitleID']}',
M_PatientPrefix = '{$prm['M_PatientPrefix']}',
M_PatientName = '{$prm['M_PatientName']}',
M_PatientSuffix = '{$prm['M_PatientSuffix']}',
M_PatientDOB = '{$pdob}',
M_PatientM_SexID = '{$prm['M_PatientM_SexID']}',
M_PatientM_ReligionID = '{$prm['M_PatientM_ReligionID']}',
M_PatientEmail = '{$prm['M_PatientEmail']}',
M_PatientPOB = '{$prm['M_PatientPOB']}',
M_PatientHP = '{$prm['M_PatientHP']}',
M_PatientPhone = '{$prm['M_PatientPhone']}',
M_PatientM_IdTypeID = '{$prm['M_PatientM_IdTypeID']}',
M_PatientIDNumber = '{$prm['M_PatientIDNumber']}',
M_PatientNote = '{$prm['M_PatientNote']}',
M_PatientNIK = '{$prm['M_PatientNIK']}',
M_PatientJabatan = '{$prm['M_PatientJabatan']}',
M_PatientKedudukan = '{$prm['M_PatientKedudukan']}',
M_PatientPJ = '{$prm['M_PatientPJ']}',
M_PatientLocation = '{$prm['M_PatientLocation']}',
M_PatientJob = '{$prm['M_PatientJob']}'
WHERE
M_PatientID = '{$prm['M_PatientID']}'
";
//echo $query;
$rows = $this->db_onedev->query($query);
$result = array(
"total" => 1,
"records" => array('status' => 'OK')
);
$ptn = $prm;
$ptn["M_PatientDOB"] = $pdob;
$ptn = json_encode($ptn);
$this->db_onedev->query("CALL one_log.log_me('PATIENT', 'PATIENT.EDIT', '{$ptn}', $userid)");
$this->sys_ok($result);
exit;
}
function newpatient()
{
if (!$this->isLogin) {
$this->sys_error("Invalid Token");
exit;
}
$prm = $this->sys_input;
$userid = $this->sys_user["M_UserID"];
$pdob = date('Y-m-d', strtotime($prm['M_PatientDOB']));
$query = "INSERT INTO m_patient (
M_PatientM_TitleID,
M_PatientPrefix,
M_PatientName,
M_PatientSuffix,
M_PatientDOB,
M_PatientM_SexID,
M_PatientM_ReligionID,
M_PatientEmail,
M_PatientPOB,
M_PatientHP,
M_PatientPhone,
M_PatientM_IdTypeID,
M_PatientIDNumber,
M_PatientNote,
M_PatientNIK,
M_PatientJabatan,
M_PatientKedudukan,
M_PatientPJ,
M_PatientLocation,
M_PatientJob,
M_PatientUserID
)
VALUES(
'{$prm['M_PatientM_TitleID']}',
'{$prm['M_PatientPrefix']}',
'{$prm['M_PatientName']}',
'{$prm['M_PatientSuffix']}',
'{$pdob}',
'{$prm['M_PatientM_SexID']}',
'{$prm['M_PatientM_ReligionID']}',
'{$prm['M_PatientEmail']}',
'{$prm['M_PatientPOB']}',
'{$prm['M_PatientHP']}',
'{$prm['M_PatientPhone']}',
'{$prm['M_PatientM_IdTypeID']}',
'{$prm['M_PatientIDNumber']}',
'{$prm['M_PatientNote']}',
'{$prm['M_PatientNIK']}',
'{$prm['M_PatientJabatan']}',
'{$prm['M_PatientKedudukan']}',
'{$prm['M_PatientPJ']}',
'{$prm['M_PatientLocation']}',
'{$prm['M_PatientJob']}',
$userid
)
";
//echo $query;
$rows = $this->db_onedev->query($query);
$last_id = $this->db_onedev->insert_id();
$result = array(
"total" => 1,
"records" => array('status' => 'OK'),
"id" => $last_id
);
$ptn = $prm;
$ptn["M_PatientID"] = $last_id;
$ptn["M_PatientDOB"] = $pdob;
$ptn = json_encode($ptn);
$this->db_onedev->query("CALL one_log.log_me('PATIENT', 'PATIENT.ADD', '{$ptn}', $userid)");
$this->sys_ok($result);
exit;
}
function deletepatient()
{
if (!$this->isLogin) {
$this->sys_error("Invalid Token");
exit;
}
$userid = $this->sys_user["M_UserID"];
$prm = $this->sys_input;
$query = "UPDATE mcu_offline_prepare SET
McuOfflinePrepareIsActive = 'N'
WHERE
McuOfflinePrepareID = '{$prm['id']}'
";
//echo $query;
$rows = $this->db_onedev->query($query);
$result = array(
"total" => 1,
"records" => array('status' => 'OK')
);
$this->sys_ok($result);
exit;
}
function getaddress()
{
if (!$this->isLogin) {
$this->sys_error("Invalid Token");
exit;
}
$prm = $this->sys_input;
$query = " SELECT m_patientaddress.*,
M_KelurahanName,
M_DistrictID,
M_DistrictName,
M_CityID,
M_CityName,
'' as action
FROM m_patientaddress
JOIN m_kelurahan ON M_PatientAddressM_KelurahanID = M_KelurahanID
JOIN m_district ON M_KelurahanM_DistrictID = M_DistrictID
JOIN m_city ON M_DistrictM_CityID = M_CityID
WHERE
M_PatientAddressIsActive = 'Y' AND M_PatientAddressM_PatientID = ?
";
//echo $query;
$rows = $this->db_onedev->query($query, array($prm['id']))->result_array();
if ($rows) {
foreach ($rows as $k => $v) {
$rows[$k]['action'] = '<v-icon color="error" @click="deleteAddress(props.item)">delete</v-icon>';
$rows[$k]['action'] .= '<v-icon color="primary" @click="deleteAddress(props.item)">edit</v-icon>';
}
}
$result = array(
"total" => count($rows),
"records" => $rows,
);
$this->sys_ok($result);
exit;
}
function savenewaddress()
{
if (!$this->isLogin) {
$this->sys_error("Invalid Token");
exit;
}
$userid = $this->sys_user["M_UserID"];
$prm = $this->sys_input;
$count_addrs = $this->db_onedev->query("SELECT COUNT(*) as countx FROM m_patientaddress WHERE M_PatientAddressM_PatientID = '{$prm['M_PatientAddressM_PatientID']}' AND M_PatientAddressIsActive = 'Y'")->row()->countx;
//echo $this->db_onedev->last_query();
if ($count_addrs == 0) {
$prm['M_PatientAddressNote'] = 'Utama';
} else {
$count_addrs_utama = $this->db_onedev->query("SELECT COUNT(*) as countx FROM m_patientaddress WHERE M_PatientAddressM_PatientID = '{$prm['M_PatientAddressM_PatientID']}' AND M_PatientAddressNote = 'Utama' AND M_PatientAddressIsActive = 'Y'")->row()->countx;
if ($count_addrs_utama > 0 && strtolower($prm['M_PatientAddressNote']) == 'utama') {
$rx = date('YmdHis');
$prm['M_PatientAddressNote'] = 'Utama_' . $rx;
}
}
$query = "INSERT INTO m_patientaddress (
M_PatientAddressM_PatientID,
M_PatientAddressNote,
M_PatientAddressDescription,
M_PatientAddressM_KelurahanID,
M_PatientAddressCreated
)
VALUES(
'{$prm['M_PatientAddressM_PatientID']}',
'{$prm['M_PatientAddressNote']}',
'{$prm['M_PatientAddressDescription']}',
'{$prm['M_PatientAddressM_KelurahanID']}',
NOW()
)
";
//echo $query;
$rows = $this->db_onedev->query($query);
$result = array(
"total" => 1,
"records" => array('status' => 'OK')
);
$ptn = $prm;
$ptn["M_UserID"] = $pdob;
$ptn = json_encode($ptn);
$this->db_onedev->query("CALL one_log.log_me('PATIENT', 'PATIENT.ADDR_ADD', '{$ptn}', $userid)");
$this->sys_ok($result);
exit;
}
function saveeditaddress()
{
if (!$this->isLogin) {
$this->sys_error("Invalid Token");
exit;
}
$userid = $this->sys_user["M_UserID"];
$prm = $this->sys_input;
$query = "UPDATE m_patientaddress SET
M_PatientAddressM_PatientID = '{$prm['M_PatientAddressM_PatientID']}',
M_PatientAddressNote = '{$prm['M_PatientAddressNote']}',
M_PatientAddressDescription = '{$prm['M_PatientAddressDescription']}',
M_PatientAddressM_KelurahanID = '{$prm['M_PatientAddressM_KelurahanID']}'
WHERE
M_PatientAddressID = '{$prm['M_PatientAddressID']}'
";
//echo $query;
$rows = $this->db_onedev->query($query);
$result = array(
"total" => 1,
"records" => array('status' => 'OK')
);
$ptn = $prm;
$ptn["M_UserID"] = $pdob;
$ptn = json_encode($ptn);
$this->db_onedev->query("CALL one_log.log_me('PATIENT', 'PATIENT.ADDR_EDIT', '{$ptn}', $userid)");
$this->sys_ok($result);
exit;
}
function deleteaddress()
{
if (!$this->isLogin) {
$this->sys_error("Invalid Token");
exit;
}
$userid = $this->sys_user["M_UserID"];
$prm = $this->sys_input;
$query = "UPDATE m_patientaddress SET
M_PatientAddressIsActive = 'N'
WHERE
M_PatientAddressID = '{$prm['M_PatientAddressID']}'
";
//echo $query;
$rows = $this->db_onedev->query($query);
$result = array(
"total" => 1,
"records" => array('status' => 'OK')
);
$ptn = $prm;
$ptn["M_UserID"] = $pdob;
$ptn = json_encode($ptn);
$this->db_onedev->query("CALL one_log.log_me('PATIENT', 'PATIENT.ADDR_DELETE', '{$ptn}', $userid)");
$this->sys_ok($result);
exit;
}
} // Penutup class Setupmcucponev6