Files
BE_IBL/application/controllers/mockup/mcuoffline/Uploaddata.php
2026-04-15 15:24:12 +07:00

740 lines
21 KiB
PHP

<?php
class Uploaddata 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->helper(array('form', 'url'));
}
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_preregister_patients.*,
DATE_FORMAT(Mcu_PreregisterDetailsDOB, '%d-%m-%Y') as dob
FROM mcu_preregister_patients
$sql_where
ORDER BY Mcu_PreregisterDetailsPatientName ASC
limit $number_limit offset $number_offset
";
//echo $sql;
$query = $this->db_onedev->query($sql, $sql_param);
$rows = $query->result_array();
if($rows){
foreach($rows as $k => $v){
//$rows[$k]['verification_px'] = $this->add_verification_test($v['M_PatientID']);
}
}
$sql = "SELECT mcu_offline_prepare.*,M_CompanyName,
DATE_FORMAT(McuOfflinePrepareStartDate, '%d.%m.%Y') as start_date,
DATE_FORMAT(McuOfflinePrepareStartDate, '%d.%m.%Y') as end_date
FROM mcu_offline_prepare
JOIN m_company ON McuOfflinePrepareM_CompanyID = M_CompanyID
WHERE
McuOfflinePrepareIsDownloaded = 'Y' AND
McuOfflinePrepareIsActive = 'Y'";
$xrow = $this->db_onedev->query($sql)->row_array();
//$this->_add_address($rows);
$result = array("total" => $tot_page, "records" => $rows, "setup"=> $xrow);
$this->sys_ok($result);
exit;
}
function savedata()
{
//print_r($_FILES['file']);
$filename = $_FILES['file']['name'];
$path = '/home/one/project/one/one-media/one-image-nonlab/';
//echo $path.$filename;
print_r(file_exists($path.$filename));
unlink($path.$filename);
if(!file_exists($path.$filename)){
$config['upload_path'] = $path;
$config['allowed_types'] = 'gz';
$config['max_size'] = 10000;
$config['max_width'] = 1024;
$config['max_height'] = 768;
$this->load->library('upload', $config);
if ( ! $this->upload->do_upload('file'))
{
$error = array('error' => $this->upload->display_errors());
$this->sys_ok($error);
exit;
}
else
{
$data = array('upload_data' => $this->upload->data());
//echo json_encode($data);
}
}
}
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_PatientNIK = '{$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
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 = {$patient_id} WHERE Mcu_PreregisterDetailsID = {$prm['Mcu_PreregisterDetailsID']}";
$this->db_onedev->query($sql);
$result = array(
"total" => 1 ,
"records" => $ptn,
);
$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 = "truncate mcu_preregister_patients";
$this->db_onedev->query($sql);
foreach($datas as $k => $v){
$pdob = date('Y-m-d',strtotime($v['TANGGAL_LAHIR']));
$query = " INSERT INTO mcu_preregister_patients (
Mcu_PreregisterDetailsMcuOfflinePrepareID,
Mcu_PreregisterDetailsPID,
Mcu_PreregisterDetailsNIK,
Mcu_PreregisterDetailsPatientName,
Mcu_PreregisterDetailsEmail,
Mcu_PreregisterDetailsHp,
Mcu_PreregisterDetailsDOB,
Mcu_PreregisterDetailsKedudukan,
Mcu_PreregisterDetailsJabatan,
Mcu_PreregisterDetailsJob,
Mcu_PreregisterDetailsLocation,
Mcu_PreregisterDetailsM_SexCode,
Mcu_PreregisterDetailsCreated,
Mcu_PreregisterDetailsUserID
)
VALUES(
'{$prm['xid']}',
'{$v['PID']}',
'{$v['NIK']}',
'{$v['NAMA']}',
'{$v['EMAIL']}',
'{$v['HP']}',
'{$pdob}',
'{$v['KEDUDUKAN']}',
'{$v['JABATAN']}',
'{$v['JOB']}',
'{$v['LOKASI']}',
'{$v['JENIS_KELAMIN']}',
NOW(),
{$userid}
)";
//echo $query;
$rows = $this->db_onedev->query($query);
}
$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']));
$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;
}
}