Files
BE_IBL/application/controllers/mockup/mcuofflineapp/Preregisterapp.php
2026-06-12 13:33:37 +07:00

2113 lines
65 KiB
PHP

<?php
class Preregisterapp 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->load->library('ibl_encryptor');
}
private function _mask_name($v) {
if (!$v) return $v;
$v = trim($v);
$words = preg_split('/\s+/', $v);
$out = [];
foreach ($words as $w) {
$l = mb_strlen($w, 'UTF-8');
if ($l <= 2) { $out[] = '***'; continue; }
$out[] = mb_substr($w, 0, 2, 'UTF-8') . str_repeat('*', max(3, $l - 2));
}
return implode(' ', $out);
}
private function _mask_phone($v) { if (!$v) return $v; $d=preg_replace('/[^0-9]/','',trim($v)); $l=strlen($d); if($l<=4) return '****'; if($l<=8) return substr($d,0,4).str_repeat('*',$l-4); return substr($d,0,4).str_repeat('*',$l-7).substr($d,-3); }
private function _mask_email($v) { if (!$v||strpos($v,'@')===false) return $v; [$loc,$dom]=explode('@',$v,2); return mb_substr($loc,0,min(2,mb_strlen($loc,'UTF-8')),'UTF-8').'***@'.$dom; }
private function _mask_id($v) { if (!$v) return $v; $v=trim($v); $l=strlen($v); if($l<=4) return '****'; return substr($v,0,4).str_repeat('*',max(3,$l-6)).($l>6?substr($v,-2):''); }
private function _mask_dob($v) { if (!$v) return $v; $p=explode('-',$v); return (count($p)===3) ? '**-**-'.$p[2] : '****-**-**'; }
public function get_setup_by_id()
{
try {
if (!$this->isLogin) {
$this->sys_error("Invalid Token");
exit;
}
$prm = $this->sys_input;
$id = $prm["id"];
$sql = "SELECT *
FROM mgm_mcu
WHERE Mgm_McuIsActive = 'Y' AND Mgm_McuID = {$id}
LIMIT 1";
$qry = $this->db_onedev->query($sql);
if (!$qry) {
$message = $this->db_onedev->error();
$message['last_qry'] = $this->db_onedev->last_query();
$this->sys_error($message);
exit;
}
$data = $qry->result_array();
$result = [
"records" => $data,
];
$this->sys_ok($result);
}
catch (Exception $exc) {
$message = $exc->getMessage();
$this->sys_error($message);
}
}
public function getsetup()
{
try {
if (!$this->isLogin) {
$this->sys_error("Invalid Token");
exit;
}
$prm = $this->sys_input;
$search = $prm["search"];
$id = isset($prm["id"]) ? $prm["id"] : null;
if($id != null){
$sql = "SELECT *
FROM mgm_mcu
WHERE Mgm_McuIsActive = 'Y' AND
Mgm_McuID = {$id}
LIMIT 1";
}else{
$sql = "SELECT *
FROM mgm_mcu
WHERE Mgm_McuIsActive = 'Y' AND ( CURDATE() BETWEEN Mgm_McuStartDate AND Mgm_McuEndDate ) AND
( Mgm_McuLabel LIKE CONCAT('%','{$search}','%') OR Mgm_McuNumber LIKE CONCAT('%','{$search}','%') )
ORDER BY Mgm_McuStartDate ASC, Mgm_McuEndDate ASC";
}
$qry = $this->db_onedev->query($sql);
$last_qry = $this->db_onedev->last_query();
if (!$qry) {
$message = $this->db_onedev->error();
$message['last_qry'] = $last_qry;
$this->sys_error($message);
exit;
}
$data = $qry->result_array();
$result = [
"records" => $data,
];
$this->sys_ok($result);
} catch (Exception $exc) {
$message = $exc->getMessage();
$this->sys_error($message);
}
}
function generate_code_string()
{
$length = 5;
$characters = '0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ';
$code = '';
for ($i = 0; $i < $length; $i++) {
$code .= $characters[rand(0, strlen($characters) - 1)];
}
return $code;
}
function generate_uuid()
{
// Generate 16 bytes (128 bits) of random data
$data = random_bytes(16);
// Set version to 0100
$data[6] = chr(ord($data[6]) & 0x0f | 0x40);
// Set bits 6-7 to 10
$data[8] = chr(ord($data[8]) & 0x3f | 0x80);
// Output the 36 character UUID
return vsprintf('%s%s-%s-%s-%s-%s%s%s', str_split(bin2hex($data), 4));
}
function generate_code_form()
{
try {
if (!$this->isLogin) {
$this->sys_error("Invalid Token");
exit;
}
$prm = $this->sys_input;
$mgm_mcu_id = $prm['id'];
$sql = "SELECT Mcu_PreregisterPatientsID
FROM mcu_preregister_patients
WHERE
Mcu_PreregisterPatientsMgm_McuID = ? AND
(
Mcu_PreregisterPatientsT_OrderHeaderID = 0 OR
Mcu_PreregisterPatientsIsRegistered = 'N'
) AND
Mcu_PreregisterPatientsIsActive = 'Y'
";
$qry = $this->db_onedev->query($sql, [$mgm_mcu_id]);
$last_qry = $this->db_onedev->last_query();
//echo $last_qry;
//exit;
if (!$qry) {
$message = $this->db_onedev->error();
$message['last_qry'] = $last_qry;
$this->sys_error($message);
exit;
}
$data = $qry->result_array();
if (count($data) > 0) {
foreach ($data as $k => $v) {
$sql = "SELECT COUNT(*) as total
FROM form_riwayat_pasien
WHERE FormRiwayatPasienPreregisterID = ? AND
FormRiwayatPasienIsActive = 'Y'
";
$qry = $this->db_onedev->query($sql, [$v['Mcu_PreregisterPatientsID']]);
//echo $this->db_onedev->last_query();
//exit;
if ($qry) {
$total = $qry->result_array()[0]['total'];
if ($total == 0) {
$code = $this->generate_code_string();
$uuid = $this->generate_uuid();
$sql = "INSERT INTO form_riwayat_pasien (
FormRiwayatPasienPreregisterID,
FormRiwayatPasienCode,
FormRiwayatPasienUUID,
FormRiwayatPasienCreated)
VALUES (?, ?, ?, NOW())";
$qry = $this->db_onedev->query($sql, [$v['Mcu_PreregisterPatientsID'], $code, $uuid]);
}
}
}
}
$result = [
"records" => $data,
];
$this->sys_ok($result);
} catch (Exception $exc) {
$message = $exc->getMessage();
$this->sys_error($message);
}
}
function search_patient_listing()
{
$prm = $this->sys_input;
if (!$this->isLogin) {
$this->sys_error("Invalid Token");
exit;
}
$search = $prm["search"];
$setup = $prm["setup"];
$status = $prm["status"];
$sqlStatus = "";
if ($status == 'Y') {
$sqlStatus = "AND Mcu_PreregisterPatientsIsRegistered = 'Y'";
} else if ($status == 'N') {
$sqlStatus = "AND Mcu_PreregisterPatientsIsRegistered = 'N'";
}
$q = [
'name' => '',
'hp' => '',
'dob' => '',
'address' => ''
];
$sql_where = "";
if ($prm['search'] != '') {
$e = explode('+', $prm['search']);
if (count($e) == 1) {
$sql_where .= "AND Mcu_PreregisterPatientsPatientName like CONCAT('%','{$e[0]}','%')";
}
if (count($e) == 2) {
$sql_where .= "AND ( Mcu_PreregisterPatientsPatientName like CONCAT('%','{$e[0]}','%') AND Mcu_PreregisterPatientsNIP like CONCAT('%','{$e[1]}','%')) ";
}
}
// if ($search != "") {
// }
$number_limit = 10;
$number_offset = ($prm['current_page'] - 1) * $number_limit;
// if($setup['Mgm_McuM_BranchID']== '100'){
// }
$sql = " SELECT count(*) as total
FROM (
SELECT
Mcu_PreregisterPatientsID,
M_PatientID
FROM mcu_preregister_patients
JOIN m_patient ON Mcu_PreregisterPatientsM_PatientID = M_PatientID
LEFT JOIN m_title ON Mcu_PreregisterPatientsM_TitleID = M_TitleID
LEFT JOIN t_orderheader ON Mcu_PreregisterPatientsT_OrderHeaderID = T_OrderHeaderID
WHERE
Mcu_PreregisterPatientsIsActive = 'Y' AND Mcu_PreregisterPatientsMgm_McuID = {$setup['Mgm_McuID']}
$sql_where
$sqlStatus
GROUP BY Mcu_PreregisterPatientsID, M_PatientID
) x
";
//echo $sql;
$query = $this->db_onedev->query($sql);
$tot_count = 0;
$tot_page = 0;
if ($query) {
$tot_count = $query->result_array()[0]["total"];
$tot_page = ceil($tot_count / $number_limit);
} else {
$this->sys_error_db("m_doctor count", $this->db_onedev);
exit;
}
$sql = " SELECT *
, '' as agreement,
'' as packets,
'' as tests,
CONCAT(IF(ISNULL(M_TitleName),'',CONCAT(M_TitleName,'.')),
' ',
IFNULL(Mcu_PreregisterPatientsPatientPrefix,''),
' ',
Mcu_PreregisterPatientsPatientName,
' ',
IFNULL(Mcu_PreregisterPatientsPatientSuffix,'')) as patient_fullname,
Mcu_PreregisterPatientsDOB as dob,
Mcu_PreregisterPatientsDOB,
IFNULL(M_PatientAddressDescription, '') as M_PatientAddress,
M_PatientAddressCity,
IFNULL(M_PatientAddressCountry, 'ID') as M_PatientAddressCountry,
IFNULL(display, 'Indonesia') as countryName,
M_PatientAddressRT,
M_PatientAddressRW,
M_PatientReligionCode,
M_CompanyEmail,
IFNULL(M_MouID, '0') as agreement_id,
IFNULL(CONCAT(M_MouNumber, ' | ', M_MouName), '') as agreement_name,
IFNULL(M_MouNumber, '') as agreement_code,
'' as agreement,
IFNULL(FormRiwayatPasienCode, 'Belum digenerate') as code_form,
IFNULL(FormRiwayatPasienUUID, '') as uuid_form
FROM mcu_preregister_patients
JOIN m_patient ON Mcu_PreregisterPatientsM_PatientID = M_PatientID
LEFT JOIN m_patientaddress ON M_PatientID = M_PatientAddressM_PatientID AND M_PatientAddressIsActive = 'Y'
JOIN mgm_mcu ON Mcu_PreregisterPatientsMgm_McuID = Mgm_McuID
JOIN m_company ON Mgm_McuM_CompanyID = M_CompanyID
LEFT join terminology on attribute_path = 'Address.country' AND (
( M_PatientAddressCountry <> '' AND M_PatientAddressCountry IS NOT NULL AND code = M_PatientAddressCountry) OR
( M_PatientAddressCountry = '' AND M_PatientAddressCountry IS NULL AND code = 'ID')
)
LEFT JOIN m_title ON Mcu_PreregisterPatientsM_TitleID = M_TitleID
LEFT JOIN t_orderheader ON Mcu_PreregisterPatientsT_OrderHeaderID = T_OrderHeaderID
LEFT JOIN m_mou ON Mcu_PreregisterPatientsM_MouNumber = M_MouNumber AND M_MouIsActive = 'Y'
LEFT JOIN form_riwayat_pasien ON Mcu_PreregisterPatientsID = FormRiwayatPasienPreregisterID AND FormRiwayatPasienIsActive = 'Y'
WHERE
Mcu_PreregisterPatientsIsActive = 'Y' AND Mcu_PreregisterPatientsMgm_McuID = {$setup['Mgm_McuID']}
$sql_where
$sqlStatus
GROUP BY Mcu_PreregisterPatientsID, M_PatientID
ORDER BY T_OrderHeaderDate DESC, Mcu_PreregisterPatientsIsRegistered ASC, Mcu_PreregisterPatientsPatientName ASC
limit $number_limit offset $number_offset";
$query = $this->db_onedev->query($sql);
//echo $sql;
if (!$query) {
$message = $this->db_onedev->error();
$message['last_qry'] =
$this->db_onedev->last_query();
$this->sys_error($message);
exit;
};
$lastQuerySearch =
$this->db_onedev->last_query();
$rows = $query->result_array();
if ($rows) {
foreach ($rows as $k => $v) {
$rows[$k]['agreement'] = [];
if($v['agreement_id'] != '0'){
$rows[$k]['agreement'] = [
'id' => $v['agreement_id'],
'name' => $v['agreement_name'],
'code' => $v['agreement_code']
];
}
$rows[$k]['packets'] = array();
$rows[$k]['tests'] = array();
//echo $v['agreement_id'];
if($v['agreement_id'] != '0'){
$join_test = '';
$filter_paket = "AND T_PacketSasCode IN ('')";
$filter_test = "AND T_TestSasCode IN ('')";
//echo $v['Mcu_PreregisterPatientsOrders'];
if ($v['Mcu_PreregisterPatientsOrders'] != '') {
$xjoin_tests = explode(',', $v['Mcu_PreregisterPatientsOrders']);
$unique_tests = array(); // array untuk menyimpan nilai unik
//echo $xjoin_tests;
if ($xjoin_tests) {
foreach ($xjoin_tests as $kjt => $vjt) {
$vjt = trim($vjt);
if (!in_array($vjt, $unique_tests)) {
$unique_tests[] = $vjt;
if ($join_test != '')
$join_test .= ",";
$join_test .= "'{$vjt}'";
}
}
}
//print_r($unique_tests)."<br>";
//echo $join_test;
$filter_paket = "AND T_PacketSasCode IN ({$join_test})";
$filter_test = "AND T_TestSasCode IN ({$join_test}) ";
}
$sql = "SELECT DISTINCT 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'
JOIN mgm_mcupacket ON T_PacketID = Mgm_McuPacketT_PacketID
AND Mgm_McuPacketIsActive = 'Y' AND Mgm_McuPacketMgm_McuID = {$setup['Mgm_McuID']}
WHERE
T_PriceM_MouID = {$v['agreement_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
T_PriceM_MouID = {$v['agreement_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']);
}
}
}
}
$pids = array();
$sql = "SELECT Mcu_PreregisterPatientsM_PatientID as id
FROM mcu_preregister_patients
WHERE
Mcu_PreregisterPatientsIsActive = 'Y' AND Mcu_PreregisterPatientsMgm_McuID = '{$setup['Mgm_McuID']}'";
$rows_all = $this->db_onedev->query($sql)->result_array();
//echo $sql;
if ($rows_all) {
foreach ($rows_all as $ka => $va) {
array_push($pids, $va['id']);
}
}
}
//$this->_add_address($rows);
$result = array(
"total" => $tot_page,
"total_data" => $tot_count,
"records" => $rows,
"pids" => $pids,
"sql" => $this->db_onedev->last_query(),
"sqlsrc" => $lastQuerySearch
);
$this->sys_ok($result);
exit;
}
function search_patient_table()
{
$prm = $this->sys_input;
$setup = $prm['setup'];
$max_rst = 100;
$tot_count = 0;
$number_limit = 10;
$number_offset = (!isset($prm['current_page']) ? 1 : $prm['current_page'] - 1) * $number_limit;
if (isset($prm['reload'])) {
$number_limit = intval($prm['current_page']) * 10;
$number_offset = 0;
}
$q = [
'name' => '',
'hp' => '',
'dob' => '',
'address' => ''
];
if ($prm['search'] != '') {
$e = explode('+', $prm['search']);
if (isset($e[0]) && $e[0] != '') {
$name_toks = $this->ibl_encryptor->query_tokens($e[0]);
$name_conds = [];
foreach ($name_toks as $tok) {
$tok_esc = $this->db_onedev->escape_str($tok);
$name_conds[] = "JSON_CONTAINS(M_PatientName_bidx, '\"$tok_esc\"')";
}
if ($name_conds) $q['name'] = "AND " . implode(' AND ', $name_conds);
}
if (isset($e[1]) && $e[1] != '') {
$dob_toks = $this->ibl_encryptor->query_tokens($e[1]);
$dob_conds = [];
foreach ($dob_toks as $tok) {
$tok_esc = $this->db_onedev->escape_str($tok);
$dob_conds[] = "JSON_CONTAINS(M_PatientDOB_bidx, '\"$tok_esc\"')";
}
if ($dob_conds) $q['dob'] = "AND " . implode(' AND ', $dob_conds);
}
if (isset($e[2]) && $e[2] != '')
$q['nik'] = "AND M_PatientNIP LIKE '%{$e[2]}%'";
}
$sql = "SELECT m_patient.*,
'N' divider,
concat(IFNULL(M_TitleName,''),' ',IFNULL(M_PatientPrefix,''),' ',M_PatientName,' ',IFNULL(M_PatientSuffix,'')) M_PatientName,
M_PatientName M_PatientRealName, M_TitleID, M_TitleName, M_PatientM_SexID,
M_PatientDOB as dob_ina,
IFNULL(M_PatientReligionCode, '-') M_PatientReligionCode,
M_PatientNoReg as Mcu_PreregisterPatientsPID,
M_PatientIdentifierValue as Mcu_PreregisterPatientsKTP,
M_PatientID as Mcu_PreregisterPatientsM_PatientID,
M_TitleID as Mcu_PreregisterPatientsM_TitleID,
M_PatientName as Mcu_PreregisterDetailsPatientName,
M_PatientM_SexID as Mcu_PreregisterPatientsPatientName,
M_PatientDOB as Mcu_PreregisterPatientsDOB,
IFNULL(M_PatientReligionCode,0) as Mcu_PreregisterPatientsReligion,
M_PatientEmail as Mcu_PreregisterPatientsEmail,
M_PatientHP as Mcu_PreregisterPatientsHp,
M_PatientPosisi as Mcu_PreregisterPatientsPosisi,
M_PatientDivisi as Mcu_PreregisterPatientsDivisi,
M_PatientJob as Mcu_PreregisterPatientsJob,
M_PatientDepartement as Mcu_PreregisterPatientsDepartment
from
m_patient
LEFT join m_title on M_PatientM_TitleID = M_TitleID
where M_PatientIsActive = 'Y'
{$q['name']}
{$q['dob']}
{$q['nik']}
group by M_PatientID
limit $number_limit offset $number_offset";
//echo $sql;
$query = $this->db_onedev->query($sql);
$qryListing = $this->db_onedev->last_query();
if ($query) {
$rows = $query->result_array();
if ($rows) {
$per_divider = 1;
foreach ($rows as $k => $v) {
if ($per_divider == 10) {
$rows[$k]['divider'] = 'Y';
}
$per_divider = $per_divider + 1;
if ($per_divider > 10)
$per_divider = 1;
}
}
$pids = array();
$sql = "SELECT Mcu_PreregisterPatientsM_PatientID as id
FROM mcu_preregister_patients
WHERE
Mcu_PreregisterPatientsIsActive = 'Y' AND Mcu_PreregisterPatientsMgm_McuID = '{$setup['Mgm_McuID']}'";
$rows_all = $this->db_onedev->query($sql)->result_array();
//echo $sql;
if ($rows_all) {
foreach ($rows_all as $ka => $va) {
array_push($pids, $va['id']);
}
}
$result = array("total" => "", "records" => $rows, "pids" => $pids, "sql" => $this->db_onedev->last_query(), "qrylisting" => $qryListing);
$this->sys_ok($result);
} else {
$this->sys_error_db("m_patient rows", $this->db_onedev);
exit;
}
}
function savenewform()
{
// $this->db_onedev->trans_begin();
$this->db_onedev->trans_begin();
// $this->db_onedev->trans_rollback();
// $this->db_onedev->trans_commit();
if (!$this->isLogin) {
$this->sys_error("Invalid Token");
exit;
}
$userid = $this->sys_user["M_UserID"];
$prm = $this->sys_input;
//print_r($prm);
$setup = $prm['setup'];
$sql = "SELECT M_CompanyNumber FROM m_company WHERE M_CompanyID = '{$setup['Mgm_McuM_CompanyID']}'";
$qry = $this->db_onedev->query($sql);
if (!$qry) {
$message = $this->db_onedev->error();
$this->db_onedev->trans_rollback();
$this->sys_error($message);
exit;
}
$companyNumber = $qry->row_array()['M_CompanyNumber'];
$v = $prm;
$name = str_replace("'", "\\'", $v['M_PatientRealName']);
$nameEscape = $this->db_onedev->escape($v['M_PatientRealName']);
// print_r($name);
$pdob = date('Y-m-d', strtotime($v['M_PatientDOB']));
$agreement_number = $v['selected_agreement']?$v['selected_agreement']['code']:'';
$this->db_onedev->trans_begin();
$query = "INSERT INTO mcu_preregister_patients (
Mcu_PreregisterPatientsMgm_McuID,
Mcu_PreregisterPatientsPID,
Mcu_PreregisterPatientsM_PatientID,
Mcu_PreregisterPatientsKTP,
Mcu_PreregisterPatientsPatientPrefix,
Mcu_PreregisterPatientsPatientName,
Mcu_PreregisterPatientsPatientSuffix,
Mcu_PreregisterPatientsM_SexID,
Mcu_PreregisterPatientsDOB,
Mcu_PreregisterPatientsReligion,
Mcu_PreregisterPatientsJob,
Mcu_PreregisterPatientsEmail,
Mcu_PreregisterPatientsHp,
Mcu_PreregisterPatientsPosisi,
Mcu_PreregisterPatientsDivisi,
Mcu_PreregisterPatientsLocation,
Mcu_PreregisterPatientsCreated,
Mcu_PreregisterPatientsUserID,
Mcu_PreregisterPatientsM_TitleID,
Mcu_PreregisterPatientsCompanyNumber,
Mcu_PreregisterPatientsDepartment,
Mcu_PreregisterPatientsNIP,
Mcu_PreregisterPatientsM_MouNumber
)
VALUES(
?,
?,
?,
?,
?,
?,
?,
?,
?,
?,
?,
?,
?,
?,
?,
?,
NOW(),
?,
?,
?,
?,
?,
?
)";
//echo $query;
$m_dob_ptp = $this->_mask_dob(date('d-m-Y', strtotime($pdob)));
$rows = $this->db_onedev->query($query, [
$setup['Mgm_McuID'],
$v['Mcu_PreregisterPatientsPID'],
$v['M_PatientID'],
$v['Mcu_PreregisterPatientsKTP'] ? $this->_mask_id($v['Mcu_PreregisterPatientsKTP']) : '',
$v['M_PatientPrefix'],
$this->_mask_name($v['M_PatientRealName']),
$v['M_PatientSuffix'],
$v['M_PatientM_SexID'],
$m_dob_ptp,
$v['M_PatientReligionCode'],
$v['Mcu_PreregisterPatientsJob'],
$this->_mask_email($v['Mcu_PreregisterPatientsEmail']),
$this->_mask_phone($v['Mcu_PreregisterPatientsHp']),
$v['Mcu_PreregisterPatientsPosisi'],
$v['Mcu_PreregisterPatientsDivisi'],
$v['Mcu_PreregisterPatientsLocation'],
$userid,
$v['Mcu_PreregisterPatientsM_TitleID'],
$companyNumber,
$v['Mcu_PreregisterPatientsDepartment'],
$v['Mcu_PreregisterPatientsNIK'],
$agreement_number
]);
if (!$rows) {
$message = $this->db_onedev->error();
$this->db_onedev->trans_rollback();
$this->sys_error($message);
exit;
}
$last_id_x = $this->db_onedev->insert_id();
if (intval($v['Mcu_PreregisterPatientsM_PatientID']) == 0) {
$sql = "SELECT fn_numbering_ibl('PA') as number";
$rows = $this->db_onedev->query($sql);
if (!$rows) {
$message = $this->db_onedev->error();
$this->db_onedev->trans_rollback();
$this->sys_error($message);
exit;
}
$number = $rows->result_array()[0]['number'];
$title_id = $v['Mcu_PreregisterPatientsM_TitleID'];
// $religion_id = $v['Mcu_PreregisterDetailsM_ReligionID'];
$religion_id = '';
$nameNewP = $this->db_onedev->escape($v["Mcu_PreregisterPatientsPatientName"]);
$nameNewPn = str_replace("'", "\\'", $v['Mcu_PreregisterPatientsPatientName']);
$typeIdentifier = 'NNIDN';
if ($v['Mcu_PreregisterPatientsKTP'] != '') {
$typeIdentifier = 'NNIDN';
}
$IdentifierSystem = 'http://terminology.hl7.org/CodeSystem/v2-0203';
if ($v['Mcu_PreregisterPatientsKTP'] != '') {
$IdentifierSystem = 'http://terminology.hl7.org/CodeSystem/v2-0203';
}
$enc_new = $this->ibl_encryptor;
$plain_name_new = $v['Mcu_PreregisterPatientsPatientName'];
$plain_ktp_new = $v['Mcu_PreregisterPatientsKTP'];
$plain_email_new = $v['Mcu_PreregisterPatientsEmail'];
$plain_hp_new = $v['Mcu_PreregisterPatientsHp'];
$dob_str_new = date('d-m-Y', strtotime($pdob));
$sql = "INSERT INTO m_patient (
M_PatientPrefix,
M_PatientName,
M_PatientName_enc,
M_PatientName_bidx,
M_PatientSuffix,
M_PatientM_TitleID,
M_PatientM_SexID,
M_PatientDOB,
M_PatientDOB_enc,
M_PatientDOB_bidx,
M_PatientIdentifierCode,
M_PatientIdentifierSystem,
M_PatientIdentifierValue,
M_PatientIDNumber,
M_PatientIDNumber_enc,
M_PatientNIK_bidx,
M_PatientPosisi,
M_PatientDivisi,
M_PatientLocation,
M_PatientJob,
M_PatientEmail,
M_PatientEmail_enc,
M_PatientHP,
M_PatientHP_enc,
M_PatientHP_bidx,
M_PatientCreatedUserID,
M_PatientNIP,
M_PatientDepartement,
M_PatientNoReg,
M_PatientCreated,
M_PatientRegisteredByCompanyID
)
VALUES(?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,NOW(),?)";
$rows = $this->db_onedev->query($sql, [
$v['Mcu_PreregisterPatientsPatientPrefix'],
$this->_mask_name($plain_name_new),
$enc_new->encrypt($plain_name_new),
$enc_new->search_bidx($plain_name_new),
$v['Mcu_PreregisterPatientsPatientSuffix'],
$title_id,
$v['M_PatientM_SexID'],
$this->_mask_dob($dob_str_new),
$enc_new->encrypt($dob_str_new),
$enc_new->search_bidx($dob_str_new),
$typeIdentifier,
$IdentifierSystem,
$plain_ktp_new ? $this->_mask_id($plain_ktp_new) : '',
$plain_ktp_new ? $this->_mask_id($plain_ktp_new) : null,
$plain_ktp_new ? $enc_new->encrypt($plain_ktp_new) : null,
$enc_new->search_bidx($plain_ktp_new ?? ''),
$v['Mcu_PreregisterPatientsPosisi'],
$v['Mcu_PreregisterPatientsDivisi'],
$v['Mcu_PreregisterPatientsLocation'],
$v['Mcu_PreregisterPatientsJob'],
$plain_email_new ? $this->_mask_email($plain_email_new) : '',
$plain_email_new ? $enc_new->encrypt($plain_email_new) : null,
$plain_hp_new ? $this->_mask_phone($plain_hp_new) : '',
$plain_hp_new ? $enc_new->encrypt($plain_hp_new) : null,
$enc_new->search_bidx($plain_hp_new ?? ''),
$userid,
$v['Mcu_PreregisterPatientsNIK'],
$v['Mcu_PreregisterPatientsDepartment'],
$number,
$setup['Mgm_McuM_CompanyID']
]);
if (!$rows) {
$message = $this->db_onedev->error();
$message['qry'] = $this->db_onedev->last_query();
$this->db_onedev->trans_rollback();
$this->sys_error($message);
exit;
}
$patient_id = $this->db_onedev->insert_id();
if ($patient_id) {
$sql = "INSERT INTO m_patientaddress (
M_PatientAddressM_PatientID,
M_PatientAddressDescription,
M_PatientAddressRegionalCd,
M_PatientAddressRT,
M_PatientAddressRW,
M_PatientAddressVillage,
M_PatientAddressDistrict,
M_PatientAddressCity,
M_PatientAddressState,
M_PatientAddressCountry,
M_PatientAddressCreated,
M_PatientAddressCreatedUserID
)
VALUES(?,?,?,?,?,?,?,?,?,?,NOW(),?)";
$save_address = $this->db_onedev->query($sql, [
$patient_id,
$v['inp_CompanyAddress'],
$v['inp_RegionalCode'],
$v['inp_CompanyAddressRT'],
$v['inp_CompanyAddressRW'],
$v['inp_CompanyAddressVillage'],
$v['inp_CompanyAddressDistrict'],
$v['inp_CompanyAddressCity'],
$v['inp_CompanyAddressState'],
$v['country'],
$userid
]);
if (!$save_address) {
$message = $this->db_onedev->error();
$this->db_onedev->trans_rollback();
$this->sys_error($message);
exit;
}
}
$sql = "UPDATE mcu_preregister_patients SET Mcu_PreregisterPatientsM_PatientID = {$patient_id}, Mcu_PreregisterPatientsPID ='{$number}' WHERE Mcu_PreregisterPatientsID = {$last_id_x}";
$rows = $this->db_onedev->query($sql);
if (!$rows) {
$message = $this->db_onedev->error();
$this->db_onedev->trans_rollback();
$this->sys_error($message);
exit;
}
}
$this->db_onedev->trans_commit();
$result = array(
"total" => 1,
"records" => array('status' => 'OK')
);
$this->db_onedev->trans_commit();
$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'
";
// $gender = [
// [
// "M_SexID" => "MALE",
// "M_SexCode" => "MALE",
// "m_sexname" => "Laki Laki"
// ],
// [
// "M_SexID" => "FEMALE",
// "M_SexCode" => "FEMALE",
// "m_sexname" => "Perempuan"
// ]
// ];
//echo $query;
$rows['titles'] = $this->db_onedev->query($query)->result_array();
$query = "SELECT * FROM m_sex WHERE M_SexIsActive = 'Y'";
$rows['sexes'] = $this->db_onedev->query($query)->result_array();
$query = " SELECT * FROM terminology
WHERE attribute_path = 'Person.religion.code'
AND code_system = 'xcpone.code.religion'
AND status_cd = 'normal'
ORDER BY order_no
";
//echo $query;
$rows['religions'] = $this->db_onedev->query($query)->result_array();
$query = " SELECT * FROM terminology
WHERE attribute_path = 'Person.identifier.type'
AND code_system = 'http://terminology.hl7.org/CodeSystem/v2-0203'
AND status_cd = 'normal'
ORDER BY order_no
";
//echo $query;
$rows['kartuidentitass'] = $this->db_onedev->query($query)->result_array();
$result = array(
"total" => count($rows),
"records" => $rows,
);
$this->sys_ok($result);
exit;
}
function removepatient()
{
if (!$this->isLogin) {
$this->sys_error("Invalid Token");
exit;
}
$userid = $this->sys_user["M_UserID"];
$prm = $this->sys_input;
$query = " UPDATE mcu_preregister_patients SET
Mcu_PreregisterPatientsIsActive = 'N',
Mcu_PreregisterPatientsUserID = {$userid}
WHERE
Mcu_PreregisterPatientsID = {$prm['Mcu_PreregisterPatientsID']}";
$this->db_onedev->query($query);
$result = array(
"total" => 1,
"records" => array('status' => 'OK')
);
$this->sys_ok($result);
exit;
}
function getagreements()
{
if (!$this->isLogin) {
$this->sys_error("Invalid Token");
exit;
}
$prm = $this->sys_input;
$query = "SELECT M_MouID as id, CONCAT(M_MouNumber, ' | ', M_MouName) as name, M_MouNumber as code
FROM mcu_preregister_patients cp
JOIN mgm_mou ON cp.Mcu_PreregisterPatientsMgm_McuID = Mgm_MouMgm_McuID AND Mgm_MouIsActive = 'Y'
JOIN m_mou ON Mgm_MouM_MouID = M_MouID AND M_MouIsActive = 'Y'
WHERE
cp.Mcu_PreregisterPatientsID = {$prm['preregister_id']}";
$rows = $this->db_onedev->query($query);
if (!$rows) {
$message = $this->db_onedev->error();
$message['qry'] = $this->db_onedev->last_query();
$this->sys_error($message);
exit;
}
$data = $rows->result_array();
$result = array(
"total" => 1,
"records" => $data
);
$this->sys_ok($result);
exit;
}
function getdatapackets()
{
if (!$this->isLogin) {
$this->sys_error("Invalid Token");
exit;
}
$prm = $this->sys_input;
$search = $prm["search"];
$setup = $prm["setup"];
$selected_agreement_id = $prm["selected_agreement"]?$prm["selected_agreement"]["id"]:0;
$number_limit = 10;
$number_offset = ($prm['current_page'] - 1) * $number_limit;
$sql = "SELECT count(*) as total
FROM (
SELECT distinct 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'
JOIN mgm_mcupacket ON T_PacketID = Mgm_McuPacketT_PacketID
AND Mgm_McuPacketIsActive = 'Y' AND Mgm_McuPacketMgm_McuID = {$setup['Mgm_McuID']}
JOIN mgm_mcu ON Mgm_McuID = Mgm_McuPacketMgm_McuID
JOIN mgm_mou ON Mgm_MouMgm_McuID = Mgm_McuID AND Mgm_MouIsActive = 'Y' AND
Mgm_MouM_MouID = Ss_PriceMouM_MouID AND Mgm_MouM_MouID = {$selected_agreement_id}
WHERE
is_packet = 'Y' AND
( T_TestName LIKE CONCAT('%','{$search}','%') )
) x
";
//echo $sql;
$query = $this->db_onedev->query($sql, []);
$tot_count = 0;
$tot_page = 0;
if ($query) {
$tot_count = $query->result_array()[0]["total"];
$tot_page = ceil($tot_count / $number_limit);
} else {
$this->sys_error_db("m_doctor count", $this->db_onedev);
exit;
}
$query = "SELECT distinct T_PacketID as id, T_PacketName as name, T_PacketSasCode as code, nat_test, ss_price_mou.T_PriceTotal as price
FROM ss_price_mou
JOIN t_packet ON T_TestID = T_PacketID AND T_PacketIsActive = 'Y'
JOIN mgm_mcupacket ON T_PacketID = Mgm_McuPacketT_PacketID
AND Mgm_McuPacketIsActive = 'Y' AND Mgm_McuPacketMgm_McuID = {$setup['Mgm_McuID']}
JOIN mgm_mcu ON Mgm_McuID = Mgm_McuPacketMgm_McuID
JOIN mgm_mou ON Mgm_MouMgm_McuID = Mgm_McuID AND Mgm_MouIsActive = 'Y' AND
Mgm_MouM_MouID = Ss_PriceMouM_MouID AND Mgm_MouM_MouID = {$selected_agreement_id}
WHERE
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,
'qry' => $this->db_onedev->last_query(),
);
$this->sys_ok($result);
exit;
}
function getdatatests()
{
if (!$this->isLogin) {
$this->sys_error("Invalid Token");
exit;
}
$prm = $this->sys_input;
$search = $prm["search"];
$setup = $prm["setup"];
$agreement_id = $prm["selected_agreement"]?$prm["selected_agreement"]["id"]:0;
$number_limit = 10;
$number_offset = ($prm['current_page'] - 1) * $number_limit;
$sql = "SELECT count(*) as total
FROM ss_price_mou
JOIN mgm_mcu ON Mgm_McuID = {$setup['Mgm_McuID']} AND Ss_PriceMouM_MouID = {$agreement_id}
JOIN t_test test ON test.T_TestID = ss_price_mou.T_TestID AND T_TestIsActive = 'Y'
AND (test.T_TestName LIKE CONCAT('%','{$search}','%') OR test.T_TestSasCode LIKE CONCAT('%','{$search}','%'))
WHERE
is_packet = 'N' AND Ss_PriceMouM_MouID = {$agreement_id}
AND T_PriceIsCito = 'N'
";
//echo $sql;
$query = $this->db_onedev->query($sql, []);
$tot_count = 0;
$tot_page = 0;
if ($query) {
$tot_count = $query->result_array()[0]["total"];
$tot_page = ceil($tot_count / $number_limit);
} else {
$this->sys_error_db("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,ss_price_mou.T_PriceTotal as price
FROM ss_price_mou
JOIN mgm_mcu ON Mgm_McuID = {$setup['Mgm_McuID']} AND Ss_PriceMouM_MouID = {$agreement_id}
JOIN t_test test ON test.T_TestID = ss_price_mou.T_TestID AND T_TestIsActive = 'Y'
AND (test.T_TestName LIKE CONCAT('%','{$search}','%') OR test.T_TestSasCode LIKE CONCAT('%','{$search}','%'))
WHERE
is_packet = 'N' AND Ss_PriceMouM_MouID = {$agreement_id}
AND T_PriceIsCito = 'N'
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 savepreregisterpatient()
{
$prm = $this->sys_input;
$userid = $this->sys_user["M_UserID"];
if (!$this->isLogin) {
$this->sys_error("Invalid Token");
exit;
}
$v = $prm['selected_patient'];
$religion = $v['selected_religion'];
$religionCode = $religion['code'];
$religionSystem = $religion['code_system'];
$setup = $prm['setup'];
$antrian = $prm['antrian'] ? $prm['antrian'] : '';
$agreement_code = $prm['selected_agreement']['code'] ? $prm['selected_agreement']['code'] : '';
if($agreement_code == '' || $agreement_code == '0'){
$this->sys_error("Agreement is required");
exit;
}
$pdob_input = $v['Mcu_PreregisterPatientsDOB'];
$Mcu_PreregisterPatientsTests = '';
$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) {
$Mcu_PreregisterPatientsTests = join(',', $packettests);
}
$sql = "SELECT * FROM m_patient
LEFT JOIN m_patientaddress ON M_PatientAddressM_PatientID = M_PatientID AND M_PatientAddressIsActive = 'Y' AND M_PatientAddressNote = 'Utama'
WHERE M_PatientID = ?";
$rows = $this->db_onedev->query($sql, [$v['Mcu_PreregisterPatientsM_PatientID']]);
if (!$rows) {
$message = $this->db_onedev->error();
$message['qry'] = $this->db_onedev->last_query();
$this->sys_error($message);
exit;
}
$dataPatientBefore = $rows->row_array();
$enc_upd = $this->ibl_encryptor;
$pdob_ts = strtotime($pdob_input);
if ($pdob_ts && $pdob_ts > 0 && strpos($pdob_input, '*') === false) {
$dob_str_upd = date('d-m-Y', $pdob_ts);
$pdob = date('Y-m-d', $pdob_ts);
} else {
$dob_str_upd = $enc_upd->decrypt($dataPatientBefore['M_PatientDOB_enc'] ?? '') ?: '';
$pdob = $dob_str_upd ? date('Y-m-d', strtotime($dob_str_upd)) : '';
}
$plain_name_upd = $v['Mcu_PreregisterPatientsPatientName'];
$plain_ktp_upd = $v['Mcu_PreregisterPatientsKTP'];
$plain_email_upd = $v['Mcu_PreregisterPatientsEmail'];
$plain_hp_upd = $v['Mcu_PreregisterPatientsHp'];
$this->db_onedev->trans_begin();
$query = " UPDATE mcu_preregister_patients SET
Mcu_PreregisterPatientsM_PatientID = ?,
Mcu_PreregisterPatientsKTP = ?,
Mcu_PreregisterPatientsNIP = ?,
Mcu_PreregisterPatientsPatientPrefix = ?,
Mcu_PreregisterPatientsPatientName = ?,
Mcu_PreregisterPatientsPatientSuffix = ?,
Mcu_PreregisterPatientsEmail = ?,
Mcu_PreregisterPatientsHp = ?,
Mcu_PreregisterPatientsDOB = ?,
Mcu_PreregisterPatientsPosisi = ?,
Mcu_PreregisterPatientsDivisi = ?,
Mcu_PreregisterPatientsJob = ?,
Mcu_PreregisterPatientsLocation = ?,
Mcu_PreregisterPatientsM_SexID = ?,
Mcu_PreregisterPatientsM_TitleID = ?,
Mcu_PreregisterPatientsCompanyNumber = ?,
Mcu_PreregisterPatientsDepartment = ?,
Mcu_PreregisterPatientsReligion = ?,
Mcu_PreregisterPatientsM_MouNumber = ?,
Mcu_PreregisterPatientsOrders = ?,
Mcu_PreregisterPatientsUserID = ?,
Mcu_PreregisterPatientsLastUpdated = NOW()
WHERE
Mcu_PreregisterPatientsID = ?";
//echo $query;
$rows = $this->db_onedev->query($query, [
$v['Mcu_PreregisterPatientsM_PatientID'],
$plain_ktp_upd ? $this->_mask_id($plain_ktp_upd) : '',
$v['Mcu_PreregisterPatientsNIP'],
$v['Mcu_PreregisterPatientsPatientPrefix'],
$this->_mask_name($plain_name_upd),
$v['Mcu_PreregisterPatientsPatientSuffix'],
$plain_email_upd ? $this->_mask_email($plain_email_upd) : '',
$plain_hp_upd ? $this->_mask_phone($plain_hp_upd) : '',
$this->_mask_dob($dob_str_upd),
$v['Mcu_PreregisterPatientsPosisi'],
$v['Mcu_PreregisterPatientsDivisi'],
$v['Mcu_PreregisterPatientsJob'],
$v['Mcu_PreregisterPatientsLocation'],
$v['Mcu_PreregisterPatientsM_SexID'],
$v['Mcu_PreregisterPatientsM_TitleID'],
$v['Mcu_PreregisterPatientsCompanyNumber'],
$v['Mcu_PreregisterPatientsDepartment'],
$religionCode,
$agreement_code,
$Mcu_PreregisterPatientsTests,
$userid,
$v['Mcu_PreregisterPatientsID']
]);
if (!$rows) {
$message = $this->db_onedev->error();
$message['qry'] = $this->db_onedev->last_query();
$this->db_onedev->trans_rollback();
$this->sys_error($message);
exit;
}
$ktp_mask_upd = $plain_ktp_upd ? $this->_mask_id($plain_ktp_upd) : '';
$sql = "UPDATE m_patient SET
M_PatientIdentifierCode = ?,
M_PatientIdentifierSystem = ?,
M_PatientIdentifierValue = ?,
M_PatientIDNumber = ?,
M_PatientIDNumber_enc = ?,
M_PatientNIK_bidx = ?,
M_PatientDOB = ?,
M_PatientDOB_enc = ?,
M_PatientDOB_bidx = ?,
M_PatientM_TitleID = ?,
M_PatientNIP = ?,
M_PatientM_SexID = ?,
M_PatientPrefix = ?,
M_PatientName = ?,
M_PatientName_enc = ?,
M_PatientName_bidx = ?,
M_PatientSuffix = ?,
M_PatientEmail = ?,
M_PatientEmail_enc = ?,
M_PatientHP = ?,
M_PatientHP_enc = ?,
M_PatientHP_bidx = ?,
M_PatientDivisi = ?,
M_PatientPosisi = ?,
M_PatientLocation = ?,
M_PatientJob = ?,
M_PatientDepartement = ?,
M_PatientReligionCode = ?,
M_PatientReligionSystem = ?,
M_PatientLastUpdatedUserID = ?,
M_PatientLastUpdated = NOW()
WHERE
M_PatientID = ?
";
$qry = $this->db_onedev->query($sql, [
$plain_ktp_upd ? 'NNIDN' : '',
$plain_ktp_upd ? 'http://terminology.hl7.org/CodeSystem/v2-0203' : '',
$ktp_mask_upd,
$ktp_mask_upd,
$plain_ktp_upd ? $enc_upd->encrypt($plain_ktp_upd) : null,
$enc_upd->search_bidx($plain_ktp_upd ?? ''),
$this->_mask_dob($dob_str_upd),
$enc_upd->encrypt($dob_str_upd),
$enc_upd->search_bidx($dob_str_upd),
$v['Mcu_PreregisterPatientsM_TitleID'],
$v['Mcu_PreregisterPatientsNIP'],
$v['Mcu_PreregisterPatientsM_SexID'],
$v['Mcu_PreregisterPatientsPatientPrefix'],
$this->_mask_name($plain_name_upd),
$enc_upd->encrypt($plain_name_upd),
$enc_upd->search_bidx($plain_name_upd),
$v['Mcu_PreregisterPatientsPatientSuffix'],
$plain_email_upd ? $this->_mask_email($plain_email_upd) : '',
$plain_email_upd ? $enc_upd->encrypt($plain_email_upd) : null,
$plain_hp_upd ? $this->_mask_phone($plain_hp_upd) : '',
$plain_hp_upd ? $enc_upd->encrypt($plain_hp_upd) : null,
$enc_upd->search_bidx($plain_hp_upd ?? ''),
$v['Mcu_PreregisterPatientsDivisi'],
$v['Mcu_PreregisterPatientsPosisi'],
$v['Mcu_PreregisterPatientsLocation'],
$v['Mcu_PreregisterPatientsJob'],
$v['Mcu_PreregisterPatientsDepartment'],
$religionCode,
$religionSystem,
$userid,
$v['Mcu_PreregisterPatientsM_PatientID']
]);
if (!$qry) {
$message = $this->db_onedev->error();
$message['qry'] = $this->db_onedev->last_query();
$this->db_onedev->trans_rollback();
$this->sys_error($message);
exit;
}
//echo $this->db_onedev->last_query();
$sql = "SELECT * FROM m_patientaddress
WHERE
M_PatientAddressM_PatientID = ? AND
M_PatientAddressIsActive = 'Y' AND
M_PatientAddressNote = 'Utama'
ORDER BY M_PatientAddressCreated DESC
LIMIT 1";
$qry = $this->db_onedev->query($sql, [$v['Mcu_PreregisterPatientsM_PatientID']]);
if (!$qry) {
$message = $this->db_onedev->error();
$message['qry'] = $this->db_onedev->last_query();
$this->db_onedev->trans_rollback();
$this->sys_error($message);
exit;
}
$dt_address = $qry->result_array();
if (count($dt_address) > 0) {
$sql = "UPDATE m_patientaddress SET
M_PatientAddressDescription = ?,
M_PatientAddressRegionalCd = ?,
M_PatientAddressRT = ?,
M_PatientAddressRW = ?,
M_PatientAddressVillage = ?,
M_PatientAddressDistrict = ?,
M_PatientAddressCity = ?,
M_PatientAddressState = ?,
M_PatientAddressCountry = ?,
M_PatientAddressLastUpdated = NOW(),
M_PatientAddressLastUpdatedUserID = ?
WHERE M_PatientAddressID = ?";
$qry = $this->db_onedev->query($sql, [
$prm['M_PatientAddress'],
$prm['M_PatientAddressRegionalCd'],
$prm['M_PatientAddressRT'],
$prm['M_PatientAddressRW'],
$prm['M_PatientAddressVillage'],
$prm['M_PatientAddressDistrict'],
$prm['M_PatientAddressCity'],
$prm['M_PatientAddressState'],
$prm['M_PatientAddressCountry'],
$userid,
$dt_address[0]['M_PatientAddressID']
]);
if (!$qry) {
$message = $this->db_onedev->error();
$this->db_onedev->trans_rollback();
$this->sys_error($message);
exit;
}
} else {
$sql = "INSERT INTO m_patientaddress (
M_PatientAddressM_PatientID,
M_PatientAddressDescription,
M_PatientAddressRegionalCd,
M_PatientAddressRT,
M_PatientAddressRW,
M_PatientAddressVillage,
M_PatientAddressDistrict,
M_PatientAddressCity,
M_PatientAddressState,
M_PatientAddressCountry,
M_PatientAddressCreated,
M_PatientAddressCreatedUserID
) VALUES(?,?,?,?,?,?,?,?,?,?,NOW(),?)";
$qry = $this->db_onedev->query($sql, [
$v['Mcu_PreregisterPatientsM_PatientID'],
$prm['M_PatientAddress'],
$prm['M_PatientAddressRegionalCd'],
$prm['M_PatientAddressRT'],
$prm['M_PatientAddressRW'],
$prm['M_PatientAddressVillage'],
$prm['M_PatientAddressDistrict'],
$prm['M_PatientAddressCity'],
$prm['M_PatientAddressState'],
$prm['M_PatientAddressCountry'],
$userid
]);
if (!$qry) {
$message = $this->db_onedev->error();
$this->db_onedev->trans_rollback();
$this->sys_error($message);
exit;
}
}
if ($antrian != '' && $antrian != null) {
$sql = "INSERT INTO preregister_antrian(
PreregisterAntrianMcu_PreregisterPatientsID,
PreregisterAntrianMgm_McuID,
PreregisterAntrianM_PatientID,
PreregisterAntrianNumber,
PreregisterAntrianUserID,
PreregisterAntrianCreated
) VALUES(?,?,?,?,?,NOW())";
$qry = $this->db_onedev->query($sql, [
$v['Mcu_PreregisterPatientsID'],
$v['Mcu_PreregisterPatientsMgm_McuID'],
$v['Mcu_PreregisterPatientsM_PatientID'],
$antrian,
$userid
]);
if (!$qry) {
$message = $this->db_onedev->error();
$message['qry'] = $this->db_onedev->last_query();
$this->db_onedev->trans_rollback();
$this->sys_error($message);
exit;
}
}
$sql = "SELECT * FROM m_patient
JOIN m_patientaddress ON M_PatientAddressM_PatientID = M_PatientID AND M_PatientAddressIsActive = 'Y' AND M_PatientAddressNote = 'Utama'
WHERE M_PatientID = ?
";
$rows = $this->db_onedev->query($sql, [$v['Mcu_PreregisterPatientsM_PatientID']]);
if (!$rows) {
$message = $this->db_onedev->error();
$message['qry'] = $this->db_onedev->last_query();
$this->sys_error($message);
exit;
}
$dataPatientAfter = $rows->row_array();
$sql = "INSERT INTO one_lab_log.log_patient(
Log_PatientM_PatientID,
Log_PatientDate,
Log_PatientCode,
Log_PatientJsonBefore,
Log_PatientJsonAfter,
Log_PatientUserID)
VALUES (?, NOW(), 'EDIT', ?, ?, ?)";
$rows = $this->db_onedev->query($sql, [
$v['Mcu_PreregisterPatientsM_PatientID'],
json_encode($dataPatientBefore),
json_encode($dataPatientAfter),
$userid
]);
if (!$rows) {
$message = $this->db_onedev->error();
$message['qry'] = $this->db_onedev->last_query();
$this->db_onedev->trans_rollback();
$this->sys_error($message);
exit;
}
$this->db_onedev->trans_commit();
$result = array(
"msg" => "ok",
"total" => 1,
"records" => $prm
);
$this->sys_ok($result);
exit;
}
function checkpatientbynoid($noKtp, $pid, $corporateid)
{
// $prm = $this->sys_input;
// $userid = $this->sys_user["M_UserID"];
// if (!$this->isLogin) {
// $this->sys_error("Invalid Token");
// exit;
// }
// $noKtp = $prm['nik'];
// $pid = $prm['pid'];
// $corporateid = $prm['corporateid'];
$sql = "SELECT * FROM m_patient
WHERE M_PatientIdentifierCode = 'NNIDN'
AND M_PatientIdentifierValue = $noKtp
AND M_PatientIsActive = 'Y'
AND M_PatientID <> $pid
AND M_PatientRegisteredByCorporateID = $corporateid";
$qry = $this->db_onedev->query($sql);
if (!$qry) {
$message = $this->db_onedev->error();
$this->sys_error($message);
$message['qry'] = $this->db_onedev->last_query();
exit;
}
$data = $qry->result_array();
if (count($data) > 0) {
$rst = [
"msg" => "errpatient",
"msg_dialog" => "Pasien memiliki NIK sama dengan pasien berikut",
"data" => $data,
"total" => count($data)
];
$this->sys_ok($rst);
exit;
}
}
function checkpatientbynamedob($name, $dob, $pid, $corporateid)
{
// $prm = $this->sys_input;
// $userid = $this->sys_user["M_UserID"];
// if (!$this->isLogin) {
// $this->sys_error("Invalid Token");
// exit;
// }
// $name = $prm['name'];
// $dob = $prm['dob'];
// $pid = $prm['pid'];
// $corporateid = $prm['corporateid'];
$sql = "SELECT * FROM m_patient
WHERE LOWER(M_PatientName)=LOWER(?)
AND M_PatientDOB= '{$dob}'
AND M_PatientIsActive = 'Y'
AND M_PatientID <> $pid
AND M_PatientRegisteredByCorporateID = $corporateid";
$qry = $this->db_onedev->query($sql, [$name]);
if (!$qry) {
$message = $this->db_onedev->error();
$message['qry'] = $this->db_onedev->last_query();
$this->sys_error($message);
exit;
}
// echo $sql;
$data = $qry->result_array();
if (count($data) > 0) {
$rst = [
"msg" => "errpatient",
"msg_dialog" => "Pasien memiliki Nama dan Tanggal Lahir sama dengan pasien berikut",
"data" => $data,
"total" => count($data)
];
$this->sys_ok($rst);
exit;
}
}
function checkpatientbynip($nip, $pid, $corporateid)
{
// $prm = $this->sys_input;
// $userid = $this->sys_user["M_UserID"];
// if (!$this->isLogin) {
// $this->sys_error("Invalid Token");
// exit;
// }
// $name = $prm['name'];
// $dob = $prm['dob'];
// $pid = $prm['pid'];
// $corporateid = $prm['corporateid'];
$sql = "SELECT * FROM m_patient
WHERE M_PatientNIP= '{$nip}'
AND M_PatientIsActive = 'Y'
AND M_PatientID <> $pid
AND M_PatientRegisteredByCorporateID = $corporateid";
$qry = $this->db_onedev->query($sql, []);
if (!$qry) {
$message = $this->db_onedev->error();
$this->sys_error($message);
exit;
}
// echo $sql;
$data = $qry->result_array();
if (count($data) > 0) {
$rst = [
"msg" => "errpatient",
"msg_dialog" => "Pasien memiliki NIP sama dengan pasien berikut",
"data" => $data,
"total" => count($data)
];
$this->sys_ok($rst);
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
T_PacketName,
T_PacketSasCode,
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,
T_PacketPrice,
T_PacketOriginalPrice
FROM
t_packetdetail as pd
JOIN t_packet ON pd.T_PacketDetailT_PacketID = T_PacketID
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 getpreregistermenu()
{
if (!$this->isLogin) {
$this->sys_error("Invalid Token");
exit;
}
$sql = "SELECT S_MenuUrl as url FROM s_menu
WHERE S_MenuName = 'Registration (Preregister)' LIMIT 1";
$qry = $this->db_onedev->query($sql);
if (!$qry) {
$message = $this->db_onedev->error();
$this->sys_error($message);
exit;
}
$data = $qry->row();
$this->sys_ok($data);
exit;
}
function lookup_barcodes()
{
try {
$prm = $this->sys_input;
//# cek token valid
if (!$this->isLogin) {
$this->sys_error("Invalid Token");
exit;
}
$sql = "SELECT T_BarcodeLabID as id,
'barcode' as type,
T_SampleTypeID,
T_BarcodeLabID,
T_BarcodeLabBarcode,
T_BarcodeLabT_OrderHeaderID as orderid,
T_BarcodeLabCounter,
T_SampleTypeName,
'N' as chex
FROM t_barcodelab
JOIN t_sampletype ON T_BarcodeLabT_SampleTypeID = T_SampleTypeID
JOIN t_bahan ON T_SampleTypeT_BahanID = T_BahanID
JOIN t_samplestation ON T_BahanT_SampleStationID = T_SampleStationID AND T_SampleStationIsNonLab = ''
WHERE
T_BarcodeLabT_OrderHeaderID = {$prm['T_OrderHeaderID']} AND T_BarcodeLabIsActive = 'Y'
UNION
SELECT T_TestID as id,
'nonlab' as type,
T_OrderDetailID as T_SampleTypeID,
'' as T_BarcodeLabID,
'-' as T_BarcodeLabBarcode,
T_OrderHeaderID as order_id,
0 as T_BarcodeLabCounter,
T_TestName as T_SampleTypeName,
'N' as chex
FROM t_orderheader
JOIN t_orderdetail ON T_OrderDetailT_OrderHeaderID = T_OrderHeaderID AND T_OrderDetailIsActive = 'Y'
JOIN t_test ON T_OrderDetailT_TestID = T_TestID AND T_TestIsResult = 'Y'
JOIN group_resultdetail ON Group_ResultDetailT_TestID = T_TestID
JOIN group_result ON Group_ResultDetailGroup_ResultID = Group_ResultID AND Group_ResultName <> 'lab'
WHERE
T_OrderHeaderID = {$prm['T_OrderHeaderID']}
GROUP BY T_TestID
";
//echo $sql;
$query = $this->db_onedev->query($sql);
if (!$query) {
$message = $this->db_onedev->error();
$message['qry'] = $this->db_onedev->last_query();
$this->sys_error($message);
exit;
}
$rows = $query->result_array();
$rst = [];
if ($rows) {
foreach ($rows as $k => $v) {
$v['chex'] = false;
// if ($v['chex'] == 'N')
// $rows[$k]['chex'] = false;
// else
// $rows[$k]['chex'] = true;
$v['count'] = 1;
$rst[] = $v;
// if ($v['type'] == 'barcode' && $v['T_SampleTypeID'] == 48) {
// $rst[] = $v;
// }
}
}
$result = array("total" => 0, "records" => $rst);
$this->sys_ok($result);
} catch (Exception $exc) {
$message = $exc->getMessage();
$this->sys_error($message);
}
}
function getcompany()
{
try {
$prm = $this->sys_input;
//# cek token valid
if (!$this->isLogin) {
$this->sys_error("Invalid Token");
exit;
}
$code = $prm['code'];
$sql = "SELECT
M_CompanyID,
M_CompanyNumber,
M_CompanyName,
'Y' AS M_CompanyDefault
FROM m_company
WHERE (M_CompanyID = ?);";
//echo $sql;
$query = $this->db_onedev->query($sql, [$code]);
if (!$query) {
$message = $this->db_onedev->error();
$message['qry'] = $this->db_onedev->last_query();
$this->sys_error($message);
exit;
}
$corporate = $query->row_array();
$sql = "SELECT
M_CompanyID,
M_CompanyNumber,
M_CompanyName,
'N' AS M_CompanyDefault
FROM m_company_relation
JOIN m_company ON M_CompanyRelationM_CompanyRelationID = M_CompanyID
AND M_CompanyIsActive = 'Y'
AND M_CompanyRelationM_CompanyID = ?";
//echo $sql;
$query = $this->db_onedev->query($sql, [$corporate['companyID']]);
if (!$query) {
$message = $this->db_onedev->error();
$message['qry'] = $this->db_onedev->last_query();
$this->sys_error($message);
exit;
}
$relation = $query->result_array();
// $rows = [$corporate,...$relation]
$rows = [$corporate];
for ($i = 0; $i < count($relation); $i++) {
array_push($rows, $relation[$i]);
}
$result = array("records" => $rows);
$this->sys_ok($result);
} catch (Exception $exc) {
$message = $exc->getMessage();
$this->sys_error($message);
}
}
function search_patient_form()
{
$prm = $this->sys_input;
$name = $prm['name'];
$dob = $prm['dob'];
$nik = $prm['nik'];
$ktp = $prm['ktp'];
$add_where = '';
// M_PatientIdentifierCode varchar(50) [NNIDN]
// M_PatientIdentifierSystem varchar(100) [http://terminology.hl7.org/CodeSystem/v2-0203]
// M_PatientIdentifierCode varchar(50) [NNIDN]
if ($nik != '') {
$add_where .= " AND M_PatientNIP = '{$nik}'";
}
if ($ktp != '') {
$ktp_toks = $this->ibl_encryptor->query_tokens($ktp);
foreach ($ktp_toks as $ktok) {
$ktok_esc = $this->db_onedev->escape_str($ktok);
$add_where .= " AND JSON_CONTAINS(M_PatientNIK_bidx, '\"$ktok_esc\"')";
}
}
$setup = $prm['setup'];
$join_company = "";
if (isset($prm['company']) && intval($prm['company']) > 0) {
$join_company = "JOIN t_orderheader ON T_OrderHeaderM_PatientID = M_PatientID AND
T_OrderHeaderIsActive = 'Y' AND
T_OrderHeaderM_CompanyID = {$prm['company']}";
}
$name_where = '1=1';
if ($name != '') {
$name_toks = $this->ibl_encryptor->query_tokens($name);
$nconds = [];
foreach ($name_toks as $ntok) {
$ntok_esc = $this->db_onedev->escape_str($ntok);
$nconds[] = "JSON_CONTAINS(M_PatientName_bidx, '\"$ntok_esc\"')";
}
if ($nconds) $name_where = implode(' AND ', $nconds);
}
$dob_where = '1=1';
if ($dob != '') {
$dob_toks = $this->ibl_encryptor->query_tokens($dob);
$dconds = [];
foreach ($dob_toks as $dtok) {
$dtok_esc = $this->db_onedev->escape_str($dtok);
$dconds[] = "JSON_CONTAINS(M_PatientDOB_bidx, '\"$dtok_esc\"')";
}
if ($dconds) $dob_where = implode(' AND ', $dconds);
}
$sql = "SELECT COUNT(*) as total
FROM (
SELECT *
FROM m_patient
$join_company
LEFT JOIN m_title ON M_PatientM_TitleID = M_TitleID
WHERE
M_PatientIsActive = 'Y'
AND M_PatientRegisteredByCompanyID = {$setup['Mgm_McuM_CompanyID']}
AND ({$name_where})
AND ({$dob_where})
{$add_where}
GROUP BY M_PatientID
) x
";
$qry = $this->db_onedev->query($sql);
if (!$qry) {
$message = $this->db_onedev->error();
$message['qry'] = $this->db_onedev->last_query();
$this->sys_error($message);
exit;
}
$countx = $qry->row()->total;
$sql = "SELECT *, M_PatientDOB as dob_ina,
M_PatientNoReg as Mcu_PreregisterPatientsPID,
M_PatientIdentifierValue as Mcu_PreregisterPatientsKTP,
M_PatientID as Mcu_PreregisterPatientsM_PatientID,
M_TitleID as Mcu_PreregisterPatientsM_TitleID,
M_PatientName as Mcu_PreregisterPatientsPatientName,
M_PatientM_SexID as Mcu_PreregisterPatientsM_SexID,
M_PatientDOB as Mcu_PreregisterPatientsDOB,
IFNULL(M_PatientReligionCode,0) as Mcu_PreregisterPatientsReligion,
M_PatientEmail as Mcu_PreregisterDetailsEmail,
M_PatientHP as Mcu_PreregisterDetailsHp,
M_PatientEmail as Mcu_PreregisterPatientsEmail,
M_PatientHP as Mcu_PreregisterPatientsHp,
M_PatientPosisi as Mcu_PreregisterPatientsPosisi,
M_PatientDivisi as Mcu_PreregisterPatientsDivisi,
M_PatientJob as Mcu_PreregisterPatientsJob,
M_PatientDepartement as Mcu_PreregisterPatientsDepartment
FROM m_patient
$join_company
LEFT join m_title on M_PatientM_TitleID = M_TitleID
WHERE
M_PatientRegisteredByCompanyID = {$setup['Mgm_McuM_CompanyID']}
AND M_PatientIsActive = 'Y'
AND ({$name_where})
AND ({$dob_where})
{$add_where}
GROUP BY M_PatientID
LIMIT 10 OFFSET 0
";
$qry = $this->db_onedev->query($sql);
if (!$qry) {
$message = $this->db_onedev->error();
$message['qry'] = $this->db_onedev->last_query();
$this->sys_error($message);
exit;
}
$rows = $qry->result_array();
$result = array(
"total" => $countx,
"records" => $rows
);
$this->sys_ok($result);
exit;
}
function getdetailcompany()
{
try {
if (!$this->isLogin) {
$this->sys_error("Invalid Token");
exit;
}
$prm = $this->sys_input;
$sql = "SELECT m_company.*, IFNULL(display, '') as countryName
FROM m_company
LEFT JOIN terminology ON attribute_path = 'Address.country' AND code = M_CompanyAddressCountry
WHERE
M_CompanyID = ?";
$qry = $this->db_onedev->query($sql, array($prm['Mgm_McuM_CompanyID']));
if (!$qry) {
$this->sys_error_db("search company select error", $this->db_onedev);
exit;
}
$row = $qry->row_array();
if (!$row) {
# code...
}
$result = array(
"records" => $row
);
$this->sys_ok($result);
} catch (Exception $exc) {
$message = $exc->getMessage();
$this->sys_error($message);
}
}
public function searchwilayah()
{
try {
if (!$this->isLogin) {
$this->sys_error("Invalid Token");
exit;
}
$prm = $this->sys_input;
$search = $prm['search'];
$sql = "SELECT
r.regional_cd,
r.regional_cd AS id,
r.regional_nm,
r.full_name AS text_nm,
r.pro_cd, IFNULL(pro.regional_nm,'') AS pro_nm,
r.kab_cd, IFNULL(kab.regional_nm,'') AS kab_nm,
r.kec_cd, IFNULL(kec.regional_nm,'') AS kec_nm,
r.kel_cd, IFNULL(kel.regional_nm,'') AS kel_nm,
r.status_cd, r.old_nm
FROM regional r
LEFT JOIN regional pro ON CONCAT(r.pro_cd, REPEAT('0', 8)) = pro.regional_cd
LEFT JOIN regional kab ON CONCAT(r.pro_cd, r.kab_cd, REPEAT('0', 6)) = kab.regional_cd
LEFT JOIN regional kec ON CONCAT(r.pro_cd, r.kab_cd, r.kec_cd, REPEAT('0', 3)) = kec.regional_cd
LEFT JOIN regional kel ON CONCAT(r.pro_cd, r.kab_cd, r.kec_cd, r.kel_cd) = kel.regional_cd
WHERE
r.full_name LIKE CONCAT('%','{$search}','%')
LIMIT 100
";
$qry = $this->db_onedev->query($sql);
if (!$qry) {
$this->sys_error_db("search wilayah 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);
}
}
public function getCountryTerminology()
{
try {
if (!$this->isLogin) {
$this->sys_error("Invalid Token");
exit;
}
$prm = $this->sys_input;
$sql = "SELECT
code,
display
FROM
terminology
WHERE status_cd = 'normal'
AND attribute_path = 'Address.country'
AND resource_type = 'Address'
AND `code` = 'ID'
AND code_system = 'urn:iso:std:iso:3166'
";
$qry = $this->db_onedev->query($sql);
if (!$qry) {
$this->sys_error_db("terminology 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);
}
}
public function getCountryTerminologySelected()
{
try {
if (!$this->isLogin) {
$this->sys_error("Invalid Token");
exit;
}
$prm = $this->sys_input;
$sql = "SELECT
resource_type,
attribute_path,
code,
parent_code,
display,
display_en,
code_system,
order_no,
ft_index,
use_ind,
description,
status_cd,
created_dttm,
created_user_id,
updated_dttm,
updated_user_id,
nullified_dttm,
nullified_user_id
FROM
terminology
WHERE status_cd = 'normal'
AND attribute_path = 'Address.country'
AND resource_type = 'Address'
AND code_system = 'urn:iso:std:iso:3166'
AND
";
$qry = $this->db_onedev->query($sql);
if (!$qry) {
$this->sys_error_db("terminology 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);
}
}
}