218 lines
7.1 KiB
PHP
218 lines
7.1 KiB
PHP
<?php
|
|
|
|
class Re_patient extends MY_Controller
|
|
{
|
|
var $db_smartone;
|
|
|
|
public function index()
|
|
{
|
|
echo "RE Patient API";
|
|
}
|
|
|
|
public function __construct()
|
|
{
|
|
parent::__construct();
|
|
$this->db_smartone = $this->load->database("onedev", true);
|
|
}
|
|
|
|
public function search()
|
|
{
|
|
$prm = $this->sys_input;
|
|
$max_rst = 10;
|
|
|
|
$sdate = $prm["start_date"] . '%';
|
|
$search = '%' . $prm["search"] . '%';
|
|
$page = $prm['page'];
|
|
/* $group_id = 0;
|
|
if (isset($prm['group_id'])) $group_id = $prm['group_id'];
|
|
|
|
$company_id = 0;
|
|
$q_company = "";
|
|
if (isset($prm['company_id'])) {
|
|
$company_id = $prm['company_id'];
|
|
if ($company_id > 0 ) {
|
|
$q_company = " and T_OrderHeaderM_CompanyID = $company_id ";
|
|
}
|
|
}
|
|
$q_search = " and
|
|
( M_PatientName LIKE ?
|
|
or T_OrderHeaderLabNumber like ?
|
|
or T_OrderHeaderAddOnLabNumberOrigin like ?
|
|
or T_OrderHeaderLabNumberExt like ?
|
|
)";
|
|
if ($prm["search"] == "" ) $q_search = "";
|
|
|
|
*/
|
|
if ($page == null)
|
|
$page = 1;
|
|
|
|
$offset = ($page - 1) * $max_rst;
|
|
|
|
$max_rst = 10;
|
|
$offset = 0;
|
|
/*
|
|
$q_group = "";
|
|
if ($group_id != 0 ) {
|
|
$sql = "select T_WorklistDetailNat_TestID Nat_TestID
|
|
from t_worklistdetailv2
|
|
where T_WorklistDetailT_WorklistID = $group_id
|
|
";
|
|
$qry = $this->db_smartone->query($sql);
|
|
$rows = $qry->result_array();
|
|
$nat_test_ids = "0";
|
|
foreach($rows as $r) {
|
|
$nat_test_ids .= ", " . $r["Nat_TestID"];
|
|
}
|
|
$q_group = " and T_TestNat_TestID in ( $nat_test_ids ) ";
|
|
}
|
|
*/
|
|
//janji hasil hari ini T_OrderHeaderID
|
|
$sql = "select T_OrderPromiseT_OrderHeaderID
|
|
from t_orderpromise
|
|
where T_OrderPromiseIsActive = 'Y' and date(T_OrderPromiseDateTime) = ?";
|
|
$qry = $this->db_smartone->query($sql, array($sdate));
|
|
$promise_ids = "0";
|
|
if ($qry) {
|
|
$xrows = $qry->result_array();
|
|
if ( count($xrows) > 0 ) {
|
|
$xids = array();
|
|
foreach($xrows as $r) $xids[] = $r["T_OrderPromiseT_OrderHeaderID"];
|
|
$promise_ids = join(",",$xids);
|
|
}
|
|
}
|
|
$sql = "select T_OrderHeaderID
|
|
from t_orderheader
|
|
where T_OrderHeaderIsActive = 'Y' and date(T_OrderHeaderDate) = ?";
|
|
$qry = $this->db_smartone->query($sql, array($sdate));
|
|
$order_ids = $promise_ids;
|
|
if ($qry) {
|
|
$xrows = $qry->result_array();
|
|
if ( count($xrows) > 0 ) {
|
|
$xids = array();
|
|
foreach($xrows as $r) $xids[] = $r["T_OrderHeaderID"];
|
|
$order_ids .= "," . join(",",$xids);
|
|
}
|
|
}
|
|
|
|
$sql = "SELECT *,
|
|
CONCAT('[', GROUP_CONCAT(DISTINCT CONCAT('\"', T_OrderPromiseDateTime, '\"') SEPARATOR ','), ']') order_promise
|
|
FROM (
|
|
select T_OrderHeaderID,
|
|
T_OrderHeaderDate,
|
|
T_OrderHeaderLabNumber,
|
|
if(T_OrderHeaderAddOnLabNumberOrigin is null,
|
|
T_OrderHeaderLabNumberExt, T_OrderHeaderAddOnLabNumberOrigin) T_OrderHeaderLabNumberExt,
|
|
T_OrderHeaderDiagnose,
|
|
fn_global_patient_name(T_OrderHeaderM_PatientID) M_PatientName,
|
|
T_OrderPromiseDateTime,
|
|
T_OrderHeaderIsCito
|
|
from t_orderheader
|
|
JOIN t_orderheaderaddon ON T_OrderHeaderAddOnT_OrderHeaderID = T_OrderHeaderID
|
|
and T_OrderHeaderAddOnVerificationDone <> 'Y'
|
|
JOIN t_orderpromise ON T_OrderPromiseT_OrderHeaderID = T_OrderHeaderID and T_OrderPromiseIsActive = 'Y'
|
|
where T_OrderHeaderIsActive = 'Y'
|
|
and T_OrderHeaderID in ( $order_ids )
|
|
AND T_OrderHeaderAddOnFOVerification = 'Y'
|
|
order by FIELD(T_OrderHeaderIsCito, 'Y', 'N') ASC, T_OrderHeaderLabNumber
|
|
) x
|
|
GROUP BY T_OrderHeaderID
|
|
order by FIELD(T_OrderHeaderIsCito, 'Y', 'N') ASC, T_OrderHeaderLabNumber
|
|
LIMIT $max_rst
|
|
";
|
|
/* if ($q_search == "" ) {
|
|
$query = $this->db_smartone->query($sql);
|
|
} else {
|
|
$query = $this->db_smartone->query($sql, [ $search, $search, $search,$search ]);
|
|
}
|
|
*/
|
|
$query = $this->db_smartone->query($sql);
|
|
if ($query) {
|
|
$rows = $query->result_array();
|
|
$tmp_ohnumber = [];
|
|
/* foreach ($rows as $k => $v)
|
|
{
|
|
$lang = [["id"=>0, "code"=>"ID", "is_si"=>"N"]];
|
|
if ($v['M_LangCode'] != "ID")
|
|
$lang[] = ["id"=>$v['M_LangID'], "code"=>$v['M_LangCode'], "is_si"=>$v['T_OrderHeaderLangIsSI']];
|
|
|
|
$rows[$k]['data'] = json_decode($v['data']);
|
|
$rows[$k]['lang'] = $lang;
|
|
$rows[$k]['delivery'] = JSON_DECODE($v['delivery']);
|
|
$rows[$k]['order_promise'] = JSON_DECODE($v['order_promise']);
|
|
|
|
foreach($rows[$k]['order_promise'] as $l => $w)
|
|
$rows[$k]['order_promise'][$l] = date('d-m-Y H:i', strtotime($w));
|
|
}
|
|
*/
|
|
$tot_count = count( $rows );
|
|
$result = array("total" => $tot_count,
|
|
"total_page" => ceil($tot_count/$max_rst),
|
|
"cur_page" => $page,
|
|
"records" => $rows,
|
|
"total_display" => sizeof($rows),
|
|
"q" => $this->db_smartone->last_query());
|
|
$this->sys_ok($result);
|
|
}
|
|
else {
|
|
$this->sys_error_db("worklist rows", $this->db_smartone);
|
|
exit;
|
|
}
|
|
}
|
|
|
|
public function history()
|
|
{
|
|
$prm = $this->sys_input;
|
|
|
|
// QUERY TOTAL
|
|
$sql = "CALL sp_process_result_history(?)";
|
|
$query = $this->db_smartone->query($sql, [$prm['order_id']]);
|
|
|
|
if ($query)
|
|
{
|
|
$row = $query->row();
|
|
$history = json_decode($row->rst);
|
|
|
|
$this->sys_ok($history);
|
|
}
|
|
else
|
|
{
|
|
$this->sys_error_db("RESULT HISTORY", $this->db_smartone);
|
|
exit;
|
|
}
|
|
}
|
|
|
|
public function save_note()
|
|
{
|
|
$prm = $this->sys_input;
|
|
|
|
$sql = "UPDATE t_orderheader SET T_OrderHeaderResultNote = ?, T_OrderHeaderResultNoteM_UserID = ?
|
|
WHERE T_OrderHeaderID = ?";
|
|
$query = $this->db_smartone->query($sql, [$prm['note'], $this->sys_user['M_UserID'], $prm['order_id']]);
|
|
if ($query)
|
|
{
|
|
$this->sys_ok($prm['order_id']);
|
|
exit;
|
|
}
|
|
|
|
$this->sys_error_db("RESULT NOTE", $this->db_smartone);
|
|
}
|
|
|
|
public function info_req()
|
|
{
|
|
$prm = $this->sys_input;
|
|
|
|
$sql = "CALL sp_process_result_reqs(?)";
|
|
$query = $this->db_smartone->query($sql, [$prm['order_id']]);
|
|
if ($query)
|
|
{
|
|
$row = $query->row();
|
|
$s_data = $row->data;
|
|
$s_data = str_replace("\n"," ",$s_data);
|
|
$this->sys_ok(json_decode($s_data));
|
|
exit;
|
|
}
|
|
|
|
$this->sys_error_db("RESULT REQ", $this->db_smartone);
|
|
}
|
|
}
|