264 lines
10 KiB
PHP
264 lines
10 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"] . '%';
|
|
$edate = $prm["end_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_OrderHeaderCorporateID = $company_id ";
|
|
}
|
|
}
|
|
$q_search = " and
|
|
( M_PatientName LIKE ?
|
|
or T_OrderHeaderLabNumber like ?
|
|
)";
|
|
if ($prm["search"] == "" ) $q_search = "";
|
|
if ($page == null)
|
|
$page = 1;
|
|
|
|
$offset = ($page - 1) * $max_rst;
|
|
|
|
$max_rst = 9999;
|
|
$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);
|
|
}
|
|
}
|
|
*/
|
|
$order_ids = 0;
|
|
$sql = "select T_OrderHeaderID
|
|
from t_orderheader
|
|
where T_OrderHeaderIsActive = 'Y' and date(T_OrderHeaderDate) BETWEEN ? AND ?";
|
|
$qry = $this->db_smartone->query($sql, array($sdate,$edate));
|
|
$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);
|
|
}else{
|
|
$order_ids = 0;
|
|
}
|
|
}
|
|
|
|
$sql = "SELECT *,
|
|
CONCAT('[', GROUP_CONCAT(DISTINCT CONCAT('\"', T_OrderHeaderDate, '\"') SEPARATOR ','), ']') order_promise
|
|
FROM (
|
|
select T_OrderHeaderID, T_OrderHeaderLabNumber, T_OrderHeaderDate,
|
|
'' T_OrderHeaderLabNumberExt, T_OrderHeaderDiagnose,
|
|
M_PatientID, M_PatientNoReg, fn_global_patient_name(M_PatientID) M_PatientName,
|
|
M_PatientDOB, T_OrderHeaderM_PatientAge, M_PatientHP, M_PatientGender M_SexName, '' M_PatientNote,
|
|
da.M_DoctorID doctor_pj_id, fn_get_doctor_fullname(da.M_DoctorID) doctor_pj_name,
|
|
0 doctor_sender_id, '' doctor_sender_name,
|
|
'' M_MouID, '' M_MouName, CorporateID, CorporateName,
|
|
T_OrderHeaderFoNote, T_OrderHeaderSamplingNote, T_OrderHeaderResultNote,
|
|
la.M_LangID M_LangID, la.M_LangCode M_LangCode, la.M_LangName M_LangName, '' T_OrderHeaderLangIsSI,
|
|
la.M_LangID SecondM_LangID, la.M_LangCode SecondM_LangCode, la.M_LangName SecondM_LangName,
|
|
'' T_OrderHeaderAddOnSecondLangIsSI,
|
|
'N' T_OrderHeaderIsCito, '' as delivery,
|
|
'' T_OrderPromiseDateTime, '' is_history,
|
|
'N' T_OrderHeaderAddOnVerificationDone,
|
|
'N' T_OrderHeaderAddOnValidationDone, '' T_OrderHeaderAddOnRequestChangeDOB
|
|
from t_orderheader
|
|
JOIN t_orderdetail ON T_OrderHeaderID = T_OrderDetailT_OrderHeaderID AND T_OrderDetailIsActive = 'Y'
|
|
JOIN t_orderheaderlang ON T_OrderHeaderLangT_OrderHeaderID = T_OrderHeaderID
|
|
JOIN t_test ON T_OrderDetailT_TestID = T_TestID
|
|
{$q_group}
|
|
JOIN group_resultdetail ON Group_ResultDetailT_TestID = T_TestID AND Group_ResultDetailIsActive = 'Y'
|
|
JOIN group_result ON Group_ResultDetailGroup_ResultID = Group_ResultID AND Group_ResultFlagNonLab = 'N'
|
|
join m_patient on T_OrderHeaderM_PatientID = M_PatientID
|
|
left join m_doctor da on T_OrderHeaderPJM_DoctorID = da.M_DoctorID
|
|
JOIN corporate on T_OrderHeaderCorporateID = CorporateID
|
|
JOIN m_lang la ON T_OrderHeaderLangM_LangID = la.M_LangID
|
|
where T_OrderHeaderIsActive = 'Y'
|
|
and T_OrderHeaderID in ( $order_ids )
|
|
{$q_company}
|
|
{$q_search}
|
|
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
|
|
";
|
|
if ($q_search == "" ) {
|
|
$query = $this->db_smartone->query($sql);
|
|
} else {
|
|
$query = $this->db_smartone->query($sql, [ $search, $search]);
|
|
}
|
|
// echo $this->db_smartone->last_query();
|
|
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']];
|
|
$sqltotal = "SELECT COUNT(T_OrderDetailID) as cnt_rst_a,
|
|
SUM(IF(T_OrderDetailResult <> '' AND T_OrderDetailResult IS NOT NULL, 1, 0)) as cnt_rst_b,
|
|
SUM(IF(T_OrderDetailVerification = 'Y', 1, 0)) as cnt_ver_n,
|
|
SUM(IF(T_OrderDetailValidation = 'Y', 1, 0)) as cnt_val_n
|
|
FROM t_orderdetail
|
|
JOIN t_test ON T_OrderDetailT_TestID = T_TestID
|
|
JOIN group_resultdetail ON Group_ResultDetailT_TestID = T_TestID AND Group_ResultDetailIsActive = 'Y'
|
|
JOIN group_result ON Group_ResultDetailGroup_ResultID = Group_ResultID AND Group_ResultFlagNonLab = 'N'
|
|
WHERE T_OrderDetailIsActive = 'Y' AND T_OrderDetailT_OrderHeaderID = {$v['T_OrderHeaderID']}
|
|
AND T_OrderDetailT_TestIsResult = 'Y'";
|
|
$sqltotal = $this->db_smartone->query($sqltotal)->row();
|
|
|
|
if($sqltotal->cnt_rst_b > 0 && $sqltotal->cnt_rst_b < $sqltotal->cnt_rst_a){
|
|
$rows[$k]['T_OrderHeaderAddOnValidationDone'] = 'P';
|
|
}elseif($sqltotal->cnt_rst_b > 0 && $sqltotal->cnt_rst_b == $sqltotal->cnt_rst_a){
|
|
$rows[$k]['T_OrderHeaderAddOnValidationDone'] = 'Y';
|
|
}
|
|
$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 );
|
|
|
|
$sql = "Select CorporateID, CorporateName
|
|
from t_orderheader
|
|
JOIN corporate ON CorporateID = T_OrderHeaderCorporateID AND CorporateIsActive = 'Y'
|
|
where T_OrderHeaderIsActive = 'Y'
|
|
and T_OrderHeaderID in ( $order_ids )
|
|
GROUP BY CorporateID";
|
|
$query = $this->db_smartone->query($sql, array($qry) );
|
|
if ($query) {
|
|
$crows = $query->result_array();
|
|
$crows[] = array("CorporateID" => 0, "CorporateName" => "Semua");
|
|
}
|
|
else {
|
|
$this->sys_error_db("", $this->db_smartone);
|
|
exit;
|
|
}
|
|
|
|
$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(),
|
|
"companies"=>$crows);
|
|
$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);
|
|
}
|
|
}
|