db_smartone = $this->load->database("onedev", true);
}
function suggest_v2() {
if (! $this->isLogin) {
$this->sys_error("Invalid Token");
exit;
}
$prm = $this->sys_input;
$orderID = $prm["T_OrderHeaderID"];
$testID = $prm["T_TestID"];
$worklistID= $prm["worklistID"];
$sampleTypeID = $prm["T_SampleTypeID"];
//cari sampleTypeID
$sql = "
select distinct T_WorklistDetailT_WorklistID
from t_worklistdetailv2
where t_WorklistDetailIsActive = 'Y' and
T_WorklistDetailNat_TestID
in (
select T_WorklistDetailNat_TestID
from
t_worklistdetailv2
where T_WorklistDetailT_WorklistID = ?
and T_WorklistDetailIsActive ='Y'
) ";
$qry = $this->db_smartone->query($sql, array($worklistID));
$w_ids = "0";
if ($qry) {
$rows = $qry->result_array();
foreach($rows as $r) {
$w_ids .= "," . $r["T_WorklistDetailT_WorklistID"];
}
}
$q_w_ids = " ( $w_ids ) ";
$sql= "select T_WorklistName, count(*) tot_px
from
t_worklist
join t_worklistdetailv2 on T_WorklistID = T_WorklistDetailT_WorklistID
and T_WorklistDetailIsActive = 'Y'
and T_WorklistIsActive = 'Y'
and T_WorklistDetailT_WorklistID in {$q_w_ids}
join t_test t on t.T_TestNat_TestID = T_WorklistDetailNat_TestID
join t_orderdetail on t.T_TestID = T_OrderDetailT_TestID
and T_OrderDetailIsActive = 'Y' and T_OrderDetailT_OrderHeaderID = ?
group by T_WorklistID
order by tot_px desc";
$qry = $this->db_smartone->query($sql, array($orderID) );
echo $this->db_smartone->last_query();
$rows = $qry->result_array();
$msg = "Tidak ada preferensi";
if (count($rows) > 0 ) {
$prev_tot_px = 0;
$msg = "";
foreach($rows as $r) {
$tot_px = $r["tot_px"];
$name = $r["T_WorklistName"];
if ($tot_px >= $prev_tot_px) {
if ($msg != "") $msg .= ", ";
$msg .= "$name [ $tot_px Px ]";
}
$prev_tot_px = $tot_px;
}
}
$result = array(
"message"=> $msg,
);
$this->sys_ok($result);
}
function suggest() {
if (! $this->isLogin) {
$this->sys_error("Invalid Token");
exit;
}
$prm = $this->sys_input;
$orderID = $prm["T_OrderHeaderID"];
$testID = $prm["T_TestID"];
$sampleTypeID = $prm["T_SampleTypeID"];
$sql= "select T_WorklistName, count(*) tot_px
from
t_worklist
join t_worklistdetail on T_WorklistID = T_WorklistDetailT_WorklistID
and T_WorklistDetailIsActive = 'Y'
and T_WorklistIsActive = 'Y'
join t_orderdetail on T_WorklistDetailT_TestID = T_OrderDetailT_TestID
and T_OrderDetailIsActive = 'Y' and T_OrderDetailT_OrderHeaderID = ?
join t_test on T_OrderDetailT_TestID = T_TestID
and T_TestT_SampleTypeID = ?
group by T_WorklistID
order by tot_px desc";
$qry = $this->db_smartone->query($sql, array($orderID, $sampleTypeID) );
$rows = $qry->result_array();
$msg = "Tidak ada preferensi";
if (count($rows) > 0 ) {
$prev_tot_px = 0;
$msg = "";
foreach($rows as $r) {
$tot_px = $r["tot_px"];
$name = $r["T_WorklistName"];
if ($tot_px >= $prev_tot_px) {
if ($msg != "") $msg .= ", ";
$msg .= "$name [ $tot_px Px ]";
}
$prev_tot_px = $tot_px;
}
}
$result = array(
"message"=> $msg,
);
$this->sys_ok($result);
}
function get_v2() {
if (! $this->isLogin) {
$this->sys_error("Invalid Token");
exit;
}
$sql= "select T_TestNat_TestID T_TestID,PreAnalyticDate, PreAnalyticTime,
PreAnalyticT_WorklistID T_WorklistID,
PreAnalyticRequirements,PreAnalyticIsOk
from pre_analytic
join t_test on PreAnalyticNat_TestID = T_TestNat_TestID
where
PreAnalyticDate = date(now()) ";
$rows = $this->db_smartone->query($sql)->result_array();
$result = array(
"records"=> $rows,
"total" => count($rows)
);
$this->sys_ok($result);
}
function get() {
if (! $this->isLogin) {
$this->sys_error("Invalid Token");
exit;
}
$sql= "select T_TestID,PreAnalyticDate, PreAnalyticTime,
PreAnalyticT_WorklistID T_WorklistID,
PreAnalyticRequirements,PreAnalyticIsOk
from pre_analytic
join t_test on PreAnalyticNat_TestID = T_TestNat_TestID
where
PreAnalyticDate = date(now()) ";
$rows = $this->db_smartone->query($sql)->result_array();
$result = array(
"records"=> $rows,
"total" => count($rows)
);
$this->sys_ok($result);
}
function save_v2() {
if (! $this->isLogin) {
$this->sys_error("Invalid Token");
exit;
}
$prm = $this->sys_input;
$testID = $prm["T_TestID"];
$worklistID = $prm["T_WorklistID"];
$reqs = $prm["reqs"];
$count = 0;
$req_ids = array();
foreach($reqs as $req) {
$count++;
$req_ids[] = $req["id"];
}
$j_req_ids = json_encode($req_ids);
$sql = "select distinct T_TestNat_TestID
from (
select T_TestNat_TestID
from t_test where T_TestNat_TestID = ?
union
select c.T_TestNat_TestID
from t_test p
join t_test c on c.T_TestSasCode like concat(p.T_TestSasCode,'%')
and length(c.T_TestSasCode) > length(p.T_TestSasCode) and p.T_TestNat_TestID = ?
and c.T_TestIsResult = 'Y'
) x
";
$qry = $this->db_smartone->query($sql, array($testID,$testID) );
$rows = $qry->result_array();
foreach($rows as $r) {
$nat_testID = $r["T_TestNat_TestID"];
$is_ok = 'Y';
if ($count > 0 ) $is_ok = 'N';
$sql= "insert into pre_analytic (PreAnalyticDate, PreAnalyticTime, PreAnalyticT_WorklistID,
PreAnalyticNat_TestID,PreAnalyticRequirements,PreAnalyticIsOk)
values(now(),now(), $worklistID, $nat_testID,?,'$is_ok')
on duplicate key update
PreAnalyticRequirements = ?,
PreAnalyticIsOk = ?";
$this->db_smartone->query($sql,array($j_req_ids, $j_req_ids, $is_ok));
}
$userID = $this->sys_user['M_UserID'];
if ($prm["userID"] > 0 ) $userID = $prm["userID"];
$j_log = json_encode( array(
"T_TestID" => $testID,
"T_WorklistID" => $worklistID,
"Requirement" => $reqs
));
$sql = "insert into one_log.log_worklist(Log_WorklistCode, Log_WorklistUserID, Log_WorklistJson)
values('PRE.ANALYTIC',$userID,'$j_log')";
$this->db_smartone->query($sql);
$result = array("message" => "OK");
$this->sys_ok($result);
}
function save() {
if (! $this->isLogin) {
$this->sys_error("Invalid Token");
exit;
}
$prm = $this->sys_input;
$testID = $prm["T_TestID"];
$worklistID = $prm["T_WorklistID"];
$reqs = $prm["reqs"];
$count = 0;
$req_ids = array();
foreach($reqs as $req) {
$count++;
$req_ids[] = $req["id"];
}
$j_req_ids = json_encode($req_ids);
$sql = "select distinct T_TestNat_TestID
from (
select T_TestNat_TestID
from t_test where T_TestID = ?
union
select c.T_TestNat_TestID
from t_test p
join t_test c on c.T_TestSasCode like concat(p.T_TestSasCode,'%')
and length(c.T_TestSasCode) > length(p.T_TestSasCode) and p.T_TestID = ?
and c.T_TestIsResult = 'Y'
) x
";
$qry = $this->db_smartone->query($sql, array($testID,$testID) );
$rows = $qry->result_array();
//if (count($rows) > 0 ) {
foreach($rows as $r) {
$nat_testID = $r["T_TestNat_TestID"];
$is_ok = 'Y';
if ($count > 0 ) $is_ok = 'N';
$sql= "insert into pre_analytic (PreAnalyticDate, PreAnalyticTime, PreAnalyticT_WorklistID,
PreAnalyticNat_TestID,PreAnalyticRequirements,PreAnalyticIsOk)
values(now(),now(), $worklistID, $nat_testID,?,'$is_ok')
on duplicate key update
PreAnalyticRequirements = ?,
PreAnalyticIsOk = ?";
$this->db_smartone->query($sql,array($j_req_ids, $j_req_ids, $is_ok));
}
$userID = $this->sys_user['M_UserID'];
if ($prm["userID"] > 0 ) $userID = $prm["userID"];
$j_log = json_encode( array(
"T_TestID" => $testID,
"T_WorklistID" => $worklistID,
"Requirement" => $reqs
));
$sql = "insert into one_log.log_worklist(Log_WorklistCode, Log_WorklistUserID, Log_WorklistJson)
values('PRE.ANALYTIC',$userID,'$j_log')";
$this->db_smartone->query($sql);
$result = array("message" => "OK");
$this->sys_ok($result);
}
function worklist_receive() {
if (! $this->isLogin) {
$this->sys_error("Invalid Token");
exit;
}
$userID = $this->sys_user['M_UserID'];
if ($prm["userID"] > 0 ) $userID = $prm["userID"];
$prm = $this->sys_input;
$orderID= $prm["T_OrderHeaderID"];
$sampleTypeID= $prm["T_SampleTypeID"];
$sql = "update t_ordersample set T_OrderSampleWorklistReceive = 'Y'
, T_OrderSampleWorklistReceiveDateTime = now(), T_OrderSampleWorklistReceiveUserID = $userID
where T_OrderSampleT_OrderHeaderID = ? and T_OrderSampleT_SampleTypeID = ?";
$this->db_smartone->query($sql, array($orderID, $sampleTypeID) );
$j_log = json_encode(
array( "T_OrderHeaderID" => $orderID ,
"T_SampleTypeID" => $testID
));
$sql = "insert into one_log.log_worklist(Log_WorklistCode, Log_WorklistUserID, Log_WorklistJson)
values('RECEIVE',$userID,'$j_log')";
$this->db_smartone->query($sql);
$result = array("message" => "OK");
$this->sys_ok($result);
}
function save_confirmation() {
if (! $this->isLogin) {
$this->sys_error("Invalid Token");
exit;
}
$prm = $this->sys_input;
$wkl = $prm["worklistid"];
$stype = $prm["stype"];
$sdate = $prm['sdate'];
$sbatch = $prm['sbatch'];
$datas = $prm['labs'];
$userID = $this->sys_user['M_UserID'];
$sql = "insert into t_mappingbatch
(T_MappingBatchDate,
T_MappingBatchT_WorklistID,
T_MappingBatchType,
T_MappingBatchNo,
T_MappingBatchUserID,
T_MappingBatchCreated,
T_MappingBatchLastUpdated)
values
('{$sdate}',
$wkl,
'{$stype}',
$sbatch,
$userID,
now(),
now())";
$query = $this->db_smartone->query($sql);
$last_id = $this->db_smartone->insert_id();
foreach ($datas as $k => $v){
foreach ($v['patients'] as $kx => $vx){
$sql = "INSERT INTO t_mappingbatchdetail (
T_MappingBatchDetailT_MappingBatchID,
T_MappingBatchDetailNo,
T_MappingBatchDetailT_OrderHeaderID,
T_MappingBatchDetailLabNumber,
T_MappingBatchDetailUserID,
T_MappingBatchDetailCreated,
T_MappingBatchDetailLastUpdated
)
VALUES(
$last_id,
'{$vx['name']}',
{$vx['labid']},
'{$vx['number']}',
$userID,
now(),
NOW()
)";
$this->db_smartone->query($sql);
//echo $this->db_smartone->last_query();
}
}
$result = array("message" => "OK","lastidx" => $last_id);
$this->sys_ok($result);
}
function save_reject() {
if (! $this->isLogin) {
$this->sys_error("Invalid Token");
exit;
}
$userID = $this->sys_user['M_UserID'];
if ($prm["userID"] > 0 ) $userID = $prm["userID"];
$prm = $this->sys_input;
$orderID= $prm["orderID"];
$sampleTypeID= $prm["sampleTypeID"];
$sql = "select * from t_ordersample where T_OrderSampleT_OrderHeaderID=? and T_OrderSampleT_SampleTypeID=?";
$qry = $this->db_smartone->query($sql,array($orderID, $sampleTypeID));
if ($qry) {
$rows = $qry->result_array();
$j_log = json_encode($rows);
$sql = "update t_ordersample
set T_OrderSampleProcessing = 'N' ,
T_OrderSampleHandling = 'N',
T_OrderSampleReceiveHandling = 'N',
T_OrderSampleSendHandling= 'N',
T_OrderSampleVerification= 'N',
T_OrderSampleReceive = 'N',
T_OrderSampleReceiveDate = null,
T_OrderSampleReceiveTime = null,
T_OrderSampleSampling = 'X',
T_OrderSampleSamplingDate = null,
T_OrderSampleSamplingTime = null
where T_OrderSampleT_OrderHeaderID = $orderID and T_OrderSampleT_SampleTypeID = $sampleTypeID";
$this->db_smartone->query($sql);
$sql = "update t_ordersamplereq, t_ordersample set T_OrderSampleReqStatus= 'X'
, T_OrderSampleReqs = '[]'
where T_OrderSampleReqNat_PositionID in (4,3,2)
and T_OrderSampleReqT_OrderHeaderID = T_OrderSampleT_OrderHeaderID
and T_OrderSampleReqT_OrderSampleID = T_OrderSampleID
and T_OrderSampleReqT_OrderHeaderID = $orderID
and T_OrderSampleT_SampleTypeID = $sampleTypeID ";
$this->db_smartone->query($sql);
$sql = "update t_sampling_queue_last_status, t_samplestation
set T_SamplingQueueLastStatusT_SamplingQueueStatusID = 2
where T_SampleStationIsNonLab = ''
and T_SamplingQueueLastStatusT_OrderHeaderID = ? ";
$this->db_smartone->query($sql,array($orderID));
$sql = "insert into one_log.log_worklist(Log_WorklistCode, Log_WorklistUserID, Log_WorklistJson)
values('REJECT',$userID,'$j_log')";
$this->db_smartone->query($sql);
$result = array("message" => "OK");
$this->sys_ok($result);
} else {
$this->sys_error($this->db_smartone->error());
}
}
function getrequirements(){
if (! $this->isLogin) {
$this->sys_error("Invalid Token");
exit;
}
$prm = $this->sys_input;
$rows = array();
$query = "
SELECT Nat_RequirementID as id,
Nat_RequirementName as name,
'N' as chex
FROM nat_requirement
JOIN nat_requirementposition ON Nat_RequirementPositionNat_RequirementID = Nat_RequirementID AND Nat_RequirementPositionNat_PositionID = 5 AND
Nat_RequirementPositionIsActive = 'Y'
WHERE
Nat_RequirementIsActive = 'Y'
GROUP BY nat_requirementID";
//echo $query;
$rows = $this->db_smartone->query($query)->result_array();
$result = array(
"total" => count($rows) ,
"records" => $rows,
);
$this->sys_ok($result);
exit;
}
public function search_px_v3()
{
$prm = $this->sys_input;
$wkl = $prm["worklist_id"];
$rtype = $prm["racktype"];
$sdate = date('Y-m-d', strtotime($prm['sdate']));
$edate = date('Y-m-d', strtotime($prm['edate']));
$pg = $prm['curr_page'];
$pTestID = '2930';
// $pg = 1;
if($rtype == '48'){
$number_limit = 46;
}else{
$number_limit = 92;
}
$number_offset = ($pg - 1) * $number_limit ;
$sql = $this->db_smartone->query("select group_concat(DISTINCT T_TestT_SampleTypeID SEPARATOR ',') as sampletype_id
FROM (select IF(fn_sampletype_from_local(Nat_TestID ) <> 0 ,fn_sampletype_from_local(Nat_TestID),fn_worklist_get_sampletype(T_TestID)) T_TestT_SampleTypeID
from
t_test
join nat_test on Nat_TestID = T_TestNat_TestID
WHERE T_TestID = $pTestID
) a")->row();
$sampletype_id = $sql->sampletype_id;
$sql = "select T_MappingBatchDetailT_OrderHeaderID
FROM
t_mappingbatch
WHERE
JOIN t_mappingbatchdetail ON T_MappingBatchDetailT_MappingBatchID = T_MappingBatchDetailID AND T_MappingBatchDetailT_OrderHeaderID > 0
T_MappingBatchDate = ? AND
T_MappingBatchT_WorklistID = ? AND
T_MappingBatchType = ?
AND T_MappingBatchIsActive = 'Y'";
$qry = $this->db_smartone->query($sql, array($sdate,$wkl,$rtype));
$batch_ids = "0";
if ($qry) {
$xrows = $qry->result_array();
if ( count($xrows) > 0 ) {
$xids = array();
foreach($xrows as $r) $xids[] = $r["T_MappingBatchDetailT_OrderHeaderID"];
$batch_ids = join(",",$xids);
}
}
$sql = "SELECT COUNT(T_OrderHeaderID) as total, GROUP_CONCAT(T_OrderHeaderID SEPARATOR ',') as all_id FROM
(SELECT T_OrderHeaderID
FROM t_orderheader
JOIN t_orderdetail ON T_OrderHeaderID = T_OrderDetailT_OrderHeaderID AND T_OrderDetailIsActive = 'Y' and T_OrderDetailVerification <> 'Y' AND T_OrderDetailT_TestID = '{$pTestID}'
LEFT JOIN t_orderpromise ON T_OrderDetailT_OrderPromiseID = T_OrderPromiseID AND T_OrderPromiseIsActive = 'Y'
JOIN t_test ON T_OrderDetailT_TestID = T_TestID
JOIN nat_test ON T_TestNat_TestID = Nat_TestID
JOIN t_worklistdetailv2 ON Nat_TestID = T_WorklistDetailNat_TestID AND T_WorklistDetailIsActive = 'Y' AND T_WorklistDetailT_WorklistID = '{$wkl}'
join pre_analytic on PreAnalyticNat_TestID = Nat_TestID AND PreAnalyticDate = date(now()) AND PreAnalyticIsOk = 'Y'
join t_ordersample ON T_OrderSampleT_OrderHeaderID = T_OrderHeaderID AND T_OrderSampleT_SampleTypeID = $sampletype_id AND T_OrderSampleWorklistReceive = 'Y'
WHERE T_OrderHeaderIsActive = 'Y' AND
(date(T_OrderHeaderDate) = '{$sdate}' or date(T_OrderPromiseDateTime) = '{$sdate}')
GROUP BY T_OrderHeaderID
) c";
// $total = $this->db_smartone->query($sql,$sql_param)->row()->total;
$query = $this->db_smartone->query($sql);
//echo $this->db_smartone->last_query();
// echo $number_limit;
//echo $number_offset;
$tot_count = 0;
$tot_page = 0;
$all_id = 0;
if ($query) {
$tot_count = $query->result_array()[0]["total"];
$all_id = $query->result_array()[0]["all_id"];
$tot_page = ceil($tot_count/$number_limit);
} else {
$this->sys_error_db("t_testattribute count", $this->db_smartone);
exit;
}
$sql = "SELECT GROUP_CONCAT(T_OrderHeaderID SEPARATOR ',') as idx FROM
(SELECT T_OrderHeaderID
FROM t_orderheader
WHERE T_OrderHeaderID IN($all_id)
LIMIT $number_limit OFFSET $number_offset
) c";
// $total = $this->db_smartone->query($sql,$sql_param)->row()->total;
$query = $this->db_smartone->query($sql);
//echo $this->db_smartone->last_query();
// echo $number_limit;
//echo $number_offset;
$idx = 0;
if ($query) {
$idx = $query->result_array()[0]["idx"];
} else {
$this->sys_error_db("t_testattributex count", $this->db_smartone);
exit;
}
$sql ="call sp_mapping_batch_v2bx(?,?,?,?,?,?,?,?)";
$query = $this->db_smartone->query($sql,array($wkl, $sdate,$rtype, $number_limit,$number_offset,$pg,$pTestID,$idx));
// echo $this->db_smartone->last_query();
if ($query) {
$rows = $query->result_array();
$result = array();
$prev_test_id = "";
$last_idx = 0;
foreach($rows as $r) {
$test_id = $r["T_MappingRackID"];
if ($prev_test_id != $test_id ) {
$result[] = array(
"T_MappingRackID" => $test_id,
"T_MappingBatchID" => $r["T_MappingBatchID"],
"T_MappingRackType" => $r["T_MappingRackType"],
"T_MappingRackNo" => $r["T_MappingRackNo"],
"T_WorklistID" => $wkl,
"isconfirm" => $r["isconfirm"],
"patients" => array()
);
$last_idx = sizeof($result) - 1;
}
if ($r["T_MappingRackDetailName"] != "" ) {
$rackname = $r["T_MappingRackDetailName"];
$lab_number = $r["T_MappingRackDetailValue"];
$labid = $r["T_OrderHeaderID"];
$worklistInfo = json_decode($r["WorklistInfo"],true);
$result[$last_idx]["patients"][] = array(
"name" => $rackname,
"number" => $lab_number,
"labid" => $labid
);
}
$prev_test_id = $test_id;
}
$tot_count = sizeof($result);
$result = array("total" => $tot_count,"totalpage" => $tot_page,"limit" => $number_limit,"offset" => $number_offset, "records" => $result,
"total_display" => $tot_count, "orderid" => $idx,"q" => $this->db_smartone->last_query());
$this->sys_ok($result);
} else {
$this->sys_error_db("worklist err", $this->db_smartone);
exit;
}
}
public function search_px_v2()
{
$prm = $this->sys_input;
$max_rst = 50;
$wkl = $prm["worklist_id"];
$sdate = date('Y-m-d', strtotime($prm['sdate']));
$edate = date('Y-m-d', strtotime($prm['edate']));
$sql ="call sp_process_worklist_requirement(?,?,?)";
$query = $this->db_smartone->query($sql,array($wkl, $sdate, $edate));
if ($query) {
$rows = $query->result_array();
$result = array();
$prev_test_id = "";
$last_idx = 0;
foreach($rows as $r) {
$test_id = $r["T_TestID"];
if ($prev_test_id != $test_id ) {
$result[] = array(
"T_TestID" => $test_id,
"T_TestCode" => $r["T_TestCode"],
"T_TestName" => $r["T_TestName"],
"T_WorklistID" => $wkl,
"patients" => array()
);
$last_idx = sizeof($result) - 1;
}
if ($r["M_PatientName"] != "" ) {
$result[$last_idx]["patients"][] = array(
"name" => $r["M_PatientName"],
"id" => $r["T_OrderHeaderID"],
"did" => $r["T_OrderDetailID"],
"number" => $r["T_OrderHeaderLabNumber"],
"T_SampleTypeID" => $r["T_SampleTypeID"],
"speciment_receive" => $r["IsCollectionReceive"],
"speciment_handling" => $r["IsSamplingHandling"],
"is_cito" => $r["IsCito"],
"is_received" => $r["IsWorklistReceive"],
"is_confirm" => $r["IsWorklistConfirm"],
"barcode" => $r["BarcodeLabel"],
"requirements" => json_decode($r["Requirement"],true)
);
}
$prev_test_id = $test_id;
}
$tot_count = sizeof($result);
$result = array("total" => $tot_count, "records" => $result,
"total_display" => $tot_count, "q" => $this->db_smartone->last_query());
$this->sys_ok($result);
} else {
$this->sys_error_db("worklist err", $this->db_smartone);
exit;
}
}
public function search_px()
{
$prm = $this->sys_input;
$max_rst = 50;
$wkl = $prm["worklist_id"];
$sdate = date('Y-m-d', strtotime($prm['sdate']));
$edate = date('Y-m-d', strtotime($prm['edate']));
// QUERY TOTAL
$sql = "select count(*) total
from t_worklistdetail
join t_test on t_worklistdetailt_testid = t_testid
where T_WorklistDetailIsActive = 'Y'
and t_worklistdetailt_worklistid = ?";
$query = $this->db_smartone->query($sql, array($wkl));
if ($query) {
$tot_count = $query->result_array()[0]["total"];
}
else {
$this->sys_error_db("worklist detail count", $this->db_smartone);
exit;
}
$sql = "select T_TestID, T_TestCode, IFNULL(T_TestWorklistName, T_TestName) T_TestName
from t_worklistdetail
join t_test on t_worklistdetailt_testid = t_testid
where T_WorklistDetailIsActive = 'Y'
and t_worklistdetailt_worklistid = ?
order by t_testname asc
limit 0, {$max_rst}";
$query = $this->db_smartone->query($sql, array($wkl));
if ($query) {
$rows = $query->result_array();
foreach ($rows as $k => $v)
{
$q_x = $this->db_smartone->query("select `fn_process_worklist_patient_list`('{$v['T_TestID']}', '{$sdate}', '{$edate}') n");
// echo "select `fn_process_worklist_patient_list`('{$v['T_TestID']}', '{$sdate}', '{$edate}') n;
";
if ($q_x) {
$x = $q_x->row();
$rows[$k]['patients'] = json_decode($x->n);
}
}
$result = array("total" => $tot_count, "records" => $rows, "total_display" => sizeof($rows), "q" => $this->db_smartone->last_query());
$this->sys_ok($result);
}
else {
$this->sys_error_db("worklist test rows", $this->db_smartone);
exit;
}
}
public function search_patient($pxid, $sdate, $edate)
{
$prm = $this->sys_input;
$max_rst = 12;
// QUERY TOTAL
$sql = "select count(*) total from (
select t_orderheaderid
from t_orderheader
join t_orderdetail on t_orderdetailt_orderheaderid = t_orderheaderid
and t_orderdetailisactive = 'Y'
and t_orderdetailt_testid = ?
where t_orderheaderdate between ? and ?
and t_orderheaderisactive = 'Y'
group by t_orderheaderid) a";
$query = $this->db_smartone->query($sql, array($pxid, $sdate.' 00:00:00', $edate.' 23:59:59'));
if ($query) {
$tot_count = $query->result_array()[0]["total"];
}
else {
$this->sys_error_db("worklist patient count", $this->db_smartone);
exit;
}
$sql = "select t_orderheaderid, t_orderheaderdate, t_orderheaderlabnumber,
m_patientnoreg, m_patientname
from t_orderheader
join m_patient on t_orderheaderm_patientid = m_patientid
join t_orderdetail on t_orderdetailt_orderheaderid = t_orderheaderid
and t_orderdetailisactive = 'Y'
and t_orderdetailt_testid = ?
where t_orderheaderdate between ? and ?
and t_orderheaderisactive = 'Y'
group by t_orderheaderid
limit 0, {$max_rst}";
$query = $this->db_smartone->query($sql, array($pxid, $sdate.' 00:00:00', $edate.' 23:59:59'));
if ($query) {
$rows = $query->result_array();
$result = array("total" => $tot_count, "records" => $rows, "total_display" => sizeof($rows), "q" => $this->db_smartone->last_query());
$this->sys_ok($result);
}
else {
$this->sys_error_db("worklist patient rows", $this->db_smartone);
exit;
}
}
}