Files
BE_CPONE/application/controllers/mockup/mcuoffline/Preregisterappcponev3.php
2026-05-11 14:55:51 +07:00

1648 lines
51 KiB
PHP

<?php
class Preregisterappcponev3 extends MY_Controller
{
var $db_onedev;
var $db_dashboard;
var $load;
public function index()
{
echo "Patient API";
}
public function __construct()
{
parent::__construct();
$this->db_onedev = $this->load->database("onedev", true);
$this->db_dashboard = $this->load->database("cpone_dashboard", true);
}
private function normalize_tanggal_mcu($rawDate)
{
$rawDate = trim((string)$rawDate);
if ($rawDate === '') {
return '';
}
$ts = strtotime($rawDate);
if ($ts === false) {
return '';
}
return date('Y-m-d', $ts);
}
private function extract_tanggal_mcu($prm, $selectedPatient = array())
{
$candidates = array();
if (isset($prm['TANGGAL_MCU'])) $candidates[] = $prm['TANGGAL_MCU'];
if (isset($prm['tanggal_mcu'])) $candidates[] = $prm['tanggal_mcu'];
if (isset($selectedPatient['TANGGAL_MCU'])) $candidates[] = $selectedPatient['TANGGAL_MCU'];
if (isset($selectedPatient['tanggal_mcu'])) $candidates[] = $selectedPatient['tanggal_mcu'];
foreach ($candidates as $candidate) {
$normalized = $this->normalize_tanggal_mcu($candidate);
if ($normalized !== '') {
return $normalized;
}
}
return '';
}
private function sync_schedule_and_daily($preregisterID, $mgmMcuID, $tanggalMcu)
{
$preregisterID = intval($preregisterID);
$mgmMcuID = intval($mgmMcuID);
$tanggalMcu = $this->normalize_tanggal_mcu($tanggalMcu);
if ($preregisterID <= 0 || $mgmMcuID <= 0 || $tanggalMcu === '') {
return;
}
$sql = "INSERT INTO mcu_patient_schedule (
Mcu_PatientSchedulePreregisterID,
Mcu_PatientScheduleDate,
Mcu_PatientScheduleIsActive,
Mcu_PatientScheduleSyncedAt
) VALUES (?, ?, 'Y', NOW())
ON DUPLICATE KEY UPDATE
Mcu_PatientScheduleIsActive = 'Y',
Mcu_PatientScheduleSyncedAt = NOW()";
$query = $this->db_dashboard->query($sql, array($preregisterID, $tanggalMcu));
if (!$query) {
return;
}
$sql = "SELECT
s.Mcu_PatientScheduleDate AS schedule_date,
COUNT(*) AS total_participant
FROM mcu_patient_schedule s
JOIN cpone.mcu_preregister_patients p
ON p.Mcu_PreregisterPatientsID = s.Mcu_PatientSchedulePreregisterID
WHERE
s.Mcu_PatientScheduleIsActive = 'Y'
AND p.Mcu_PreregisterPatientsIsActive = 'Y'
AND p.Mcu_PreregisterPatientsMgm_McuID = ?
GROUP BY s.Mcu_PatientScheduleDate";
$query = $this->db_dashboard->query($sql, array($mgmMcuID));
if (!$query) {
return;
}
$rows = $query->result_array();
if (count($rows) === 0) {
return;
}
foreach ($rows as $row) {
$sql = "INSERT INTO mcu_participant_daily (
Mcu_ParticipantDailyMcuID,
Mcu_ParticipantDailyDate,
Mcu_ParticipantDailyTotal,
Mcu_ParticipantDailyIsActive
) VALUES (?, ?, ?, 'Y')
ON DUPLICATE KEY UPDATE
Mcu_ParticipantDailyTotal = VALUES(Mcu_ParticipantDailyTotal),
Mcu_ParticipantDailyIsActive = 'Y'";
$this->db_dashboard->query($sql, array(
$mgmMcuID,
$row['schedule_date'],
intval($row['total_participant'])
));
}
}
private function sync_patient_dashboard($preregisterID)
{
$preregisterID = intval($preregisterID);
if ($preregisterID <= 0) {
return;
}
$sql = "SELECT
Mcu_PreregisterPatientsID,
Mcu_PreregisterPatientsMgm_McuID,
Mcu_PreregisterPatientsPatientName,
Mcu_PreregisterPatientsNIP,
Mcu_PreregisterPatientsGender,
Mcu_PreregisterPatientsDOB,
Mcu_PreregisterPatientsDepartment,
Mcu_PreregisterPatientsDivisi,
Mcu_PreregisterPatientsPosisi,
Mcu_PreregisterPatientsIsRegistered,
Mcu_PreregisterPatientsT_OrderHeaderID
FROM mcu_preregister_patients
WHERE Mcu_PreregisterPatientsID = ? AND Mcu_PreregisterPatientsIsActive = 'Y'
LIMIT 1";
$query = $this->db_onedev->query($sql, array($preregisterID));
if (!$query || $query->num_rows() === 0) {
return;
}
$row = $query->row_array();
$orderID = null;
if (
isset($row['Mcu_PreregisterPatientsIsRegistered']) &&
$row['Mcu_PreregisterPatientsIsRegistered'] === 'Y' &&
intval($row['Mcu_PreregisterPatientsT_OrderHeaderID']) > 0
) {
$orderID = intval($row['Mcu_PreregisterPatientsT_OrderHeaderID']);
}
$sql = "INSERT INTO mcu_patient (
Mcu_PatientPreregisterID,
Mcu_PatientMcuID,
Mcu_PatientName,
Mcu_PatientNIP,
Mcu_PatientGender,
Mcu_PatientDOB,
Mcu_PatientDepartment,
Mcu_PatientDivision,
Mcu_PatientPosisi,
Mcu_PatientIsRegistered,
Mcu_PatientOrderID,
Mcu_PatientIsActive,
Mcu_PatientSyncedAt
) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, 'Y', NOW())
ON DUPLICATE KEY UPDATE
Mcu_PatientMcuID = VALUES(Mcu_PatientMcuID),
Mcu_PatientName = VALUES(Mcu_PatientName),
Mcu_PatientNIP = VALUES(Mcu_PatientNIP),
Mcu_PatientGender = VALUES(Mcu_PatientGender),
Mcu_PatientDOB = VALUES(Mcu_PatientDOB),
Mcu_PatientDepartment = VALUES(Mcu_PatientDepartment),
Mcu_PatientDivision = VALUES(Mcu_PatientDivision),
Mcu_PatientPosisi = VALUES(Mcu_PatientPosisi),
Mcu_PatientIsRegistered = VALUES(Mcu_PatientIsRegistered),
Mcu_PatientOrderID = VALUES(Mcu_PatientOrderID),
Mcu_PatientIsActive = 'Y',
Mcu_PatientSyncedAt = NOW()";
$this->db_dashboard->query($sql, array(
intval($row['Mcu_PreregisterPatientsID']),
intval($row['Mcu_PreregisterPatientsMgm_McuID']),
$row['Mcu_PreregisterPatientsPatientName'],
$row['Mcu_PreregisterPatientsNIP'],
$row['Mcu_PreregisterPatientsGender'],
$row['Mcu_PreregisterPatientsDOB'],
$row['Mcu_PreregisterPatientsDepartment'],
$row['Mcu_PreregisterPatientsDivisi'],
$row['Mcu_PreregisterPatientsPosisi'],
$row['Mcu_PreregisterPatientsIsRegistered'],
$orderID
));
}
public function getsetup()
{
try {
// if (!$this->isLogin) {
// $this->sys_error("Invalid Token");
// exit;
// }
$sql = "SELECT *
FROM mgm_mcu
WHERE Mgm_McuIsActive = 'Y' AND ( CURDATE() BETWEEN Mgm_McuStartDate AND Mgm_McuEndDate )
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 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;
$sql = " SELECT count(*) as total
FROM mcu_preregister_patients
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
";
//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,
DATE_FORMAT(Mcu_PreregisterPatientsDOB,'%d-%m-%Y') as dob,
DATE_FORMAT(Mcu_PreregisterPatientsDOB,'%d-%m-%Y') as Mcu_PreregisterPatientsDOB
FROM mcu_preregister_patients
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
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;
};
$rows = $query->result_array();
if ($rows) {
foreach ($rows as $k => $v) {
$rows[$k]['packets'] = array();
$rows[$k]['tests'] = array();
$join_test = '';
$filter_paket = "AND T_PacketSasCode IN ('')";
$filter_test = "AND T_TestSasCode IN ('')";
if ($v['Mcu_PreregisterPatientsOrders'] != '') {
$xjoin_tests = explode(',', $v['Mcu_PreregisterPatientsOrders']);
//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'
JOIN mgm_mcupacket ON T_PacketID = Mgm_McuPacketT_PacketID
AND Mgm_McuPacketIsActive = 'Y' AND Mgm_McuPacketMgm_McuID = {$setup['Mgm_McuID']}
WHERE
T_PriceT_PriceHeaderID = {$setup['Mgm_McuT_PriceHeaderID']} 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_PriceT_PriceHeaderID = {$setup['Mgm_McuT_PriceHeaderID']} 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());
$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]))
$q['name'] = "AND M_PatientName LIKE '%{$e[0]}%'";
if (isset($e[1]))
$q['dob'] = "AND ((DATE_FORMAT(M_PatientDOB, '%d-%m-%Y') LIKE '%{$e[1]}%' and M_PatientDOB IS NOT NULL) OR (M_PatientDOB IS NULL AND '{$e[1]}' = ''))";
if (isset($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_PatientGender,
DATE_FORMAT(M_PatientDOB,'%d-%m-%Y') 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_PatientGender 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'
AND M_PatientRegisteredByCorporateID = {$setup['Mgm_McuCorporateID']}
{$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 CorporateCode FROM corporate WHERE CorporateID = '{$setup['Mgm_McuCorporateID']}'";
$qry = $this->db_onedev->query($sql);
if (!$qry) {
$message = $this->db_onedev->error();
$this->db_onedev->trans_rollback();
$this->sys_error($message);
exit;
}
$corporateCode = $qry->row_array()['CorporateCode'];
$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']));
// $data = array(
// "Mcu_PreregisterPatientsMgm_McuID" => $setup['Mgm_McuID'],
// "Mcu_PreregisterPatientsPID" => $v['Mcu_PreregisterPatientsPID'],
// "Mcu_PreregisterPatientsM_PatientID" => $v['M_PatientID'],
// "Mcu_PreregisterPatientsKTP" => $v['Mcu_PreregisterPatientsKTP'],
// "Mcu_PreregisterPatientsPatientPrefix" => $v['M_PatientPrefix'],
// "Mcu_PreregisterPatientsPatientName" => $name,
// "Mcu_PreregisterPatientsPatientSuffix" => $v['M_PatientSuffix'],
// "Mcu_PreregisterPatientsGender" => $v['M_PatientGender'],
// "Mcu_PreregisterPatientsDOB" => $pdob,
// "Mcu_PreregisterPatientsReligion" => $v['M_PatientReligionCode'],
// "Mcu_PreregisterPatientsJob" => $v['M_PatientJob'],
// "Mcu_PreregisterPatientsEmail" => $v['M_PatientEmail'],
// "Mcu_PreregisterPatientsHp" => $v['M_PatientHp'],
// "Mcu_PreregisterPatientsPosisi" => $v['M_PatientPosisi'],
// "Mcu_PreregisterPatientsDivisi" => $v['M_PatientDivisi'],
// "Mcu_PreregisterPatientsLocation" => $v['M_PatientLocation'],
// "Mcu_PreregisterPatientsCreated" => date('Y-m-d H:i:s'),
// "Mcu_PreregisterPatientsUserID" => $userid,
// "Mcu_PreregisterPatientsM_TitleID" => $v['Mcu_PreregisterPatientsM_TitleID'],
// "Mcu_PreregisterPatientsCorporateCode" => $corporateCode,
// "Mcu_PreregisterPatientsDepartment" => $v['M_PatientDepartement'],
// "Mcu_PreregisterPatientsNIP" => $v['M_PatientNIP']
// );
// $rows = $this->db_onedev->insert(
// "mcu_preregister_patients",
// $data
// );
// $setup['Mgm_McuID'],
// $v['Mcu_PreregisterPatientsPID'],
// $v['M_PatientID'],
// $v['Mcu_PreregisterPatientsKTP'],
// $v['M_PatientPrefix'],
// $this->db_onedev->escape_str($name),
// $v['M_PatientSuffix'],
// $v['M_PatientGender'],
// $pdob,
// $v['M_PatientReligionCode'],
// $v['M_PatientJob'],
// $v['M_PatientEmail'],
// $v['M_PatientHp'],
// $v['M_PatientPosisi'],
// $v['M_PatientDivisi'],
// $v['M_PatientLocation'],
// $userid,
// $v['Mcu_PreregisterPatientsM_TitleID'],
// $corporateCode,
// $v['M_PatientDepartement'],
// $v['M_PatientNIP']
$query = "INSERT INTO mcu_preregister_patients (
Mcu_PreregisterPatientsMgm_McuID,
Mcu_PreregisterPatientsPID,
Mcu_PreregisterPatientsM_PatientID,
Mcu_PreregisterPatientsKTP,
Mcu_PreregisterPatientsPatientPrefix,
Mcu_PreregisterPatientsPatientName,
Mcu_PreregisterPatientsPatientSuffix,
Mcu_PreregisterPatientsGender,
Mcu_PreregisterPatientsDOB,
Mcu_PreregisterPatientsReligion,
Mcu_PreregisterPatientsJob,
Mcu_PreregisterPatientsEmail,
Mcu_PreregisterPatientsHp,
Mcu_PreregisterPatientsPosisi,
Mcu_PreregisterPatientsDivisi,
Mcu_PreregisterPatientsLocation,
Mcu_PreregisterPatientsCreated,
Mcu_PreregisterPatientsUserID,
Mcu_PreregisterPatientsM_TitleID,
Mcu_PreregisterPatientsCorporateCode,
Mcu_PreregisterPatientsDepartment,
Mcu_PreregisterPatientsNIP
)
VALUES(
?,?,?,?,?,?,?,
?,
?,
?,
?,
?,
?,
?,
?,
?,
NOW(),
?,
?,
?,
?,
?
)";
//echo $query;
$rows = $this->db_onedev->query($query, [
$setup['Mgm_McuID'],
$v['Mcu_PreregisterPatientsPID'],
$v['M_PatientID'],
$v['Mcu_PreregisterPatientsKTP'],
$v['M_PatientPrefix'],
$v['M_PatientRealName'],
$v['M_PatientSuffix'],
$v['M_PatientGender'],
$pdob,
$v['M_PatientReligionCode'],
$v['M_PatientJob'],
$v['M_PatientEmail'],
$v['M_PatientHp'],
$v['M_PatientPosisi'],
$v['M_PatientDivisi'],
$v['M_PatientLocation'],
$userid,
$v['Mcu_PreregisterPatientsM_TitleID'],
$corporateCode,
$v['M_PatientDepartement'],
$v['M_PatientNIP']
]);
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) {
// {
// "Mcu_PreregisterPatientsID": 0,
// "Mcu_PreregisterPatientsNIK": "",
// "Mcu_PreregisterPatientsKTP": "ktp",
// "Mcu_PreregisterPatientsM_TitleID": "1",
// "Mcu_PreregisterPatientsPatientPrefix": "",
// "Mcu_PreregisterPatientsPatientName": "nama",
// "Mcu_PreregisterPatientsPatientSuffix": "",
// "Mcu_PreregisterPatientsM_SexCode": "MALE",
// "Mcu_PreregisterPatientsDOB": "06-11-2000",
// "Mcu_PreregisterPatientsPosisi": "jabatan",
// "Mcu_PreregisterPatientsEmail": "",
// "Mcu_PreregisterPatientsHp": "",
// "Mcu_PreregisterPatientsDivisi": "divisi",
// "Mcu_PreregisterPatientsLocation": "lokasi ",
// "Mcu_PreregisterPatientsJob": "pekerjaan",
// "Mcu_PreregisterPatientsDepartment": "departement",
// "Mcu_PreregisterPatientsM_PatientID": 0,
// "setup": {
// "Mgm_McuID": "31",
// "Mgm_McuT_PriceHeaderID": "1",
// "Mgm_McuM_BranchID": "1",
// "Mgm_McuLabel": "MCU WESTERINDO",
// "Mgm_McuFlagRelasiBayarSendiri": "N",
// "Mgm_McuBisaTambahPemeriksaan": "N",
// "Mgm_McuCorporateID": "36",
// "Mgm_McuNumber": "MGM240600028",
// "Mgm_McuNumberNational": "",
// "Mgm_McuNote": "",
// "Mgm_McuStartDate": "2024-06-20",
// "Mgm_McuEndDate": "2024-06-30",
// "Mgm_McuPicEmail": "joko@gmail.com",
// "Mgm_McuPicPassword": "b4f6ec9fb9956ce1b2a8b5144ea10519",
// "Mgm_McuIsActive": "Y",
// "Mgm_McuCreated": "2024-06-20 17:07:04",
// "Mgm_McuCreatedUserID": "2",
// "Mgm_McuLastUpdated": "0000-00-00 00:00:00",
// "Mgm_McuLastUpdatedUserID": "0",
// "Mgm_McuLastDeleted": "0000-00-00 00:00:00",
// "Mgm_McuLastDeletedUserID": "0",
// "Mgm_McuTotalParticipant": "0"
// }
// }
$sql = "SELECT fn_numbering_cpone('P') 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']);
$sql = "INSERT INTO m_patient (
M_PatientPrefix,
M_PatientName,
M_PatientSuffix,
M_PatientM_TitleID,
M_PatientGender,
M_PatientDOB,
M_PatientIdentifierCode,
M_PatientIdentifierSystem,
M_PatientIdentifierValue,
M_PatientPosisi,
M_PatientDivisi,
M_PatientLocation,
M_PatientJob,
M_PatientEmail,
M_PatientHP,
M_PatientCreatedUserID,
M_PatientNIP,
M_PatientDepartement,
M_PatientNoReg,
M_PatientCreated,
M_PatientRegisteredByCorporateID
)
VALUES(
'{$v["Mcu_PreregisterPatientsPatientPrefix"]}',
'{$nameNewPn}',
'{$v["Mcu_PreregisterPatientsPatientSuffix"]}',
'{$title_id}',
'{$v["Mcu_PreregisterPatientsM_SexCode"]}',
'{$pdob}',
'NNIDN',
'http://terminology.hl7.org/CodeSystem/v2-0203',
'{$v["Mcu_PreregisterPatientsKTP"]}',
'{$v['Mcu_PreregisterPatientsPosisi']}',
'{$v['Mcu_PreregisterPatientsDivisi']}',
'{$v['Mcu_PreregisterPatientsLocation']}',
'{$v['Mcu_PreregisterPatientsJob']}',
'{$v['Mcu_PreregisterPatientsEmail']}',
'{$v['Mcu_PreregisterPatientsHp']}',
'{$userid}',
'{$v['Mcu_PreregisterPatientsNIK']}',
'{$v['Mcu_PreregisterPatientsDepartment']}',
'{$number}',
NOW(),
'{$setup['Mgm_McuCorporateID']}'
)";
//echo $sql;
$rows = $this->db_onedev->query($sql);
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();
$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;
}
// $sql = "SELECT * FROM m_patient WHERE M_PatientID = {$patient_id}";
// $ptn = $this->db_onedev->query($sql)->row_array();
// $ptn = json_encode($ptn);
//$this->db_onedev->query("CALL one_log.log_me('PATIENT', 'PATIENT.ADDR_ADD', '{$ptn_addr}', $userid)");
}
$this->sync_patient_dashboard($last_id_x);
$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();
$rows['sexes'] = $gender;
$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 getdatapackets()
{
if (!$this->isLogin) {
$this->sys_error("Invalid Token");
exit;
}
$prm = $this->sys_input;
$search = $prm["search"];
$setup = $prm["setup"];
$number_limit = 10;
$number_offset = ($prm['current_page'] - 1) * $number_limit;
$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
Ss_PriceMouMgm_McuID = {$setup['Mgm_McuID']} AND is_packet = 'Y' AND
( T_TestName LIKE CONCAT('%','{$search}','%') )";
$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']}
WHERE
T_PriceT_PriceHeaderID = {$setup['Mgm_McuT_PriceHeaderID']} AND 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
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_PriceT_PriceHeaderID = {$setup['Mgm_McuT_PriceHeaderID']} 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,
'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"];
$number_limit = 10;
$number_offset = ($prm['current_page'] - 1) * $number_limit;
// $sql = "SELECT * FROM mgm_mcu
// JOIN t_priceheader
// ON Mgm_McuStartDate BETWEEN T_PriceHeaderStartDate AND T_PriceHeaderEndDate
// AND T_PriceHeaderEndDate BETWEEN T_PriceHeaderStartDate AND T_PriceHeaderEndDate
// WHERE Mgm_McuID = {$setup['Mgm_McuID']}
// ORDER BY T_PriceHeaderID DESC LIMIT 1";
// $getpriceHeaderID = $this->db_onedev->query($sql, []);
// if (!$getpriceHeaderID) {
// $message = $this->db_onedev->error();
// $this->sys_error($message);
// exit;
// }
// $priceheaderid = $getpriceHeaderID->result_array()[0]["T_PriceHeaderID"];
$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'
JOIN t_price price ON test.T_TestID = price.T_PriceT_TestID AND T_PriceIsActive = 'Y'
AND T_PriceT_PriceHeaderID = {$setup['Mgm_McuT_PriceHeaderID']}
WHERE
Ss_PriceMouMgm_McuID = {$setup['Mgm_McuID']} AND is_packet = 'N' AND
price.T_PriceIsCito = 'N'";
// AND T_PriceT_PriceHeaderID IN (SELECT t_priceheader FROM t_price WHERE T_PriceHeaderStartDate )
$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 AND T_TestIsActive = 'Y'
JOIN t_price price ON test.T_TestID = price.T_PriceT_TestID AND T_PriceIsActive = 'Y'
AND price.T_PriceT_PriceHeaderID = {$setup['Mgm_McuT_PriceHeaderID']}
WHERE
ss_price_mou.T_PriceT_PriceHeaderID = {$setup['Mgm_McuT_PriceHeaderID']}
AND is_packet = 'N'
AND price.T_PriceIsCito = 'N'
) 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 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'
JOIN t_price price ON test.T_TestID = price.T_PriceT_TestID AND T_PriceIsActive = 'Y'
AND price.T_PriceT_PriceHeaderID = {$setup['Mgm_McuT_PriceHeaderID']}
WHERE
ss_price_mou.T_PriceT_PriceHeaderID = {$setup['Mgm_McuT_PriceHeaderID']}
AND is_packet = 'N'
AND price.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'];
$pdob = date('Y-m-d', strtotime($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);
}
// if (trim($v['Mcu_PreregisterPatientsKTP']) != "") {
// // $this->checkpatientbynamedob($v['Mcu_PreregisterPatientsPatientName'], $pdob, $v['Mcu_PreregisterPatientsM_PatientID'], $setup['Mgm_McuCorporateID']);
// // } else {
// $this->checkpatientbynoid($v['Mcu_PreregisterPatientsKTP'], $v['Mcu_PreregisterPatientsM_PatientID'], $setup['Mgm_McuCorporateID']);
// }
// if (trim($v['Mcu_PreregisterPatientsNIP']) != "") {
// $this->checkpatientbynip(trim($v['Mcu_PreregisterPatientsNIP']), $v['Mcu_PreregisterPatientsM_PatientID'], $setup['Mgm_McuCorporateID']);
// }
$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_PreregisterPatientsGender = ?,
Mcu_PreregisterPatientsM_TitleID = ?,
Mcu_PreregisterPatientsCorporateCode = ?,
Mcu_PreregisterPatientsDepartment = ?,
Mcu_PreregisterPatientsReligion = ?,
Mcu_PreregisterPatientsOrders = ?,
Mcu_PreregisterPatientsUserID = ?,
Mcu_PreregisterPatientsLastUpdated = NOW()
WHERE
Mcu_PreregisterPatientsID = ?";
//echo $query;
$rows = $this->db_onedev->query($query, [
$v['Mcu_PreregisterPatientsM_PatientID'],
$v['Mcu_PreregisterPatientsKTP'],
$v['Mcu_PreregisterPatientsNIP'],
$v['Mcu_PreregisterPatientsPatientPrefix'],
$v['Mcu_PreregisterPatientsPatientName'],
$v['Mcu_PreregisterPatientsPatientSuffix'],
$v['Mcu_PreregisterPatientsEmail'],
$v['Mcu_PreregisterPatientsHp'],
$pdob,
$v['Mcu_PreregisterPatientsPosisi'],
$v['Mcu_PreregisterPatientsDivisi'],
$v['Mcu_PreregisterPatientsJob'],
$v['Mcu_PreregisterPatientsLocation'],
$v['Mcu_PreregisterPatientsGender'],
$v['Mcu_PreregisterPatientsM_TitleID'],
$v['Mcu_PreregisterPatientsCorporateCode'],
$v['Mcu_PreregisterPatientsDepartment'],
$religionCode,
$Mcu_PreregisterPatientsTests,
$userid,
$v['Mcu_PreregisterPatientsID']
]);
if (!$rows) {
$message = $this->db_onedev->error();
$message['qry'] = $this->db_onedev->last_query();
$this->sys_error($message);
exit;
}
$this->sync_patient_dashboard($v['Mcu_PreregisterPatientsID']);
$sql_ktp = '';
if (isset($v['Mcu_PreregisterPatientsKTP']) && $v['Mcu_PreregisterPatientsKTP'] != '') {
$sql_ktp = "M_PatientIdentifierCode = 'NNIDN', M_PatientIdentifierSystem='http://terminology.hl7.org/CodeSystem/v2-0203', M_PatientIdentifierValue = '{$v['Mcu_PreregisterPatientsKTP']}',";
//echo $sql_ktp;
} else {
$sql_ktp = "M_PatientIdentifierCode = '', M_PatientIdentifierSystem='', M_PatientIdentifierValue = '',";
}
$sql = "UPDATE m_patient SET
$sql_ktp
M_PatientDOB = ?,
M_PatientM_TitleID = ?,
M_PatientNIP = ?,
M_PatientGender = ?,
M_PatientPrefix = ?,
M_PatientName = ?,
M_PatientSuffix = ?,
M_PatientEmail = ?,
M_PatientHP = ?,
M_PatientDivisi = ?,
M_PatientPosisi = ?,
M_PatientLocation = ?,
M_PatientJob = ?,
M_PatientDepartement = ?,
M_PatientReligionCode = ?,
M_PatientReligionSystem = ?,
M_PatientLastUpdatedUserID = ?,
M_PatientLastUpdated = NOW()
WHERE
M_PatientID = ?
";
//echo $sql;
$qry = $this->db_onedev->query($sql, [
$pdob,
$v['Mcu_PreregisterPatientsM_TitleID'],
$v['Mcu_PreregisterPatientsNIP'],
$v['Mcu_PreregisterPatientsGender'],
$v['Mcu_PreregisterPatientsPatientPrefix'],
$v['Mcu_PreregisterPatientsPatientName'],
$v['Mcu_PreregisterPatientsPatientSuffix'],
$v['Mcu_PreregisterPatientsEmail'],
$v['Mcu_PreregisterPatientsHp'],
$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->sys_error($message);
exit;
}
$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
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
JOIN t_packet ON 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 getcorporate()
{
try {
$prm = $this->sys_input;
//# cek token valid
if (!$this->isLogin) {
$this->sys_error("Invalid Token");
exit;
}
$code = $prm['code'];
$sql = "SELECT
CorporateID,
CorporateCode,
CorporateName,
'Y' AS CorporateDefault
FROM corporate
WHERE (CorporateID = ?);";
//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
CorporateID,
CorporateCode,
CorporateName,
'N' AS CorporateDefault
FROM corporate_relation
JOIN corporate ON CorporateRelationCorporateRelationID = CorporateID
AND CorporateRelationIsActive = 'Y'
AND CorporateRelationCorporateID = ?";
//echo $sql;
$query = $this->db_onedev->query($sql, [$corporate['CorporateID']]);
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 != '') {
$add_where .= " AND M_PatientIdentifierValue = '{$nik}' AND M_PatientIdentifierCode = 'NNIDN'";
}
$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']}";
}
$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_PatientRegisteredByCorporateID = {$setup['Mgm_McuCorporateID']}
AND M_PatientName LIKE CONCAT('%',?,'%') AND
(DATE_FORMAT(M_PatientDOB, '%d-%m-%Y') LIKE '%{$dob}%' and M_PatientDOB IS NOT NULL)
{$add_where}
GROUP BY M_PatientID
) x
";
//echo $sql;
$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;
}
$countx = $qry->row()->total;
$sql = "SELECT *, DATE_FORMAT(M_PatientDOB, '%d-%m-%Y') 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_PatientGender as Mcu_PreregisterPatientsGender,
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_PatientRegisteredByCorporateID = {$setup['Mgm_McuCorporateID']}
AND M_PatientIsActive = 'Y' AND
M_PatientName LIKE CONCAT('%',?,'%') AND
(DATE_FORMAT(M_PatientDOB, '%d-%m-%Y') LIKE '%{$dob}%' and M_PatientDOB IS NOT NULL)
{$add_where}
GROUP BY M_PatientID
LIMIT 10 OFFSET 0
";
//echo $sql;
$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;
}
$rows = $qry->result_array();
$result = array(
"total" => $countx,
"records" => $rows
);
$this->sys_ok($result);
exit;
}
}