db_onedev->query($sql, array($mgmMcuID, $templateID, $userID, $userID)); } function get_report_template_mcu() { if (!$this->isLogin) { $this->sys_error("Invalid Token"); exit; } $prm = $this->sys_input; $mgmMcuID = 0; if (isset($prm['Mgm_McuID'])) { $mgmMcuID = intval($prm['Mgm_McuID']); } $sql = "SELECT t.Mcu_ReportUrlTemplateID AS id, t.Mcu_ReportUrlTemplateName AS reportName, t.Mcu_ReportUrlTemplateType AS reportType, t.Mcu_ReportUrlTemplateUrl AS reportUrl, t.Mcu_ReportUrlTemplateParams AS reportParams, IF(mr.Mgm_McuReportMcu_ReportUrlTemplateID = t.Mcu_ReportUrlTemplateID, 'Y', 'N') AS selected FROM mcu_report_url_template t LEFT JOIN mgm_mcureport mr ON mr.Mgm_McuReportMcu_ReportUrlTemplateID = t.Mcu_ReportUrlTemplateID AND mr.Mgm_McuReportMgm_McuID = ? AND mr.Mgm_McuReportIsActive = 'Y' WHERE t.Mcu_ReportUrlTemplateIsActive = 'Y' ORDER BY t.Mcu_ReportUrlTemplateName ASC"; $query = $this->db_onedev->query($sql, array($mgmMcuID)); if (!$query) { $this->sys_error_db("mcu_report_url_template select", $this->db_onedev); exit; } $rows = $query->result_array(); $selected = null; foreach ($rows as $row) { if ($row['selected'] === 'Y') { $selected = $row; break; } } $result = array( "total" => count($rows), "records" => $rows, "selected" => $selected ); $this->sys_ok($result); exit; } public function index() { echo "Patient API"; } public function __construct() { parent::__construct(); $this->db_onedev = $this->load->database("onedev", true); $this->load->library("SsPriceMou"); } // cpone public function searchv0() { $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_McuNumber LIKE '%{$prm['search']}%' OR CorporateName LIKE '%{$prm['search']}%' OR Mgm_McuLabel LIKE '%{$prm['search']}%' )"; $sql = "SELECT COUNT(*) AS total FROM ( SELECT mgm.Mgm_McuID FROM mgm_mcu mgm LEFT JOIN corporate corp ON mgm.Mgm_McuCorporateID = corp.CorporateID AND corp.CorporateIsActive = 'Y' AND mgm.Mgm_McuIsActive = 'Y' LEFT JOIN t_priceheader price ON mgm.Mgm_McuT_PriceHeaderID = price.T_PriceHeaderID AND price.T_PriceHeaderIsActive = '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' $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 -- mgm_mcu IFNULL(mgm.Mgm_McuID, 0) AS Mgm_McuID, IFNULL(mgm.Mgm_McuLabel, '') AS Mgm_McuLabel, IFNULL(mgm.Mgm_McuPicName,'') AS Mgm_McuPicName, -- IFNULL(mgm.Mgm_McuFlagRelasiBayarSendiri, '') AS Mgm_McuFlagRelasiBayarSendiri, -- IFNULL(mgm.Mgm_McuBisaTambahPemeriksaan, '') AS Mgm_McuBisaTambahPemeriksaan, mgm.Mgm_McuFlagRelasiBayarSendiri, mgm.Mgm_McuBisaTambahPemeriksaan, mgm.Mgm_McuLowBackPainTampilSemua, IFNULL(mgm.Mgm_McuCorporateID, 0) AS Mgm_McuCorporateID, 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_McuT_PriceHeaderID, 0) AS Mgm_McuT_PriceHeaderID, 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 = 'cpone' THEN 'Generate password pasien oleh CPONE' ELSE '' END AS generatepasswordbyname, -- corporate IFNULL(corp.CorporateID, 0) AS CorporateID, IFNULL(corp.CorporateCode, '') AS CorporateCode, IFNULL(corp.CorporateName, '') AS CorporateName, IFNULL(corp.CorporateAddress, '') AS CorporateAddress, IFNULL(corp.CorporateAddressRegionalCd, '') AS CorporateAddressRegionalCd, IFNULL(corp.CorporateAddressRT, '') AS CorporateAddressRT, IFNULL(corp.CorporateAddressRW, '') AS CorporateAddressRW, IFNULL(corp.CorporateAddressVillage, '') AS CorporateAddressVillage, IFNULL(corp.CorporateAddressDistrict, '') AS CorporateAddressDistrict, IFNULL(corp.CorporateAddressCity, '') AS CorporateAddressCity, IFNULL(corp.CorporateAddressState, '') AS CorporateAddressState, IFNULL(corp.CorporateAddressCountry, '') AS CorporateAddressCountry, IFNULL(corp.CorporateEmail, '') AS CorporateEmail, IFNULL(corp.CorporatePhone, '') AS CorporatePhone, IFNULL(corp.CorporatePICName, '') AS CorporatePICName, IFNULL(corp.CorporatePICEmail, '') AS CorporatePICEmail, IFNULL(corp.CorporatePICPhone, '') AS CorporatePICPhone, IFNULL(corp.CorporateFlagHolding, '') AS CorporateFlagHolding, IFNULL(corp.CorporateHoldingCorporateID, 0) AS CorporateHoldingCorporateID, IFNULL(corp.CorporatePICBillName, '') AS CorporatePICBillName, IFNULL(corp.CorporatePICBillEmail, '') AS CorporatePICBillEmail, IFNULL(corp.CorporatePICBillPhone, '') AS CorporatePICBillPhone, IFNULL(corp.CorporateDueDate, 0) AS CorporateDueDate, IFNULL(corp.CorporateFlagJPA, '') AS CorporateFlagJPA, IFNULL(corp.CorporateUsername, '') AS CorporateUsername, IFNULL(corp.CorporatePassword, '') AS CorporatePassword, IFNULL(corp.CorporateIsActive, '') AS CorporateIsActive, -- t_priceheader IFNULL(price.T_PriceHeaderID, 0) AS T_PriceHeaderID, IFNULL(price.T_PriceHeaderName, '') AS T_PriceHeaderName, IFNULL(price.T_PriceHeaderStartDate, '0000-00-00') AS T_PriceHeaderStartDate, IFNULL(price.T_PriceHeaderEndDate, '0000-00-00') AS T_PriceHeaderEndDate, IFNULL(price.T_PriceHeaderIsActive, '') AS T_PriceHeaderIsActive, -- 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, --IFNULL(branch.M_BranchName, '') AS M_BranchName, 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_BranchCreatedUserID, 0) AS M_BranchCreatedUserID, IFNULL(branch.M_BranchLastUpdated, '0000-00-00 00:00:00') AS M_BranchLastUpdated, IFNULL(branch.M_BranchLastUpdatedUserID, 0) AS M_BranchLastUpdatedUserID, IFNULL(branch.M_BranchDeleted, '0000-00-00 00:00:00') AS M_BranchDeleted, IFNULL(branch.M_BranchDeletedUserID, 0) AS M_BranchDeletedUserID, '' as packets, mgm.Mgm_McuTemplateMulti, IF(ISNULL(config_website.configWebsiteID), 'N', 'Y') AS check_price_website FROM mgm_mcu mgm left join corporate corp ON mgm.Mgm_McuCorporateID = corp.CorporateID AND corp.CorporateIsActive = 'Y' AND mgm.Mgm_McuIsActive = 'Y' LEFT JOIN t_priceheader price ON mgm.Mgm_McuT_PriceHeaderID = price.T_PriceHeaderID AND price.T_PriceHeaderIsActive = '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' $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_PacketT_PriceHeaderID, T_PacketSasCode, T_PacketName, T_PriceHeaderStartDate, T_PriceHeaderEndDate, 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 t_priceheader ON T_PacketT_PriceHeaderID = T_PriceHeaderID AND T_PacketIsActive = 'Y' AND T_PriceHeaderIsActive = 'Y' AND T_PacketT_PriceHeaderID = {$v['Mgm_McuT_PriceHeaderID']} AND ( T_PacketSasCode LIKE '%$filter_paket%' OR T_PacketName LIKE '%$filter_paket%' ) "; //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(); $dataNew = []; if (count($datapaket) > 0) { foreach ($datapaket as $key => $vx) { $dataNew[] = $vx; } $rows[$k]['packets'] = $dataNew; } // $rows[$k]['packets'] = $this->db_onedev->query($sql)->result_array(); // 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_BranchCreatedUserID'] = ''; $rows[$k]['M_BranchLastUpdated'] = ''; $rows[$k]['M_BranchLastUpdatedUserID'] = ''; $rows[$k]['M_BranchDeleted'] = ''; $rows[$k]['M_BranchDeletedUserID'] = ''; } } } $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; } $backgrounds = []; $sql = "SELECT M_BackgroundReportCode AS code, M_BackgroundReportName AS name, M_BackgroundReportImage AS image FROM m_background_report WHERE M_BackgroindReportIsActive = 'Y'"; $qry = $this->db_onedev->query($sql); if ($qry) { $backgrounds = $qry->result_array(); } else { $this->sys_error_db("template Backgrounds select error", $this->db_onedev); exit; } $result = array( "total" => $tot_page, "records" => $rows, "covers" => $covers, "backgrounds" => $backgrounds, "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 getbg() { if (!$this->isLogin) { $this->sys_error("Invalid Token"); exit; } $prm = $this->sys_input; $sql = "SELECT M_BackgroundReportCode AS code, M_BackgroundReportName AS name, M_BackgroundReportImage AS image FROM mgm_background_report JOIN m_background_report ON Mgm_BackgroundReportM_BackgroundReportCode = M_BackgroundReportCode WHERE Mgm_BackgroundReportMgm_McuID = ? AND Mgm_BackgroundReportIsActive = '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 Background report select error", $this->db_onedev); exit; } $rows = $qry->result_array(); if(count($rows) == 0){ $sql = "SELECT M_BackgroundReportCode AS code, M_BackgroundReportName AS name, M_BackgroundReportImage AS image FROM m_background_report WHERE M_BackgroundReportCode = 'DFLT' AND M_BackgroindReportIsActive = 'Y' LIMIT 1"; $qry = $this->db_onedev->query($sql); if(!$qry){ $this->sys_error_db("template background report 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 searchcorporate() { //# 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 corporate WHERE CorporateName like ? AND CorporateIsActive = '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("corporate count", $this->db_onedev); exit; } $sql = " SELECT CorporateID as id, CorporateName as name FROM corporate WHERE CorporateName like ? AND CorporateIsActive = 'Y' ORDER BY CorporateName 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("corporate rows", $this->db_onedev); exit; } } function getPackets() { if (!$this->isLogin) { $this->sys_error("Invalid Token"); exit; } $prm = $this->sys_input; $search = $prm["searchPacket"]; $T_PriceHeaderID = $prm["T_PriceHeaderID"]; $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_PacketT_PriceHeaderID, T_PacketSasCode, T_PacketName, T_PriceHeaderStartDate, T_PriceHeaderEndDate, T_PacketSasCode as code, T_PacketName as name, 'N' as T_PacketIsActive from t_packet JOIN ss_price_mou ON T_PriceT_PriceHeaderID = T_PacketT_PriceHeaderID LEFT join mgm_mcupacket ON T_PacketID = Mgm_McuPacketT_PacketID AND Mgm_McuPacketMgm_McuID = ? AND Mgm_McuPacketIsActive = 'Y' join t_priceheader ON T_PacketT_PriceHeaderID = T_PriceHeaderID AND T_PacketIsActive = 'Y' AND T_PacketIsGenerated = 'Y' AND T_PriceHeaderIsActive = 'Y' AND ( T_PacketSasCode LIKE '%$search%' OR T_PacketName LIKE '%$search%' ) AND T_PacketT_PriceHeaderID = $T_PriceHeaderID group by T_PacketID ) x "; //echo $sql; $query = $this->db_onedev->query($sql, array($prm["Mgm_McuID"])); }else{ $sql = "SELECT count(*) as total FROM ( SELECT T_PacketID as id, T_PacketID, T_PacketT_PriceHeaderID, T_PacketSasCode, T_PacketName, T_PriceHeaderStartDate, T_PriceHeaderEndDate, T_PacketSasCode as code, T_PacketName as name, 'N' as T_PacketIsActive from t_packet JOIN ss_price_mou ON T_PriceT_PriceHeaderID = T_PacketT_PriceHeaderID -- join mgm_mcupacket ON T_PacketID = Mgm_McuPacketT_PacketID AND Mgm_McuPacketMgm_McuID = ? AND Mgm_McuPacketIsActive = 'Y' join t_priceheader ON T_PacketT_PriceHeaderID = T_PriceHeaderID AND T_PacketIsActive = 'Y' AND T_PacketIsGenerated = 'Y' AND T_PriceHeaderIsActive = 'Y' AND ( T_PacketSasCode LIKE '%$search%' OR T_PacketName LIKE '%$search%' ) AND T_PacketT_PriceHeaderID = $T_PriceHeaderID group by T_PacketID ) x "; //echo $sql; $query = $this->db_onedev->query($sql, array($prm["Mgm_McuID"])); } $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; } if(isset($prm['Mgm_McuID'])){ $query = "SELECT T_PacketID as id, T_PacketID, T_PacketT_PriceHeaderID, T_PacketSasCode, T_PacketName, T_PriceHeaderStartDate, T_PriceHeaderEndDate, T_PacketSasCode as code, T_PacketName as name, 'N' as T_PacketIsActive from t_packet JOIN ss_price_mou ON T_PriceT_PriceHeaderID = T_PacketT_PriceHeaderID LEFT join mgm_mcupacket ON T_PacketID = Mgm_McuPacketT_PacketID AND Mgm_McuPacketMgm_McuID = ? AND Mgm_McuPacketIsActive = 'Y' join t_priceheader ON T_PacketT_PriceHeaderID = T_PriceHeaderID AND T_PacketIsActive = 'Y' AND T_PacketIsGenerated = 'Y' AND T_PriceHeaderIsActive = 'Y' AND ( T_PacketSasCode LIKE '%$search%' OR T_PacketName LIKE '%$search%' ) AND T_PacketT_PriceHeaderID = $T_PriceHeaderID group by T_PacketID ORDER BY T_PacketSasCode ASC limit $number_limit offset $number_offset "; //echo $query; $rows = $this->db_onedev->query($query, array($prm["Mgm_McuID"]))->result_array(); }else{ $query = "SELECT T_PacketID as id, T_PacketID, T_PacketT_PriceHeaderID, T_PacketSasCode, T_PacketName, T_PriceHeaderStartDate, T_PriceHeaderEndDate, T_PacketSasCode as code, T_PacketName as name, 'N' as T_PacketIsActive from t_packet JOIN ss_price_mou ON T_PriceT_PriceHeaderID = T_PacketT_PriceHeaderID -- join mgm_mcupacket ON T_PacketID = Mgm_McuPacketT_PacketID AND Mgm_McuPacketMgm_McuID = ? AND Mgm_McuPacketIsActive = 'Y' join t_priceheader ON T_PacketT_PriceHeaderID = T_PriceHeaderID AND T_PacketIsActive = 'Y' AND T_PacketIsGenerated = 'Y' AND T_PriceHeaderIsActive = 'Y' AND ( T_PacketSasCode LIKE '%$search%' OR T_PacketName LIKE '%$search%' ) AND T_PacketT_PriceHeaderID = $T_PriceHeaderID group by T_PacketID 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 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"]; $corporate_id = $prm["corporate_id"]; $sql = "SELECT * FROM mgm_mcuemailresult JOIN mgm_mcu ON Mgm_McuEmailResultMgm_McuID = Mgm_McuID JOIN corporate ON Mgm_McuCorporateID = CorporateID 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 corporate WHERE CorporateIsActive = 'Y' AND CorporateID = ?"; $qry = $this->db_onedev->query($sql,array($corporate_id)); $rows = $qry->result_array(); } $result = array( "total" => count($rows), "records" => $rows[0], ); $this->sys_ok($result); } function savesetupv0() { if (!$this->isLogin) { $this->sys_error("Invalid Token"); exit; } $userid = $this->sys_user["M_UserID"]; $prm = $this->sys_input; $priceheaderid = array(); // $Packetid = array(); if (count($prm['selected_packets']) > 0) { foreach ($prm['selected_packets'] as $kp => $vp) { array_push($priceheaderid, $vp['T_PacketT_PriceHeaderID']); // array_push($Packetid,$vp['T_PacketID']); } } // if(count($priceheaderid) > 0){ // $Mgm_McuT_PriceHeaderID = join(',',$priceheaderid); // } // if(count($Packetid) > 0){ // $Mgm_McuPacketT_PacketID = join(',',$Packetid); // } $Mgm_McuTemplateFisikTemplateMappingID = $prm['Mgm_McuTemplateFisikTemplateMappingID']['FisikTemplateMappingID']; $password = $prm['Mgm_McuPicPassword']; $Mgm_McuPicPassword = md5($this->one_salt . $password . $this->one_salt); $Mgm_McuFlagRelasiBayarSendiri = "N"; $Mgm_McuBisaTambahPemeriksaan = "N"; $Mgm_McuLowBackPainTampilSemua = "N"; $Mgm_McuPriceWebsite = "N"; if ($prm['Mgm_McuBisaTambahPemeriksaan'] == true) { $Mgm_McuBisaTambahPemeriksaan = "Y"; } if ($prm['Mgm_McuFlagRelasiBayarSendiri'] == true) { $Mgm_McuFlagRelasiBayarSendiri = "Y"; } if ($prm['Mgm_McuLowBackPainTampilSemua'] == true) { $Mgm_McuLowBackPainTampilSemua = "Y"; } if ($prm['inp_Mgm_McuPriceWebsite'] == true) { $Mgm_McuPriceWebsite = "Y"; } $Mgm_McuCorporateID = $prm['Mgm_McuCorporateID']['id']; $Mgm_McuNumber = ""; $Mgm_McuNumberNational = ""; $Mgm_McuNote = $prm['Mgm_McuNote']; $Mgm_McuLabel = strtoupper($prm['Mgm_McuLabel']); $Mgm_McuPicName = strtoupper($prm['Mgm_McuPicName']); $Mgm_McuStartDate = date('Y-m-d', strtotime($prm["Mgm_McuStartDate"])); $Mgm_McuEndDate = date('Y-m-d', strtotime($prm["Mgm_McuEndDate"])); $Mgm_McuPicEmail = $prm['Mgm_McuPicEmail']; // $Mgm_McuTotalParticipant = $prm['Mgm_McuTotalParticipant']; $Mgm_McuTotalParticipant = 0; $Mgm_McuT_PriceHeaderID = $prm['Mgm_McuT_PriceHeaderID']; $Mgm_McuM_BranchID = $prm['Mgm_McuM_BranchID']; $Mgm_McuReportHasil = $prm['Mgm_McuReportHasil']; $Mcu_ReportUrlTemplateID = $this->resolve_report_template_id($prm); $Mgm_McuGeneratePasswordBY = $prm['Mgm_McuGeneratePasswordBY']; $cover = isset($prm['cover']) ? $prm['cover'] : ['code' => 'DFLT', 'name' => 'Cover Default']; $background = isset($prm['background']) ? $prm['background'] : ['code' => 'DFLT', 'name' => 'Background Default', 'image' => 'one-ui/BackgroundWesterindo.png']; $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("t_packet 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_cpone('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 cpone", $this->db_onedev); exit; } $data_numbering = $qry_get_numbering->result_array(); $Mgm_McuNumber = $data_numbering[0]['numberx']; // insert mgm_mcu $sql_mgmmcu = "INSERT INTO mgm_mcu ( Mgm_McuReportHasil, Mgm_McuT_PriceHeaderID, Mgm_McuLabel, Mgm_McuPicName, Mgm_McuFlagRelasiBayarSendiri, Mgm_McuBisaTambahPemeriksaan, Mgm_McuCorporateID, Mgm_McuNumber, Mgm_McuNumberNational, Mgm_McuNote, Mgm_McuStartDate, Mgm_McuEndDate, Mgm_McuPicEmail, Mgm_McuPicPassword, Mgm_McuGeneratePasswordBY, Mgm_McuIsActive, Mgm_McuCreated, Mgm_McuCreatedUserID, Mgm_McuTotalParticipant, Mgm_McuM_BranchID, Mgm_McuLowBackPainTampilSemua ) VALUES ( '{$Mgm_McuReportHasil}', '{$Mgm_McuT_PriceHeaderID}', '{$Mgm_McuLabel}', '{$Mgm_McuPicName}', '{$Mgm_McuFlagRelasiBayarSendiri}', '{$Mgm_McuBisaTambahPemeriksaan}', {$Mgm_McuCorporateID}, '{$Mgm_McuNumber}', '{$Mgm_McuNumberNational}', '{$Mgm_McuNote}', '{$Mgm_McuStartDate}', '{$Mgm_McuEndDate}', '{$Mgm_McuPicEmail}', '{$Mgm_McuPicPassword}', '{$Mgm_McuGeneratePasswordBY}', 'Y', NOW(), {$userid}, {$Mgm_McuTotalParticipant}, {$Mgm_McuM_BranchID}, '{$Mgm_McuLowBackPainTampilSemua}' ) "; $qry = $this->db_onedev->query($sql_mgmmcu); 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(); $this->upsert_mgm_mcureport($last_id, $Mcu_ReportUrlTemplateID, $userid); $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 if (count($prm['selected_packets']) > 0) { foreach ($prm['selected_packets'] as $kp => $vp) { $Mgm_McuPacketT_PacketID = $vp['T_PacketID']; 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 ( $last_id, '{$Mgm_McuPacketT_PacketID}', 'Y', NOW(), $userid )"; $qry_mgm_mcupacket = $this->db_onedev->query($sql_mgm_mcupacket); 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 = $userid WHERE Mgm_McuPacketMgm_McuID = ? AND Mgm_McuPacketT_PacketID IN ('".implode("','", $delete_packet)."')"; $qry_delete_packet = $this->db_onedev->query($sql_delete_packet, array($last_id)); if (!$qry_delete_packet) { $this->db_onedev->trans_rollback(); $this->sys_error_db("mgm_mcupacket delete", $this->db_onedev); exit; } } // insert mgm_mcutemplate $mgm_mcutemplate = "INSERT INTO mgm_mcutemplate ( Mgm_McuTemplateMgm_McuID, Mgm_McuTemplateFisikTemplateMappingID, Mgm_McuTemplateIsActive, Mgm_McuTemplateCreated, Mgm_McuTemplateCreatedUserID ) VALUES ( $last_id, $Mgm_McuTemplateFisikTemplateMappingID, 'Y', NOW(), $userid )"; $qry_mgm_mcutemplate = $this->db_onedev->query($mgm_mcutemplate); if (!$qry_mgm_mcutemplate) { $this->db_onedev->trans_rollback(); $this->sys_error_db("mgm_mcutemplate insert", $this->db_onedev); exit; } // insert mgm_mcuuser if (count($prm["arrUserMcu"]) > 0) { foreach ($prm["arrUserMcu"] as $key => $val) { $passwordUserMcu = $val['Mgm_McuUserPassword']; $Mgm_McuUserPassword = md5($this->one_salt . $passwordUserMcu . $this->one_salt); $Mgm_McuUserEmail = $val["Mgm_McuUserEmail"]; $sql_mgm_mcuuser = "INSERT INTO mgm_mcuuser( Mgm_McuUserMgm_McuID, Mgm_McuUserEmail, Mgm_McuUserPassword, Mgm_McuUserIsActive, Mgm_McuUserCreated, Mgm_McuUserCreatedUserID ) VALUES( $last_id, '{$Mgm_McuUserEmail}', '{$Mgm_McuUserPassword}', 'Y', NOW(), $userid )"; $qry_mgm_mcuuser = $this->db_onedev->query($sql_mgm_mcuuser); if (!$qry_mgm_mcuuser) { $this->db_onedev->trans_rollback(); $this->sys_error_db("mgm_mcuuser insert", $this->db_onedev); exit; } } } } // kalau edit yg mgm_mcupacket di N kan sesuai // Mgm_McuPacketMgm_McuID // baru di insert yg baru else { // var_dump($prm); // check data password for update // check paket exists or not $last_id = $prm["xid"]; $this->upsert_mgm_mcureport($last_id, $Mcu_ReportUrlTemplateID, $userid); $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' 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(); $passwordOld = $rowx['Mgm_McuPicPassword']; if ($passwordOld == $password) { $Mgm_McuPicPassword = $passwordOld; } // echo $passwordOld; // echo "\n".$password; // echo "\n".$Mgm_McuPicPassword; // exit; // update mgmmcu $sql_mgmmcu = "UPDATE mgm_mcu SET Mgm_McuReportHasil = '{$Mgm_McuReportHasil}', Mgm_McuT_PriceHeaderID = '{$Mgm_McuT_PriceHeaderID}', Mgm_McuLabel = '{$Mgm_McuLabel}', Mgm_McuPicName = '{$Mgm_McuPicName}', Mgm_McuFlagRelasiBayarSendiri = '{$Mgm_McuFlagRelasiBayarSendiri}', Mgm_McuBisaTambahPemeriksaan = '{$Mgm_McuBisaTambahPemeriksaan}', Mgm_McuCorporateID = {$Mgm_McuCorporateID}, -- Mgm_McuNumber = '{$Mgm_McuNumber}', -- Mgm_McuNumberNational = '{$Mgm_McuNumberNational}', Mgm_McuNote = '{$Mgm_McuNote}', Mgm_McuStartDate = '{$Mgm_McuStartDate}', Mgm_McuEndDate = '{$Mgm_McuEndDate}', Mgm_McuPicEmail = '{$Mgm_McuPicEmail}', Mgm_McuPicPassword = '{$Mgm_McuPicPassword}', Mgm_McuGeneratePasswordBY = '{$Mgm_McuGeneratePasswordBY}', Mgm_McuIsActive = 'Y', Mgm_McuLastUpdated = NOW(), Mgm_McuLastUpdatedUserID = {$userid}, Mgm_McuTotalParticipant = {$Mgm_McuTotalParticipant}, Mgm_McuLowBackPainTampilSemua = '{$Mgm_McuLowBackPainTampilSemua}', Mgm_McuM_BranchID = {$Mgm_McuM_BranchID} WHERE Mgm_McuID = {$prm["xid"]} "; $qry = $this->db_onedev->query($sql_mgmmcu); if (!$qry) { $this->db_onedev->trans_rollback(); $this->sys_error_db("mgm_mcu update", $this->db_onedev); exit; } $last_id = $prm["xid"]; // // update packets // // update isActive N kan semua $sqlUpdatePacket = "UPDATE mgm_mcupacket SET Mgm_McuPacketIsActive = 'N', Mgm_McuPacketLastUpdated = NOW(), Mgm_McuPacketLastUpdatedUserID = $userid, Mgm_McuPacketDeleted = NOW(), Mgm_McuPacketDeletedUserID = $userid WHERE Mgm_McuPacketMgm_McuID = $last_id"; $qry_mgm_update_mcupacket = $this->db_onedev->query($sqlUpdatePacket); if (!$qry_mgm_update_mcupacket) { $this->db_onedev->trans_rollback(); $this->sys_error_db("mgm_mcupacket update", $this->db_onedev); exit; } if (count($prm['selected_packets']) > 0) { foreach ($prm['selected_packets'] as $kp => $vp) { $Mgm_McuPacketT_PacketID = $vp['T_PacketID']; $sql_mgm_mcupacket = "INSERT INTO mgm_mcupacket ( Mgm_McuPacketMgm_McuID, Mgm_McuPacketT_PacketID, Mgm_McuPacketIsActive, Mgm_McuPacketCreated, Mgm_McuPacketCreatedUserID ) VALUES ( $last_id, '{$Mgm_McuPacketT_PacketID}', 'Y', NOW(), $userid )"; $qry_mgm_mcupacket = $this->db_onedev->query($sql_mgm_mcupacket); if (!$qry_mgm_mcupacket) { $this->db_onedev->trans_rollback(); $this->sys_error_db("mgm_mcupacket insert", $this->db_onedev); exit; } } } // update mgm_mcutemplate $sql_mgm_mcutemplate = "UPDATE mgm_mcutemplate SET Mgm_McuTemplateIsActive = 'N', Mgm_McuTemplateDelete = NOW(), Mgm_McuTemplateDeletedUserID = $userid WHERE Mgm_McuTemplateMgm_McuID = $last_id AND Mgm_McuTemplateIsActive = 'Y'"; $qry_mgm_mcutemplate = $this->db_onedev->query($sql_mgm_mcutemplate); if (!$qry_mgm_mcutemplate) { $this->db_onedev->trans_rollback(); $this->sys_error_db("mgm_mcutemplate update", $this->db_onedev); exit; } $mgm_mcutemplate = "INSERT INTO mgm_mcutemplate ( Mgm_McuTemplateMgm_McuID, Mgm_McuTemplateFisikTemplateMappingID, Mgm_McuTemplateCreated, Mgm_McuTemplateCreatedUserID )VALUES( $last_id, $Mgm_McuTemplateFisikTemplateMappingID, NOW(), $userid ) "; $qry_mgm_mcutemplate = $this->db_onedev->query($mgm_mcutemplate); if (!$qry_mgm_mcutemplate) { $this->db_onedev->trans_rollback(); $this->sys_error_db("mgm_mcutemplate update", $this->db_onedev); exit; } // insert mgm_mcuuser if (count($prm["arrUserMcu"]) > 0) { foreach ($prm["arrUserMcu"] as $key => $val) { $passwordUserMcu = $val['Mgm_McuUserPassword']; $Mgm_McuUserPassword = md5($this->one_salt . $passwordUserMcu . $this->one_salt); $Mgm_McuUserEmail = $val["Mgm_McuUserEmail"]; if ($val["Mgm_McuUserID"] == '0' || $val["Mgm_McuUserID"] == 0) { $sql_mgm_mcuuser = "INSERT INTO mgm_mcuuser( Mgm_McuUserMgm_McuID, Mgm_McuUserEmail, Mgm_McuUserPassword, Mgm_McuUserIsActive, Mgm_McuUserCreated, Mgm_McuUserCreatedUserID ) VALUES( $last_id, '{$Mgm_McuUserEmail}', '{$Mgm_McuUserPassword}', 'Y', NOW(), $userid )"; $qry_mgm_mcuuser = $this->db_onedev->query($sql_mgm_mcuuser); if (!$qry_mgm_mcuuser) { $this->db_onedev->trans_rollback(); $this->sys_error_db("mgm_mcuuser insert", $this->db_onedev); exit; } } } } // update mgm_mcuuser if ($prm["deleted_usermcus"]) { foreach ($prm["deleted_usermcus"] as $k => $v) { $sql = "UPDATE mgm_mcuuser SET Mgm_McuUserIsActive = 'N', Mgm_McuUserLastUpdated = NOW(), Mgm_McuUserLastUpdatedUserID = $userid WHERE Mgm_McuUserID = {$v['Mgm_McuUserID']}"; $qry = $this->db_onedev->query($sql); if (!$qry) { $this->db_onedev->trans_rollback(); $this->sys_error_db("mgm_mcuuser update", $this->db_onedev); exit; } } } } if($Mgm_McuPriceWebsite == 'Y'){ $sql_config_website = "SELECT * FROM config_website WHERE configWebsiteIsActive = 'Y'"; $qry_config_website = $this->db_onedev->query($sql_config_website); if (!$qry_config_website) { $this->db_onedev->trans_rollback(); $this->sys_error_db("config_website select", $this->db_onedev); exit; } $row_config_website = $qry_config_website->result_array(); $data_log = []; if(count($row_config_website) > 0){ $data_log['before'] = $row_config_website[0]; $sql_data = "UPDATE config_website SET configWebsiteMgm_McuID = $last_id WHERE configWebsiteID = {$row_config_website[0]['configWebsiteID']}"; }else{ $data_log['before'] = []; $sql_data = "INSERT INTO config_website ( configWebsiteMgm_McuID, configWebsiteIsActive ) VALUES ( $last_id, 'Y' )"; } $qry_insert_update = $this->db_onedev->query($sql_data); if (!$qry_insert_update) { $this->db_onedev->trans_rollback(); $this->sys_error_db("config_website insert or update", $this->db_onedev); exit; } $qry_config_website = $this->db_onedev->query($sql_config_website); if (!$qry_config_website) { $this->db_onedev->trans_rollback(); $this->sys_error_db("config_website select", $this->db_onedev); exit; } $row_config_website = $qry_config_website->row_array(); $data_log['after'] = $row_config_website; $sql = "INSERT INTO log_config_website ( LogConfigWebsiteCode, LogConfigWebsiteJSON, LogConfigWebsiteCreated, LogConfigWebsiteUserID ) VALUES ( 'CHG_MGM_MCU', '".json_encode($data_log)."', NOW(), {$userid} )"; $qry_log = $this->db_onedev->query($sql); if (!$qry_log) { $this->db_onedev->trans_rollback(); $this->sys_error_db("log_config_website insert", $this->db_onedev); exit; } } if(isset($prm['mgm_mcuemailresult'])){ $sql = "UPDATE mgm_mcuemailresult SET Mgm_McuEmailResultIsActive = 'N', Mgm_McuEmailResultLastUpdated = NOW(), Mgm_McuEmailResultLastUpdatedUserID = $userid WHERE Mgm_McuEmailResultMgm_McuID = $last_id AND Mgm_McuEmailResultIsActive = 'Y'"; $qry = $this->db_onedev->query($sql); if(!$qry){ $this->db_onedev->trans_rollback(); $this->sys_error_db("mgm_mcuemailresult update", $this->db_onedev); exit; } $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 ]); } // delete mgm_mcucover $sql = "UPDATE mgm_cover SET Mgm_CoverIsActive = 'N', Mgm_CoverDeleted = NOW(), Mgm_CoverDeletedUserID = ? WHERE Mgm_CoverMgm_McuID = ? AND Mgm_CoverIsActive = 'Y'"; $qry = $this->db_onedev->query($sql, [ $userid, $last_id ]); // insert mgm_mcucover $sql_mgm_mcucover = "INSERT INTO mgm_cover ( Mgm_CoverMgm_McuID, Mgm_CoverM_CoverCode, Mgm_CoverIsActive, Mgm_CoverCreated, Mgm_CoverCreatedUserID ) VALUES ( $last_id, '{$cover['code']}', 'Y', NOW(), $userid )"; $qry_mgm_mcucover = $this->db_onedev->query($sql_mgm_mcucover); // delete mgm_mcubackground $sql = "UPDATE mgm_background_report SET Mgm_BackgroundReportIsActive = 'N', Mgm_BackgroundReportDeleted = NOW(), Mgm_BackgroundReportDeletedUserID = ? WHERE Mgm_BackgroundReportMgm_McuID = ? AND Mgm_BackgroundReportIsActive = 'Y'"; $qry = $this->db_onedev->query($sql, [ $userid, $last_id ]); // insert mgm_mcubackground $sql_mgm_mcubackground = "INSERT INTO mgm_background_report ( Mgm_BackgroundReportMgm_McuID, Mgm_BackgroundReportM_BackgroundReportCode, Mgm_BackgroundReportIsActive, Mgm_BackgroundReportCreated, Mgm_BackgroundReportCreatedUserID ) VALUES ( $last_id, '{$background['code']}', 'Y', NOW(), $userid )"; $qry_mgm_mcubackground = $this->db_onedev->query($sql_mgm_mcubackground); $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' 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); $data_log = [ 'before' => $json_before, 'after' => $json_after ]; $json_log = json_encode($data_log); $sql = "INSERT INTO cpone_log.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_onedev->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_onedev); 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(); $result = array( "total" => 1, "records" => $row, ); $this->sys_ok($result); exit; } function deletemcuv0() { if (!$this->isLogin) { $this->sys_error("Invalid Token"); exit; } $userid = $this->sys_user["M_UserID"]; $prm = $this->sys_input; $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' WHERE Mgm_McuID = '{$prm['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); // 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); $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' WHERE Mgm_McuID = '{$prm['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); $data_log = [ 'before' => $json_before, 'after' => $json_after ]; $json_log = json_encode($data_log); $sql = "INSERT INTO cpone_log.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_onedev->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_onedev); exit; } $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 = $T_PacketID"; $qry = $this->db_onedev->query($sql); 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_BranchCreatedUserID, 0) AS M_BranchCreatedUserID, IFNULL(M_BranchLastUpdated, '0000-00-00 00:00:00') AS M_BranchLastUpdated, IFNULL(M_BranchLastUpdatedUserID, 0) AS M_BranchLastUpdatedUserID, IFNULL(M_BranchDeleted, '0000-00-00 00:00:00') AS M_BranchDeleted, IFNULL(M_BranchDeletedUserID, 0) AS M_BranchDeletedUserID 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_BranchCreatedUserID' => '', 'M_BranchLastUpdated' => '', 'M_BranchLastUpdatedUserID' => '', 'M_BranchDeleted' => '', 'M_BranchDeletedUserID' => '' ); $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 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 search() { $prm = $this->sys_input; if (!$this->isLogin) { $this->sys_error("Invalid Token"); exit; } $status = isset($prm["status"]["id"]) ? $prm["status"]["id"] : 'N'; $company = isset($prm["company"]) ? intval($prm["company"]) : 0; // echo $norm; $filter_company = ''; if ($company > 0) { $filter_company = " AND McuOfflinePrepareM_CompanyID = {$company}"; } $sql_where = "WHERE McuOfflinePrepareIsActive = 'Y' AND McuOfflinePrepareIsDownloaded = '{$status}' $filter_company"; $sql_param = array(); $limit = ''; if ($all == 'N') { $limit = ' LIMIT 10'; } $number_limit = 10; $number_offset = ($prm['current_page'] - 1) * $number_limit; $sql = " SELECT count(*) as total FROM mcu_offline_prepare JOIN m_company ON McuOfflinePrepareM_CompanyID = M_CompanyID $sql_where "; //echo $sql; $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("m_patient count", $this->db_onedev); exit; } $sql = " SELECT mcu_offline_prepare.*, M_CompanyName, DATE_FORMAT(McuOfflinePrepareStartDate, '%d.%m.%Y') as start_date, DATE_FORMAT(McuOfflinePrepareEndDate, '%d.%m.%Y') as end_date, McuOfflinePreparePromiseDate as promise_date, McuOfflinePreparePromiseTime as promise_time, McuOfflinePrepareDoctors as doctors, McuOfflinePrepareMous as mous, McuOfflinePrepareDeliveries as deliveries, '' as allmous, McuOfflinePrepareM_MouDefaultID as mou_default_id, M_MouName as mou_default_name, CONCAT('[ ',M_DoctorCode,' ] ',IFNULL(M_DoctorPrefix,''),'',IFNULL(M_DoctorPrefix2,''),' ',M_DoctorName,' ',IFNULL(M_DoctorSufix,''),IFNULL(M_DoctorSufix2,''),IFNULL(M_DoctorSufix3,'')) as doctor_default_name, McuOfflinePrepareM_DoctorDefaultID as doctor_default_id, '' as default_mou, '' as default_doctor, '' as default_doctor_address, M_DoctorAddressID as doctor_address_id, M_DoctorAddressNote as doctor_address_label, M_DoctorAddressDescription as doctor_address_description, '' as doctor_address, '' as packets, '' as tests FROM mcu_offline_prepare JOIN m_company ON McuOfflinePrepareM_CompanyID = M_CompanyID JOIN m_mou ON McuOfflinePrepareM_MouDefaultID = M_MouID JOIN m_doctor ON McuOfflinePrepareM_DoctorDefaultID = M_DoctorID JOIN m_doctoraddress ON McuOfflinePrepareM_DoctorAddressDefaultID = M_DoctorAddressID $sql_where ORDER BY McuOfflinePrepareCode ASC limit $number_limit offset $number_offset "; //echo $sql; $query = $this->db_onedev->query($sql, $sql_param); $rows = $query->result_array(); if ($rows) { foreach ($rows as $k => $v) { $v['doctors'] = preg_replace("/\\n/", "___n___", $v['doctors']); $rows[$k]['doctors'] = json_decode($v['doctors']); //print_r($v['doctors']); $v['mous'] = preg_replace("/\\n/", "___n___", $v['mous']); $rows[$k]['mous'] = json_decode($v['mous']); $v['deliveries'] = preg_replace("/\\n/", "___n___", $v['deliveries']); $rows[$k]['deliveries'] = json_decode($v['deliveries']); $rows[$k]['default_mou'] = array('id' => $v['mou_default_id'], 'name' => $v['mou_default_name']); $rows[$k]['packets'] = array(); $rows[$k]['tests'] = array(); $rows[$k]['Mgm_McuLowBackPainTampilSemua'] = $v['inp_Mgm_McuLowBackPainTampilSemua'] == 'N' ? false : true; $join_test = ''; $filter_paket = "AND T_PacketSasCode IN ('')"; $filter_test = "AND T_TestSasCode IN ('')"; if ($v['McuOfflinePrepareTests'] != '') { $xjoin_tests = explode(',', $v['McuOfflinePrepareTests']); //print_r($xjoin_tests); if ($xjoin_tests) { foreach ($xjoin_tests as $kjt => $vjt) { if ($join_test != '') $join_test .= ","; $join_test .= "'{$vjt}'"; } } //echo $join_test; $filter_paket = "AND T_PacketSasCode IN ({$join_test})"; $filter_test = "AND T_TestSasCode IN ({$join_test}) "; } $sql = "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 = {$v['mou_default_id']} AND is_packet = 'Y' $filter_paket"; //echo $sql; $rows[$k]['packets'] = $this->db_onedev->query($sql)->result_array(); if ($rows[$k]['packets']) { foreach ($rows[$k]['packets'] as $kp => $vp) { $rows[$k]['packets'][$kp]['nat_test'] = json_decode($vp['nat_test']); } } $sql = "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 T_TestIsActive = 'Y' WHERE Ss_PriceMouM_MouID = {$v['mou_default_id']} AND is_packet = 'N' AND T_PriceIsCito = 'N' $filter_test"; //echo $sql; $rows[$k]['tests'] = $this->db_onedev->query($sql)->result_array(); if ($rows[$k]['tests']) { foreach ($rows[$k]['tests'] as $kp => $vp) { $rows[$k]['tests'][$kp]['nat_test'] = json_decode($vp['nat_test']); } } $sql = "SELECT M_MouID as id, M_MouName as name FROM m_mou WHERE M_MouM_CompanyID = {$v['McuOfflinePrepareM_CompanyID']} AND ( '{$v['McuOfflinePrepareStartDate']}' >= M_MouStartDate) AND ( '{$v['McuOfflinePrepareEndDate']}' <= M_MouEndDate ) AND M_MouIsActive = 'Y' AND M_MouIsReleased = 'Y'"; //echo $sql; $rows[$k]['allmous'] = $this->db_onedev->query($sql)->result_array(); $rows[$k]['default_doctor_address'] = array('id' => $v['doctor_address_id'], 'label' => $v['doctor_address_label'], 'description' => $v['doctor_address_description']); $sql = "SELECT M_DoctorAddressID as id, M_DoctorAddressNote as label, M_DoctorAddressDescription as description FROM m_doctoraddress WHERE M_DoctorAddressM_DoctorID = {$v['doctor_default_id']} AND M_DoctorAddressIsActive = 'Y'"; //echo $sql; $rows[$k]['doctor_address'] = $this->db_onedev->query($sql)->result_array(); $rows[$k]['default_doctor'] = array('id' => $v['doctor_default_id'], 'name' => $v['doctor_default_name'], 'xaddress' => $rows[$k]['doctor_address']); } } //$this->_add_address($rows); $result = array("total" => $tot_page, "records" => $rows, "sql" => $this->db_onedev->last_query()); $this->sys_ok($result); exit; } function getdatapackets() { 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 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 = {$prm['id']} 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 = {$prm['id']} AND is_packet = 'Y' AND ( T_TestName 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 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 getdeliveries() { //# cek token valid if (!$this->isLogin) { $this->sys_error("Invalid Token"); exit; } $prm = $this->sys_input; $id = $prm['id']; //$prm['start_date'] = strtotime($prm['start_date']); //$prm['end_date'] = strtotime($prm['end_date']); $type = 'mou'; $sql = "SELECT * FROM m_mou WHERE M_MouID = {$id}"; $data_mou = $this->db_onedev->query($sql)->row_array(); $sql = " SELECT 0 as kelurahan, 0 as address_id, M_DeliveryM_DeliveryTypeID as delivery_type, M_DeliveryID as delivery_id, M_DeliveryName as delivery_name, '' as description, 'N' as chex, '' as note, 'origin' as typeform, 'patient' as type, M_DeliveryTypeCode as delivery_code FROM m_delivery JOIN m_deliverytype ON M_DeliveryTypeCode = 'PICKUP' AND M_DeliveryM_DeliveryTypeID = M_DeliveryTypeID WHERE M_DeliverySource = 'patient' AND M_DeliveryIsActive = 'Y' UNION SELECT M_CompanyM_KelurahanID as kelurahan, 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_KelurahanName,', ',M_DistrictName,', ',M_CityName) 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 JOIN m_kelurahan ON M_CompanyM_KelurahanID = M_KelurahanID JOIN m_district ON M_KelurahanM_DistrictID = M_DistrictID JOIN m_city ON M_DistrictM_CityID = M_CityID WHERE M_CompanyID = {$data_mou['M_MouM_CompanyID']} UNION SELECT 0 as kelurahan, 0 as address_id, M_DeliveryM_DeliveryTypeID as delivery_type, M_DeliveryID as delivery_id, M_DeliveryName as delivery_name, IFNULL(M_MouEmail,'Belum ada email agreement') as description, 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 = 'mou' AND M_DeliveryIsActive = 'Y' JOIN m_deliverytype ON M_DeliveryTypeCode = 'EMAIL' AND M_DeliveryM_DeliveryTypeID = M_DeliveryTypeID WHERE M_MouID = {$id}"; //echo $sql; $rows = $this->db_onedev->query($sql)->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 searchcompany() { //# 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(); //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 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 savesetup() { if (!$this->isLogin) { $this->sys_error("Invalid Token"); exit; } $userid = $this->sys_user["M_UserID"]; $prm = $this->sys_input; $sdate = date('Y-m-d', strtotime($prm["startdate"])); $edate = date('Y-m-d', strtotime($prm["enddate"])); $promise_date = date('Y-m-d', strtotime($prm["promise_date"])); $promise_time = date('H:i:s', strtotime($prm["promise_time"])); $mous = json_encode($prm["mous"]); $deliveries = json_encode($prm["deliveries"]); $doctors = addslashes(str_replace('\n', '\\\n', json_encode($prm["doctors"]))); $packettests = array(); if (count($prm['selected_packets']) > 0) { foreach ($prm['selected_packets'] as $kp => $vp) { array_push($packettests, $vp['code']); } } if (count($prm['selected_tests']) > 0) { foreach ($prm['selected_tests'] as $kt => $vt) { array_push($packettests, $vt['code']); } } if (count($packettests) > 0) { $McuOfflinePrepareTests = join(',', $packettests); } if ($prm["act"] == 'new') { $query = " INSERT INTO mcu_offline_prepare( McuOfflinePrepareStartDate, McuOfflinePrepareEndDate, McuOfflinePrepareM_CompanyID, McuOfflinePrepareMous, McuOfflinePrepareDoctors, McuOfflinePrepareM_MouDefaultID, McuOfflinePrepareM_DoctorDefaultID, McuOfflinePrepareM_DoctorAddressDefaultID, McuOfflinePreparePromiseDate, McuOfflinePreparePromiseTime, McuOfflinePrepareDeliveries, McuOfflinePrepareTests, McuOfflinePrepareUserID, McuOfflinePrepareCreated ) VALUES( '{$sdate}', '{$edate}', {$prm["company"]["id"]}, '{$mous}', '{$doctors}', {$prm["default_mou"]["id"]}, {$prm["default_doctor"]["id"]}, {$prm["default_doctor_address"]["id"]}, '{$promise_date}', '{$promise_time}', '{$deliveries}', '{$McuOfflinePrepareTests}', {$userid}, NOW() ) "; //echo $query; $this->db_onedev->query($query); $last_id = $this->db_onedev->insert_id(); } else { $query = " UPDATE mcu_offline_prepare SET McuOfflinePrepareStartDate = '{$sdate}', McuOfflinePrepareEndDate = '{$edate}', McuOfflinePrepareM_CompanyID = {$prm["company"]["id"]}, McuOfflinePrepareMous = '{$mous}', McuOfflinePrepareDeliveries = '{$deliveries}', McuOfflinePrepareDoctors = '{$doctors}', McuOfflinePreparePromiseDate = '{$promise_date}', McuOfflinePreparePromiseTime = '{$promise_time}', McuOfflinePrepareM_MouDefaultID = {$prm["default_mou"]["id"]}, McuOfflinePrepareM_DoctorDefaultID = {$prm["default_doctor"]["id"]}, McuOfflinePrepareM_DoctorAddressDefaultID = {$prm["default_doctor_address"]["id"]}, McuOfflinePrepareUserID = {$userid} WHERE McuOfflinePrepareID = {$prm["xid"]} "; $this->db_onedev->query($query); $last_id = $prm["xid"]; } //echo $query; $sql = "SELECT McuOfflinePrepareCode as xnumber FROM mcu_offline_prepare WHERE McuOfflinePrepareID = {$last_id}"; //echo $sql; $row = $this->db_onedev->query($sql)->row_array(); $result = array( "total" => 1, "records" => $row, ); $this->sys_ok($result); 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'] = 'delete'; $rows[$k]['action'] .= 'edit'; } } $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