1236 lines
40 KiB
PHP
1236 lines
40 KiB
PHP
<?php
|
|
class Patient extends MY_Controller
|
|
{
|
|
var $db_onedev;
|
|
public function index()
|
|
{
|
|
echo "Patient API";
|
|
}
|
|
public function __construct()
|
|
{
|
|
parent::__construct();
|
|
$this->db_onedev = $this->load->database("onedev", true);
|
|
}
|
|
function _add_address(&$pat) {
|
|
if (count($pat) == "0") {
|
|
return array();
|
|
}
|
|
foreach($pat as $idx => $p ) {
|
|
$pat[$idx]["address"] = array($p["M_PatientAddress"]);
|
|
}
|
|
}
|
|
|
|
function add_address_patient($orderid){
|
|
$query =" SELECT M_PatientAddressID as id,
|
|
M_PatientAddressNote as note,
|
|
M_PatientAddressDescription as description,
|
|
M_PatientAddressM_KelurahanID as vilageid
|
|
FROM m_patientaddress
|
|
JOIN t_orderheader ON M_PatientAddressM_PatientID = T_OrderHeaderM_PatientID
|
|
WHERE
|
|
T_OrderHeaderID = {$orderid} AND M_PatientAddressIsActive = 'Y'
|
|
";
|
|
//echo $query;
|
|
$rows = $this->db_onedev->query($query)->result_array();
|
|
if($rows)
|
|
return $rows;
|
|
else
|
|
return array();
|
|
}
|
|
|
|
function add_address_doctor($orderid){
|
|
$query =" SELECT M_DoctorAddressID as id,
|
|
M_DoctorAddressNote as note,
|
|
M_DoctorAddressDescription as description,
|
|
M_DoctorAddressM_KelurahanID as vilageid
|
|
FROM m_doctoraddress
|
|
JOIN t_orderheader ON T_OrderHeaderSenderM_DoctorID = M_DoctorAddressM_DoctorID
|
|
WHERE
|
|
T_OrderHeaderID = {$orderid} AND M_DoctorAddressIsActive = 'Y'
|
|
";
|
|
//echo $query;
|
|
$rows = $this->db_onedev->query($query)->result_array();
|
|
if($rows)
|
|
return $rows;
|
|
else
|
|
return array();
|
|
}
|
|
|
|
function add_verification_patient($orderid){
|
|
$query =" SELECT Fo_VericationTypeID as id,
|
|
IFNULL(Fo_VerificationID,0) as xid,
|
|
IFNULL(Fo_VerificationIsOK,'N') as chex,
|
|
IF(ISNULL(Fo_VerificationID),'',Fo_VerificationReason) as note,
|
|
Fo_VerificationTypeLabel as label
|
|
FROM fo_verificationtype
|
|
LEFT JOIN fo_verification ON Fo_VerificationFo_VericationTypeID = Fo_VericationTypeID AND Fo_VerificationT_OrderHeaderID = $orderid
|
|
WHERE
|
|
Fo_VerificationTypeGroup = 'PATIENT' AND Fo_VerificationTypeIsActive = 'Y'
|
|
GROUP BY Fo_VericationTypeID
|
|
";
|
|
//echo $query;
|
|
$rows = $this->db_onedev->query($query)->result_array();
|
|
foreach($rows as $k => $v){
|
|
if($v['chex'] == 'N')
|
|
$rows[$k]['chex'] = false;
|
|
else
|
|
$rows[$k]['chex'] = true;
|
|
}
|
|
return $rows;
|
|
}
|
|
|
|
function add_verification_doctor($orderid){
|
|
$query =" SELECT Fo_VericationTypeID as id,
|
|
IFNULL(Fo_VerificationID,0) as xid,
|
|
IFNULL(Fo_VerificationIsOK,'N') as chex,
|
|
IF(ISNULL(Fo_VerificationID),'',Fo_VerificationReason) as note,
|
|
Fo_VerificationTypeLabel as label
|
|
FROM fo_verificationtype
|
|
LEFT JOIN fo_verification ON Fo_VerificationFo_VericationTypeID = Fo_VericationTypeID AND Fo_VerificationT_OrderHeaderID = $orderid
|
|
WHERE
|
|
Fo_VerificationTypeGroup = 'DOCTOR' AND Fo_VerificationTypeIsActive = 'Y'
|
|
GROUP BY Fo_VericationTypeID
|
|
";
|
|
$rows = $this->db_onedev->query($query)->result_array();
|
|
foreach($rows as $k => $v){
|
|
if($v['chex'] == 'N')
|
|
$rows[$k]['chex'] = false;
|
|
else
|
|
$rows[$k]['chex'] = true;
|
|
}
|
|
return $rows;
|
|
}
|
|
|
|
function add_verification_companymou($orderid){
|
|
$query =" SELECT Fo_VericationTypeID as id,
|
|
IFNULL(Fo_VerificationID,0) as xid,
|
|
IFNULL(Fo_VerificationIsOK,'N') as chex,
|
|
IF(ISNULL(Fo_VerificationID),'',Fo_VerificationReason) as note,
|
|
Fo_VerificationTypeLabel as label
|
|
FROM fo_verificationtype
|
|
LEFT JOIN fo_verification ON Fo_VerificationFo_VericationTypeID = Fo_VericationTypeID AND Fo_VerificationT_OrderHeaderID = $orderid
|
|
WHERE
|
|
Fo_VerificationTypeGroup = 'COMPANY' AND Fo_VerificationTypeIsActive = 'Y'
|
|
GROUP BY Fo_VericationTypeID
|
|
";
|
|
$rows = $this->db_onedev->query($query)->result_array();
|
|
foreach($rows as $k => $v){
|
|
if($v['chex'] == 'N')
|
|
$rows[$k]['chex'] = false;
|
|
else
|
|
$rows[$k]['chex'] = true;
|
|
}
|
|
return $rows;
|
|
}
|
|
|
|
function add_verification_payment($orderid){
|
|
$query =" SELECT Fo_VericationTypeID as id,
|
|
IFNULL(Fo_VerificationID,0) as xid,
|
|
IFNULL(Fo_VerificationIsOK,'N') as chex,
|
|
IF(ISNULL(Fo_VerificationID),'',Fo_VerificationReason) as note,
|
|
Fo_VerificationTypeLabel as label,
|
|
'reguler' as type
|
|
FROM fo_verificationtype
|
|
LEFT JOIN fo_verification ON Fo_VerificationFo_VericationTypeID = Fo_VericationTypeID AND Fo_VerificationT_OrderHeaderID = $orderid
|
|
WHERE
|
|
Fo_VerificationTypeGroup = 'PAYMENT' AND Fo_VerificationTypeIsActive = 'Y'
|
|
GROUP BY Fo_VericationTypeID
|
|
";
|
|
$rows = $this->db_onedev->query($query)->result_array();
|
|
foreach($rows as $k => $v){
|
|
if($v['chex'] == 'N')
|
|
$rows[$k]['chex'] = false;
|
|
else
|
|
$rows[$k]['chex'] = true;
|
|
}
|
|
return $rows;
|
|
}
|
|
|
|
function add_verification_supplies($orderid){
|
|
$query =" SELECT M_SuppliesID as id,
|
|
IFNULL(T_OrderSuppliesID,0) as xid,
|
|
IF(ISNULL(T_OrderSuppliesID),'N',T_OrderSuppliesIsActive) as chex,
|
|
IFNULL(T_OrderSuppliesQty,1) as qty,
|
|
M_SuppliesName as name,
|
|
IF(ISNULL(T_OrderSuppliesID),NOW(),T_OrderSuppliesLastUpdated) as lastupdated,
|
|
IF(ISNULL(T_OrderSuppliesID),NOW(),T_OrderSuppliesLastUpdated) as tx_lastupdated
|
|
FROM m_supplies
|
|
LEFT JOIN t_ordersupplies ON T_OrderSuppliesT_OrderHeaderID = $orderid AND T_OrderSuppliesM_SuppliesID = M_SuppliesID
|
|
WHERE
|
|
M_SuppliesIsActive = 'Y'
|
|
";
|
|
//echo $query ;
|
|
$rows = $this->db_onedev->query($query)->result_array();
|
|
foreach($rows as $k => $v){
|
|
if($v['chex'] == 'N')
|
|
$rows[$k]['chex'] = false;
|
|
else
|
|
$rows[$k]['chex'] = true;
|
|
}
|
|
return $rows;
|
|
}
|
|
|
|
function add_verification_barcode_xxx($orderid){
|
|
$query =" SELECT T_SampleTypeID as id, IFNULL(T_BarcodeLabID,0) as xid,
|
|
IF(ISNULL(T_BarcodeLabID),'N',T_BarcodeLabIsActive) as chex,
|
|
T_TestName as testname,
|
|
IFNULL(T_BarcodeLabCounter,1) as qty, T_SampleTypeName as samplename,
|
|
IF(ISNULL(T_BarcodeLabID),CONCAT(T_OrderHeaderLabNumber,'.',T_SampleTypeID,'.',1),T_BarcodeLabBarcode) as barcodenumber,
|
|
IF(ISNULL(T_BarcodeLabID),NOW(),T_BarcodeLabLastUpdated) as lastupdated,
|
|
IF(ISNULL(T_BarcodeLabID),NOW(),T_BarcodeLabLastUpdated) as tx_lastupdated
|
|
FROM t_orderdetail
|
|
JOIN t_orderheader ON T_OrderHeaderID = T_OrderDetailT_OrderHeaderID
|
|
JOIN t_test ON T_OrderDetailT_TestID = T_TestID
|
|
JOIN t_sampletype ON T_TestT_SampleTypeID = T_SampleTypeID
|
|
LEFT JOIN t_barcodelab ON T_BarcodeLabT_OrderHeaderID = T_OrderDetailT_OrderHeaderID AND
|
|
T_BarcodeLabT_SampleTypeID = T_TestT_SampleTypeID AND T_BarcodeLabIsActive = 'Y'
|
|
WHERE T_OrderDetailT_OrderHeaderID = {$orderid}
|
|
GROUP BY T_SampleTypeID
|
|
";
|
|
// echo $query ;
|
|
$rows = $this->db_onedev->query($query)->result_array();
|
|
foreach($rows as $k => $v){
|
|
if($v['chex'] == 'N')
|
|
$rows[$k]['chex'] = false;
|
|
else
|
|
$rows[$k]['chex'] = true;
|
|
}
|
|
return $rows;
|
|
}
|
|
|
|
function add_verification_barcode($orderid){
|
|
$query =" SELECT T_SampleTypeID as id,
|
|
T_SampleTypeName as name,
|
|
'' as children
|
|
FROM t_orderheader
|
|
JOIN t_orderdetail ON T_OrderDetailT_OrderHeaderID = T_OrderHeaderID
|
|
JOIN t_test ON T_OrderDetailT_TestID = T_TestID
|
|
JOIN t_sampletype ON T_TestT_SampleTypeID = T_SampleTypeID
|
|
WHERE
|
|
T_OrderHeaderID = {$orderid}
|
|
GROUP BY T_SampleTypeID
|
|
";
|
|
// echo $query ;
|
|
$rows = $this->db_onedev->query($query)->result();
|
|
foreach($rows as $k => $v){
|
|
$query = "SELECT T_SampleTypeID as id, IFNULL(T_BarcodeLabID,0) as xid,
|
|
IF(ISNULL(T_BarcodeLabID),'Y',T_BarcodeLabIsActive) as chex,
|
|
T_TestName as testname,
|
|
T_SampleTypeName as samplename,
|
|
IF(ISNULL(T_BarcodeLabID),CONCAT(T_OrderHeaderLabNumber,'.',T_SampleTypeID,'.',1),T_BarcodeLabBarcode) as barcodenumber
|
|
FROM t_orderdetail
|
|
JOIN t_orderheader ON T_OrderHeaderID = T_OrderDetailT_OrderHeaderID
|
|
JOIN t_test ON T_OrderDetailT_TestID = T_TestID
|
|
JOIN t_sampletype ON T_TestT_SampleTypeID = T_SampleTypeID
|
|
LEFT JOIN t_barcodelab ON T_BarcodeLabT_OrderHeaderID = T_OrderDetailT_OrderHeaderID AND
|
|
T_BarcodeLabT_SampleTypeID = T_TestT_SampleTypeID AND T_BarcodeLabIsActive = 'Y'
|
|
WHERE
|
|
T_OrderDetailT_OrderHeaderID = {$orderid} AND T_SampleTypeID = {$v->id}
|
|
GROUP BY T_BarcodeLabID ";
|
|
$v->children = $this->db_onedev->query($query)->result_array();
|
|
foreach($v->children as $ki => $vi){
|
|
if($vi['chex'] == 'N')
|
|
$v->children[$ki]['chex'] = false;
|
|
else
|
|
$v->children[$ki]['chex'] = true;
|
|
}
|
|
}
|
|
return $rows;
|
|
}
|
|
|
|
function add_verification_delivery($orderid){
|
|
$query =" SELECT T_OrderDeliveryID as id,
|
|
IFNULL(Fo_VerificationDeliveryID,0) as xid,
|
|
M_DeliveryTypeCode as code,
|
|
IF(ISNULL(Fo_VerificationDeliveryID),'N',Fo_VerificationDeliveryIsOK) as chex,
|
|
M_DeliveryID as deliveryid,
|
|
M_DeliveryTypeID as typedeliveryid,
|
|
T_OrderDeliveryM_KelurahanID as vilageid,
|
|
IF(ISNULL(Fo_VerificationDeliveryID),'',Fo_VerificationDeliveryReason) as note,
|
|
'reguler' as type,
|
|
CASE
|
|
WHEN T_OrderDeliveryM_DeliveryID = 1 THEN M_DeliveryName
|
|
WHEN T_OrderDeliveryM_DeliveryID = 4 THEN CONCAT(M_DeliveryName, ' : ', M_DoctorAddressDescription)
|
|
WHEN T_OrderDeliveryM_DeliveryID = 2 THEN CONCAT(M_DeliveryName, ' : ', M_PatientAddressDescription)
|
|
WHEN ( T_OrderDeliveryM_DeliveryID = 7 OR T_OrderDeliveryM_DeliveryID = 9 ) THEN CONCAT(M_DeliveryName, ' : ', M_DoctorHP)
|
|
WHEN ( T_OrderDeliveryM_DeliveryID = 6 OR T_OrderDeliveryM_DeliveryID = 8 ) THEN CONCAT(M_DeliveryName, ' : ', M_PatientHP)
|
|
ELSE
|
|
CONCAT(M_DeliveryName,' : ',T_OrderDeliveryDestination)
|
|
END as label,
|
|
CASE
|
|
WHEN T_OrderDeliveryM_DeliveryID = 1 THEN ''
|
|
WHEN T_OrderDeliveryM_DeliveryID = 4 THEN M_DoctorAddressDescription
|
|
WHEN T_OrderDeliveryM_DeliveryID = 2 THEN M_PatientAddressDescription
|
|
WHEN ( T_OrderDeliveryM_DeliveryID = 7 OR T_OrderDeliveryM_DeliveryID = 9 ) THEN M_DoctorHP
|
|
WHEN ( T_OrderDeliveryM_DeliveryID = 6 OR T_OrderDeliveryM_DeliveryID = 8 ) THEN M_PatientHP
|
|
ELSE
|
|
T_OrderDeliveryDestination
|
|
END as destination,
|
|
CASE
|
|
WHEN T_OrderDeliveryM_DeliveryID = 4 THEN M_DoctorAddressID
|
|
WHEN T_OrderDeliveryM_DeliveryID = 2 THEN M_PatientAddressID
|
|
ELSE
|
|
0
|
|
END as addressid
|
|
FROM t_orderdelivery
|
|
JOIN t_orderheader ON T_OrderDeliveryT_OrderHeaderID = T_OrderHeaderID
|
|
JOIN m_delivery ON T_OrderDeliveryM_DeliveryID = M_DeliveryID
|
|
JOIN m_deliverytype ON T_OrderDeliveryM_DeliveryTypeID = M_DeliveryTypeID
|
|
LEFT JOIN m_doctoraddress ON T_OrderDeliveryAddressID = M_DoctorAddressID AND T_OrderDeliveryM_DeliveryID = 4
|
|
LEFT JOIN m_patientaddress ON T_OrderDeliveryAddressID = M_PatientAddressID AND T_OrderDeliveryM_DeliveryID = 2
|
|
LEFT JOIN fo_verification_delivery ON Fo_VerificationDeliveryT_OrderHeaderID = T_OrderDeliveryT_OrderHeaderID AND Fo_VerificationDeliveryIsActive = 'Y'
|
|
LEFT JOIN m_doctor ON T_OrderHeaderSenderM_DoctorID = M_DoctorID AND ( T_OrderDeliveryM_DeliveryID = 7 OR T_OrderDeliveryM_DeliveryID = 9 )
|
|
LEFT JOIN m_patient ON T_OrderHeaderM_PatientID = M_PatientID AND ( T_OrderDeliveryM_DeliveryID = 6 OR T_OrderDeliveryM_DeliveryID = 8 )
|
|
WHERE
|
|
T_OrderDeliveryT_OrderHeaderID = {$orderid} AND T_OrderDeliveryIsActive = 'Y'
|
|
GROUP BY T_OrderDeliveryID
|
|
UNION
|
|
SELECT 0 as id,
|
|
IFNULL(Fo_VerificationDeliveryAddID,0) as xid,
|
|
M_DeliveryTypeCode as code,
|
|
IF(ISNULL(Fo_VerificationDeliveryAddID),'N',Fo_VerificationDeliveryAddOK) as chex,
|
|
Fo_VerificationDeliveryAddM_DeliveryID as deliveryid,
|
|
Fo_VerificationDeliveryAddM_DeliveryTypeID as typedeliveryid,
|
|
Fo_VerificationDeliveryAddM_KelurahanID as vilageid,
|
|
IF(ISNULL(Fo_VerificationDeliveryAddID),'',Fo_VerificationDeliveryAddReason) as note,
|
|
'reguler' as type,
|
|
CASE
|
|
WHEN Fo_VerificationDeliveryAddM_DeliveryID = 1 THEN M_DeliveryName
|
|
WHEN Fo_VerificationDeliveryAddM_DeliveryID = 4 THEN CONCAT(M_DeliveryName, ' : ', M_DoctorAddressDescription)
|
|
WHEN Fo_VerificationDeliveryAddM_DeliveryID = 2 THEN CONCAT(M_DeliveryName, ' : ', M_PatientAddressDescription)
|
|
WHEN ( Fo_VerificationDeliveryAddM_DeliveryID = 7 OR Fo_VerificationDeliveryAddM_DeliveryID = 9 ) THEN CONCAT(M_DeliveryName, ' : ', M_DoctorHP)
|
|
WHEN ( Fo_VerificationDeliveryAddM_DeliveryID = 6 OR Fo_VerificationDeliveryAddM_DeliveryID = 8 ) THEN CONCAT(M_DeliveryName, ' : ', M_PatientHP)
|
|
ELSE
|
|
CONCAT(M_DeliveryName,' : ',Fo_VerificationDeliveryAddDestination)
|
|
END as label,
|
|
CASE
|
|
WHEN Fo_VerificationDeliveryAddM_DeliveryID = 1 THEN ''
|
|
WHEN Fo_VerificationDeliveryAddM_DeliveryID = 4 THEN M_DoctorAddressDescription
|
|
WHEN Fo_VerificationDeliveryAddM_DeliveryID = 2 THEN M_PatientAddressDescription
|
|
WHEN ( Fo_VerificationDeliveryAddM_DeliveryID = 7 OR Fo_VerificationDeliveryAddM_DeliveryID = 9 ) THEN M_DoctorHP
|
|
WHEN ( Fo_VerificationDeliveryAddM_DeliveryID = 6 OR Fo_VerificationDeliveryAddM_DeliveryID = 8 ) THEN M_PatientHP
|
|
ELSE
|
|
Fo_VerificationDeliveryAddDestination
|
|
END as destination,
|
|
CASE
|
|
WHEN Fo_VerificationDeliveryAddM_DeliveryID = 4 THEN M_DoctorAddressID
|
|
WHEN Fo_VerificationDeliveryAddM_DeliveryID = 2 THEN M_PatientAddressID
|
|
ELSE
|
|
0
|
|
END as addressid
|
|
FROM fo_verification_delivery_add
|
|
JOIN t_orderheader ON Fo_VerificationDeliveryAddT_OrderHeaderID = T_OrderHeaderID
|
|
JOIN m_delivery ON Fo_VerificationDeliveryAddM_DeliveryID = M_DeliveryID
|
|
JOIN m_deliverytype ON Fo_VerificationDeliveryAddM_DeliveryTypeID = M_DeliveryTypeID
|
|
LEFT JOIN m_doctoraddress ON Fo_VerificationDeliveryAddAddressID = M_DoctorAddressID AND Fo_VerificationDeliveryAddM_DeliveryID = 4
|
|
LEFT JOIN m_patientaddress ON Fo_VerificationDeliveryAddAddressID = M_PatientAddressID AND Fo_VerificationDeliveryAddM_DeliveryID = 2
|
|
LEFT JOIN m_doctor ON T_OrderHeaderSenderM_DoctorID = M_DoctorID AND ( Fo_VerificationDeliveryAddM_DeliveryID = 7 OR Fo_VerificationDeliveryAddM_DeliveryID = 9 )
|
|
LEFT JOIN m_patient ON T_OrderHeaderM_PatientID = M_PatientID AND ( Fo_VerificationDeliveryAddM_DeliveryID = 6 OR Fo_VerificationDeliveryAddM_DeliveryID = 8 )
|
|
WHERE
|
|
Fo_VerificationDeliveryAddT_OrderHeaderID = {$orderid} AND Fo_VerificationDeliveryAddIsActive = 'Y'
|
|
";
|
|
//echo $query ;
|
|
$rows = $this->db_onedev->query($query)->result_array();
|
|
foreach($rows as $k => $v){
|
|
if($v['chex'] == 'N')
|
|
$rows[$k]['chex'] = false;
|
|
else
|
|
$rows[$k]['chex'] = true;
|
|
}
|
|
return $rows;
|
|
}
|
|
|
|
function add_verification_test($orderid){
|
|
$query =" SELECT * FROM (
|
|
SELECT T_OrderDetailID as id,
|
|
IFNULL(Fo_VerificationTestID,0) as xid,
|
|
IF(ISNULL(Fo_VerificationTestID),'N',Fo_VerificationTestIsOK) as chex,
|
|
IF(ISNULL(Fo_VerificationTestID),'',Fo_VerificationTestReason) as note,
|
|
T_TestID as pxid,
|
|
T_TestName as pxname,
|
|
T_OrderDetailIsCito as flagcito,
|
|
T_OrderDetailPrice as bruto,
|
|
T_OrderDetailDiscTotal as discount,
|
|
T_OrderDetailTotal as total,
|
|
'N' as addon
|
|
FROM t_orderdetail
|
|
JOIN t_test ON T_OrderDetailT_TestID = T_TestID AND T_TestIsPrice = 'Y'
|
|
LEFT JOIN fo_verification_test ON Fo_VerificationTestT_OrderDetailID = T_OrderDetailID
|
|
WHERE
|
|
T_OrderDetailT_OrderHeaderID = $orderid AND T_OrderDetailIsActive = 'Y'
|
|
UNION
|
|
SELECT 0 as id,
|
|
IFNULL(Fo_VerificationTestAddID,0) as xid,
|
|
IF(ISNULL(Fo_VerificationTestAddIsOK),'N',Fo_VerificationTestAddIsOK) as chex,
|
|
'' as note,
|
|
Fo_VerificationTestAddT_TestID as pxid,
|
|
T_TestName as pxname,
|
|
Fo_VerificationTestAddIsCito as flagcito,
|
|
Fo_VerificationTestAddBruto as bruto,
|
|
Fo_VerificationTestAddDiscount as discount,
|
|
Fo_VerificationTestAddTotal as total,
|
|
'N' as addon
|
|
FROM fo_verification_test_add
|
|
JOIN t_test ON Fo_VerificationTestAddT_TestID = T_TestID
|
|
WHERE
|
|
Fo_VerificationTestAddT_OrderHeaderID = $orderid AND Fo_VerificationTestAddIsActive = 'Y' ) x
|
|
GROUP BY pxid
|
|
";
|
|
//echo $query ;
|
|
$rows = $this->db_onedev->query($query)->result_array();
|
|
foreach($rows as $k => $v){
|
|
if($v['chex'] == 'N')
|
|
$rows[$k]['chex'] = false;
|
|
else
|
|
$rows[$k]['chex'] = true;
|
|
|
|
if($v['addon'] == 'N')
|
|
$rows[$k]['addon'] = false;
|
|
else
|
|
$rows[$k]['addon'] = true;
|
|
}
|
|
return $rows;
|
|
}
|
|
|
|
function add_verification_info($orderid){
|
|
$query =" SELECT Fo_VericationTypeID as id,
|
|
IFNULL(Fo_VerificationID,0) as xid,
|
|
IFNULL(Fo_VerificationIsOK,'N') as chex,
|
|
IF(ISNULL(Fo_VerificationID),'',Fo_VerificationReason) as note,
|
|
Fo_VerificationTypeLabel as label
|
|
FROM fo_verificationtype
|
|
LEFT JOIN fo_verification ON Fo_VerificationFo_VericationTypeID = Fo_VericationTypeID AND Fo_VerificationT_OrderHeaderID = $orderid
|
|
WHERE
|
|
Fo_VerificationTypeGroup = 'INFO' AND Fo_VerificationTypeIsActive = 'Y'
|
|
GROUP BY Fo_VericationTypeID
|
|
";
|
|
//echo $query;
|
|
$rows = $this->db_onedev->query($query)->result_array();
|
|
foreach($rows as $k => $v){
|
|
if($v['chex'] == 'N')
|
|
$rows[$k]['chex'] = false;
|
|
else
|
|
$rows[$k]['chex'] = true;
|
|
}
|
|
return $rows;
|
|
}
|
|
|
|
function add_verifications_label($orderid){
|
|
$query =" SELECT Fo_VerificationsLabelID as id,
|
|
IFNULL(Fo_VerificationsValueID,0) as xid,
|
|
IFNULL(Fo_VerificationsValueCheck,'N') as chex,
|
|
IF(ISNULL(Fo_VerificationsValueID),'',Fo_VerificationsValueNote) as note,
|
|
Fo_VerificationsLabelName as label
|
|
FROM fo_verificationslabel
|
|
LEFT JOIN fo_verificationsvalue ON Fo_VerificationsValueFo_VerificationsLabelID = Fo_VerificationsLabelID AND Fo_VerificationsValueT_OrderHeaderID = $orderid
|
|
WHERE
|
|
Fo_VerificationsLabelIsActive = 'Y'
|
|
GROUP BY Fo_VerificationsLabelID
|
|
";
|
|
$rows = $this->db_onedev->query($query)->result_array();
|
|
foreach($rows as $k => $v){
|
|
if($v['chex'] == 'N')
|
|
$rows[$k]['chex'] = false;
|
|
else
|
|
$rows[$k]['chex'] = true;
|
|
}
|
|
return $rows;
|
|
}
|
|
|
|
public function search()
|
|
{
|
|
$prm = $this->sys_input;
|
|
//# cek token valid
|
|
if (! $this->isLogin) {
|
|
$this->sys_error("Invalid Token");
|
|
exit;
|
|
}
|
|
$nolab = $prm["nolab"];
|
|
$nama = $prm["nama"];
|
|
$companyID = $prm["companyID"];
|
|
|
|
$sql_where = "";
|
|
$sql_param = array();
|
|
if ($nama != "") {
|
|
if ($sql_where != "") {
|
|
$sql_where .=" and ";
|
|
}
|
|
$sql_where .= " M_PatientName like ? ";
|
|
$sql_param[] = "%$nama%";
|
|
}
|
|
if ($nolab != "") {
|
|
if ($sql_where != "") {
|
|
$sql_where .=" and ";
|
|
}
|
|
$sql_where .= " ( T_OrderHeaderLabNumber like ? or T_OrderHeaderLabNumberExt like ? ) ";
|
|
$sql_param[] = "%$nolab%";
|
|
$sql_param[] = "%$nolab%";
|
|
}
|
|
if ($sql_where != "") $sql_where .= " and ";
|
|
$sql_where .= " T_OrderHeaderIsActive = 'Y' ";
|
|
|
|
if ($companyID > 0 ) {
|
|
if ($sql_where != "") {
|
|
$sql_where .= " and ";
|
|
}
|
|
$sql_where .= " T_OrderHeaderM_CompanyID = $companyID ";
|
|
}
|
|
|
|
$sql = "SELECT
|
|
M_PatientNoReg,
|
|
CONCAT(M_TitleName,' ',M_PatientName) as M_PatientName,
|
|
M_PatientHP,
|
|
T_OrderHeaderLabNumberExt,
|
|
T_OrderHeaderM_PatientAge,
|
|
DATE_FORMAT(M_PatientDOB,'%d-%m-%Y') as M_PatientDOB,
|
|
T_OrderHeaderID as ohid,
|
|
T_OrderHeaderLabNumber,
|
|
T_OrderHeaderDate,
|
|
'' as M_StatusName,
|
|
T_OrderHeaderID, M_SexName,
|
|
M_CompanyName,
|
|
T_OrderHeaderM_CompanyID,
|
|
T_OrderHeaderVerificationNote as verification_note,
|
|
fn_fo_verification_last_status(T_OrderHeaderID,2) as check_status,
|
|
T_OrderHeaderDate as orderdate,
|
|
T_OrderHeaderIsCito as iscito
|
|
FROM t_orderheader
|
|
JOIN m_patient ON T_OrderHeaderM_PatientID = M_PatientID
|
|
JOIN m_title ON M_PatientM_TitleID = M_TitleID
|
|
JOIN m_sex ON M_PatientM_SexID = M_SexID
|
|
JOIN m_company ON T_OrderHeaderM_CompanyID = M_CompanyID
|
|
where $sql_where AND T_OrderHeaderIsCito = 'N'
|
|
GROUP BY T_OrderHeaderID
|
|
HAVING check_status > 0
|
|
ORDER BY iscito DESC, T_OrderHeaderID ASC
|
|
";
|
|
|
|
$query = $this->db_onedev->query($sql, $sql_param);
|
|
$rows = $query->result_array();
|
|
if($rows){
|
|
foreach($rows as $k => $v){
|
|
$rows[$k]['verifications'] = $this->add_verifications_label($v['ohid']);
|
|
}
|
|
}
|
|
|
|
//$rst = array_merge($rows_cito,$rows_not_cito);
|
|
|
|
//$this->_add_address($rows_not_cito);
|
|
$result = array("total" => count($rst), "records" => $rows, "sql"=> $this->db_onedev->last_query());
|
|
$this->sys_ok($result);
|
|
exit;
|
|
}
|
|
|
|
function getcompanies(){
|
|
if (! $this->isLogin) {
|
|
$this->sys_error("Invalid Token");
|
|
exit;
|
|
}
|
|
|
|
$rst_data = array('status'=>'OK');
|
|
$sql = "
|
|
SELECT id,name
|
|
FROM (
|
|
SELECT
|
|
M_CompanyID as id,
|
|
M_CompanyName as name,
|
|
fn_fo_verification_last_status(T_OrderHeaderID,2) as check_status
|
|
FROM t_orderheader
|
|
JOIN m_company ON T_OrderHeaderM_CompanyID = M_CompanyID
|
|
GROUP BY M_CompanyID
|
|
HAVING check_status > 0
|
|
) x
|
|
";
|
|
//echo $sql;
|
|
$rows = $this->db_onedev->query($sql)->result_array();
|
|
|
|
$result = array(
|
|
"total" => 1 ,
|
|
"records" => $rows
|
|
);
|
|
|
|
$this->sys_ok($result);
|
|
exit;
|
|
}
|
|
|
|
public function save()
|
|
{
|
|
try {
|
|
$xprm = $this->sys_input;
|
|
//# cek token valid
|
|
if (! $this->isLogin) {
|
|
$this->sys_error("Invalid Token");
|
|
exit;
|
|
}
|
|
$xuserid = $this->sys_user['M_UserID'];
|
|
//# ambil parameter input
|
|
|
|
//print_r($xprm);
|
|
$prm = $xprm['patient'];
|
|
$xstatus = $xprm['act'];
|
|
$fostatusid = 3;
|
|
$fologcode = 'FO.VERIFICATION.CONFIRM';
|
|
$id = $prm['T_OrderHeaderID'];
|
|
echo $xstatus;
|
|
if($xstatus == 'N'){
|
|
$fostatusid = 4;
|
|
$fologcode = 'FO.VERIFICATION.REJECT';
|
|
}else{
|
|
|
|
$this->save_barcode_new($id);
|
|
}
|
|
|
|
|
|
//print_r($prm);
|
|
$xverificationnote = $prm['verification_note'];
|
|
//echo $xverificationnote;
|
|
|
|
$sql = "update t_orderheader
|
|
set
|
|
T_OrderHeaderVerificationNote = '{$xverificationnote}'
|
|
where
|
|
T_OrderHeaderID = $id";
|
|
//echo $sql;
|
|
$query = $this->db_onedev->query($sql);
|
|
|
|
|
|
/*$xverification_patient = $this->saveverifications($id,$prm['verification_patient'],'PATIENT',$xuserid);
|
|
$xverification_doctor = $this->saveverifications($id,$prm['verification_doctor'],'DOCTOR',$xuserid);
|
|
$xverification_companymou = $this->saveverifications($id,$prm['verification_companymou'],'COMPANY',$xuserid);
|
|
$xverification_payment = $this->saveverifications($id,$prm['verification_payment'],'PAYMENT',$xuserid);
|
|
$xverification_info = $this->saveverifications($id,$prm['verification_info'],'INFO',$xuserid);
|
|
|
|
$xverification_delivery = $this->saveverification_delivery($id,$prm['verification_delivery'],$xuserid);
|
|
$xverification_px = $this->saveverification_px($id,$prm['verification_px'],$xuserid);*/
|
|
|
|
$sql = "insert into fo_status(
|
|
Fo_StatusDate,
|
|
Fo_StatusT_OrderHeaderID,
|
|
Fo_StatusM_StatusID,
|
|
Fo_StatusM_UserID,
|
|
Fo_StatusCreated,
|
|
Fo_StatusUpdated)
|
|
values( now(), ?, ?, ?, now(),now())";
|
|
//echo $sql;
|
|
$query = $this->db_onedev->query($sql,
|
|
array(
|
|
$id,
|
|
$fostatusid,
|
|
$xuserid
|
|
)
|
|
);
|
|
|
|
if (!$query) {
|
|
$this->sys_error_db("fo_status insert");
|
|
exit;
|
|
}
|
|
|
|
|
|
$data_log = array();
|
|
$data_log['orderid'] = $id;
|
|
/*$data_log['verification_patient'] = $prm['verification_patient'];
|
|
$data_log['verification_doctor'] = $prm['verification_doctor'];
|
|
$data_log['verification_companymou'] = $prm['verification_companymou'];
|
|
$data_log['verification_payment'] = $prm['verification_payment'];
|
|
$data_log['verification_info'] = $prm['verification_info'];
|
|
$data_log['verification_px'] = $prm['verification_px'];
|
|
$data_log['verification_delivery'] = $prm['verification_delivery'];*/
|
|
|
|
$json_dt_log = json_encode($data_log);
|
|
$sql = "insert into one_log.log_fo(
|
|
Log_FoDate,
|
|
Log_FoCode,
|
|
Log_FoJson,
|
|
Log_FoUserID)
|
|
values( now(), ?, ?, ?)";
|
|
//echo $sql;
|
|
$query = $this->db_onedev->query($sql,
|
|
array(
|
|
$fologcode,
|
|
$json_dt_log,
|
|
$xuserid
|
|
)
|
|
);
|
|
|
|
if (!$query) {
|
|
$this->sys_error_db("one_log.fo_log insert");
|
|
exit;
|
|
}
|
|
|
|
if($xstatus == 'Y'){
|
|
$msg = 'Verifikasi berhasil dilakukan';
|
|
}
|
|
else{
|
|
$msg = 'Tolak Verifikasi berhasil dilakukan';
|
|
$sql = "INSERT INTO t_ordermessage (
|
|
T_OrderMessageT_OrderHeaderID,
|
|
T_OrderMessageType,
|
|
T_OrderMessageMessage,
|
|
T_OrderMessageFromUserID,
|
|
T_OrderMessageCreated,
|
|
T_OrderMessageLastUpdated
|
|
)
|
|
VALUES(
|
|
{$id},
|
|
'FO.VERIFICATION.REJECT',
|
|
'{$xverificationnote}',
|
|
{$xuserid},
|
|
NOW(),
|
|
NOW()
|
|
)";
|
|
//echo $sql;
|
|
$query = $this->db_onedev->query($sql);
|
|
if (!$query) {
|
|
$this->sys_error_db("one_log.t_ordermessage insert");
|
|
exit;
|
|
}
|
|
}
|
|
|
|
|
|
$rows = array('message'=>$msg);
|
|
$result = array ("total" => 0, "records" => $rows);
|
|
$this->sys_ok($result);
|
|
} catch(Exception $exc) {
|
|
$message = $exc->getMessage();
|
|
$this->sys_error($message);
|
|
}
|
|
|
|
}
|
|
|
|
function save_barcode_new($orderid){
|
|
$xuserid = $this->sys_user['M_UserID'];
|
|
|
|
$query =" SELECT T_SampleTypeID as id,
|
|
T_SampleTypeName as name,
|
|
'' as children
|
|
FROM t_orderheader
|
|
JOIN t_orderdetail ON T_OrderDetailT_OrderHeaderID = T_OrderHeaderID
|
|
JOIN t_test ON T_OrderDetailT_TestID = T_TestID
|
|
JOIN t_sampletype ON T_TestT_SampleTypeID = T_SampleTypeID
|
|
WHERE
|
|
T_OrderHeaderID = {$orderid}
|
|
GROUP BY T_SampleTypeID
|
|
";
|
|
//echo $query ;
|
|
$barcodes = $this->db_onedev->query($query)->result();
|
|
foreach($barcodes as $k => $v){
|
|
$query = "SELECT T_SampleTypeID as id, IFNULL(T_BarcodeLabID,0) as xid,
|
|
IF(ISNULL(T_BarcodeLabID),'Y',T_BarcodeLabIsActive) as chex,
|
|
T_TestName as testname,
|
|
T_SampleTypeName as samplename,
|
|
IF(ISNULL(T_BarcodeLabID),CONCAT(T_OrderHeaderLabNumber,'.',T_SampleTypeID,'.',1),T_BarcodeLabBarcode) as barcodenumber
|
|
FROM t_orderdetail
|
|
JOIN t_orderheader ON T_OrderHeaderID = T_OrderDetailT_OrderHeaderID
|
|
JOIN t_test ON T_OrderDetailT_TestID = T_TestID
|
|
JOIN t_sampletype ON T_TestT_SampleTypeID = T_SampleTypeID
|
|
LEFT JOIN t_barcodelab ON T_BarcodeLabT_OrderHeaderID = T_OrderDetailT_OrderHeaderID AND
|
|
T_BarcodeLabT_SampleTypeID = T_TestT_SampleTypeID AND T_BarcodeLabIsActive = 'Y'
|
|
WHERE
|
|
T_OrderDetailT_OrderHeaderID = {$orderid} AND T_SampleTypeID = {$v->id}
|
|
GROUP BY T_BarcodeLabID ";
|
|
$v->children = $this->db_onedev->query($query)->result_array();
|
|
//$v->children = $barcode_data;
|
|
foreach($v->children as $ki => $vi){
|
|
if($vi['chex'] == 'N')
|
|
$v->children[$ki]['chex'] = false;
|
|
else
|
|
$v->children[$ki]['chex'] = true;
|
|
$sql = "insert into t_barcodelab(
|
|
T_BarcodeLabT_OrderHeaderID,
|
|
T_BarcodeLabBarcode,
|
|
T_BarcodeLabT_SampleTypeID,
|
|
T_BarcodeLabCreated,
|
|
T_BarcodeLabLastUpdated,
|
|
T_BarcodeLabUserID)
|
|
values( ?, ?, ?, now(),now(),?)";
|
|
|
|
$query = $this->db_onedev->query($sql,
|
|
array(
|
|
$orderid,
|
|
$v->children[$ki]['barcodenumber'],
|
|
$v->children[$ki]['id'],
|
|
$xuserid
|
|
)
|
|
);
|
|
// echo $this->db_onedev->last_query();
|
|
if (!$query) {
|
|
$this->sys_error_db("t_barcodelab insert");
|
|
exit;
|
|
}
|
|
}
|
|
|
|
}
|
|
|
|
//insert log
|
|
$supplies = array();
|
|
$query =" SELECT M_SuppliesID as id,
|
|
IFNULL(T_OrderSuppliesID,0) as xid,
|
|
IF(ISNULL(T_OrderSuppliesID),'N',T_OrderSuppliesIsActive) as chex,
|
|
IFNULL(T_OrderSuppliesQty,1) as qty,
|
|
M_SuppliesName as name,
|
|
IF(ISNULL(T_OrderSuppliesID),NOW(),T_OrderSuppliesLastUpdated) as lastupdated,
|
|
IF(ISNULL(T_OrderSuppliesID),NOW(),T_OrderSuppliesLastUpdated) as tx_lastupdated
|
|
FROM m_supplies
|
|
JOIN t_ordersupplies ON T_OrderSuppliesT_OrderHeaderID = $orderid AND T_OrderSuppliesM_SuppliesID = M_SuppliesID
|
|
WHERE
|
|
M_SuppliesIsActive = 'Y'
|
|
";
|
|
//echo $query ;
|
|
$supplies = $this->db_onedev->query($query)->result_array();
|
|
|
|
foreach($supplies as $k => $v){
|
|
if($v['chex'] == 'N')
|
|
$supplies[$k]['chex'] = false;
|
|
else
|
|
$supplies[$k]['chex'] = true;
|
|
}
|
|
|
|
$dt_log = array('orderid'=>$orderid,'supplies'=>$supplies,'barcode'=>$barcodes);
|
|
$fologcode = 'FO.Verification.BarcodeSupplies';
|
|
$json_dt_log = json_encode($dt_log);
|
|
$sql = "insert into one_log.log_supplies_barcode(
|
|
Log_SuppliesBarcodeDate,
|
|
Log_SuppliesBarcodeCode,
|
|
Log_SuppliesBarcodeJson,
|
|
Log_SuppliesBarcodeUserID)
|
|
values( now(), ?, ?, ?)";
|
|
//echo $sql;
|
|
$query = $this->db_onedev->query($sql,
|
|
array(
|
|
$fologcode,
|
|
$json_dt_log,
|
|
$xuserid
|
|
)
|
|
);
|
|
|
|
if (!$query) {
|
|
$this->sys_error_db("one_log.log_supplies_barcode insert");
|
|
exit;
|
|
}
|
|
}
|
|
|
|
function saveverifications($id,$verifications,$type,$userid)
|
|
{
|
|
try {
|
|
//$xverificationtypeid = $this->db_onedev->query("SELECT * FROM fo_verificationtype WHERE Fo_VerificationTypeGroup = '{$type}' AND Fo_VerificationTypeIsActive = 'Y'")->row()->Fo_VericationTypeID;
|
|
//echo $xverificationtypeid;
|
|
//print_r($verifications);
|
|
foreach($verifications as $k => $v){
|
|
//print_r($v);
|
|
if(intval($v['xid']) == 0){
|
|
$sql = "insert into fo_verification(
|
|
Fo_VerificationT_OrderHeaderID,
|
|
Fo_VerificationFo_VericationTypeID,
|
|
Fo_VerificationIsOK,
|
|
Fo_VerificationReason,
|
|
Fo_VerificationCreated,
|
|
Fo_VerificationLastUpdated,
|
|
Fo_VerificationUserID)
|
|
values( ?, ?, ?, ?, now(),now(),?)";
|
|
//echo $sql;
|
|
$query = $this->db_onedev->query($sql,
|
|
array(
|
|
$id,
|
|
$v['id'],
|
|
$v['chex'] == true ?'Y':'N',
|
|
$v['note'],
|
|
$userid
|
|
)
|
|
);
|
|
if (!$query) {
|
|
$this->sys_error_db("fo_verification insert");
|
|
exit;
|
|
}
|
|
}
|
|
}
|
|
return true;
|
|
|
|
} catch(Exception $exc) {
|
|
$message = $exc->getMessage();
|
|
$this->sys_error($message);
|
|
}
|
|
}
|
|
|
|
function saveverification_delivery($id,$deliveries,$userid)
|
|
{
|
|
try {
|
|
foreach($deliveries as $k => $v){
|
|
if($v['id'] === 0){
|
|
$sql = "insert into fo_verification_delivery_add(
|
|
Fo_VerificationDeliveryAddT_OrderHeaderID,
|
|
Fo_VerificationDeliveryAddM_DeliveryID,
|
|
Fo_VerificationDeliveryAddM_DeliveryTypeID,
|
|
Fo_VerificationDeliveryAddDestination,
|
|
Fo_VerificationDeliveryAddAddressID,
|
|
Fo_VerificationDeliveryAddM_KelurahanID,
|
|
Fo_VerificationDeliveryAddOK,
|
|
Fo_VerificationDeliveryAddReason,
|
|
Fo_VerificationDeliveryAddCreated,
|
|
Fo_VerificationDeliveryAddLastUpdated,
|
|
Fo_VerificationDeliveryAddUserID)
|
|
values( ?, ?, ?, ?,?,?,?,?, now(),now(),?)";
|
|
//echo $sql;
|
|
$query = $this->db_onedev->query($sql,
|
|
array(
|
|
$id,
|
|
$v['deliveryid'],
|
|
$v['typedeliveryid'],
|
|
$v['destination'],
|
|
$v['addressid'],
|
|
$v['vilageid'],
|
|
$v['chex'] == true ?'Y':'N',
|
|
$v['note'],
|
|
$userid
|
|
)
|
|
);
|
|
if (!$query) {
|
|
echo $this->db_onedev->last_query();
|
|
$this->sys_error_db("fo_verification_delivery_add insert");
|
|
exit;
|
|
}
|
|
|
|
}else{
|
|
$sql = "insert into fo_verification_delivery(
|
|
Fo_VerificationDeliveryT_OrderHeaderID,
|
|
Fo_VerificationDeliveryT_OrderDeliveryID,
|
|
Fo_VerificationDeliveryIsOK,
|
|
Fo_VerificationDeliveryReason,
|
|
Fo_VerificationDeliveryCreated,
|
|
Fo_VerificationDeliveryLastUpdated,
|
|
Fo_VerificationDeliveryUserID)
|
|
values( ?, ?, ?, ?, now(),now(),?)";
|
|
//echo $sql;
|
|
$query = $this->db_onedev->query($sql,
|
|
array(
|
|
$id,
|
|
$v['id'],
|
|
$v['chex'] == true ?'Y':'N',
|
|
$v['note'],
|
|
$userid
|
|
)
|
|
);
|
|
if (!$query) {
|
|
echo $this->db_onedev->last_query();
|
|
$this->sys_error_db("fo_verification_delivery insert");
|
|
exit;
|
|
}
|
|
//echo $this->db_onedev->last_query();
|
|
}
|
|
}
|
|
return true;
|
|
|
|
} catch(Exception $exc) {
|
|
$message = $exc->getMessage();
|
|
$this->sys_error($message);
|
|
}
|
|
}
|
|
|
|
|
|
function lookup_barcodes()
|
|
{
|
|
try {
|
|
$prm = $this->sys_input;
|
|
//# cek token valid
|
|
if (! $this->isLogin) {
|
|
$this->sys_error("Invalid Token");
|
|
exit;
|
|
}
|
|
$sql = "SELECT T_BarcodeLabID as id, 'barcode' as type,T_SampleTypeID,T_BarcodeLabID,T_BarcodeLabBarcode, T_BarcodeLabT_OrderHeaderID as orderid, T_BarcodeLabCounter, T_SampleTypeName, 'N' as chex
|
|
FROM t_barcodelab
|
|
JOIN t_sampletype ON T_BarcodeLabT_SampleTypeID = T_SampleTypeID
|
|
JOIN t_bahan ON T_SampleTypeT_BahanID = T_BahanID
|
|
JOIN t_samplestation ON T_BahanT_SampleStationID = T_SampleStationID AND T_SampleStationIsNonLab = ''
|
|
WHERE
|
|
T_BarcodeLabT_OrderHeaderID = {$prm['ohid']} AND T_BarcodeLabIsActive = 'Y'
|
|
UNION
|
|
SELECT T_OrderHeaderID as id, 'formulir' as type, 0,0,T_OrderHeaderLabNumber as T_BarcodeLabBarcode,{$prm['ohid']}, 1, 'Formulir' as T_SampleTypeName, 'N' as chex
|
|
FROM t_orderheader
|
|
WHERE
|
|
T_OrderHeaderID = {$prm['ohid']}
|
|
";
|
|
//echo $sql;
|
|
|
|
$rows = $this->db_onedev->query($sql)->result_array();
|
|
if($rows){
|
|
foreach($rows as $k => $v){
|
|
if($v['chex'] == 'N')
|
|
$rows[$k]['chex'] = false;
|
|
else
|
|
$rows[$k]['chex'] = true;
|
|
}
|
|
}
|
|
$result = array ("total" => 0, "records" => $rows);
|
|
$this->sys_ok($result);
|
|
|
|
} catch(Exception $exc) {
|
|
$message = $exc->getMessage();
|
|
$this->sys_error($message);
|
|
}
|
|
}
|
|
|
|
function saveverification_px($id,$pxs,$userid)
|
|
{
|
|
try {
|
|
foreach($pxs as $k => $v){
|
|
|
|
if(intval($v['id']) == 0){
|
|
$cxh = $v['chex'] == true ?'Y':'N';
|
|
$sql = "insert into fo_verification_test_add(
|
|
Fo_VerificationTestAddT_OrderHeaderID,
|
|
Fo_VerificationTestAddT_TestID,
|
|
Fo_VerificationTestAddBruto,
|
|
Fo_VerificationTestAddDiscount,
|
|
Fo_VerificationTestAddTotal,
|
|
Fo_VerificationTestAddIsOK,
|
|
Fo_VerificationTestAddIsCito,
|
|
Fo_VerificationTestAddCreated,
|
|
Fo_VerificationTestAddLastUpdated,
|
|
Fo_VerificationTestAddUserID)
|
|
values( $id, {$v['pxid']}, {$v['bruto']}, {$v['discount']},{$v['total']},'{$cxh}','{$v['flagcito']}',now(),now(),{$userid})";
|
|
//echo $sql;
|
|
$query = $this->db_onedev->query($sql);
|
|
//echo $this->db_onedev->last_query();
|
|
if (!$query) {
|
|
$this->sys_error_db("fo_verification_test_add insert");
|
|
exit;
|
|
}
|
|
}else{
|
|
$sql = "insert into fo_verification_test(
|
|
Fo_VerificationTestT_OrderHeaderID,
|
|
Fo_VerificationTestT_OrderDetailID,
|
|
Fo_VerificationTestIsOK,
|
|
Fo_VerificationTestReason,
|
|
Fo_VerificationTestCreated,
|
|
Fo_VerificationTestLastUpdated,
|
|
Fo_VerificationTestUserID)
|
|
values( ?, ?, ?, ?, now(),now(),?)";
|
|
//echo $sql;
|
|
$query = $this->db_onedev->query($sql,
|
|
array(
|
|
$id,
|
|
$v['id'],
|
|
$v['chex'] == true ?'Y':'N',
|
|
$v['note'],
|
|
$userid
|
|
)
|
|
);
|
|
//echo $this->db_onedev->last_query();
|
|
if (!$query) {
|
|
$this->sys_error_db("fo_verification_test insert");
|
|
exit;
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
return true;
|
|
|
|
} catch(Exception $exc) {
|
|
$message = $exc->getMessage();
|
|
$this->sys_error($message);
|
|
}
|
|
}
|
|
|
|
function verify(){
|
|
if (! $this->isLogin) {
|
|
$this->sys_error("Invalid Token");
|
|
exit;
|
|
}
|
|
$prm = $this->sys_input;
|
|
$userid = $this->sys_user["M_UserID"];
|
|
$xstatus = $prm['act'];
|
|
if($xstatus == 'Y'){
|
|
$query =" INSERT INTO fo_verificationsvalue (
|
|
Fo_VerificationsValueT_OrderHeaderID,
|
|
Fo_VerificationsValueFo_VerificationsLabelID,
|
|
Fo_VerificationsValueCheck,
|
|
Fo_VerificationsValueNote,
|
|
Fo_VerificationsValueUserID,
|
|
Fo_VerificationsValueCreated
|
|
)
|
|
SELECT {$prm['T_OrderHeaderID']},
|
|
Fo_VerificationsLabelID,
|
|
'Y',
|
|
'',
|
|
{$userid},
|
|
NOW()
|
|
FROM fo_verificationslabel
|
|
WHERE
|
|
Fo_VerificationsLabelIsActive = 'Y'
|
|
";
|
|
//echo $query;
|
|
$this->db_onedev->query($query);
|
|
//sipe : inject barcode
|
|
//
|
|
$sql = "call sp_fo_barcode_generate(" . $prm["T_OrderHeaderID"] . ")";
|
|
$this->db_onedev->query($sql);
|
|
}
|
|
else{
|
|
$verifications = $prm['verifications'];
|
|
foreach($verifications as $k => $v){
|
|
$chx = $v['chex'] == true ?'Y':'N';
|
|
$query =" INSERT INTO fo_verificationsvalue (
|
|
Fo_VerificationsValueT_OrderHeaderID,
|
|
Fo_VerificationsValueFo_VerificationsLabelID,
|
|
Fo_VerificationsValueCheck,
|
|
Fo_VerificationsValueNote,
|
|
Fo_VerificationsValueUserID,
|
|
Fo_VerificationsValueCreated
|
|
)
|
|
values( {$prm['T_OrderHeaderID']},
|
|
{$v['id']},
|
|
'{$chx}',
|
|
'{$v['note']}',
|
|
{$userid},
|
|
NOW()
|
|
)
|
|
";
|
|
//echo $query;
|
|
$this->db_onedev->query($query);
|
|
}
|
|
}
|
|
|
|
|
|
|
|
$fostatusid = 3;
|
|
$fologcode = 'FO.VERIFICATION.CONFIRM';
|
|
if($xstatus == 'N'){
|
|
$fostatusid = 4;
|
|
$fologcode = 'FO.VERIFICATION.REJECT';
|
|
}
|
|
|
|
$sql = "insert into fo_status(
|
|
Fo_StatusDate,
|
|
Fo_StatusT_OrderHeaderID,
|
|
Fo_StatusM_StatusID,
|
|
Fo_StatusM_UserID,
|
|
Fo_StatusCreated,
|
|
Fo_StatusUpdated)
|
|
values( now(), ?, ?, ?, now(),now())";
|
|
//echo $sql;
|
|
$query = $this->db_onedev->query($sql,
|
|
array(
|
|
$prm['T_OrderHeaderID'],
|
|
$fostatusid,
|
|
$userid
|
|
)
|
|
);
|
|
//echo $this->db_onedev->last_query();
|
|
|
|
if (!$query) {
|
|
$this->sys_error_db("fo_status insert");
|
|
exit;
|
|
}
|
|
|
|
$sql = "SELECT * FROM fo_verificationsvalue WHERE Fo_VerificationsValueT_OrderHeaderID = {$prm['T_OrderHeaderID']}";
|
|
|
|
$data_log = array();
|
|
$data_log['orderid'] = $prm['T_OrderHeaderID'];
|
|
$data_log['values'] = $this->db_onedev->query($sql)->result_array();
|
|
$data_log['note'] = '';
|
|
|
|
$json_dt_log = json_encode($data_log);
|
|
$sql = "insert into one_log.log_fo(
|
|
Log_FoDate,
|
|
Log_FoCode,
|
|
Log_FoJson,
|
|
Log_FoUserID)
|
|
values( now(), ?, ?, ?)";
|
|
//echo $sql;
|
|
$query = $this->db_onedev->query($sql,
|
|
array(
|
|
$fologcode,
|
|
$json_dt_log,
|
|
$userid
|
|
)
|
|
);
|
|
|
|
if (!$query) {
|
|
$this->sys_error_db("one_log.fo_log insert");
|
|
exit;
|
|
}
|
|
|
|
|
|
$xverificationnote = '';
|
|
if($xstatus == 'Y'){
|
|
$msg = 'Verifikasi berhasil dilakukan';
|
|
//$this->save_barcode_new($prm['T_OrderHeaderID']);
|
|
}
|
|
else{
|
|
$msg = 'Tolak Verifikasi berhasil dilakukan';
|
|
$sql = "INSERT INTO t_ordermessage (
|
|
T_OrderMessageT_OrderHeaderID,
|
|
T_OrderMessageType,
|
|
T_OrderMessageMessage,
|
|
T_OrderMessageFromUserID,
|
|
T_OrderMessageCreated,
|
|
T_OrderMessageLastUpdated
|
|
)
|
|
VALUES(
|
|
{$prm['T_OrderHeaderID']},
|
|
'FO.VERIFICATION.REJECT',
|
|
'{$xverificationnote}',
|
|
{$userid},
|
|
NOW(),
|
|
NOW()
|
|
)";
|
|
//echo $sql;
|
|
$query = $this->db_onedev->query($sql);
|
|
if (!$query) {
|
|
$this->sys_error_db("one_log.t_ordermessage insert");
|
|
exit;
|
|
}
|
|
}
|
|
|
|
//sipe : broadcast
|
|
if ($xstatus == "Y") {
|
|
$this->broadcast("fo-verification-y");
|
|
} else {
|
|
$this->broadcast("fo-verification-x");
|
|
}
|
|
$rows = array('message'=>$msg);
|
|
$result = array ("total" => 0, "records" => $rows);
|
|
$this->sys_ok($result);
|
|
}
|
|
|
|
|
|
function addnewlabel(){
|
|
if (! $this->isLogin) {
|
|
$this->sys_error("Invalid Token");
|
|
exit;
|
|
}
|
|
$rst_data = array('status'=>'OK');
|
|
|
|
$prm = $this->sys_input;
|
|
$userid = $this->sys_user["M_UserID"];
|
|
$counter_barcode = $this->db_onedev->query("SELECT COUNT(*) as xc FROM t_barcodelab WHERE T_BarcodeLabT_OrderHeaderID = {$prm['orderid']} AND T_BarcodeLabT_SampleTypeID = {$prm['T_SampleTypeID']} AND T_BarcodeLabIsActive = 'Y'")->row()->xc;
|
|
$new_counter = intval($counter_barcode)+1;
|
|
$new_label = substr($prm["T_BarcodeLabBarcode"],0,-1).$new_counter ;
|
|
$sql = "INSERT INTO t_barcodelab (
|
|
T_BarcodeLabT_OrderHeaderID ,
|
|
T_BarcodeLabBarcode,
|
|
T_BarcodeLabT_SampleTypeID,
|
|
T_BarcodeLabUserID
|
|
)
|
|
VALUES(
|
|
{$prm['orderid']},
|
|
'{$new_label}',
|
|
{$prm['T_SampleTypeID']},
|
|
{$userid}
|
|
)";
|
|
//echo $sql;
|
|
$this->db_onedev->query($sql);
|
|
|
|
$result = array(
|
|
"total" => 1 ,
|
|
"records" => $rst_data
|
|
);
|
|
$this->sys_ok($result);
|
|
|
|
exit;
|
|
}
|
|
|
|
}
|