Files
BE_CPONE/application/controllers/v1/su/Barcode.php_18724
2026-04-27 10:26:26 +07:00

356 lines
14 KiB
Plaintext

<?php
ini_set('display_errors', 1);
ini_set('display_startup_errors', 1);
error_reporting(E_ALL);
class Barcode extends CI_Controller
{
function formulir()
{
$orderId = $this->input->get("orderId");
$this->db_onedev = $this->load->database("onedev", true);
if ($orderId == "") $orderId = "'0'";
$sql = "select
DATE_FORMAT(T_OrderHeaderDate, '%d-%m-%Y ')as datereg,
T_OrderHeaderLabNumber as nolab,
M_PatientNoReg as noreg,
CONCAT(IFNULL(M_TitleName,''),'. ',ifnull(M_PatientPrefix,'') , ' ' ,M_PatientName,' ' , ifnull(M_PatientSuffix,'')) AS M_PatientName,
T_OrderHeaderM_PatientAge as age,
DATE_FORMAT(M_PatientDOB, '%d-%m-%Y') AS M_PatientDOB,
M_PatientAddress AS alamat,
'' as city,
'' AS M_DoctorName,
group_concat(distinct T_TestName) as test,
IF(M_PatientGender = 'male','L','P') as sexcode,
CorporateName as patienttype
from t_orderheader
join m_patient on T_OrderHeaderM_PatientID = M_PatientID
join t_orderdetail on T_OrderDetailT_OrderHeaderID = T_OrderHeaderID
join t_test on T_OrderDetailT_TestID = T_TestID
join m_title on M_PatientM_TitleID = M_TitleID
left join corporate ON T_OrderHeaderCorporateID = CorporateID AND CorporateIsActive = 'Y'
where T_OrderHeaderID = {$orderId}
group by T_OrderHeaderID ";
$query = $this->db_onedev->query($sql);
$rows = $query->result_array();
$data = array();
if (count($rows) > 0) $data = $rows[0];
echo json_encode(array(
"status" => "OK",
"message" => "",
"rows" => $data
));
}
function so_group()
{
$orderId = $this->input->get("orderId");
$this->db_onedev = $this->load->database("onedev", true);
if ($orderId == "") $orderId = "'0'";
$sql = "select
DATE_FORMAT(T_OrderHeaderDate, '%d-%m-%Y ')as datereg,
fn_lookup_external(T_OrderHeaderLabNumber,'L') as nolab,
M_PatientNoReg as noreg,
CONCAT(M_TitleName,'. ',ifnull(M_PatientPrefix,'') , ' ' ,M_PatientName,' ' , ifnull(M_PatientSuffix,'')) AS M_PatientName,
T_OrderHeaderM_PatientAge as age,
DATE_FORMAT(M_PatientDOB, '%d-%m-%Y') AS M_PatientDOB,
(SELECT M_PatientAddressDescription from m_patientaddress AS p
WHERE M_PatientAddressM_PatientID = M_PatientID
ORDER BY M_PatientAddressM_PatientID
LIMIT 1) AS alamat,
M_CityName as city,
CONCAT(M_DoctorPrefix,' ',M_DoctorName,' ',M_DoctorSufix) AS M_DoctorName,
group_concat(distinct T_TestName separator ', ') as test ,
M_SexCode as sexcode, M_CompanyName as patienttype
from t_orderheader
join m_patient on T_OrderHeaderM_PatientID = M_PatientID
join t_orderdetail on T_OrderDetailT_OrderHeaderID = T_OrderHeaderID AND T_OrderDetailIsActive = 'Y'
join t_test on T_OrderDetailT_TestID = T_TestID
join so_resultentry on T_OrderDetailID = So_ResultEntryT_OrderDetailID
join m_title on M_PatientM_TitleID = M_TitleID
left join m_sex ON M_PatientM_SexID = M_SexID AND M_SexIsActive = 'Y'
left join m_company ON T_OrderHeaderM_CompanyID = M_CompanyID AND M_CompanyIsActive = 'Y'
left join m_mou ON T_OrderHeaderM_MouID = M_MouID AND M_MouIsActive = 'Y'
left join m_doctor ON T_OrderHeaderSenderM_DoctorID = M_DoctorID AND M_DoctorIsActive = 'Y'
left join m_patientaddress on M_PatientAddressM_PatientID = M_PatientID
left join m_kelurahan on M_PatientAddressM_KelurahanID = M_KelurahanID
left join m_district on M_KelurahanM_DistrictID = M_DistrictID
left join m_city on M_DistrictM_CityID = M_CityID
where T_OrderHeaderID = $orderId and T_TestIsResult ='y' and T_TestIsNonLab <> ''
group by T_OrderHeaderID ";
$query = $this->db_onedev->query($sql);
$rows = $query->result_array();
$data = array();
if (count($rows) > 0) $data = $rows[0];
echo json_encode(array(
"status" => "OK",
"message" => "",
"rows" => $data
));
}
/*
//+ "^FT5,200^A0N,23,24^FH\^FD"+ data.city+"^FS"+ "\n"
//+ "^FT5,175^A0N,23,24^FH\^FD" + data.address + "^FS"+ "\n"
//+ "^FT3,150^A0N,28,28^FH\^FD"+ data.title+" "+ data.patientName +"^FS"+ "\n"
//+ "^BY3,3,45^FT22,70^BCN,,Y,N"+ "\n"
//+ "^FD>;" + xbarcodeId + "^FS"+ "\n"
//+ "^FT5,225^A0N,23,24^FH\^FD"+ data.patienttype +"^FS"+ "\n"
//+ "^PQ1,0,1,Y^XZ"+ "\n"
*/
function so()
{
$orderId = $this->input->get("orderId");
$this->db_onedev = $this->load->database("onedev", true);
if ($orderId == "") $orderId = "'0'";
// orderId = order detail id
$sql = "select
DATE_FORMAT(T_OrderHeaderDate, '%d-%m-%Y ')as datereg,
T_OrderHeaderLabNumber as nolab,
M_PatientNoReg as noreg,
CONCAT(IF(M_TitleName IS NULL,'',CONCAT(M_TitleName,'. ')),ifnull(M_PatientPrefix,'') , ' ' ,M_PatientName,' ' , ifnull(M_PatientSuffix,'')) AS M_PatientName,
T_OrderHeaderM_PatientAge as age,
DATE_FORMAT(M_PatientDOB, '%d-%m-%Y') AS M_PatientDOB,
M_PatientAddress AS alamat,
M_PatientAddressCity as city,
'' AS M_DoctorName,
T_TestName as test,
IF(M_PatientGender = 'male','L','P') as sex_code, CorporateName as patienttype
from t_orderheader
join m_patient on T_OrderHeaderM_PatientID = M_PatientID
join t_orderdetail on T_OrderHeaderID = T_OrderDetailT_OrderHeaderID and T_OrderHeaderID = $orderId
join t_test on T_OrderDetailT_TestID = T_TestID
left join m_title on M_PatientM_TitleID = M_TitleID
left join corporate ON T_OrderHeaderCorporateID = CorporateID AND CorporateIsActive = 'Y'
";
$query = $this->db_onedev->query($sql);
//echo $sql;
$rows = $query->result_array();
foreach ($rows as $key => $value) {
$oldage = explode("tahun", $value['age']);
$rows[$key]['age'] = $oldage[0] . ' Tahun';
}
echo json_encode(array(
"status" => "OK",
"message" => "",
"rows" => $rows
));
}
function sov1()
{
$orderId = $this->input->get("orderId");
$this->db_onedev = $this->load->database("onedev", true);
if ($orderId == "") $orderId = "'0'";
// orderId = order detail id
$a_bcodes = explode(",", $orderId);
$s_bcode = "";
foreach ($a_bcodes as $b) {
if ($s_bcode != "") $s_bcode .= ",";
$s_bcode .= "'$b'";
}
$sql = "select
DATE_FORMAT(T_OrderHeaderDate, '%d-%m-%Y ')as datereg,
T_OrderHeaderLabNumber as nolab,
M_PatientNoReg as noreg,
CONCAT(IF(M_TitleName IS NULL,'',CONCAT(M_TitleName,'. ')),ifnull(M_PatientPrefix,'') , ' ' ,M_PatientName,' ' , ifnull(M_PatientSuffix,'')) AS M_PatientName,
T_OrderHeaderM_PatientAge as age,
DATE_FORMAT(M_PatientDOB, '%d-%m-%Y') AS M_PatientDOB,
M_PatientAddress AS alamat,
M_PatientAddressCity as city,
'' AS M_DoctorName,
T_TestName as test,
IF(M_PatientGender = 'male','L','P') as sex_code, CorporateName as patienttype
from t_orderheader
join m_patient on T_OrderHeaderM_PatientID = M_PatientID
join t_orderdetail on T_OrderHeaderID = T_OrderDetailT_OrderHeaderID and T_OrderDetailID IN ($s_bcode)
join t_test on T_OrderDetailT_TestID = T_TestID
JOIN nonlab_barcode ON T_TestNat_TestID = Nonlab_BarcodeNat_TestID AND Nonlab_BarcodeIsActive = 'Y'
left join m_title on M_PatientM_TitleID = M_TitleID
left join corporate ON T_OrderHeaderCorporateID = CorporateID AND CorporateIsActive = 'Y'
GROUP BY Nonlab_BarcodeID
";
$query = $this->db_onedev->query($sql);
//echo $sql;
$rows = $query->result_array();
foreach ($rows as $key => $value) {
$oldage = explode("tahun", $value['age']);
$rows[$key]['age'] = $oldage[0] . ' Tahun';
}
echo json_encode(array(
"status" => "OK",
"message" => "",
"rows" => $rows
));
}
function so_label()
{
$orderId = $this->input->get("orderId");
$this->db_onedev = $this->load->database("onedev", true);
if ($orderId == "") $orderId = "'0'";
$sql = "select
CONCAT(M_TitleName,'. ',ifnull(M_PatientPrefix,'') , ' ' ,M_PatientName,' ' , ifnull(M_PatientSuffix,'')) AS M_PatientName,
concat(M_PatientKedudukan ,' / ',M_PatientNIK ) as nrp,
M_PatientJob,
M_PatientJabatan ,
concat(DATE_FORMAT(M_PatientDOB, '%d/%m/%Y') , ' (',TIMESTAMPDIFF(YEAR, M_PatientDOB, CURDATE()) ,' th) ', M_SexName , ', ',ifnull(M_ReligionName,'')) as tgllahir,
(SELECT concat(M_PatientAddressDescription , ' ' , M_KelurahanName)
from m_patientaddress AS p
left join m_kelurahan on M_PatientAddressM_KelurahanID = M_KelurahanID
left join m_district on M_KelurahanM_DistrictID = M_DistrictID
left join m_city on M_DistrictM_CityID = M_CityID
WHERE M_PatientAddressM_PatientID = M_PatientID
ORDER BY M_PatientAddressM_PatientID
LIMIT 1) AS alamat,
M_PatientHP,
concat(T_OrderHeaderLabNumber,' / ', DATE_FORMAT(T_OrderHeaderDate, '%d/%m/%Y ')) as lab,
DATE_FORMAT(T_OrderHeaderDate, '%d-%m-%Y ')as datereg,
fn_lookup_external(T_OrderHeaderLabNumber,'L') as nolab,
M_PatientNoReg as noreg, M_CompanyName as patienttype,
M_PatientPJ ,
M_PatientLocation ,
M_PatientIDNumber
from t_orderheader
left join m_patient on T_OrderHeaderM_PatientID = M_PatientID
left join m_title on M_PatientM_TitleID = M_TitleID
left join m_religion on M_PatientM_ReligionID = M_ReligionID
left join m_sex ON M_PatientM_SexID = M_SexID AND M_SexIsActive = 'Y'
left join m_company ON T_OrderHeaderM_CompanyID = M_CompanyID AND M_CompanyIsActive = 'Y'
left join m_mou ON T_OrderHeaderM_MouID = M_MouID AND M_MouIsActive = 'Y'
where T_OrderHeaderID = $orderId
group by T_OrderHeaderID ";
$query = $this->db_onedev->query($sql);
$rows = $query->result_array();
$data = array();
if (count($rows) > 0) $data = $rows[0];
echo json_encode(array(
"status" => "OK",
"message" => "",
"rows" => $data
));
}
function formulir_khusus()
{
$orderId = $this->input->get("orderId");
$this->db_onedev = $this->load->database("onedev", true);
if ($orderId == "") $orderId = "'0'";
$sql = "select
DATE_FORMAT(T_OrderHeaderDate, '%d-%m-%Y ')as datereg,
T_OrderHeaderLabNumber as nolab,
M_PatientNoReg as noreg,
CONCAT(M_TitleName,'. ',ifnull(M_PatientPrefix,'') , ' ' ,M_PatientName,' ' , ifnull(M_PatientSuffix,'')) AS M_PatientName,
T_OrderHeaderM_PatientAge as age,
concat(M_PatientKedudukan ,' / ',M_PatientNIK ) as nrp,
M_PatientJob,
M_PatientJabatan ,
concat( ' (',TIMESTAMPDIFF(YEAR, M_PatientDOB, CURDATE()) ,' th) ', M_SexCode ) as tgllahir,
DATE_FORMAT(M_PatientDOB, '%d-%m-%Y') AS M_PatientDOB,
(SELECT M_PatientAddressDescription from m_patientaddress AS p
WHERE M_PatientAddressM_PatientID = M_PatientID
ORDER BY M_PatientAddressM_PatientID
LIMIT 1) AS alamat,
M_CityName as city,
CONCAT(M_DoctorPrefix,' ',M_DoctorName,' ',M_DoctorSufix) AS M_DoctorName,
group_concat(distinct T_TestName) as test ,
M_SexCode as sexcode, M_CompanyName as patienttype
from t_orderheader
join m_patient on T_OrderHeaderM_PatientID = M_PatientID
join t_orderdetail on T_OrderDetailT_OrderHeaderID = T_OrderHeaderID
join t_test on T_OrderDetailT_TestID = T_TestID
join m_title on M_PatientM_TitleID = M_TitleID
left join m_religion on M_PatientM_ReligionID = M_ReligionID
left join m_sex ON M_PatientM_SexID = M_SexID AND M_SexIsActive = 'Y'
left join m_company ON T_OrderHeaderM_CompanyID = M_CompanyID AND M_CompanyIsActive = 'Y'
left join m_mou ON T_OrderHeaderM_MouID = M_MouID AND M_MouIsActive = 'Y'
left join m_doctor ON T_OrderHeaderSenderM_DoctorID = M_DoctorID AND M_DoctorIsActive = 'Y'
left join m_patientaddress on M_PatientAddressM_PatientID = M_PatientID
left join m_kelurahan on M_PatientAddressM_KelurahanID = M_KelurahanID
left join m_district on M_KelurahanM_DistrictID = M_DistrictID
left join m_city on M_DistrictM_CityID = M_CityID
where T_OrderHeaderID = $orderId
group by T_OrderHeaderID ";
$query = $this->db_onedev->query($sql);
$rows = $query->result_array();
$data = array();
if (count($rows) > 0) $data = $rows[0];
echo json_encode(array(
"status" => "OK",
"message" => "",
"rows" => $data
));
}
function pk()
{
$barcodeId = $this->input->get("barcodeId");
$this->db_onedev = $this->load->database("onedev", true);
if ($barcodeId == "") $barcodeId = "'0'";
$a_bcodes = explode(",", $barcodeId);
$s_bcode = "";
foreach ($a_bcodes as $b) {
if ($s_bcode != "") $s_bcode .= ",";
$s_bcode .= "'$b'";
}
$sql = "select
RIGHT(T_OrderHeaderLabNumber,7 ) T_OrderHeaderLabNumber ,
T_OrderHeaderLabNumber Full_T_OrderHeaderLabNumber,
T_SampleTypeName,
left(T_BarcodeLabBarcode ,13) T_BarcodeLabBarcode ,
CONCAT(M_TitleName,'. ',ifnull(M_PatientPrefix,'') , ' ' ,M_PatientName,' ' , ifnull(M_PatientSuffix,'')) M_PatientName,
M_PatientNoReg,
T_OrderHeaderM_PatientAge,
DATE_FORMAT(M_PatientDOB, '%d-%m-%Y') AS M_PatientDOB,
if(M_PatientGender = 'male' , 'L' , 'P') as Gender,
CorporateName,M_PatientNIP,
DATE_FORMAT(T_OrderHeaderDate,'%d/%m/%Y') T_OrderHeaderDate,
case
when M_PatientGender = 'male' then 'M'
when M_PatientGender = 'female' then 'F'
end Sex,
T_SampleTypeSuffix
from t_barcodelab
join t_sampletype on T_BarcodeLabT_SampleTypeID = T_SampleTypeID
join t_orderheader on T_BarcodeLabT_OrderHeaderID = T_OrderHeaderID
join m_patient on T_OrderHeaderM_PatientID = M_PatientID
join m_title on M_PatientM_TitleID = M_TitleID
left join corporate on T_OrderHeaderCorporateID = CorporateID and CorporateIsActive = 'Y'
where T_BarcodeLabBarcode in ( $s_bcode ) ";
$query = $this->db_onedev->query($sql);
//echo $sql;
$rows = $query->result_array();
echo json_encode(array(
"status" => "OK",
"message" => "",
"rows" => $rows
));
}
}