1313 lines
44 KiB
PHP
1313 lines
44 KiB
PHP
<?php
|
|
class Registrationv3 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->db_oneklinik = $this->load->database("onedev", true);
|
|
$this->db_antrione = $this->load->database("antrione", true);
|
|
$this->load->library('ibl_encryptor');
|
|
// $this->IP_SOCKET_IO = "devone.aplikasi.web.id";
|
|
|
|
$this->IP_SOCKET_IO = "localhost";
|
|
//$one_db = "one_aditya";
|
|
}
|
|
|
|
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').'***'; }
|
|
private function _mask_dob($v) { if (!$v) return $v; $p=explode('-',$v); return (count($p)===3) ? '**-**-'.$p[2] : '****-**-**'; }
|
|
|
|
public function search_x()
|
|
{
|
|
$prm = $this->sys_input;
|
|
if (!$this->isLogin) {
|
|
$this->sys_error("Invalid Token");
|
|
exit;
|
|
}
|
|
$norm = $prm["snorm"];
|
|
$nama = str_replace("'", "\\'", $prm["name"]);
|
|
|
|
// echo $norm;
|
|
|
|
$sql_where = "WHERE M_PatientIsActive = 'Y' ";
|
|
$sql_param = array();
|
|
if ($nama != "") {
|
|
if ($sql_where != "") {
|
|
$sql_where .= " and ";
|
|
}
|
|
$sql_where .= " M_PatientName 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 100';
|
|
}
|
|
$number_limit = 100;
|
|
$number_offset = ($prm['current_page'] - 1) * $number_limit;
|
|
|
|
//echo $this->db_onedev->last_query();
|
|
$tot_count = 0;
|
|
$tot_page = 0;
|
|
|
|
|
|
$sql = "SELECT
|
|
M_PatientID,
|
|
M_PatientNoReg,
|
|
M_PatientPrefix,
|
|
M_PatientName,
|
|
M_PatientSuffix,
|
|
M_PatientHP,
|
|
M_PatientEmail,
|
|
M_PatientPOB,
|
|
M_PatientPhone,
|
|
M_PatientIDNumber,
|
|
DATE_FORMAT(M_PatientDOB,'%d-%m-%Y') as M_PatientDOB,
|
|
M_PatientNote,
|
|
M_PatientNIK,
|
|
M_PatientJabatan,
|
|
M_PatientKedudukan,
|
|
M_PatientPJ,
|
|
M_PatientLocation,
|
|
M_PatientJob,
|
|
M_PatientM_SexID,
|
|
M_SexName,
|
|
M_PatientM_TitleID,
|
|
M_TitleName,
|
|
M_PatientM_ReligionID,
|
|
M_ReligionName,
|
|
M_PatientM_IdTypeID,
|
|
M_IdTypeName,
|
|
M_PatientIDNumber,
|
|
IF(ISNULL(M_PatientSuspendID),'active','suspend' ) as status
|
|
FROM m_patient
|
|
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
|
|
LEFT JOIN m_idtype ON M_PatientM_IdTypeID = M_IdTypeID
|
|
LEFT JOIN m_patientsuspend ON M_PatientSuspendM_PatientID = M_PatientID AND M_PatientSuspendIsActive = 'Y'
|
|
$sql_where
|
|
ORDER BY M_PatientName ASC
|
|
limit 100
|
|
";
|
|
// $sql;
|
|
$query = $this->db_onedev->query($sql, $sql_param);
|
|
$rows = $query->result_array();
|
|
if ($rows) {
|
|
foreach ($rows as $k => $v) {
|
|
$rows[$k]['M_PatientName'] = stripslashes($rows[$k]['M_PatientName']);
|
|
$rows[$k]['M_PatientPOB'] = stripslashes($rows[$k]['M_PatientPOB']);
|
|
//$rows[$k]['verification_px'] = $this->add_verification_test($v['M_PatientID']);
|
|
|
|
}
|
|
}
|
|
|
|
|
|
//$this->_add_address($rows);
|
|
$result = array("total" => 1, "records" => $rows, "sql" => $this->db_onedev->last_query());
|
|
$this->sys_ok($result);
|
|
exit;
|
|
}
|
|
|
|
|
|
|
|
function getsexreg()
|
|
{
|
|
if (!$this->isLogin) {
|
|
$this->sys_error("Invalid Token");
|
|
exit;
|
|
}
|
|
$rows = [];
|
|
$rows['default_location'] = array();
|
|
|
|
$query = "SELECT M_DoctorID as id,
|
|
M_DoctorCode as code,
|
|
M_DoctorName as name,
|
|
M_DoctorMcuDefaultKlinik as is_default,
|
|
M_DoctorMcuPriceKlinik as price
|
|
FROM m_doctormcu
|
|
JOIN m_doctor ON M_DoctorMcuM_DoctorID = M_DoctorID
|
|
WHERE
|
|
M_DoctorMcuIsActive = 'Y'
|
|
";
|
|
//echo $query;
|
|
$rows['doctors'] = $this->db_onedev->query($query)->result_array();
|
|
|
|
$rows['default_doctor'] = [];
|
|
foreach ($rows['doctors'] as $key => $value) {
|
|
if($value['is_default'] == 'Y')
|
|
$rows['default_doctor'] = $value;
|
|
}
|
|
|
|
|
|
|
|
$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();
|
|
|
|
$query = "SELECT *
|
|
FROM m_branch
|
|
WHERE
|
|
M_BranchIsDefault = 'Y' AND M_BranchIsActive = 'Y'
|
|
";
|
|
//echo $query;
|
|
$branch_default = $this->db_onedev->query($query)->row_array();
|
|
|
|
if ($branch_default) {
|
|
$query = " SELECT *
|
|
FROM m_city
|
|
WHERE
|
|
M_CityIsActive = 'Y' AND M_CityID = ?
|
|
";
|
|
//echo $query;
|
|
$rows['default_location']['city_address'] = $this->db_onedev->query($query, array($branch_default['M_BranchM_CityID']))->row_array();
|
|
|
|
|
|
$query = " SELECT *
|
|
FROM m_city
|
|
WHERE
|
|
M_CityIsActive = 'Y' AND M_CityM_ProvinceID = ?
|
|
";
|
|
//echo $query;
|
|
$rows['default_location']['cities'] = $this->db_onedev->query($query, array($rows['default_location']['city_address']['M_CityM_ProvinceID']))->result_array();
|
|
|
|
$query = " SELECT *
|
|
FROM m_province
|
|
WHERE
|
|
M_ProvinceIsActive = 'Y' AND M_ProvinceID = ?
|
|
";
|
|
//echo $query;
|
|
$rows['default_location']['province_address'] = $this->db_onedev->query($query, array($rows['default_location']['city_address']['M_CityM_ProvinceID']))->row_array();
|
|
|
|
$query = " SELECT *
|
|
FROM m_province
|
|
WHERE
|
|
M_ProvinceIsActive = 'Y'
|
|
";
|
|
//echo $query;
|
|
$rows['default_location']['provinces'] = $this->db_onedev->query($query)->result_array();
|
|
|
|
$query = " SELECT *
|
|
FROM m_district
|
|
WHERE
|
|
M_DistrictIsActive = 'Y' AND M_DistrictM_CityID = ?
|
|
";
|
|
//echo $query;
|
|
$rows['default_location']['districts'] = $this->db_onedev->query($query, array($branch_default['M_BranchM_CityID']))->result_array();
|
|
|
|
$query = " SELECT *
|
|
FROM m_district
|
|
WHERE
|
|
M_DistrictIsActive = 'Y' AND M_DistrictID = ?
|
|
";
|
|
//echo $query;
|
|
$rows['default_location']['district_address'] = $this->db_onedev->query($query, array($branch_default['M_BranchM_DistrictID']))->row_array();
|
|
|
|
$query = " SELECT *
|
|
FROM m_kelurahan
|
|
WHERE
|
|
M_KelurahanIsActive = 'Y' AND M_KelurahanM_DistrictID = ?
|
|
";
|
|
//echo $query;
|
|
$rows['default_location']['kelurahans'] = $this->db_onedev->query($query, array($branch_default['M_BranchM_DistrictID']))->result_array();
|
|
|
|
$query = " SELECT *
|
|
FROM m_kelurahan
|
|
WHERE
|
|
M_KelurahanIsActive = 'Y' AND M_KelurahanID = ?
|
|
";
|
|
//echo $query;
|
|
$rows['default_location']['kelurahan_address'] = $this->db_onedev->query($query, array($branch_default['M_BranchM_KelurahanID']))->row_array();
|
|
}
|
|
|
|
|
|
|
|
$result = array(
|
|
"total" => count($rows),
|
|
"records" => $rows,
|
|
);
|
|
$this->sys_ok($result);
|
|
exit;
|
|
}
|
|
|
|
function searchcity()
|
|
{
|
|
if (!$this->isLogin) {
|
|
$this->sys_error("Invalid Token");
|
|
exit;
|
|
}
|
|
$prm = $this->sys_input;
|
|
|
|
$max_rst = 12;
|
|
$tot_count = 0;
|
|
|
|
$q = [
|
|
'search' => '%'
|
|
];
|
|
|
|
if ($prm['search'] != '') {
|
|
$q['search'] = "%{$prm['search']}%";
|
|
}
|
|
|
|
// QUERY TOTAL
|
|
$sql = "SELECT count(*) as total
|
|
FROM m_city
|
|
WHERE
|
|
M_CityName like ?
|
|
AND M_CityIsActive = 'Y'";
|
|
$query = $this->db_onedev->query($sql, $q['search']);
|
|
//echo $query;
|
|
if ($query) {
|
|
$tot_count = $query->result_array()[0]["total"];
|
|
} else {
|
|
$this->sys_error_db("m_city count", $this->db_onedev);
|
|
exit;
|
|
}
|
|
|
|
$sql = "
|
|
SELECT *
|
|
FROM m_city
|
|
WHERE
|
|
M_CityName like ?
|
|
AND M_CityIsActive = 'Y'
|
|
ORDER BY M_CityName DESC
|
|
";
|
|
$query = $this->db_onedev->query($sql, array($q['search']));
|
|
|
|
if ($query) {
|
|
$rows = $query->result_array();
|
|
//echo $this->db_onedev->last_query();
|
|
$result = array("total" => $tot_count, "records" => $rows, "total_display" => sizeof($rows));
|
|
$this->sys_ok($result);
|
|
} else {
|
|
$this->sys_error_db("m_city rows", $this->db_onedev);
|
|
exit;
|
|
}
|
|
}
|
|
|
|
function getprovinces()
|
|
{
|
|
$prm = $this->sys_input;
|
|
$query = " SELECT *
|
|
FROM m_province
|
|
WHERE
|
|
M_ProvinceIsActive = 'Y'
|
|
";
|
|
//echo $query;
|
|
$rows = $this->db_onedev->query($query)->result_array();
|
|
|
|
$result = array(
|
|
"total" => count($rows),
|
|
"records" => $rows,
|
|
);
|
|
$this->sys_ok($result);
|
|
exit;
|
|
}
|
|
|
|
function getcities()
|
|
{
|
|
$prm = $this->sys_input;
|
|
$query = " SELECT *
|
|
FROM m_city
|
|
WHERE
|
|
M_CityIsActive = 'Y' AND M_CityM_ProvinceID = ?
|
|
";
|
|
//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 getdistricts()
|
|
{
|
|
$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 getkelurahans()
|
|
{
|
|
$prm = $this->sys_input;
|
|
$query = " SELECT *
|
|
FROM m_kelurahan
|
|
WHERE
|
|
M_KelurahanIsActive = 'Y' AND M_KelurahanM_DistrictID = ?
|
|
";
|
|
//echo $query;
|
|
$rows = $this->db_onedev->query($query, array($prm['id']))->result_array();
|
|
|
|
$result = array(
|
|
"total" => count($rows),
|
|
"records" => $rows,
|
|
);
|
|
$this->sys_ok($result);
|
|
exit;
|
|
}
|
|
|
|
function save()
|
|
{
|
|
if (!$this->isLogin) {
|
|
$this->sys_error("Invalid Token");
|
|
exit;
|
|
}
|
|
$prm = $this->sys_input;
|
|
$userid = $this->sys_user["M_UserID"];
|
|
$sql = "SELECT * FROM m_patient WHERE M_PatientID = {$prm['M_PatientID']}";
|
|
$rows_before = $this->db_onedev->query($sql)->row_array();
|
|
|
|
$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;
|
|
|
|
$this->db_onedev
|
|
->set('M_PatientName', $this->_mask_name($patient_name))
|
|
->set('M_PatientName_enc', $enc->encrypt($patient_name))
|
|
->set('M_PatientName_bidx', $enc->search_bidx($patient_name))
|
|
->set('M_PatientM_TitleID', $prm['M_PatientM_TitleID'])
|
|
->set('M_PatientPrefix', $prm['M_PatientPrefix'])
|
|
->set('M_PatientSuffix', $prm['M_PatientSuffix'])
|
|
->set('M_PatientDOB', $this->_mask_dob($dob_str))
|
|
->set('M_PatientDOB_enc', $enc->encrypt($dob_str))
|
|
->set('M_PatientDOB_bidx', $enc->search_bidx($dob_str))
|
|
->set('M_PatientM_SexID', $prm['M_PatientM_SexID'])
|
|
->set('M_PatientM_ReligionID', $prm['M_PatientM_ReligionID'])
|
|
->set('M_PatientEmail', $this->_mask_email($prm['M_PatientEmail']))
|
|
->set('M_PatientEmail_enc', $enc->encrypt($prm['M_PatientEmail']))
|
|
->set('M_PatientPOB', $this->_mask_short($prm['M_PatientPOB']))
|
|
->set('M_PatientPOB_enc', $enc->encrypt($prm['M_PatientPOB']))
|
|
->set('M_PatientHP', $this->_mask_phone($prm['M_PatientHP']))
|
|
->set('M_PatientHP_enc', $enc->encrypt($prm['M_PatientHP']))
|
|
->set('M_PatientHP_bidx', $enc->search_bidx($prm['M_PatientHP']))
|
|
->set('M_PatientPhone', $this->_mask_phone($prm['M_PatientPhone']))
|
|
->set('M_PatientPhone_enc', $enc->encrypt($prm['M_PatientPhone']))
|
|
->set('M_PatientM_IdTypeID', $prm['M_PatientM_IdTypeID'])
|
|
->set('M_PatientIDNumber', $this->_mask_id($prm['M_PatientIDNumber']))
|
|
->set('M_PatientIDNumber_enc', $enc->encrypt($prm['M_PatientIDNumber']))
|
|
->set('M_PatientNIK', $prm['M_PatientNIK'])
|
|
->set('M_PatientNIK_bidx', $enc->search_bidx($prm['M_PatientNIK'] ?? ''))
|
|
->set('M_PatientNote', $prm['M_PatientNote'])
|
|
->set('M_PatientJabatan', $prm['M_PatientJabatan'])
|
|
->set('M_PatientKedudukan', $prm['M_PatientKedudukan'])
|
|
->set('M_PatientPJ', $prm['M_PatientPJ'])
|
|
->set('M_PatientLocation', $prm['M_PatientLocation'])
|
|
->set('M_PatientJob', $prm['M_PatientJob'])
|
|
->set('M_PatientUserID', $userid)
|
|
->where('M_PatientID', $prm['M_PatientID'])
|
|
->update('m_patient');
|
|
|
|
$sql = "SELECT *
|
|
FROM m_patientaddress
|
|
WHERE M_PatientAddressM_PatientID = {$prm['M_PatientID']} AND M_PatientAddressIsActive = 'Y'
|
|
ORDER BY M_PatientAddressID ASC LIMIT 1";
|
|
|
|
$d_address = $this->db_onedev->query($sql)->row_array();
|
|
$address_desc = $prm['M_PatientAddressDescription'];
|
|
|
|
$this->db_onedev
|
|
->set('M_PatientAddressM_KelurahanID', $prm['M_PatientAddressM_KelurahanID'])
|
|
->set('M_PatientAddressDescription', $this->_mask_address($address_desc))
|
|
->set('M_PatientAddressDescription_enc', $enc->encrypt($address_desc))
|
|
->where('M_PatientAddressID', $d_address['M_PatientAddressID'])
|
|
->update('m_patientaddress');
|
|
|
|
$result = array(
|
|
"total" => 1,
|
|
"records" => array('status' => 'OK')
|
|
);
|
|
$ptn = $prm;
|
|
$ptn["M_PatientDOB"] = $pdob;
|
|
$xbefore = json_encode($rows_before);
|
|
$ptn = json_encode($ptn);
|
|
/*$this->db_onedev->query("INSERT INTO one_log.log_patient (
|
|
Log_PatientCode,
|
|
Log_PatientJson,
|
|
Log_PatientJsonBefore,
|
|
Log_PatientUserID
|
|
)
|
|
VALUES(
|
|
'PATIENT.EDIT',
|
|
'{$ptn}',
|
|
'{$xbefore}',
|
|
'{$userid}'
|
|
)");*/
|
|
$this->sys_ok($result);
|
|
exit;
|
|
}
|
|
|
|
|
|
function newpatient()
|
|
{
|
|
if (!$this->isLogin) {
|
|
$this->sys_error("Invalid Token");
|
|
exit;
|
|
}
|
|
$prm = $this->sys_input;
|
|
$userid = $this->sys_user["M_UserID"];
|
|
|
|
$pdob = date('Y-m-d', strtotime($prm['M_PatientDOB']));
|
|
$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' => $this->_mask_dob($dob_str),
|
|
'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();
|
|
if ($last_id) {
|
|
$sql = "SELECT * FROM m_patient
|
|
LEFT JOIN m_branch ON M_BranchIsDefault = 'Y' AND M_BranchIsActive = 'Y'
|
|
WHERE M_PatientID = {$last_id}
|
|
LIMIT 1";
|
|
//echo $sql;
|
|
$data_patient = $this->db_onedev->query($sql)->row_array();
|
|
if ($data_patient) {
|
|
if (intval($prm['M_PatientM_IdTypeID']) == 4) {
|
|
$new_nik_varchar = "00" . $data_patient['M_BranchCode'] . str_pad($data_patient['M_PatientNoReg'], 12, "0", STR_PAD_LEFT);
|
|
$sql = "UPDATE m_patient SET M_PatientIDNumber = '{$new_nik_varchar}' WHERE M_PatientID = {$last_id}";
|
|
$this->db_onedev->query($sql);
|
|
//echo $sql;
|
|
}
|
|
}
|
|
|
|
$address_description = $prm['M_PatientAddressDescription'];
|
|
// save address
|
|
$add = [
|
|
'M_PatientAddressM_PatientID' => $last_id,
|
|
'M_PatientAddressDescription' => $this->_mask_address($address_description),
|
|
'M_PatientAddressDescription_enc' => $enc->encrypt($address_description),
|
|
'M_PatientAddressUserID' => $userid,
|
|
'M_PatientAddressRegionalCd' => $prm['M_PatientAddressRegionalCd'] ?? null,
|
|
'M_PatientAddressLocation' => $prm['M_PatientAddressLocation'] ?? null,
|
|
'M_PatientAddressCity' => $prm['M_PatientAddressCity'] ?? null,
|
|
'M_PatientAddressVillage' => $prm['M_PatientAddressVillage'] ?? null,
|
|
'M_PatientAddressDistrict' => $prm['M_PatientAddressDistrict'] ?? null,
|
|
'M_PatientAddressState' => $prm['M_PatientAddressState'] ?? null,
|
|
'M_PatientAddressCountry' => $prm['M_PatientAddressCountry'] ?? null,
|
|
'M_PatientAddressCountryCode' => $prm['M_PatientAddressCountryCode'] ?? null,
|
|
'M_PatientAddressNote' => $prm['M_PatientAddressNote'] ?? 'Utama',
|
|
];
|
|
$this->db_onedev->insert('m_patientaddress', $add);
|
|
//echo $this->db_onedev->last_query();
|
|
}
|
|
|
|
$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',
|
|
M_PatientUserID = {$userid}
|
|
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.*,
|
|
IFNULL(r.regional_nm, '') AS M_KelurahanName,
|
|
IFNULL(r.full_name, '') AS M_RegionalFullName,
|
|
IFNULL(r.pro_cd, '') AS pro_cd,
|
|
IFNULL(r.kab_cd, '') AS kab_cd,
|
|
IFNULL(r.kec_cd, '') AS kec_cd,
|
|
IFNULL(pro.regional_nm, '') AS M_ProvinceName,
|
|
IFNULL(kab.regional_nm, '') AS M_CityName,
|
|
IFNULL(kec.regional_nm, '') AS M_DistrictName,
|
|
'' AS action
|
|
FROM m_patientaddress
|
|
LEFT JOIN regional r ON M_PatientAddressRegionalCd = r.regional_cd
|
|
LEFT JOIN regional pro ON CONCAT(r.pro_cd, REPEAT('0', 8)) = pro.regional_cd
|
|
LEFT JOIN regional kab ON CONCAT(r.pro_cd, r.kab_cd, REPEAT('0', 6)) = kab.regional_cd
|
|
LEFT JOIN regional kec ON CONCAT(r.pro_cd, r.kab_cd, r.kec_cd, REPEAT('0', 3)) = kec.regional_cd
|
|
WHERE M_PatientAddressIsActive = 'Y' AND M_PatientAddressM_PatientID = ?
|
|
ORDER BY M_PatientAddressID ASC
|
|
LIMIT 1";
|
|
|
|
$address = $this->db_onedev->query($query, [$prm['id']])->row_array();
|
|
$address['M_PatientAddressDescription'] = $this->ibl_encryptor->decrypt($address['M_PatientAddressDescription_enc'] ?? '') ?: stripslashes($address['M_PatientAddressDescription'] ?? '');
|
|
unset($address['M_PatientAddressDescription_enc']);
|
|
$rows['address'] = $address;
|
|
|
|
$pro_cd = $address['pro_cd'] ?? '';
|
|
$kab_cd = $address['kab_cd'] ?? '';
|
|
$kec_cd = $address['kec_cd'] ?? '';
|
|
$regional_cd = $address['M_PatientAddressRegionalCd'] ?? '';
|
|
|
|
$rows['province_address'] = $pro_cd ? $this->db_onedev->query(
|
|
"SELECT regional_cd AS M_ProvinceID, regional_nm AS M_ProvinceName FROM regional WHERE regional_cd = ?",
|
|
[$pro_cd . str_repeat('0', 8)]
|
|
)->row_array() : [];
|
|
|
|
$rows['provinces'] = $this->db_onedev->query(
|
|
"SELECT regional_cd AS M_ProvinceID, regional_nm AS M_ProvinceName FROM regional WHERE RIGHT(regional_cd, 8) = '00000000' ORDER BY regional_nm"
|
|
)->result_array();
|
|
|
|
$rows['city_address'] = ($pro_cd && $kab_cd) ? $this->db_onedev->query(
|
|
"SELECT regional_cd AS M_CityID, regional_nm AS M_CityName FROM regional WHERE regional_cd = ?",
|
|
[$pro_cd . $kab_cd . str_repeat('0', 6)]
|
|
)->row_array() : [];
|
|
|
|
$rows['cities'] = $pro_cd ? $this->db_onedev->query(
|
|
"SELECT regional_cd AS M_CityID, regional_nm AS M_CityName FROM regional WHERE pro_cd = ? AND RIGHT(regional_cd, 8) != '00000000' AND RIGHT(regional_cd, 6) = '000000' ORDER BY regional_nm",
|
|
[$pro_cd]
|
|
)->result_array() : [];
|
|
|
|
$rows['district_address'] = ($pro_cd && $kab_cd && $kec_cd) ? $this->db_onedev->query(
|
|
"SELECT regional_cd AS M_DistrictID, regional_nm AS M_DistrictName FROM regional WHERE regional_cd = ?",
|
|
[$pro_cd . $kab_cd . $kec_cd . str_repeat('0', 3)]
|
|
)->row_array() : [];
|
|
|
|
$rows['districts'] = ($pro_cd && $kab_cd) ? $this->db_onedev->query(
|
|
"SELECT regional_cd AS M_DistrictID, regional_nm AS M_DistrictName FROM regional WHERE pro_cd = ? AND kab_cd = ? AND RIGHT(regional_cd, 6) != '000000' AND RIGHT(regional_cd, 3) = '000' ORDER BY regional_nm",
|
|
[$pro_cd, $kab_cd]
|
|
)->result_array() : [];
|
|
|
|
$rows['kelurahan_address'] = $regional_cd ? $this->db_onedev->query(
|
|
"SELECT regional_cd AS M_KelurahanID, regional_nm AS M_KelurahanName FROM regional WHERE regional_cd = ?",
|
|
[$regional_cd]
|
|
)->row_array() : [];
|
|
|
|
$rows['kelurahans'] = ($pro_cd && $kab_cd && $kec_cd) ? $this->db_onedev->query(
|
|
"SELECT regional_cd AS M_KelurahanID, regional_nm AS M_KelurahanName FROM regional WHERE pro_cd = ? AND kab_cd = ? AND kec_cd = ? AND RIGHT(regional_cd, 3) != '000' ORDER BY regional_nm",
|
|
[$pro_cd, $kab_cd, $kec_cd]
|
|
)->result_array() : [];
|
|
|
|
$this->sys_ok(["total" => count($rows), "records" => $rows]);
|
|
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;
|
|
}
|
|
}
|
|
$prm['M_PatientAddressDescription'] = str_replace("'", "\\'", $prm['M_PatientAddressDescription']);
|
|
$query = "INSERT INTO m_patientaddress (
|
|
M_PatientAddressM_PatientID,
|
|
M_PatientAddressNote,
|
|
M_PatientAddressDescription,
|
|
M_PatientAddressM_KelurahanID,
|
|
M_PatientAddressCreated,
|
|
M_PatientAddressUserID
|
|
)
|
|
VALUES(
|
|
'{$prm['M_PatientAddressM_PatientID']}',
|
|
'{$prm['M_PatientAddressNote']}',
|
|
'{$prm['M_PatientAddressDescription']}',
|
|
'{$prm['M_PatientAddressM_KelurahanID']}',
|
|
NOW(),
|
|
'{$userid}'
|
|
)
|
|
";
|
|
//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;
|
|
$prm['M_PatientAddressDescription'] = str_replace("'", "\\'", $prm['M_PatientAddressDescription']);
|
|
$sql = "SELECT * FROM m_patientaddress WHERE M_PatientAddressID = {$prm['M_PatientAddressID']}";
|
|
$rows_before = $this->db_onedev->query($sql)->row_array();
|
|
$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']}',
|
|
M_PatientAddressUserID = {$userid}
|
|
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;
|
|
$xbefore = json_encode($rows_before);
|
|
$ptn = json_encode($ptn);
|
|
/*$this->db_onedev->query("INSERT INTO one_log.log_patient (
|
|
Log_PatientCode,
|
|
Log_PatientJson,
|
|
Log_PatientJsonBefore,
|
|
Log_PatientUserID
|
|
)
|
|
VALUES(
|
|
'PATIENT.ADDR_EDIT',
|
|
'{$ptn}',
|
|
'{$xbefore}',
|
|
'{$userid}'
|
|
)");*/
|
|
//$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',
|
|
M_PatientAddressUserID = {$userid}
|
|
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;
|
|
}
|
|
|
|
public function search()
|
|
{
|
|
$prm = $this->sys_input;
|
|
|
|
$number_limit = 10;
|
|
$number_offset = (!isset($prm['current_page']) ? 1 : $prm['current_page'] - 1) * $number_limit;
|
|
|
|
$where_noreg = '';
|
|
$where_name = '';
|
|
$where_hp = '';
|
|
$where_dob = '';
|
|
$where_nik = '';
|
|
$where_snorm = '';
|
|
|
|
if (!empty($prm['noreg'])) {
|
|
$noreg = $this->db_onedev->escape_like_str($prm['noreg']);
|
|
$where_noreg = "AND M_PatientNoReg LIKE '%{$noreg}%'";
|
|
}
|
|
|
|
if (!empty($prm['snorm'])) {
|
|
$where_snorm = "AND M_PatientNoReg = '{$prm['snorm']}'";
|
|
} elseif (!empty($prm['search'])) {
|
|
$e = explode('+', $prm['search']);
|
|
|
|
if (!empty($e[0]) && mb_strlen(trim($e[0])) >= 3) {
|
|
$toks = $this->ibl_encryptor->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) $where_name = 'AND (' . implode(' AND ', $conds) . ')';
|
|
}
|
|
|
|
if (!empty($e[1]) && mb_strlen(trim($e[1])) >= 3) {
|
|
$toks = $this->ibl_encryptor->query_tokens($e[1]);
|
|
$conds = [];
|
|
foreach ($toks as $tok) {
|
|
$tok_esc = $this->db_onedev->escape_str($tok);
|
|
$conds[] = "JSON_CONTAINS(M_PatientHP_bidx, '\"$tok_esc\"')";
|
|
}
|
|
if ($conds) $where_hp = 'AND (' . implode(' AND ', $conds) . ')';
|
|
}
|
|
|
|
if (!empty($e[2]) && mb_strlen(trim($e[2])) >= 3) {
|
|
$toks = $this->ibl_encryptor->query_tokens($e[2]);
|
|
$conds = [];
|
|
foreach ($toks as $tok) {
|
|
$tok_esc = $this->db_onedev->escape_str($tok);
|
|
$conds[] = "JSON_CONTAINS(M_PatientDOB_bidx, '\"$tok_esc\"')";
|
|
}
|
|
if ($conds) $where_dob = 'AND (' . implode(' AND ', $conds) . ')';
|
|
}
|
|
|
|
if (!empty($e[3]) && mb_strlen(trim($e[3])) >= 3) {
|
|
$toks = $this->ibl_encryptor->query_tokens($e[3]);
|
|
$conds = [];
|
|
foreach ($toks as $tok) {
|
|
$tok_esc = $this->db_onedev->escape_str($tok);
|
|
$conds[] = "JSON_CONTAINS(M_PatientNIK_bidx, '\"$tok_esc\"')";
|
|
}
|
|
if ($conds) $where_nik = 'AND (' . implode(' AND ', $conds) . ')';
|
|
}
|
|
}
|
|
|
|
if (empty($prm['snorm']) && empty($prm['search']) && empty($prm['noreg'])) {
|
|
$this->sys_ok(["total" => 0, "records" => []]);
|
|
return;
|
|
}
|
|
|
|
$sql = "SELECT 'N' divider, M_PatientID, M_PatientNoReg, M_PatientPrefix, M_PatientSuffix,
|
|
concat(M_TitleName,' ',IFNULL(M_PatientPrefix,''),' ',M_PatientName,' ',IFNULL(M_PatientSuffix,'')) M_PatientNameRaw,
|
|
M_TitleID, M_TitleName, M_SexID, M_SexName,
|
|
M_PatientDOB,
|
|
'' M_PatientAddress,
|
|
M_PatientAddressID,
|
|
M_PatientAddressRegionalCd, M_PatientAddressLocation, M_PatientAddressCity,
|
|
M_PatientAddressVillage, M_PatientAddressDistrict, M_PatientAddressState,
|
|
M_PatientAddressCountry, M_PatientAddressCountryCode,
|
|
M_PatientAddressM_KelurahanID M_KelurahanID, 0 M_DistrictID, 0 M_CityID, 0 M_ProvinceID,
|
|
M_PatientM_ReligionID, IFNULL(M_ReligionName, '-') M_ReligionName,
|
|
IFNULL(M_PatientNote, '') M_PatientNote, M_PatientPhoto,
|
|
M_PatientM_IdTypeID,
|
|
M_PatientJabatan, M_PatientKedudukan, M_PatientPJ, M_PatientLocation, M_PatientJob,
|
|
IF(ISNULL(M_PatientSuspendID),'active','suspend') as status,
|
|
M_PatientName_enc, M_PatientHP_enc, M_PatientDOB_enc,
|
|
M_PatientEmail_enc, M_PatientPhone_enc, M_PatientPOB_enc,
|
|
M_PatientIDNumber_enc, M_PatientNIK_enc, M_PatientAddressDescription_enc
|
|
FROM m_patient
|
|
JOIN m_title ON M_PatientM_TitleID = M_TitleID
|
|
JOIN m_sex ON M_PatientM_SexID = M_SexID
|
|
JOIN m_patientaddress ON M_PatientAddressM_PatientID = M_PatientID AND M_PatientAddressIsActive = 'Y'
|
|
LEFT JOIN m_religion ON M_PatientM_ReligionID = M_ReligionID
|
|
LEFT JOIN m_patientsuspend ON M_PatientSuspendM_PatientID = M_PatientID AND M_PatientSuspendIsActive = 'Y'
|
|
WHERE M_PatientIsActive = 'Y' AND M_PatientSuspendID IS NULL
|
|
{$where_noreg}
|
|
{$where_snorm}
|
|
{$where_name}
|
|
{$where_hp}
|
|
{$where_dob}
|
|
{$where_nik}
|
|
GROUP BY M_PatientID
|
|
LIMIT {$number_limit} OFFSET {$number_offset}";
|
|
|
|
$query = $this->db_onedev->query($sql);
|
|
|
|
if (!$query) {
|
|
$this->sys_error_db("m_patient rows", $this->db_onedev);
|
|
return;
|
|
}
|
|
|
|
$rows = $query->result_array();
|
|
$enc = $this->ibl_encryptor;
|
|
|
|
foreach ($rows as $k => $v) {
|
|
$rows[$k]['M_PatientName'] = $enc->decrypt($v['M_PatientName_enc']) ?? $v['M_PatientNameRaw'];
|
|
$rows[$k]['M_PatientHP'] = $enc->decrypt($v['M_PatientHP_enc']) ?? '';
|
|
$rows[$k]['M_PatientEmail'] = $enc->decrypt($v['M_PatientEmail_enc']) ?? '';
|
|
$rows[$k]['M_PatientPOB'] = $enc->decrypt($v['M_PatientPOB_enc']) ?? '';
|
|
$rows[$k]['M_PatientPhone'] = $enc->decrypt($v['M_PatientPhone_enc']) ?? '';
|
|
$rows[$k]['M_PatientIDNumber'] = $enc->decrypt($v['M_PatientIDNumber_enc']) ?? '';
|
|
$rows[$k]['M_PatientNIK'] = $enc->decrypt($v['M_PatientNIK_enc']) ?? '';
|
|
$dob_dec = $enc->decrypt($v['M_PatientDOB_enc']) ?? '';
|
|
$rows[$k]['M_PatientDOB'] = $dob_dec;
|
|
$rows[$k]['dob_ina'] = $dob_dec;
|
|
$rows[$k]['M_PatientAddressDescription'] = $enc->decrypt($v['M_PatientAddressDescription_enc']) ?? '';
|
|
$rows[$k]['M_PatientAddress'] = $rows[$k]['M_PatientAddressDescription'];
|
|
|
|
foreach (array_keys($rows[$k]) as $col) {
|
|
if (substr($col, -4) === '_enc') unset($rows[$k][$col]);
|
|
}
|
|
unset($rows[$k]['M_PatientNameRaw']);
|
|
|
|
$info = $this->db_onedev->query("SELECT fn_fo_patient_visit(?) info", [$v['M_PatientID']])->row();
|
|
$rows[$k]['info'] = json_decode($info->info);
|
|
}
|
|
|
|
$this->sys_ok(["total" => 0, "records" => $rows]);
|
|
}
|
|
|
|
function calculateAge($tanggal_lahir)
|
|
{
|
|
// Ambil tanggal sekarang
|
|
$tanggal_sekarang = new DateTime();
|
|
|
|
// Ubah tanggal lahir ke objek DateTime
|
|
$tanggal_lahir = new DateTime($tanggal_lahir);
|
|
|
|
// Hitung selisih antara tanggal sekarang dan tanggal lahir
|
|
$perbedaan = $tanggal_sekarang->diff($tanggal_lahir);
|
|
|
|
// Dapatkan tahun, bulan, dan hari dari selisih
|
|
$umur_tahun = $perbedaan->y;
|
|
$umur_bulan = $perbedaan->m;
|
|
$umur_hari = $perbedaan->d;
|
|
|
|
|
|
return array($umur_tahun, $umur_bulan, $umur_hari);
|
|
}
|
|
|
|
function saveorder()
|
|
{
|
|
if (!$this->isLogin) {
|
|
$this->sys_error("Invalid Token");
|
|
exit;
|
|
}
|
|
|
|
$userid = $this->sys_user["M_UserID"];
|
|
$prm = $this->sys_input;
|
|
|
|
$exp_dob = explode("-", $prm['patient']['M_PatientDOB']);
|
|
$queueNumber = $prm['queueNumber'];
|
|
$queueID = $prm['queueID'];
|
|
|
|
list($umur_tahun, $umur_bulan, $umur_hari) = $this->calculateAge($exp_dob[2] . '-' . $exp_dob[1] . '-' . $exp_dob[0]);
|
|
|
|
$sql = "SELECT * FROM one_klinik.setting WHERE settingIsActive = 'Y' LIMIT 1";
|
|
$setting_data = $this->db_oneklinik->query($sql)->row_array();
|
|
|
|
$price = intval($prm['doctor']['price']) == 0?$setting_data['settingPriceDefault']:$prm['doctor']['price'];
|
|
|
|
$sql = "INSERT INTO one_klinik.`order`
|
|
(`orderDate`,
|
|
`orderM_PatientID`,
|
|
`orderM_DoctorID`,
|
|
`orderAge`,
|
|
`orderKeluhan`,
|
|
`orderSubtotal`,
|
|
`orderTotal`,
|
|
`orderUserID`,
|
|
`orderCreated`,
|
|
orderQueueNumber,
|
|
orderM_LocationID)
|
|
VALUES (NOW(),?,?,?,?,?,?,$userid,NOW(),?,?)";
|
|
|
|
$save_order = $this->db_oneklinik->query($sql, array(
|
|
$prm['patient']['M_PatientID'],
|
|
$prm['doctor']['id'],
|
|
$umur_tahun . ' Tahun ' . $umur_bulan . ' Bulan ' . $umur_hari . ' Hari',
|
|
$prm['keluhan'],
|
|
$price,
|
|
$price,
|
|
$queueNumber,
|
|
$setting_data['settingM_LocationID']
|
|
));
|
|
//echo $this->db_oneklinik->last_query();
|
|
if ($save_order) {
|
|
$last_id = $this->db_oneklinik->insert_id();
|
|
$sql = "INSERT INTO one_klinik.`order_status`(
|
|
orderStatusCode,
|
|
orderStatusOrderID,
|
|
orderStatusValue,
|
|
orderStatusUserID,
|
|
orderStatusCreated
|
|
)
|
|
VALUES(
|
|
'R',?,'D',?,NOW()
|
|
)";
|
|
$query = $this->db_oneklinik->query($sql, array($last_id, $userID));
|
|
if (!$query) {
|
|
$this->sys_error_db("error insert order status", $this->db_oneklinik);
|
|
exit;
|
|
}
|
|
|
|
$sql = "INSERT INTO one_klinik.`order_status`(
|
|
orderStatusCode,
|
|
orderStatusOrderID,
|
|
orderStatusValue,
|
|
orderStatusUserID,
|
|
orderStatusCreated
|
|
)
|
|
VALUES(
|
|
'SA',?,'D',?,NOW()
|
|
)";
|
|
$query = $this->db_oneklinik->query($sql, array($last_id, $userID));
|
|
if (!$query) {
|
|
$this->sys_error_db("error insert order status", $this->db_oneklinik);
|
|
exit;
|
|
}
|
|
//echo $last_id;
|
|
$sql = "SELECT * FROM one_klinik.`order` WHERE orderID = {$last_id}";
|
|
//echo $sql;
|
|
$data_order = $this->db_oneklinik->query($sql)->row_array();
|
|
if ($queueID != "0" && trim($queueNumber) != "") {
|
|
$this->done_today_by_queue_number($queueNumber, $queueID);
|
|
}
|
|
|
|
$this->sys_ok($data_order);
|
|
} else {
|
|
$this->sys_error_db("error order save", $this->db_oneklinik);
|
|
exit;
|
|
}
|
|
}
|
|
|
|
public function done_today_by_queue_number($get_queue_number, $queueID)
|
|
{
|
|
try {
|
|
// if (!$this->isLogin) {
|
|
// $this->sys_error("Invalid Token");
|
|
// exit;
|
|
// }
|
|
|
|
$prm = $this->sys_input;
|
|
// $get_queue_number = $this->uri->segment('4');
|
|
// $queueID = $this->uri->segment('5');
|
|
|
|
// check IP ADDRESS
|
|
$sql_cek_counter_ip = "select counterIsDedicated, counterID
|
|
from counter
|
|
where counterIsActive = 'Y'
|
|
AND counterIP = ?";
|
|
// echo $sql_cek_counter_ip;
|
|
|
|
$qry_cek_counter_ip = $this->db_antrione->query($sql_cek_counter_ip, [$this->input->ip_address()]);
|
|
|
|
$last_qry = $this->db_antrione->last_query();
|
|
|
|
if (!$qry_cek_counter_ip) {
|
|
$this->db_antrione->trans_rollback();
|
|
$error = $this->db_antrione->error()["message"];
|
|
$this->sys_error_db($error, $this->db_antrione);
|
|
exit;
|
|
}
|
|
|
|
$data_cek_counter_ip = $qry_cek_counter_ip->result_array();
|
|
|
|
if (count($data_cek_counter_ip) > 0) {
|
|
// call sp_done(?,?)
|
|
|
|
$counterID = $data_cek_counter_ip[0]['counterID'];
|
|
$sql_sp_done = "call sp_done(?,?,?)";
|
|
$qry_call_sp = $this->db_antrione->query($sql_sp_done, [$get_queue_number, $counterID, '']);
|
|
|
|
if (!$qry_call_sp) {
|
|
$this->db_antrione->trans_rollback();
|
|
$error = $this->db_antrione->error()["message"];
|
|
$this->sys_error_db($error, $this->db_antrione);
|
|
exit;
|
|
}
|
|
$this->clean_mysqli_connection($this->db_antrione->conn_id);
|
|
|
|
if ($qry_call_sp->result_array()[0]['status'] == "ERR") {
|
|
echo json_encode(array(
|
|
'status' => $qry_call_sp->result_array()[0]['status'],
|
|
'message' => $qry_call_sp->result_array()[0]['message']
|
|
));
|
|
} else {
|
|
$sql_get_sID = "SELECT queueServiceID as serviceID,
|
|
queueCounterID as counterID,
|
|
serviceIsConsultDoctor
|
|
FROM queue
|
|
left join service
|
|
ON queueServiceID = ServiceID
|
|
AND ServiceIsActive = 'Y'
|
|
WHERE queueID = ?";
|
|
$qry_get_sID = $this->db_antrione->query($sql_get_sID, [$queueID]);
|
|
|
|
$last_qry = $this->db_antrione->last_query();
|
|
|
|
if (!$qry_get_sID) {
|
|
$error = $this->db_antrione->error()["message"];
|
|
$this->sys_error_db($error, $this->db_antrione);
|
|
exit;
|
|
}
|
|
|
|
$data = $qry_get_sID->row_array();
|
|
$serviceID = $data['serviceID'];
|
|
$counterID = $data['counterID'];
|
|
$serviceIsConsultDoctor = $data['serviceIsConsultDoctor'];
|
|
|
|
// check jk serviceIsConsultDoctor Y mk antrian konsul dokter
|
|
|
|
if ($serviceIsConsultDoctor == 'Y') {
|
|
file_get_contents("http://" . $this->IP_SOCKET_IO . ":9099/broadcast/done.kd.$serviceID.$counterID");
|
|
} else {
|
|
file_get_contents("http://" . $this->IP_SOCKET_IO . ":9099/broadcast/done.fo.$serviceID.$counterID");
|
|
}
|
|
|
|
return array(
|
|
'status' => $qry_call_sp->result_array()[0]['status'],
|
|
'message' => $qry_call_sp->result_array()[0]['message'],
|
|
);
|
|
}
|
|
} else {
|
|
return
|
|
array(
|
|
array(
|
|
'status' => 'ERR',
|
|
'message' => 'Invalid IP address ' . $this->input->ip_address()
|
|
)
|
|
);
|
|
}
|
|
} catch (Exception $exc) {
|
|
$message = $exc->getMessage();
|
|
$this->sys_error($message);
|
|
exit;
|
|
}
|
|
}
|
|
|
|
function searchregion()
|
|
{
|
|
if (!$this->isLogin) {
|
|
$this->sys_error("Invalid Token");
|
|
exit;
|
|
}
|
|
$prm = $this->sys_input;
|
|
$search = $prm['search'];
|
|
|
|
$sql = "SELECT
|
|
r.regional_cd,
|
|
r.regional_cd AS id,
|
|
r.regional_nm,
|
|
r.full_name AS text_nm,
|
|
r.pro_cd, IFNULL(pro.regional_nm,'') AS pro_nm,
|
|
r.kab_cd, IFNULL(kab.regional_nm,'') AS kab_nm,
|
|
r.kec_cd, IFNULL(kec.regional_nm,'') AS kec_nm,
|
|
r.kel_cd, IFNULL(kel.regional_nm,'') AS kel_nm,
|
|
r.status_cd, r.old_nm
|
|
FROM regional r
|
|
LEFT JOIN regional pro ON CONCAT(r.pro_cd, REPEAT('0', 8)) = pro.regional_cd
|
|
LEFT JOIN regional kab ON CONCAT(r.pro_cd, r.kab_cd, REPEAT('0', 6)) = kab.regional_cd
|
|
LEFT JOIN regional kec ON CONCAT(r.pro_cd, r.kab_cd, r.kec_cd, REPEAT('0', 3)) = kec.regional_cd
|
|
LEFT JOIN regional kel ON CONCAT(r.pro_cd, r.kab_cd, r.kec_cd, r.kel_cd) = kel.regional_cd
|
|
WHERE
|
|
r.full_name LIKE CONCAT('%','{$search}','%')
|
|
LIMIT 100
|
|
";
|
|
|
|
$qry = $this->db_onedev->query($sql);
|
|
|
|
if (!$qry) {
|
|
$this->sys_error_db("search wilayah select error", $this->db_onedev);
|
|
exit;
|
|
}
|
|
|
|
$rows = $qry->result_array();
|
|
|
|
$result = array(
|
|
"records" => $rows,
|
|
"sql" => $this->db_onedev->last_query()
|
|
);
|
|
|
|
$this->sys_ok($result);
|
|
exit;
|
|
}
|
|
|
|
function search_countries()
|
|
{
|
|
if (!$this->isLogin) {
|
|
$this->sys_error("Invalid Token");
|
|
exit;
|
|
}
|
|
$prm = $this->sys_input;
|
|
$search = $prm['search'];
|
|
|
|
if (!$search || $search == '') {
|
|
$search = 'Indonesia';
|
|
}
|
|
|
|
$sql = "SELECT * FROM terminology WHERE attribute_path = 'Address.country' AND display LIKE '%$search%' ORDER BY display ASC LIMIT 20";
|
|
$query = $this->db_onedev->query($sql);
|
|
$rows = $query->result_array();
|
|
$result = array("records" => $rows);
|
|
$this->sys_ok($result);
|
|
exit;
|
|
}
|
|
|
|
function getpoli()
|
|
{
|
|
if (!$this->isLogin) {
|
|
$this->sys_error("Invalid Token");
|
|
exit;
|
|
}
|
|
|
|
$sql = "SELECT
|
|
M_ClinicUnitID AS id,
|
|
M_ClinicUnitCode AS code,
|
|
M_ClinicUnitName AS name,
|
|
M_ClinicUnitDescription AS description,
|
|
M_ClinicUnitSatusehatLocationID AS satusehat_location_id
|
|
FROM one_klinik.m_clinic_unit
|
|
WHERE M_ClinicUnitIsActive = 'Y'
|
|
ORDER BY M_ClinicUnitID ASC";
|
|
|
|
$query = $this->db_oneklinik->query($sql);
|
|
if (!$query) {
|
|
$this->sys_error_db("getpoli error", $this->db_oneklinik);
|
|
exit;
|
|
}
|
|
$rows = $query->result_array();
|
|
$this->sys_ok(array("records" => $rows));
|
|
exit;
|
|
}
|
|
}
|