Files
2026-04-27 10:31:17 +07:00

755 lines
21 KiB
PHP

<?php
class Specimenlocal extends MY_Controller
{
var $db_onedev;
public function index()
{
echo "SPECIMENLOCAL API";
}
public function __construct()
{
parent::__construct();
$this->db_onedev = $this->load->database("onedev", true);
}
function lookupspecimenlocal(){
try {
//# cek token valid
if (! $this->isLogin) {
$this->sys_error("Invalid Token");
exit;
}
$prm = $this->sys_input;
$id = $prm['id'];
$sql = "select T_SpecimenLocalID as id,
T_SpecimenLocalNat_TestID as testid,
T_SpecimenLocalT_SampleTypeID as sampletypeid,
Nat_TestID,
CONCAT(T_SampleTypeName,' ' ,'[ ',T_SampleTypeCode,' ]') as description,
CONCAT(T_SampleTypeName,' ' ,'[ ',T_SampleTypeCode,' ]') as Nat_TestNames,
'xxx' as action
from t_specimenlocal
JOIN nat_test ON T_SpecimenLocalNat_TestID = Nat_TestID
JOIN t_sampletype ON T_SpecimenLocalT_SampleTypeID = T_SampleTypeID
where
T_SpecimenLocalNat_TestID = {$id} AND T_SpecimenLocalIsActive = 'Y'";
//echo $sql;
$rows = $this->db_onedev->query($sql)->result();
$result = array ("total" => count($rows), "records" => $rows);
$this->sys_ok($result);
} catch(Exception $exc) {
$message = $exc->getMessage();
$this->sys_error($message);
}
}
public function lookup()
{
try {
//# cek token valid
if (! $this->isLogin) {
$this->sys_error("Invalid Token");
exit;
}
$prm = $this->sys_input;
$search = $prm['search'];
$all = $prm['all'];
$limit = '';
if($all == 'N'){
$limit = 'ORDER BY Nat_TestCode ASC LIMIT 10';
}
$sql = "select COUNT(*) as total
from nat_test
LEFT JOIN nat_sampletype ON Nat_TestNat_SampleTypeID = Nat_SampleTypeID
where
Nat_TestIsActive = 'Y'";
$sql_param = array($search);
$total = $this->db_onedev->query($sql,$sql_param)->row()->total;
$sql = "select Nat_TestID as id, Nat_TestName as name,
Nat_SampleTypeName as samplename,
CONCAT(Nat_TestName,' ' ,'[ ',Nat_TestCode,' ]') as description
from nat_test
LEFT JOIN nat_sampletype ON Nat_TestNat_SampleTypeID = Nat_SampleTypeID
where
( Nat_TestName LIKE CONCAT('%','{$search}','%')
)AND
Nat_TestIsActive = 'Y' $limit";
$sql_param = array($search);
$query = $this->db_onedev->query($sql);
//echo $this->db_onedev->last_query();
if ($query) {
$rows = $query->result_array();
} else {
$this->sys_error_db("nat_test select");
exit;
}
$result = array ("total" => $total, "total_filter"=>count($rows),"records" => $rows);
$this->sys_ok($result);
} catch(Exception $exc) {
$message = $exc->getMessage();
$this->sys_error($message);
}
}
public function addnewtest()
{
try {
//# cek token valid
if (! $this->isLogin) {
$this->sys_error("Invalid Token");
exit;
}
//# ambil parameter input
$prm = $this->sys_input;
$name_test = $prm['name'];
$address_test = $prm['address'];
$phone_test = $prm['phone'];
$email_test = $prm['email'];
$pic_test = $prm['pic'];
$testtypenew_test = $prm['testtypenew'];
$testtype_test = $prm['testtype'];
$islabfrom = $prm['islabfrom'];
$islabto = $prm['islabto'];
$city = $prm['city'];
$district = $prm['district'];
$kelurahan = $prm['kelurahan'];
$testmindp = $prm['testmindp'];
$doctor = $prm['doctor'];
if($testtypenew_test != ''){
$sql = "insert into nat_testtype(
Nat_TestTypeName,
Nat_TestTypeCreated,
Nat_TestTypeLastUpdated
)
values( ?, now(), now())";
$query = $this->db_onedev->query($sql,
array(
$testtypenew_test
)
);
//echo $query;
if (!$query) {
$this->sys_error_db("nat_testtype insert");
exit;
}
$testtypenewid = $this->db_onedev->insert_id();
$sqltest = "insert into nat_test(
Nat_TestName,
Nat_TestNat_CityID,
Nat_TestNat_DistrictID,
Nat_TestNat_KelurahanID,
Nat_TestAddress,
Nat_TestPhone,
Nat_TestEmail,
Nat_TestPIC,
Nat_TestNat_TestTypeID,
Nat_TestIsLabFrom,
Nat_TestIsLabTo,
Nat_TestMinDP,
Nat_TestNat_DoctorID,
Nat_TestCreated,
Nat_TestLastUpdated
)
values( ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, now(), now())";
$querytest = $this->db_onedev->query($sqltest,
array(
$name_test,
$city,
$district,
$kelurahan,
$address_test,
$phone_test,
$email_test,
$pic_test,
$testtypenewid,
$islabfrom,
$islabto,
$testmindp,
$doctor
)
);
//echo $query;
if (!$querytest) {
$this->sys_error_db("nat_test insert");
exit;
}
$result = array ("total" => 1, "records" => array("xid" => 0));
$this->sys_ok($result);
} else{
$sql = "insert into nat_test(
Nat_TestName,
Nat_TestNat_CityID,
Nat_TestNat_DistrictID,
Nat_TestNat_KelurahanID,
Nat_TestAddress,
Nat_TestPhone,
Nat_TestEmail,
Nat_TestPIC,
Nat_TestNat_TestTypeID,
Nat_TestIsLabFrom,
Nat_TestIsLabTo,
Nat_TestMinDP,
Nat_TestNat_DoctorID,
Nat_TestCreated,
Nat_TestLastUpdated
)
values( ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, now(), now())";
$query = $this->db_onedev->query($sql,
array(
$name_test,
$city,
$district,
$kelurahan,
$address_test,
$phone_test,
$email_test,
$pic_test,
$testtype_test,
$islabfrom,
$islabto,
$testmindp,
$doctor
)
);
//echo $query;
if (!$query) {
$this->sys_error_db("nat_test insert");
exit;
}
$result = array ("total" => 1, "records" => array("xid" => 0));
$this->sys_ok($result);
}
} catch(Exception $exc) {
$message = $exc->getMessage();
$this->sys_error($message);
}
}
public function edittest()
{
try {
//# cek token valid
if (! $this->isLogin) {
$this->sys_error("Invalid Token");
exit;
}
//# ambil parameter input
$prm = $this->sys_input;
$id_test = $prm['id'];
$name_test = $prm['name'];
$address_test = $prm['address'];
$phone_test = $prm['phone'];
$email_test = $prm['email'];
$pic_test = $prm['pic'];
$testtypenew_test = $prm['testtypenew'];
$testtype_test = $prm['testtype'];
$islabfrom = $prm['islabfrom'];
$islabto = $prm['islabto'];
$city = $prm['city'];
$district = $prm['district'];
$kelurahan = $prm['kelurahan'];
$testmindp = $prm['testmindp'];
$doctor = $prm['doctor'];
if($testtypenew_test != ''){
$sql = "insert into nat_testtype(
Nat_TestTypeName,
Nat_TestTypeCreated,
Nat_TestTypeLastUpdated
)
values( ?, now(), now())";
$query = $this->db_onedev->query($sql,
array(
$testtypenew_test
)
);
//echo $query;
if (!$query) {
$this->sys_error_db("nat_testtype insert");
exit;
}
$testtypenewid = $this->db_onedev->insert_id();
$sqltest = "update nat_test SET
Nat_TestName = ?,
Nat_TestNat_CityID = ?,
Nat_TestNat_DistrictID = ?,
Nat_TestNat_KelurahanID = ?,
Nat_TestAddress = ?,
Nat_TestPhone = ?,
Nat_TestEmail = ?,
Nat_TestPIC = ?,
Nat_TestNat_TestTypeID = ?,
Nat_TestIsLabFrom = ?,
Nat_TestIsLabTo = ?,
Nat_TestMinDP = ?,
Nat_TestNat_DoctorID = ?,
Nat_TestLastUpdated = now()
where
Nat_TestID = ?
";
$querytest = $this->db_onedev->query($sqltest,
array(
$name_test,
$city,
$district,
$kelurahan,
$address_test,
$phone_test,
$email_test,
$pic_test,
$testtypenewid,
$islabfrom,
$islabto,
$testmindp,
$doctor,
$id_test
)
);
//echo $query;
if (!$querytest) {
$this->sys_error_db("nat_test update");
exit;
}
$result = array ("total" => 1, "records" => array("xid" => $id_test));
$this->sys_ok($result);
} else {
$sql = "update nat_test SET
Nat_TestName = ?,
Nat_TestNat_CityID = ?,
Nat_TestNat_DistrictID = ?,
Nat_TestNat_KelurahanID = ?,
Nat_TestAddress = ?,
Nat_TestPhone = ?,
Nat_TestEmail = ?,
Nat_TestPIC = ?,
Nat_TestNat_TestTypeID = ?,
Nat_TestIsLabFrom = ?,
Nat_TestIsLabTo = ?,
Nat_TestMinDP = ?,
Nat_TestNat_DoctorID = ?,
Nat_TestLastUpdated = now()
where
Nat_TestID = ?
";
$query = $this->db_onedev->query($sql,
array(
$name_test,
$city,
$district,
$kelurahan,
$address_test,
$phone_test,
$email_test,
$pic_test,
$testtype_test,
$islabfrom,
$islabto,
$testmindp,
$doctor,
$id_test
)
);
//echo $query;
if (!$query) {
$this->sys_error_db("nat_test update");
exit;
}
$result = array ("total" => 1, "records" => array("xid" => $id_test));
$this->sys_ok($result);
}
} catch(Exception $exc) {
$message = $exc->getMessage();
$this->sys_error($message);
}
}
public function addnewspecimenlocal()
{
try {
//# cek token valid
if (! $this->isLogin) {
$this->sys_error("Invalid Token");
exit;
}
//# ambil parameter input
$prm = $this->sys_input;
$testid = $prm['testid'];
$sampletypeid = $prm['sampletypeid'];
if($prm['xid'] == "0" || $prm['xid'] == 0){
$sql = "insert into t_specimenlocal(
T_SpecimenLocalNat_TestID,
T_SpecimenLocalT_SampleTypeID,
T_SpecimenLocalCreated,
T_SpecimenLocalLastUpdated
)
values( ?,?,now(),now())";
$query = $this->db_onedev->query($sql,
array(
$testid,
$sampletypeid
)
);
//echo $query;
if (!$query) {
$this->sys_error_db("t_specimenlocal insert");
exit;
}
$result = array ("total" => 1, "records" => array("xid" => 0));
$this->sys_ok($result);
}else{
$sql = "UPDATE t_specimenlocal SET T_SpecimenLocalNat_TestID = '{$testid}' WHERE T_SpecimenLocalID = '{$prm['xid']}'";
//echo $sql;
$query = $this->db_onedev->query($sql);
$result = array ("total" => 1, "records" => array("xid" => 0));
$this->sys_ok($result);
}
} catch(Exception $exc) {
$message = $exc->getMessage();
$this->sys_error($message);
}
}
public function deletespecimenlocal()
{
try {
//# cek token valid
if (! $this->isLogin) {
$this->sys_error("Invalid Token");
exit;
}
//# ambil parameter input
$prm = $this->sys_input;
$sql = "update t_specimenlocal SET
T_SpecimenLocalIsActive = 'N',
T_SpecimenLocalLastUpdated = now()
WHERE
T_SpecimenLocalID = ?
";
$query = $this->db_onedev->query($sql,
array(
$prm['id']
)
);
// echo $query;
if (!$query) {
$this->sys_error_db("t_specimenlocal delete");
exit;
}
$result = array ("total" => 1, "records" => array("xid" => 0));
$this->sys_ok($result);
} catch(Exception $exc) {
$message = $exc->getMessage();
$this->sys_error($message);
}
}
public function deletetest()
{
try {
//# cek token valid
if (! $this->isLogin) {
$this->sys_error("Invalid Token");
exit;
}
//# ambil parameter input
$prm = $this->sys_input;
$sql = "update nat_test SET
Nat_TestIsActive = 'N',
Nat_TestLastUpdated = now()
WHERE
Nat_TestID = ?
";
$query = $this->db_onedev->query($sql,
array(
$prm['id']
)
);
// echo $query;
if (!$query) {
$this->sys_error_db("nat_test delete");
exit;
}
$sql = "UPDATE t_specimenlocal SET
T_SpecimenLocalIsActive = 'N',
T_SpecimenLocalLastUpdated = now()
WHERE
T_SpecimenLocalNat_TestID = ?
";
$query = $this->db_onedev->query($sql,
array(
$prm['id']
)
);
// echo $query;
if (!$query) {
$this->sys_error_db("t_specimenlocal delete");
exit;
}
$result = array ("total" => 1, "records" => array("xid" => 0));
$this->sys_ok($result);
} catch(Exception $exc) {
$message = $exc->getMessage();
$this->sys_error($message);
}
}
function selecttesttype(){
try {
//# cek token valid
if (! $this->isLogin) {
$this->sys_error("Invalid Token");
exit;
}
$rows = [];
$query =" SELECT *
FROM nat_testtype
WHERE
Nat_TestTypeIsActive = 'Y'
";
//echo $query;
$rows['testtypes'] = $this->db_onedev->query($query)->result_array();
$result = array(
"total" => count($rows) ,
"records" => $rows,
);
$this->sys_ok($result);
} catch(Exception $exc) {
$message = $exc->getMessage();
$this->sys_error($message);
}
}
function selectdoctor(){
try {
//# cek token valid
if (! $this->isLogin) {
$this->sys_error("Invalid Token");
exit;
}
$rows = [];
$query =" SELECT *
FROM nat_doctor
WHERE
Nat_DoctorIsActive = 'Y'
";
//echo $query;
$rows['doctors'] = $this->db_onedev->query($query)->result_array();
$result = array(
"total" => count($rows) ,
"records" => $rows,
);
$this->sys_ok($result);
} catch(Exception $exc) {
$message = $exc->getMessage();
$this->sys_error($message);
}
}
function searchsampletype(){
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 t_sampletype
WHERE
T_SampleTypeName like ?
AND T_SampleTypeIsActive = '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("t_sampletype count",$this->db);
exit;
}
$sql = "
SELECT * FROM(SELECT *, CONCAT(T_SampleTypeName,' ' ,'[ ',T_SampleTypeCode,' ]') as T_SampleTypeNames
FROM t_sampletype
WHERE T_SampleTypeIsActive = 'Y') a
WHERE
T_SampleTypeNames like ?
AND T_SampleTypeIsActive = 'Y'
ORDER BY T_SampleTypeName 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("t_sampletype rows",$this->db);
exit;
}
}
function searchcity(){
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 nat_city
WHERE
Nat_CityName like ?
AND Nat_CityIsActive = '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("nat_city count",$this->db);
exit;
}
$sql = "
SELECT *
FROM nat_city
WHERE
Nat_CityName like ?
AND Nat_CityIsActive = 'Y'
ORDER BY Nat_CityName 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("nat_city rows",$this->db);
exit;
}
}
function getdistrict(){
$prm = $this->sys_input;
$query =" SELECT *
FROM nat_district
WHERE
Nat_DistrictIsActive = 'Y' AND Nat_DistrictNat_CityID = ?
";
//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 getkelurahan(){
$prm = $this->sys_input;
$query =" SELECT *
FROM nat_kelurahan
WHERE
Nat_KelurahanIsActive = 'Y' AND Nat_KelurahanNat_DistrictID = ?
";
//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;
}
}