426 lines
11 KiB
PHP
426 lines
11 KiB
PHP
<?php
|
|
class Screening 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);
|
|
}
|
|
|
|
public function search()
|
|
{
|
|
|
|
$prm = $this->sys_input;
|
|
$id = $prm['id'];
|
|
|
|
$sql = "SELECT orderID,
|
|
orderDate,
|
|
orderNumber,
|
|
orderIsScreening,
|
|
orderIsAnamnese,
|
|
orderIsCheck,
|
|
orderAge as patient_age,
|
|
DATE_FORMAT(orderDate,'%d-%m-%Y') as order_date,
|
|
'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_ReligionName,
|
|
M_PatientM_IdTypeID,
|
|
M_IdTypeName,
|
|
M_PatientIDNumber,
|
|
IF(ISNULL(M_PatientSuspendID),'active','suspend' ) as status,
|
|
M_PatientAddressM_KelurahanID M_KelurahanID,
|
|
0 M_DistrictID,
|
|
0 M_CityID,
|
|
0 M_ProvinceID
|
|
FROM one_klinik.order
|
|
JOIN m_patient ON M_PatientID = orderM_PatientID AND M_PatientIsActive = 'Y'
|
|
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'
|
|
LEFT JOIN m_religion ON m_patientm_religionid = m_religionid
|
|
LEFT JOIN m_patientsuspend ON M_PatientSuspendM_PatientID = M_PatientID AND M_PatientSuspendIsActive = 'Y'
|
|
WHERE
|
|
orderNumber = '{$id}' AND
|
|
M_PatientSuspendID IS NULL
|
|
|
|
GROUP BY M_PatientID";
|
|
//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" => 1, "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_data(){
|
|
if (! $this->isLogin) {
|
|
$this->sys_error("Invalid Token");
|
|
exit;
|
|
}
|
|
|
|
$prm = $this->sys_input;
|
|
|
|
$result = array('data' => '');
|
|
|
|
$sql = "SELECT orderScreeningKesanUmum as kesan_umum,
|
|
orderScreeningValueKesadaran as kesadaran,
|
|
orderScreeningValuePernafasan as pernafasan,
|
|
orderScreeningValueResikoJatuh as resiko_jatuh,
|
|
orderScreeningValueNyeriDada as nyeri_dada,
|
|
orderScreeningValueSkalaNyeri as skala_nyeri,
|
|
orderScreeningValueBatuk as batuk,
|
|
orderScreeningValueKeputusan as keputusan
|
|
FROM one_klinik.order_screening
|
|
WHERE
|
|
orderScreeningOrderID = ? AND orderScreeningIsActive = 'Y'
|
|
LIMIT 1";
|
|
$query = $this->db_oneklinik->query($sql,array($prm['orderid']));
|
|
if(!$query){
|
|
$this->sys_error("Gagal get data");
|
|
echo $this->db_oneklinik->last_query();
|
|
}
|
|
$result = $query->row_array();
|
|
|
|
$this->sys_ok($result);
|
|
exit;
|
|
}
|
|
|
|
|
|
protected function objToArray($obj)
|
|
{
|
|
// Not an object or array
|
|
if (!is_object($obj) && !is_array($obj)) {
|
|
return $obj;
|
|
}
|
|
|
|
// Parse array
|
|
foreach ($obj as $key => $value) {
|
|
$arr[$key] = $this->objToArray($value);
|
|
}
|
|
|
|
// Return parsed array
|
|
return $arr;
|
|
}
|
|
|
|
|
|
public function list_patient()
|
|
{
|
|
|
|
$prm = $this->sys_input;
|
|
|
|
$max_rst = 20;
|
|
$tot_count = 0;
|
|
$number_limit = 20;
|
|
$number_offset = (!isset($prm['current_page'])?1:$prm['current_page'] - 1) * $number_limit ;
|
|
$xdate = $prm['date'];
|
|
$status = $prm['status'];
|
|
|
|
$sql = "SELECT 'N' divider,
|
|
CONCAT(IF(ISNULL(M_TitleName),'',CONCAT(M_TitleName,'. ')),M_PatientName) as patient_name,
|
|
`order`.*,DATE_FORMAT(orderDate,'%d-%m-%Y') as date_order,
|
|
'' as kode_status, '' as status
|
|
FROM one_klinik.`order`
|
|
JOIN m_patient ON orderM_PatientID = M_PatientID
|
|
LEFT JOIN m_title ON M_PatientM_TitleID = M_TitleID
|
|
WHERE
|
|
orderIsActive = 'Y' AND DATE(orderDate) = ? AND orderIsScreening = ?
|
|
LIMIT $number_limit offset $number_offset";
|
|
//echo $sql;
|
|
$query = $this->db_oneklinik->query($sql,array($xdate,$status));
|
|
//echo $this->db_oneklinik->last_query();
|
|
|
|
if ($query) {
|
|
$rows = $query->result_array();
|
|
$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 process_now(){
|
|
if (! $this->isLogin) {
|
|
$this->sys_error("Invalid Token");
|
|
exit;
|
|
}
|
|
|
|
$prm = $this->sys_input;
|
|
$userID = $this->sys_user['M_UserID'];
|
|
//print_r($prm['subgroup']);
|
|
|
|
$sql = "INSERT INTO one_klinik.order_status (
|
|
orderStatusOrderID,
|
|
orderStatusCode,
|
|
orderStatusValue,
|
|
orderStatusUserID
|
|
)
|
|
VALUES(
|
|
?,?,?,?
|
|
)";
|
|
|
|
$query = $this->db_oneklinik->query($sql,array($prm['orderID'],'S','Y',$userID));
|
|
if(!$query){
|
|
$this->sys_error("Gagal Process");
|
|
}
|
|
|
|
$sql = "UPDATE one_klinik.`order` SET orderIsScreening = 'Y', orderUserID = ?
|
|
WHERE
|
|
orderID = ?";
|
|
|
|
$query = $this->db_oneklinik->query($sql,array($userID,$prm['orderID']));
|
|
if(!$query){
|
|
$this->sys_error("Gagal Update");
|
|
}
|
|
|
|
|
|
$result = array('process'=>'OK');
|
|
|
|
|
|
|
|
$this->sys_ok($result);
|
|
exit;
|
|
}
|
|
|
|
function cancel_now(){
|
|
if (! $this->isLogin) {
|
|
$this->sys_error("Invalid Token");
|
|
exit;
|
|
}
|
|
|
|
$prm = $this->sys_input;
|
|
$userID = $this->sys_user['M_UserID'];
|
|
//print_r($prm['subgroup']);
|
|
|
|
$sql = "INSERT INTO one_klinik.order_status (
|
|
orderStatusOrderID,
|
|
orderStatusCode,
|
|
orderStatusValue,
|
|
orderStatusUserID
|
|
)
|
|
VALUES(
|
|
?,?,?,?
|
|
)";
|
|
|
|
$query = $this->db_oneklinik->query($sql,array($prm['orderID'],'S','N',$userID));
|
|
if(!$query){
|
|
$this->sys_error("Gagal Process");
|
|
}
|
|
|
|
$sql = "UPDATE one_klinik.`order` SET orderIsScreening = 'N', orderUserID = ?
|
|
WHERE
|
|
orderID = ?";
|
|
|
|
$query = $this->db_oneklinik->query($sql,array($userID,$prm['orderID']));
|
|
if(!$query){
|
|
$this->sys_error("Gagal Process");
|
|
}
|
|
|
|
|
|
$result = array('process'=>'OK');
|
|
|
|
|
|
|
|
$this->sys_ok($result);
|
|
exit;
|
|
}
|
|
|
|
function end_session(){
|
|
if (! $this->isLogin) {
|
|
$this->sys_error("Invalid Token");
|
|
exit;
|
|
}
|
|
|
|
$prm = $this->sys_input;
|
|
$userID = $this->sys_user['M_UserID'];
|
|
//print_r($prm['subgroup']);
|
|
|
|
$sql = "SELECT COUNT(*) as xcount
|
|
FROM one_klinik.order_screening
|
|
WHERE
|
|
orderScreeningOrderID = ? AND orderScreeningIsActive = 'Y'";
|
|
$query = $this->db_oneklinik->query($sql,array($prm['orderID']));
|
|
if(!$query){
|
|
|
|
$this->sys_error("count exist");
|
|
echo $this->db_oneklinik->last_query();
|
|
}
|
|
|
|
$check_exist = $query->row()->xcount;
|
|
|
|
if($check_exist == 0){
|
|
$sql = "INSERT one_klinik.order_screening (
|
|
orderScreeningOrderID,
|
|
orderScreeningKesanUmum,
|
|
orderScreeningValueKesadaran,
|
|
orderScreeningValuePernafasan,
|
|
orderScreeningValueResikoJatuh,
|
|
orderScreeningValueNyeriDada,
|
|
orderScreeningValueSkalaNyeri,
|
|
orderScreeningValueBatuk,
|
|
orderScreeningValueKeputusan,
|
|
orderScreeningCreated,
|
|
orderScreeningUserID
|
|
)
|
|
VALUES(
|
|
?,?,?,?,?,?,?,?,?,NOW(),?
|
|
)";
|
|
$query = $this->db_oneklinik->query($sql,array(
|
|
$prm['orderID'],
|
|
$prm['kesan_umum'],
|
|
$prm['kesadaran'],
|
|
$prm['pernafasan'],
|
|
$prm['resiko_jatuh'],
|
|
$prm['nyeri_dada'],
|
|
$prm['skala_nyeri'],
|
|
$prm['batuk'],
|
|
$prm['keputusan'],
|
|
$userID)
|
|
);
|
|
if(!$query){
|
|
$this->sys_error("Gagal insert");
|
|
}
|
|
}else{
|
|
$sql = "UPDATE one_klinik.order_screening SET
|
|
orderScreeningKesanUmum = ?,
|
|
orderScreeningValueKesadaran = ?,
|
|
orderScreeningValuePernafasan = ?,
|
|
orderScreeningValueResikoJatuh = ?,
|
|
orderScreeningValueNyeriDada = ?,
|
|
orderScreeningValueSkalaNyeri = ?,
|
|
orderScreeningValueBatuk = ?,
|
|
orderScreeningValueKeputusan = ?,
|
|
orderScreeningUserID = ?
|
|
WHERE
|
|
orderScreeningOrderID = ?
|
|
";
|
|
$query = $this->db_oneklinik->query($sql,[
|
|
$prm['kesan_umum'],
|
|
$prm['kesadaran'],
|
|
$prm['pernafasan'],
|
|
$prm['resiko_jatuh'],
|
|
$prm['nyeri_dada'],
|
|
$prm['skala_nyeri'],
|
|
$prm['batuk'],
|
|
$prm['keputusan'],
|
|
$userID,
|
|
$prm['orderID']
|
|
]);
|
|
if(!$query){
|
|
echo $this->db_oneklinik->last_query();
|
|
$this->sys_error("Gagal Update");
|
|
}
|
|
}
|
|
|
|
|
|
$sql = "INSERT INTO one_klinik.order_status (
|
|
orderStatusOrderID,
|
|
orderStatusCode,
|
|
orderStatusValue,
|
|
orderStatusUserID
|
|
)
|
|
VALUES(
|
|
?,?,?,?
|
|
)";
|
|
|
|
$query = $this->db_oneklinik->query($sql,array($prm['orderID'],'S','D',$userID));
|
|
if(!$query){
|
|
$this->sys_error("Gagal End");
|
|
}
|
|
|
|
$sql = "UPDATE one_klinik.`order` SET orderIsScreening = 'D', orderUserID = ?
|
|
WHERE
|
|
orderID = ?";
|
|
|
|
$query = $this->db_oneklinik->query($sql,array($userID,$prm['orderID']));
|
|
if(!$query){
|
|
$this->sys_error("Gagal ENd");
|
|
}
|
|
|
|
|
|
$result = array('process'=>'OK');
|
|
|
|
|
|
|
|
$this->sys_ok($result);
|
|
exit;
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|