Files
2026-04-15 15:23:57 +07:00

175 lines
5.9 KiB
PHP

<?php
class Order extends MY_Controller
{
function __construct()
{
parent::__construct();
}
function reply($resp)
{
echo json_encode($resp);
exit;
}
function index()
{
$resp = array("status" => "ERR", "message" => "", "rows" => array());
$param = $this->sys_input;
$date = $param["date"];
$maxIDcito = 0;
$maxIDnormal = 0;
if (isset($param["maxID"])) {
list($maxIDcito, $maxIDnormal) = explode("|", $param["maxID"]);
}
//janji hasil hari ini
$sql = "select distinct T_OrderPromiseT_OrderHeaderID
from t_orderpromise
where T_OrderPromiseIsActive = 'Y'
and date(T_OrderPromiseDateTime) = ?
";
$qry = $this->db->query($sql, array($date));
if (!$qry) {
$resp["message"] = "ERR : " . $this->db->error()["message"] . "|"
. $this->db->last_query();
$this->reply($resp);
}
$rows = $qry->result_array();
$promise_ids = "0";
foreach ($rows as $r) {
$promise_ids .= ", " . $r["T_OrderPromiseT_OrderHeaderID"];
}
//order hari ini atu janji hasil hari ini
$sql = "select T_OrderHeaderID
from t_orderheader
join t_orderheaderaddon
on T_OrderHeaderIsActive = 'Y'
and (
( T_OrderHeaderIsCito = 'N' and T_OrderHeaderID > ? )
or
( T_OrderHeaderIsCito = 'Y' and T_OrderHeaderID > ? )
)
and (
date(T_OrderHeaderDate) = ?
or
T_OrderHeaderID in ($promise_ids)
)
and T_OrderHeaderID = T_OrderHeaderAddOnT_OrderHeaderID
-- and T_OrderHeaderAddOnVerificationDone <> 'Y'
order by T_OrderHeaderIsCito desc, T_OrderHeaderID
limit 0,10";
$qry = $this->db->query($sql, array($maxIDnormal, $maxIDcito, $date));
if (!$qry) {
$resp["message"] = "ERR : " . $this->db->error()["message"] . "|"
. $this->db->last_query();
$this->reply($resp);
}
$rows = $qry->result_array();
$s_ids = "0";
foreach ($rows as $r) {
$s_ids .= ", " . $r["T_OrderHeaderID"];
}
$sql = "
select T_OrderHeaderID,
date_format(T_OrderHeaderDate,'%Y-%m-%d %H:%i') T_OrderHeaderDate
,T_OrderHeaderLabNumber,
if (T_OrderHeaderAddOnLabNumberOrigin is null ,
T_OrderHeaderLabNumberExt,
T_OrderHeaderAddOnLabNumberOrigin )
T_OrderHeaderLabNumberExt,
T_OrderHeaderIsCito,
fn_global_patient_name(T_OrderHeaderM_PatientID) PatientName
from
t_orderheader
join t_orderheaderaddon
on T_OrderHeaderID = T_OrderHeaderAddOnT_OrderHeaderID
and T_OrderHeaderIsActive = 'Y'
and T_OrderHeaderID in ($s_ids)
order by T_OrderHeaderIsCito desc, T_OrderHeaderDate
";
$qry = $this->db->query($sql, array($maxIDnormal, $maxIDcito, $date));
if (!$qry) {
$resp["message"] = "ERR : " . $this->db->error()["message"] . "|"
. $this->db->last_query();
$this->reply($resp);
}
$rows = $qry->result_array();
$result = array();
foreach ($rows as $r) {
$result[] = array(
"id" => intVal($r["T_OrderHeaderID"]),
"date" => $r["T_OrderHeaderDate"],
"nolab" => $r["T_OrderHeaderLabNumber"],
"nolabExt" => $r["T_OrderHeaderLabNumberExt"],
"maxID" => "",
"name" => $r["PatientName"],
"isCito" => $r["T_OrderHeaderIsCito"]
);
if ($r["T_OrderHeaderIsCito"] == "Y") {
if ($r["T_OrderHeaderID"] > $maxIDcito) {
$maxIDcito = $r["T_OrderHeaderID"];
}
} else {
if ($r["T_OrderHeaderID"] > $maxIDnormal) {
$maxIDnormal = $r["T_OrderHeaderID"];
}
}
}
foreach ($result as $idx => $r) {
$result[$idx]["maxID"] = $maxIDcito . "|" . $maxIDnormal;
}
$resp["status"] = "OK";
$resp["rows"] = $result;
$this->reply($resp);
}
function get_verif() {
// OK, NOT_OK, NOT_APPLICABLE, NOT_IMPLEMENTED
$param = $this->sys_input;
$item = $param["item"];
$orderDetailID = $param["orderDetailID"];
$resp["status"] = "OK";
$result = array();
for($i=0;$i<7;$i++) {
$result[$i] = rand(0,3);
}
$resp["result"] = $result;
sleep(3);
$this->reply($resp);
}
function detail()
{
$resp = array("status" => "ERR", "message" => "", "rows" => array());
$param = $this->sys_input;
$id = $param["id"];
$sql = "select T_OrderDetailID,
T_OrderDetailT_TestName, T_OrderDetailResult,
ifnull(T_OrderDetailNat_UnitName,'') T_OrderDetailUnitName,
ifnull(T_OrderDetailNote,'') T_OrderDetailNote,
T_OrderDetailResultFlag, T_OrderDetailVerification,
ifnull(T_OrderDetailNormalValueNote,'') T_OrderDetailNormalValueNote,
T_OrderdetailNat_MethodeName
from
t_orderdetail where T_OrderDetailT_OrderHeaderID = ?
and T_OrderDetailIsActive = 'Y'
and T_OrderDetailT_TestIsResult = 'Y'
and T_OrderDetailResult <> ''
order by T_OrderDetailT_TestSasCode
";
$qry = $this->db->query($sql, array($id));
if (!$qry) {
$resp["message"] = "ERR : " . $this->db->error()["message"] . "|"
. $this->db->last_query();
$this->reply($resp);
}
$rows = $qry->result_array();
$resp["status"] = "OK";
$resp["rows"] = $rows;
$this->reply($resp);
}
}