664 lines
30 KiB
PHP
664 lines
30 KiB
PHP
<?php
|
|
class Rv_px extends MY_Controller
|
|
{
|
|
var $db_smartone;
|
|
|
|
public function index()
|
|
{
|
|
echo "RE Px API";
|
|
}
|
|
|
|
public function __construct()
|
|
{
|
|
parent::__construct();
|
|
$this->db_smartone = $this->load->database("onedev", true);
|
|
}
|
|
|
|
function multi_rule($order_header_id, $detail_id,$nat_test_id) {
|
|
//check if multirules exists for nat_test_id
|
|
$reflex_result = array();
|
|
$title = array();
|
|
$sql = "select *
|
|
from t_orderdetail where T_OrderDetailID = ?";
|
|
$qry = $this->db_smartone->query($sql,array($detail_id));
|
|
if (! $qry ) {
|
|
$title["title"] = "Multirule Tidak berlaku";
|
|
$title["sub_title"] = "Pemeriksaan tidak ditemukan dalam order";
|
|
return array("X","Multirule tidak berlaku|[OrderDetail Not Found]",$reflex_result, $title);
|
|
}
|
|
$rows = $qry->result_array();
|
|
if (count($rows) == 0 ) {
|
|
$title["title"] = "Multirule Tidak berlaku";
|
|
$title["sub_title"] = "Pemeriksaan tidak ditemukan dalam order";
|
|
return array("X","Multirule tidak berlaku|[OrderDetail Not Found]",$reflex_result, $title);
|
|
}
|
|
$r = $rows[0];
|
|
// get condition
|
|
$theTestName = $r["T_OrderDetailT_TestName"];
|
|
if ($r["T_OrderDetailNat_NormalValueID"] == 0 ) {
|
|
$title["title"] = "Multirule $theTestName";
|
|
$title["sub_title"] = "Tidak berlaku, karena Normal Value tidak ada";
|
|
return array("X","Multirule $theTestName|tidak berlaku [Normal Value Not Found]",$reflex_result, $title);
|
|
}
|
|
$minValue = $r["T_OrderDetailMinValue"];
|
|
$maxValue = $r["T_OrderDetailMaxValue"];
|
|
$minInclusive = $r["T_OrderDetailMinValueInclusive"];
|
|
$maxInclusive = $r["T_OrderDetailMaxValueInclusive"];
|
|
$methodeID = $r["T_OrderDetailNat_MethodeID"];
|
|
$methode = $r["T_OrderdetailNat_MethodeName"];
|
|
$value = $r["T_OrderDetailResult"];
|
|
$testName = $r["T_OrderDetailT_TestName"];
|
|
$title["title"] = "Multirule $theTestName";
|
|
if (! is_numeric($value) ) {
|
|
$title["sub_title"] = "Tidak berlaku, karena hasil bukan numerik";
|
|
return array("X","Multirule $theTestName|tidak berlaku [Result not numeric]",$reflex_result, $title);
|
|
}
|
|
try {
|
|
$n_value = floatval($value);
|
|
$n_minValue = floatval($minValue);
|
|
$n_maxValue = floatval($maxValue);
|
|
} catch(Exception $e) {
|
|
$title["title"] = "Multirule $theTestName";
|
|
$title["sub_title"] = "Tidak berlaku, karena batasan Nilai Normal tidak numerik";
|
|
return array("X","Multirule $theTestName|tidak berlaku [Min/Max Value not numeric]",$reflex_result, $title);
|
|
}
|
|
// conndition 1 : L , 2 : N , 3 : H
|
|
$conditionID = 0;
|
|
$condition = "Unknown";
|
|
if ($n_value < $n_minValue || ( $n_value <= $n_minValue && $minInclusive == "N" ) ) {
|
|
$conditionID = 1;
|
|
$condition = "Low";
|
|
} else if ( $n_value > $n_maxValue || ( $n_value >= $n_maxValue && $maxInclusive == "N") ) {
|
|
$conditionID = 3;
|
|
$condition = "High";
|
|
} else {
|
|
$conditionID = 2;
|
|
$condition = "Normal";
|
|
}
|
|
if ($conditionID == 0 ) {
|
|
$title["title"] = "Multirule $theTestName";
|
|
$title["sub_title"] = "Tidak berlaku, karena kondisi Low/Normal/High tidak bisa ditentukan.";
|
|
return array("X","Multirule $theTestName|tidak berlaku [Low/Normal/High tidak bisa di tentukan]",$reflex_result, $title);
|
|
}
|
|
//check multi rule
|
|
$sql = "select * from nat_multirule
|
|
where NatMultiruleIsActive = 'Y' and NatMultiruleNat_TestID = ?
|
|
and ( NatMultiruleNat_MethodeID is null or NatMultiruleNat_MethodeID = 0 or NatMultiruleNat_MethodeID = ? )
|
|
and NatMultiruleNat_ConditionID = ?
|
|
order by NatMultiruleNat_MethodeID desc
|
|
limit 0,1";
|
|
$qry = $this->db_smartone->query($sql,array($nat_test_id, $methodeID, $conditionID));
|
|
if (! $qry) {
|
|
$title["title"] = "Multirule $theTestName";
|
|
$title["sub_title"] = "Tidak berlaku, karena masterdata $theTestName untuk kondisi $condition dengan methode $methode tidak di temukan.";
|
|
return array("X","Multirule $theTestName|tidak ditemukan [$condition, $methode]",$reflex_result, $title);
|
|
}
|
|
$rows = $qry->result_array();
|
|
if (count($rows) == 0 ) {
|
|
$title["title"] = "Multirule $theTestName";
|
|
// Normal tidak memiliki Reflex Test
|
|
if ($conditionID == 2 ) {
|
|
$title["sub_title"] = "Terpenuhi, $theTestName untuk kondisi $condition dengan methode $methode tidak memiliki reflex test.";
|
|
return array("Y","Multirule $theTestName|terpenuhi [$condition, $methode]",$reflex_result, $title);
|
|
}
|
|
$title["sub_title"] = "Tidak berlaku, karena masterdata $theTestName untuk kondisi $condition dengan methode $methode tidak di temukan.";
|
|
return array("X","Multirule $theTestName|tidak ditemukan [$condition, $methode]",$reflex_result, $title);
|
|
}
|
|
$r = $rows[0];
|
|
$mrID = $r["NatMultiruleID"];
|
|
$title["overlimit"] = false;
|
|
if ($conditionID == 1 ) {
|
|
try {
|
|
$n_x_low = floatval($r["NatMultiruleExtraLow"]);
|
|
} catch(Exception $e) {
|
|
$title["title"] = "Multirule $theTestName";
|
|
$title["sub_title"] = "Tidak berlaku, karena masterdata extra low bukan numerik";
|
|
return array("X","Multirule $theTestName invalid Extra Low [$condition, $methode]",$reflex_result, $title);
|
|
}
|
|
if ($n_x_low > $n_value ) {
|
|
$title["overlimit"] = true;
|
|
$title["title"] = "Multirule $theTestName";
|
|
$title["sub_title"] = "Tidak berlaku, karena hasil kurang dari extra low, " . $r["NatMultiruleExtraLow"] ;
|
|
$title["sub_title"] = "Hasil $theTestName extra low < " . $r["NatMultiruleExtraLow"] ;
|
|
return array("X","Multirule $theTestName kurang dari Extra Low [$condition, $methode]",$reflex_result, $title);
|
|
}
|
|
}
|
|
if ($conditionID == 2 ) {
|
|
try {
|
|
$n_x_high = floatval($r["NatMultiruleExtraHigh"]);
|
|
} catch(Exception $e) {
|
|
$title["title"] = "Multirule $theTestName";
|
|
$title["sub_title"] = "Tidak berlaku, karena masterdata extra high bukan numerik";
|
|
$title["sub_title"] = "Hasil $theTestName extra high > " . $r["NatMultiruleExtraLow"] ;
|
|
return array("X","Multirule $theTestName invalid Extra High [$condition, $methode]",$reflex_result, $title);
|
|
}
|
|
if ($n_x_high < $n_value ) {
|
|
$title["overlimit"] = true;
|
|
$title["title"] = "Multirule $theTestName";
|
|
$title["sub_title"] = "Tidak berlaku, karena hasil lebih besar dari extra high, " . $r["NatMultiruleExtraHigh"] ;
|
|
return array("X","Multirule $theTestName lebih dari Extra Low [$condition, $methode]",$reflex_result, $title);
|
|
}
|
|
}
|
|
|
|
//Argument 1
|
|
|
|
//check reflex
|
|
$sql = "select distinct Nat_ReflexTestID,
|
|
Nat_TestName, Nat_ConditionName, Nat_TestID,
|
|
Nat_ReflexTestNat_ConditionID,
|
|
T_OrderDetailNat_NormalValueID, T_OrderDetailResult, T_OrderDetailNat_MethodeName,
|
|
T_OrderDetailMaxValueInclusive, T_OrderDetailMinValueInclusive,
|
|
T_OrderDetailMinValue, T_OrderDetailMaxValue, T_OrderDetailVerification
|
|
from
|
|
nat_reflextest
|
|
join nat_condition on Nat_ReflexTestNat_ConditionID = Nat_ConditionID and Nat_ReflexTestIsActive = 'Y'
|
|
join nat_test on Nat_ReflexTestNat_TestID = Nat_TestID and Nat_TestIsActive = 'Y'
|
|
and Nat_ReflexTestIsActive = 'Y' and Nat_ReflexTestNatMultiRuleID = ?
|
|
join t_test on Nat_TestID = T_TestNat_TestID and T_TestIsActive = 'Y'
|
|
join t_orderdetail on T_TestID = T_OrderDetailT_TestID
|
|
and T_OrderDetailIsActive = 'Y' and T_OrderDetailT_OrderHeaderID = ?
|
|
order by Nat_ReflexTestID, Nat_ReflexTestNat_RelationID desc";
|
|
$qry = $this->db_smartone->query($sql, array($mrID, $order_header_id));
|
|
//if ( $nat_test_id == 4098 ) {
|
|
// echo $this->db_smartone->last_query();
|
|
//}
|
|
//echo "\n";
|
|
if (! $qry ) {
|
|
$title["title"] = "Multirule $theTestName";
|
|
$title["sub_title"] = "Tidak berlaku, karena $theTestName dengan kondisi $condition, tidak memiliki masterdata Argument 1";
|
|
return array("X","Multirule $theTestName , Argument 1 tidak ditemukan [$condition, $methode]",$reflex_result, $title);
|
|
}
|
|
$rows = $qry->result_array();
|
|
if (count($rows) == 0 ) {
|
|
$title["title"] = "Multirule $theTestName";
|
|
$title["sub_title"] = "Tidak berlaku, karena $theTestName dengan kondisi $condition, tidak memiliki Argument 1";
|
|
return array("X","Multirule $theTestName , Reflex Test tidak ditemukan [$condition, $methode]",$reflex_result, $title);
|
|
}
|
|
$flag_mandatory_err = false;
|
|
$flag_optional_err = false;
|
|
// testname, is_mandatory status , note
|
|
$flag_optional_valid = false;
|
|
$flag_mandatory_valid = true;
|
|
$have_mandatory = false;
|
|
|
|
$title["sub_title"] = "$theTestName hasil $condition";
|
|
//Listing Argument List
|
|
$argument_1_list = array();
|
|
$arr_px_1 = array();
|
|
foreach($rows as $r) {
|
|
$conditionID = $r["Nat_ReflexTestNat_ConditionID"];
|
|
$conditionName = $r["Nat_ConditionName"];
|
|
$nat_TestID = $r["Nat_TestID"];
|
|
|
|
if ( isset($arr_px_1[$nat_TestID])) {
|
|
$idx = $arr_px_1[$nat_TestID] ;
|
|
} else {
|
|
$argument_1_list[] = array (
|
|
"px" => $r["Nat_TestName"],
|
|
"pxID" => $r["Nat_TestID"],
|
|
"reflexID" => $r["Nat_ReflexTestID"],
|
|
"is_ok" => false,
|
|
"is_show_mandatory" => false,
|
|
"condition" => $conditionName,
|
|
"conditionID" => $conditionID,
|
|
"note" => ""
|
|
);
|
|
$idx = count($argument_1_list) -1;
|
|
$arr_px_1[$nat_TestID] = $idx;
|
|
}
|
|
// nat test ini sdh terpenuhi
|
|
if ($argument_1_list[$idx]["is_ok"] === true ) continue;
|
|
|
|
if ( $r["T_OrderDetailVerification"] != "Y" ) {
|
|
$argument_1_list[$idx]["note"] = "Belum di verifikasi";
|
|
continue;
|
|
}
|
|
if ( !($r["T_OrderDetailNat_NormalValueID"] > 0) ) {
|
|
$argument_1_list[$idx]["note"] = "Belum memiliki nilai normal";
|
|
continue;
|
|
}
|
|
try {
|
|
$d_value = floatval($r["T_OrderDetailResult"]);
|
|
$d_min_value = floatval($r["T_OrderDetailMinValue"]);
|
|
$d_max_value = floatval($r["T_OrderDetailMaxValue"]);
|
|
$d_min_inclusive = $r["T_OrderDetailMinValueInclusive"];
|
|
$d_max_inclusive = $r["T_OrderDetailMaxValueInclusive"];
|
|
$condition = "Unknown";
|
|
$argument_1_list[$idx]["result"] = $condition;
|
|
if ($d_value < $d_min_value || ( $d_value <= $d_min_value && $d_min_inclusive == "N" ) ) {
|
|
$conditionID = 1;
|
|
$condition = "Low";
|
|
} else if ( $d_value > $d_max_value || ( $d_value >= $d_max_value && $d_max_inclusive == "N") ) {
|
|
$conditionID = 3;
|
|
$condition = "High";
|
|
} else {
|
|
$conditionID = 2;
|
|
$condition = "Normal";
|
|
}
|
|
if ($conditionID == 0 ) {
|
|
$argument_1_list[$idx]["note"] = " kondisi [ Low/Normal/Hight ] tidak bisa ditentukan ";
|
|
continue;
|
|
}
|
|
$argument_1_list[$idx]["result"] = $condition;
|
|
if ( $conditionID == $r["Nat_ReflexTestNat_ConditionID"]) {
|
|
$argument_1_list[$idx]["note"] = "hasil $condition, Argument 1 " . $r["Nat_ConditionName"] ;
|
|
$argument_1_list[$idx]["is_ok"] = true;
|
|
$argument_1_list[$idx]["is_show_mandatory"] = true;
|
|
$argument_1_list[$idx]["reflexID"] = $r["Nat_ReflexTestID"];
|
|
$argument_1_list[$idx]["condition"] = $conditionName;
|
|
$argument_1_list[$idx]["conditionID"] = $conditionID;
|
|
} else {
|
|
$argument_1_list[$idx]["note"] = "hasil $condition, Argument 1 " . $r["Nat_ConditionName"] ;
|
|
$argument_1_list[$idx]["is_ok"] = false;
|
|
$argument_1_list[$idx]["reflexID"] = $r["Nat_ReflexTestID"];
|
|
}
|
|
} catch(Exception $e) {
|
|
$argument_1_list[$idx]["note"] = " kondisi [ Low/Normal/Hight ] tidak bisa ditentukan ( konversi numerik )";
|
|
continue;
|
|
}
|
|
}
|
|
$flag_error = false;
|
|
$s_ids = "0";
|
|
foreach($argument_1_list as $list ) {
|
|
if ( $list["is_ok"] == false ) {
|
|
$flag_error = true;
|
|
continue;
|
|
}
|
|
$s_ids .= "," . $list["reflexID"] ;
|
|
}
|
|
// Mandatory
|
|
$sql = "select Nat_ReflexTestID,
|
|
Nat_TestName, Nat_ConditionName, Nat_TestID,
|
|
Nat_ReflexMandatoryNat_ConditionID, Nat_ConditionName,
|
|
T_OrderDetailNat_NormalValueID, T_OrderDetailResult, T_OrderDetailNat_MethodeName,
|
|
T_OrderDetailMaxValueInclusive, T_OrderDetailMinValueInclusive,
|
|
T_OrderDetailMinValue, T_OrderDetailMaxValue, T_OrderDetailVerification
|
|
from
|
|
nat_reflextest
|
|
join nat_reflexmandatory on Nat_ReflexMandatoryNat_ReflexTestID in ( $s_ids )
|
|
and Nat_ReflexTestID = Nat_ReflexMandatoryNat_ReflexTestID and Nat_ReflexTestIsActive = 'Y'
|
|
join nat_condition on Nat_ReflexMandatoryNat_ConditionID = Nat_ConditionID and Nat_ReflexMandatoryIsActive = 'Y'
|
|
join nat_test on Nat_ReflexMandatoryNat_TestID = Nat_TestID and Nat_TestIsActive = 'Y'
|
|
and Nat_ReflexMandatoryIsActive = 'Y'
|
|
join t_test on Nat_TestID = T_TestNat_TestID and T_TestIsActive = 'Y'
|
|
join t_orderdetail on T_TestID = T_OrderDetailT_TestID
|
|
and T_OrderDetailIsActive = 'Y' and T_OrderDetailT_OrderHeaderID = ?
|
|
order by Nat_ReflexTestID, Nat_ReflexTestNat_RelationID desc";
|
|
$qry = $this->db_smartone->query($sql, array($order_header_id));
|
|
$reflex_id_not_ok = array();
|
|
if ($qry) {
|
|
$rows = $qry->result_array();
|
|
foreach($rows as $r) {
|
|
$is_ok = false;
|
|
$is_display = true;
|
|
$result = "";
|
|
|
|
if ( $r["T_OrderDetailVerification"] != "Y" ) {
|
|
$result = "Belum di verifikasi";
|
|
continue;
|
|
}
|
|
if ( !($r["T_OrderDetailNat_NormalValueID"] > 0) ) {
|
|
$result = "Belum memiliki nilai normal";
|
|
continue;
|
|
}
|
|
if ($result == "" ) {
|
|
try {
|
|
$d_value = floatval($r["T_OrderDetailResult"]);
|
|
$d_min_value = floatval($r["T_OrderDetailMinValue"]);
|
|
$d_max_value = floatval($r["T_OrderDetailMaxValue"]);
|
|
$d_min_inclusive = $r["T_OrderDetailMinValueInclusive"];
|
|
$d_max_inclusive = $r["T_OrderDetailMaxValueInclusive"];
|
|
$condition = "Unknown";
|
|
if ($d_value < $d_min_value || ( $d_value <= $d_min_value && $d_min_inclusive == "N" ) ) {
|
|
$conditionID = 1;
|
|
$condition = "Low";
|
|
} else if ( $d_value > $d_max_value || ( $d_value >= $d_max_value && $d_max_inclusive == "N") ) {
|
|
$conditionID = 3;
|
|
$condition = "High";
|
|
} else {
|
|
$conditionID = 2;
|
|
$condition = "Normal";
|
|
}
|
|
if ($conditionID == 0 ) {
|
|
$result = " kondisi [ Low/Normal/Hight ] tidak bisa ditentukan ";
|
|
}
|
|
} catch(Exception $e) {
|
|
$result = " kondisi [ Low/Normal/Hight ] tidak bisa ditentukan ( konversi numerik )";
|
|
}
|
|
if ( $conditionID == $r["Nat_ReflexMandatoryNat_ConditionID"]) {
|
|
$result = $condition;
|
|
$is_ok = true;
|
|
} else {
|
|
$result = $condition;
|
|
$is_ok = false;
|
|
}
|
|
}
|
|
$mandatory[] = array(
|
|
"reflexID" => $r["Nat_ReflexTestID"],
|
|
"px" => $r["Nat_TestName"],
|
|
"condition" => $r["Nat_ConditionName"],
|
|
"is_display" => $is_display,
|
|
"result" => $result,
|
|
"is_ok" => $is_ok
|
|
);
|
|
if (! $is_ok ) $reflex_id_not_ok[] = $r["Nat_ReflexTestID"];
|
|
}
|
|
}
|
|
foreach($argument_1_list as $idx => $l ) {
|
|
$argument_1_list[$idx]["is_ok_argument"] = false;
|
|
if ($argument_1_list[$idx]["is_ok"] ) {
|
|
$argument_1_list[$idx]["is_ok_argument"] = true ;
|
|
}
|
|
if ( in_array($l["reflexID"], $reflex_id_not_ok ) ) {
|
|
$argument_1_list[$idx]["is_ok"] = false;
|
|
}
|
|
$argument_1_list[$idx]["mandatory"] = array();
|
|
foreach($mandatory as $m ) {
|
|
if ( $m["reflexID"] == $l["reflexID"] ) {
|
|
$argument_1_list[$idx]["mandatory"][] = $m;
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
$flag_error = false;
|
|
foreach($argument_1_list as $list ) {
|
|
if ( $list["is_ok"] == false ) {
|
|
$flag_error = true;
|
|
break;
|
|
}
|
|
}
|
|
|
|
$title["argument_1"] = $argument_1_list;
|
|
|
|
if ( ! $flag_error ) {
|
|
return array("Y","Multirule $theTestName , Reflex Test terpenuhi",$reflex_result, $title);
|
|
} else {
|
|
return array("N","Multirule $theTestName , Reflex Test tidak terpenuhi",$reflex_result, $title);
|
|
}
|
|
}
|
|
public function single_validation() {
|
|
$prm = $this->sys_input;
|
|
$od_id = $prm["order_id"];
|
|
$validation = $prm["validation"];
|
|
$userID = $this->sys_user["M_UserID"];
|
|
if ( ! $this->isLogin ) {
|
|
echo json_encode(
|
|
array("status"=>"ERR", "message"=> "Invalid Token")
|
|
);
|
|
exit;
|
|
}
|
|
if ($validation == "Y") {
|
|
$sql = "update t_orderdetail
|
|
set T_OrderDetailValidation = 'Y'
|
|
, T_OrderDetailValUserID = ?
|
|
, T_OrderDetailValDate = now()
|
|
where T_OrderDetailID = ?
|
|
and T_OrderDetailVerification = 'Y'";
|
|
} else {
|
|
$sql = "update t_orderdetail
|
|
set T_OrderDetailValidation = 'N'
|
|
, T_OrderDetailValUserID = ?
|
|
, T_OrderDetailValDate = now()
|
|
where T_OrderDetailID = ?";
|
|
}
|
|
$this->db_smartone->query($sql, array($userID,$od_id));
|
|
$this->db_smartone->query("call sp_valid_parent(?)", array($od_id));
|
|
$this->clean_mysqli_connection($this->db_smartone->conn_id);
|
|
|
|
//log
|
|
$order = $this->db_smartone->select('T_OrderDetailT_OrderHeaderID id, T_OrderHeaderLabNumber lab_number,
|
|
T_OrderDetailT_TestName, T_OrderDetailID, T_OrderDetailResult', false)
|
|
->join('t_orderheader', 'T_OrderHeaderID = T_OrderDetailT_OrderHeaderID')
|
|
->where('T_OrderDetailID', $od_id)
|
|
->get('t_orderdetail')
|
|
->row();
|
|
$dblog = $this->load->database("onelog", true);
|
|
if ($validation == "Y") {
|
|
$dblog->set('Log_ProcessCode', 'PROCESS.Result.Validation')
|
|
->set('Log_ProcessOrderID', $order->id)
|
|
->set('Log_ProcessOrderNumber', $order->lab_number)
|
|
->set('Log_ProcessJson', json_encode($data))
|
|
->set('Log_ProcessUserID', $this->sys_user['M_UserID'])
|
|
->insert('log_process');
|
|
} else {
|
|
$dblog->set('Log_ProcessCode', 'PROCESS.Result.Unvalidation')
|
|
->set('Log_ProcessOrderID', $order->id)
|
|
->set('Log_ProcessOrderNumber', $order->lab_number)
|
|
->set('Log_ProcessJson', json_encode($data))
|
|
->set('Log_ProcessUserID', $this->sys_user['M_UserID'])
|
|
->insert('log_process');
|
|
}
|
|
if ($validation == "Y") {
|
|
$this->load->library("Txbranchstatus");
|
|
$this->txbranchstatus->update("VALIDATION",$od_id,$this->sys_user['M_StaffName']);
|
|
}
|
|
|
|
$result = array("status"=>"OK","message" => "");
|
|
$this->sys_ok($result);
|
|
}
|
|
|
|
public function search()
|
|
{
|
|
$prm = $this->sys_input;
|
|
$max_rst = 99;
|
|
|
|
$id = $prm["order_id"];
|
|
$lang = $this->lang_default_code;
|
|
$lang_id = isset($prm['lang_id']) ? $prm['lang_id'] : '0';
|
|
|
|
if ($lang_id != 0)
|
|
{
|
|
$l = $this->db_smartone->where("Nat_LangID", $lang_id)->get("nat_lang")->row();
|
|
$lang = $l->Nat_LangCode;
|
|
}
|
|
|
|
$tot_count = 0;
|
|
|
|
// if ($lang == $this->lang_default_code)
|
|
// {
|
|
$sql = "SELECT a1.*, cOUNT(a2.T_OrderDetailID) level
|
|
FROM (
|
|
SELECT x.T_OrderDetailVerification verification,
|
|
IFNULL(y.T_OrderDetailT_TestID, x.T_OrderDetailT_TestID) t_testid,
|
|
IFNULL(y.T_OrderDetailT_TestName, y.T_OrderDetailT_TestName) t_testname,
|
|
y.T_OrderDetailResult result, y.T_OrderDetailResult result_old,
|
|
y.T_OrderDetailNote note, y.T_OrderDetailNote note_old, x.T_OrderDetailID id,
|
|
x.T_OrderDetailT_TestIsResult is_result, a.T_TestIsQuantitative is_quantitative,
|
|
x.T_OrderDetailResultFlag result_flag,
|
|
x.T_OrderDetailValMRState mr_state,
|
|
x.T_OrderDetailValidation validation,
|
|
x.T_OrderDetailValidation validation_old,
|
|
y.T_OrderDetailReqStatus sample_handling_perfect,
|
|
y.T_OrderDetailNat_NormalValueID normal_id,
|
|
y.T_OrderDetailNormalValueNote normal_note, y.T_OrderDetailNat_UnitName unit_name,
|
|
y.T_OrderdetailNat_MethodeID methode_id, y.T_OrderdetailNat_MethodeName methode_name,
|
|
a.T_TestNat_TestID nattest_id, a.T_TestID tx_id, count(T_ResultInstrumentID) as result_instrument_n,
|
|
x.T_OrderDetailVerification, T_OrderSampleReceive sample_receive,
|
|
T_OrderSampleProcessing sample_processing, T_OrderSampleWorklistReceive sample_worklist_receive,
|
|
PreAnalyticID pre_analytic,
|
|
T_OrderHeaderID order_id, y.T_OrderDetailT_TestSasCode test_sas_code,
|
|
tx.T_TestSasCode,
|
|
T_OrderDetailAddOnResample `resample`, T_OrderDetailAddOnResampleStatus resample_status,
|
|
T_OrderDetailAddOnRef ref,
|
|
fn_process_group_result(x.T_OrderDetailT_TestID) ResultGroupName
|
|
FROM t_orderdetail x
|
|
|
|
JOIN t_test tx ON x.T_OrderDetailT_TestID = T_TestID
|
|
JOIN documentation_group_detail ON DocumentationGroupDetailNat_SubGroupID = tx.T_TestNat_SubGroupID
|
|
AND DocumentationGroupDetailIsActive = 'Y'
|
|
JOIN documentation_group ON DocumentationGroupDetailDocumentationGroupID = DocumentationGroupID
|
|
AND DocumentationGroupName = 'lab'
|
|
|
|
LEFT JOIN t_orderdetail y ON x.T_OrderDetailT_TestSasCode LIKE CONCAT(y.T_OrderDetailT_TestSasCode, '%')
|
|
AND x.T_OrderDetailT_OrderHeaderID = y.T_OrderDetailT_OrderHeaderID
|
|
AND y.T_OrderDetailIsActive = 'Y'
|
|
|
|
LEFT JOIN t_orderdetailaddon ON x.T_OrderDetailID = T_OrderDetailAddOnT_OrderDetailID
|
|
|
|
JOIN t_orderheader ON y.T_OrderDetailT_OrderHeaderID = T_OrderHeaderID
|
|
LEFT JOIN t_test a ON y.T_OrderDetailT_TestID = a.T_TestID
|
|
AND a.T_TestIsNonLab = ''
|
|
LEFT JOIN (SELECT T_OrderSampleT_SampleTypeID, T_OrderSampleReceive, T_OrderSampleProcessing, T_OrderSampleWorklistReceive
|
|
FROM t_ordersample WHERE T_OrderSampleT_OrderHeaderID = ?
|
|
AND T_OrderSampleIsactive = 'Y'
|
|
GROUP BY T_OrderSampleT_SampleTypeID) os ON a.T_TestT_SampleTypeID = os.T_OrderSampleT_SampleTypeID
|
|
|
|
LEFT JOIN t_resultinstrument ON T_ResultInstrumentT_OrderDetailID = x.T_OrderDetailID
|
|
|
|
LEFT JOIN pre_analytic ON PreAnalyticNat_TestID = a.T_TestNat_TestID AND PreAnalyticDate = date(now()) and PreAnalyticIsActive = 'Y'
|
|
WHERE x.T_OrderDetailT_OrderHeaderID = ?
|
|
AND x.T_OrderDetailIsActive = 'Y'
|
|
GROUP BY y.T_OrderDetailT_TestID
|
|
ORDER BY y.T_OrderDetailT_TestSasCode ASC
|
|
) a1
|
|
|
|
LEFT JOIN t_orderdetail a2 ON a2.T_OrderDetailT_OrderHeaderID = a1.order_id
|
|
AND a2.T_OrderDetailIsActive = 'Y'
|
|
AND a1.test_sas_code LIKE CONCAT(a2.T_OrderDetailT_testSasCode, '%')
|
|
|
|
GROUP BY a1.t_testid
|
|
order by a1.T_TestSasCode
|
|
";
|
|
$query = $this->db_smartone->query($sql, [$id, $id]);
|
|
|
|
|
|
if ($query) {
|
|
$rst = [];
|
|
$rows = $query->result_array();
|
|
|
|
// echo json_encode($rows); return;
|
|
// echo $this->db_smartone->last_query(); return;
|
|
foreach($rows as $k => $v)
|
|
{
|
|
if ($v['is_result'] == "Y" && $v['is_quantitative'] == "N")
|
|
{
|
|
$v['template'] = [];
|
|
$x = $this->db_smartone->query("CALL sp_master_resulttemplate_get('{$v['t_testid']}')");
|
|
$this->clean_mysqli_connection($this->db_smartone->conn_id);
|
|
if ($x)
|
|
$v['template'] = $x->result_array();
|
|
}
|
|
|
|
|
|
// Sample Handling & Verification Perfect
|
|
$v['mr_state'] = "X";
|
|
//$x_check = " check : " . $v["T_OrderDetailVerification"] . " : " . $v["is_quantitative"] . " : " . $v["sample_handling_perfect"];
|
|
$x_check = "";
|
|
if ($v['sample_handling_perfect'] == 'X')
|
|
{
|
|
//cek ulang sample_handling_perfect nya
|
|
$y = $this->db_smartone->query("SELECT fn_process_sample_handling_perfect('{$id}', '{$v['t_testid']}') c")
|
|
->row();
|
|
$v['sample_handling_perfect'] = $y->c;
|
|
if ( $v['sample_handling_perfect'] == "Y" ) {
|
|
if ($v["T_OrderDetailVerification"] == "Y" && $v["is_quantitative"] == "Y" ) {
|
|
$v["mr_state"] = $this->multi_rule($v["order_id"],$v["id"],$v["nattest_id"]);
|
|
} else {
|
|
if ( $v["is_quantitative"] != "Y" ) {
|
|
$v["mr_state"] = array("X","Multirule belum berlaku [Hasil Qualitative] $x_check",array());
|
|
} else {
|
|
$v["mr_state"] = array("X","Multirule tidak berlaku [Belum verifikasi] $x_check" ,array());
|
|
}
|
|
}
|
|
} else {
|
|
$v["mr_state"] = array("X","Multirule tidak berlaku [Belum verifikasi] $x_check" ,array());
|
|
}
|
|
} else {
|
|
//hanya verified dan quantitative
|
|
if ($v["T_OrderDetailVerification"] == "Y" && $v["is_quantitative"] == "Y" ) {
|
|
$v["mr_state"] = $this->multi_rule($v["order_id"],$v["id"],$v["nattest_id"]);
|
|
} else {
|
|
if ( $v["is_quantitative"] != "Y" ) {
|
|
$v["mr_state"] = array("X","Multirule belum berlaku [Hasil Qualitative] $x_check",array());
|
|
} else {
|
|
$v["mr_state"] = array("X","Multirule tidak berlaku [Belum verifikasi] $x_check" ,array());
|
|
}
|
|
}
|
|
}
|
|
|
|
// IF Rujukan, by pas Pre Analytik
|
|
if ($v['ref'] == 'Y')
|
|
$v['pre_analytic'] = 'Y';
|
|
|
|
$rst[] = $v;
|
|
}
|
|
|
|
$result = array("total" => $tot_count, "records" => $rst, "total_display" => sizeof($rows), "q" => $this->db_smartone->last_query());
|
|
$this->sys_ok($result);
|
|
}
|
|
else {
|
|
$this->sys_error_db("RE Px rows", $this->db_smartone);
|
|
exit;
|
|
}
|
|
}
|
|
|
|
public function confirm()
|
|
{
|
|
$prm = $this->sys_input;
|
|
$data = json_decode($prm["id"]);
|
|
|
|
if (sizeof($data) < 1)
|
|
{
|
|
$this->sys_error_db("RE Verification Confirmation", $this->db_smartone);
|
|
exit;
|
|
}
|
|
else
|
|
{
|
|
$ids = [];
|
|
foreach ($data as $k => $v)
|
|
{
|
|
$this->db_smartone->set('T_OrderDetailVerDeltaCheck', $v->delta)
|
|
->set('T_OrderDetailVerTrendAnalysis', $v->trend)
|
|
->set('T_OrderDetailVerification', $v->verification)
|
|
->set('T_OrderDetailVerDate', date('Y-m-d H:i:s'))
|
|
->set('T_OrderDetailVerUserID', $this->sys_user->M_UserID)
|
|
->where('T_OrderDetailID', $v->id)
|
|
->update('t_orderdetail');
|
|
$ids[] = $v->id;
|
|
}
|
|
|
|
$this->sys_ok($ids);
|
|
}
|
|
}
|
|
|
|
public function search_group()
|
|
{
|
|
$prm = $this->sys_input;
|
|
$max_rst = 12;
|
|
|
|
// 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 group_id, T_WorklistName group_name
|
|
from t_worklist
|
|
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;
|
|
}
|
|
}
|
|
} |