- mask_name nama satu kata: tampil 2 char + bintang sisanya - masking + enkripsi insert/update m_patient di Registrationv3, ibl_registration/Patient, Patientv4, setupmcuoffline-ibl/Preregister, mcuoffline/Preregisterapp - masking insert ke mcu_preregister_patients (PatientName, KTP, NIK, Email, Hp) - search patient pakai bidx, decrypt setelah query di mcuoffline/Preregisterapp - matching existing patient ganti LIKE ke bidx search - SP sp_upsert_mcu_patient_by_preregister_id & sp_upsert_mcu_patient_by_mgm_mcuid JOIN m_patient ambil _enc, simpan ke one_lab_dashboard.mcu_patient - ALTER mcu_patient.Mcu_PatientName dan Mcu_PatientDOB ke TEXT Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
1824 lines
62 KiB
PHP
1824 lines
62 KiB
PHP
<?php
|
|
class Preregisterapp extends MY_Controller
|
|
{
|
|
var $db_onedev;
|
|
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);
|
|
if (count($words) === 1) {
|
|
$l = mb_strlen($v, 'UTF-8');
|
|
if ($l <= 2) return $v;
|
|
return mb_substr($v, 0, 2, 'UTF-8') . str_repeat('*', $l - 2);
|
|
}
|
|
$first = $words[0];
|
|
$rest = array_slice($words, 1);
|
|
$masked = array_map(function($w) {
|
|
if (!$w) return '';
|
|
$init = mb_substr($w, 0, 1, 'UTF-8');
|
|
return $init . str_repeat('*', max(3, mb_strlen($w, 'UTF-8') - 1));
|
|
}, $rest);
|
|
return $first . ' ' . implode(' ', $masked);
|
|
}
|
|
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_short($v) { if (!$v) return $v; $v=trim($v); $l=mb_strlen($v,'UTF-8'); if($l<=2) return '***'; return mb_substr($v,0,2,'UTF-8').'***'; }
|
|
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_address($v) { if (!$v) return $v; $v=trim($v); $l=mb_strlen($v,'UTF-8'); if($l<=5) return '***'; return mb_substr($v,0,5,'UTF-8').'***'; }
|
|
|
|
|
|
|
|
function searchcompany(){
|
|
//# cek token valid
|
|
if (! $this->isLogin) {
|
|
$this->sys_error("Invalid Token");
|
|
exit;
|
|
}
|
|
|
|
$prm = $this->sys_input;
|
|
|
|
$max_rst = 12;
|
|
$tot_count =0;
|
|
|
|
$q = [
|
|
'search' => '%'
|
|
];
|
|
|
|
if ($prm['search'] != '')
|
|
{
|
|
$q['search'] = "%{$prm['search']}%";
|
|
}
|
|
|
|
// QUERY TOTAL
|
|
$sql = "SELECT count(*) as total
|
|
FROM m_company
|
|
WHERE
|
|
M_CompanyName like ?
|
|
AND M_CompanyIsActive = 'Y'";
|
|
$query = $this->db_onedev->query($sql,$q['search']);
|
|
//echo $query;
|
|
if ($query) {
|
|
$tot_count = $query->result_array()[0]["total"];
|
|
}
|
|
else {
|
|
$this->sys_error_db("m_company count",$this->db_onedev);
|
|
exit;
|
|
}
|
|
$rst = array(array('id'=>0,'name'=>'Semua'));
|
|
|
|
$sql = "
|
|
SELECT M_CompanyID as id, M_CompanyName as name
|
|
FROM m_company
|
|
WHERE
|
|
M_CompanyName like ?
|
|
AND M_CompanyIsActive = 'Y'
|
|
ORDER BY M_CompanyName ASC
|
|
";
|
|
$query = $this->db_onedev->query($sql, array($q['search']));
|
|
|
|
if ($query) {
|
|
$rows = $query->result_array();
|
|
array_push($rows,array('id'=>0,'name'=>'Semua'));
|
|
//echo $this->db_onedev->last_query();
|
|
$result = array("total" => $tot_count, "records" => $rows, "total_display" => sizeof($rows));
|
|
$this->sys_ok($result);
|
|
}
|
|
else {
|
|
$this->sys_error_db("m_company rows",$this->db_onedev);
|
|
exit;
|
|
}
|
|
}
|
|
public function search()
|
|
{
|
|
$prm = $this->sys_input;
|
|
if (! $this->isLogin) {
|
|
$this->sys_error("Invalid Token");
|
|
exit;
|
|
}
|
|
$norm = $prm["snorm"];
|
|
$nama = $prm["name"];
|
|
|
|
// echo $norm;
|
|
|
|
$sql_where = "WHERE Mcu_PreregisterDetailsIsActive = 'Y' ";
|
|
$sql_param = array();
|
|
if ($nama != "") {
|
|
if ($sql_where != "") {
|
|
$sql_where .=" and ";
|
|
}
|
|
$sql_where .= " Mcu_PreregisterDetailsPatientName like ? ";
|
|
$sql_param[] = "%$nama%";
|
|
}
|
|
if ($norm != "") {
|
|
if ($sql_where != "") {
|
|
$sql_where .=" and ";
|
|
}
|
|
$sql_where .= " M_PatientNoReg like ? ";
|
|
$sql_param[] = "%$norm%";
|
|
}
|
|
|
|
$limit = '';
|
|
if($all == 'N'){
|
|
$limit = ' LIMIT 10';
|
|
}
|
|
$number_limit = 10;
|
|
$number_offset = ($prm['current_page'] - 1) * $number_limit ;
|
|
$sql = " SELECT count(*) as total
|
|
FROM mcu_preregister_patients
|
|
$sql_where
|
|
";
|
|
//echo $sql;
|
|
$query = $this->db_onedev->query($sql, $sql_param);
|
|
//echo $this->db_onedev->last_query();
|
|
$tot_count = 0;
|
|
$tot_page = 0;
|
|
if ($query) {
|
|
$tot_count = $query->result_array()[0]["total"];
|
|
$tot_page = ceil($tot_count/$number_limit);
|
|
} else {
|
|
$this->sys_error_db("m_patient count", $this->db_onedev);
|
|
exit;
|
|
}
|
|
|
|
$sql = "SELECT mcu_offline_prepare.*,M_CompanyName,
|
|
DATE_FORMAT(McuOfflinePrepareStartDate, '%d.%m.%Y') as start_date,
|
|
DATE_FORMAT(McuOfflinePrepareEndDate, '%d.%m.%Y') as end_date,
|
|
'' as agreements
|
|
FROM mcu_offline_prepare
|
|
JOIN m_company ON McuOfflinePrepareM_CompanyID = M_CompanyID
|
|
WHERE
|
|
McuOfflinePrepareIsDownloaded = 'Y' AND
|
|
McuOfflinePrepareIsActive = 'Y'";
|
|
//echo $sq
|
|
$xrow = $this->db_onedev->query($sql)->row_array();
|
|
|
|
$sql = "SELECT mcu_preregister_patients.*,
|
|
DATE_FORMAT(Mcu_PreregisterDetailsDOB, '%d-%m-%Y') as dob
|
|
FROM mcu_preregister_patients
|
|
WHERE
|
|
Mcu_PreregisterDetailsIsActive = 'Y' AND
|
|
Mcu_PreregisterDetailsMcuOfflinePrepareID = {$xrow['McuOfflinePrepareID']}
|
|
ORDER BY Mcu_PreregisterDetailsPatientName ASC
|
|
limit $number_limit offset $number_offset
|
|
";
|
|
//echo $sql;
|
|
$query = $this->db_onedev->query($sql);
|
|
$rows = $query->result_array();
|
|
if($rows){
|
|
foreach($rows as $k => $v){
|
|
|
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
//$this->_add_address($rows);
|
|
$result = array("total" => $tot_page, "records" => $rows, "setup"=> $xrow);
|
|
$this->sys_ok($result);
|
|
exit;
|
|
}
|
|
|
|
function getsexreg(){
|
|
if (! $this->isLogin) {
|
|
$this->sys_error("Invalid Token");
|
|
exit;
|
|
}
|
|
$rows = [];
|
|
$query =" SELECT *
|
|
FROM m_title
|
|
WHERE
|
|
M_TitleIsActive = 'Y'
|
|
";
|
|
//echo $query;
|
|
$rows['titles'] = $this->db_onedev->query($query)->result_array();
|
|
|
|
$query =" SELECT *
|
|
FROM m_sex
|
|
WHERE
|
|
M_SexIsActive = 'Y'
|
|
";
|
|
//echo $query;
|
|
$rows['sexes'] = $this->db_onedev->query($query)->result_array();
|
|
$query =" SELECT *
|
|
FROM m_religion
|
|
WHERE
|
|
M_ReligionIsActive = 'Y'
|
|
";
|
|
//echo $query;
|
|
$rows['religions'] = $this->db_onedev->query($query)->result_array();
|
|
|
|
$query =" SELECT *
|
|
FROM m_idtype
|
|
WHERE
|
|
M_IdTypeIsActive = 'Y'
|
|
";
|
|
//echo $query;
|
|
$rows['kartuidentitass'] = $this->db_onedev->query($query)->result_array();
|
|
|
|
|
|
$result = array(
|
|
"total" => count($rows) ,
|
|
"records" => $rows,
|
|
);
|
|
$this->sys_ok($result);
|
|
exit;
|
|
}
|
|
|
|
function gotoreg(){
|
|
if (! $this->isLogin) {
|
|
$this->sys_error("Invalid Token");
|
|
exit;
|
|
}
|
|
|
|
$userid = $this->sys_user["M_UserID"];
|
|
$prm = $this->sys_input;
|
|
|
|
$new_status = "Y";
|
|
/*$patient_id = 0;
|
|
if(!$prm["Mcu_PreregisterDetailsNIK"] && $prm["Mcu_PreregisterDetailsNIK"] != ''){
|
|
$sql = "SELECT *
|
|
FROM m_patient
|
|
WHERE
|
|
M_PatientNIK = '{$prm["Mcu_PreregisterDetailsNIK"]}' AND M_PatientIsActive = 'Y'";
|
|
$exist_r = $this->db_onedev->query($sql)->row_array();
|
|
if($exist_r){
|
|
$patient_id = $exist_r["M_PatientID"];
|
|
}
|
|
}
|
|
|
|
if(!$prm["Mcu_PreregisterDetailsPID"] && $prm["Mcu_PreregisterDetailsPID"] != ''){
|
|
$sql = "SELECT *
|
|
FROM m_patient
|
|
WHERE
|
|
M_PatientNoReg = '{$prm["M_PatientNoReg"]}' AND M_PatientIsActive = 'Y' LIMIT 1";
|
|
$exist_r = $this->db_onedev->query($sql)->row_array();
|
|
if($exist_r){
|
|
$patient_id = $exist_r["M_PatientID"];
|
|
}
|
|
}
|
|
|
|
if($patient_id == 0){
|
|
$pdob = date('Y-m-d',strtotime($prm['Mcu_PreregisterDetailsDOB']));
|
|
$sql = "SELECT *
|
|
FROM m_patient
|
|
WHERE
|
|
M_PatientName = '{$prm["Mcu_PreregisterDetailsPatientName"]}' AND
|
|
M_PatientDOB = '{$pdob}' AND
|
|
M_PatientIsActive = 'Y' LIMIT 1";
|
|
$exist_r = $this->db_onedev->query($sql)->row_array();
|
|
if($exist_r){
|
|
$patient_id = $exist_r["M_PatientID"];
|
|
}
|
|
}
|
|
|
|
if($patient_id == 0){
|
|
$sex_id = 0;
|
|
$sql = "SELECT * FROM m_sex WHERE M_SexCode = '{$prm["Mcu_PreregisterDetailsM_SexCode"]}' AND M_SexIsActive = 'Y' LIMIT 1";
|
|
$sex_id = $this->db_onedev->query($sql)->row()->M_SexID;
|
|
|
|
$title_id = 0;
|
|
$sql = "SELECT * FROM m_title WHERE M_TitleM_SexID = '{$sex_id}' AND M_TitleIsActive = 'Y' ORDER BY M_TitleID ASC LIMIT 1";
|
|
$title_id = $this->db_onedev->query($sql)->row()->M_TitleID;
|
|
|
|
$religion_id = 0;
|
|
$sql = "SELECT * FROM m_religion WHERE M_ReligionName = 'OTHERS' AND M_ReligionIsActive = 'Y' LIMIT 1";
|
|
$religion_id = $this->db_onedev->query($sql)->row()->M_ReligionID;
|
|
|
|
$pdob = date('Y-m-d',strtotime($prm['Mcu_PreregisterDetailsDOB']));
|
|
$sql = "INSERT INTO m_patient (
|
|
M_PatientName,
|
|
M_PatientM_TitleID,
|
|
M_PatientM_SexID,
|
|
M_PatientM_ReligionID,
|
|
M_PatientPOB,
|
|
M_PatientDOB,
|
|
M_PatientNIK,
|
|
M_PatientJabatan,
|
|
M_PatientLocation,
|
|
M_PatientKedudukan,
|
|
M_PatientJob,
|
|
M_PatientEmail,
|
|
M_PatientHP,
|
|
M_PatientUserID
|
|
)
|
|
VALUES(
|
|
'{$prm["Mcu_PreregisterDetailsPatientName"]}',
|
|
{$title_id},
|
|
{$sex_id},
|
|
{$religion_id},
|
|
'-',
|
|
'{$pdob}',
|
|
'{$prm["Mcu_PreregisterDetailsNIK"]}',
|
|
'{$prm['Mcu_PreregisterDetailsJabatan']}',
|
|
'{$prm['Mcu_PreregisterDetailsLocation']}',
|
|
'{$prm['Mcu_PreregisterDetailsKedudukan']}',
|
|
'{$prm['Mcu_PreregisterDetailsJob']}',
|
|
'{$prm['Mcu_PreregisterDetailsEmail']}',
|
|
'{$prm['Mcu_PreregisterDetailsHp']}',
|
|
'{$userid}'
|
|
)";
|
|
//echo $sql;
|
|
$this->db_onedev->query($sql);
|
|
$patient_id = $this->db_onedev->insert_id();
|
|
$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.ADD', '{$ptn}', $userid)");
|
|
|
|
$sql = "SELECT *
|
|
FROM mcu_preregister_patients
|
|
JOIN mcu_offline_prepare ON McuOfflinePrepareID = Mcu_PreregisterDetailsMcuOfflinePrepareID
|
|
JOIN m_company ON McuOfflinePrepareM_CompanyID = M_CompanyID
|
|
WHERE
|
|
Mcu_PreregisterDetailsID = {$prm['Mcu_PreregisterDetailsID']}";
|
|
$data_xall = $this->db_onedev->query($sql)->row();
|
|
|
|
$sql = "INSERT INTO m_patientaddress (
|
|
M_PatientAddressM_PatientID,
|
|
M_PatientAddressDescription,
|
|
M_PatientAddressM_KelurahanID,
|
|
M_PatientAddressCreated
|
|
)
|
|
VALUES(
|
|
{$patient_id},
|
|
'{$data_xall->M_CompanyAddress}',
|
|
'{$data_xall->M_CompanyM_KelurahanID}',
|
|
NOW()
|
|
)";
|
|
$this->db_onedev->query($sql);
|
|
$patient_addr_id = $this->db_onedev->insert_id();
|
|
$sql = "SELECT * FROM m_patientaddress WHERE M_PatientAddressID = {$patient_addr_id}";
|
|
$ptn_addr = $this->db_onedev->query($sql)->row_array();
|
|
$ptn_addr = json_encode($ptn_addr);
|
|
$this->db_onedev->query("CALL one_log.log_me('PATIENT', 'PATIENT.ADDR_ADD', '{$ptn_addr}', $userid)");
|
|
|
|
|
|
}
|
|
else{
|
|
$pdob = date('Y-m-d',strtotime($prm['Mcu_PreregisterDetailsDOB']));
|
|
$sql ="UPDATE m_patient SET
|
|
M_PatientEmail = '{$prm['Mcu_PreregisterDetailsEmail']}',
|
|
M_PatientHP = '{$prm['Mcu_PreregisterDetailsHp']}',
|
|
M_PatientNIK = '{$prm['Mcu_PreregisterDetailsNIK']}',
|
|
M_PatientJabatan = '{$prm['Mcu_PreregisterDetailsJabatan']}',
|
|
M_PatientKedudukan = '{$prm['Mcu_PreregisterDetailsKedudukan']}',
|
|
M_PatientLocation = '{$prm['Mcu_PreregisterDetailsLocation']}',
|
|
M_PatientJob = '{$prm['Mcu_PreregisterDetailsJob']}'
|
|
WHERE
|
|
M_PatientID = '{$patient_id}'
|
|
";
|
|
//echo $query;
|
|
$this->db_onedev->query($sql);
|
|
|
|
$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.EDIT', '{$ptn}', $userid)");
|
|
}
|
|
|
|
$sql = "UPDATE mcu_preregister_patients SET Mcu_PreregisterDetailsM_PatientID = {$prm['Mcu_PreregisterDetailsM_PatientID']} WHERE Mcu_PreregisterDetailsID = {$prm['Mcu_PreregisterDetailsID']}";
|
|
$this->db_onedev->query($sql);*/
|
|
$result = array(
|
|
"total" => 1 ,
|
|
"records" => $prm,
|
|
);
|
|
$this->sys_ok($result);
|
|
exit;
|
|
}
|
|
|
|
function searchcity(){
|
|
if (! $this->isLogin) {
|
|
$this->sys_error("Invalid Token");
|
|
exit;
|
|
}
|
|
$prm = $this->sys_input;
|
|
|
|
$max_rst = 12;
|
|
$tot_count =0;
|
|
|
|
$q = [
|
|
'search' => '%'
|
|
];
|
|
|
|
if ($prm['search'] != '')
|
|
{
|
|
$q['search'] = "%{$prm['search']}%";
|
|
}
|
|
|
|
// QUERY TOTAL
|
|
$sql = "SELECT count(*) as total
|
|
FROM m_city
|
|
WHERE
|
|
M_CityName like ?
|
|
AND M_CityIsActive = 'Y'";
|
|
$query = $this->db_onedev->query($sql,$q['search']);
|
|
//echo $query;
|
|
if ($query) {
|
|
$tot_count = $query->result_array()[0]["total"];
|
|
}
|
|
else {
|
|
$this->sys_error_db("m_city count",$this->db_onedev);
|
|
exit;
|
|
}
|
|
|
|
$sql = "
|
|
SELECT *
|
|
FROM m_city
|
|
WHERE
|
|
M_CityName like ?
|
|
AND M_CityIsActive = 'Y'
|
|
ORDER BY M_CityName DESC
|
|
";
|
|
$query = $this->db_onedev->query($sql, array($q['search']));
|
|
|
|
if ($query) {
|
|
$rows = $query->result_array();
|
|
//echo $this->db_onedev->last_query();
|
|
$result = array("total" => $tot_count, "records" => $rows, "total_display" => sizeof($rows));
|
|
$this->sys_ok($result);
|
|
}
|
|
else {
|
|
$this->sys_error_db("m_city rows",$this->db_onedev);
|
|
exit;
|
|
}
|
|
}
|
|
function getdistrict(){
|
|
$prm = $this->sys_input;
|
|
$query =" SELECT *
|
|
FROM m_district
|
|
WHERE
|
|
M_DistrictIsActive = 'Y' AND M_DistrictM_CityID = ?
|
|
";
|
|
//echo $query;
|
|
$rows = $this->db_onedev->query($query,array($prm['id']))->result_array();
|
|
|
|
$result = array(
|
|
"total" => count($rows) ,
|
|
"records" => $rows,
|
|
);
|
|
$this->sys_ok($result);
|
|
exit;
|
|
}
|
|
|
|
function search_patient_table()
|
|
{
|
|
$prm = $this->sys_input;
|
|
$setup = $prm['setup'];
|
|
$company = isset($prm['company'])?$prm['company']:0;
|
|
$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']}";
|
|
}
|
|
$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' => ''
|
|
];
|
|
|
|
|
|
|
|
$enc = $this->ibl_encryptor;
|
|
if ($prm['search'] != '')
|
|
{
|
|
$e = explode('+', $prm['search']);
|
|
if (isset($e[0]) && strlen($e[0]) >= 3) {
|
|
$toks = $enc->query_tokens($e[0]);
|
|
$conds = [];
|
|
foreach ($toks as $tok) { $tok_esc = $this->db_onedev->escape_str($tok); $conds[] = "JSON_CONTAINS(M_PatientName_bidx, '\"$tok_esc\"')"; }
|
|
if ($conds) $q['name'] = "AND (" . implode(' AND ', $conds) . ")";
|
|
}
|
|
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]) && strlen($e[2]) >= 3) {
|
|
$toks = $enc->query_tokens($e[2]);
|
|
$conds = [];
|
|
foreach ($toks as $tok) { $tok_esc = $this->db_onedev->escape_str($tok); $conds[] = "JSON_CONTAINS(M_PatientNIK_bidx, '\"$tok_esc\"')"; }
|
|
if ($conds) $q['nik'] = "AND (" . implode(' AND ', $conds) . ")";
|
|
}
|
|
}
|
|
|
|
|
|
$sql = "SELECT m_patient.*,
|
|
'N' divider,
|
|
concat(M_TitleName,' ',IFNULL(M_PatientPrefix,''),' ',M_PatientName,' ',IFNULL(M_PatientSuffix,'')) M_PatientNameDisplay,
|
|
M_TitleID, M_TitleName, M_SexID, M_SexName,
|
|
DATE_FORMAT(M_PatientDOB,'%d-%m-%Y') as dob_ina,
|
|
IFNULL(M_ReligionName, '-') M_ReligionName,
|
|
M_PatientNoReg as Mcu_PreregisterDetailsPID,
|
|
M_PatientID as Mcu_PreregisterDetailsM_PatientID,
|
|
M_TitleID as Mcu_PreregisterDetailsM_TitleID,
|
|
M_SexCode as Mcu_PreregisterDetailsM_SexCode,
|
|
M_PatientDOB as Mcu_PreregisterDetailsDOB,
|
|
IFNULL(M_ReligionID,0) as Mcu_PreregisterDetailsM_ReligionID,
|
|
M_PatientJabatan as Mcu_PreregisterDetailsJabatan,
|
|
M_PatientKedudukan as Mcu_PreregisterDetailsKedudukan,
|
|
M_PatientLocation as Mcu_PreregisterDetailsLocation,
|
|
M_PatientJob as Mcu_PreregisterDetailsJob
|
|
from
|
|
m_patient
|
|
$join_company
|
|
join m_title on M_PatientM_TitleID = M_TitleID
|
|
join m_sex on M_PatientM_SexID = M_SexID
|
|
left join m_religion on m_patientm_religionid = m_religionid
|
|
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);
|
|
|
|
if ($query) {
|
|
$rows = $query->result_array();
|
|
if($rows){
|
|
$per_divider = 1;
|
|
foreach($rows as $k => $v){
|
|
$name = $enc->decrypt($v['M_PatientName_enc'] ?? '') ?? $v['M_PatientName'];
|
|
$hp = $enc->decrypt($v['M_PatientHP_enc'] ?? '') ?? $v['M_PatientHP'];
|
|
$email = $enc->decrypt($v['M_PatientEmail_enc'] ?? '') ?? $v['M_PatientEmail'];
|
|
$nik = $enc->decrypt($v['M_PatientNIK_enc'] ?? '') ?? $v['M_PatientNIK'];
|
|
$rows[$k]['M_PatientName'] = $name;
|
|
$rows[$k]['M_PatientHP'] = $hp;
|
|
$rows[$k]['M_PatientEmail'] = $email;
|
|
$rows[$k]['M_PatientNIK'] = $nik;
|
|
$rows[$k]['Mcu_PreregisterDetailsPatientName'] = $name;
|
|
$rows[$k]['Mcu_PreregisterDetailsNIK'] = $nik;
|
|
$rows[$k]['Mcu_PreregisterDetailsEmail'] = $email;
|
|
$rows[$k]['Mcu_PreregisterDetailsHp'] = $hp;
|
|
foreach (array_keys($rows[$k]) as $col) {
|
|
if (substr($col, -4) === '_enc' || substr($col, -5) === '_bidx') unset($rows[$k][$col]);
|
|
}
|
|
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_PreregisterDetailsM_PatientID as id
|
|
FROM mcu_preregister_patients
|
|
WHERE
|
|
Mcu_PreregisterDetailsIsActive = 'Y' AND Mcu_PreregisterDetailsMcuOfflinePrepareID = '{$setup['McuOfflinePrepareID']}'";
|
|
|
|
$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" => $tot_page, "records" => $rows,"pids" => $pids, "sql"=> $this->db_onedev->last_query());
|
|
$this->sys_ok($result);
|
|
}
|
|
else {
|
|
$this->sys_error_db("m_patient rows",$this->db_onedev);
|
|
exit;
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
function search_patient_form(){
|
|
$prm = $this->sys_input;
|
|
$name = $prm['name'];
|
|
$dob = $prm['dob'];
|
|
$nik = $prm['nik'];
|
|
$enc = $this->ibl_encryptor;
|
|
|
|
$name_where = '1=1';
|
|
if (strlen($name) >= 3) {
|
|
$toks = $enc->query_tokens($name);
|
|
$conds = [];
|
|
foreach ($toks as $tok) { $tok_esc = $this->db_onedev->escape_str($tok); $conds[] = "JSON_CONTAINS(M_PatientName_bidx, '\"$tok_esc\"')"; }
|
|
if ($conds) $name_where = implode(' AND ', $conds);
|
|
}
|
|
$nik_where = '';
|
|
if ($nik != '' && strlen($nik) >= 3) {
|
|
$toks = $enc->query_tokens($nik);
|
|
$conds = [];
|
|
foreach ($toks as $tok) { $tok_esc = $this->db_onedev->escape_str($tok); $conds[] = "JSON_CONTAINS(M_PatientNIK_bidx, '\"$tok_esc\"')"; }
|
|
if ($conds) $nik_where = "AND (" . implode(' AND ', $conds) . ")";
|
|
}
|
|
$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 M_PatientID
|
|
FROM m_patient
|
|
$join_company
|
|
WHERE
|
|
M_PatientIsActive = 'Y' AND ({$name_where})
|
|
AND (DATE_FORMAT(M_PatientDOB, '%d-%m-%Y') LIKE '%{$dob}%' and M_PatientDOB IS NOT NULL)
|
|
{$nik_where}
|
|
GROUP BY M_PatientID
|
|
) x";
|
|
$countx = $this->db_onedev->query($sql)->row()->total;
|
|
|
|
$sql = "SELECT m_patient.*, DATE_FORMAT(M_PatientDOB, '%d-%m-%Y') as dob_ina,
|
|
M_PatientNoReg as Mcu_PreregisterDetailsPID,
|
|
M_PatientID as Mcu_PreregisterDetailsM_PatientID,
|
|
M_TitleID as Mcu_PreregisterDetailsM_TitleID,
|
|
M_SexCode as Mcu_PreregisterDetailsM_SexCode,
|
|
M_PatientDOB as Mcu_PreregisterDetailsDOB,
|
|
IFNULL(M_ReligionID,0) as Mcu_PreregisterDetailsM_ReligionID,
|
|
M_PatientJabatan as Mcu_PreregisterDetailsJabatan,
|
|
M_PatientKedudukan as Mcu_PreregisterDetailsKedudukan,
|
|
M_PatientLocation as Mcu_PreregisterDetailsLocation,
|
|
M_PatientJob as Mcu_PreregisterDetailsJob
|
|
FROM m_patient
|
|
$join_company
|
|
LEFT join m_title on M_PatientM_TitleID = M_TitleID
|
|
LEFT join m_sex on M_PatientM_SexID = M_SexID
|
|
left join m_religion on m_patientm_religionid = m_religionid
|
|
WHERE
|
|
M_PatientIsActive = 'Y' AND ({$name_where})
|
|
AND (DATE_FORMAT(M_PatientDOB, '%d-%m-%Y') LIKE '%{$dob}%' and M_PatientDOB IS NOT NULL)
|
|
{$nik_where}
|
|
GROUP BY M_PatientID
|
|
LIMIT 10 OFFSET 0";
|
|
|
|
$rows = $this->db_onedev->query($sql)->result_array();
|
|
foreach ($rows as $k => $v) {
|
|
$name_dec = $enc->decrypt($v['M_PatientName_enc'] ?? '') ?? $v['M_PatientName'];
|
|
$hp_dec = $enc->decrypt($v['M_PatientHP_enc'] ?? '') ?? $v['M_PatientHP'];
|
|
$email_dec = $enc->decrypt($v['M_PatientEmail_enc'] ?? '') ?? $v['M_PatientEmail'];
|
|
$nik_dec = $enc->decrypt($v['M_PatientNIK_enc'] ?? '') ?? $v['M_PatientNIK'];
|
|
$rows[$k]['M_PatientName'] = $name_dec;
|
|
$rows[$k]['M_PatientHP'] = $hp_dec;
|
|
$rows[$k]['M_PatientEmail'] = $email_dec;
|
|
$rows[$k]['M_PatientNIK'] = $nik_dec;
|
|
$rows[$k]['Mcu_PreregisterDetailsPatientName'] = $name_dec;
|
|
$rows[$k]['Mcu_PreregisterDetailsNIK'] = $nik_dec;
|
|
$rows[$k]['Mcu_PreregisterDetailsEmail'] = $email_dec;
|
|
$rows[$k]['Mcu_PreregisterDetailsHp'] = $hp_dec;
|
|
foreach (array_keys($rows[$k]) as $col) {
|
|
if (substr($col, -4) === '_enc' || substr($col, -5) === '_bidx') unset($rows[$k][$col]);
|
|
}
|
|
}
|
|
|
|
$result = array("total" => $countx, "records" => $rows);
|
|
$this->sys_ok($result);
|
|
exit;
|
|
}
|
|
|
|
function generatesetup(){
|
|
$prm = $this->sys_input;
|
|
$setupcode = $prm['setupcode'];
|
|
$query =" SELECT mcu_offline_prepare.*, '' as patients,
|
|
M_CompanyName,
|
|
'' as agreements,
|
|
'' as deliveries,
|
|
'' as doctors,
|
|
M_MouName as default_mou_name,
|
|
M_DoctorName as default_doctor_name,
|
|
DATE_FORMAT(McuOfflinePrepareStartDate,'%d-%m-%Y') as start_date,
|
|
DATE_FORMAT(McuOfflinePrepareEndDate,'%d-%m-%Y') as end_date,
|
|
DATE_FORMAT(McuOfflinePreparePromiseDate,'%d-%m-%Y') as promise_date,
|
|
TIME_FORMAT(McuOfflinePreparePromiseTime,'%H:%i') as promise_time
|
|
FROM mcu_offline_prepare
|
|
JOIN m_company ON McuOfflinePrepareM_CompanyID = M_CompanyID
|
|
JOIN m_mou ON McuOfflinePrepareM_MouDefaultID = M_MouID
|
|
JOIN m_doctor ON McuOfflinePrepareM_DoctorDefaultID = M_DoctorID
|
|
WHERE
|
|
McuOfflinePrepareCode = '{$setupcode}'
|
|
LIMIT 1
|
|
";
|
|
//echo $query;
|
|
$row = $this->db_onedev->query($query)->row_array();
|
|
|
|
if($row){
|
|
$row['agreements'] = json_decode($row['McuOfflinePrepareMous']);
|
|
$row['deliveries'] = json_decode($row['McuOfflinePrepareDeliveries']);
|
|
$row['doctors'] = json_decode($row['McuOfflinePrepareDoctors']);
|
|
}
|
|
|
|
$result = array(
|
|
"total" => 1 ,
|
|
"records" => $row
|
|
);
|
|
$this->sys_ok($result);
|
|
exit;
|
|
}
|
|
|
|
function search_patient_listing()
|
|
{
|
|
$prm = $this->sys_input;
|
|
if (! $this->isLogin) {
|
|
$this->sys_error("Invalid Token");
|
|
exit;
|
|
}
|
|
|
|
$search = $prm["search"];
|
|
$setup = $prm["setup"];
|
|
|
|
$sql_where = "";
|
|
if ($search != "") {
|
|
$sql_where .= " AND ( Mcu_PreregisterDetailsKTP like CONCAT('%','{$search}','%') OR Mcu_PreregisterDetailsPatientName like CONCAT('%','{$search}','%') OR Mcu_PreregisterDetailsNIK like CONCAT('%','{$search}','%')) ";
|
|
}
|
|
|
|
$number_limit = 10;
|
|
$number_offset = ($prm['current_page'] - 1) * $number_limit ;
|
|
|
|
$sql = " SELECT count(*) as total
|
|
FROM mcu_preregister_patients
|
|
JOIN m_sex ON TRIM(Mcu_PreregisterDetailsM_SexCode) = TRIM(M_SexCode)
|
|
LEFT JOIN m_religion ON Mcu_PreregisterDetailsM_ReligionID = M_ReligionID
|
|
LEFT JOIN m_title ON Mcu_PreregisterDetailsM_TitleID = M_TitleID
|
|
WHERE
|
|
Mcu_PreregisterDetailsIsActive = 'Y' AND Mcu_PreregisterDetailsMcuOfflinePrepareID = '{$setup['McuOfflinePrepareID']}'
|
|
$sql_where
|
|
|
|
";
|
|
//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_PreregisterDetailsPatientPrefix,''),' ',Mcu_PreregisterDetailsPatientName,' ',IFNULL(Mcu_PreregisterDetailsPatientSuffix,'')) as patient_fullname,
|
|
DATE_FORMAT(Mcu_PreregisterDetailsDOB,'%d-%m-%Y') as dob,
|
|
DATE_FORMAT(Mcu_PreregisterDetailsDOB,'%d-%m-%Y') as Mcu_PreregisterDetailsDOB
|
|
FROM mcu_preregister_patients
|
|
JOIN m_sex ON TRIM(Mcu_PreregisterDetailsM_SexCode) = TRIM(M_SexCode)
|
|
LEFT JOIN m_religion ON Mcu_PreregisterDetailsM_ReligionID = M_ReligionID
|
|
LEFT JOIN m_title ON Mcu_PreregisterDetailsM_TitleID = M_TitleID
|
|
WHERE
|
|
Mcu_PreregisterDetailsIsActive = 'Y' AND Mcu_PreregisterDetailsMcuOfflinePrepareID = '{$setup['McuOfflinePrepareID']}'
|
|
$sql_where
|
|
ORDER BY Mcu_PreregisterDetailsFlagAction ASC, Mcu_PreregisterDetailsPatientName ASC
|
|
limit $number_limit offset $number_offset";
|
|
|
|
$query = $this->db_onedev->query($sql);
|
|
//echo $sql;
|
|
$rows = $query->result_array();
|
|
if($rows){
|
|
foreach($rows as $k => $v){
|
|
$rows[$k]['agreement'] = array();
|
|
$sql = "SELECT M_MouID as id, M_MouName as name, M_MouNumber as code
|
|
FROM m_mou
|
|
WHERE
|
|
M_MouNumber = '{$v['Mcu_PreregisterDetailsAgreement']}'";
|
|
$rows[$k]['agreement'] = $this->db_onedev->query($sql)->row_array();
|
|
$rows[$k]['packets'] = array();
|
|
$rows[$k]['tests'] = array();
|
|
if($rows[$k]['agreement']){
|
|
$rows[$k]['Mcu_PreregisterDetailsAgreement'] = $rows[$k]['agreement']['code'];
|
|
|
|
$join_test = '';
|
|
$filter_paket = "AND T_PacketSasCode IN ('')";
|
|
$filter_test = "AND T_TestSasCode IN ('')";
|
|
if($v['Mcu_PreregisterDetailsTests'] != ''){
|
|
$xjoin_tests = explode(',',$v['Mcu_PreregisterDetailsTests']);
|
|
//print_r($xjoin_tests);
|
|
if($xjoin_tests){
|
|
foreach($xjoin_tests as $kjt => $vjt){
|
|
if($join_test != '')
|
|
$join_test .= ",";
|
|
|
|
$join_test .= "'{$vjt}'";
|
|
|
|
}
|
|
}
|
|
//echo $join_test;
|
|
$filter_paket = "AND T_PacketSasCode IN ({$join_test})";
|
|
$filter_test = "AND T_TestSasCode IN ({$join_test}) ";
|
|
}
|
|
|
|
|
|
$sql = "SELECT T_PacketID as id, T_PacketName as name, T_PacketSasCode as code, nat_test
|
|
FROM ss_price_mou
|
|
JOIN t_packet ON T_TestID = T_PacketID AND T_PacketIsActive = 'Y'
|
|
WHERE
|
|
Ss_PriceMouM_MouID = {$rows[$k]['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
|
|
Ss_PriceMouM_MouID = {$rows[$k]['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_PreregisterDetailsM_PatientID as id
|
|
FROM mcu_preregister_patients
|
|
WHERE
|
|
Mcu_PreregisterDetailsIsActive = 'Y' AND Mcu_PreregisterDetailsMcuOfflinePrepareID = '{$setup['McuOfflinePrepareID']}'";
|
|
|
|
$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, "records" => $rows,"pids"=> $pids,"sql"=> $this->db_onedev->last_query());
|
|
$this->sys_ok($result);
|
|
exit;
|
|
}
|
|
|
|
function getkelurahan(){
|
|
$prm = $this->sys_input;
|
|
$query =" SELECT *
|
|
FROM m_kelurahan
|
|
WHERE
|
|
M_KelurahanIsActive = 'Y' AND M_KelurahanM_DistrictID = ?
|
|
";
|
|
//echo $query;
|
|
$rows = $this->db_onedev->query($query,array($prm['id']))->result_array();
|
|
|
|
$result = array(
|
|
"total" => count($rows) ,
|
|
"records" => $rows,
|
|
);
|
|
$this->sys_ok($result);
|
|
exit;
|
|
}
|
|
|
|
function getdatapatient(){
|
|
$prm = $this->sys_input;
|
|
$query =" SELECT mcu_offline_prepare.*,
|
|
'' as agreements,
|
|
'' as deliveries,
|
|
'' as doctors,
|
|
M_CompanyName,
|
|
M_MouName as default_mou_name,
|
|
M_DoctorName as default_doctor_name,
|
|
DATE_FORMAT(McuOfflinePrepareStartDate,'%d-%m-%Y') as start_date,
|
|
DATE_FORMAT(McuOfflinePrepareEndDate,'%d-%m-%Y') as end_date,
|
|
DATE_FORMAT(McuOfflinePreparePromiseDate,'%d-%m-%Y') as promise_date,
|
|
TIME_FORMAT(McuOfflinePreparePromiseTime,'%H:%i') as promise_time
|
|
FROM mcu_offline_prepare
|
|
JOIN m_company ON McuOfflinePrepareM_CompanyID = M_CompanyID
|
|
JOIN m_mou ON McuOfflinePrepareM_MouDefaultID = M_MouID
|
|
JOIN m_doctor ON McuOfflinePrepareM_DoctorDefaultID = M_DoctorID
|
|
WHERE
|
|
McuOfflinePrepareID = {$prm['Mcu_PreregisterDetailsMcuOfflinePrepareID']};
|
|
";
|
|
//echo $query;
|
|
$rows = $this->db_onedev->query($query)->result_array();
|
|
if($rows){
|
|
foreach($rows as $k => $v){
|
|
$rows[$k]['agreements'] = json_decode($v['McuOfflinePrepareMous']);
|
|
$rows[$k]['deliveries'] = json_decode($v['McuOfflinePrepareDeliveries']);
|
|
$rows[$k]['doctors'] = json_decode($v['McuOfflinePrepareDoctors']);
|
|
|
|
}
|
|
}
|
|
$result = array(
|
|
"total" => count($rows) ,
|
|
"records" => $rows,
|
|
);
|
|
$this->sys_ok($result);
|
|
exit;
|
|
}
|
|
|
|
function getdatapackets(){
|
|
if (! $this->isLogin) {
|
|
$this->sys_error("Invalid Token");
|
|
exit;
|
|
}
|
|
$prm = $this->sys_input;
|
|
$search = $prm["search"];
|
|
|
|
$number_limit = 10;
|
|
$number_offset = ($prm['current_page'] - 1) * $number_limit ;
|
|
|
|
$sql = "SELECT count(*) as total
|
|
FROM (
|
|
SELECT T_PacketID as id, T_PacketName as name, T_PacketSasCode as code
|
|
FROM ss_price_mou
|
|
JOIN t_packet ON T_TestID = T_PacketID AND T_PacketIsActive = 'Y'
|
|
WHERE
|
|
Ss_PriceMouM_MouID = {$prm['id']} AND is_packet = 'Y' AND
|
|
( T_TestName LIKE CONCAT('%','{$search}','%') )
|
|
) x
|
|
";
|
|
//echo $sql;
|
|
$query = $this->db_onedev->query($sql, $sql_param);
|
|
$tot_count = 0;
|
|
$tot_page = 0;
|
|
if ($query) {
|
|
$tot_count = $query->result_array()[0]["total"];
|
|
$tot_page = ceil($tot_count/$number_limit);
|
|
} else {
|
|
$this->sys_error_db("m_doctor count", $this->db_onedev);
|
|
exit;
|
|
}
|
|
|
|
$query ="
|
|
SELECT T_PacketID as id, T_PacketName as name, T_PacketSasCode as code, nat_test
|
|
FROM ss_price_mou
|
|
JOIN t_packet ON T_TestID = T_PacketID AND T_PacketIsActive = 'Y'
|
|
WHERE
|
|
Ss_PriceMouM_MouID = {$prm['id']} AND is_packet = 'Y' AND
|
|
( T_TestName LIKE CONCAT('%','{$search}','%') )
|
|
ORDER BY T_PacketSasCode ASC
|
|
limit $number_limit offset $number_offset
|
|
";
|
|
//echo $query;
|
|
$rows = $this->db_onedev->query($query)->result_array();
|
|
if($rows){
|
|
foreach($rows as $kp => $vp){
|
|
$rows[$kp]['nat_test'] = json_decode($vp['nat_test']);
|
|
}
|
|
}
|
|
|
|
$result = array(
|
|
"total" => $tot_page ,
|
|
"records" => $rows,
|
|
);
|
|
$this->sys_ok($result);
|
|
exit;
|
|
}
|
|
|
|
function getdatatests(){
|
|
if (! $this->isLogin) {
|
|
$this->sys_error("Invalid Token");
|
|
exit;
|
|
}
|
|
$prm = $this->sys_input;
|
|
$search = $prm["search"];
|
|
$number_limit = 10;
|
|
$number_offset = ($prm['current_page'] - 1) * $number_limit ;
|
|
|
|
$sql = "SELECT count(*) as total
|
|
FROM (
|
|
SELECT test.T_TestID as id, test.T_TestName as name, test.T_TestSasCode as code, nat_test
|
|
FROM ss_price_mou
|
|
JOIN t_test test ON test.T_TestID = ss_price_mou.T_TestID
|
|
WHERE
|
|
Ss_PriceMouM_MouID = {$prm['id']} AND
|
|
( ss_price_mou.T_TestName LIKE CONCAT('%','{$search}','%') ) AND
|
|
T_PriceIsCito = 'N'
|
|
GROUP BY Ss_PriceMouID
|
|
) x
|
|
";
|
|
//echo $sql;
|
|
$query = $this->db_onedev->query($sql, $sql_param);
|
|
$tot_count = 0;
|
|
$tot_page = 0;
|
|
if ($query) {
|
|
$tot_count = $query->result_array()[0]["total"];
|
|
$tot_page = ceil($tot_count/$number_limit);
|
|
} else {
|
|
$this->sys_error_db("m_doctor count", $this->db_onedev);
|
|
exit;
|
|
}
|
|
$query ="
|
|
SELECT test.T_TestID as id, test.T_TestName as name, test.T_TestSasCode as code, nat_test
|
|
FROM ss_price_mou
|
|
JOIN t_test test ON test.T_TestID = ss_price_mou.T_TestID
|
|
WHERE
|
|
Ss_PriceMouM_MouID = {$prm['id']} AND
|
|
( ss_price_mou.T_TestName LIKE CONCAT('%','{$search}','%') ) AND
|
|
T_PriceIsCito = 'N'
|
|
GROUP BY Ss_PriceMouID
|
|
ORDER BY T_TestSasCode ASC
|
|
limit $number_limit offset $number_offset
|
|
";
|
|
//echo $query;
|
|
$rows = $this->db_onedev->query($query)->result_array();
|
|
if($rows){
|
|
foreach($rows as $kp => $vp){
|
|
$rows[$kp]['nat_test'] = json_decode($vp['nat_test']);
|
|
}
|
|
}
|
|
$result = array(
|
|
"total" => $tot_page ,
|
|
"records" => $rows,
|
|
);
|
|
$this->sys_ok($result);
|
|
exit;
|
|
}
|
|
|
|
function save(){
|
|
if (! $this->isLogin) {
|
|
$this->sys_error("Invalid Token");
|
|
exit;
|
|
}
|
|
$userid = $this->sys_user["M_UserID"];
|
|
$prm = $this->sys_input;
|
|
$datas = $prm['data'];
|
|
//print_r($prm);
|
|
$sql = "truncate mcu_preregister_patients";
|
|
$this->db_onedev->query($sql);
|
|
unset($datas[0]);
|
|
foreach($datas as $k => $v){
|
|
$pdob = date('Y-m-d',strtotime($v['TANGGAL_LAHIR']));
|
|
$m_nama = $this->db_onedev->escape_str($this->_mask_name($v['NAMA']));
|
|
$m_ktp = $this->_mask_id($v['KTP']);
|
|
$m_nik = $this->_mask_id($v['NIK']);
|
|
$m_email = $this->_mask_email($v['EMAIL']);
|
|
$m_hp = $this->_mask_phone($v['HP']);
|
|
$query = " INSERT INTO mcu_preregister_patients (
|
|
Mcu_PreregisterDetailsMcuOfflinePrepareID,
|
|
Mcu_PreregisterDetailsPID,
|
|
Mcu_PreregisterDetailsKTP,
|
|
Mcu_PreregisterDetailsNIK,
|
|
Mcu_PreregisterDetailsPatientName,
|
|
Mcu_PreregisterDetailsEmail,
|
|
Mcu_PreregisterDetailsHp,
|
|
Mcu_PreregisterDetailsDOB,
|
|
Mcu_PreregisterDetailsKedudukan,
|
|
Mcu_PreregisterDetailsJabatan,
|
|
Mcu_PreregisterDetailsJob,
|
|
Mcu_PreregisterDetailsLocation,
|
|
Mcu_PreregisterDetailsM_SexCode,
|
|
Mcu_PreregisterDetailsAgreement,
|
|
Mcu_PreregisterDetailsTests,
|
|
Mcu_PreregisterDetailsCreated,
|
|
Mcu_PreregisterDetailsUserID
|
|
)
|
|
VALUES(
|
|
'{$prm['xid']}',
|
|
'{$v['PID']}',
|
|
'{$m_nik}',
|
|
'{$m_ktp}',
|
|
'{$m_nama}',
|
|
'{$m_email}',
|
|
'{$m_hp}',
|
|
'{$pdob}',
|
|
'{$v['KEDUDUKAN']}',
|
|
'{$v['JABATAN']}',
|
|
'{$v['JOB']}',
|
|
'{$v['LOKASI']}',
|
|
'{$v['JENIS_KELAMIN']}',
|
|
'{$v['AGREEMENT']}',
|
|
'{$v['PEMERIKSAAN']}',
|
|
NOW(),
|
|
{$userid}
|
|
)";
|
|
//echo $query;
|
|
$rows = $this->db_onedev->query($query);
|
|
if($rows){
|
|
$last_id_x = $this->db_onedev->insert_id();
|
|
$patient_id = 0;
|
|
$sql = "SELECT *
|
|
FROM mcu_offline_prepare
|
|
JOIN m_company ON McuOfflinePrepareM_CompanyID = M_CompanyID
|
|
WHERE McuOfflinePrepareID = {$prm['xid']}";
|
|
$row_header = $this->db_onedev->query($sql)->result_array();
|
|
|
|
if($v['PID'] != ''){
|
|
$sql = "SELECT * FROM m_patient WHERE M_PatientNoReg = '{$v['PID']}' LIMIT 1";
|
|
$exist_r = $this->db_onedev->query($sql)->row_array();
|
|
if($exist_r){
|
|
$patient_id = $exist_r["M_PatientID"];
|
|
}
|
|
}
|
|
|
|
$enc = $this->ibl_encryptor;
|
|
if($v['KTP'] != ''){
|
|
$ktp_toks = $enc->query_tokens($v['KTP']);
|
|
$ktp_conds = [];
|
|
foreach ($ktp_toks as $tok) { $tok_esc = $this->db_onedev->escape_str($tok); $ktp_conds[] = "JSON_CONTAINS(M_PatientNIK_bidx, '\"$tok_esc\"')"; }
|
|
if ($ktp_conds) {
|
|
$sql = "SELECT M_PatientID FROM m_patient
|
|
WHERE M_PatientIsActive = 'Y' AND (" . implode(' AND ', $ktp_conds) . ")
|
|
LIMIT 1";
|
|
$exist_r = $this->db_onedev->query($sql)->row_array();
|
|
if($exist_r) $patient_id = $exist_r["M_PatientID"];
|
|
}
|
|
}
|
|
|
|
if($patient_id == 0){
|
|
$name_toks = $enc->query_tokens($v['NAMA']);
|
|
$name_conds = [];
|
|
foreach ($name_toks as $tok) { $tok_esc = $this->db_onedev->escape_str($tok); $name_conds[] = "JSON_CONTAINS(M_PatientName_bidx, '\"$tok_esc\"')"; }
|
|
$name_where = $name_conds ? implode(' AND ', $name_conds) : '0';
|
|
$sql = "SELECT M_PatientID FROM m_patient
|
|
WHERE ({$name_where}) AND M_PatientDOB = '{$pdob}' AND M_PatientIsActive = 'Y' LIMIT 1";
|
|
$exist_r = $this->db_onedev->query($sql)->row_array();
|
|
if($exist_r) $patient_id = $exist_r["M_PatientID"];
|
|
}
|
|
|
|
|
|
|
|
if($patient_id == 0){
|
|
$sex_id = 0;
|
|
$sql = "SELECT * FROM m_sex WHERE M_SexCode = '{$v['JENIS_KELAMIN']}' AND M_SexIsActive = 'Y' LIMIT 1";
|
|
$sex_id = $this->db_onedev->query($sql)->row()->M_SexID;
|
|
|
|
$title_id = 0;
|
|
$sql = "SELECT * FROM m_title WHERE M_TitleM_SexID = '{$sex_id}' AND M_TitleIsActive = 'Y' ORDER BY M_TitleID ASC LIMIT 1";
|
|
$title_id = $this->db_onedev->query($sql)->row()->M_TitleID;
|
|
|
|
$religion_id = 0;
|
|
$sql = "SELECT * FROM m_religion WHERE M_ReligionName = 'OTHERS' AND M_ReligionIsActive = 'Y' LIMIT 1";
|
|
$religion_id = $this->db_onedev->query($sql)->row()->M_ReligionID;
|
|
|
|
//$pdob = date('Y-m-d',strtotime($prm['Mcu_PreregisterDetailsDOB']));
|
|
/*$sql = "INSERT INTO m_patient (
|
|
M_PatientName,
|
|
M_PatientM_TitleID,
|
|
M_PatientM_SexID,
|
|
M_PatientM_ReligionID,
|
|
M_PatientPOB,
|
|
M_PatientDOB,
|
|
M_PatientNIK,
|
|
M_PatientJabatan,
|
|
M_PatientLocation,
|
|
M_PatientKedudukan,
|
|
M_PatientJob,
|
|
M_PatientEmail,
|
|
M_PatientHP,
|
|
M_PatientUserID
|
|
)
|
|
VALUES(
|
|
'{$v["NAMA"]}',
|
|
{$title_id},
|
|
{$sex_id},
|
|
{$religion_id},
|
|
'-',
|
|
'{$pdob}',
|
|
'{$v["NIK"]}',
|
|
'{$v['JABATAN']}',
|
|
'{$v['LOKASI']}',
|
|
'{$v['KEDUDUKAN']}',
|
|
'{$v['JOB']}',
|
|
'{$v['EMAIL']}',
|
|
'{$v['HP']}',
|
|
'{$userid}'
|
|
)";
|
|
//echo $sql;
|
|
$this->db_onedev->query($sql);*/
|
|
$enc = $this->ibl_encryptor;
|
|
$dob_str = date('d-m-Y', strtotime($pdob));
|
|
$data_insert_patient = [
|
|
'M_PatientName' => $this->_mask_name($v["NAMA"]),
|
|
'M_PatientName_enc' => $enc->encrypt($v["NAMA"]),
|
|
'M_PatientName_bidx' => $enc->search_bidx($v["NAMA"]),
|
|
'M_PatientM_TitleID' => $title_id,
|
|
'M_PatientM_SexID' => $sex_id,
|
|
'M_PatientM_ReligionID' => $religion_id,
|
|
'M_PatientPOB' => '***',
|
|
'M_PatientPOB_enc' => $enc->encrypt('-'),
|
|
'M_PatientDOB' => $pdob,
|
|
'M_PatientDOB_enc' => $enc->encrypt($dob_str),
|
|
'M_PatientDOB_bidx' => $enc->search_bidx($dob_str),
|
|
'M_PatientNIK' => $v["NIK"],
|
|
'M_PatientNIK_bidx' => $enc->search_bidx($v["NIK"] ?? ''),
|
|
'M_PatientJabatan' => $v['JABATAN'],
|
|
'M_PatientLocation' => $v['LOKASI'],
|
|
'M_PatientKedudukan' => $v['KEDUDUKAN'],
|
|
'M_PatientJob' => $v['JOB'],
|
|
'M_PatientEmail' => $this->_mask_email($v['EMAIL']),
|
|
'M_PatientEmail_enc' => $enc->encrypt($v['EMAIL']),
|
|
'M_PatientHP' => $this->_mask_phone($v['HP']),
|
|
'M_PatientHP_enc' => $enc->encrypt($v['HP']),
|
|
'M_PatientHP_bidx' => $enc->search_bidx($v['HP']),
|
|
'M_PatientUserID' => $userid,
|
|
];
|
|
if(isset($v["KTP"]) && $v["KTP"] != ''){
|
|
$data_insert_patient['M_PatientM_IdTypeID'] = 1;
|
|
$data_insert_patient['M_PatientIDNumber'] = $this->_mask_id($v["KTP"]);
|
|
$data_insert_patient['M_PatientIDNumber_enc'] = $enc->encrypt($v["KTP"]);
|
|
}
|
|
|
|
$this->db_onedev->insert('m_patient', $data_insert_patient);
|
|
$patient_id = $this->db_onedev->insert_id();
|
|
$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.ADD', '{$ptn}', $userid)");
|
|
|
|
$sql = "INSERT INTO m_patientaddress (
|
|
M_PatientAddressM_PatientID,
|
|
M_PatientAddressDescription,
|
|
M_PatientAddressM_KelurahanID,
|
|
M_PatientAddressCreated
|
|
)
|
|
VALUES(
|
|
{$patient_id},
|
|
'{$row_header['M_CompanyAddress']}',
|
|
'{$row_header['M_CompanyM_KelurahanID']}',
|
|
NOW()
|
|
)";
|
|
$this->db_onedev->query($sql);
|
|
/*$patient_addr_id = $this->db_onedev->insert_id();
|
|
$sql = "SELECT * FROM m_patientaddress WHERE M_PatientAddressID = {$patient_addr_id}";
|
|
$ptn_addr = $this->db_onedev->query($sql)->row_array();
|
|
$ptn_addr = json_encode($ptn_addr);
|
|
$this->db_onedev->query("CALL one_log.log_me('PATIENT', 'PATIENT.ADDR_ADD', '{$ptn_addr}', $userid)");*/
|
|
|
|
|
|
}
|
|
else{
|
|
//$pdob = date('Y-m-d',strtotime($prm['Mcu_PreregisterDetailsDOB']));
|
|
$sql ="UPDATE m_patient SET
|
|
M_PatientEmail = '{$v['EMAIL']}',
|
|
M_PatientHP = '{$v['HP']}',
|
|
M_PatientNIK = '{$v['NIK']}',
|
|
M_PatientKTP = '{$v['KTP']}',
|
|
M_PatientJabatan = '{$v['JABATAN']}',
|
|
M_PatientKedudukan = '{$v['KEDUDUKAN']}',
|
|
M_PatientLocation = '{$v['LOKASI']}',
|
|
M_PatientJob = '{$v['JOB']}'
|
|
WHERE
|
|
M_PatientID = '{$patient_id}'
|
|
";
|
|
|
|
$this->db_onedev->query($sql);
|
|
|
|
/*$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.EDIT', '{$ptn}', $userid)");*/
|
|
}
|
|
|
|
$sql = "UPDATE mcu_preregister_patients SET Mcu_PreregisterDetailsM_PatientID = {$patient_id} WHERE Mcu_PreregisterDetailsID = {$last_id_x}";
|
|
$this->db_onedev->query($sql);
|
|
}
|
|
}
|
|
|
|
|
|
|
|
$result = array(
|
|
"total" => 1 ,
|
|
"records" => array('status'=>'OK')
|
|
);
|
|
|
|
$this->sys_ok($result);
|
|
exit;
|
|
}
|
|
|
|
function newpatient(){
|
|
if (! $this->isLogin) {
|
|
$this->sys_error("Invalid Token");
|
|
exit;
|
|
}
|
|
$prm = $this->sys_input;
|
|
$userid = $this->sys_user["M_UserID"];
|
|
|
|
$pdob = date('Y-m-d', strtotime($prm['M_PatientDOB']));
|
|
$dob_str = date('d-m-Y', strtotime($prm['M_PatientDOB']));
|
|
$patient_name = $prm['M_PatientName'];
|
|
$enc = $this->ibl_encryptor;
|
|
|
|
$ptn = [
|
|
'M_PatientName' => $this->_mask_name($patient_name),
|
|
'M_PatientName_enc' => $enc->encrypt($patient_name),
|
|
'M_PatientName_bidx' => $enc->search_bidx($patient_name),
|
|
'M_PatientM_TitleID' => $prm['M_PatientM_TitleID'],
|
|
'M_PatientPrefix' => $prm['M_PatientPrefix'],
|
|
'M_PatientSuffix' => $prm['M_PatientSuffix'],
|
|
'M_PatientDOB' => $pdob,
|
|
'M_PatientDOB_enc' => $enc->encrypt($dob_str),
|
|
'M_PatientDOB_bidx' => $enc->search_bidx($dob_str),
|
|
'M_PatientM_SexID' => $prm['M_PatientM_SexID'],
|
|
'M_PatientM_ReligionID' => $prm['M_PatientM_ReligionID'],
|
|
'M_PatientEmail' => $this->_mask_email($prm['M_PatientEmail']),
|
|
'M_PatientEmail_enc' => $enc->encrypt($prm['M_PatientEmail']),
|
|
'M_PatientPOB' => $this->_mask_short($prm['M_PatientPOB']),
|
|
'M_PatientPOB_enc' => $enc->encrypt($prm['M_PatientPOB']),
|
|
'M_PatientHP' => $this->_mask_phone($prm['M_PatientHP']),
|
|
'M_PatientHP_enc' => $enc->encrypt($prm['M_PatientHP']),
|
|
'M_PatientHP_bidx' => $enc->search_bidx($prm['M_PatientHP']),
|
|
'M_PatientPhone' => $this->_mask_phone($prm['M_PatientPhone']),
|
|
'M_PatientPhone_enc' => $enc->encrypt($prm['M_PatientPhone']),
|
|
'M_PatientM_IdTypeID' => $prm['M_PatientM_IdTypeID'],
|
|
'M_PatientIDNumber' => $this->_mask_id($prm['M_PatientIDNumber']),
|
|
'M_PatientIDNumber_enc' => $enc->encrypt($prm['M_PatientIDNumber']),
|
|
'M_PatientNIK' => $prm['M_PatientNIK'],
|
|
'M_PatientNIK_bidx' => $enc->search_bidx($prm['M_PatientNIK'] ?? ''),
|
|
'M_PatientNote' => $prm['M_PatientNote'],
|
|
'M_PatientJabatan' => $prm['M_PatientJabatan'],
|
|
'M_PatientKedudukan' => $prm['M_PatientKedudukan'],
|
|
'M_PatientPJ' => $prm['M_PatientPJ'],
|
|
'M_PatientLocation' => $prm['M_PatientLocation'],
|
|
'M_PatientJob' => $prm['M_PatientJob'],
|
|
'M_PatientUserID' => $userid,
|
|
];
|
|
$this->db_onedev->insert('m_patient', $ptn);
|
|
$last_id = $this->db_onedev->insert_id();
|
|
$result = array(
|
|
"total" => 1 ,
|
|
"records" => array('status'=>'OK'),
|
|
"id" => $last_id
|
|
);
|
|
$ptn = $prm;
|
|
$ptn["M_PatientID"] = $last_id;
|
|
$ptn["M_PatientDOB"] = $pdob;
|
|
$ptn = json_encode($ptn);
|
|
$this->db_onedev->query("CALL one_log.log_me('PATIENT', 'PATIENT.ADD', '{$ptn}', $userid)");
|
|
$this->sys_ok($result);
|
|
exit;
|
|
}
|
|
|
|
function deletepatient(){
|
|
if (! $this->isLogin) {
|
|
$this->sys_error("Invalid Token");
|
|
exit;
|
|
}
|
|
$userid = $this->sys_user["M_UserID"];
|
|
$prm = $this->sys_input;
|
|
$query ="UPDATE m_patient SET
|
|
M_PatientIsActive = 'N'
|
|
WHERE
|
|
M_PatientID = '{$prm['M_PatientID']}'
|
|
";
|
|
//echo $query;
|
|
$rows = $this->db_onedev->query($query);
|
|
|
|
$result = array(
|
|
"total" => 1 ,
|
|
"records" => array('status'=>'OK')
|
|
);
|
|
$ptn = $prm;
|
|
$ptn["M_PatientDOB"] = $pdob;
|
|
$ptn = json_encode($ptn);
|
|
$this->db_onedev->query("CALL one_log.log_me('PATIENT', 'PATIENT.DELETE', '{$ptn}', $userid)");
|
|
$this->sys_ok($result);
|
|
exit;
|
|
}
|
|
|
|
function getaddress(){
|
|
if (! $this->isLogin) {
|
|
$this->sys_error("Invalid Token");
|
|
exit;
|
|
}
|
|
$prm = $this->sys_input;
|
|
$query =" SELECT m_patientaddress.*,
|
|
M_KelurahanName,
|
|
M_DistrictID,
|
|
M_DistrictName,
|
|
M_CityID,
|
|
M_CityName,
|
|
'' as action
|
|
FROM m_patientaddress
|
|
JOIN m_kelurahan ON M_PatientAddressM_KelurahanID = M_KelurahanID
|
|
JOIN m_district ON M_KelurahanM_DistrictID = M_DistrictID
|
|
JOIN m_city ON M_DistrictM_CityID = M_CityID
|
|
WHERE
|
|
M_PatientAddressIsActive = 'Y' AND M_PatientAddressM_PatientID = ?
|
|
";
|
|
//echo $query;
|
|
$rows = $this->db_onedev->query($query,array($prm['id']))->result_array();
|
|
if($rows){
|
|
foreach($rows as $k => $v){
|
|
$rows[$k]['action'] = '<v-icon color="error" @click="deleteAddress(props.item)">delete</v-icon>';
|
|
$rows[$k]['action'] .= '<v-icon color="primary" @click="deleteAddress(props.item)">edit</v-icon>';
|
|
|
|
}
|
|
}
|
|
$result = array(
|
|
"total" => count($rows) ,
|
|
"records" => $rows,
|
|
);
|
|
$this->sys_ok($result);
|
|
exit;
|
|
}
|
|
function savenewaddress(){
|
|
if (! $this->isLogin) {
|
|
$this->sys_error("Invalid Token");
|
|
exit;
|
|
}
|
|
$userid = $this->sys_user["M_UserID"];
|
|
$prm = $this->sys_input;
|
|
$count_addrs = $this->db_onedev->query("SELECT COUNT(*) as countx FROM m_patientaddress WHERE M_PatientAddressM_PatientID = '{$prm['M_PatientAddressM_PatientID']}' AND M_PatientAddressIsActive = 'Y'")->row()->countx;
|
|
|
|
//echo $this->db_onedev->last_query();
|
|
if($count_addrs == 0){
|
|
$prm['M_PatientAddressNote'] = 'Utama';
|
|
}
|
|
else{
|
|
$count_addrs_utama = $this->db_onedev->query("SELECT COUNT(*) as countx FROM m_patientaddress WHERE M_PatientAddressM_PatientID = '{$prm['M_PatientAddressM_PatientID']}' AND M_PatientAddressNote = 'Utama' AND M_PatientAddressIsActive = 'Y'")->row()->countx;
|
|
if($count_addrs_utama > 0 && strtolower($prm['M_PatientAddressNote']) == 'utama'){
|
|
$rx = date('YmdHis');
|
|
$prm['M_PatientAddressNote'] = 'Utama_'.$rx;
|
|
}
|
|
}
|
|
$query ="INSERT INTO m_patientaddress (
|
|
M_PatientAddressM_PatientID,
|
|
M_PatientAddressNote,
|
|
M_PatientAddressDescription,
|
|
M_PatientAddressM_KelurahanID,
|
|
M_PatientAddressCreated
|
|
)
|
|
VALUES(
|
|
'{$prm['M_PatientAddressM_PatientID']}',
|
|
'{$prm['M_PatientAddressNote']}',
|
|
'{$prm['M_PatientAddressDescription']}',
|
|
'{$prm['M_PatientAddressM_KelurahanID']}',
|
|
NOW()
|
|
)
|
|
";
|
|
//echo $query;
|
|
$rows = $this->db_onedev->query($query);
|
|
|
|
$result = array(
|
|
"total" => 1 ,
|
|
"records" => array('status'=>'OK')
|
|
);
|
|
$ptn = $prm;
|
|
$ptn["M_UserID"] = $pdob;
|
|
$ptn = json_encode($ptn);
|
|
$this->db_onedev->query("CALL one_log.log_me('PATIENT', 'PATIENT.ADDR_ADD', '{$ptn}', $userid)");
|
|
$this->sys_ok($result);
|
|
exit;
|
|
}
|
|
|
|
function saveeditaddress(){
|
|
if (! $this->isLogin) {
|
|
$this->sys_error("Invalid Token");
|
|
exit;
|
|
}
|
|
$userid = $this->sys_user["M_UserID"];
|
|
$prm = $this->sys_input;
|
|
|
|
$query ="UPDATE m_patientaddress SET
|
|
M_PatientAddressM_PatientID = '{$prm['M_PatientAddressM_PatientID']}',
|
|
M_PatientAddressNote = '{$prm['M_PatientAddressNote']}',
|
|
M_PatientAddressDescription = '{$prm['M_PatientAddressDescription']}',
|
|
M_PatientAddressM_KelurahanID = '{$prm['M_PatientAddressM_KelurahanID']}'
|
|
WHERE
|
|
M_PatientAddressID = '{$prm['M_PatientAddressID']}'
|
|
";
|
|
//echo $query;
|
|
$rows = $this->db_onedev->query($query);
|
|
|
|
$result = array(
|
|
"total" => 1 ,
|
|
"records" => array('status'=>'OK')
|
|
);
|
|
$ptn = $prm;
|
|
$ptn["M_UserID"] = $pdob;
|
|
$ptn = json_encode($ptn);
|
|
$this->db_onedev->query("CALL one_log.log_me('PATIENT', 'PATIENT.ADDR_EDIT', '{$ptn}', $userid)");
|
|
$this->sys_ok($result);
|
|
exit;
|
|
}
|
|
|
|
function deleteaddress(){
|
|
if (! $this->isLogin) {
|
|
$this->sys_error("Invalid Token");
|
|
exit;
|
|
}
|
|
$userid = $this->sys_user["M_UserID"];
|
|
$prm = $this->sys_input;
|
|
|
|
$query ="UPDATE m_patientaddress SET
|
|
M_PatientAddressIsActive = 'N'
|
|
WHERE
|
|
M_PatientAddressID = '{$prm['M_PatientAddressID']}'
|
|
";
|
|
//echo $query;
|
|
$rows = $this->db_onedev->query($query);
|
|
|
|
$result = array(
|
|
"total" => 1 ,
|
|
"records" => array('status'=>'OK')
|
|
);
|
|
$ptn = $prm;
|
|
$ptn["M_UserID"] = $pdob;
|
|
$ptn = json_encode($ptn);
|
|
$this->db_onedev->query("CALL one_log.log_me('PATIENT', 'PATIENT.ADDR_DELETE', '{$ptn}', $userid)");
|
|
$this->sys_ok($result);
|
|
exit;
|
|
}
|
|
|
|
function savenewform(){
|
|
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'];
|
|
$v = $prm;
|
|
$sql = "SELECT *
|
|
FROM mcu_offline_prepare
|
|
JOIN m_mou ON McuOfflinePrepareM_MouDefaultID = M_MouID
|
|
WHERE
|
|
McuOfflinePrepareID = {$setup['McuOfflinePrepareID']}";
|
|
//echo $sql;
|
|
$data_prepare = $this->db_onedev->query($sql)->row_array();
|
|
$default_agreement_code = $data_prepare['M_MouNumber'];
|
|
$default_tests = $data_prepare['McuOfflinePrepareTests'];
|
|
$v['Mcu_PreregisterDetailsPatientName'] = str_replace("'", "\\'", $v['Mcu_PreregisterDetailsPatientName']);
|
|
$pdob = date('Y-m-d',strtotime($v['Mcu_PreregisterDetailsDOB']));
|
|
$m_nama = $this->db_onedev->escape_str($this->_mask_name($v['Mcu_PreregisterDetailsPatientName']));
|
|
$m_nik = $this->_mask_id($v['Mcu_PreregisterDetailsNIK']);
|
|
$m_email = $this->_mask_email($v['Mcu_PreregisterDetailsEmail']);
|
|
$m_hp = $this->_mask_phone($v['Mcu_PreregisterDetailsHp']);
|
|
$query = " INSERT INTO mcu_preregister_patients (
|
|
Mcu_PreregisterDetailsMcuOfflinePrepareID,
|
|
Mcu_PreregisterDetailsM_PatientID,
|
|
Mcu_PreregisterDetailsNIK,
|
|
Mcu_PreregisterDetailsPatientPrefix,
|
|
Mcu_PreregisterDetailsPatientName,
|
|
Mcu_PreregisterDetailsPatientSuffix,
|
|
Mcu_PreregisterDetailsEmail,
|
|
Mcu_PreregisterDetailsHp,
|
|
Mcu_PreregisterDetailsDOB,
|
|
Mcu_PreregisterDetailsKedudukan,
|
|
Mcu_PreregisterDetailsJabatan,
|
|
Mcu_PreregisterDetailsJob,
|
|
Mcu_PreregisterDetailsLocation,
|
|
Mcu_PreregisterDetailsM_SexCode,
|
|
Mcu_PreregisterDetailsM_TitleID,
|
|
Mcu_PreregisterDetailsM_ReligionID,
|
|
Mcu_PreregisterDetailsAgreement,
|
|
Mcu_PreregisterDetailsTests,
|
|
Mcu_PreregisterDetailsCreated,
|
|
Mcu_PreregisterDetailsUserID
|
|
)
|
|
VALUES(
|
|
'{$setup['McuOfflinePrepareID']}',
|
|
'{$v['Mcu_PreregisterDetailsM_PatientID']}',
|
|
'{$m_nik}',
|
|
'{$v['Mcu_PreregisterDetailsPatientPrefix']}',
|
|
'{$m_nama}',
|
|
'{$v['Mcu_PreregisterDetailsPatientSuffix']}',
|
|
'{$m_email}',
|
|
'{$m_hp}',
|
|
'{$pdob}',
|
|
'{$v['Mcu_PreregisterDetailsKedudukan']}',
|
|
'{$v['Mcu_PreregisterDetailsJabatan']}',
|
|
'{$v['Mcu_PreregisterDetailsJob']}',
|
|
'{$v['Mcu_PreregisterDetailsLocation']}',
|
|
'{$v['Mcu_PreregisterDetailsM_SexCode']}',
|
|
'{$v['Mcu_PreregisterDetailsM_TitleID']}',
|
|
'{$v['Mcu_PreregisterDetailsM_ReligionID']}',
|
|
'{$default_agreement_code}',
|
|
'{$default_tests}',
|
|
NOW(),
|
|
{$userid}
|
|
)";
|
|
//echo $query;
|
|
$rows = $this->db_onedev->query($query);
|
|
$last_id_x = $this->db_onedev->insert_id();
|
|
if(intval($v['Mcu_PreregisterDetailsM_PatientID']) == 0){
|
|
$sql = "SELECT *
|
|
FROM mcu_offline_prepare
|
|
JOIN m_company ON McuOfflinePrepareM_CompanyID = M_CompanyID
|
|
WHERE McuOfflinePrepareID = {$setup['McuOfflinePrepareID']}";
|
|
$row_header = $this->db_onedev->query($sql)->result_array();
|
|
//echo $sql;
|
|
$sex_id = 0;
|
|
$sql = "SELECT * FROM m_sex WHERE M_SexCode = '{$v['Mcu_PreregisterDetailsM_SexCode']}' AND M_SexIsActive = 'Y' LIMIT 1";
|
|
//echo $sql;
|
|
$sex_id = $this->db_onedev->query($sql)->row()->M_SexID;
|
|
$title_id = $v['Mcu_PreregisterDetailsM_TitleID'];
|
|
$religion_id = $v['Mcu_PreregisterDetailsM_ReligionID'];
|
|
|
|
$sql = "INSERT INTO m_patient (
|
|
M_PatientPrefix,
|
|
M_PatientName,
|
|
M_PatientSuffix,
|
|
M_PatientM_TitleID,
|
|
M_PatientM_SexID,
|
|
M_PatientM_ReligionID,
|
|
M_PatientPOB,
|
|
M_PatientDOB,
|
|
M_PatientNIK,
|
|
M_PatientJabatan,
|
|
M_PatientLocation,
|
|
M_PatientKedudukan,
|
|
M_PatientJob,
|
|
M_PatientEmail,
|
|
M_PatientHP,
|
|
M_PatientUserID
|
|
)
|
|
VALUES(
|
|
'{$v["Mcu_PreregisterDetailsPatientPrefix"]}',
|
|
'{$v["Mcu_PreregisterDetailsPatientName"]}',
|
|
'{$v["Mcu_PreregisterDetailsPatientSuffix"]}',
|
|
'{$title_id}',
|
|
'{$sex_id}',
|
|
'{$religion_id}',
|
|
'-',
|
|
'{$pdob}',
|
|
'{$v["Mcu_PreregisterDetailsNIK"]}',
|
|
'{$v['Mcu_PreregisterDetailsJabatan']}',
|
|
'{$v['Mcu_PreregisterDetailsLocation']}',
|
|
'{$v['Mcu_PreregisterDetailsKedudukan']}',
|
|
'{$v['Mcu_PreregisterDetailsJob']}',
|
|
'{$v['Mcu_PreregisterDetailsEmail']}',
|
|
'{$v['Mcu_PreregisterDetailsHp']}',
|
|
'{$userid}'
|
|
)";
|
|
//echo $sql;
|
|
$this->db_onedev->query($sql);
|
|
$patient_id = $this->db_onedev->insert_id();
|
|
$sql = "UPDATE mcu_preregister_patients SET Mcu_PreregisterDetailsM_PatientID = {$patient_id} WHERE Mcu_PreregisterDetailsID = {$last_id_x}";
|
|
$this->db_onedev->query($sql);
|
|
|
|
$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.ADD', '{$ptn}', $userid)");
|
|
|
|
$sql = "INSERT INTO m_patientaddress (
|
|
M_PatientAddressM_PatientID,
|
|
M_PatientAddressDescription,
|
|
M_PatientAddressM_KelurahanID,
|
|
M_PatientAddressCreated,
|
|
M_PatientAddressUserID
|
|
)
|
|
VALUES(
|
|
{$patient_id},
|
|
'{$row_header['M_CompanyAddress']}',
|
|
'{$row_header['M_CompanyM_KelurahanID']}',
|
|
NOW(),
|
|
'{$userid}'
|
|
)";
|
|
$this->db_onedev->query($sql);
|
|
$patient_addr_id = $this->db_onedev->insert_id();
|
|
$sql = "SELECT * FROM m_patientaddress WHERE M_PatientAddressID = {$patient_addr_id}";
|
|
$ptn_addr = $this->db_onedev->query($sql)->row_array();
|
|
$ptn_addr = json_encode($ptn_addr);
|
|
//$this->db_onedev->query("CALL one_log.log_me('PATIENT', 'PATIENT.ADDR_ADD', '{$ptn_addr}', $userid)");
|
|
}
|
|
|
|
|
|
$result = array(
|
|
"total" => 1 ,
|
|
"records" => array('status'=>'OK')
|
|
);
|
|
|
|
$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'];
|
|
$pdob = date('Y-m-d',strtotime($v['Mcu_PreregisterDetailsDOB']));
|
|
|
|
$Mcu_PreregisterDetailsTests = '';
|
|
$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_PreregisterDetailsTests = join(',',$packettests);
|
|
}
|
|
$query = " UPDATE mcu_preregister_patients SET
|
|
Mcu_PreregisterDetailsM_PatientID = '{$v['Mcu_PreregisterDetailsM_PatientID']}',
|
|
Mcu_PreregisterDetailsKTP = '{$v['Mcu_PreregisterDetailsKTP']}',
|
|
Mcu_PreregisterDetailsNIK = '{$v['Mcu_PreregisterDetailsNIK']}',
|
|
Mcu_PreregisterDetailsPatientPrefix = '{$v['Mcu_PreregisterDetailsPatientPrefix']}',
|
|
Mcu_PreregisterDetailsPatientName = '{$v['Mcu_PreregisterDetailsPatientName']}',
|
|
Mcu_PreregisterDetailsPatientSuffix = '{$v['Mcu_PreregisterDetailsPatientSuffix']}',
|
|
Mcu_PreregisterDetailsEmail = '{$v['Mcu_PreregisterDetailsEmail']}',
|
|
Mcu_PreregisterDetailsHp = '{$v['Mcu_PreregisterDetailsHp']}',
|
|
Mcu_PreregisterDetailsDOB = '{$pdob}',
|
|
Mcu_PreregisterDetailsKedudukan = '{$v['Mcu_PreregisterDetailsKedudukan']}',
|
|
Mcu_PreregisterDetailsJabatan = '{$v['Mcu_PreregisterDetailsJabatan']}',
|
|
Mcu_PreregisterDetailsJob = '{$v['Mcu_PreregisterDetailsJob']}',
|
|
Mcu_PreregisterDetailsLocation = '{$v['Mcu_PreregisterDetailsLocation']}',
|
|
Mcu_PreregisterDetailsM_SexCode = '{$v['Mcu_PreregisterDetailsM_SexCode']}',
|
|
Mcu_PreregisterDetailsM_TitleID = '{$v['Mcu_PreregisterDetailsM_TitleID']}',
|
|
Mcu_PreregisterDetailsM_ReligionID = '{$v['Mcu_PreregisterDetailsM_ReligionID']}',
|
|
Mcu_PreregisterDetailsAgreement = '{$v['Mcu_PreregisterDetailsAgreement']}',
|
|
Mcu_PreregisterDetailsTests = '{$Mcu_PreregisterDetailsTests}',
|
|
Mcu_PreregisterDetailsUserID = {$userid}
|
|
WHERE
|
|
Mcu_PreregisterDetailsID = {$v['Mcu_PreregisterDetailsID']}";
|
|
//echo $query;
|
|
$rows = $this->db_onedev->query($query);
|
|
$sql = "SELECT * FROM m_sex WHERE M_SexCode = '{$v['Mcu_PreregisterDetailsM_SexCode']}' AND M_SexIsActive = 'Y'";
|
|
$sex_data = $this->db_onedev->query($sql)->row_array();
|
|
$sql_ktp = '';
|
|
if(isset($v['Mcu_PreregisterDetailsKTP']) && $v['Mcu_PreregisterDetailsKTP'] != ''){
|
|
$sql_ktp = "M_PatientM_IdTypeID = 1, M_PatientIDNumber = '{$v['Mcu_PreregisterDetailsKTP']}',";
|
|
//echo $sql_ktp;
|
|
}
|
|
$sql ="UPDATE m_patient SET
|
|
$sql_ktp
|
|
M_PatientDOB = '{$pdob}',
|
|
M_PatientM_TitleID = '{$v['Mcu_PreregisterDetailsM_TitleID']}',
|
|
M_PatientM_SexID = {$sex_data['M_SexID']},
|
|
M_PatientPrefix = '{$v['Mcu_PreregisterDetailsPatientPrefix']}',
|
|
M_PatientName = '{$v['Mcu_PreregisterDetailsPatientName']}',
|
|
M_PatientSuffix = '{$v['Mcu_PreregisterDetailsPatientSuffix']}',
|
|
M_PatientEmail = '{$v['Mcu_PreregisterDetailsEmail']}',
|
|
M_PatientHP = '{$v['Mcu_PreregisterDetailsHp']}',
|
|
M_PatientNIK = '{$v['Mcu_PreregisterDetailsNIK']}',
|
|
M_PatientJabatan = '{$v['Mcu_PreregisterDetailsJabatan']}',
|
|
M_PatientKedudukan = '{$v['Mcu_PreregisterDetailsKedudukan']}',
|
|
M_PatientLocation = '{$v['Mcu_PreregisterDetailsLocation']}',
|
|
M_PatientJob = '{$v['Mcu_PreregisterDetailsJob']}',
|
|
M_PatientM_ReligionID = '{$v['Mcu_PreregisterDetailsM_ReligionID']}'
|
|
WHERE
|
|
M_PatientID = '{$v['Mcu_PreregisterDetailsM_PatientID']}'
|
|
";
|
|
//echo $sql;
|
|
$this->db_onedev->query($sql);
|
|
|
|
$result = array(
|
|
"total" => 1 ,
|
|
"records" => $prm
|
|
);
|
|
|
|
$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_PreregisterDetailsIsActive = 'N',
|
|
Mcu_PreregisterDetailsUserID = {$userid}
|
|
WHERE
|
|
Mcu_PreregisterDetailsID = {$prm['Mcu_PreregisterDetailsID']}";
|
|
$this->db_onedev->query($query);
|
|
$result = array(
|
|
"total" => 1 ,
|
|
"records" => array('status'=>'OK')
|
|
);
|
|
|
|
$this->sys_ok($result);
|
|
exit;
|
|
}
|
|
}
|