Flatten mockup repo

This commit is contained in:
sas.fajri
2026-04-27 10:31:17 +07:00
parent bf9b9097ee
commit 8ba3d33c6d
3307 changed files with 2795939 additions and 1 deletions

View File

@@ -0,0 +1,710 @@
<?php
class Pre_analytic extends MY_Controller
{
var $db_smartone;
public function index()
{
echo "Patient API";
}
public function __construct()
{
parent::__construct();
$this->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 [ <b>$tot_px</b> 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 [ <b>$tot_px</b> 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");
$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'];
// $pg = 1;
if($rtype == '48'){
$number_limit = 46;
}else{
$number_limit = 92;
}
$number_offset = ($pg - 1) * $number_limit ;
$sql = "SELECT COUNT(T_OrderHeaderID) as total FROM
(SELECT T_OrderHeaderID
from
(SELECT T_OrderHeaderID,
fn_mapping_batch_get_worklist(T_OrderHeaderID, T_TestID) as isreceive
FROM
t_worklistdetailv2
join t_test t on T_WorklistDetailNat_TestID = t.T_TestNat_TestID
and T_WorklistDetailIsActive = 'Y'
and T_WorklistDetailT_WorklistID = $wkl
join nat_test on T_WorklistDetailNat_TestID = Nat_TestID
join t_orderdetail on t.T_TestID = T_OrderDetailT_TestID
and T_OrderDetailIsActive = 'Y'
and T_OrderDetailVerification <> 'Y'
left join t_orderpromise on T_OrderDetailT_OrderHeaderID = T_OrderPromiseT_OrderHeaderID
and T_OrderDetailT_OrderPromiseID = T_OrderPromiseID
join t_orderheader on T_OrderHeaderID = T_OrderDetailT_OrderHeaderID
and (
date(T_OrderHeaderDate) = '{$sdate}'
or
date(T_OrderPromiseDateTime) = '{$sdate}'
)
and T_OrderHeaderIsActive = 'Y'
join t_orderheaderaddon on T_OrderHeaderID = T_OrderHeaderAddonT_OrderHeaderID
join pre_analytic on PreAnalyticNat_TestID = Nat_TestID AND PreAnalyticDate = date(now()) AND PreAnalyticIsOk = 'Y'
left join t_worklist_confirm on T_OrderHeaderID = T_WorklistConfirmT_OrderHeaderID
and t.T_TestID = T_WorklistConfirmT_TestID and T_WorklistConfirmIsActive = 'Y'
GROUP BY T_OrderHeaderID) a WHERE isreceive = 'Y') b ";
// $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;
if ($query) {
$tot_count = $query->result_array()[0]["total"];
$tot_page = ceil($tot_count/$number_limit);
} else {
$this->sys_error_db("t_testattribute count", $this->db_smartone);
exit;
}
$sql ="call sp_mapping_batch_v2(?,?,?,?,?,?)";
$query = $this->db_smartone->query($sql,array($wkl, $sdate,$rtype, $number_limit,$number_offset,$pg));
// 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, "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; <br/>";
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;
}
}
}

View File

@@ -0,0 +1,184 @@
<?php
class Receive_patient extends MY_Controller
{
var $db_smartone;
public function index()
{
echo "Patient API";
}
public function __construct()
{
parent::__construct();
$this->db_smartone = $this->load->database("onedev", true);
}
public function search()
{
$prm = $this->sys_input;
$max_rst = 12;
$nolab = '%' . $prm["nolab"] . '%';
$search = '%' . $prm["search"] . '%';
if ($prm['nolab'] != '')
$nolab = "%{$prm['nolab']}%";
// QUERY TOTAL
$sql = "select count(*) total
from t_ordersample
join t_orderheader on t_ordersamplet_orderheaderid = t_orderheaderid
join m_patient on t_orderheaderm_patientid = m_patientid
join m_title on M_PatientM_TitleID = M_TitleID
join last_statussample on t_ordersamplet_orderheaderid = last_statussamplet_orderheaderid
and t_ordersamplet_sampletypeid = last_statussamplet_sampletypeid
and t_ordersamplebarcode = last_statussamplebarcode
join m_statussample on last_statussamplem_statussampleid = m_statussampleid
and m_statussamplecode = 'SAMPLING.Handling.To.Process'
where T_OrderHeaderLabNumber like ?
and M_PatientName LIKE ?";
$query = $this->db_smartone->query($sql, array($nolab, $search));
if ($query) {
$tot_count = $query->result_array()[0]["total"];
}
else {
$this->sys_error_db("m_patient count", $this->db_smartone);
exit;
}
$sql = "select T_OrderHeaderID, T_OrderHeaderLabNumber lab, T_OrderHeaderDate `date`,
M_PatientID, M_PatientNoReg,
concat(M_TitleName,' ',M_PatientName) name,
T_OrderSampleBarcode sid, '' status, last_statussampleid id
from t_ordersample
join t_orderheader on t_ordersamplet_orderheaderid = t_orderheaderid
join m_patient on t_orderheaderm_patientid = m_patientid
join m_title on M_PatientM_TitleID = M_TitleID
join last_statussample on t_ordersamplet_orderheaderid = last_statussamplet_orderheaderid
and t_ordersamplet_sampletypeid = last_statussamplet_sampletypeid
and t_ordersamplebarcode = last_statussamplebarcode
join m_statussample on last_statussamplem_statussampleid = m_statussampleid
and m_statussamplecode = 'SAMPLING.Handling.To.Process'
where T_OrderHeaderLabNumber like ?
and M_PatientName LIKE ?
limit 0, {$max_rst}";
$query = $this->db_smartone->query($sql, array($nolab, $search));
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("m_patient rows", $this->db_smartone);
exit;
}
}
public function search_sent()
{
$prm = $this->sys_input;
$max_rst = 12;
$nolab = '%' . $prm["nolab"] . '%';
$search = '%' . $prm["search"] . '%';
if ($prm['nolab'] != '')
$nolab = "%{$prm['nolab']}%";
// QUERY TOTAL
$sql = "select count(*) total
from t_ordersample
join t_orderheader on t_ordersamplet_orderheaderid = t_orderheaderid
join m_patient on t_orderheaderm_patientid = m_patientid
join m_title on M_PatientM_TitleID = M_TitleID
join last_statussample on t_ordersamplet_orderheaderid = last_statussamplet_orderheaderid
and t_ordersamplet_sampletypeid = last_statussamplet_sampletypeid
and t_ordersamplebarcode = last_statussamplebarcode
join m_statussample on last_statussamplem_statussampleid = m_statussampleid
and (m_statussamplecode = 'PROCESS.Process.From.Handling')
where T_OrderHeaderLabNumber like ?
and M_PatientName LIKE ?";
$query = $this->db_smartone->query($sql, array($nolab, $search));
if ($query) {
$tot_count = $query->result_array()[0]["total"];
}
else {
$this->sys_error_db("m_patient count", $this->db_smartone);
exit;
}
$sql = "select T_OrderHeaderID, T_OrderHeaderLabNumber lab, T_OrderHeaderDate `date`,
M_PatientID, M_PatientNoReg,
concat(M_TitleName,' ',M_PatientName) name,
T_OrderSampleBarcode sid, m_statussamplecode status, last_statussampleid id
from t_ordersample
join t_orderheader on t_ordersamplet_orderheaderid = t_orderheaderid
join m_patient on t_orderheaderm_patientid = m_patientid
join m_title on M_PatientM_TitleID = M_TitleID
join last_statussample on t_ordersamplet_orderheaderid = last_statussamplet_orderheaderid
and t_ordersamplet_sampletypeid = last_statussamplet_sampletypeid
and t_ordersamplebarcode = last_statussamplebarcode
join m_statussample on last_statussamplem_statussampleid = m_statussampleid
and (m_statussamplecode = 'PROCESS.Process.From.Handling')
where T_OrderHeaderLabNumber like ?
and M_PatientName LIKE ?
limit 0, {$max_rst}";
$query = $this->db_smartone->query($sql, array($nolab, $search));
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("m_patient rows", $this->db_smartone);
exit;
}
}
function receive()
{
$prm = $this->sys_input;
$sql = "CALL sp_process_worklist_01_receive_remove('RCV', '0', '{$prm['ids']}')";
$query = $this->db_smartone->query($sql);
if ($query)
{
$row = $query->row();
$this->sys_ok($row);
}
else {
$this->sys_error_db("handling receive", $this->db_smartone);
exit;
}
}
function remove()
{
$prm = $this->sys_input;
$sql = "CALL sp_process_worklist_01_receive_remove('RMV', '{$prm['id']}', '')";
$query = $this->db_smartone->query($sql);
if ($query)
{
$row = $query->row();
$this->sys_ok($row);
}
else {
$this->sys_error_db("worklist receive remove", $this->db_smartone);
exit;
}
}
}

View File

@@ -0,0 +1,39 @@
<?php
class Staff extends MY_Controller
{
var $db_smartone;
public function index()
{
echo "Patient API";
}
public function __construct()
{
parent::__construct();
$this->db_smartone = $this->load->database("onedev", true);
}
function search() {
if (! $this->isLogin) {
$this->sys_error("Invalid Token");
exit;
}
$prm = $this->sys_input;
$rows = [];
$query ="SELECT M_StaffID as id, M_StaffName as name, M_StaffCode as code, M_UserID as userid
FROM m_staff
JOIN m_user ON M_UserM_StaffID = M_StaffID AND M_UserIsActive = 'Y'
WHERE
M_StaffIsActive = 'Y' AND M_StaffCode = '{$prm['search']}' LIMIT 1 ";
$rows = $this->db_onedev->query($query)->row_array();
$result = array(
"total" => count($rows) ,
"records" => $rows,
);
$this->sys_ok($result);
exit;
}
}

View File

@@ -0,0 +1,352 @@
<?php
class Worklist_new extends MY_Controller
{
var $db_smartone;
public function index()
{
echo "Worklist API";
}
public function __construct()
{
parent::__construct();
$this->db_smartone = $this->load->database("onedev", true);
}
public function search_v2()
{
$prm = $this->sys_input;
$max_rst = 12;
// $nolab = '%' . $prm["nolab"] . '%';
$search = '%' . $prm["search"] . '%';
$chosen = $prm['chosen'];
// if ($prm['nolab'] != '')
// $nolab = "%{$prm['nolab']}%";
// QUERY TOTAL
$sql = "select count(*) total
from t_test
join documentation_group_detail on T_TestNat_SubGroupID = DocumentationGroupDetailNat_SubGroupID
AND DocumentationGroupDetailIsActive = 'Y'
join documentation_group on DocumentationGroupDetailDocumentationGroupID = DocumentationGroupID
AND DocumentationGroupIsActive = 'Y' AND DocumentationGroupName = 'lab'
where t_testisactive = 'Y'
and t_testisworklist = 'Y'
and t_testname like ?
and not find_in_set(t_testid, ?)";
$query = $this->db_smartone->query($sql, [$search, $chosen]);
if ($query) {
$tot_count = $query->result_array()[0]["total"];
}
else {
$this->sys_error_db("worklist count", $this->db_smartone);
exit;
}
$sql = "select T_TestID, T_TestCode,
T_TestName
from t_test
left join t_sampletype on T_TestT_SampleTypeID = T_SampleTypeID
join documentation_group_detail on T_TestNat_SubGroupID = DocumentationGroupDetailNat_SubGroupID
AND DocumentationGroupDetailIsActive = 'Y'
join documentation_group on DocumentationGroupDetailDocumentationGroupID = DocumentationGroupID
AND DocumentationGroupIsActive = 'Y' AND DocumentationGroupName = 'lab'
where T_TestIsActive = 'Y'
and T_TestIsWorklist = 'Y'
and t_testname like ?
and not find_in_set(t_testid, ?)
order by T_TestName ASC
limit 0, {$max_rst}";
$query = $this->db_smartone->query($sql, [$search, $chosen]);
if ($query) {
$rows = $query->result_array();
foreach ($rows as $k => $v)
$rows[$k]['data'] = json_decode($v['data']);
$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 rows", $this->db_smartone);
exit;
}
}
public function search()
{
$prm = $this->sys_input;
$max_rst = 50;
// $nolab = '%' . $prm["nolab"] . '%';
$search = '%' . $prm["search"] . '%';
$chosen = $prm['chosen'];
// if ($prm['nolab'] != '')
// $nolab = "%{$prm['nolab']}%";
// QUERY TOTAL
$sql = "select count(*) total
from t_test
join documentation_group_detail on T_TestNat_SubGroupID = DocumentationGroupDetailNat_SubGroupID
AND DocumentationGroupDetailIsActive = 'Y'
join documentation_group on DocumentationGroupDetailDocumentationGroupID = DocumentationGroupID
AND DocumentationGroupIsActive = 'Y' AND DocumentationGroupName = 'lab'
where t_testisactive = 'Y'
and t_testisworklist = 'Y'
and t_testname like ?
and not find_in_set(t_testid, ?)";
$query = $this->db_smartone->query($sql, [$search, $chosen]);
if ($query) {
$tot_count = $query->result_array()[0]["total"];
}
else {
$this->sys_error_db("worklist count", $this->db_smartone);
exit;
}
$sql = "select T_TestID, T_TestCode,
T_TestName
from t_test
left join t_sampletype on T_TestT_SampleTypeID = T_SampleTypeID
join documentation_group_detail on T_TestNat_SubGroupID = DocumentationGroupDetailNat_SubGroupID
AND DocumentationGroupDetailIsActive = 'Y'
join documentation_group on DocumentationGroupDetailDocumentationGroupID = DocumentationGroupID
AND DocumentationGroupIsActive = 'Y' AND DocumentationGroupName = 'lab'
where T_TestIsActive = 'Y'
and T_TestIsWorklist = 'Y'
and t_testname like ?
and not find_in_set(t_testid, ?)
order by T_TestName ASC
limit 0, {$max_rst}";
$query = $this->db_smartone->query($sql, [$search, $chosen]);
if ($query) {
$rows = $query->result_array();
foreach ($rows as $k => $v)
$rows[$k]['data'] = json_decode($v['data']);
$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 rows", $this->db_smartone);
exit;
}
}
public function save()
{
//# ambil parameter input
$prm = $this->sys_input;
$name = $prm['name'];
$test = json_encode(explode(',', $prm['test']));
$rujukan = $prm['rujukan'];
$instrument = $prm['instrument'];
$sql = "CALL sp_process_worklist_new('{$name}', '{$test}', '{$rujukan}', '{$instrument}')";
$query = $this->db_smartone->query($sql);
if ($query) {
$row = $query->row();
$result = $row;
$this->sys_ok($result);
}
else {
$this->sys_error_db("worklist save rows", $this->db_smartone);
exit;
}
}
public function save_edit()
{
//# ambil parameter input
$prm = $this->sys_input;
$name = $prm['name'];
$id = $prm['id'];
$test = json_encode(explode(',', $prm['test']));
$rujukan = $prm['rujukan'];
$instrument = $prm['instrument'];
$sql = "CALL sp_process_worklist_edit('{$id}', '{$name}', '{$test}', '{$rujukan}', '{$instrument}')";
$query = $this->db_smartone->query($sql);
if ($query) {
$row = $query->row();
$result = $row;
$this->sys_ok($result);
}
else {
$this->sys_error_db("worklist save rows", $this->db_smartone);
exit;
}
}
public function search_chosen()
{
$prm = $this->sys_input;
$max_rst = 100;
$wkl = $prm["worklist_id"];
// 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;
}
$search = "%" . $prm["search"] . "%";
$sql = "select T_TestID, T_TestCode,
concat(T_TestName,' [', ifnull(T_SampleTypeName,'Belum ada SampleType') , ']') T_TestName
from t_worklistdetail
join t_test on t_worklistdetailt_testid = t_testid
left join t_sampletype on T_TestT_SampleTypeID = T_SampleTypeID
where T_WorklistDetailIsActive = 'Y'
and T_TestName like ?
and t_worklistdetailt_worklistid = ?
order by t_testname asc
limit 0, {$max_rst}";
$query = $this->db_smartone->query($sql, array($search,$wkl));
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 test rows", $this->db_smartone);
exit;
}
}
public function search_patient($pxid, $sdate, $edate)
{
$prm = $this->sys_input;
$max_rst = 12;
// $wkl = $prm["worklist_id"];
// $edate = date('Y-m-d H:i:s');
// $sdate = date_create();
// date_sub($sdate, date_interval_create_from_date_string("30 days"));
// $sdate = date_format($sdate,"Y-m-d H:i:s");
// $search = '%' . $prm["search"] . '%';
// if ($prm['nolab'] != '')
// $nolab = "%{$prm['nolab']}%";
// 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;
}
}
function del()
{
$prm = $this->sys_input;
$wkl = $prm["worklist_id"];
// QUERY DELETE
$sql = "update t_worklistdetail
set t_worklistdetailisactive = 'N'
where T_WorklistDetailIsActive = 'Y'
and t_worklistdetailt_worklistid = ?";
$query = $this->db_smartone->query($sql, array($wkl));
if ($query) {
// QUERY DELETE
$sql = "update t_worklist
set t_worklistisactive = 'N'
where T_WorklistIsActive = 'Y'
and t_worklistid = ?";
$query = $this->db_smartone->query($sql, array($wkl));
$result = ["worklist_id" => $wkl];
$this->sys_ok($result);
exit;
}
else {
$this->sys_error_db("worklist detail delete", $this->db_smartone);
exit;
}
}
public function search_instrument()
{
$prm = $this->sys_input;
$sql = "select Nat_InstrumentID, Nat_InstrumentName
from nat_instrument
WHERE Nat_InstrumentIsActive = 'Y'
order by Nat_InstrumentName ASC";
$query = $this->db_smartone->query($sql);
if ($query) {
$rows = $query->result_array();
$result = array("records" => $rows);
$this->sys_ok($result);
}
else {
$this->sys_error_db("Instrument rows", $this->db_smartone);
exit;
}
}
}

View File

@@ -0,0 +1,224 @@
<?php
class Worklist_patient extends MY_Controller
{
var $db_smartone;
public function index()
{
echo "Worklist API";
}
public function __construct()
{
parent::__construct();
$this->db_smartone = $this->load->database("onedev", true);
}
public function search()
{
$prm = $this->sys_input;
$max_rst = 50;
// $nolab = '%' . $prm["nolab"] . '%';
// $search = '%' . $prm["search"] . '%';
// if ($prm['nolab'] != '')
// $nolab = "%{$prm['nolab']}%";
// QUERY TOTAL
$sql = "select count(*) total
from t_worklist
where T_WorklistIsActive = 'Y'
order by T_WorklistName ASC";
$query = $this->db_smartone->query($sql);
if ($query) {
$tot_count = $query->result_array()[0]["total"];
}
else {
$this->sys_error_db("worklist count", $this->db_smartone);
exit;
}
$sql = "select T_WorklistID, T_WorklistName, T_WorklistIsRujukan, Nat_InstrumentID, Nat_InstrumentName
from t_worklist
left join nat_instrument on t_worklistnat_instrumentid = nat_instrumentid
where T_WorklistIsActive = 'Y'
order by T_WorklistName ASC
limit 0, {$max_rst}";
$query = $this->db_smartone->query($sql);
if ($query) {
$rows = $query->result_array();
foreach ($rows as $k => $v)
$rows[$k]['data'] = json_decode($v['data']);
$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 rows", $this->db_smartone);
exit;
}
}
public function search_px()
{
$prm = $this->sys_input;
$max_rst = 12;
$wkl = $prm["worklist_id"];
$sdate = date('Y-m-d', strtotime($prm['sdate']));
$edate = date('Y-m-d', strtotime($prm['edate']));
// $search = '%' . $prm["search"] . '%';
// if ($prm['nolab'] != '')
// $nolab = "%{$prm['nolab']}%";
// 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)
{
$x = $this->db_smartone->query("select `fn_process_worklist_patient_list`('{$v['T_TestID']}', '{$sdate}', '{$edate}') n")->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;
// $wkl = $prm["worklist_id"];
// $edate = date('Y-m-d H:i:s');
// $sdate = date_create();
// date_sub($sdate, date_interval_create_from_date_string("30 days"));
// $sdate = date_format($sdate,"Y-m-d H:i:s");
// $search = '%' . $prm["search"] . '%';
// if ($prm['nolab'] != '')
// $nolab = "%{$prm['nolab']}%";
// 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;
}
}
function verify()
{
$prm = $this->sys_input;
$data = json_encode($prm['data']);
$sql = "CALL sp_sampling_handling_02_process_reject('PRC', '{$prm['orderid']}', '{$prm['laststatusid']}', '{$data}')";
$query = $this->db_smartone->query($sql);
if ($query)
{
$row = $query->row();
$this->sys_ok($row);
}
else {
$this->sys_error_db("verification verify", $this->db_smartone);
exit;
}
}
function reject()
{
$prm = $this->sys_input;
$data = json_encode($prm['data']);
$sql = "CALL sp_sampling_handling_02_process_reject('RJC', '{$prm['orderid']}', '{$prm['laststatusid']}', '{$data}')";
$query = $this->db_smartone->query($sql);
if ($query)
{
$row = $query->row();
$this->sys_ok($row);
}
else {
$this->sys_error_db("verification reject", $this->db_smartone);
exit;
}
}
}

View File

@@ -0,0 +1,224 @@
<?php
class Worklist_patient extends MY_Controller
{
var $db_smartone;
public function index()
{
echo "Worklist API";
}
public function __construct()
{
parent::__construct();
$this->db_smartone = $this->load->database("onedev", true);
}
public function search()
{
$prm = $this->sys_input;
$max_rst = 12;
// $nolab = '%' . $prm["nolab"] . '%';
// $search = '%' . $prm["search"] . '%';
// if ($prm['nolab'] != '')
// $nolab = "%{$prm['nolab']}%";
// QUERY TOTAL
$sql = "select count(*) total
from t_worklist
where T_WorklistIsActive = 'Y'
order by T_WorklistName ASC";
$query = $this->db_smartone->query($sql);
if ($query) {
$tot_count = $query->result_array()[0]["total"];
}
else {
$this->sys_error_db("worklist count", $this->db_smartone);
exit;
}
$sql = "select T_WorklistID, T_WorklistName, T_WorklistIsRujukan, Nat_InstrumentID, Nat_InstrumentName
from t_worklist
left join nat_instrument on t_worklistnat_instrumentid = nat_instrumentid
where T_WorklistIsActive = 'Y'
order by T_WorklistName ASC";
//limit 0, {$max_rst}";
$query = $this->db_smartone->query($sql);
if ($query) {
$rows = $query->result_array();
foreach ($rows as $k => $v)
$rows[$k]['data'] = json_decode($v['data']);
$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 rows", $this->db_smartone);
exit;
}
}
public function search_px()
{
$prm = $this->sys_input;
$max_rst = 12;
$wkl = $prm["worklist_id"];
$sdate = date('Y-m-d', strtotime($prm['sdate']));
$edate = date('Y-m-d', strtotime($prm['edate']));
// $search = '%' . $prm["search"] . '%';
// if ($prm['nolab'] != '')
// $nolab = "%{$prm['nolab']}%";
// 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)
{
$x = $this->db_smartone->query("select `fn_process_worklist_patient_list`('{$v['T_TestID']}', '{$sdate}', '{$edate}') n")->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;
// $wkl = $prm["worklist_id"];
// $edate = date('Y-m-d H:i:s');
// $sdate = date_create();
// date_sub($sdate, date_interval_create_from_date_string("30 days"));
// $sdate = date_format($sdate,"Y-m-d H:i:s");
// $search = '%' . $prm["search"] . '%';
// if ($prm['nolab'] != '')
// $nolab = "%{$prm['nolab']}%";
// 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;
}
}
function verify()
{
$prm = $this->sys_input;
$data = json_encode($prm['data']);
$sql = "CALL sp_sampling_handling_02_process_reject('PRC', '{$prm['orderid']}', '{$prm['laststatusid']}', '{$data}')";
$query = $this->db_smartone->query($sql);
if ($query)
{
$row = $query->row();
$this->sys_ok($row);
}
else {
$this->sys_error_db("verification verify", $this->db_smartone);
exit;
}
}
function reject()
{
$prm = $this->sys_input;
$data = json_encode($prm['data']);
$sql = "CALL sp_sampling_handling_02_process_reject('RJC', '{$prm['orderid']}', '{$prm['laststatusid']}', '{$data}')";
$query = $this->db_smartone->query($sql);
if ($query)
{
$row = $query->row();
$this->sys_ok($row);
}
else {
$this->sys_error_db("verification reject", $this->db_smartone);
exit;
}
}
}