458 lines
12 KiB
PHP
458 lines
12 KiB
PHP
<?php
|
|
class Carousel 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);
|
|
}
|
|
|
|
public function search()
|
|
{
|
|
$prm = $this->sys_input;
|
|
if (! $this->isLogin) {
|
|
$this->sys_error("Invalid Token");
|
|
exit;
|
|
}
|
|
|
|
$sql_param = array();
|
|
|
|
|
|
$limit = '';
|
|
$number_limit = 100;
|
|
$number_offset = ($prm['current_page'] - 1) * $number_limit ;
|
|
|
|
$tot_count = 0;
|
|
$tot_page = 0;
|
|
|
|
|
|
$sql = "SELECT m_carousel.*, CONCAT('/one-media/one-regonline/',M_CarouselImageUrl) as xurl
|
|
FROM m_carousel
|
|
WHERE
|
|
M_CarouselIsActive = 'Y'
|
|
";
|
|
$query = $this->db_onedev->query($sql, $sql_param);
|
|
$rows = $query->result_array();
|
|
|
|
$result = array("total" => 1, "records" => $rows, "sql"=> $this->db_onedev->last_query());
|
|
$this->sys_ok($result);
|
|
exit;
|
|
}
|
|
|
|
function uploadimage(){
|
|
if (! $this->isLogin) {
|
|
$this->sys_error("Invalid Token");
|
|
exit;
|
|
}
|
|
|
|
$userid = $this->sys_user["M_UserID"];
|
|
$data = [];
|
|
$errors = [];
|
|
//print_r($_SERVER);
|
|
|
|
$prm = $this->sys_input;
|
|
|
|
//$config['upload_path'] = 'assets/';
|
|
|
|
$path = '/home/one/project/one/one-media/one-regonline/';
|
|
//echo $path;
|
|
$config['upload_path'] = $path;
|
|
$config['allowed_types'] = 'jpg|jpeg|png';
|
|
|
|
$config['max_size'] = '300';
|
|
$count = count($_FILES['files']['name']);
|
|
//echo $count;
|
|
$this->load->library('upload',$config);
|
|
|
|
$error = [];
|
|
for($i=0;$i<$count;$i++){
|
|
|
|
|
|
if(!empty($_FILES['files']['name'][$i])){
|
|
|
|
|
|
|
|
$_FILES['file']['name'] = $_FILES['files']['name'][$i];
|
|
|
|
$_FILES['file']['type'] = $_FILES['files']['type'][$i];
|
|
|
|
$_FILES['file']['tmp_name'] = $_FILES['files']['tmp_name'][$i];
|
|
|
|
$_FILES['file']['error'] = $_FILES['files']['error'][$i];
|
|
|
|
$_FILES['file']['size'] = $_FILES['files']['size'][$i];
|
|
|
|
|
|
$sql = "SELECT * FROM m_branch WHERE M_BranchIsActive = 'Y' AND M_BranchIsDefault = 'Y' LIMIT 1";
|
|
$data_branch = $this->db_onedev->query($sql)->row_array();
|
|
$namex = 'carousel-'.$data_branch['M_BranchCode'].'-'.date("ymdHis").'-'.$this->generateRandomString(5);
|
|
//echo $namex;
|
|
|
|
$config['file_name'] = $namex;
|
|
$this->upload->initialize($config);
|
|
//echo $config['file_name'] ;
|
|
|
|
|
|
|
|
|
|
|
|
if($this->upload->do_upload('file')){
|
|
|
|
$uploadData = $this->upload->data();
|
|
|
|
$filename = $uploadData['file_name'];
|
|
//echo $filename;
|
|
|
|
$sql = "INSERT INTO m_carousel (
|
|
M_CarouselM_BranchID,
|
|
M_CarouselImageUrl,
|
|
M_CarouselUserID,
|
|
M_CarouselCreated
|
|
)
|
|
VALUES(
|
|
{$data_branch['M_BranchID']},
|
|
'{$filename}',
|
|
{$userid},
|
|
NOW()
|
|
|
|
)";
|
|
//echo $sql;
|
|
$this->db_onedev->query($sql);
|
|
$xlast_id = $this->db_onedev->insert_id();
|
|
$data['totalFiles'][] = array('name' => $_FILES['files']['name'][$i] ,'image_url' => '/one-media/one-image-nonlab/'.$filename);
|
|
|
|
}
|
|
else{
|
|
$error = array('image'=>$_FILES['files']['name'][$i],'error' => $this->upload->display_errors());
|
|
$errors[] = $error;
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
$result = array("total" =>count( $data['totalFiles']), "records" => $data['totalFiles'],'errors'=>$errors);
|
|
$this->sys_ok($result);
|
|
}
|
|
|
|
|
|
function generateRandomString($length = 10) {
|
|
$characters = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ';
|
|
$charactersLength = strlen($characters);
|
|
$randomString = '';
|
|
for ($i = 0; $i < $length; $i++) {
|
|
$randomString .= $characters[rand(0, $charactersLength - 1)];
|
|
}
|
|
return $randomString;
|
|
}
|
|
|
|
|
|
function save(){
|
|
if (! $this->isLogin) {
|
|
$this->sys_error("Invalid Token");
|
|
exit;
|
|
}
|
|
$prm = $this->sys_input;
|
|
$userid = $this->sys_user["M_UserID"];
|
|
|
|
$query ="UPDATE m_carousel SET
|
|
M_CarouselOrder = '{$prm['M_CarouselOrder']}',
|
|
M_CarouselStatus = '{$prm['M_CarouselStatus']}',
|
|
M_CarouselLastUpdated = NOW(),
|
|
M_CarouselUserID = '{$userid}'
|
|
WHERE
|
|
M_CarouselID = '{$prm['M_CarouselID']}'
|
|
";
|
|
//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']));
|
|
$prm['M_PatientName'] = str_replace("'", "\\'", $prm['M_PatientName']);
|
|
$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_carousel SET
|
|
M_CarouselIsActive = 'N',
|
|
M_CarouselLastUpdated = NOW(),
|
|
M_CarouselUserID = {$userid}
|
|
WHERE
|
|
M_CarouselID = '{$prm['M_CarouselID']}'
|
|
";
|
|
//echo $query;
|
|
$rows = $this->db_onedev->query($query);
|
|
|
|
$result = array(
|
|
"total" => 1 ,
|
|
"records" => array('status'=>'OK')
|
|
);
|
|
$ptn = $prm;
|
|
|
|
$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]['M_PatientAddressDescription'] = stripslashes($v['M_PatientAddressDescription']);
|
|
$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;
|
|
}
|
|
}
|
|
$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;
|
|
}
|
|
|
|
|
|
}
|