Files
2026-04-15 15:23:57 +07:00

192 lines
5.7 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);
$this->db_oneklinik = $this->load->database("onedev", true);
$one_db = "one_aditya";
}
function search()
{
$prm = $this->sys_input;
$max_rst = 100;
$tot_count =0;
$number_limit = 10;
$number_offset = (!isset($prm['current_page'])?1:$prm['current_page'] - 1) * $number_limit ;
$q = [
'noreg' => "",
'name' => '',
'hp' => '',
'dob' => '',
'address' => '',
'nik' =>''
];
$q_pid = "";
if ($prm['noreg'] != '')
$q['noreg'] = "AND M_PatientNoReg like '%{$prm['noreg']}%'";
if($prm['snorm'] == ''){
if ($prm['search'] != '')
{
$e = explode('+', $prm['search']);
if (isset($e[0])){
$e[0] = str_replace("'", "\\'", $e[0]);
$q['name'] = "AND M_PatientName LIKE '%{$e[0]}%'";
}
if (isset($e[1]))
$q['hp'] = "AND ((M_PatientHP LIKE '%{$e[1]}%' and M_PatientHP IS NOT NULL) OR (M_PatientHP IS NULL AND '{$e[1]}' = ''))";
if (isset($e[2]))
$q['dob'] = "AND ((DATE_FORMAT(M_PatientDOB, '%d-%m-%Y') LIKE '%{$e[2]}%' and M_PatientDOB IS NOT NULL) OR (M_PatientDOB IS NULL AND '{$e[2]}' = ''))";
if (isset($e[3]))
$q['address'] = "AND M_PatientAddressDescription LIKE '%{$e[3]}%'";
if (isset($e[4]))
$q['nik'] = "AND M_PatientIDNumber = '{$e[4]}'";
}
}else{
$q_pid = "AND M_PatientNoReg = '{$prm['snorm']}'";
}
$sql = "SELECT 'N' divider,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_PatientM_IdTypeID,
M_IdTypeName,
M_PatientIDNumber,
M_PatientPhoto,
M_PatientAddressM_KelurahanID M_KelurahanID,
0 M_DistrictID, 0 M_CityID, 0 M_ProvinceID
FROM m_patient
JOIN one_klinik.`order` ON orderM_PatientID = M_PatientID
JOIN m_title ON M_PatientM_TitleID = M_TitleID
JOIN m_sex ON M_PatientM_SexID = M_SexID
JOIN m_branch ON M_BranchIsActive = 'Y' AND M_BranchIsDefault = 'Y'
JOIN m_patientaddress ON M_PatientAddressM_PatientID = M_PatientID AND M_PatientAddressIsActive = 'Y'
LEFT JOIN m_idtype ON M_IdTypeID = M_PatientM_IdTypeID AND M_IdTypeIsActive = 'Y'
WHERE
M_PatientIsActive = 'Y'
{$q['address']}
{$q['noreg']}
{$q['name']}
{$q['hp']}
{$q['dob']}
{$q['nik']}
{$q_pid}
GROUP BY M_PatientID
LIMIT $number_limit offset $number_offset";
//echo $sql;
$query = $this->db_onedev->query($sql);
if ($query) {
$rows = $query->result_array();
foreach ($rows as $k => $v)
{
$rows[$k]['M_PatientName'] = stripslashes($rows[$k]['M_PatientName']);
$rows[$k]['M_PatientAddressDescription'] = stripslashes($v['M_PatientAddressDescription']);
$patient_name = str_replace("'", "\\'", $prm['M_PatientName']);
$sql = "SELECT *, concat('{$rows[$k]['M_PatientAddressDescription'] }', '\n\n',
m_kelurahanname, ', ',
m_districtname,'\n',
m_cityname, ', ',
m_provincename) as xaddress
FROM m_kelurahan
JOIN m_district ON M_KelurahanM_DistrictID = M_DistrictID
JOIN m_city ON M_DistrictM_CityID = M_CityID
JOIN m_province ON M_CityM_ProvinceID = M_ProvinceID
WHERE
M_KelurahanID = {$v['M_KelurahanID']} ";
//echo $sql;
$row_address = $this->db_onedev->query($sql)->row_array();
$rows[$k]['M_PatientAddress'] = stripslashes($row_address['xaddress']);
$rows[$k]['M_DistrictID'] = $row_address['M_DistrictID'];
$rows[$k]['M_CityID'] = $row_address['M_CityID'];
$rows[$k]['M_ProvinceID'] = $row_address['M_ProvinceID'];
$info = $this->db_onedev->query("SELECT fn_fo_patient_visit(?) info", [$v['M_PatientID']])->row();
$rows[$k]['info'] = json_decode($info->info);
}
$result = array("total" => $tot_page, "records" => $rows, "sql"=> $this->db_onedev->last_query());
$this->sys_ok($result);
}
else {
$this->sys_error_db("m_patient rows",$this->db_onedev);
exit;
}
}
function get_resume_medics()
{
$prm = $this->sys_input;
$sql = "SELECT one_klinik.`order`.*, date_format(orderDate,'%d-%m-%Y %H:%i') as order_date
FROM one_klinik.`order`
WHERE
orderIsActive = 'Y' AND orderM_PatientID = ?
ORDER BY orderDate DESC";
//echo $sql;
$query = $this->db_oneklinik->query($sql,array($prm['id']));
if ($query) {
$rows = $query->result_array();
$result = array("total" => $tot_page, "records" => $rows, "sql"=> $this->db_oneklinik->last_query());
$this->sys_ok($result);
}
else {
$this->sys_error_db("resume medic rows",$this->db_oneklinik);
exit;
}
}
}