261 lines
8.7 KiB
PHP
261 lines
8.7 KiB
PHP
<?php
|
|
class Check_normal extends MY_Controller
|
|
{
|
|
function __construct() {
|
|
parent::__construct();
|
|
}
|
|
function index() {
|
|
echo "<pre>";
|
|
|
|
}
|
|
function cek($order , $test , $instrumentID = 0) {
|
|
$sql = "select T_OrderHeaderID,
|
|
T_OrderHeaderLabNumber, M_PatientName, M_PatientM_SexID,
|
|
fn_global_age_count_day(M_PatientDob,T_OrderHeaderDate) ageDay
|
|
from t_orderheader
|
|
join m_patient on T_OrderHeaderM_PatientID = M_PatientID
|
|
where T_OrderHeaderLabNumber = ?";
|
|
$qry = $this->db->query($sql, array($order));
|
|
if (! $qry) {
|
|
print_r($this->db->error());
|
|
exit;
|
|
}
|
|
|
|
$rows = $qry->result_array();
|
|
if (count($rows) == 0 ) {
|
|
echo "Order not found $order \n";
|
|
exit;
|
|
}
|
|
$header = $rows[0];
|
|
|
|
$sql = "select T_TestName,T_TestID, T_TestNat_TestID ,
|
|
T_OrderdetailNat_MethodeName, T_OrderDetailNat_NormalValueID,
|
|
T_OrderDetailNormalValueNote, T_TestT_SampleTypeID
|
|
from
|
|
t_orderdetail
|
|
join t_test on T_OrderDetailT_TestID = T_TestID
|
|
and T_OrderDetailIsActive = 'Y'
|
|
and T_OrderDetailT_OrderHeaderID = ?";
|
|
$qry = $this->db->query($sql, array($header["T_OrderHeaderID"]));
|
|
|
|
if (! $qry) {
|
|
print_r($this->db->error());
|
|
exit;
|
|
}
|
|
$rows = $qry->result_array();
|
|
$detail = array();
|
|
foreach($rows as $r) {
|
|
$xpos = stripos($r["T_TestName"],$test);
|
|
if ($xpos === FALSE ) {
|
|
continue;
|
|
}
|
|
$detail = $r;
|
|
$tOrderHeaderID = $header["T_OrderHeaderID"];
|
|
$name = $header["M_PatientName"];
|
|
$sexID = $header["M_PatientM_SexID"];
|
|
$ageDay = $header["ageDay"];
|
|
$natTestID = $detail["T_TestNat_TestID"];
|
|
$testName = $detail["T_TestName"];
|
|
$methode = $detail["T_OrderdetailNat_MethodeName"];
|
|
$normalValue = $detail["T_OrderDetailNormalValueNote"];
|
|
$sampleTypeID = $detail["T_TestT_SampleTypeID"];
|
|
echo "<pre>";
|
|
echo "Check Nilai Normal $testName, no lab. $order , $name , tanggal $tanggal : \n";
|
|
echo "Pemeriksaan : $testName, Sample Type ID : $sampleTypeID \n";
|
|
echo "Methode terpilih di orderdetail : $methode, NormalValue : $normalValue \n";
|
|
echo "Umur in day $ageDay , Nat_TestID $natTestID\n";
|
|
|
|
$sql = "select distinct
|
|
M_InstrumentMethodeNat_MethodeID, Nat_MethodeName, M_InstrumentMethodePriority,
|
|
M_InstrumentMethodeCreated, M_InstrumentMethodeLastUpdated
|
|
from m_instrumentmethode
|
|
join nat_methode on M_InstrumentMethodeNat_MethodeID = Nat_MethodeID
|
|
and Nat_MethodeIsActive = 'Y'
|
|
join nat_instrument on M_InstrumentMethodeNat_InstrumentID = Nat_InstrumentID
|
|
and Nat_InstrumentIsActive ='Y'
|
|
where M_InstrumentMethodeNat_TestID = ?
|
|
and M_InstrumentMethodeIsActive = 'Y'
|
|
order by M_InstrumentMethodePriority desc";
|
|
$qry = $this->db->query($sql, array($natTestID));
|
|
if (! $qry) {
|
|
print_r($this->db->error());
|
|
continue;
|
|
}
|
|
$rows = $qry->result_array();
|
|
if (count($rows) == 0 ) {
|
|
echo "Error Belum Ada Methode \n";
|
|
continue;
|
|
}
|
|
$methodeID = 0;
|
|
"Methode:\n";
|
|
foreach($rows as $idx => $r) {
|
|
$methodeID = $r["M_InstrumentMethodeNat_MethodeID"];
|
|
$methodeName = $r["Nat_MethodeName"];
|
|
$created= $r["M_InstrumentMethodeCreated"];
|
|
echo "\n";
|
|
echo "Priority: " . $r["M_InstrumentMethodePriority"] . " => " . $r["M_InstrumentMethodeNat_MethodeID"] . " | " . $r["Nat_MethodeName"] . "|$created";
|
|
echo "\n";
|
|
if ($methodeID == 0 ) {
|
|
echo "Error Belum Ada Methode \n";
|
|
continue;
|
|
}
|
|
//$sql = "select fn_sampling_get_normal(v_MethodeID, v_Nat_TestID, v_M_SexID, v_M_AgeInDay)";
|
|
if ($instrumentID > 0 ) {
|
|
$sql = "select fn_instrument_get_normal(?, ?, ?) as normalID";
|
|
$qry = $this->db->query($sql, array($instrumentID, $natTestID, $tOrderHeaderID ));
|
|
} else {
|
|
$sql = "select fn_sampling_get_normal(?, ?, ?,?) as normalID";
|
|
$qry = $this->db->query($sql, array($methodeID, $natTestID, $sexID, $ageDay));
|
|
echo "--\n" . $this->db->last_query() . "\n---\n";
|
|
}
|
|
if (! $qry) {
|
|
print_r($this->db->error());
|
|
continue;
|
|
}
|
|
$rows = $qry->result_array();
|
|
if (count($rows) == 0 ) {
|
|
echo "Nilai Normal Tidak Ketemu\n";
|
|
continue;
|
|
}
|
|
$normalID = $rows[0]["normalID"];
|
|
if ($normalID == 0 ) {
|
|
echo "Nilai Normal Tidak Ketemu\n";
|
|
continue;
|
|
}
|
|
$sql = "select * from nat_normalvalue where Nat_NormalValueID = ?";
|
|
$qry = $this->db->query($sql, array($normalID));
|
|
if (! $qry) {
|
|
print_r($this->db->error());
|
|
continue;
|
|
}
|
|
$rows = $qry->result_array();
|
|
print_r($rows);
|
|
echo "\n";
|
|
}
|
|
}
|
|
|
|
}
|
|
|
|
function all($order , $instrumentID = 0) {
|
|
$sql = "select T_OrderHeaderID,T_OrderHeaderDate,
|
|
T_OrderHeaderLabNumber, M_PatientName, M_PatientM_SexID,
|
|
fn_global_age_count_day(M_PatientDob,T_OrderHeaderDate) ageDay
|
|
from t_orderheader
|
|
join m_patient on T_OrderHeaderM_PatientID = M_PatientID
|
|
where T_OrderHeaderLabNumber = ?";
|
|
$qry = $this->db->query($sql, array($order));
|
|
if (! $qry) {
|
|
print_r($this->db->error());
|
|
exit;
|
|
}
|
|
|
|
$rows = $qry->result_array();
|
|
if (count($rows) == 0 ) {
|
|
echo "Order not found $order \n";
|
|
exit;
|
|
}
|
|
$header = $rows[0];
|
|
$sql = "select T_TestName,T_TestID, T_TestNat_TestID ,
|
|
T_OrderdetailNat_MethodeName, T_OrderDetailNat_NormalValueID,
|
|
T_OrderDetailNormalValueNote, T_TestT_SampleTypeID
|
|
from
|
|
t_orderdetail
|
|
join t_test on T_OrderDetailT_TestID = T_TestID
|
|
and T_OrderDetailIsActive = 'Y'
|
|
and T_OrderDetailT_OrderHeaderID = ?";
|
|
$qry = $this->db->query($sql, array($header["T_OrderHeaderID"]));
|
|
|
|
if (! $qry) {
|
|
print_r($this->db->error());
|
|
exit;
|
|
}
|
|
$rows = $qry->result_array();
|
|
$detail = array();
|
|
$name = $header["M_PatientName"];
|
|
$sexID = $header["M_PatientM_SexID"];
|
|
$ageDay = $header["ageDay"];
|
|
$tOrderHeaderID = $header["T_OrderHeaderID"];
|
|
$tanggal = $header["T_OrderHeaderDate"];
|
|
foreach($rows as $r) {
|
|
$detail = $r;
|
|
$natTestID = $detail["T_TestNat_TestID"];
|
|
$testName = $detail["T_TestName"];
|
|
$methode = $detail["T_OrderdetailNat_MethodeName"];
|
|
$normalValue = $detail["T_OrderDetailNormalValueNote"];
|
|
$sampleTypeID = $detail["T_TestT_SampleTypeID"];
|
|
echo "<pre>";
|
|
echo "Check Nilai Normal $testName, no lab. $order , $name , tanggal $tanggal : \n";
|
|
echo "Pemeriksaan : $testName, Sample Type ID : $sampleTypeID \n";
|
|
echo "Methode terpilih di orderdetail : $methode, NormalValue : $normalValue \n";
|
|
echo "Umur in day $ageDay , Nat_TestID $natTestID\n";
|
|
|
|
$sql = "select distinct
|
|
M_InstrumentMethodeNat_MethodeID, Nat_MethodeName, M_InstrumentMethodePriority
|
|
from m_instrumentmethode
|
|
join nat_methode on M_InstrumentMethodeNat_MethodeID = Nat_MethodeID
|
|
and Nat_MethodeIsActive = 'Y'
|
|
join nat_instrument on M_InstrumentMethodeNat_InstrumentID = Nat_InstrumentID
|
|
and Nat_InstrumentIsActive ='Y'
|
|
where M_InstrumentMethodeNat_TestID = ?
|
|
and M_InstrumentMethodeIsActive = 'Y'
|
|
order by M_InstrumentMethodePriority desc";
|
|
$qry = $this->db->query($sql, array($natTestID));
|
|
if (! $qry) {
|
|
print_r($this->db->error());
|
|
exit;
|
|
}
|
|
$rows = $qry->result_array();
|
|
if (count($rows) == 0 ) {
|
|
echo "Error Belum Ada Methode \n";
|
|
continue;
|
|
}
|
|
$methodeID = 0;
|
|
"Methode:\n";
|
|
foreach($rows as $idx => $r) {
|
|
if ($idx == 0 ) {
|
|
$methodeID = $r["M_InstrumentMethodeNat_MethodeID"];
|
|
}
|
|
$methodeName = $r["Nat_MethodeName"];
|
|
echo "Priority : " . $r["M_InstrumentMethodePriority"] . " => |" . $r["M_InstrumentMethodeNat_MethodeID"] . " | " . $r["Nat_MethodeName"] ;
|
|
echo "\n";
|
|
}
|
|
|
|
if ($methodeID == 0 ) {
|
|
echo "Error Belum Ada Methode \n";
|
|
exit;
|
|
}
|
|
//$sql = "select fn_sampling_get_normal(v_MethodeID, v_Nat_TestID, v_M_SexID, v_M_AgeInDay)";
|
|
if ($instrumentID > 0 ) {
|
|
$sql = "select fn_instrument_get_normal(?, ?, ?) as normalID";
|
|
$qry = $this->db->query($sql, array($instrumentID, $natTestID, $tOrderHeaderID ));
|
|
} else {
|
|
$sql = "select fn_sampling_get_normal(?, ?, ?,?) as normalID";
|
|
$qry = $this->db->query($sql, array($methodeID, $natTestID, $sexID, $ageDay));
|
|
}
|
|
if (! $qry) {
|
|
print_r($this->db->error());
|
|
exit;
|
|
}
|
|
$rows = $qry->result_array();
|
|
if (count($rows) == 0 ) {
|
|
echo "Nilai Normal Tidak Ketemu\n";
|
|
exit;
|
|
}
|
|
$normalID = $rows[0]["normalID"];
|
|
if ($normalID == 0 ) {
|
|
echo "Nilai Normal Tidak Ketemu\n";
|
|
exit;
|
|
}
|
|
$sql = "select * from nat_normalvalue where Nat_NormalValueID = ?";
|
|
$qry = $this->db->query($sql, array($normalID));
|
|
if (! $qry) {
|
|
print_r($this->db->error());
|
|
exit;
|
|
}
|
|
$rows = $qry->result_array();
|
|
print_r($rows);
|
|
}
|
|
}
|
|
|
|
}
|