Files
BE_CPONE/application/controllers/cpone/mcuoffline/Preregisterv3.php
2026-05-05 14:43:57 +07:00

1507 lines
44 KiB
PHP

<?php
use SebastianBergmann\Environment\Console;
class Preregisterv3 extends MY_Controller
{
var $db;
public function __construct()
{
parent::__construct();
// $this->db = $this->load->database("cpone", true);
}
public function index()
{
// $cek = $this->db->query("select database() as current_db")->result();
// print_r($cek);
echo "PATIENT API";
}
function getmgmmcu()
{
try {
if (!$this->isLogin) {
$this->sys_error("Invalid Token");
exit;
}
$prm = $this->sys_input;
$sql = "SELECT Mgm_McuID,
CONCAT(Mgm_McuLabel,' ', '[', Mgm_McuNumber, ']') as mcuName,
DATE_FORMAT(Mgm_McuStartDate, '%d-%m-%Y') as Mgm_McuStartDate,
DATE_FORMAT(Mgm_McuEndDate, '%d-%m-%Y') as Mgm_McuEndDate,
Mgm_McuFlagRelasiBayarSendiri,
Mgm_McuBisaTambahPemeriksaan,
Mgm_McuLabel,
Mgm_McuNumber,
Mgm_McuNumberNational,
Mgm_McuNote,
Mgm_McuCorporateID
FROM mgm_mcu
WHERE Mgm_McuIsActive = 'Y'";
$qry = $this->db->query($sql);
if ($qry) {
$rows = $qry->result_array();
} else {
$this->sys_error_db("mcu select error", $this->db);
exit;
}
$result = array(
"records" => $rows,
"sql" => $this->db->last_query()
);
$this->sys_ok($result);
} catch (Exception $exc) {
$message = $exc->getMessage();
$this->sys_error($message);
}
}
function cekKTP($nik, $tanggal, $bulan, $tahun)
{
if (strlen($nik) != 16) {
return false;
}
$d = substr($nik, 6, 2);
$m = substr($nik, 8, 2);
$y = substr($nik, 10, 2);
//jika tahun full, ambil 2 digit terakhir
if (strlen($tahun == 4)) {
$tahun = substr($tahun, 2, 2);
}
if (intval($d) > 40) {
//Wanita
$d = intval($d) - 40;
}
if ($tanggal / $d != 1) {
return false;
}
if ($bulan / $m != 1) {
return false;
}
if ($tahun / $y != 1) {
return false;
}
//setelah berhasil melewati rintangan, berarti nomornya valid (tidak 100% valid)
return true;
}
function savecsv()
{
try {
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);
// exit;
$batchSize = 500; // Define the batch size
// Split the array into chunks of 250 records
$dataChunks = array_chunk($datas, $batchSize);
// Loop through each chunk and insert the batch
foreach ($dataChunks as $batchData) {
$insertData = [];
$sql = "INSERT INTO cpone_log.log_xls(
Mgm_McuID,
trx_date,
json,
userid
) VALUES(?,NOW(),?,?)";
$save_log = $this->db->query($sql,array(
$prm['xid'],
json_encode($batchData),
$userid
));
}
$exist_patients_arr = [];
$exist_pat = [];
foreach ($datas as $k => $v) {
$timestamp = strtotime($v['TANGGAL_LAHIR']);
$pdob = date('Y-m-d', $timestamp);
$v['NAMA'] = trim(str_replace("'", "\\'", $v['NAMA']));
$datas[$k]['NAMA'] = trim(str_replace("'", "\\'", $v['NAMA']));
$datas[$k]['LOKASI'] = trim(str_replace("'", "\\'", $v['LOKASI']));
$datas[$k]['DEPARTEMENT'] = trim(str_replace("'", "\\'", $v['DEPARTEMENT']));
$datas[$k]['DIVISI'] = trim(str_replace("'", "\\'", $v['DIVISI']));
$datas[$k]['JOB'] = trim(str_replace("'", "\\'", $v['JOB']));
$datas[$k]['POSISI'] = trim(str_replace("'", "\\'", $v['POSISI']));
$idxxxist = $v['NAMA'].$pdob.$v['NIP'];
if (in_array($idxxxist, $exist_patients_arr))
$exist_pat[] = $idxxxist;
else
$exist_patients_arr[] = $idxxxist;
}
// exit;
if(count($exist_pat) > 0){
$dt_error = join("</br>",$exist_pat);
$this->sys_error("Ada data pasien yang sama : ".$dt_error );
exit;
}
// bisa upload file excel beberapa kali
// $sql = "UPDATE mcu_preregister_patients SET Mcu_PreregisterPatientsIsActive = 'N' WHERE Mcu_PreregisterPatientsMgm_McuID = '{$prm['xid']}'";
// $this->db->query($sql);
//echo $sql;
$this->db->trans_begin();
foreach ($datas as $k => $v) {
$timestamp = strtotime($v['TANGGAL_LAHIR']);
$pdob = date('Y-m-d', $timestamp);
// $arrDate = explode('-', $pdob);
// $year = $arrDate[0];
// $month = $arrDate[1];
// $day = $arrDate[2];
// print_r($year);
// print_r($month);
// print_r($day);
// $cekPatientKTP = $this->cekKTP($v['KTP'], $day, $month, $year);
// print_r($cekPatientKTP);
// if ($cekPatientKTP) {
// print_r("benar");
// exit;
// } else {
// print_r("salah");
// exit;
// }
// exit;
$v['NAMA'] = str_replace("'", "\\'", $v['NAMA']);
$patient_id = 0;
if ($v['PID'] != '') {
$sql = "SELECT *
FROM m_patient
WHERE M_PatientNoReg = '{$v['PID']}' LIMIT 1";
$query = $this->db->query($sql);
if(!$query){
$last_qry = $this->db->last_query();
$this->db->trans_rollback();
$this->sys_error("select m_patient : ".$last_qry);
exit;
}
$exist_r = $query->row_array();
if ($exist_r) {
$patient_id = $exist_r["M_PatientID"];
$v['NAMA'] = addslashes($exist_r["M_PatientName"]);
$pdob = date('Y-m-d', strtotime($exist_r['M_PatientDOB']));
$title_id = $exist_r["M_PatientM_TitleID"];
$sex_id = $exist_r["M_PatientGender"];
$religion_id = $exist_r["M_PatientReligionCode"];
$v['NIK'] = $v['NIK'] ? $v['NIK'] : $exist_r["M_PatientNIK"];
$v['EMAIL'] = $v['EMAIL'] ? $v['EMAIL'] : $exist_r["M_PatientEmail"];
$v['HP'] = $v['HP'] ? $v['HP'] : $exist_r["M_PatientHP"];
$v['JOB'] = $v['JOB'] ? addslashes($v['JOB']) : addslashes($exist_r["M_PatientJob"]);
$v['POSISI'] = $v['POSISI'] ? addslashes($v['POSISI']) : addslashes($exist_r["M_PatientPosisi"]);
$v['DIVISI'] = $v['DIVISI'] ? addslashes($v['DIVISI']) : addslashes($exist_r["M_PatientDivisi"]);
$v['DEPARTEMENT'] = $v['DEPARTEMENT'] ? addslashes($v['DEPARTEMENT']) : addslashes($exist_r["M_PatientDepartement"]);
$v['LOKASI'] = $v['LOKASI'] ? addslashes($v['LOKASI']) : addslashes($exist_r["M_PatientLocation"]);
$v['JENIS_KELAMIN'] = $exist_r["M_PatientGender"] == 'male' ? 'L' : 'P';
}
// echo $sql;
}
if ($v['KTP'] != '') {
$sql = "SELECT *
FROM m_patient
WHERE
M_PatientIdentifierCode = 'NNIDN' AND
M_PatientIdentifierValue = '{$v['KTP']}' AND
M_PatientIsActive = 'Y' LIMIT 1";
$query = $this->db->query($sql);
if(!$query){
$last_qry = $this->db->last_query();
$this->db->trans_rollback();
$this->sys_error("select m_patient : ".$last_qry);
exit;
}
$exist_r = $query->row_array();
if ($exist_r) {
$patient_id = $exist_r["M_PatientID"];
$v['NAMA'] = $exist_r["M_PatientName"];
//$pdob = date('Y-m-d',strtotime($exist_r['M_PatientDOB']));
$title_id = $exist_r["M_PatientM_TitleID"];
$v['EMAIL'] = $v['EMAIL'] ? $v['EMAIL'] : $exist_r["M_PatientEmail"];
$v['JENIS_KELAMIN'] = $v['JENIS_KELAMIN'] ? $v['JENIS_KELAMIN'] : 'L';
$v['HP'] = $v['HP'] ? $v['HP'] : $exist_r["M_PatientHP"];
$v['JOB'] = $v['JOB'] ? $v['JOB'] : $exist_r["M_PatientJob"];
$v['POSISI'] = $v['POSISI'] ? $v['POSISI'] : $exist_r["M_PatientPosisi"];
$v['DIVISI'] = $v['DIVISI'] ? $v['DIVISI'] : $exist_r["M_PatientDivisi"];
$v['LOKASI'] = $v['LOKASI'] ? addslashes($v['LOKASI']) : addslashes($exist_r["M_PatientLocation"]);
$v['DEPARTEMENT'] = $v['DEPARTEMENT'] ? $v['DEPARTEMENT'] : $exist_r["M_PatientDepartement"];
}
//echo $sql;
}
$title_id = 0;
$gender = "";
//$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->query($sql)->row()->M_TitleID;
if (TRIM($v['JENIS_KELAMIN']) == 'L') {
$title_id = 1;
$gender = "male";
} else {
$title_id = 3;
$gender = "female";
}
$sql_corporate = "SELECT CorporateID, CorporateCode
FROM corporate
WHERE CorporateIsActive = 'Y' AND CorporateID = '{$prm['corporateID']}' LIMIT 1";
$qry_corporate = $this->db->query($sql_corporate);
if ($qry_corporate) {
$rowcor = $qry_corporate->row_array();
} else {
$last_qry = $this->db->last_query();
$this->db->trans_rollback();
$this->sys_error("select corporate : ".$last_qry);
exit;
}
$v['NAMA'] = trim(str_replace("'", "\\'", $v['NAMA']));
$v['NAMA'] = addslashes($v['NAMA']);
$sql_pre = "SELECT * FROM mcu_preregister_patients WHERE (
Mcu_PreregisterPatientsPatientName = '{$v['NAMA']}' AND
Mcu_PreregisterPatientsDOB = '{$pdob}' AND
Mcu_PreregisterPatientsNIP = '{$v['NIP']}'
) AND
Mcu_PreregisterPatientsMgm_McuID = '{$prm['xid']}' AND
Mcu_PreregisterPatientsIsActive = 'Y' LIMIT 1";
$qry_pre = $this->db->query($sql_pre);
if(!$qry_pre){
$last_qry = $this->db->last_query();
$this->db->trans_rollback();
$this->sys_error("select mcu_preregister_patients : ".$last_qry);
exit;
}
$exist_r = $qry_pre->result_array();
if (count($exist_r) == 0) {
$query = " INSERT INTO mcu_preregister_patients (
Mcu_PreregisterPatientsMgm_McuID,
Mcu_PreregisterPatientsCorporateCode,
Mcu_PreregisterPatientsNIP,
Mcu_PreregisterPatientsKTP,
Mcu_PreregisterPatientsM_PatientID,
Mcu_PreregisterPatientsM_TitleID,
Mcu_PreregisterPatientsPatientName,
Mcu_PreregisterPatientsGender,
Mcu_PreregisterPatientsDOB,
Mcu_PreregisterPatientsJob,
Mcu_PreregisterPatientsEmail,
Mcu_PreregisterPatientsHp,
Mcu_PreregisterPatientsPosisi,
Mcu_PreregisterPatientsDivisi,
Mcu_PreregisterPatientsLocation,
Mcu_PreregisterPatientsDepartment,
Mcu_PreregisterPatientsOrders,
Mcu_PreregisterPatientsCreated,
Mcu_PreregisterPatientsUserID
)
VALUES(
'{$prm['xid']}',
'{$rowcor["CorporateCode"]}',
'{$v['NIP']}',
'{$v['KTP']}',
'{$patient_id}',
'{$title_id}',
'{$v['NAMA']}',
'{$gender}',
'{$pdob}',
'{$v['JOB']}',
'{$v['EMAIL']}',
'{$v['HP']}',
'{$v['POSISI']}',
'{$v['DIVISI']}',
'{$v['LOKASI']}',
'{$v['DEPARTEMENT']}',
'{$v['PEMERIKSAAN']}',
NOW(),
{$userid}
)";
// echo $query;
// exit;
$rows = $this->db->query($query);
if(!$rows){
$last_qry = $this->db->last_query();
$this->db->trans_rollback();
$this->sys_error("insert mcu_preregister_patients : ".$last_qry);
exit;
}
if ($rows) {
$last_id_x = $this->db->insert_id();
if (!empty($v['TANGGAL_MCU'])) {
$mcutime = strtotime($v['TANGGAL_MCU']);
$mcudate = date('Y-m-d', $mcutime);
$sqlmcudate = "INSERT INTO mcu_preregister_date (
Mcu_PreregisterDateMcu_PreregisterPatientsID,
Mcu_PreregisterDateCheckinSchedule,
Mcu_PreregisterDateCreated,
Mcu_PreregisterDateCreatedUserID
) VALUES (?,?,NOW(),?)";
$quemcudate = $this->db->query($sqlmcudate, [
$last_id_x, $mcudate, $userid
]);
if (!$quemcudate) {
$last_qry = $this->db->last_query();
$this->db->trans_rollback();
$this->sys_error("failed insert mcu_preregister_date : ".$last_qry);
exit;
}
}
if ($patient_id == 0) {
$sql = "SELECT *
FROM m_patient
WHERE
M_PatientName = '{$v['NAMA']}' AND
M_PatientDOB = '{$pdob}' AND
M_PatientNIP = '{$v['NIP']}' AND
M_PatientIsActive = 'Y' LIMIT 1";
$query = $this->db->query($sql);
if(!$query){
$last_qry = $this->db->last_query();
$this->db->trans_rollback();
$this->sys_error("select m_patient : ".$last_qry);
exit;
}
$exist_r = $query->row_array();
if ($exist_r) {
$patient_id = $exist_r["M_PatientID"];
}
//echo $sql;
}
$sql_cor = "SELECT *
FROM corporate
WHERE
CorporateID = '{$prm['corporateID']}' AND
CorporateIsActive = 'Y' LIMIT 1";
$qry_cor = $this->db->query($sql_cor);
if(!$qry_cor){
$last_qry = $this->db->last_query();
$this->db->trans_rollback();
$this->sys_error("select corporate : ".$last_qry);
exit;
}
$qry_cor = $qry_cor->row_array();
// print_r($patient_id);
// exit;
$corporate_id = 0;
if ($v['CORPORATE'] == '') {
$corporate_id = $prm['corporateID'];
} else {
$sql_cor = "SELECT *
FROM corporate
WHERE
CorporateCode = '{$v['CORPORATE']}' AND
CorporateIsActive = 'Y' LIMIT 1";
$query = $this->db->query($sql_cor);
if(!$query){
$last_qry = $this->db->last_query();
$this->db->trans_rollback();
$this->sys_error("select corporate : ".$last_qry);
exit;
}
$rst_corporate = $query->row_array();
$corporate_id = $rst_corporate['CorporateID'];
}
//echo $patient_id;
if ($patient_id == 0) {
//echo 'insert new patient';
//$pdob = date('Y-m-d',strtotime($prm['Mcu_PreregisterDetailsDOB']));
$sql = "INSERT INTO m_patient (
M_PatientRegisteredByCorporateID,
M_PatientNoReg,
M_PatientName,
M_PatientGender,
M_PatientM_TitleID,
M_PatientDOB,
M_PatientIdentifierValue,
M_PatientNIP,
M_PatientJob,
M_PatientPosisi,
M_PatientDivisi,
M_PatientLocation,
M_PatientDepartement,
M_PatientHP,
M_PatientEmail,
M_PatientAddress,
M_PatientAddressRegionalCd,
M_PatientAddressCity,
M_PatientAddressRT,
M_PatientAddressRW,
M_PatientAddressVillage,
M_PatientAddressDistrict,
M_PatientAddressState,
M_PatientAddressCountry,
M_PatientCreatedUserID
)
VALUES(
'{$corporate_id}',
`fn_numbering_cpone`('P'),
'{$v["NAMA"]}',
'{$gender}',
{$title_id},
'{$pdob}',
'{$v['KTP']}',
'{$v['NIP']}',
'{$v['JOB']}',
'{$v['POSISI']}',
'{$v['DIVISI']}',
'{$v['LOKASI']}',
'{$v['DEPARTEMENT']}',
'{$v['HP']}',
'{$v['EMAIL']}',
'{$qry_cor['CorporateAddress']}',
'{$qry_cor['CorporateAddressRegionalCd']}',
'{$qry_cor['CorporateAddressCity']}',
'{$qry_cor['CorporateAddressRT']}',
'{$qry_cor['CorporateAddressRW']}',
'{$qry_cor['CorporateAddressVillage']}',
'{$qry_cor['CorporateAddressDistrict']}',
'{$qry_cor['CorporateAddressState']}',
'{$qry_cor['CorporateAddressCountry']}',
'{$userid}'
)";
// echo $sql;
// exit;
$query = $this->db->query($sql);
if(!$query){
$last_qry = $this->db->last_query();
$this->db->trans_rollback();
$this->sys_error("insert m_patient : ".$last_qry);
exit;
}
$patient_id = $this->db->insert_id();
} else {
//echo 'masuk';
$data_update_patient = array(
'M_PatientDOB' => $pdob
);
if ($v['JENIS_KELAMIN'] == 'L')
$data_update_patient['M_PatientM_TitleID'] = 1;
else
$data_update_patient['M_PatientM_TitleID'] = 3;
if ($prm['corporateID'] != '')
$data_update_patient['M_PatientRegisteredByCorporateID'] = $prm['corporateID'];
if ($v['EMAIL'] != '')
$data_update_patient['M_PatientEmail'] = $v['EMAIL'];
if ($v['HP'] != '')
$data_update_patient['M_PatientHP'] = $v['HP'];
if ($v['JOB'] != '')
$data_update_patient['M_PatientJob'] = $v['JOB'];
if ($v['POSISI'] != '')
$data_update_patient['M_PatientPosisi'] = $v['POSISI'];
if ($v['DIVISI'] != '')
$data_update_patient['M_PatientDivisi'] = $v['DIVISI'];
if ($v['LOKASI'] != '')
$data_update_patient['M_PatientLocation'] = $v['LOKASI'];
if ($v['DEPARTEMENT'] != '')
$data_update_patient['M_PatientDepartement'] = $v['DEPARTEMENT'];
if ($qry_cor['CorporateAddress'] != '')
$data_update_patient['M_PatientAddress'] = $qry_cor['CorporateAddress'];
if ($qry_cor['CorporateAddressRegionalCd'] != '')
$data_update_patient['M_PatientAddressRegionalCd'] = $qry_cor['CorporateAddressRegionalCd'];
if ($qry_cor['CorporateAddressCity'] != '')
$data_update_patient['M_PatientAddressCity'] = $qry_cor['CorporateAddressCity'];
if ($qry_cor['CorporateAddressRT'] != '')
$data_update_patient['M_PatientAddressRT'] = $qry_cor['CorporateAddressRT'];
if ($qry_cor['CorporateAddressRW'] != '')
$data_update_patient['M_PatientAddressRW'] = $qry_cor['CorporateAddressRW'];
if ($qry_cor['CorporateAddressVillage'] != '')
$data_update_patient['M_PatientAddressVillage'] = $qry_cor['CorporateAddressVillage'];
if ($qry_cor['CorporateAddressDistrict'] != '')
$data_update_patient['M_PatientAddressDistrict'] = $qry_cor['CorporateAddressDistrict'];
if ($qry_cor['CorporateAddressState'] != '')
$data_update_patient['M_PatientAddressState'] = $qry_cor['CorporateAddressState'];
if ($qry_cor['CorporateAddressCountry'] != '')
$data_update_patient['M_PatientAddressCountry'] = $qry_cor['CorporateAddressCountry'];
$this->db->where('M_PatientID', $patient_id);
$this->db->update('m_patient', $data_update_patient);
//echo $this->db->last_query();
}
$sql = "UPDATE mcu_preregister_patients SET Mcu_PreregisterPatientsM_PatientID = {$patient_id}
WHERE Mcu_PreregisterPatientsID = {$last_id_x}";
$query = $this->db->query($sql);
if(!$query){
$last_qry = $this->db->last_query();
$this->db->trans_rollback();
$this->sys_error("update mcu_preregister_patients : ".$last_qry);
exit;
}
$qry_sync_patient = $this->db->query(
"CALL cpone.sp_upsert_mcu_patient_by_preregister_id(?)",
array($last_id_x)
);
if (!$qry_sync_patient) {
$last_qry = $this->db->last_query();
$this->db->trans_rollback();
$this->sys_error("call sp_upsert_mcu_patient_by_preregister_id : " . $last_qry);
exit;
}
if (isset($this->db->conn_id) && $this->db->conn_id instanceof mysqli) {
while ($this->db->conn_id->more_results() && $this->db->conn_id->next_result()) {
$dummyResult = $this->db->conn_id->store_result();
if ($dummyResult instanceof mysqli_result) {
$dummyResult->free();
}
}
}
}
}
}
$qry_sync_project = $this->db->query(
"CALL cpone.sp_upsert_mcu_project_by_mgm_mcuid(?)",
array(intval($prm['xid']))
);
if (!$qry_sync_project) {
$last_qry = $this->db->last_query();
$this->db->trans_rollback();
$this->sys_error("call sp_upsert_mcu_project_by_mgm_mcuid : " . $last_qry);
exit;
}
if (isset($this->db->conn_id) && $this->db->conn_id instanceof mysqli) {
while ($this->db->conn_id->more_results() && $this->db->conn_id->next_result()) {
$dummyResult = $this->db->conn_id->store_result();
if ($dummyResult instanceof mysqli_result) {
$dummyResult->free();
}
}
}
if ($this->db->trans_status() === FALSE) {
$this->db->trans_rollback();
$this->sys_error("Transaction Failed");
exit;
} else {
$this->db->trans_commit();
}
$result = array(
"total" => 1,
"records" => array('status' => 'OK')
);
$this->sys_ok($result);
exit;
} catch (Exception $exc) {
$message = $exc->getMessage();
$this->sys_error($message);
}
}
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->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;
}
public function search()
{
$prm = $this->sys_input;
if (!$this->isLogin) {
$this->sys_error("Invalid Token");
exit;
}
$search = $prm["search"];
$nama = $prm["name"];
// echo $norm;
$sql_where = " ";
$sql_param = array();
if ($search != "") {
$sql_where = " AND ( Mcu_PreregisterPatientsKTP like CONCAT('%','{$search}','%') OR Mcu_PreregisterPatientsPatientName like CONCAT('%','{$search}','%')) ";
//$sql_param[] = "%$search%";
}
$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
WHERE
Mcu_PreregisterPatientsMgm_McuID = {$prm['mgm_mcuid']} AND
Mcu_PreregisterPatientsIsActive = 'Y'
$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_PreregisterPatientsDOB, '%d-%m-%Y') as dob
FROM mcu_preregister_patients
WHERE
Mcu_PreregisterPatientsMgm_McuID = {$prm['mgm_mcuid']} AND Mcu_PreregisterPatientsIsActive = 'Y'
$sql_where
ORDER BY Mcu_PreregisterPatientsPatientName ASC
limit $number_limit offset $number_offset
";
//echo $sql;
$query = $this->db_onedev->query($sql);
$rows = $query->result_array();
//$this->_add_address($rows);
$result = array("total" => $tot_page, "records" => $rows);
$this->sys_ok($result);
exit;
}
function getsexreg()
{
if (!$this->isLogin) {
$this->sys_error("Invalid Token");
exit;
}
$rows = [];
$query = " SELECT *
FROM m_title
WHERE
M_TitleIsActive = 'Y'
";
//echo $query;
$rows['titles'] = $this->db_onedev->query($query)->result_array();
$query = " SELECT *
FROM m_sex
WHERE
M_SexIsActive = 'Y'
";
//echo $query;
$rows['sexes'] = $this->db_onedev->query($query)->result_array();
$query = " SELECT *
FROM m_religion
WHERE
M_ReligionIsActive = 'Y'
";
//echo $query;
$rows['religions'] = $this->db_onedev->query($query)->result_array();
$query = " SELECT *
FROM m_idtype
WHERE
M_IdTypeIsActive = 'Y'
";
//echo $query;
$rows['kartuidentitass'] = $this->db_onedev->query($query)->result_array();
$result = array(
"total" => count($rows),
"records" => $rows,
);
$this->sys_ok($result);
exit;
}
function gotoreg()
{
if (!$this->isLogin) {
$this->sys_error("Invalid Token");
exit;
}
$userid = $this->sys_user["M_UserID"];
$prm = $this->sys_input;
$new_status = "Y";
$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 getkelurahan()
{
$prm = $this->sys_input;
$query = " SELECT *
FROM m_kelurahan
WHERE
M_KelurahanIsActive = 'Y' AND M_KelurahanM_DistrictID = ?
";
//echo $query;
$rows = $this->db_onedev->query($query, array($prm['id']))->result_array();
$result = array(
"total" => count($rows),
"records" => $rows,
);
$this->sys_ok($result);
exit;
}
function save()
{
if (!$this->isLogin) {
$this->sys_error("Invalid Token");
exit;
}
$userid = $this->sys_user["M_UserID"];
$prm = $this->sys_input;
$datas = $prm['data'];
//print_r($prm);
// $sql = "UPDATE mcu_preregister_patients SET Mcu_PreregisterDetailsIsActive = 'N' WHERE Mcu_PreregisterDetailsMcuOfflinePrepareID = '{$prm['xid']}'";
// $this->db_onedev->query($sql);
//echo $sql;
//unset($datas[0]);
$sql = "SELECT *
FROM mcu_offline_prepare
JOIN m_mou ON McuOfflinePrepareM_MouDefaultID = M_MouID
WHERE
McuOfflinePrepareID = {$prm['xid']}";
$data_prepare = $this->db_onedev->query($sql)->row_array();
$default_agreement_code = $data_prepare['M_MouNumber'];
$default_tests = $data_prepare['McuOfflinePrepareTests'];
foreach ($datas as $k => $v) {
$agreement = $v['AGREEMENT'];
$tests = $v['PEMERIKSAAN'];
if ($agreement == '') {
$agreement = $default_agreement_code;
}
if ($tests == '') {
$tests = $default_tests;
}
$xdate = substr($v['TANGGAL_LAHIR'], 0, 2);
$xmonth = substr($v['TANGGAL_LAHIR'], 3, 2);
$xyear = substr($v['TANGGAL_LAHIR'], 6, 4);
$tgl_lahir = $xdate . '-' . $xmonth . '-' . $xyear;
$pdob = date('Y-m-d', strtotime($tgl_lahir));
$v['NAMA'] = str_replace("'", "\\'", $v['NAMA']);
$v['NAMA'] = $this->strip_unicode($v['NAMA']);
$patient_id = 0;
if ($v['PID'] != '') {
$sql = "SELECT *
FROM m_patient
JOIN m_sex ON M_PatientM_SexID = M_SexID
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"];
$v['NAMA'] = $exist_r["M_PatientName"];
$pdob = date('Y-m-d', strtotime($exist_r['M_PatientDOB']));
$title_id = $exist_r["M_PatientM_TitleID"];
$sex_id = $exist_r["M_PatientM_SexID"];
$religion_id = $exist_r["M_PatientM_ReligionID"];
$v['NIK'] = $v['NIK'] ? $v['NIK'] : $exist_r["M_PatientNIK"];
$v['EMAIL'] = $v['EMAIL'] ? $v['EMAIL'] : $exist_r["M_PatientEmail"];
$v['HP'] = $v['HP'] ? $v['HP'] : $exist_r["M_PatientHP"];
$v['KEDUDUKAN'] = $v['KEDUDUKAN'] ? $v['KEDUDUKAN'] : $exist_r["M_PatientKedudukan"];
$v['JABATAN'] = $v['JABATAN'] ? $v['JABATAN'] : $exist_r["M_PatientJabatan"];
$v['JOB'] = $v['JOB'] ? $v['JOB'] : $exist_r["M_PatientJob"];
$v['LOKASI'] = $v['LOKASI'] ? addslashes($v['LOKASI']) : addslashes($exist_r["M_PatientLocation"]);
$v['JENIS_KELAMIN'] = $exist_r["M_SexCode"];
}
//echo $sql;
}
if ($v['KTP'] != '') {
$sql = "SELECT *
FROM m_patient
JOIN m_sex ON M_PatientM_SexID = M_SexID
WHERE M_PatientM_IdTypeID = 1 AND
M_PatientIDNumber = '{$v['KTP']}' AND
M_PatientIsActive = 'Y'
LIMIT 1";
$exist_r = $this->db_onedev->query($sql)->row_array();
if ($exist_r) {
$patient_id = $exist_r["M_PatientID"];
$v['NAMA'] = $exist_r["M_PatientName"];
//$pdob = date('Y-m-d',strtotime($exist_r['M_PatientDOB']));
$title_id = $exist_r["M_PatientM_TitleID"];
$sex_id = $exist_r["M_PatientM_SexID"];
$religion_id = $exist_r["M_PatientM_ReligionID"];
$v['NIK'] = $v['NIK'] ? $v['NIK'] : $exist_r["M_PatientNIK"];
$v['EMAIL'] = $v['EMAIL'] ? $v['EMAIL'] : $exist_r["M_PatientEmail"];
$v['HP'] = $v['HP'] ? $v['HP'] : $exist_r["M_PatientHP"];
$v['KEDUDUKAN'] = $v['KEDUDUKAN'] ? $v['KEDUDUKAN'] : $exist_r["M_PatientKedudukan"];
$v['JABATAN'] = $v['JABATAN'] ? $v['JABATAN'] : $exist_r["M_PatientJabatan"];
$v['JOB'] = $v['JOB'] ? $v['JOB'] : $exist_r["M_PatientJob"];
$v['LOKASI'] = $v['LOKASI'] ? addslashes($v['LOKASI']) : addslashes($exist_r["M_PatientLocation"]);
$v['JENIS_KELAMIN'] = $exist_r["M_SexCode"];
$v['KTP'] = $v['KTP'] ? $v['KTP'] : $exist_r["M_PatientIDNumber"];
}
//echo $sql;
}
if ($patient_id == 0) {
$sex_id = 0;
$sql = "SELECT * FROM m_sex WHERE M_SexCode = TRIM('{$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;
if (TRIM($v['JENIS_KELAMIN']) == 'L')
$title_id = 2;
else
$title_id = 4;
$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;
}
$query = " INSERT INTO mcu_preregister_patients (
Mcu_PreregisterDetailsMcuOfflinePrepareID,
Mcu_PreregisterDetailsPID,
Mcu_PreregisterDetailsKTP,
Mcu_PreregisterDetailsNIK,
Mcu_PreregisterDetailsM_TitleID,
Mcu_PreregisterDetailsPatientName,
Mcu_PreregisterDetailsM_ReligionID,
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']}',
'{$v['KTP']}',
'{$v['NIK']}',
'{$title_id}',
'{$v['NAMA']}',
'{$religion_id}',
'{$v['EMAIL']}',
'{$v['HP']}',
'{$pdob}',
'{$v['KEDUDUKAN']}',
'{$v['JABATAN']}',
'{$v['JOB']}',
'{$v['LOKASI']}',
TRIM('{$v['JENIS_KELAMIN']}'),
'{$agreement}',
'{$tests}',
NOW(),
{$userid}
)";
//echo $query;
$rows = $this->db_onedev->query($query);
if ($rows) {
$last_id_x = $this->db_onedev->insert_id();
$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)->row_array();
//print_r($row_header);
if ($patient_id == 0) {
$sql = "SELECT *
FROM m_patient
WHERE
M_PatientName = '{$v['NAMA']}' AND
M_PatientDOB = '{$pdob}' AND
M_PatientNIP = '{$v['NIK']}' AND
M_PatientIsActive = 'Y' LIMIT 1";
$exist_r = $this->db_onedev->query($sql)->row_array();
if ($exist_r) {
$patient_id = $exist_r["M_PatientID"];
}
//echo $sql;
}
//echo $patient_id;
if ($patient_id == 0) {
//echo 'insert new patient';
//$pdob = date('Y-m-d',strtotime($prm['Mcu_PreregisterDetailsDOB']));
$M_PatientM_IdTypeID = 0;
$M_PatientIDNumber = NULL;
if (isset($v["KTP"]) && $v["KTP"] != '') {
$M_PatientM_IdTypeID = 1;
$M_PatientIDNumber = $v["KTP"];
}
$sql = "INSERT INTO m_patient (
M_PatientName,
M_PatientM_TitleID,
M_PatientM_SexID,
M_PatientM_ReligionID,
M_PatientPOB,
M_PatientDOB,
M_PatientNIK,
M_PatientM_IdTypeID,
M_PatientIDNumber,
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"]}',
'{$M_PatientM_IdTypeID}',
'{$M_PatientIDNumber}',
'{$v['JABATAN']}',
'{$v['LOKASI']}',
'{$v['KEDUDUKAN']}',
'{$v['JOB']}',
'{$v['EMAIL']}',
'{$v['HP']}',
'{$userid}'
)";
//echo $sql;
$this->db_onedev->query($sql);
$data_insert_patient = array(
'M_PatientName' => $v["NAMA"],
'M_PatientM_TitleID' => $title_id,
'M_PatientM_SexID' => $sex_id,
'M_PatientM_ReligionID' => $religion_id,
'M_PatientPOB' => '-',
'M_PatientDOB' => $pdob,
'M_PatientNIK' => $v["NIK"],
'M_PatientJabatan' => $v['JABATAN'],
'M_PatientLocation' => $v['LOKASI'],
'M_PatientKedudukan' => $v['KEDUDUKAN'],
'M_PatientJob' => $v['JOB'],
'M_PatientEmail' => $v['EMAIL'],
'M_PatientHP' => $v['HP'],
'M_PatientUserID' => $userid
);
//$this->db->insert('m_patient', $data_insert_patient);
//echo $this->db_onedev->last_query();
$patient_id = $this->db_onedev->insert_id();
//$sql = "SELECT LAST_INSERT_ID() as xid";
//$patient_id = $this->db_onedev->query($sql)->row()->xid;
//echo $patient_id ;
$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);
//echo $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 {
//echo 'masuk';
//$pdob = date('Y-m-d',strtotime($prm['Mcu_PreregisterDetailsDOB']));
$data_update_patient = array(
'M_PatientDOB' => $pdob
);
if ($v['JENIS_KELAMIN'] == 'L')
$data_update_patient['M_PatientM_TitleID'] = 2;
else
$data_update_patient['M_PatientM_TitleID'] = 4;
if ($v['EMAIL'] != '')
$data_update_patient['M_PatientEmail'] = $v['EMAIL'];
if ($v['HP'] != '')
$data_update_patient['M_PatientHP'] = $v['HP'];
if ($v['NIK'] != '')
$data_update_patient['M_PatientNIK'] = $v['NIK'];
if ($v['JABATAN'] != '')
$data_update_patient['M_PatientJabatan'] = $v['JABATAN'];
if ($v['KEDUDUKAN'] != '')
$data_update_patient['M_PatientKedudukan'] = $v['KEDUDUKAN'];
if ($v['LOKASI'] != '')
$data_update_patient['M_PatientLocation'] = $v['LOKASI'];
if ($v['JOB'] != '')
$data_update_patient['M_PatientJob'] = $v['JOB'];
if (isset($v["KTP"]) && $v["KTP"] != '') {
$data_update_patient['M_PatientM_IdTypeID'] = 1;
$data_update_patient['M_PatientIDNumber'] = $v["KTP"];
}
$this->db_onedev->where('M_PatientID', $patient_id);
$this->db_onedev->update('m_patient', $data_update_patient);
//echo $this->db_onedev->last_query();
//$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 strip_unicode($inp)
{
//echo $inp;
$result = mb_convert_encoding($inp, 'US-ASCII', 'UTF-8');
//echo $result;
$result = str_replace("?", " ", $result);
//echo $result;
return $result;
}
function newpatient()
{
if (!$this->isLogin) {
$this->sys_error("Invalid Token");
exit;
}
$prm = $this->sys_input;
$userid = $this->sys_user["M_UserID"];
$pdob = date('Y-m-d', strtotime($prm['M_PatientDOB']));
$query = "INSERT INTO m_patient (
M_PatientM_TitleID,
M_PatientPrefix,
M_PatientName,
M_PatientSuffix,
M_PatientDOB,
M_PatientM_SexID,
M_PatientM_ReligionID,
M_PatientEmail,
M_PatientPOB,
M_PatientHP,
M_PatientPhone,
M_PatientM_IdTypeID,
M_PatientIDNumber,
M_PatientNote,
M_PatientNIK,
M_PatientJabatan,
M_PatientKedudukan,
M_PatientPJ,
M_PatientLocation,
M_PatientJob,
M_PatientUserID
)
VALUES(
'{$prm['M_PatientM_TitleID']}',
'{$prm['M_PatientPrefix']}',
'{$prm['M_PatientName']}',
'{$prm['M_PatientSuffix']}',
'{$pdob}',
'{$prm['M_PatientM_SexID']}',
'{$prm['M_PatientM_ReligionID']}',
'{$prm['M_PatientEmail']}',
'{$prm['M_PatientPOB']}',
'{$prm['M_PatientHP']}',
'{$prm['M_PatientPhone']}',
'{$prm['M_PatientM_IdTypeID']}',
'{$prm['M_PatientIDNumber']}',
'{$prm['M_PatientNote']}',
'{$prm['M_PatientNIK']}',
'{$prm['M_PatientJabatan']}',
'{$prm['M_PatientKedudukan']}',
'{$prm['M_PatientPJ']}',
'{$prm['M_PatientLocation']}',
'{$prm['M_PatientJob']}',
$userid
)
";
//echo $query;
$rows = $this->db_onedev->query($query);
$last_id = $this->db_onedev->insert_id();
$result = array(
"total" => 1,
"records" => array('status' => 'OK'),
"id" => $last_id
);
$ptn = $prm;
$ptn["M_PatientID"] = $last_id;
$ptn["M_PatientDOB"] = $pdob;
$ptn = json_encode($ptn);
$this->db_onedev->query("CALL one_log.log_me('PATIENT', 'PATIENT.ADD', '{$ptn}', $userid)");
$this->sys_ok($result);
exit;
}
function deletepatient()
{
if (!$this->isLogin) {
$this->sys_error("Invalid Token");
exit;
}
$userid = $this->sys_user["M_UserID"];
$prm = $this->sys_input;
$query = "UPDATE 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;
}
}