Files
2026-05-25 20:01:37 +07:00

589 lines
16 KiB
PHP

<?php
class Testprice extends MY_Controller
{
var $db_onedev;
public function index()
{
echo "Test Price API";
}
public function __construct()
{
parent::__construct();
$this->db_onedev = $this->load->database("onedev", true);
}
public function search()
{
$prm = $this->sys_input;
if (! $this->isLogin) {
$this->sys_error("Invalid Token");
exit;
}
$code = $prm["code"];
$nama = $prm["nama"];
// echo $norm;
$sql_where = "WHERE T_TestIsActive = 'Y' AND T_TestIsPrice = 'Y'";
$sql_param = array();
if ($code != "") {
if ($sql_where != "") {
$sql_where .=" and ";
}
$sql_where .= " T_TestCode like ? ";
$sql_param[] = "%$code%";
}
if ($nama != "") {
if ($sql_where != "") {
$sql_where .=" and ";
}
$sql_where .= " T_TestName like ? ";
$sql_param[] = "%$nama%";
}
//if ($sql_where != "") $sql_where .= " and ";
// Order masih dalam status registrasi
//$sql_where .= " M_PatientIsActive = 'Y' ";
$sql = " SELECT count(*) as total
FROM t_test
$sql_where
";
//echo $sql;
$query = $this->db_onedev->query($sql, $sql_param);
$tot_count = 0;
if ($query) {
$tot_count = $query->result_array()[0]["total"];
} else {
$this->sys_error_db("t_test count", $this->db_onedev);
exit;
}
$sql = "SELECT *
FROM t_test
$sql_where
ORDER BY T_TestCode ASC
limit 0,$tot_count";
//echo $sql;
$query = $this->db_onedev->query($sql, $sql_param);
$rows = $query->result_array();
if($rows){
foreach($rows as $k => $v){
}
}
//$this->_add_address($rows);
$result = array("total" => $tot_count, "records" => $rows, "sql"=> $this->db_onedev->last_query());
$this->sys_ok($result);
exit;
}
function searchcompany(){
if (! $this->isLogin) {
$this->sys_error("Invalid Token");
exit;
}
$prm = $this->sys_input;
$max_rst = 12;
$tot_count =0;
$q = [
'search' => '%'
];
if ($prm['search'] != '')
{
$q['search'] = "%{$prm['search']}%";
}
// QUERY TOTAL
$sql = "SELECT count(*) as total
FROM m_company
WHERE
M_CompanyName like ?
AND M_CompanyIsActive = 'Y' AND M_CompanyIsLabFrom = 'Y'";
$query = $this->db_onedev->query($sql,$q['search']);
//echo $query;
if ($query) {
$tot_count = $query->result_array()[0]["total"];
}
else {
$this->sys_error_db("m_company count",$this->db_onedev);
exit;
}
$sql = "
SELECT *
FROM m_company
WHERE
M_CompanyName like ?
AND M_CompanyIsActive = 'Y' AND M_CompanyIsLabFrom = 'Y'
ORDER BY M_CompanyName DESC
";
$query = $this->db_onedev->query($sql, array($q['search']));
if ($query) {
$rows = $query->result_array();
//echo $this->db_onedev->last_query();
$result = array("total" => $tot_count, "records" => $rows, "total_display" => sizeof($rows));
$this->sys_ok($result);
}
else {
$this->sys_error_db("m_company rows",$this->db_onedev);
exit;
}
}
function getmou(){
$prm = $this->sys_input;
$query =" SELECT *
FROM m_mou
WHERE
M_MouIsActive = 'Y' AND M_MouM_CompanyID = ?
";
//echo $query;
$rows = $this->db_onedev->query($query,array($prm['id']))->result_array();
$result = array(
"total" => count($rows) ,
"records" => $rows,
);
$this->sys_ok($result);
exit;
}
function getpricemoureg(){
if (! $this->isLogin) {
$this->sys_error("Invalid Token");
exit;
}
$rows = [];
$query =" SELECT *
FROM m_company
WHERE
M_CompanyIsActive = 'Y'
";
//echo $query;
$rows['companys'] = $this->db_onedev->query($query)->result_array();
$query =" SELECT *
FROM m_mou
WHERE
M_MouIsActive = 'Y'
";
//echo $query;
$rows['pricemous'] = $this->db_onedev->query($query)->result_array();
$result = array(
"total" => count($rows) ,
"records" => $rows,
);
$this->sys_ok($result);
exit;
}
function save(){
if (! $this->isLogin) {
$this->sys_error("Invalid Token");
exit;
}
$prm = $this->sys_input;
$pdob = date('Y-m-d',strtotime($prm['M_PatientDOB']));
$query ="UPDATE m_patient SET
M_PatientM_TitleID = '{$prm['M_PatientM_TitleID']}',
M_PatientName = '{$prm['M_PatientName']}',
M_PatientDOB = '{$pdob}',
M_PatientM_SexID = '{$prm['M_PatientM_SexID']}',
M_PatientM_ReligionID = '{$prm['M_PatientM_ReligionID']}',
M_PatientEmail = '{$prm['M_PatientEmail']}',
M_PatientHP = '{$prm['M_PatientHP']}',
M_PatientPhone = '{$prm['M_PatientPhone']}',
M_PatientM_IdTypeID = '{$prm['M_PatientM_IdTypeID']}',
M_PatientIDNumber = '{$prm['M_PatientIDNumber']}',
M_PatientNote = '{$prm['M_PatientNote']}'
WHERE
M_PatientID = '{$prm['M_PatientID']}'
";
//echo $query;
$rows = $this->db_onedev->query($query);
$result = array(
"total" => 1 ,
"records" => array('status'=>'OK')
);
$this->sys_ok($result);
exit;
}
function newreceivereference(){
if (! $this->isLogin) {
$this->sys_error("Invalid Token");
exit;
}
$prm = $this->sys_input;
$pdate = date('Y-m-d',strtotime($prm['sdate']));
$userid = $this->sys_user["M_UserID"];
$query ="INSERT INTO t_test (
T_TestM_CompanyID,
T_TestM_MouID,
T_TestDate,
T_TestNote,
T_TestUserID,
T_TestCreated
)
VALUES(
'{$prm['companyid']}',
'{$prm['mouid']}',
'{$pdate}',
'{$prm['note']}',
'{$userid}',
NOW()
)
";
// echo $query;
$rows = $this->db_onedev->query($query);
$last_id = $this->db_onedev->insert_id();
$querylog ="INSERT INTO g_receivereferenceheaderstatuslog (
G_ReceiveReferenceHeaderStatusLogDate,
G_ReceiveReferenceHeaderStatusLogT_TestID,
G_ReceiveReferenceHeaderStatusLogM_StatusReferenceID,
G_ReceiveReferenceHeaderStatusLogM_UserID,
G_ReceiveReferenceHeaderStatusLogUserID,
G_ReceiveReferenceHeaderStatusLogCreated,
G_ReceiveReferenceHeaderStatusLogLastUpdated
)
VALUES(
NOW(),
'{$last_id}',
'1',
'{$userid}',
'{$userid}',
NOW(),
NOW()
)";
//echo $querylog;
$insert_new_log = $this->db_onedev->query($querylog);
$result = array(
"total" => 1 ,
"records" => array('status'=>'OK'),
"id" => $last_id
);
$this->sys_ok($result);
exit;
}
function sendorder(){
if (! $this->isLogin) {
$this->sys_error("Invalid Token");
exit;
}
$prm = $this->sys_input;
$userid = $this->sys_user["M_UserID"];
$query ="UPDATE t_test SET
T_TestIsSent = 'Y',
T_TestSentDate = now(),
T_TestUserID = '{$userid}'
WHERE
T_TestID = '{$prm['T_TestID']}'
";
//echo $query;
$rows = $this->db_onedev->query($query);
$rows = $this->db_onedev->query($query);
$querylog ="INSERT INTO g_receivereferenceheaderstatuslog (
G_ReceiveReferenceHeaderStatusLogDate,
G_ReceiveReferenceHeaderStatusLogT_TestID,
G_ReceiveReferenceHeaderStatusLogM_StatusReferenceID,
G_ReceiveReferenceHeaderStatusLogM_UserID,
G_ReceiveReferenceHeaderStatusLogUserID,
G_ReceiveReferenceHeaderStatusLogCreated,
G_ReceiveReferenceHeaderStatusLogLastUpdated
)
VALUES(
NOW(),
'{$prm['T_TestID']}',
'2',
'{$userid}',
'{$userid}',
NOW(),
NOW()
)";
//echo $querylog;
$insert_new_log = $this->db_onedev->query($querylog);
$result = array(
"total" => 1 ,
"records" => array('status'=>'OK')
);
$this->sys_ok($result);
exit;
}
function getpricemou(){
if (! $this->isLogin) {
$this->sys_error("Invalid Token");
exit;
}
$prm = $this->sys_input;
$query =" SELECT t_price.*,
IF(T_PriceIsCito = 'Y','Ya','Tidak') as T_PriceIsCito,
T_TestID,
T_TestName,
M_CompanyID,
M_CompanyName,
M_MouID,
M_MouName,
M_MouStartDate,
M_MouEndDate,
FORMAT(T_PriceTotal,0) as T_PriceTotal,
CONCAT(DATE_FORMAT(M_MouStartDate,'%d-%m-%Y'),' s/d ',DATE_FORMAT(M_MouEndDate,'%d-%m-%Y')) as periode,
'' as action
FROM t_price
JOIN t_test ON T_PriceT_TestID = T_TestID
JOIN m_company ON T_PriceM_CompanyID = M_CompanyID
JOIN m_mou ON T_PriceM_MouID = M_MouID AND (date(now()) BETWEEN M_MouStartDate AND M_MouEndDate) AND M_MouIsActive = 'Y'
WHERE
T_TestID = ?
GROUP BY T_PriceID
ORDER BY T_PricePriority ASC
";
//echo $query;
$rows = $this->db_onedev->query($query,array($prm['id']))->result_array();
if($rows){
foreach($rows as $k => $v){
$rows[$k]['action'] = '<v-icon color="error" @click="deleteAddress(props.item)">delete</v-icon>';
$rows[$k]['action'] .= '<v-icon color="primary" @click="deleteAddress(props.item)">edit</v-icon>';
}
}
$result = array(
"total" => count($rows) ,
"records" => $rows,
);
$this->sys_ok($result);
exit;
}
function add_day($testid,$methodeid){
$query =" SELECT m_methode_priority.*,IFNULL(M_MethodePriorityNumber,0) as M_MethodePriorityNumber, m_dayofweek.*,IF(M_MethodePriorityID IS NULL,'N','Y') as isday, IFNULL(M_MethodePriorityNat_MethodeID,0) as xid
FROM m_dayofweek
JOIN t_test ON T_TestID = '{$testid}'
JOIN nat_normalvalue ON T_TestID = Nat_NormalValueT_TestID AND Nat_NormalValueNat_MethodeID = '{$methodeid}'
JOIN nat_methode ON Nat_NormalValueNat_MethodeID = Nat_MethodeID
LEFT JOIN m_methode_priority ON T_TestID = M_MethodePriorityT_TestID AND Nat_MethodeID = M_MethodePriorityNat_MethodeID AND M_DayOfWeekID = M_MethodePriorityM_DayOfWeekID AND M_MethodePriorityIsActive = 'Y'
GROUP BY M_DayOfWeekID";
//echo $query;
$rows = $this->db_onedev->query($query)->result_array();
if(!$rows)
$rows = array();
return $rows;
}
function savenewmethode(){
if (! $this->isLogin) {
$this->sys_error("Invalid Token");
exit;
}
$prm = $this->sys_input;
$userid = $this->sys_user["M_UserID"];
foreach($prm['orderdays'] as $k=>$v){
$query = "INSERT INTO m_methode_priority (
M_MethodePriorityM_MethodePriorityID,
M_MethodePriorityT_TestID,
M_MethodePriorityT_TestCode,
M_MethodePriorityT_TestName,
M_MethodePriorityT_TestPrice,
M_MethodePriorityT_TestDisc,
M_MethodePriorityT_TestDiscRp,
M_MethodePriorityT_TestTotal,
M_MethodePriorityUserID,
M_MethodePriorityCreated,
M_MethodePriorityLastUpdated
)
VALUE(
?,?,?,?,?,?,?,?,?, now(),now()
)";
$insert_new_test = $this->db_onedev->query($query,array(
$orderpatient_id,
$v['T_TestID'],
$v['T_TestCode'],
$v['T_TestName'],
$v['T_PriceAmount'],
$v['T_PriceDisc'],
$v['T_PriceDiscRp'],
$v['total'],
$userid
));
}
$result = array(
"total" => 1 ,
"records" => array('status'=>'OK')
);
$this->sys_ok($result);
exit;
}
function saveeditmethode(){
if (! $this->isLogin) {
$this->sys_error("Invalid Token");
exit;
}
$prm = $this->sys_input;
$test_id = $prm['M_MethodePriorityT_TestID'];
$methode_id = $prm['M_MethodePriorityNat_MethodeID'];
$priority = $prm['M_MethodePriorityNumber'];
$userid = $this->sys_user["M_UserID"];
foreach($prm['orderdays'] as $k=>$v){
if(($v['xid'] == 0 || $v['xid'] == '0') && ($v['isday'] === 'Y')){
$query = "INSERT INTO m_methode_priority(
M_MethodePriorityT_TestID,
M_MethodePriorityNat_MethodeID,
M_MethodePriorityM_DayOfWeekID,
M_MethodePriorityNumber,
M_MethodePriorityUserID,
M_MethodePriorityCreated,
M_MethodePriorityLastUpdated
)
VALUE(
?,?,?,?,?,now(),now()
)";
$insert_methode = $this->db_onedev->query($query,array(
$test_id,
$methode_id,
$v['M_DayOfWeekID'],
$priority,
$userid
));
}elseif($v['xid'] > 0 && $v['isday'] === 'N'){
$queryupdate ="UPDATE m_methode_priority SET
M_MethodePriorityIsActive = 'N',
M_MethodePriorityUserID = '{$userid}',
M_MethodePriorityLastUpdated = now()
WHERE
M_MethodePriorityID = ?
";
// echo $queryupdate;
$update_methode = $this->db_onedev->query($queryupdate,array($v['M_MethodePriorityID'],));
// echo $update_methode;
}else{
$queryupdate ="UPDATE m_methode_priority SET
M_MethodePriorityNumber = '{$priority}',
M_MethodePriorityUserID = '{$userid}',
M_MethodePriorityLastUpdated = now()
WHERE
M_MethodePriorityID = ?
";
// echo $queryupdate;
$update_methode = $this->db_onedev->query($queryupdate,array($v['M_MethodePriorityID'],));
}
}
$result = array(
"total" => 1 ,
"records" => array('status'=>'OK')
);
$this->sys_ok($result);
exit;
}
function deletepatient(){
if (! $this->isLogin) {
$this->sys_error("Invalid Token");
exit;
}
$prm = $this->sys_input;
$userid = $this->sys_user["M_UserID"];
$query ="UPDATE t_receivereferencepatient SET
M_MethodePriorityIsActive = 'N',
M_MethodePriorityUserID = '{$userid}'
WHERE
M_MethodePriorityID = '{$prm['M_MethodePriorityID']}'
";
//echo $query;
$rows = $this->db_onedev->query($query);
$query ="UPDATE m_methode_priority SET
M_MethodePriorityIsActive = 'N',
M_MethodePriorityUserID = '{$userid}'
WHERE
M_MethodePriorityM_MethodePriorityID = '{$prm['M_MethodePriorityID']}' AND M_MethodePriorityIsActive = 'Y'
";
//echo $query;
$rows = $this->db_onedev->query($query);
$result = array(
"total" => 1 ,
"records" => array('status'=>'OK')
);
$this->sys_ok($result);
exit;
}
function searchtest(){
$prm = $this->sys_input;
$max_rst = 12;
$tot_count = 0;
$q = [
'search' => '%'
];
if ($prm['search'] != '')
{
$q['search'] = "%{$prm['search']}%";
}
$mou_id = $prm['mouid'];
// QUERY TOTAL
$sql = "SELECT count(*) as total
FROM t_test
JOIN t_price ON T_PriceT_TestID = T_TestID AND T_PriceIsCito = 'N' AND T_PriceM_MouID = '{$mou_id}'
WHERE
T_TestName like ? AND
T_TestIsActive = 'Y'
ORDER BY T_TestName ASC";
$query = $this->db_onedev->query($sql,$q['search']);
//echo $query;
if ($query) {
$tot_count = $query->result_array()[0]["total"];
}
else {
$this->sys_error_db("test count",$this->db_onedev);
exit;
}
$sql = "
SELECT 'Y' as editable, 0 as xid, T_TestID, T_TestCode, T_TestName, T_PriceAmount, T_PriceDisc, T_PriceDiscRp, T_PriceAmount - ((T_PriceDisc/100) * T_PriceAmount) - T_PriceDiscRp as total,
M_CompanyID,'N' as M_CompanyIsBill, 0 as M_CompanyMinDP
FROM one_lis_dev.t_test
JOIN one_lis_dev.t_price ON T_PriceT_TestID = T_TestID AND T_PriceIsCito = 'N' AND T_PriceM_MouID = '{$mou_id}'
JOIN one_lis_dev.m_mou ON M_MouID = '{$mou_id}'
JOIN one_lis_dev.m_company ON M_MouM_CompanyID = M_CompanyID
WHERE
T_TestName like ? AND
T_TestIsActive = 'Y'
ORDER BY T_TestName ASC
";
$query = $this->db_onedev->query($sql, array($q['search']));
if ($query) {
$rows = $query->result_array();
//echo $this->db_onedev->last_query();
$result = array("total" => $tot_count, "records" => $rows, "total_display" => sizeof($rows));
$this->sys_ok($result);
}
else {
$this->sys_error_db("test rows",$this->db_onedev);
exit;
}
}
}