Files
REG_IBL/one-api/application/controllers/mockup/clinic/fo/Px.php
2026-05-25 20:01:37 +07:00

410 lines
15 KiB
PHP

<?php
//diberi tambahan pembeda IsFromPanel
//utk contoh kasus yg ndak bisa di delete
//sementara profile di ambilkan dari panel juga dengan IsFromPanel = N
class Px extends MY_Controller
{
var $db_smartone;
public function index()
{
echo "Px API";
}
public function __construct()
{
parent::__construct();
$this->db_smartone = $this->load->database("onedev", true);
}
public function profile() {
$prm = $this->sys_input;
$search = $prm["search"];
$mouCompanyID = $prm["mouCompanyID"];
$sql_param = array($mouCompanyID, "%$search%");
$sql = "select count(distinct T_TestPanelID) total
from
t_testpanel
join t_testpaneldetail on T_TestPanelID = T_TestPanelDetailT_TestPanelID
and T_TestPanelIsActive = 'Y' and T_TestPanelDetailIsActive = 'Y'
join t_test on T_TestPanelDetailT_TestID = T_TestID
and T_TestIsActive = 'Y'
join t_testprice on T_TestID = T_TestPriceT_TestID
and T_TestIsPrice = 'Y'
and T_TestPriceIsActive = 'Y'
and T_TestPriceM_MouCompanyID = ?
where
T_TestPanelName like ? ";
$query = $this->db_smartone->query($sql, $sql_param);
$tot_count =0;
if ($query) {
$tot_count = $query->result_array()[0]["total"];
} else {
$this->sys_error_db("m_testpanel count", $this->db_smartone);
exit;
}
$sql = "select distinct T_TestPanelID
from
t_testpanel
join t_testpaneldetail on T_TestPanelID = T_TestPanelDetailT_TestPanelID
and T_TestPanelIsActive = 'Y' and T_TestPanelDetailIsActive = 'Y'
join t_test on T_TestPanelDetailT_TestID = T_TestID
and T_TestIsActive = 'Y'
join t_testprice on T_TestID = T_TestPriceT_TestID
and T_TestIsPrice = 'Y'
and T_TestPriceIsActive = 'Y'
and T_TestPriceM_MouCompanyID = ?
where
T_TestPanelName like ?
limit 0,20";
$query = $this->db_smartone->query($sql,$sql_param);
$xrows = $query->result_array();
$a_tpid = "-1";
foreach($xrows as $r) {
$a_tpid .= "," . $r["T_TestPanelID"];
}
$sql = "select distinct T_TestPanelID,T_TestPanelName,
T_TestID,T_TestName, 'N' IsFromPanel, T_TestRequirement,
t_testprice.*
from
t_testpanel
join t_testpaneldetail on T_TestPanelID = T_TestPanelDetailT_TestPanelID
and T_TestPanelIsActive = 'Y' and T_TestPanelDetailIsActive = 'Y'
join t_test on T_TestPanelDetailT_TestID = T_TestID
and T_TestIsActive = 'Y'
join t_testprice on T_TestID = T_TestPriceT_TestID
and T_TestIsPrice = 'Y'
and T_TestPriceM_MouCompanyID = ?
and T_TestPriceIsActive = 'Y'
where
T_TestPanelID in ( $a_tpid ) ";
$query = $this->db_smartone->query($sql,array($mouCompanyID));
$xrows = $query->result_array();
$rows = array();
$prev_tpanel_id = 0;
foreach($xrows as $r) {
$tpanel_id = $r["T_TestPanelID"];
if ($tpanel_id != $prev_tpanel_id) {
$rows[] = array(
"T_TestPanelID" => $r["T_TestPanelID"],
"T_TestPanelName" => $r["T_TestPanelName"],
"test" => array()
);
}
$idx = count($rows) - 1;
$rows[$idx]["test"][] = $r;
$prev_tpanel_id = $tpanel_id;
}
$result = array("total" => $tot_count, "records" => $rows );
$this->sys_ok($result);
exit;
}
public function panel() {
$prm = $this->sys_input;
$search = $prm["search"];
$mouCompanyID = $prm["mouCompanyID"];
$sql_param = array($mouCompanyID, "%$search%");
$sql = "select count(distinct T_TestPanelID) total
from
t_testpanel
join t_testpaneldetail on T_TestPanelID = T_TestPanelDetailT_TestPanelID
and T_TestPanelIsActive = 'Y' and T_TestPanelDetailIsActive = 'Y'
join t_test on T_TestPanelDetailT_TestID = T_TestID
and T_TestIsActive = 'Y'
join t_testprice on T_TestID = T_TestPriceT_TestID
and T_TestIsPrice = 'Y'
and T_TestPriceIsActive = 'Y'
and T_TestPriceM_MouCompanyID = ?
where
T_TestPanelName like ? ";
$query = $this->db_smartone->query($sql, $sql_param);
$tot_count =0;
if ($query) {
$tot_count = $query->result_array()[0]["total"];
} else {
$this->sys_error_db("m_testpanel count", $this->db_smartone);
exit;
}
$sql = "select distinct T_TestPanelID
from
t_testpanel
join t_testpaneldetail on T_TestPanelID = T_TestPanelDetailT_TestPanelID
and T_TestPanelIsActive = 'Y' and T_TestPanelDetailIsActive = 'Y'
join t_test on T_TestPanelDetailT_TestID = T_TestID
and T_TestIsActive = 'Y'
join t_testprice on T_TestID = T_TestPriceT_TestID
and T_TestIsPrice = 'Y'
and T_TestPriceIsActive = 'Y'
and T_TestPriceM_MouCompanyID = ?
where
T_TestPanelName like ?
limit 0,20";
$query = $this->db_smartone->query($sql,$sql_param);
$xrows = $query->result_array();
$a_tpid = "-1";
foreach($xrows as $r) {
$a_tpid .= "," . $r["T_TestPanelID"];
}
$sql = "select distinct T_TestPanelID,T_TestPanelName,
T_TestID,T_TestName, 'Y' IsFromPanel,T_TestRequirement,
t_testprice.*
from
t_testpanel
join t_testpaneldetail on T_TestPanelID = T_TestPanelDetailT_TestPanelID
and T_TestPanelIsActive = 'Y' and T_TestPanelDetailIsActive = 'Y'
join t_test on T_TestPanelDetailT_TestID = T_TestID
and T_TestIsActive = 'Y'
join t_testprice on T_TestID = T_TestPriceT_TestID
and T_TestIsPrice = 'Y'
and T_TestPriceM_MouCompanyID = ?
and T_TestPriceIsActive = 'Y'
where
T_TestPanelID in ( $a_tpid )
order by T_TestPanelID";
$query = $this->db_smartone->query($sql,array($mouCompanyID));
$xrows = $query->result_array();
$rows = array();
$prev_tpanel_id = 0;
foreach($xrows as $r) {
$tpanel_id = $r["T_TestPanelID"];
if ($tpanel_id != $prev_tpanel_id) {
$rows[] = array(
"T_TestPanelID" => $r["T_TestPanelID"],
"T_TestPanelName" => $r["T_TestPanelName"],
"test" => array()
);
}
$idx = count($rows) - 1;
$rows[$idx]["test"][] = $r;
$prev_tpanel_id = $tpanel_id;
}
$result = array("total" => $tot_count, "records" => $rows );
$this->sys_ok($result);
exit;
}
public function search_old()
{
$prm = $this->sys_input;
$search = $prm["search"];
$sql_param = array("%$search%");
$sql = "select count(distinct T_TestID) total
from
t_test
where
T_TestIsActive = 'Y'
AND T_TestIsPrice = 'Y'
AND T_TestName like ? ";
$query = $this->db_smartone->query($sql, $sql_param);
$tot_count =0;
if ($query) {
$tot_count = $query->result_array()[0]["total"];
} else {
$this->sys_error_db("m_company count", $this->db_smartone);
exit;
}
$sql = "select distinct T_TestID,T_TestName, 'N' IsFromPanel, T_TestRequirement
from
t_test
where
T_TestIsActive = 'Y'
AND T_TestIsPrice = 'Y'
AND T_TestName like ?
limit 0,20
";
$query = $this->db_smartone->query($sql, $sql_param);
$rows = $query->result_array();
$result = array("total" => $tot_count, "records" => $rows );
$this->sys_ok($result);
exit;
}
public function search_v2()
{
$prm = $this->sys_input;
$search = $prm["search"];
$mouCompanyID = $prm["mouCompanyID"];
$sql_param = array($mouCompanyID, "%$search%");
$query = $this->db_smartone->query("CALL sp_fo_px_count_v2(?, ?)", $sql_param);
$this->clean_mysqli_connection($this->db_smartone->conn_id);
$tot_count = 0;
if ($query) {
$tot_count = $query->result_array()[0]["data"];
} else {
$this->sys_error_db("PX count", $this->db_smartone);
exit;
}
if (isset($prm['order_id']))
$query = $this->db_smartone->query("CALL sp_fo_px_search_byorder_v2(?, ?)", [$prm['order_id'], $mouCompanyID]);
else if ($search == "")
$query = $this->db_smartone->query("CALL sp_fo_px_search_favorite_v2(?, ?)", $sql_param);
else
$query = $this->db_smartone->query("CALL sp_fo_px_search_v2(?, ?)", $sql_param);
$this->clean_mysqli_connection($this->db_smartone->conn_id);
// echo $this->db_smartone->last_query();
// $query = $this->db_smartone->query($sql);
if ($query)
{
$rows = $query->result_array();
$id_to_remove = [];
// var_dump($rows);
foreach ($rows as $k => $v)
{
$rows[$k]['requirement'] = [];
$x = $this->db_smartone->query("SELECT fn_fo_requirement_get('{$v['T_TestID']}') x")
->row();
if ($x->x != null)
$rows[$k]['requirement'] = json_decode($x->x);
$rows[$k]['nat_test'] = json_decode($v['nat_test']);
$rows[$k]['child_test'] = json_decode($v['child_test']);
// IF PROFILE
if ($v['px_type'] == "PR" || $v['px_type'] == "PXR") {
if ($v['T_TestID'] == null)
{
$id_to_remove[] = $k;
continue;
}
else
{
foreach ($rows[$k]['child_test'] as $l => $w) {
$rows[$k]['child_test'][$l]->requirement = [];
$rows[$k]['child_test'][$l]->nat_test = json_decode($w->nat_test);
$x = $this->db_smartone->query("SELECT fn_fo_requirement_get('{$w->T_TestID}') x")
->row();
if ($x->x != null)
$rows[$k]['child_test'][$l]->requirement = json_decode($x->x);
}
}
}
}
// REMOVE INDEXES
foreach ($id_to_remove as $l => $w)
{ $x = $w - $l; array_splice($rows, $x, 1); }
$result = array("total" => $tot_count, "records" => (array) $rows, "query" => $sqlx, "query2" => $sqly );
$this->sys_ok($result);
exit;
}
}
public function search()
{
$prm = $this->sys_input;
$search = $prm["search"];
$mouCompanyID = $prm["mouCompanyID"];
$sql_param = array($mouCompanyID, "%$search%");
$query = $this->db_smartone->query("CALL sp_fo_px_count(?, ?)", $sql_param);
$this->clean_mysqli_connection($this->db_smartone->conn_id);
$tot_count = 0;
if ($query) {
$tot_count = $query->result_array()[0]["data"];
} else {
$this->sys_error_db("PX count", $this->db_smartone);
exit;
}
if (isset($prm['order_id']))
$query = $this->db_smartone->query("CALL sp_fo_px_search_byorder(?, ?)", [$prm['order_id'], $mouCompanyID]);
else if ($search == "")
$query = $this->db_smartone->query("CALL sp_fo_px_search_favorite(?, ?)", $sql_param);
else
$query = $this->db_smartone->query("CALL sp_fo_px_search(?, ?)", $sql_param);
$this->clean_mysqli_connection($this->db_smartone->conn_id);
// echo $this->db_smartone->last_query();
// $query = $this->db_smartone->query($sql);
if ($query)
{
$rows = $query->result_array();
$id_to_remove = [];
// var_dump($rows);
foreach ($rows as $k => $v)
{
$rows[$k]['requirement'] = [];
$x = $this->db_smartone->query("SELECT fn_fo_requirement_get('{$v['T_TestID']}') x")
->row();
if ($x->x != null)
$rows[$k]['requirement'] = json_decode($x->x);
$rows[$k]['nat_test'] = json_decode($v['nat_test']);
$rows[$k]['child_test'] = json_decode($v['child_test']);
// IF PROFILE
if ($v['px_type'] == "PR" || $v['px_type'] == "PXR") {
if ($v['T_TestID'] == null)
{
$id_to_remove[] = $k;
continue;
}
else
{
foreach ($rows[$k]['child_test'] as $l => $w) {
$rows[$k]['child_test'][$l]->requirement = [];
$rows[$k]['child_test'][$l]->nat_test = json_decode($w->nat_test);
$x = $this->db_smartone->query("SELECT fn_fo_requirement_get('{$w->T_TestID}') x")
->row();
if ($x->x != null)
$rows[$k]['child_test'][$l]->requirement = json_decode($x->x);
}
}
}
}
// REMOVE INDEXES
foreach ($id_to_remove as $l => $w)
{ $x = $w - $l; array_splice($rows, $x, 1); }
$result = array("total" => $tot_count, "records" => (array) $rows, "query" => $sqlx, "query2" => $sqly );
$this->sys_ok($result);
exit;
}
}
function get_price()
{
$prm = $this->sys_input;
$r = [];
$sql_param = array($prm['test_id'], date('Y-m-d'), $prm['cito'], $prm['mou_id']);
$sql = "select fn_price(?, ?, ?, ?) as price";
$query = $this->db_smartone->query($sql, $sql_param);
if ($query) {
$r = $query->result_array()[0];
$r = json_decode($r['price']);
$this->sys_ok($r);
exit;
} else {
$this->sys_error_db("get price", $this->db_smartone);
exit;
}
}
}