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

627 lines
17 KiB
PHP

<?php
class Patient 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()
{
$r = $this->sys_input;
if (! $this->isLogin) {
$this->sys_error("Invalid Token");
exit;
}
$full_name = $r["M_PatientName"];
if ($pasien["patient_fullname"] != "") {
$full_name = $pasien["patient_fullname"];
}
$param = [
"nik" => $r["M_PatientIDNumber"],
"dob" => $r["M_PatientDOB"],
"name" => $r["M_PatientName"],
"full_name" => $full_name,
"hp" => $r["M_PatientHp"],
"alamat" => $r["M_PatientAddressDescription"],
];
$resp = [];
$this->load->library("NatPatientLib");
$get_data = $this->natpatientlib->search_by_nik($param);
if($get_data){
foreach($get_data['rows'] as $k => $v){
$new_data = $v;
$new_data['status'] = 'N';
array_push($resp,$new_data);
}
}
$get_data['rows'] = $resp ;
echo json_encode($get_data);
}
public function validasi()
{
$param = $this->sys_input;
if (! $this->isLogin) {
$this->sys_error("Invalid Token");
exit;
}
$patient_id = $param['selpatient']['M_PatientID'];
$userid = $this->sys_user["M_UserID"];
$username = $this->sys_user["M_UserName"];
$this->load->library("NatPatientLib");
$get_data = $this->natpatientlib->confirm($patient_id, $param['data'], $userid, $username);
echo json_encode($get_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 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;
}
$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']));
$prm['M_PatientName'] = str_replace("'", "\\'", $prm['M_PatientName']);
$prm['M_PatientPOB'] = str_replace("'", "\\'", $prm['M_PatientPOB']);
$query ="UPDATE m_patient SET
M_PatientM_TitleID = '{$prm['M_PatientM_TitleID']}',
M_PatientPrefix = '{$prm['M_PatientPrefix']}',
M_PatientName = '{$prm['M_PatientName']}',
M_PatientSuffix = '{$prm['M_PatientSuffix']}',
M_PatientDOB = '{$pdob}',
M_PatientM_SexID = '{$prm['M_PatientM_SexID']}',
M_PatientM_ReligionID = '{$prm['M_PatientM_ReligionID']}',
M_PatientEmail = '{$prm['M_PatientEmail']}',
M_PatientPOB = '{$prm['M_PatientPOB']}',
M_PatientHP = '{$prm['M_PatientHP']}',
M_PatientPhone = '{$prm['M_PatientPhone']}',
M_PatientM_IdTypeID = '{$prm['M_PatientM_IdTypeID']}',
M_PatientIDNumber = '{$prm['M_PatientIDNumber']}',
M_PatientNote = '{$prm['M_PatientNote']}',
M_PatientNIK = '{$prm['M_PatientNIK']}',
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}'
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;
$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']));
$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_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 getdatalocations()
{
if (! $this->isLogin) {
$this->sys_error("Invalid Token");
exit;
}
$prm = $this->sys_input;
$id = $prm['id'];
$query =" SELECT M_KelurahanID,M_KelurahanName
FROM m_kelurahan
WHERE
M_KelurahanID = ?
";
//echo $query;
$kelurahan = $this->db_onedev->query($query,array($id))->row_array();
//echo $this->db_onedev->last_query();
$query =" SELECT M_CityID, M_CityName
FROM m_kelurahan
JOIN m_district ON M_KelurahanM_DistrictID = M_DistrictID
JOIN m_city ON M_DistrictM_CityID = M_CityID
WHERE
M_KelurahanID = ?
GROUP BY M_CityID LIMIT 1
";
//echo $query;
$city = $this->db_onedev->query($query,array($id))->row_array();
$cities[] = $city;
$query ="SELECT M_DistrictID, M_DistrictName
FROM m_kelurahan
JOIN m_district ON M_KelurahanM_DistrictID = M_DistrictID
WHERE
M_KelurahanID = ?
GROUP BY M_DistrictID LIMIT 1
";
//echo $query;
$district = $this->db_onedev->query($query,array($id))->row_array();
$query ="SELECT M_DistrictID, M_DistrictName
FROM m_district
WHERE
M_DistrictM_CityID = ?
";
//echo $query;
$districts = $this->db_onedev->query($query,array($city['M_CityID']))->result_array();
$query ="SELECT M_KelurahanID,M_KelurahanName
FROM m_kelurahan
WHERE
M_KelurahanM_DistrictID = ?
";
//echo $query;
$kelurahans = $this->db_onedev->query($query,array($district['M_DistrictID']))->result_array();
$result = array(
"kelurahan" => $kelurahan ,
"kelurahans" => $kelurahans ,
"district" => $district ,
"districts" => $districts ,
"city" => $city ,
"cities" => $cities ,
);
$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;
}
function savepatientnas(){
if (! $this->isLogin) {
$this->sys_error("Invalid Token");
exit;
}
$username = $this->sys_user["M_UserUsername"];
$prm = $this->sys_input;
$this->load->library("NatPatientLib");
$save_data = $this->natpatientlib->save_nasional($username,$prm);
echo json_encode($save_data);
}
}