2928 lines
103 KiB
PHP
2928 lines
103 KiB
PHP
<?php
|
|
class Resultentry extends MY_Controller
|
|
{
|
|
var $db_onedev;
|
|
public function index()
|
|
{
|
|
echo "Resultentry API";
|
|
}
|
|
|
|
public function __construct()
|
|
{
|
|
parent::__construct();
|
|
$this->db_onedev = $this->load->database("onedev", true);
|
|
$this->load->helper(array('form', 'url'));
|
|
$this->load->library('Nonlabtemplate');
|
|
$this->load->library("Soresultlog");
|
|
$this->load->library("Reporturl");
|
|
$this->load->library("Genkelainan");
|
|
$this->load->library("Generateqrreport");
|
|
}
|
|
|
|
function getdetails($id)
|
|
{
|
|
$rows = [];
|
|
|
|
$sql = "SELECT so_walklettercourierdetail.*, M_SexName,
|
|
CONCAT(M_TitleName,' ',M_PatientName) as patient_fullname,
|
|
T_SampleTypeName as samplename,
|
|
T_OrderHeaderLabNumber as labnumber,
|
|
'Y' as active,
|
|
So_WalkLetterCourierDetailFlagImage as flag_image,
|
|
So_WalkLetterCourierDetailFlagReceiveImage as flag_image_receive,
|
|
So_WalkLetterCourierDetailFlagReceiveResult as flag_result_receive,
|
|
So_WalkLetterCourierDetailID as idx,
|
|
T_OrderHeaderID as orderid,
|
|
T_SampleTypeID as sampleid
|
|
FROM so_walklettercourierdetail
|
|
JOIN t_orderheader ON So_WalkLetterCourierDetailT_OrderHeaderID = T_OrderHeaderID
|
|
JOIN t_sampletype ON So_WalkLetterCourierDetailT_SampleTypeID = T_SampleTypeID
|
|
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
|
|
WHERE
|
|
So_WalkLetterCourierDetailSo_WalkLetterCourierID = {$id} AND So_WalkLetterCourierDetailIsActive = 'Y'";
|
|
//echo $sql;
|
|
$rows = $this->db_onedev->query($sql)->result_array();
|
|
return $rows;
|
|
}
|
|
|
|
function getdeliveries($orderid, $typeresult)
|
|
{
|
|
$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 OR T_OrderDeliveryM_DeliveryID = 10 ) THEN M_DeliveryName
|
|
WHEN T_OrderDeliveryM_DeliveryID = 2 THEN CONCAT(M_DeliveryName)
|
|
WHEN ( T_OrderDeliveryM_DeliveryID = 7 OR T_OrderDeliveryM_DeliveryID = 9 ) THEN M_DeliveryName
|
|
WHEN ( T_OrderDeliveryM_DeliveryID = 6 OR T_OrderDeliveryM_DeliveryID = 8 ) THEN M_DeliveryName
|
|
ELSE
|
|
M_DeliveryName
|
|
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,
|
|
'brown' as color,
|
|
'' as status_payment,
|
|
'' as url
|
|
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
|
|
|
|
";
|
|
//echo $query .'; ';
|
|
$query_result = $this->db_onedev->query($query);
|
|
|
|
// Check if query failed
|
|
if ($query_result === FALSE) {
|
|
error_log("getdeliveries query failed: " . print_r($this->db_onedev->error(), true));
|
|
return array(); // Return empty array instead of crashing
|
|
}
|
|
|
|
$rows = $query_result->result_array();
|
|
//echo $this->db_onedev->last_query();
|
|
$rst = '';
|
|
foreach ($rows as $k => $v) {
|
|
if ($rst != '')
|
|
$rst .= ", ";
|
|
|
|
$rows[$k]['url'] = array();
|
|
$format = ''; // Initialize format variable
|
|
if ($v['typedeliveryid'] == '3' || $v['typedeliveryid'] == '4' || $v['typedeliveryid'] == '5') {
|
|
$sql = "SELECT IF(M_MouIsBill = 'Y','Y',Last_StatusPaymentIsLunas) as xpayment
|
|
FROM last_statuspayment
|
|
join t_orderheader ON Last_StatusPaymentT_OrderHeaderID = T_OrderHeaderID
|
|
JOIN m_mou ON T_OrderHeaderM_MouID = M_MouID
|
|
WHERE
|
|
Last_StatusPaymentT_OrderHeaderID = {$orderid}";
|
|
//echo $sql;
|
|
$query_payment = $this->db_onedev->query($sql);
|
|
|
|
// Check if query failed or no results
|
|
if ($query_payment === FALSE || !$query_payment->row()) {
|
|
error_log("getdeliveries payment query failed or no result");
|
|
$status_payment = 'N'; // Default to N if query fails
|
|
} else {
|
|
$status_payment = $query_payment->row()->xpayment;
|
|
}
|
|
|
|
$rows[$k]['status_payment'] = $status_payment;
|
|
if ($status_payment == 'Y') {
|
|
$xtype = $typeresult;
|
|
if ($typeresult == 'xray' || $typeresult == 'Rontgen')
|
|
$xtype = 'Rontgen';
|
|
if ($typeresult == 'bdm' || $typeresult == 'BMD')
|
|
$xtype = 'BMD';
|
|
|
|
$sql = "SELECT t_email_nonlab.*, T_OrderDetailT_TestName as test_name
|
|
FROM t_email_nonlab
|
|
LEFT JOIN so_resultentry ON T_EmailNonLabSo_ResultEntryID = So_ResultEntryID
|
|
LEFT JOIN t_orderdetail ON So_ResultEntryT_OrderDetailID = T_OrderDetailID
|
|
WHERE
|
|
T_EmailNonLabT_OrderHeaderID = {$orderid} AND T_EmailNonLabType = '{$xtype}'";
|
|
$query_format = $this->db_onedev->query($sql);
|
|
|
|
// Check if query failed
|
|
if ($query_format === FALSE) {
|
|
error_log("getdeliveries email format query failed");
|
|
$row_format = array();
|
|
} else {
|
|
$row_format = $query_format->result_array();
|
|
}
|
|
|
|
if ($row_format && count($row_format) > 0) {
|
|
$format_array = array();
|
|
$url = array();
|
|
foreach ($row_format as $k_f => $v_f) {
|
|
array_push($format_array, $v_f['T_EmailNonLabFormat']);
|
|
$xurl = array('test' => $v_f['test_name'], 'url' => $v_f['T_EmailNonLabUrl']);
|
|
array_push($url, $xurl);
|
|
}
|
|
$join_format = join(",", $format_array);
|
|
$format = $join_format; // Set format for later use
|
|
$rows[$k]['color'] = 'teal lighten-2';
|
|
$rows[$k]['label'] = $v["label"] . " : ( " . $join_format . " )";
|
|
$rows[$k]['url'] = $url;
|
|
} else {
|
|
$rows[$k]['label'] = $v["label"] . " : Belum Pilih Format";
|
|
}
|
|
} else {
|
|
$rows[$k]['color'] = 'orange lighten-2';
|
|
}
|
|
}
|
|
|
|
|
|
$rst .= $v['label'] . $format;
|
|
}
|
|
return $rows;
|
|
}
|
|
|
|
function getphotos($orderid, $sampletypeid)
|
|
{
|
|
$rows = [];
|
|
//print_r($_SERVER);
|
|
$urlbase = 'http://' . $_SERVER['SERVER_NAME'] . "/one-media/one-image-nonlab/";
|
|
$sql = "SELECT So_ImageUploadID as id,
|
|
So_ImageUploadOldName as oldname,
|
|
CONCAT('{$urlbase}',So_ImageUploadNewName) as newname
|
|
FROM so_imageupload
|
|
WHERE
|
|
So_ImageUploadT_OrderHeaderID = {$orderid} AND So_ImageUploadT_SampleTypeID = {$sampletypeid} AND So_ImageUploadIsActive = 'Y'";
|
|
//echo $sql;
|
|
$rows = $this->db_onedev->query($sql)->result_array();
|
|
return $rows;
|
|
}
|
|
|
|
public function search()
|
|
{
|
|
$prm = $this->sys_input;
|
|
if (!$this->isLogin) {
|
|
$this->sys_error("Invalid Token");
|
|
exit;
|
|
}
|
|
$userid = $this->sys_user["M_UserID"];
|
|
$filter_branch = '';
|
|
$sql = "SELECT *
|
|
FROM m_user
|
|
WHERE
|
|
M_UserID = {$userid}";
|
|
$query = $this->db_onedev->query($sql);
|
|
$data_user = $query->row_array();
|
|
if (intval($data_user['M_UserLoginM_BranchID']) > 0) {
|
|
$filter_branch = " AND T_OrderHeaderM_BranchID = {$data_user['M_UserLoginM_BranchID']}";
|
|
}
|
|
|
|
|
|
$search = $prm["search"];
|
|
$status = $prm["stationid"];
|
|
$companyid = $prm['companyid'];
|
|
$filter_company = '';
|
|
$filter_company_exclude = "";
|
|
if (($companyid != 0 || $companyid != '0') && $prm["switch_exclude"])
|
|
$filter_company_exclude = "AND M_CompanyID <> {$companyid}";
|
|
if (($companyid != 0 || $companyid != '0') && !$prm["switch_exclude"]) {
|
|
$filter_company = " AND T_OrderHeaderM_CompanyID = {$companyid}";
|
|
}
|
|
$startdate = $prm["startdate"];
|
|
$enddate = $prm["enddate"];
|
|
$groupid = 3;
|
|
$subgroupid = $prm["subgroupid"];
|
|
$typeresult = isset($prm["typeresult"]) ? $prm["typeresult"] : 'Rontgen';
|
|
$join_group = '';
|
|
if ($groupid != 0) {
|
|
//$join_group = "JOIN nat_group ON T_TestNat_GroupID = Nat_GroupID AND Nat_GroupID = {$groupid}";
|
|
}
|
|
$join_subgroup = '';
|
|
if ($subgroupid != 0) {
|
|
//$join_group = "JOIN nat_subgroup ON T_TestNat_SubgroupID = Nat_SubgroupID AND Nat_SubgroupID = {$subgroupid}";
|
|
}
|
|
|
|
if (!isset($prm['current_page']))
|
|
$prm['current_page'] = 1;
|
|
|
|
|
|
$filter_date = " AND ( DATE(T_SamplingSoDoneDate) = '{$startdate}' OR DATE(T_OrderHeaderDate) = '{$startdate}' )";
|
|
$sql_where = " AND T_OrderDetailIsActive = 'Y'";
|
|
|
|
$number_limit = 10;
|
|
$number_offset = ($prm['current_page'] - 1) * $number_limit;
|
|
//$sql_param = array();
|
|
if ($search != "") {
|
|
//$prev_date = date('Y-m-d', strtotime('-30 day', strtotime($startdate)));
|
|
//echo $prev_date;
|
|
//$filter_date = " AND DATE(T_OrderHeaderDate) BETWEEN '{$prev_date}' AND '{$startdate}'";
|
|
$sql_where = " AND ( T_OrderHeaderLabNumber like '%$search%' OR M_PatientName like '%$search%' ) AND T_OrderDetailIsActive = 'Y'";
|
|
}
|
|
|
|
|
|
$sql = " SELECT count(*) as total
|
|
FROM (
|
|
SELECT So_ResultEntryID, M_CompanyID as company_id
|
|
FROM t_orderdetail
|
|
JOIN t_test ON T_OrderDetailT_TestID = T_TestID
|
|
AND T_TestID IN (SELECT Group_ResultDetailT_TestID
|
|
FROM group_result
|
|
JOIN group_resultdetail
|
|
ON Group_ResultID = Group_ResultDetailGroup_ResultID
|
|
AND Group_ResultIsActive = 'Y'
|
|
AND Group_ResultDetailIsActive = 'Y'
|
|
AND Group_ResultName = '{$typeresult}')
|
|
JOIN t_orderheader ON T_OrderDetailT_OrderHeaderID = T_OrderHeaderID $filter_branch
|
|
JOIN t_samplingso ON T_SamplingSoT_OrderHeaderID = T_OrderHeaderID
|
|
AND T_SamplingSoFlag = 'V' $filter_date
|
|
AND T_SamplingSoT_TestID = T_TestID
|
|
JOIN m_patient ON T_OrderHeaderM_PatientID = M_PatientID $sql_where
|
|
JOIN m_company ON T_OrderHeaderM_CompanyID = M_CompanyID
|
|
$filter_company $filter_company_exclude
|
|
LEFT JOIN m_title ON M_PatientM_TitleID = M_TitleID
|
|
LEFT JOIN so_resultentry ON T_OrderDetailID = So_ResultEntryT_OrderDetailID AND So_ResultEntryIsActive = 'Y'
|
|
LEFT JOIN m_doctor ON So_ResultEntryM_DoctorID = M_DoctorID
|
|
AND M_DoctorIsActive = 'Y'
|
|
$join_group
|
|
$join_subgroup
|
|
GROUP BY T_OrderHeaderID
|
|
) x
|
|
";
|
|
//echo $sql;
|
|
$query = $this->db_onedev->query($sql);
|
|
|
|
$tot_count = 0;
|
|
$tot_page = 0;
|
|
if ($query) {
|
|
$tot_count = $query->result_array()[0]["total"];
|
|
$tot_page = ceil($tot_count / $number_limit);
|
|
} else {
|
|
|
|
$this->sys_error_db("t_samplestorageout count", $this->db_onedev);
|
|
exit;
|
|
}
|
|
$sqlTotal = $this->db_onedev->last_query();
|
|
|
|
|
|
$sql = "SELECT
|
|
IFNULL(So_ResultEntryID,0) as re_id,
|
|
T_OrderHeaderID as trx_id,
|
|
M_PatientID as patientid,
|
|
M_DoctorID doctorID,
|
|
T_SamplingSOID,
|
|
CONCAT(M_DoctorPrefix,' ',M_DoctorPrefix2, ' ', M_DoctorName, ' ',M_DoctorSufix,' ', M_DoctorSufix2, ' ') doctorName,
|
|
T_OrderHeaderLabNumber as ordernumber,
|
|
UPPER(CONCAT(IFNULL(M_TitleName,''),' ',M_PatientName)) as patient_fullname,
|
|
UPPER(M_SexName) as sexname,
|
|
DATE_FORMAT(T_OrderHeaderDate,'%d-%m-%Y') as orderdate,
|
|
DATE_FORMAT(M_PatientDOB,'%d-%m-%Y') as dob,
|
|
UPPER(T_OrderHeaderM_PatientAge) as umur,
|
|
M_CompanyID as company_id,
|
|
UPPER(M_CompanyName) as company_name,
|
|
'' as details,
|
|
CASE
|
|
WHEN So_ResultEntryStatus = 'NEW' THEN 'BARU'
|
|
WHEN So_ResultEntryStatus = 'VAL1' AND T_OrderDetailPrintCount = 0 THEN 'VERIFIKASI'
|
|
WHEN So_ResultEntryStatus = 'VAL2' THEN 'VALIDASI'
|
|
WHEN T_OrderDetailPrintCount <> 0 THEN 'PRINTED'
|
|
END as status_name,
|
|
'' as deliveries,
|
|
IFNULL(T_OrderHeaderFoNote,'') as fo_note,
|
|
fn_getstaffname(T_OrderHeaderFoNoteM_UserID) as fo_note_user,
|
|
'' as fo_ver_note,
|
|
'' as fo_ver_note_user,
|
|
IFNULL(T_OrderHeaderSamplingNote,'') as sampling_note,
|
|
fn_getstaffname(T_OrderHeaderSamplingNoteM_UserID) as sampling_note_user,
|
|
fn_result_so_has_history_nonlab(M_PatientID,T_OrderHeaderID) as has_histories,
|
|
Group_ResultName as group_name
|
|
FROM t_orderdetail
|
|
JOIN t_test ON T_OrderDetailT_TestID = T_TestID
|
|
JOIN group_resultdetail ON Group_ResultDetailT_TestID = T_TestID AND
|
|
Group_ResultDetailIsActive = 'Y'
|
|
JOIN group_result ON Group_ResultDetailGroup_ResultID = Group_ResultID
|
|
AND Group_ResultName = '{$typeresult}'
|
|
JOIN t_orderheader ON T_OrderDetailT_OrderHeaderID = T_OrderHeaderID $filter_branch
|
|
JOIN t_samplingso ON T_SamplingSoT_OrderHeaderID = T_OrderHeaderID
|
|
AND T_SamplingSoFlag = 'V' $filter_date
|
|
AND T_SamplingSoT_TestID = T_TestID
|
|
JOIN m_patient ON T_OrderHeaderM_PatientID = M_PatientID
|
|
$sql_where
|
|
JOIN m_sex ON M_PatientM_SexID = M_SexID
|
|
JOIN m_company ON T_OrderHeaderM_CompanyID = M_CompanyID $filter_company $filter_company_exclude
|
|
LEFT JOIN m_title ON M_PatientM_TitleID = M_TitleID
|
|
LEFT JOIN m_user userfo ON T_OrderHeaderFoNoteM_UserID = userfo.M_UserID
|
|
LEFT JOIN m_user usersampling ON T_OrderHeaderSamplingNoteM_UserID = usersampling.M_UserID
|
|
LEFT JOIN so_resultentry ON T_OrderDetailID = So_ResultEntryT_OrderDetailID AND So_ResultEntryIsActive = 'Y'
|
|
LEFT JOIN m_doctor ON So_ResultEntryM_DoctorID = M_DoctorID
|
|
AND M_DoctorIsActive = 'Y'
|
|
$join_group
|
|
$join_subgroup
|
|
GROUP BY T_OrderHeaderID
|
|
ORDER BY T_OrderHeaderID ASC
|
|
limit $number_limit offset $number_offset
|
|
|
|
";
|
|
///echo $sql;
|
|
$query = $this->db_onedev->query($sql);
|
|
//echo $this->db_onedev->last_query();
|
|
//exit;
|
|
if (!$query) {
|
|
$message = $this->db_onedev->error();
|
|
$message['qry'] = $this->db_onedev->last_query();
|
|
$this->sys_error($message);
|
|
exit;
|
|
}
|
|
$sqlSearch = $this->db_onedev->last_query();
|
|
$rows = $query->result_array();
|
|
//echo $this->db_onedev->last_query();
|
|
|
|
if ($rows) {
|
|
foreach ($rows as $k => $v) {
|
|
$arr_status = array();
|
|
|
|
if (intval($v['re_id']) == 0) {
|
|
|
|
$insert_so = $this->nonlabtemplate->generate($v['T_SamplingSOID']);
|
|
// echo $v['T_SamplingSOID'];
|
|
// print_r($insert_so);
|
|
if ($insert_so) {
|
|
$v['re_id'] = $insert_so['So_ResultEntryID'];
|
|
$rows[$k]['re_id'] = $v['re_id'];
|
|
$v['status_name'] = 'NEW';
|
|
$rows[$k]['status_name'] = $v['status_name'];
|
|
}
|
|
}
|
|
|
|
// Detail tidak di-load di sini untuk meningkatkan performa
|
|
// Detail akan di-load ketika selectMe/select_transaction diklik di frontend
|
|
// Panggil endpoint get_detail dengan parameter trx_id dan typeresult
|
|
$rows[$k]['details'] = array();
|
|
$rows[$k]['deliveries'] = "";
|
|
$rows[$k]['detail_loaded'] = false; // Flag untuk menandai bahwa detail belum di-load
|
|
}
|
|
}
|
|
|
|
|
|
//$this->_add_address($rows);
|
|
$result = array(
|
|
"total" => $tot_page,
|
|
"records" => $rows,
|
|
"sql" => $this->db_onedev->last_query(),
|
|
'sqlTotal' => $sqlTotal,
|
|
'sqlSearch' => $sqlSearch,
|
|
);
|
|
$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'] == '') {
|
|
|
|
$rows = array(array('id' => 0, 'name' => 'Semua'));
|
|
$result = array("total" => 1, "records" => $rows, "total_display" => sizeof($rows));
|
|
$this->sys_ok($result);
|
|
} else {
|
|
$q['search'] = "%{$prm['search']}%";
|
|
// SELECT M_CompanyID as id, M_CompanyName as name
|
|
// FROM m_company
|
|
// WHERE
|
|
// M_CompanyName like ?
|
|
// AND M_CompanyIsActive = 'Y'
|
|
// ORDER BY M_CompanyName DESC
|
|
$sql = "SELECT M_CompanyID AS id, M_CompanyName as name FROM m_company
|
|
WHERE M_CompanyName LIKE ?
|
|
AND M_CompanyIsActive = 'Y'
|
|
ORDER BY M_CompanyName DESC
|
|
";
|
|
$query = $this->db_onedev->query($sql, array($q['search']));
|
|
|
|
if ($query) {
|
|
$rows = $query->result_array();
|
|
array_push($rows, array('id' => 0, 'name' => 'Semua'));
|
|
//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 getlangs($orderid)
|
|
{
|
|
$sql = "
|
|
SELECT M_LangID as id, M_LangCode as code, M_LangName as name, 'N' as chex
|
|
FROM t_orderheader
|
|
JOIN m_lang ON T_OrderHeaderM_LangID = M_LangID
|
|
WHERE
|
|
T_OrderHeaderID = {$orderid}
|
|
UNION
|
|
SELECT M_LangID as id, M_LangCode as code, M_LangName as name, 'N' as chex
|
|
FROM t_orderheader
|
|
JOIN t_orderheaderaddon ON T_OrderHeaderAddOnT_OrderHeaderID = T_OrderHeaderID
|
|
JOIN m_lang ON T_OrderHeaderAddOnSecondM_LangID = M_LangID
|
|
WHERE
|
|
T_OrderHeaderID = {$orderid}
|
|
";
|
|
$rst = $this->db_onedev->query($sql)->result_array();
|
|
return $rst;
|
|
}
|
|
|
|
function getordersamples()
|
|
{
|
|
$prm = $this->sys_input;
|
|
if (!$this->isLogin) {
|
|
$this->sys_error("Invalid Token");
|
|
exit;
|
|
}
|
|
$prm = $this->sys_input;
|
|
$doctorid = $prm['doctorid'];
|
|
$doctoraddressid = $prm['doctoraddressid'];
|
|
$sql = "SELECT
|
|
0 as idx,
|
|
M_SexName,
|
|
CONCAT(M_TitleName,' ',M_PatientName) as patient_fullname,
|
|
T_SampleTypeName as samplename,
|
|
T_OrderHeaderLabNumber as labnumber,
|
|
T_OrderHeaderID as orderid,
|
|
T_SampleTypeID as sampleid,
|
|
'Y' as active,
|
|
'N' as flag_image
|
|
FROM t_samplingso
|
|
JOIN t_orderheader ON T_SamplingSoT_OrderHeaderID = T_OrderHeaderID
|
|
JOIN t_sampletype ON T_SamplingSoT_SampleTypeID = T_SampleTypeID
|
|
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
|
|
WHERE
|
|
T_SamplingSoM_DoctorID = {$doctorid} AND T_SamplingSoM_DoctorAddressID = {$doctoraddressid} AND T_SamplingSoVerifyFlagWL = 'N' AND T_SamplingSoIsActive = 'Y'";
|
|
//echo $sql;
|
|
$rows = $this->db_onedev->query($sql)->result_array();
|
|
$result = array(
|
|
"total" => count($rows),
|
|
"records" => $rows,
|
|
);
|
|
$this->sys_ok($result);
|
|
exit;
|
|
}
|
|
|
|
function getgroups()
|
|
{
|
|
if (!$this->isLogin) {
|
|
$this->sys_error("Invalid Token");
|
|
exit;
|
|
}
|
|
$rows = [];
|
|
$query = " SELECT Nat_GroupID as id, Nat_GroupName as title, CONCAT('GROUP : ',Nat_GroupName) as fulltitle, '' as childrens
|
|
FROM nat_group
|
|
WHERE
|
|
Nat_GroupIsActive = 'Y' AND ( Nat_GroupCode = 2 OR Nat_GroupCode = 3 )
|
|
";
|
|
//echo $query;
|
|
$rows['groups'] = $this->db_onedev->query($query)->result_array();
|
|
if ($rows['groups']) {
|
|
foreach ($rows['groups'] as $k => $v) {
|
|
$childrens = array(array('id' => 0, 'title' => 'Semua', 'fulltitle' => 'Subgroub : Semua'));
|
|
$query = " SELECT Nat_SubGroupID as id, Nat_SubGroupName as title, CONCAT('SUBGROUP : ',Nat_SubGroupName) as fulltitle
|
|
FROM nat_subgroup
|
|
WHERE
|
|
Nat_SubGroupNat_GroupID = {$v['id']} AND Nat_SubGroupIsActive = 'Y'
|
|
";
|
|
//echo $query;
|
|
$xrst = $this->db_onedev->query($query)->result_array();
|
|
if ($xrst) {
|
|
foreach ($xrst as $ki => $vi) {
|
|
array_push($childrens, $vi);
|
|
}
|
|
}
|
|
$rows['groups'][$k]['childrens'] = $childrens;
|
|
}
|
|
}
|
|
$query = " SELECT M_LangID as id, M_LangCode as name
|
|
FROM m_lang
|
|
WHERE
|
|
M_LangIsActive = 'Y'
|
|
";
|
|
//echo $query;
|
|
$rows['langs'] = $this->db_onedev->query($query)->result_array();
|
|
$result = array(
|
|
"total" => count($rows),
|
|
"records" => $rows,
|
|
);
|
|
$this->sys_ok($result);
|
|
exit;
|
|
}
|
|
|
|
function getsubgroups()
|
|
{
|
|
if (!$this->isLogin) {
|
|
$this->sys_error("Invalid Token");
|
|
exit;
|
|
}
|
|
$prm = $this->sys_input;
|
|
$rows = array(array('id' => 0, 'title' => 'Semua', 'fulltitle' => 'Subgroub : Semua'));
|
|
$query = " SELECT Nat_SubGroupID as id, Nat_SubGroupName as title, CONCAT('SUBGROUP : ',Nat_SubGroupName) as fulltitle
|
|
FROM nat_subgroup
|
|
WHERE
|
|
Nat_SubGroupNat_GroupID = {$prm['id']} AND Nat_SubGroupIsActive = 'Y'
|
|
";
|
|
//echo $query;
|
|
$rst = $this->db_onedev->query($query)->result_array();
|
|
if ($rst) {
|
|
foreach ($rst as $k => $v) {
|
|
array_push($rows, $v);
|
|
}
|
|
}
|
|
$result = array(
|
|
"total" => count($rows),
|
|
"records" => $rows,
|
|
);
|
|
$this->sys_ok($result);
|
|
exit;
|
|
}
|
|
|
|
function getstation()
|
|
{
|
|
if (!$this->isLogin) {
|
|
$this->sys_error("Invalid Token");
|
|
exit;
|
|
}
|
|
$rows = [];
|
|
$query = " SELECT T_SampleStationID as id, T_SampleStationName as name
|
|
FROM t_samplestation
|
|
WHERE
|
|
T_SampleStationIsActive = 'Y'
|
|
";
|
|
//echo $query;
|
|
$rows['stations'] = $this->db_onedev->query($query)->result_array();
|
|
//print_r($statuses);
|
|
foreach ($statuses as $k => $v) {
|
|
array_push($rows['statuses'], $v);
|
|
}
|
|
|
|
$result = array(
|
|
"total" => count($rows),
|
|
"records" => $rows,
|
|
);
|
|
$this->sys_ok($result);
|
|
exit;
|
|
}
|
|
|
|
function getdoctoraddress()
|
|
{
|
|
if (!$this->isLogin) {
|
|
$this->sys_error("Invalid Token");
|
|
exit;
|
|
}
|
|
$prm = $this->sys_input;
|
|
$query = " SELECT M_DoctorAddressID as id, M_DoctorAddressDescription as name
|
|
FROM m_doctoraddress
|
|
WHERE
|
|
M_DoctorAddressM_DoctorID = {$prm['id']} AND M_DoctorAddressIsActive = 'Y'
|
|
";
|
|
//echo $query;
|
|
$rows = $this->db_onedev->query($query)->result_array();
|
|
|
|
$result = array(
|
|
"total" => count($rows),
|
|
"records" => $rows,
|
|
);
|
|
$this->sys_ok($result);
|
|
exit;
|
|
}
|
|
|
|
|
|
function saveresult()
|
|
{
|
|
if (!$this->isLogin) {
|
|
$this->sys_error("Invalid Token");
|
|
exit;
|
|
}
|
|
|
|
$errors = [];
|
|
|
|
$prm = $this->sys_input;
|
|
$userid = $this->sys_user["M_UserID"];
|
|
|
|
if ($prm['act'] === 'save') {
|
|
$sql = "SELECT * FROM so_resultentry WHERE So_ResultEntryID = {$prm['trx']['trx_id']}";
|
|
$row_resultentry = $this->db_onedev->query($sql)->row_array();
|
|
|
|
$sql = "SELECT IFNULL(M_DoctorID,0) as M_DoctorID
|
|
FROM m_staff
|
|
JOIN m_user ON M_UserM_StaffID = M_StaffID AND M_UserID = {$userid}
|
|
LEFT JOIN m_doctor ON M_StaffM_DoctorID = M_DoctorID
|
|
WHERE
|
|
M_StaffIsActive = 'Y'
|
|
LIMIT 1";
|
|
$row_doctor_staff = $this->db_onedev->query($sql)->row_array();
|
|
//echo $sql;
|
|
|
|
if (intval($row_doctor_staff['M_DoctorID']) > 0 && intval($row_resultentry['So_ResultEntryM_DoctorID']) == 0) {
|
|
$sql = "UPDATE so_resultentry SET So_ResultEntryM_DoctorID = {$row_doctor_staff['M_DoctorID']}
|
|
WHERE So_ResultEntryID = {$prm['trx']['trx_id']}
|
|
";
|
|
$this->db_onedev->query($sql);
|
|
//echo $sql;
|
|
}
|
|
|
|
$sql = "UPDATE so_resultentry
|
|
SET
|
|
So_ResultEntryIsNormal = 'Z',
|
|
So_ResultEntryUserID = {$userid}
|
|
WHERE
|
|
So_ResultEntryID = {$prm['trx']['trx_id']}";
|
|
$this->db_onedev->query($sql);
|
|
//echo $this->db_onedev->last_query();
|
|
}
|
|
|
|
if ($prm['act'] === 'val1') {
|
|
$sql = "UPDATE so_resultentry
|
|
SET So_ResultEntryValidation1 = 'Y',
|
|
So_ResultEntryStatus = 'VAL1',
|
|
So_ResultEntryLastUpdatedUserID = {$userid} ,
|
|
So_ResultEntryLastUpdated = NOW()
|
|
WHERE
|
|
So_ResultEntryID = {$prm['trx']['trx_id']}";
|
|
$qry = $this->db_onedev->query($sql);
|
|
if (!$qry) {
|
|
$message = $this->db_onedev->error();
|
|
$message['qry'] = $this->db_onedev->last_query();
|
|
$this->sys_error($message);
|
|
exit;
|
|
}
|
|
|
|
|
|
$errors = $this->genkelainan->generate_kelainan_nonlab(0, $prm['trx']['trx_id'], $userid);
|
|
//echo $this->db_onedev->last_query();
|
|
$this->broadcast("result-radiodiagnostic-v1");
|
|
}
|
|
|
|
if ($prm['act'] === 'unval1') {
|
|
$sql = "SELECT IFNULL(Mcu_ResumeValidation, 'N') as status, COUNT(Mcu_ResumeID)
|
|
FROM mcu_resume
|
|
WHERE Mcu_ResumeT_OrderHeaderID = {$prm['trx']['orderid']}
|
|
AND Mcu_ResumeIsActive = 'Y'";
|
|
$qry = $this->db_onedev->query($sql);
|
|
if (!$qry) {
|
|
$message = $this->db_onedev->error();
|
|
$message['qry'] = $this->db_onedev->last_query();
|
|
$this->sys_error("Error cek resume individu");
|
|
exit;
|
|
}
|
|
$cek = $qry->row_array();
|
|
if ($cek['status'] == 'Y') {
|
|
$this->sys_error("Resume individu sudah di validasi, unvalidasi resume individu terlebih dahulu ....");
|
|
exit;
|
|
}
|
|
// print_r($cek);
|
|
$sql = "UPDATE so_resultentry SET
|
|
So_ResultEntryValidation1 = 'N',
|
|
So_ResultEntryStatus = 'NEW',
|
|
So_ResultEntryLastUpdatedUserID = {$userid} ,
|
|
So_ResultEntryLastUpdated = NOW()
|
|
WHERE So_ResultEntryID = {$prm['trx']['trx_id']}";
|
|
$qry = $this->db_onedev->query($sql);
|
|
if (!$qry) {
|
|
$message = $this->db_onedev->error();
|
|
$message['qry'] = $this->db_onedev->last_query();
|
|
$this->sys_error($message);
|
|
exit;
|
|
}
|
|
}
|
|
|
|
if ($prm['act'] === 'val2') {
|
|
$sql = "UPDATE so_resultentry SET
|
|
So_ResultEntryValidation2 = 'Y',
|
|
So_ResultEntryStatus = 'VAL2',
|
|
So_ResultEntryUserID = {$userid}
|
|
WHERE So_ResultEntryID = {$prm['trx']['trx_id']}";
|
|
$this->db_onedev->query($sql);
|
|
$sql = "SELECT t_samplingso.*
|
|
FROM t_samplingso
|
|
JOIN so_resultentry ON So_ResultEntryT_OrderHeaderID = T_SamplingSoT_OrderHeaderID AND So_ResultEntryID = {$prm['trx']['trx_id']}
|
|
JOIN t_orderdetail ON So_ResultEntryT_OrderDetailID = T_OrderDetailID
|
|
JOIN t_test ON T_OrderDetailT_TestID = T_TestID
|
|
JOIN t_sampletype ON T_TestT_SampleTypeID = T_SampleTypeID
|
|
JOIN t_barcodelab ON T_BarcodeLabT_OrderHeaderID = T_OrderDetailT_OrderHeaderID AND T_BarcodeLabT_SampleTypeID = T_SampleTypeID
|
|
WHERE T_SamplingSoIsActive = 'Y'
|
|
GROUP BY T_SamplingSoID";
|
|
$data_sampling = $this->db_onedev->query($sql)->result_array();
|
|
if ($data_sampling) {
|
|
foreach ($data_sampling as $k => $v) {
|
|
$sql = "UPDATE t_samplingso SET T_SamplingSoIsDone = 'Y' WHERE T_SamplingSoID = {$v['T_SamplingSoID']}";
|
|
$this->db_onedev->query($sql);
|
|
}
|
|
}
|
|
}
|
|
|
|
if ($prm['act'] === 'unval2') {
|
|
$sql = "UPDATE so_resultentry SET
|
|
So_ResultEntryValidation2 = 'N',
|
|
So_ResultEntryStatus = 'VAL1',
|
|
So_ResultEntryUserID = {$userid}
|
|
WHERE So_ResultEntryID = {$prm['trx']['trx_id']}";
|
|
$this->db_onedev->query($sql);
|
|
$sql = "SELECT t_samplingso.*
|
|
FROM t_samplingso
|
|
JOIN so_resultentry ON So_ResultEntryT_OrderHeaderID = T_SamplingSoT_OrderHeaderID AND So_ResultEntryID = {$prm['trx']['trx_id']}
|
|
JOIN t_orderdetail ON So_ResultEntryT_OrderDetailID = T_OrderDetailID
|
|
JOIN t_test ON T_OrderDetailT_TestID = T_TestID
|
|
JOIN t_sampletype ON T_TestT_SampleTypeID = T_SampleTypeID
|
|
JOIN t_barcodelab ON T_BarcodeLabT_OrderHeaderID = T_OrderDetailT_OrderHeaderID AND T_BarcodeLabT_SampleTypeID = T_SampleTypeID
|
|
WHERE T_SamplingSoIsActive = 'Y'
|
|
GROUP BY T_SamplingSoID";
|
|
$data_sampling = $this->db_onedev->query($sql)->result_array();
|
|
if ($data_sampling) {
|
|
foreach ($data_sampling as $k => $v) {
|
|
$sql = "UPDATE t_samplingso SET T_SamplingSoIsDone = 'N' WHERE T_SamplingSoID = {$v['T_SamplingSoID']}";
|
|
$this->db_onedev->query($sql);
|
|
}
|
|
}
|
|
}
|
|
|
|
if ($prm['act'] === 'save' || $prm['act'] === 'val1' || $prm['act'] === 'val2') {
|
|
if ($prm['trx']['status_result'] && count($prm['trx']['status_result']) > 0) {
|
|
$sql = "UPDATE so_resultentry_category_result SET
|
|
So_ResultEntryCategoryResultIsActive = 'N',
|
|
So_ResultEntryCategoryResultLastUpdatedUserID = {$userid},
|
|
So_ResultEntryCategoryResultLastUpdated = NOW()
|
|
WHERE
|
|
So_ResultEntryCategoryResultSo_ResultEntryID = {$prm['trx']['trx_id']} AND
|
|
So_ResultEntryCategoryResultIsActive = 'Y'";
|
|
$qry = $this->db_onedev->query($sql);
|
|
if (!$qry) {
|
|
$message = $this->db_onedev->error();
|
|
$message['qry'] = $this->db_onedev->last_query();
|
|
$this->sys_error($message);
|
|
exit;
|
|
}
|
|
|
|
/*$sql = "UPDATE t_kelainan_nonlab SET
|
|
T_KelainanNonLabIsActive = 'N'
|
|
WHERE
|
|
T_KelainanNonLabSo_ResultEntryID = {$prm['trx']['trx_id']} AND
|
|
T_KelainanNonLabIsActive = 'Y'";
|
|
$qry = $this->db_onedev->query($sql);
|
|
if (!$qry) {
|
|
$message = $this->db_onedev->error();
|
|
$message['qry'] = $this->db_onedev->last_query();
|
|
$this->sys_error($message);
|
|
exit;
|
|
}*/
|
|
foreach ($prm['trx']['status_result'] as $key_data => $value_data) {
|
|
$sql = "INSERT INTO so_resultentry_category_result (
|
|
So_ResultEntryCategoryResultSo_ResultEntryID,
|
|
So_ResultEntryCategoryNonlabConclusionDetailID,
|
|
So_ResultEntryCategoryResultCreated,
|
|
So_ResultEntryCategoryResultCreatedUserID
|
|
)
|
|
VALUES(
|
|
{$prm['trx']['trx_id']},
|
|
'{$value_data['id']}',
|
|
NOW(),
|
|
{$userid}
|
|
)";
|
|
$qry = $this->db_onedev->query($sql);
|
|
if (!$qry) {
|
|
$message = $this->db_onedev->error();
|
|
$message['qry'] = $this->db_onedev->last_query();
|
|
$this->sys_error($message);
|
|
exit;
|
|
}
|
|
if ($value_data['isNormal'] == 'N') {
|
|
$sql = "SELECT * FROM mcu_summarynonlab
|
|
WHERE Mcu_SummaryNonlabConclusionDetailIDs = {$value_data['id']}
|
|
AND Mcu_SummaryNonlabIsActive = 'Y'";
|
|
$qry = $this->db_onedev->query($sql);
|
|
// print_r($qry);
|
|
|
|
if (!$qry) {
|
|
$message = $this->db_onedev->error();
|
|
$message['qry'] = $this->db_onedev->last_query();
|
|
$this->sys_error($message);
|
|
exit;
|
|
}
|
|
$summary = $qry->result_array();
|
|
// echo $summary;
|
|
|
|
/*for ($k = 0; $k < count($summary); $k++) {
|
|
$sql = "SELECT COUNT(T_KelainanNonLabID) as total
|
|
FROM t_kelainan_nonlab
|
|
WHERE {$summary[$k]['Mcu_SummaryNonlabID']} IN (T_KelainanNonLabMcu_SummaryNonlabID)
|
|
AND T_KelainanNonLabT_OrderHeaderID = {$prm['trx']['orderid']}
|
|
AND T_KelainanNonLabIsActive = 'Y' ";
|
|
$qry = $this->db_onedev->query($sql);
|
|
if (!$qry) {
|
|
$message = $this->db_onedev->error();
|
|
$message['qry'] = $this->db_onedev->last_query();
|
|
$this->sys_error($message);
|
|
exit;
|
|
}
|
|
$count = $qry->result_array()[0]['total'];
|
|
if (intval($count) == 0) {
|
|
$sql = "INSERT INTO t_kelainan_nonlab (
|
|
T_KelainanNonLabSo_ResultEntryID,
|
|
T_KelainanNonLabT_OrderHeaderID,
|
|
T_KelainanNonLabNat_TestID,
|
|
T_KelainanNonLabMcu_SummaryNonlabID,
|
|
T_KelainanNonLabCreatedUserID,
|
|
T_KelainanLabNonCreated
|
|
)
|
|
VALUES(
|
|
{$prm['trx']['trx_id']},
|
|
{$prm['trx']['orderid']},
|
|
{$prm['trx']['nat_testid']},
|
|
{$summary[$k]['Mcu_SummaryNonlabID']},
|
|
{$userid},
|
|
NOW()
|
|
)
|
|
";
|
|
$qry = $this->db_onedev->query($sql);
|
|
if (!$qry) {
|
|
$message = $this->db_onedev->error();
|
|
$message['qry'] = $this->db_onedev->last_query();
|
|
$this->sys_error($message);
|
|
exit;
|
|
}
|
|
}
|
|
}*/
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
|
|
// $sql = "SELECT * FROM so_resultentry WHERE So_ResultEntryID = '{$prm['trx']['trx_id']}'";
|
|
// //echo $sql;
|
|
// $re_langid = $this->db_onedev->query($sql)->row()->So_ResultEntryM_LangID;
|
|
// if ($re_langid == $prm['trx']['language_id']) {
|
|
//echo 1;
|
|
foreach ($prm['trx']['details'] as $k => $v) {
|
|
$results = str_replace("'", "\\'", $v['result_value']);
|
|
$sql = "UPDATE so_resultentrydetail SET
|
|
So_ResultEntryDetailResult = '{$results}',
|
|
So_ResultEntryDetailLastUpdatedUserID = {$userid},
|
|
So_ResultEntryDetailLastUpdated = NOW()
|
|
WHERE So_ResultEntryDetailID = {$v['trx_id']}";
|
|
$qry = $this->db_onedev->query($sql);
|
|
if (!$qry) {
|
|
$message = $this->db_onedev->error();
|
|
$message['qry'] = $this->db_onedev->last_query();
|
|
$this->sys_error($message);
|
|
exit;
|
|
}
|
|
|
|
//echo $this->db_onedev->last_query();
|
|
}
|
|
|
|
|
|
|
|
|
|
$last_id = $prm['trx']['trx_id'];
|
|
//$order_id = $prm['trx']['orderid'];
|
|
$sql = "SELECT * FROM so_resultentry WHERE So_ResultEntryID = {$last_id}";
|
|
$data_log_header = $this->db_onedev->query($sql)->row_array();
|
|
$sql = "SELECT * FROM so_resultentrydetail WHERE So_ResultEntryDetailSo_ResultEntryID = {$last_id}";
|
|
$data_log_details = $this->db_onedev->query($sql)->result_array();
|
|
|
|
$status_verif = 'N';
|
|
$act = "UPDATE_ACT";
|
|
if ($prm['act'] == 'val1') {
|
|
$status_verif = 'Y';
|
|
$act = "VALIDATION";
|
|
$sql = "SELECT so_resultentrydetail.*, IF(NonlabTemplateMcuID IS NULL,'N','Y') as is_kesimpulan, T_TestID, T_TestName, So_ResultEntryT_OrderHeaderID, Group_ResultID
|
|
FROM so_resultentrydetail
|
|
JOIN so_resultentry ON So_ResultEntryDetailSo_ResultEntryID = So_ResultEntryID AND So_ResultEntryIsActive = 'Y'
|
|
JOIN t_orderdetail ON So_ResultEntryT_OrderDetailID = T_OrderDetailID AND T_OrderDetailIsActive = 'Y'
|
|
JOIN t_test ON T_OrderDetailT_TestID = T_TestID AND T_TestIsActive = 'Y'
|
|
JOIN group_resultdetail ON Group_ResultDetailT_TestID = T_TestID AND Group_ResultDetailIsActive = 'Y'
|
|
JOIN group_result ON Group_ResultDetailGroup_ResultID = Group_ResultID AND Group_ResultIsActive = 'Y'
|
|
LEFT JOIN nonlab_template_mcu ON NonlabTemplateMcuNat_TestID = T_TestNat_TestID AND NonlabTemplateMcuIsActive = 'Y' AND
|
|
NonlabTemplateMcuNonlabTemplateDetailID = So_ResultEntryDetailNonlab_TemplateDetailID
|
|
WHERE
|
|
So_ResultEntryDetailSo_ResultEntryID = {$last_id} AND
|
|
So_ResultEntryDetailIsActive = 'Y'";
|
|
$qry = $this->db_onedev->query($sql);
|
|
$data_result_details = $qry->result_array();
|
|
if (count($data_result_details) > 0) {
|
|
$group_result_id = $data_result_details[0]['Group_ResultID'];
|
|
$test_id = $data_result_details[0]['T_TestID'];
|
|
$test_name = $data_result_details[0]['T_TestName'];
|
|
$order_id = $data_result_details[0]['So_ResultEntryT_OrderHeaderID'];
|
|
$data_result_details = json_encode($data_result_details);
|
|
$sql = "UPDATE mcu_resume_results SET Mcu_ResumeResultsIsActive = 'N'
|
|
WHERE Mcu_ResumeResultsT_OrderHeaderID = ? AND
|
|
Mcu_ResumeResultsGroupResultID = ? AND
|
|
Mcu_ResumeResultsT_TestID = ? AND
|
|
Mcu_ResumeResultsIsActive = 'Y'";
|
|
|
|
$qry = $this->db_onedev->query($sql, array($order_id, $group_result_id, $test_id));
|
|
//echo $this->db_onedev->last_query();
|
|
if (!$qry) {
|
|
//echo $this->db_onedev->last_query();
|
|
echo json_encode(
|
|
array("status" => "ERR", "message" => "Error: " . $this->db_onedev->error())
|
|
);
|
|
exit;
|
|
}
|
|
$sql = "INSERT INTO mcu_resume_results(
|
|
Mcu_ResumeResultsType,
|
|
Mcu_ResumeResultsT_OrderHeaderID,
|
|
Mcu_ResumeResultsGroupResultID,
|
|
Mcu_ResumeResultsT_TestID,
|
|
Mcu_ResumeResultsName,
|
|
Mcu_ResumeResultsJSON,
|
|
Mcu_ResumeResultsCreated,
|
|
Mcu_ResumeResultsUserID)
|
|
VALUES('KHUSUS',?,?,?,?,?,NOW(),?)";
|
|
$qry = $this->db_onedev->query($sql, array($order_id, $group_result_id, $test_id, $test_name, $data_result_details, $userid));
|
|
if (!$qry) {
|
|
//echo $this->db_onedev->last_query();
|
|
echo json_encode(
|
|
array("status" => "ERR", "message" => "Error: " . $this->db_onedev->error())
|
|
);
|
|
exit;
|
|
}
|
|
}
|
|
}
|
|
|
|
if ($prm['act'] == 'unval1')
|
|
$act = "UNVALIDATION";
|
|
|
|
$this->soresultlog->step_action($act, $last_id, $userid);
|
|
|
|
if ($prm['act'] == 'val1' || $prm['act'] == 'unval1') {
|
|
|
|
$verdate = 'NULL';
|
|
if ($status_verif == 'Y')
|
|
$verdate = 'NOW()';
|
|
$veruser = $status_verif == 'Y' ? $userid : 0;
|
|
$sql = "SELECT So_ResultEntryT_OrderDetailID
|
|
FROM so_resultentry
|
|
WHERE
|
|
So_ResultEntryID = {$last_id} LIMIT 1";
|
|
$qry = $this->db_onedev->query($sql);
|
|
$data_result_entry = $qry->result_array();
|
|
$orderdetail_id = $data_result_entry[0]['So_ResultEntryT_OrderDetailID'];
|
|
$sql = "UPDATE t_orderdetail SET T_OrderDetailVerification = '{$status_verif}',
|
|
T_OrderDetailVerDate = '{$verdate}',
|
|
T_OrderDetailVerUserID = {$veruser}
|
|
WHERE T_OrderDetailID = {$orderdetail_id}";
|
|
$qry = $this->db_onedev->query($sql);
|
|
if (!$qry) {
|
|
$message = $this->db_onedev->error();
|
|
$message['qry'] = $this->db_onedev->last_query();
|
|
$this->sys_error($message);
|
|
exit;
|
|
}
|
|
|
|
$sql = "SELECT T_OrderHeaderGroupResultGroup_ResultID,
|
|
T_OrderHeaderGroupResultDetailsT_OrderHeaderID
|
|
FROM t_orderheader_group_result_details
|
|
JOIN t_orderheader_group_result ON T_OrderHeaderGroupResultID =
|
|
T_OrderHeaderGroupResultDetailsT_OrderHeaderGroupResultID AND
|
|
T_OrderHeaderGroupResultDetailsIsActive = 'Y'
|
|
WHERE
|
|
T_OrderHeaderGroupResultDetailsT_OrderDetailID = ? AND
|
|
T_OrderHeaderGroupResultDetailsIsActive = 'Y' LIMIT 1";
|
|
$query = $this->db_onedev->query($sql, [$orderdetail_id]);
|
|
if (!$query) {
|
|
$this->sys_error_db("single verification select group result", $this->db_onedev);
|
|
exit();
|
|
}
|
|
|
|
$row_dt_group = $query->result_array();
|
|
//echo $this->db_onedev->last_query();
|
|
if (count($row_dt_group) > 0) {
|
|
$ohid = $row_dt_group[0]["T_OrderHeaderGroupResultDetailsT_OrderHeaderID"];
|
|
$gid = $row_dt_group[0]["T_OrderHeaderGroupResultGroup_ResultID"];
|
|
$this->verification_by_group($ohid, $gid);
|
|
} else {
|
|
$this->sys_error_db("group result tidak ditemukan", $this->db_onedev);
|
|
exit();
|
|
}
|
|
}
|
|
|
|
|
|
|
|
$data_log = json_encode(array('header' => $data_log_header, 'details' => $data_log_details));
|
|
$this->soresultlog->log_result($data_log, $last_id, $userid);
|
|
|
|
// generate QR untuk test non lab (ECG, Spirometri, Audiometri)
|
|
if ($prm['act'] == 'val1') {
|
|
// ambil data
|
|
$sql_get = "SELECT DISTINCT
|
|
T_OrderHeaderGroupResultID,
|
|
T_OrderHeaderGroupResultGroup_ResultID,
|
|
T_OrderHeaderGroupResultT_TestID,
|
|
T_OrderHeaderGroupResultGroup_ResultName,
|
|
T_TestName,
|
|
Group_ResultName
|
|
FROM t_orderheader_group_result
|
|
JOIN t_test
|
|
ON T_OrderHeaderGroupResultT_TestID = T_TestID
|
|
AND T_TestIsActive = 'Y'
|
|
JOIN group_resultdetail ON Group_ResultDetailT_TestID = T_TestID AND
|
|
Group_ResultDetailIsActive = 'Y'
|
|
JOIN group_result ON Group_ResultDetailGroup_ResultID = Group_ResultID
|
|
WHERE T_OrderHeaderGroupResultT_TestID = ?
|
|
AND T_OrderHeaderGroupResultT_OrderHeaderID = ?
|
|
AND T_OrderHeaderGroupResultIsActive = 'Y'";
|
|
|
|
$qry_get = $this->db_onedev->query($sql_get, [
|
|
$prm['trx']['test_id'],
|
|
$prm['trx']['orderid']
|
|
]);
|
|
if (!$qry_get) {
|
|
$this->sys_error_db("error t_orderheader_group_result", $this->db_onedev);
|
|
exit;
|
|
}
|
|
|
|
$data = $qry_get->result_array();
|
|
|
|
// mapping test kode print
|
|
$map = [
|
|
'Rontgen' => 'RONTGEN-RESULT-P-01',
|
|
'USG' => 'USG-RESULT-P-01',
|
|
'BMD' => 'BMD-RESULT-P-01',
|
|
'MRI' => 'MRI-RESULT-P-01'
|
|
];
|
|
|
|
$sql_branch = "SELECT M_BranchID,
|
|
M_BranchCode,
|
|
M_BranchName,
|
|
M_BranchIPAddress
|
|
FROM m_branch
|
|
WHERE M_BranchIsDefault = 'Y'
|
|
AND M_BranchIsActive = 'Y'";
|
|
$qry_branch = $this->db_onedev->query($sql_branch);
|
|
if (!$qry_branch) {
|
|
$this->sys_error_db('error m_branch', $this->db_onedev);
|
|
exit;
|
|
}
|
|
$branch = $qry_branch->row_array();
|
|
$base = "http://" . $branch['M_BranchIPAddress'] . "/";
|
|
|
|
// ambil endpoint URL dari DB
|
|
$sql_url = "SELECT QR_ReportEndpointID,
|
|
QR_ReportEndpointUrl,
|
|
QR_ReportEndpointIsActive
|
|
FROM qr_report_endpoint
|
|
WHERE QR_ReportEndpointIsActive = 'Y' LIMIT 1";
|
|
$qry_url = $this->db_onedev->query($sql_url);
|
|
$endpoint_url = "";
|
|
if ($qry_url) {
|
|
$data_url = $qry_url->result_array();
|
|
if (count($data_url) > 0) {
|
|
$endpoint_url = $data_url[0]['QR_ReportEndpointUrl'];
|
|
}
|
|
} else {
|
|
$this->db_onedev->trans_rollback();
|
|
$this->sys_error_db("Error Query Endpoint URL", $this->db_onedev);
|
|
exit;
|
|
}
|
|
|
|
$verify_url = $endpoint_url . 'rpt';
|
|
|
|
foreach ($data as $value) {
|
|
|
|
$group_result_name = $value['Group_ResultName'];
|
|
|
|
// kalau tidak ada di mapping skip
|
|
if (!isset($map[$group_result_name])) {
|
|
continue;
|
|
}
|
|
|
|
$printCode = $map[$group_result_name];
|
|
|
|
// ambil URL print
|
|
$sql_url = "SELECT Print_TransactionUrlWatermark, Print_TransactionUrlEletronic
|
|
FROM print_transaction
|
|
WHERE Print_TransactionCode = ?
|
|
LIMIT 1";
|
|
$qry_url = $this->db_onedev->query($sql_url, [$printCode]);
|
|
if (!$qry_url) {
|
|
$this->sys_error_db('error print_transaction', $this->db_onedev);
|
|
exit;
|
|
}
|
|
|
|
$rst_url = $qry_url->row_array();
|
|
$template_url = $rst_url['Print_TransactionUrlWatermark'];
|
|
$template_url_electronic = isset($rst_url['Print_TransactionUrlEletronic']) ? $rst_url['Print_TransactionUrlEletronic'] : '';
|
|
// Tambah base_url di depan
|
|
$full_url = $base . ltrim($template_url, '/');
|
|
|
|
// ubah semua report jadi versi watermark
|
|
$full_url = str_replace(
|
|
'.rptdesign',
|
|
'_watermark.rptdesign',
|
|
$full_url
|
|
);
|
|
|
|
// Ganti parameter
|
|
$full_url = str_replace(
|
|
['PUsername', 'PT_OrderHeaderID', 'TS'],
|
|
[
|
|
trim($this->sys_user['M_UserUsername']),
|
|
$prm['trx']['trx_id'],
|
|
time()
|
|
],
|
|
$full_url
|
|
);
|
|
$full_url_electronic = '';
|
|
if ($template_url_electronic !== '') {
|
|
$full_url_electronic = $base . ltrim($template_url_electronic, '/');
|
|
$full_url_electronic = str_replace(
|
|
['PUsername', 'PT_OrderHeaderID', 'TS'],
|
|
[
|
|
trim($this->sys_user['M_UserUsername']),
|
|
$prm['trx']['trx_id'],
|
|
time()
|
|
],
|
|
$full_url_electronic
|
|
);
|
|
}
|
|
|
|
// cek sudah pernah generate belum
|
|
$sql_check = "SELECT QR_PrintOutID
|
|
FROM qr_printout
|
|
WHERE QR_PrintOutT_OrderHeaderID = ?
|
|
AND QR_PrintOutGroup_ResultID = ?
|
|
AND QR_PrintOutT_TestID = ?
|
|
AND QR_PrintOutIsActive = 1
|
|
LIMIT 1";
|
|
|
|
$qry_check = $this->db_onedev->query($sql_check, [
|
|
$prm['trx']['orderid'],
|
|
$value['T_OrderHeaderGroupResultGroup_ResultID'],
|
|
$value['T_OrderHeaderGroupResultT_TestID']
|
|
]);
|
|
|
|
$exist = $qry_check->row_array();
|
|
|
|
// kalau belum pernah insert
|
|
if (empty($exist)) {
|
|
// generate QR
|
|
$params = [
|
|
'orderHeaderID' => $prm['trx']['orderid'],
|
|
'groupResultID' => $value['T_OrderHeaderGroupResultGroup_ResultID'],
|
|
'testID' => $value['T_OrderHeaderGroupResultT_TestID'],
|
|
'groupResultName' => $value['T_OrderHeaderGroupResultGroup_ResultName'],
|
|
'verifyBaseURL' => $verify_url,
|
|
'QR_PrintOutReportURL' => $full_url,
|
|
'QR_PrintOutReportURLElectronic' => $full_url_electronic,
|
|
'createdByUserID' => $userid
|
|
];
|
|
|
|
$this->generateqrreport->saveQRPrintout($params);
|
|
}
|
|
}
|
|
}
|
|
|
|
$result = array(
|
|
"total" => 1,
|
|
"records" => array('status' => 'OK', 'errors' => $errors)
|
|
);
|
|
$this->sys_ok($result);
|
|
exit;
|
|
}
|
|
|
|
|
|
function validation_by_group($order_id, $group_id)
|
|
{
|
|
$sql = "SELECT COUNT(*) as total_all
|
|
FROM t_orderdetail
|
|
JOIN t_orderheader_group_result_details ON
|
|
T_OrderHeaderGroupResultDetailsT_OrderHeaderID = T_OrderDetailT_OrderHeaderID AND
|
|
T_OrderHeaderGroupResultDetailsIsActive = 'Y' AND
|
|
T_OrderHeaderGroupResultDetailsT_OrderDetailID = T_OrderDetailID
|
|
JOIN t_orderheader_group_result ON
|
|
T_OrderHeaderGroupResultDetailsT_OrderHeaderGroupResultID =
|
|
T_OrderHeaderGroupResultID AND
|
|
T_OrderHeaderGroupResultT_OrderHeaderID = T_OrderHeaderGroupResultDetailsT_OrderHeaderID AND
|
|
T_OrderHeaderGroupResultIsActive = 'Y' AND
|
|
T_OrderHeaderGroupResultGroup_ResultID = ?
|
|
WHERE T_OrderDetailT_OrderHeaderID = ? AND
|
|
T_OrderDetailIsActive = 'Y'";
|
|
$qry = $this->db_onedev->query($sql, [$group_id, $order_id]);
|
|
if (!$qry) {
|
|
$this->sys_error_db("worklist count", $this->db_onedev);
|
|
exit();
|
|
}
|
|
//echo $this->db_onedev->last_query() . ';';
|
|
$total_all = $qry->result_array()[0]["total_all"];
|
|
|
|
$sql = "SELECT COUNT(*) as total_validated
|
|
FROM t_orderdetail
|
|
JOIN t_orderheader_group_result_details ON
|
|
T_OrderHeaderGroupResultDetailsT_OrderHeaderID = T_OrderDetailT_OrderHeaderID AND
|
|
T_OrderHeaderGroupResultDetailsIsActive = 'Y' AND
|
|
T_OrderHeaderGroupResultDetailsT_OrderDetailID = T_OrderDetailID
|
|
JOIN t_orderheader_group_result ON
|
|
T_OrderHeaderGroupResultDetailsT_OrderHeaderGroupResultID =
|
|
T_OrderHeaderGroupResultID AND
|
|
T_OrderHeaderGroupResultT_OrderHeaderID = T_OrderHeaderGroupResultDetailsT_OrderHeaderID AND
|
|
T_OrderHeaderGroupResultIsActive = 'Y' AND
|
|
T_OrderHeaderGroupResultGroup_ResultID = ?
|
|
WHERE T_OrderDetailT_OrderHeaderID = ? AND
|
|
T_OrderDetailIsActive = 'Y' AND T_OrderDetailValidation = 'Y'";
|
|
$qry = $this->db_onedev->query($sql, [$group_id, $order_id]);
|
|
if (!$qry) {
|
|
$this->sys_error_db("worklist count", $this->db_onedev);
|
|
exit();
|
|
}
|
|
//echo $this->db_onedev->last_query() . ';';
|
|
$total_validated = $qry->result_array()[0]["total_validated"];
|
|
|
|
$status = "N";
|
|
if ($total_validated > 0 && $total_validated < $total_all) {
|
|
$status = "P";
|
|
} else if ($total_validated > 0 && $total_validated == $total_all) {
|
|
$status = "Y";
|
|
}
|
|
|
|
|
|
//echo $total_all;
|
|
//echo $total_verified;
|
|
//echo $status;
|
|
$sql = "UPDATE t_orderheader_group_result SET
|
|
T_OrderHeaderValidation = ?
|
|
WHERE
|
|
T_OrderHeaderGroupResultT_OrderHeaderID = ? AND
|
|
T_OrderHeaderGroupResultGroup_ResultID = ?";
|
|
$query = $this->db_onedev->query($sql, [$status, $order_id, $group_id]);
|
|
if (!$query) {
|
|
$this->sys_error_db("worklist count", $this->db_onedev);
|
|
exit();
|
|
}
|
|
//echo $this->db_onedev->last_query();
|
|
|
|
return true;
|
|
}
|
|
|
|
function verification_by_group($order_id, $group_id)
|
|
{
|
|
$sql = "SELECT COUNT(*) as total_all
|
|
FROM t_orderdetail
|
|
JOIN t_orderheader_group_result_details ON
|
|
T_OrderHeaderGroupResultDetailsT_OrderHeaderID = T_OrderDetailT_OrderHeaderID AND
|
|
T_OrderHeaderGroupResultDetailsIsActive = 'Y' AND
|
|
T_OrderHeaderGroupResultDetailsT_OrderDetailID = T_OrderDetailID
|
|
JOIN t_orderheader_group_result ON
|
|
T_OrderHeaderGroupResultDetailsT_OrderHeaderGroupResultID =
|
|
T_OrderHeaderGroupResultID AND
|
|
T_OrderHeaderGroupResultT_OrderHeaderID = T_OrderHeaderGroupResultDetailsT_OrderHeaderID AND
|
|
T_OrderHeaderGroupResultIsActive = 'Y' AND
|
|
T_OrderHeaderGroupResultGroup_ResultID = ?
|
|
WHERE T_OrderDetailT_OrderHeaderID = ? AND
|
|
T_OrderDetailIsActive = 'Y'";
|
|
$qry = $this->db_onedev->query($sql, [$group_id, $order_id]);
|
|
if (!$qry) {
|
|
$this->sys_error_db("worklist count", $this->db_onedev);
|
|
exit();
|
|
}
|
|
//echo $this->db_onedev->last_query() . ';';
|
|
$total_all = $qry->result_array()[0]["total_all"];
|
|
|
|
$sql = "SELECT COUNT(*) as total_verified
|
|
FROM t_orderdetail
|
|
JOIN t_orderheader_group_result_details ON
|
|
T_OrderHeaderGroupResultDetailsT_OrderHeaderID = T_OrderDetailT_OrderHeaderID AND
|
|
T_OrderHeaderGroupResultDetailsIsActive = 'Y' AND
|
|
T_OrderHeaderGroupResultDetailsT_OrderDetailID = T_OrderDetailID
|
|
JOIN t_orderheader_group_result ON
|
|
T_OrderHeaderGroupResultDetailsT_OrderHeaderGroupResultID =
|
|
T_OrderHeaderGroupResultID AND
|
|
T_OrderHeaderGroupResultT_OrderHeaderID = T_OrderHeaderGroupResultDetailsT_OrderHeaderID AND
|
|
T_OrderHeaderGroupResultIsActive = 'Y' AND
|
|
T_OrderHeaderGroupResultGroup_ResultID = ?
|
|
WHERE T_OrderDetailT_OrderHeaderID = ? AND
|
|
T_OrderDetailIsActive = 'Y' AND T_OrderDetailVerification = 'Y'";
|
|
$qry = $this->db_onedev->query($sql, [$group_id, $order_id]);
|
|
if (!$qry) {
|
|
$this->sys_error_db("worklist count", $this->db_onedev);
|
|
exit();
|
|
}
|
|
//echo $this->db_onedev->last_query() . ';';
|
|
$total_verified = $qry->result_array()[0]["total_verified"];
|
|
|
|
$status = "N";
|
|
if ($total_verified > 0 && $total_verified < $total_all) {
|
|
$status = "P";
|
|
} else if ($total_verified > 0 && $total_verified == $total_all) {
|
|
$status = "Y";
|
|
}
|
|
|
|
|
|
//echo $total_all;
|
|
//echo $total_verified;
|
|
//echo $status;
|
|
$sql = "UPDATE t_orderheader_group_result SET
|
|
T_OrderHeaderVerification = ?
|
|
WHERE
|
|
T_OrderHeaderGroupResultT_OrderHeaderID = ? AND
|
|
T_OrderHeaderGroupResultGroup_ResultID = ?";
|
|
$query = $this->db_onedev->query($sql, [$status, $order_id, $group_id]);
|
|
if (!$query) {
|
|
$this->sys_error_db("worklist count", $this->db_onedev);
|
|
exit();
|
|
}
|
|
//echo $this->db_onedev->last_query();
|
|
|
|
return true;
|
|
}
|
|
|
|
|
|
|
|
function deletetrx()
|
|
{
|
|
if (!$this->isLogin) {
|
|
$this->sys_error("Invalid Token");
|
|
exit;
|
|
}
|
|
$prm = $this->sys_input;
|
|
$userid = $this->sys_user["M_UserID"];
|
|
|
|
$query = "UPDATE so_walklettercourier SET
|
|
So_WalkLetterCourierIsActive = 'N',
|
|
So_WalkLetterCourierUserID = '{$userid}'
|
|
WHERE
|
|
So_WalkLetterCourierID = {$prm['trx_id']}
|
|
";
|
|
//echo $query;
|
|
$saveheader = $this->db_onedev->query($query);
|
|
$last_id = $prm['trx_id'];
|
|
|
|
$sql = "SELECT * FROM so_resultentry WHERE So_ResultEntryID = {$last_id}";
|
|
$data_log_header = $this->db_onedev->query($sql)->result();
|
|
$sql = "SELECT * FROM so_resultentrydetail WHERE So_ResultEntryDetailSo_ResultEntryID = {$last_id}";
|
|
$data_log_details = $this->db_onedev->query($sql)->result();
|
|
|
|
$data_log = json_encode(array('header' => $data_log_header, 'details' => $data_log_details));
|
|
$sql = "INSERT INTO one_log.log_resultentry_so (
|
|
Log_ResultEntrySoDate,
|
|
Log_ResultEntrySoJSON,
|
|
Log_ResultEntrySoUserID
|
|
)
|
|
VALUES(
|
|
NOW(),
|
|
'{$data_log}',
|
|
{$userid}
|
|
)";
|
|
//echo $sql;
|
|
$this->db_onedev->query($sql);
|
|
|
|
$result = array(
|
|
"total" => 1,
|
|
"records" => array('status' => 'OK'),
|
|
"numbering" => $prm['trx_numbering'],
|
|
"id" => $prm['trx_id']
|
|
);
|
|
$this->sys_ok($result);
|
|
exit;
|
|
}
|
|
|
|
|
|
function gettemplate()
|
|
{
|
|
if (!$this->isLogin) {
|
|
$this->sys_error("Invalid Token");
|
|
exit;
|
|
}
|
|
$prm = $this->sys_input;
|
|
$userid = $this->sys_user["M_UserID"];
|
|
$rst = array();
|
|
|
|
$sql = "SELECT So_TemplateLabelID as id, So_TemplateLabelName as label, '' as details
|
|
FROM so_templatelabel
|
|
WHERE
|
|
So_TemplateLabelM_DoctorID = {$prm['doctor_id']} AND
|
|
So_TemplateLabelT_TestID = {$prm['test_id']} AND
|
|
So_TemplateLabelSo_TemplateID = {$prm['template_id']} AND
|
|
So_TemplateLabelIsActive = 'Y'";
|
|
//echo $sql;
|
|
$rst = $this->db_onedev->query($sql)->result();
|
|
|
|
if (!$rst) {
|
|
$sql = "SELECT So_TemplateLabelID as id, So_TemplateLabelName as label, '' as details
|
|
FROM so_templatelabel
|
|
WHERE
|
|
So_TemplateLabelM_DoctorID = 0 AND
|
|
So_TemplateLabelT_TestID = {$prm['test_id']} AND
|
|
So_TemplateLabelSo_TemplateID = {$prm['template_id']} AND
|
|
So_TemplateLabelIsActive = 'Y'";
|
|
$rst = $this->db_onedev->query($sql)->result();
|
|
}
|
|
|
|
if ($rst) {
|
|
foreach ($rst as $k => $v) {
|
|
$sql = "SELECT so_templatevalueid as id, So_TemplateValueText as value, So_TemplateValueSo_TemplateDetailID as template_detail_id
|
|
FROM so_templatevalue
|
|
JOIN so_templatedetail ON So_TemplateValueSo_TemplateDetailID = So_TemplateDetailID AND
|
|
So_TemplateDetailM_LangID = {$prm['language_id']}
|
|
WHERE
|
|
So_TemplateValueSo_TemplateLabelID = {$v->id} AND So_TemplateValueIsActive = 'Y' ";
|
|
//echo $sql;
|
|
$v->details = $this->db_onedev->query($sql)->result();
|
|
}
|
|
}
|
|
|
|
$result = array(
|
|
"total" => 1,
|
|
"records" => $rst
|
|
);
|
|
$this->sys_ok($result);
|
|
exit;
|
|
}
|
|
|
|
// function printcount()
|
|
// {
|
|
// if (!$this->isLogin) {
|
|
// $this->sys_error("Invalid Token");
|
|
// exit;
|
|
// }
|
|
// $prm = $this->sys_input;
|
|
// $userid = $this->sys_user["M_UserID"];
|
|
// $trx_id = $prm["trx_id"];
|
|
// $sql = "SELECT
|
|
// re.So_ResultEntryT_OrderDetailID,
|
|
// re.So_ResultEntryT_OrderHeaderID,
|
|
// re.So_ResultEntryM_LangID,
|
|
// gr.Group_ResultName
|
|
// FROM so_resultentry re
|
|
// JOIN t_orderdetail od ON re.So_ResultEntryT_OrderDetailID = od.T_OrderDetailID
|
|
// JOIN t_test t ON od.T_OrderDetailT_TestID = t.T_TestID
|
|
// JOIN group_resultdetail grd ON t.T_TestID = grd.Group_ResultDetailT_TestID
|
|
// JOIN group_result gr ON grd.Group_ResultDetailGroup_ResultID = gr.Group_ResultID
|
|
// WHERE re.So_ResultEntryID = '{$trx_id}'";
|
|
// $res_data = $this->db_onedev->query($sql)->row();
|
|
// $orderdetail_id = $res_data->So_ResultEntryT_OrderDetailID;
|
|
|
|
// $sql = "UPDATE t_orderdetail SET
|
|
// T_OrderDetailPrintCount = T_OrderDetailPrintCount + 1,
|
|
// T_OrderDetailPrintBy = {$userid},
|
|
// T_OrderDetailPrintTime = NOW()
|
|
// WHERE
|
|
// T_OrderDetailID = '{$orderdetail_id}'";
|
|
// $this->db_onedev->query($sql);
|
|
// $type = $res_data->Group_ResultName;
|
|
// $lang = $res_data->So_ResultEntryM_LangID;
|
|
// $format = isset($prm['format']) ? $prm['format'] : '';
|
|
|
|
// $rptname = "rpt_hasil_so_xray";
|
|
// $pid = $trx_id;
|
|
|
|
// if ($type == 'Rontgen' || $type == 'X-Ray') $rptname = "rpt_hasil_so_xray";
|
|
// if ($type == 'USG') {
|
|
// $rptname = "rpt_hasil_so_usg";
|
|
// }
|
|
// if ($type == 'BMD') $rptname = "rpt_hasil_so_bdm";
|
|
// if ($type == 'MRI') $rptname = "rpt_hasil_so_xray_mri";
|
|
|
|
// if ($format == 'format-2') {
|
|
// if ($type == 'Rontgen' || $type == 'X-Ray') $rptname = "rpt_hasil_so_xray_2";
|
|
// if ($type == 'USG') $rptname = "rpt_hasil_so_usg_2";
|
|
// if ($type == 'BMD') $rptname = "rpt_hasil_so_bdm_2";
|
|
// if ($type == 'MRI') $rptname = "rpt_hasil_so_xray_mri_2";
|
|
// }
|
|
|
|
// if ($lang == 2) {
|
|
// $rptname .= "_eng";
|
|
// }
|
|
|
|
// $sql_staff = "SELECT M_StaffName FROM m_staff JOIN m_user ON M_UserM_StaffID = M_StaffID WHERE M_UserID = ?";
|
|
// $staff = $this->db_onedev->query($sql_staff, array($userid))->row();
|
|
// $username = $staff ? $staff->M_StaffName : '';
|
|
|
|
// $tm = round(microtime(true) * 1000);
|
|
// $generatedUrl = "/birt/run?__report=report/onelab/lab/{$rptname}.rptdesign&__format=pdf&username={$username}&PID={$pid}&tm={$tm}";
|
|
|
|
// $this->sys_input['orderid'] = $res_data->So_ResultEntryT_OrderHeaderID;
|
|
// $this->sys_input['re_id'] = $trx_id;
|
|
// $this->sys_input['type'] = $type;
|
|
// $this->sys_input['format'] = $format;
|
|
// $this->sys_input['url'] = $generatedUrl;
|
|
|
|
// $this->generateurl();
|
|
|
|
// $result = array(
|
|
// "total" => 1,
|
|
// "records" => $prm
|
|
// );
|
|
// $this->sys_ok($result);
|
|
// exit;
|
|
// }
|
|
|
|
function printcount()
|
|
{
|
|
if (!$this->isLogin) {
|
|
$this->sys_error("Invalid Token");
|
|
exit;
|
|
}
|
|
$prm = $this->sys_input;
|
|
$userid = $this->sys_user["M_UserID"];
|
|
$trx_id = isset($prm["trx_id"]) ? intval($prm["trx_id"]) : 0;
|
|
|
|
// Gunakan Binding (?) untuk keamanan dan mencegah error sintaks
|
|
$sql = "SELECT
|
|
re.So_ResultEntryT_OrderDetailID,
|
|
re.So_ResultEntryT_OrderHeaderID,
|
|
re.So_ResultEntryID,
|
|
gr.Group_ResultName,
|
|
gr.Group_ResultID
|
|
FROM so_resultentry re
|
|
JOIN t_orderdetail od ON re.So_ResultEntryT_OrderDetailID = od.T_OrderDetailID
|
|
JOIN t_test t ON od.T_OrderDetailT_TestID = t.T_TestID
|
|
JOIN group_resultdetail grd ON t.T_TestID = grd.Group_ResultDetailT_TestID
|
|
JOIN group_result gr ON grd.Group_ResultDetailGroup_ResultID = gr.Group_ResultID
|
|
WHERE re.So_ResultEntryID = {$trx_id}";
|
|
|
|
$query = $this->db_onedev->query($sql, array($trx_id));
|
|
|
|
// Validasi: Apakah query berhasil running?
|
|
if ($query === FALSE) {
|
|
$error = $this->db_onedev->error();
|
|
$this->sys_error("Database Error: " . $error['message']);
|
|
exit;
|
|
}
|
|
|
|
$res_data = $query->row();
|
|
|
|
// Validasi: Apakah data ditemukan?
|
|
if (!$res_data) {
|
|
$this->sys_error("Data transaksi (RE ID: $trx_id) tidak ditemukan.");
|
|
exit;
|
|
}
|
|
|
|
$orderdetail_id = $res_data->So_ResultEntryT_OrderDetailID;
|
|
|
|
// Update Print Count
|
|
$sql_update = "UPDATE t_orderdetail SET
|
|
T_OrderDetailPrintCount = T_OrderDetailPrintCount + 1,
|
|
T_OrderDetailPrintBy = ?,
|
|
T_OrderDetailPrintTime = NOW()
|
|
WHERE T_OrderDetailID = ?";
|
|
$this->db_onedev->query($sql_update, array($userid, $orderdetail_id));
|
|
|
|
// Logika penentuan rptname
|
|
$type = $res_data->Group_ResultName;
|
|
$lang = $res_data->So_ResultEntryM_LangID;
|
|
$format = "default-format";
|
|
$pid = $res_data->So_ResultEntryID;
|
|
|
|
// Default fallback report name
|
|
$rptname = "rpt_hasil_so_xray";
|
|
if ($type == 'BMD') {
|
|
$rptname = "rpt_hasil_so_bmd";
|
|
}
|
|
|
|
// Ambil Nama Staff untuk Parameter BIRT
|
|
$sql_staff = "SELECT M_StaffName FROM m_staff JOIN m_user ON M_UserM_StaffID = M_StaffID WHERE M_UserID = ?";
|
|
$staff = $this->db_onedev->query($sql_staff, array($userid))->row();
|
|
$username = $staff ? urlencode($staff->M_StaffName) : '';
|
|
$tm = round(microtime(true) * 1000);
|
|
|
|
// --- LOGIKA BARU MENGGUNAKAN REPORTURL ---
|
|
$generatedUrl = '';
|
|
$code_prefix = '';
|
|
|
|
// Mapping Type ke Code Prefix (Sesuaikan dengan data di tabel print_transaction)
|
|
if ($type == 'Rontgen' || $type == 'X-Ray')
|
|
$code_prefix = 'RONTGEN';
|
|
elseif ($type == 'USG')
|
|
$code_prefix = 'USG';
|
|
elseif ($type == 'BMD')
|
|
$code_prefix = 'BMD';
|
|
elseif ($type == 'MRI')
|
|
$code_prefix = 'MRI';
|
|
|
|
if ($code_prefix) {
|
|
$tx_code = $code_prefix . '-RESULT-P-01';
|
|
$params = [
|
|
'PUsername' => $username,
|
|
'PT_OrderHeaderID' => $pid,
|
|
'TS' => $tm
|
|
];
|
|
$res = $this->reporturl->get_report_url_by_code($tx_code, $params, 'N');
|
|
if ($res[0]) {
|
|
$generatedUrl = $res[1];
|
|
}
|
|
}
|
|
|
|
// Fallback ke logika lama jika URL belum tergenerate (kode tidak ditemukan di DB)
|
|
if (empty($generatedUrl)) {
|
|
$generatedUrl = "/birt/run?__report=report/onelab/lab/{$rptname}.rptdesign&__format=pdf&username={$username}&PID={$pid}&tm={$tm}";
|
|
}
|
|
|
|
// Simpan ke Metadata Email
|
|
$this->sys_input['orderid'] = $res_data->So_ResultEntryT_OrderHeaderID;
|
|
$this->sys_input['re_id'] = $trx_id;
|
|
$this->sys_input['type'] = $type;
|
|
$this->sys_input['format'] = $format;
|
|
$this->sys_input['url'] = $generatedUrl;
|
|
$this->sys_input['group_id'] = $res_data->Group_ResultID;
|
|
|
|
$this->generateurl(); // Memanggil fungsi penyimpanan URL
|
|
|
|
$this->sys_ok(array("total" => 1, "records" => $prm));
|
|
exit;
|
|
}
|
|
|
|
public function generateurl()
|
|
{
|
|
if (!$this->isLogin) {
|
|
$this->sys_error("Invalid Token");
|
|
exit;
|
|
}
|
|
|
|
$prm = $this->sys_input;
|
|
$userid = $this->sys_user["M_UserID"];
|
|
|
|
$orderid = isset($prm['orderid']) ? $prm['orderid'] : 0;
|
|
$re_id = isset($prm['re_id']) ? $prm['re_id'] : 0;
|
|
$type = isset($prm['type']) ? $prm['type'] : '';
|
|
$format = isset($prm['format']) ? $prm['format'] : '';
|
|
$url = isset($prm['url']) ? $prm['url'] : '';
|
|
$group_id = isset($prm['group_id']) ? $prm['group_id'] : 0;
|
|
|
|
if ($orderid == 0 || $re_id == 0 || empty($url)) {
|
|
$this->sys_error("Data tidak lengkap (OrderID/ResultID/URL kosong)");
|
|
exit;
|
|
}
|
|
$check_sql = "SELECT T_EmailNonLabID FROM t_email_nonlab
|
|
WHERE T_EmailNonLabT_OrderHeaderID = ?
|
|
AND T_EmailNonLabSo_ResultEntryID = ?
|
|
AND T_EmailNonLabType = ?";
|
|
|
|
$q_existing = $this->db_onedev->query($check_sql, array($orderid, $re_id, $type));
|
|
$existing = ($q_existing) ? $q_existing->row() : null;
|
|
|
|
if ($existing) {
|
|
$sql = "UPDATE t_email_nonlab SET
|
|
T_EmailNonLabType = ?,
|
|
T_EmailNonLabGroup_ResultID = ?,
|
|
T_EmailNonLabGroup_ResultName = ?,
|
|
T_EmailNonLabUrl = ?,
|
|
T_EmailNonLabUserID = ?,
|
|
T_EmailNonLabUpdated = NOW()
|
|
WHERE T_EmailNonLabID = ?";
|
|
$this->db_onedev->query($sql, array($type, $group_id, $type, $url, $userid, $existing->T_EmailNonLabID));
|
|
} else {
|
|
$sql = "INSERT INTO t_email_nonlab (
|
|
T_EmailNonLabT_OrderHeaderID,
|
|
T_EmailNonLabSo_ResultEntryID,
|
|
T_EmailNonLabType,
|
|
T_EmailNonLabGroup_ResultID,
|
|
T_EmailNonLabGroup_ResultName,
|
|
T_EmailNonLabFormat,
|
|
T_EmailNonLabUrl,
|
|
T_EmailNonLabUserID,
|
|
T_EmailNonLabCreated,
|
|
T_EmailNonLabUpdated
|
|
)
|
|
VALUES (?, ?, ?, ?, ?, ?, ?, ?, NOW(), NOW())";
|
|
|
|
|
|
$query = $this->db_onedev->query($sql, array($orderid, $re_id, $type, $group_id, $type, $format, $url, $userid));
|
|
|
|
|
|
if (!$query) {
|
|
$this->sys_error_db("Gagal menyimpan URL Email", $this->db_onedev);
|
|
exit;
|
|
}
|
|
}
|
|
|
|
$result = array(
|
|
"status" => "OK",
|
|
"message" => "URL Berhasil disimpan"
|
|
);
|
|
$this->sys_ok($result);
|
|
exit;
|
|
}
|
|
|
|
function getrstbylang()
|
|
{
|
|
if (!$this->isLogin) {
|
|
$this->sys_error("Invalid Token");
|
|
exit;
|
|
}
|
|
$prm = $this->sys_input;
|
|
$x_langid = $prm['lang']['id'];
|
|
$x_reid = $prm['detail']['trx_id'];
|
|
$sql = "SELECT * FROM so_resultentry WHERE So_ResultEntryID = '{$x_reid}'";
|
|
//echo $sql;
|
|
$re_langid = $this->db_onedev->query($sql)->row()->So_ResultEntryM_LangID;
|
|
if ($x_langid == $re_langid) {
|
|
$sql = "SELECT
|
|
So_ResultEntryDetailID as trx_id,
|
|
So_ResultEntryDetailSo_TemplateDetailID as template_detail_id,
|
|
So_ResultEntryDetailSo_TemplateDetailName as result_label,
|
|
IFNULL(So_ResultEntryDetailResult,'') as result_value,
|
|
So_ResultEntryDetailFlagPrint as flag_print
|
|
FROM so_resultentrydetail
|
|
|
|
JOIN so_resultentry ON So_ResultEntryDetailSo_ResultEntryID = So_ResultEntryID AND So_ResultEntryM_LangID = {$x_langid}
|
|
WHERE
|
|
So_ResultEntryDetailSo_ResultEntryID = {$x_reid} AND So_ResultEntryDetailisActive = 'Y'
|
|
";
|
|
} else {
|
|
$sql = "
|
|
SELECT
|
|
IFNULL(So_ResultEntryDetailOtherID,0) as trx_id,
|
|
So_TemplateDetailID as template_detail_id,
|
|
IF(ISNULL(So_ResultEntryDetailOtherID),So_TemplateDetailName,So_ResultEntryDetailOtherSo_TemplateDetailName) as result_label,
|
|
So_ResultEntryDetailOtherResult as result_value,
|
|
IFNULL(So_ResultEntryDetailOtherFlagPrint,'N') as flag_print
|
|
FROM so_resultentry
|
|
JOIN t_orderdetail ON T_OrderDetailID = So_ResultEntryT_OrderDetailID
|
|
JOIN so_testtemplate ON So_ResultEntrySo_TemplateID = So_TestTemplateSo_TemplateID AND So_TestTemplateT_TestID = T_OrderDetailT_TestID AND So_TestTemplateIsActive = 'Y'
|
|
JOIN so_templatedetail ON So_TemplateDetailSo_TemplateID = So_TestTemplateSo_TemplateID AND So_TemplateDetailM_LangID = {$x_langid} AND
|
|
So_TemplateDetailIsActive = 'Y'
|
|
LEFT JOIN so_resultentrydetail_other ON So_ResultEntryDetailOtherM_LangID = So_TemplateDetailM_LangID AND
|
|
So_ResultEntryDetailOtherSo_ResultEntryID = So_ResultEntryID AND
|
|
So_ResultEntryDetailOtherSo_TemplateDetailID = So_TemplateDetailID AND
|
|
So_ResultEntryDetailOtherIsActive = 'Y'
|
|
WHERE
|
|
So_ResultEntryID = {$x_reid} AND So_ResultEntryIsActive = 'Y'
|
|
";
|
|
}
|
|
|
|
//echo $sql;
|
|
$rst = $this->db_onedev->query($sql)->result_array();
|
|
$result = array(
|
|
"total" => 1,
|
|
"records" => $rst
|
|
);
|
|
$this->sys_ok($result);
|
|
exit;
|
|
}
|
|
|
|
|
|
function save_flagprint()
|
|
{
|
|
if (!$this->isLogin) {
|
|
$this->sys_error("Invalid Token");
|
|
exit;
|
|
}
|
|
|
|
$rst_data = array('status' => 'OK');
|
|
|
|
$prm = $this->sys_input;
|
|
$row = $prm['row'];
|
|
$selected_trx = $prm['selected_trx'];
|
|
$userid = $this->sys_user["M_UserID"];
|
|
$sql = "SELECT * FROM so_resultentry WHERE So_ResultEntryID = '{$selected_trx['re_id']}'";
|
|
//echo $sql;
|
|
$re_langid = $this->db_onedev->query($sql)->row()->So_ResultEntryM_LangID;
|
|
if ($re_langid == $prm['lang']) {
|
|
$sql = "UPDATE so_resultentrydetail SET
|
|
So_ResultEntryDetailFlagPrint = '{$row['flag_print']}',
|
|
So_ResultEntryDetailUserID = {$userid}
|
|
WHERE So_ResultEntryDetailID = {$row['trx_id']}";
|
|
//echo $sql;
|
|
$this->db_onedev->query($sql);
|
|
} else {
|
|
$sql = "UPDATE so_resultentrydetail_other SET
|
|
So_ResultEntryDetailOtherFlagPrint = '{$row['flag_print']}',
|
|
So_ResultEntryDetailOtherUserID = {$userid}
|
|
WHERE So_ResultEntryDetailOtherID = {$row['trx_id']}";
|
|
//echo $sql;
|
|
$this->db_onedev->query($sql);
|
|
}
|
|
|
|
|
|
$result = array(
|
|
"total" => 1,
|
|
"records" => $rst_data
|
|
);
|
|
$this->sys_ok($result);
|
|
|
|
exit;
|
|
}
|
|
|
|
function gethistory()
|
|
{
|
|
if (!$this->isLogin) {
|
|
$this->sys_error("Invalid Token");
|
|
exit;
|
|
}
|
|
|
|
$rst_data = array('status' => 'OK');
|
|
|
|
$prm = $this->sys_input;
|
|
$patientid = $prm['patientid'];
|
|
$orderid = $prm['orderid'];
|
|
$sql = "SELECT
|
|
T_OrderHeaderM_PatientID as patientid,
|
|
T_OrderHeaderID as orderid,
|
|
T_OrderHeaderLabNumber as noreg,
|
|
date_format(T_OrderHeaderDate,'%d-%m-%Y') as order_date,
|
|
T_OrderHeaderM_PatientAge as age,
|
|
GROUP_CONCAT(T_TestName separator ',') as tests
|
|
FROM t_orderheader
|
|
JOIN t_orderdetail ON T_OrderDetailT_OrderHeaderID = T_OrderHeaderID AND
|
|
T_OrderDetailIsActive = 'Y'
|
|
JOIN t_test ON T_OrderDetailT_TestID = T_TestID AND
|
|
T_OrderDetailT_TestIsResult = 'Y' AND
|
|
T_TestIsNonLab <> ''
|
|
WHERE
|
|
T_OrderHeaderM_PatientID = {$patientid} AND
|
|
T_OrderHeaderID < {$orderid} AND
|
|
T_OrderHeaderIsActive = 'Y'
|
|
GROUP BY T_OrderHeaderID";
|
|
|
|
$result = array(
|
|
"total" => 1,
|
|
"records" => $rst_data
|
|
);
|
|
$this->sys_ok($result);
|
|
|
|
exit;
|
|
}
|
|
|
|
function search_histories()
|
|
{
|
|
$prm = $this->sys_input;
|
|
if (!$this->isLogin) {
|
|
$this->sys_error("Invalid Token");
|
|
exit;
|
|
}
|
|
|
|
$search = $prm["search"];
|
|
$patientid = $prm['patientid'];
|
|
$orderid = $prm['orderid'];
|
|
|
|
if (!isset($prm['current_page']))
|
|
$prm['current_page'] = 1;
|
|
|
|
$sql_where = "";
|
|
$number_limit = 10;
|
|
$number_offset = ($prm['current_page'] - 1) * $number_limit;
|
|
|
|
if ($search != "") {
|
|
$sql_where = "";
|
|
}
|
|
|
|
$sql = " SELECT count(*) as total
|
|
FROM (
|
|
SELECT *
|
|
FROM t_orderheader
|
|
JOIN t_orderdetail ON T_OrderDetailT_OrderHeaderID = T_OrderHeaderID AND
|
|
T_OrderDetailIsActive = 'Y'
|
|
JOIN t_test ON T_OrderDetailT_TestID = T_TestID AND
|
|
T_OrderDetailT_TestIsResult = 'Y' AND
|
|
T_TestIsNonLab <> ''
|
|
WHERE
|
|
T_OrderHeaderM_PatientID = {$patientid} AND
|
|
T_OrderHeaderID < {$orderid} AND
|
|
T_OrderHeaderIsActive = 'Y'
|
|
GROUP BY T_OrderHeaderID
|
|
) x
|
|
";
|
|
//echo $sql;
|
|
$query = $this->db_onedev->query($sql);
|
|
|
|
$tot_count = 0;
|
|
$tot_page = 0;
|
|
if ($query) {
|
|
$tot_count = $query->result_array()[0]["total"];
|
|
$tot_page = ceil($tot_count / $number_limit);
|
|
} else {
|
|
$this->sys_error_db("t_samplestorageout count", $this->db_onedev);
|
|
exit;
|
|
}
|
|
|
|
|
|
$sql = "SELECT
|
|
T_OrderHeaderM_PatientID as patientid,
|
|
T_OrderHeaderID as orderid,
|
|
T_OrderHeaderLabNumber as noreg,
|
|
date_format(T_OrderHeaderDate,'%d-%m-%Y') as order_date,
|
|
T_OrderHeaderM_PatientAge as age,
|
|
GROUP_CONCAT(T_TestName separator ',') as tests
|
|
FROM t_orderheader
|
|
JOIN t_orderdetail ON T_OrderDetailT_OrderHeaderID = T_OrderHeaderID AND
|
|
T_OrderDetailValidation = 'Y' AND
|
|
T_OrderDetailIsActive = 'Y'
|
|
JOIN t_test ON T_OrderDetailT_TestID = T_TestID AND
|
|
T_OrderDetailT_TestIsResult = 'Y' AND
|
|
T_TestIsNonLab <> ''
|
|
WHERE
|
|
T_OrderHeaderM_PatientID = {$patientid} AND
|
|
T_OrderHeaderID < {$orderid} AND
|
|
T_OrderHeaderIsActive = 'Y'
|
|
GROUP BY T_OrderHeaderID
|
|
ORDER BY T_OrderHeaderID DESC
|
|
limit $number_limit offset $number_offset";
|
|
//echo $sql;
|
|
$query = $this->db_onedev->query($sql);
|
|
$rows = $query->result_array();
|
|
//echo $this->db_onedev->last_query();
|
|
|
|
if ($rows) {
|
|
foreach ($rows as $k => $v) {
|
|
$sql = "SELECT
|
|
So_ResultEntryID as trx_id,
|
|
T_OrderDetailT_OrderHeaderID as orderid,
|
|
UPPER(T_TestName) as test_name,
|
|
T_TestID as test_id,
|
|
M_LangID as language_id,
|
|
M_LangName as language_name,
|
|
CONCAT(M_DoctorPrefix,M_DoctorPrefix2,' ',M_DoctorName,'...') as doctor_fullname,
|
|
'' as details,
|
|
'N' as xshow
|
|
FROM so_resultentry
|
|
JOIN t_orderdetail ON T_OrderDetailID = So_ResultEntryT_OrderDetailID AND T_OrderDetailIsActive = 'Y'
|
|
JOIN t_orderheader ON So_ResultEntryT_OrderHeaderID = T_OrderHeaderID
|
|
JOIN t_test ON T_OrderDetailT_TestID = T_TestID
|
|
JOIN t_samplingso ON T_SamplingSoT_OrderHeaderID = T_OrderDetailT_OrderHeaderID AND
|
|
T_SamplingSoT_TestID = T_TestID
|
|
JOIN m_doctor ON T_SamplingSoM_DoctorID = M_DoctorID
|
|
JOIN m_lang ON So_ResultEntryM_LangID = M_LangID
|
|
WHERE
|
|
So_ResultEntryT_OrderHeaderID = {$v['orderid']} AND So_ResultEntryValidation2 = 'Y'
|
|
GROUP BY So_ResultEntryID
|
|
";
|
|
//echo $sql;
|
|
$rst_details = $this->db_onedev->query($sql)->result_array();
|
|
foreach ($rst_details as $ki => $vi) {
|
|
$sql = "SELECT
|
|
So_ResultEntryDetailID as trx_id,
|
|
So_ResultEntryDetailSo_TemplateDetailID as template_detail_id,
|
|
So_ResultEntryDetailSo_TemplateDetailName as result_label,
|
|
So_ResultEntryDetailResult as result_value
|
|
FROM so_resultentrydetail
|
|
|
|
WHERE
|
|
So_ResultEntryDetailSo_ResultEntryID = {$vi['trx_id']} AND So_ResultEntryDetailisActive = 'Y'";
|
|
//echo $sql;
|
|
$rst_details[$ki]['details'] = $this->db_onedev->query($sql)->result_array();
|
|
}
|
|
$rows[$k]['details'] = $rst_details;
|
|
}
|
|
}
|
|
|
|
$result = array("total" => $tot_page, "records" => $rows, "sql" => $this->db_onedev->last_query());
|
|
$this->sys_ok($result);
|
|
exit;
|
|
}
|
|
function getdoctor()
|
|
{
|
|
if (!$this->isLogin) {
|
|
$this->sys_error("Invalid Token");
|
|
exit;
|
|
}
|
|
$prm = $this->sys_input;
|
|
$search = $prm['search'];
|
|
$query = " SELECT M_DoctorID,
|
|
M_DoctorID doctorID,
|
|
M_DoctorPrefix,
|
|
M_DoctorPrefix2,
|
|
M_DoctorName,
|
|
M_DoctorSufix,
|
|
M_DoctorSufix2,
|
|
M_DoctorCode ,
|
|
CONCAT(M_DoctorPrefix,' ',M_DoctorPrefix2, ' ', M_DoctorName, ' ',M_DoctorSufix,' ', M_DoctorSufix2, ' ') doctorName
|
|
FROM m_doctor
|
|
WHERE M_DoctorIsActive = 'Y'
|
|
AND CONCAT(M_DoctorPrefix,' ',M_DoctorPrefix2, ' ', M_DoctorName, ' ',M_DoctorSufix,' ', M_DoctorSufix2, ' ') LIKE '%$search%'
|
|
";
|
|
//echo $query;
|
|
$rows = $this->db_onedev->query($query)->result_array();
|
|
|
|
$result = array(
|
|
"total" => count($rows),
|
|
"records" => $rows,
|
|
"query" => $this->db_onedev->last_query()
|
|
);
|
|
$this->sys_ok($result);
|
|
exit;
|
|
}
|
|
function savedoctor()
|
|
{
|
|
if (!$this->isLogin) {
|
|
$this->sys_error("Invalid Token");
|
|
exit;
|
|
}
|
|
|
|
$prm = $this->sys_input;
|
|
$userid = $this->sys_user["M_UserID"];
|
|
$id = $prm['id'];
|
|
$doctorid = $prm['doctorid'];
|
|
$query = " UPDATE so_resultentry
|
|
SET So_ResultEntryM_DoctorID = $doctorid
|
|
WHERE So_ResultEntryID = $id";
|
|
//echo $query;
|
|
$rows = $this->db_onedev->query($query);
|
|
if (!$rows) {
|
|
$message = $this->db_onedev->error();
|
|
$message['qry'] = $this->db_onedev->last_query();
|
|
$this->sys_error($message);
|
|
exit;
|
|
}
|
|
|
|
$act = "CX_DOCTOR";
|
|
$this->soresultlog->step_action($act, $id, $userid);
|
|
|
|
$result = array();
|
|
$this->sys_ok($result);
|
|
exit;
|
|
}
|
|
public function searchbyid()
|
|
{
|
|
$prm = $this->sys_input;
|
|
if (!$this->isLogin) {
|
|
$this->sys_error("Invalid Token");
|
|
exit;
|
|
}
|
|
$userid = $this->sys_user["M_UserID"];
|
|
$nolab = $prm["nolab"];
|
|
$type = $prm["type"];
|
|
$search = $prm["search"];
|
|
|
|
$groupid = 3;
|
|
$subgroupid = $prm["subgroupid"];
|
|
$typeresult = isset($prm["type"]) ? $prm["type"] : 'Rontgen';
|
|
$join_group = '';
|
|
if ($groupid != 0) {
|
|
//$join_group = "JOIN nat_group ON T_TestNat_GroupID = Nat_GroupID AND Nat_GroupID = {$groupid}";
|
|
}
|
|
$join_subgroup = '';
|
|
if ($subgroupid != 0) {
|
|
//$join_group = "JOIN nat_subgroup ON T_TestNat_SubgroupID = Nat_SubgroupID AND Nat_SubgroupID = {$subgroupid}";
|
|
}
|
|
|
|
if (!isset($prm['current_page']))
|
|
$prm['current_page'] = 1;
|
|
|
|
|
|
$sql_where = "WHERE T_OrderDetailIsActive = 'Y'";
|
|
|
|
$number_limit = 10;
|
|
$number_offset = ($prm['current_page'] - 1) * $number_limit;
|
|
//$sql_param = array();
|
|
|
|
$sql_where = " WHERE ( T_OrderHeaderLabNumber = '{$nolab}' ) AND T_OrderDetailIsActive = 'Y' ";
|
|
|
|
|
|
|
|
$sql = " SELECT count(*) as total
|
|
FROM (
|
|
SELECT So_ResultEntryID, M_CompanyID as company_id
|
|
FROM t_orderdetail
|
|
LEFT JOIN so_resultentry ON T_OrderDetailID = So_ResultEntryT_OrderDetailID AND So_ResultEntryIsActive = 'Y'
|
|
JOIN t_test ON T_OrderDetailT_TestID = T_TestID
|
|
JOIN t_orderheader ON T_OrderDetailT_OrderHeaderID = T_OrderHeaderID
|
|
JOIN m_company ON T_OrderHeaderM_CompanyID = M_CompanyID
|
|
JOIN m_patient ON T_OrderHeaderM_PatientID = M_PatientID
|
|
LEFT JOIN m_title ON M_PatientM_TitleID = M_TitleID
|
|
JOIN t_samplingso ON T_SamplingSoT_OrderHeaderID = T_OrderHeaderID
|
|
AND T_SamplingSoFlag = 'D'
|
|
AND T_SamplingSoT_TestID = T_TestID
|
|
JOIN group_resultdetail ON Group_ResultDetailT_TestID = T_TestID AND
|
|
Group_ResultDetailIsActive = 'Y'
|
|
JOIN group_result ON Group_ResultDetailGroup_ResultID = Group_ResultID AND
|
|
Group_ResultName = '{$typeresult}'
|
|
LEFT JOIN m_doctor ON So_ResultEntryM_DoctorID = M_DoctorID
|
|
AND M_DoctorIsActive = 'Y'
|
|
$join_group
|
|
$join_subgroup
|
|
$sql_where
|
|
GROUP BY T_OrderHeaderID
|
|
) x
|
|
";
|
|
//echo $sql;
|
|
$query = $this->db_onedev->query($sql);
|
|
|
|
$tot_count = 0;
|
|
$tot_page = 0;
|
|
if ($query) {
|
|
$tot_count = $query->result_array()[0]["total"];
|
|
$tot_page = ceil($tot_count / $number_limit);
|
|
} else {
|
|
$this->sys_error_db("t_samplestorageout count", $this->db_onedev);
|
|
exit;
|
|
}
|
|
|
|
|
|
$sql = "SELECT * FROM (SELECT
|
|
IFNULL(So_ResultEntryID,0) as re_id,
|
|
T_OrderHeaderID as trx_id,
|
|
M_PatientID as patientid,
|
|
M_DoctorID doctorID,
|
|
T_SamplingSOID,
|
|
CONCAT(M_DoctorPrefix,' ',M_DoctorPrefix2, ' ', M_DoctorName, ' ',M_DoctorSufix,' ', M_DoctorSufix2, ' ') doctorName,
|
|
T_OrderHeaderLabNumber as ordernumber,
|
|
UPPER(CONCAT(M_TitleName,' ',M_PatientName)) as patient_fullname,
|
|
UPPER(M_SexName) as sexname,
|
|
DATE_FORMAT(T_OrderHeaderDate,'%d-%m-%Y') as orderdate,
|
|
DATE_FORMAT(M_PatientDOB,'%d-%m-%Y') as dob,
|
|
UPPER(T_OrderHeaderM_PatientAge) as umur,
|
|
M_CompanyID as company_id,
|
|
UPPER(M_CompanyName) as company_name,
|
|
'' as details,
|
|
CASE
|
|
WHEN So_ResultEntryStatus = 'NEW' THEN 'BARU'
|
|
WHEN So_ResultEntryStatus = 'VAL1' AND T_OrderDetailPrintCount = 0 THEN 'VERIFIKASI'
|
|
WHEN So_ResultEntryStatus = 'VAL2' THEN 'VALIDASI'
|
|
WHEN T_OrderDetailPrintCount <> 0 THEN 'PRINTED'
|
|
END as status_name,
|
|
'' as deliveries,
|
|
IFNULL(T_OrderHeaderFoNote,'') as fo_note,
|
|
fn_getstaffname(T_OrderHeaderFoNoteM_UserID) as fo_note_user,
|
|
'' as fo_ver_note,
|
|
'' as fo_ver_note_user,
|
|
IFNULL(T_OrderHeaderSamplingNote,'') as sampling_note,
|
|
fn_getstaffname(T_OrderHeaderSamplingNoteM_UserID) as sampling_note_user,
|
|
fn_result_so_has_history_nonlab(M_PatientID,T_OrderHeaderID) as has_histories,
|
|
Group_ResultName as group_name
|
|
FROM t_orderdetail
|
|
LEFT JOIN so_resultentry ON T_OrderDetailID = So_ResultEntryT_OrderDetailID AND So_ResultEntryIsActive = 'Y'
|
|
JOIN t_test ON T_OrderDetailT_TestID = T_TestID
|
|
JOIN t_orderheader ON T_OrderDetailT_OrderHeaderID = T_OrderHeaderID
|
|
LEFT JOIN m_user userfo ON T_OrderHeaderFoNoteM_UserID = userfo.M_UserID
|
|
LEFT JOIN m_user usersampling ON T_OrderHeaderSamplingNoteM_UserID = usersampling.M_UserID
|
|
JOIN m_company ON T_OrderHeaderM_CompanyID = M_CompanyID
|
|
JOIN m_patient ON T_OrderHeaderM_PatientID = M_PatientID
|
|
JOIN m_sex ON M_PatientM_SexID = M_SexID
|
|
LEFT JOIN m_title ON M_PatientM_TitleID = M_TitleID
|
|
JOIN t_samplingso ON T_SamplingSoT_OrderHeaderID = T_OrderHeaderID
|
|
AND T_SamplingSoT_TestID = T_TestID
|
|
JOIN group_resultdetail ON Group_ResultDetailT_TestID = T_TestID AND
|
|
Group_ResultDetailIsActive = 'Y'
|
|
JOIN group_result ON Group_ResultDetailGroup_ResultID = Group_ResultID AND
|
|
Group_ResultName = '{$typeresult}'
|
|
LEFT JOIN m_doctor ON So_ResultEntryM_DoctorID = M_DoctorID
|
|
AND M_DoctorIsActive = 'Y'
|
|
$join_group
|
|
$join_subgroup
|
|
$sql_where
|
|
GROUP BY T_OrderHeaderID
|
|
ORDER BY T_OrderHeaderID ASC
|
|
limit $number_limit offset $number_offset
|
|
) x
|
|
";
|
|
// echo $sql;
|
|
$query = $this->db_onedev->query($sql);
|
|
if (!$query) {
|
|
$message = $this->db_onedev->error();
|
|
$message['qry'] = $this->db_onedev->last_query();
|
|
$this->sys_error($message);
|
|
exit;
|
|
}
|
|
$rows = $query->result_array();
|
|
//echo $this->db_onedev->last_query();
|
|
|
|
|
|
if ($rows) {
|
|
foreach ($rows as $k => $v) {
|
|
$arr_status = array();
|
|
|
|
if (intval($v['re_id']) == 0) {
|
|
// echo 'IN';
|
|
$insert_so = $this->nonlabtemplate->generate($v['T_SamplingSOID']);
|
|
// echo $v['T_SamplingSOID'];
|
|
// print_r($insert_so);
|
|
if ($insert_so) {
|
|
$v['re_id'] = $insert_so['So_ResultEntryID'];
|
|
/*$sql = "SELECT IFNULL(M_DoctorID,0) as M_DoctorID
|
|
FROM m_staff
|
|
JOIN m_user ON M_UserM_StaffID = M_StaffID AND M_UserID = {$userid}
|
|
LEFT JOIN m_doctor ON M_StaffM_DoctorID = M_DoctorID
|
|
WHERE
|
|
M_StaffIsActive = 'Y'
|
|
LIMIT 1";
|
|
$row_doctor_staff = $this->db_onedev->query($sql)->row_array();*/
|
|
//echo $sql;
|
|
|
|
/*if (intval($row_doctor_staff['M_DoctorID']) > 0) {
|
|
$sql = "UPDATE so_resultentry SET So_ResultEntryM_DoctorID = {$row_doctor_staff['M_DoctorID']}
|
|
WHERE So_ResultEntryID = {$v['re_id']}
|
|
";
|
|
$this->db_onedev->query($sql);
|
|
//echo $sql;
|
|
}*/
|
|
$rows[$k]['re_id'] = $v['re_id'];
|
|
$v['status_name'] = 'NEW';
|
|
$rows[$k]['status_name'] = $v['status_name'];
|
|
} else {
|
|
$message = $this->db_onedev->error();
|
|
$message['qry'] = $this->db_onedev->last_query();
|
|
$this->sys_error($message);
|
|
exit;
|
|
}
|
|
}
|
|
|
|
$sql = "SELECT
|
|
So_ResultEntryID as trx_id,
|
|
T_OrderDetailT_OrderHeaderID as orderid,
|
|
T_OrderHeaderM_PatientID as patientid,
|
|
T_TestT_SampleTypeID as sampletypeid,
|
|
UPPER(T_TestName) as test_name,
|
|
T_TestNat_TestID as nat_testid,
|
|
T_TestID as test_id,
|
|
'' as language_id,
|
|
So_ResultEntryNonlab_TemplateID as template_id,
|
|
-- IF(T_OrderHeaderAddOnPatientMcu = 'Y' OR M_MouIsMcu = 'Y','Y','N') as is_mcu,
|
|
'' as status_result,
|
|
'' as status_result_arr,
|
|
CASE
|
|
WHEN So_ResultEntryStatus = 'NEW' THEN 'BARU'
|
|
WHEN So_ResultEntryStatus = 'VAL1' THEN 'VALIDASI 1'
|
|
WHEN So_ResultEntryStatus = 'VAL2' THEN 'VALIDASI 2'
|
|
END as status_name,
|
|
CASE
|
|
WHEN So_ResultEntryStatus = 'NEW' THEN 'BARU'
|
|
WHEN So_ResultEntryStatus = 'VAL1' AND T_OrderDetailPrintCount = 0 THEN 'VALIDASI 1'
|
|
WHEN So_ResultEntryStatus = 'VAL2' THEN 'VALIDASI 2'
|
|
WHEN T_OrderDetailPrintCount <> 0 THEN 'PRINTED'
|
|
END as status_header,
|
|
Group_ResultName as type,
|
|
'' as langs,
|
|
So_ResultEntryStatus as status,
|
|
'' as language_name,
|
|
IFNULL(M_DoctorID,0) as doctor_id,
|
|
CONCAT(M_DoctorPrefix,' ',M_DoctorPrefix2, ' ', M_DoctorName, ' ',M_DoctorSufix,' ', M_DoctorSufix2, ' ') as doctor_fullname,
|
|
'' as details,
|
|
'' as photos
|
|
FROM so_resultentry
|
|
JOIN t_orderdetail ON So_ResultEntryT_OrderDetailID = T_OrderDetailID AND T_OrderDetailIsActive = 'Y'
|
|
JOIN t_orderheader ON So_ResultEntryT_OrderHeaderID = T_OrderHeaderID
|
|
JOIN mgm_mcu ON T_OrderHeaderMgm_McuID = Mgm_McuID
|
|
JOIN t_test ON T_OrderDetailT_TestID = T_TestID
|
|
JOIN group_resultdetail ON Group_ResultDetailT_TestID = T_TestID AND
|
|
Group_ResultDetailIsActive = 'Y'
|
|
JOIN group_result ON Group_ResultDetailGroup_ResultID = Group_ResultID
|
|
AND Group_ResultName = '{$typeresult}'
|
|
LEFT JOIN m_doctor ON So_ResultEntryM_DoctorID = M_DoctorID
|
|
JOIN t_samplingso ON T_SamplingSoT_OrderHeaderID = T_OrderDetailT_OrderHeaderID AND T_SamplingSoT_TestID = T_TestID
|
|
$join_group
|
|
$join_subgroup
|
|
WHERE
|
|
So_ResultEntryT_OrderHeaderID = {$v['trx_id']}
|
|
GROUP BY So_ResultEntryID";
|
|
//echo $sql;
|
|
$rst_details = $this->db_onedev->query($sql)->result_array();
|
|
foreach ($rst_details as $ki => $vi) {
|
|
array_push($arr_status, $vi['status_header']);
|
|
$xstatus_result = array();
|
|
/*if($vi['status_result'] == 'N'){
|
|
$xstatus_result = array('id'=>'N','name'=>'Tidak Normal');
|
|
}
|
|
if($vi['status_result'] == 'Y'){
|
|
$xstatus_result = array('id'=>'Y','name'=>'Normal');
|
|
}*/
|
|
// SELECT Mcu_StatusResultValueCode as id, Mcu_StatusResultValueName as name
|
|
// FROM so_resultentry_category_result
|
|
// JOIN mcu_statusresult_value ON So_ResultEntryCategoryResultValue = Mcu_StatusResultValueCode AND
|
|
// Mcu_StatusResultValueIsActive = 'Y'
|
|
// WHERE
|
|
// So_ResultEntryCategoryResultSo_ResultEntryID = {$vi['trx_id']} AND
|
|
// So_ResultEntryCategoryResultIsActive = 'Y'
|
|
$sql = "SELECT NonlabConclusionDetailID as id, NonlabConclusionDetailName as name
|
|
FROM so_resultentry_category_result
|
|
JOIN nonlab_conclusion_detail ON So_ResultEntryCategoryNonlabConclusionDetailID = NonlabConclusionDetailID AND
|
|
NonlabConclusionDetailIsActive = 'Y'
|
|
WHERE
|
|
So_ResultEntryCategoryResultSo_ResultEntryID = {$vi['trx_id']} AND
|
|
So_ResultEntryCategoryResultIsActive = 'Y'
|
|
";
|
|
$get_status_result = $this->db_onedev->query($sql)->result_array();
|
|
if ($get_status_result) {
|
|
$xstatus_result = $get_status_result;
|
|
}
|
|
|
|
$rst_details[$ki]['status_result'] = $xstatus_result;
|
|
|
|
$sql = "SELECT NonlabConclusionDetailID AS id, NonlabConclusionDetailName as name
|
|
FROM nonlab_conclusion_detail d1
|
|
JOIN (SELECT * FROM nonlab_conclusion WHERE NonlabConclusionIsActive = 'Y' LIMIT 1) d2
|
|
ON d1.NonlabConclusionDetailNonlabConclusionID = d2.NonlabConclusionID";
|
|
$data_status_result_array = $this->db_onedev->query($sql)->result_array();
|
|
|
|
// SELECT Mcu_StatusResultJson as xjson
|
|
// FROM mcu_statusresult
|
|
// JOIN mcu_statusresult_detail ON Mcu_StatusResultDetailMcu_StatusResultID = Mcu_StatusResultID AND
|
|
// Mcu_StatusResultDetailIsActive = 'Y' AND Mcu_StatusResultDetailNat_TestID = {$vi['nat_testid']}
|
|
// WHERE
|
|
// Mcu_StatusResultIsDefault = 'N' AND
|
|
// Mcu_StatusResultIsActive = 'Y'
|
|
// GROUP BY Mcu_StatusResultID
|
|
// LIMIT 1
|
|
$sql = "SELECT NonlabConclusionDetailID AS id , NonlabConclusionDetailName as name
|
|
FROM nonlab_conclusion_mapping
|
|
JOIN nonlab_conclusion_detail ON NonlabConclusionMappingNonlabConclusionID = NonlabConclusionDetailNonlabConclusionID AND NonlabConclusionDetailIsActive ='Y'
|
|
JOIN nonlab_conclusion ON NonlabConclusionMappingNonlabConclusionID = NonlabConclusionID AND NonlabConclusionIsActive = 'Y'
|
|
WHERE NonlabConclusionMappingNat_TestID = {$vi['nat_testid']}";
|
|
$data_status_result_array_other = $this->db_onedev->query($sql)->result_array();
|
|
if ($data_status_result_array_other) {
|
|
$data_status_result_array = $data_status_result_array_other;
|
|
//$data_status_result_array = preg_replace('/\\\\/', '', json_encode($data_status_result_array_other->row()->xjson));
|
|
}
|
|
|
|
$rst_details[$ki]['status_result_arr'] = $data_status_result_array;
|
|
$rst_details[$ki]['status_result'] = $xstatus_result;
|
|
$sql = "SELECT
|
|
So_ResultEntryDetailID as trx_id,
|
|
So_ResultEntryDetailNonlab_TemplateDetailID as template_detail_id,
|
|
So_ResultEntryDetailNonlab_TemplateDetailName as result_label,
|
|
So_ResultEntryDetailResult as result_value,
|
|
So_ResultEntryDetailFlagPrint as flag_print,
|
|
So_ResultEntryDetailResult as result_value_before
|
|
FROM so_resultentrydetail
|
|
WHERE
|
|
So_ResultEntryDetailSo_ResultEntryID = {$vi['trx_id']} AND So_ResultEntryDetailisActive = 'Y'
|
|
";
|
|
// echo $sql;
|
|
$rst_details[$ki]['details'] = $this->db_onedev->query($sql)->result_array();
|
|
if (!$rst_details[$ki]['details']) {
|
|
$message = $this->db_onedev->error();
|
|
$message['qry'] = $this->db_onedev->last_query();
|
|
$this->sys_error($message);
|
|
exit;
|
|
}
|
|
// $rst_details[$ki]['langs'] = $this->getlangs($vi['orderid']);
|
|
$rst_details[$ki]['langs'] = "";
|
|
$rst_details[$ki]['photos'] = "";
|
|
// $rst_details[$ki]['photos'] = $this->getphotos($vi['orderid'], $vi['sampletypeid']);
|
|
//get default value template
|
|
$sql = "SELECT
|
|
Nonlab_TemplateResultID as resultDefaultID,
|
|
Nonlab_TemplateResultName as resultDefaultName,
|
|
Nonlab_TemplateResultNonlabTemplateID as resultDefaultTemplateID,
|
|
Nonlab_TemplateResultM_DoctorID as resultDefaultDoctorID
|
|
FROM nonlab_template_result
|
|
WHERE Nonlab_TemplateResultNonlabTemplateID = '{$vi['template_id']}'
|
|
AND Nonlab_TemplateResultM_DoctorID IN ('0', '{$vi['doctor_id']}')
|
|
AND Nonlab_TemplateResultIsActive = 'Y'";
|
|
// echo $sql;
|
|
$qry = $this->db_onedev->query($sql);
|
|
if (!$qry) {
|
|
$message = $this->db_onedev->error();
|
|
$message['qry'] = $this->db_onedev->last_query();
|
|
$this->sys_error($message);
|
|
exit;
|
|
}
|
|
$resultDefault = $qry->result_array();
|
|
|
|
for ($a = 0; $a < count($resultDefault); $a++) {
|
|
$sql = "SELECT
|
|
NonlabTemplateResultDetailID as resultDefaultDetailID,
|
|
NonlabTemplateResultDetailNonlab_TemplateResultID,
|
|
NonlabTemplateResultDetailNonlabTemplateDetailID AS resultDefaultDetailNonlabtemplateDetailID,
|
|
NonlabTemplateResultDetailResult as resultDefaultDetailResult
|
|
FROM nonlab_template_result_detail
|
|
WHERE NonlabTemplateResultDetailNonlab_TemplateResultID = '{$resultDefault[$a]['resultDefaultID']}'
|
|
AND NonlabTemplateResultDetailIsActive = 'Y'";
|
|
$qry = $this->db_onedev->query($sql);
|
|
if (!$qry) {
|
|
$message = $this->db_onedev->error();
|
|
$message['qry'] = $this->db_onedev->last_query();
|
|
$this->sys_error($message);
|
|
exit;
|
|
}
|
|
$resultDefaultDetail = $qry->result_array();
|
|
$resultDefault[$a]['detail'] = $resultDefaultDetail;
|
|
}
|
|
// $rows[$k]['defaultValue'] = $resultDefault;
|
|
$rst_details[$ki]['defaultValue'] = $resultDefault;
|
|
}
|
|
$rows[$k]['details'] = $rst_details;
|
|
$rows[$k]['deliveries'] = "";
|
|
// $rows[$k]['deliveries'] = $this->getdeliveries($v['trx_id'], $prm["typeresult"]);
|
|
$status_header = 'BARU';
|
|
if (in_array("VALIDASI 1", $arr_status) && !in_array("PRINTED", $arr_status) && !in_array("BARU", $arr_status) & !in_array("VALIDASI 2", $arr_status)) {
|
|
$status_header = 'VERIFIKASI';
|
|
}
|
|
if (in_array("PRINTED", $arr_status)) {
|
|
$status_header = 'PRINTED';
|
|
}
|
|
if (in_array("VALIDASI 2", $arr_status) && !in_array("PRINTED", $arr_status) && !in_array("BARU", $arr_status) & !in_array("VALIDASI 1", $arr_status)) {
|
|
$status_header = 'VALIDASI';
|
|
}
|
|
$rows[$k]['status_name'] = $status_header;
|
|
}
|
|
}
|
|
$sql = "SELECT
|
|
S_MenuUrl
|
|
FROM s_menu WHERE
|
|
S_MenuName = 'Specimen Collection Mobile' AND S_MenuIsActive = 'Y'";
|
|
$nextUrl = $this->db_onedev->query($sql)->result_array()[0]['S_MenuUrl'];
|
|
|
|
//$this->_add_address($rows);
|
|
$result = array("total" => $tot_page, "records" => $rows, "nexturl" => $nextUrl);
|
|
$this->sys_ok($result);
|
|
exit;
|
|
}
|
|
|
|
function getdoctortemplate()
|
|
{
|
|
try {
|
|
if (!$this->isLogin) {
|
|
$this->sys_error("Invalid Token");
|
|
exit;
|
|
}
|
|
$prm = $this->sys_input;
|
|
if (!isset($prm['doctor_id']) || (string)$prm['doctor_id'] === '') {
|
|
$this->sys_error("Parameter 'doctor_id' is required!");
|
|
exit;
|
|
}
|
|
$doctor_id = $prm['doctor_id'];
|
|
$template_id = isset($prm['template_id']) ? $prm['template_id'] : '';
|
|
|
|
// Query untuk mendapatkan template default (0) DAN template spesifik dokter
|
|
$sql = "SELECT
|
|
Nonlab_TemplateResultID as resultDefaultID,
|
|
Nonlab_TemplateResultName as resultDefaultName,
|
|
Nonlab_TemplateResultNonlabTemplateID as resultDefaultTemplateID,
|
|
Nonlab_TemplateResultM_DoctorID as resultDefaultDoctorID
|
|
FROM nonlab_template_result
|
|
WHERE Nonlab_TemplateResultIsActive = 'Y'
|
|
AND (Nonlab_TemplateResultM_DoctorID = ? OR Nonlab_TemplateResultM_DoctorID = 0)
|
|
AND Nonlab_TemplateResultNonlabTemplateID = ?
|
|
ORDER BY Nonlab_TemplateResultID DESC";
|
|
|
|
$query = $this->db_onedev->query($sql, array($doctor_id, $template_id));
|
|
|
|
if ($query) {
|
|
$rows = $query->result_array();
|
|
|
|
// Ambil detail untuk setiap template
|
|
for ($a = 0; $a < count($rows); $a++) {
|
|
$sql_detail = "SELECT
|
|
NonlabTemplateResultDetailID as resultDefaultDetailID,
|
|
NonlabTemplateResultDetailNonlab_TemplateResultID,
|
|
NonlabTemplateResultDetailNonlabTemplateDetailID AS resultDefaultDetailNonlabtemplateDetailID,
|
|
NonlabTemplateResultDetailResult as resultDefaultDetailResult
|
|
FROM nonlab_template_result_detail
|
|
WHERE NonlabTemplateResultDetailNonlab_TemplateResultID = '{$rows[$a]['resultDefaultID']}'
|
|
AND NonlabTemplateResultDetailIsActive = 'Y'";
|
|
$qry_detail = $this->db_onedev->query($sql_detail);
|
|
if ($qry_detail) {
|
|
$rows[$a]['detail'] = $qry_detail->result_array();
|
|
}
|
|
}
|
|
|
|
$result = array("total" => count($rows), "records" => $rows);
|
|
$this->sys_ok($result);
|
|
} else {
|
|
$this->sys_error_db("Error getting doctor templates", $this->db_onedev);
|
|
exit;
|
|
}
|
|
} catch (Exception $e) {
|
|
$this->sys_error($e->getMessage());
|
|
}
|
|
}
|
|
|
|
public function searchdoctor()
|
|
{
|
|
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_doctor
|
|
WHERE
|
|
M_DoctorName like ?
|
|
AND M_DoctorIsActive = '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_doctor count", $this->db_onedev);
|
|
exit;
|
|
}
|
|
|
|
$sql = "
|
|
SELECT * FROM(
|
|
SELECT 0 as M_DoctorID, 'Semua Dokter' as M_DoctorName, 'Semua Dokter' as M_DoctorNames
|
|
UNION
|
|
SELECT M_DoctorID, M_DoctorName, CONCAT(IFNULL(M_DoctorPrefix,''),IFNULL(M_DoctorPrefix2,''),' ',M_DoctorName,' ',IFNULL(M_DoctorSufix,''),IFNULL(M_DoctorSufix2,''),IFNULL(M_DoctorSufix3,'')) as M_DoctorNames
|
|
FROM m_doctor
|
|
WHERE M_DoctorIsActive = 'Y') a
|
|
WHERE
|
|
M_DoctorNames like ?
|
|
ORDER BY M_DoctorName 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_doctor rows", $this->db_onedev);
|
|
exit;
|
|
}
|
|
}
|
|
|
|
|
|
function gettemplates()
|
|
{
|
|
if (!$this->isLogin) {
|
|
$this->sys_error("Invalid Token");
|
|
exit;
|
|
}
|
|
$prm = $this->sys_input;
|
|
$userid = $this->sys_user["M_UserID"];
|
|
$doctorid = isset($prm['doctor_id']) ? $prm['doctor_id'] : 0;
|
|
$nat_testid = isset($prm['nat_testid']) ? $prm['nat_testid'] : 0;
|
|
$template_id = isset($prm['template_id']) ? $prm['template_id'] : 0;
|
|
|
|
if ($nat_testid == 0 || $template_id == 0) {
|
|
echo $this->sys_error("Invalid Parameter Nat Test ID or Template ID");
|
|
exit;
|
|
}
|
|
$query = "SELECT
|
|
Nonlab_TemplateResultID as id,
|
|
Nonlab_TemplateResultName as label,
|
|
'' as details
|
|
FROM nonlab_template_result
|
|
WHERE
|
|
( Nonlab_TemplateResultM_DoctorID = ? OR Nonlab_TemplateResultM_DoctorID = 0) AND
|
|
Nonlab_TemplateResultNat_TestID = ? AND
|
|
Nonlab_TemplateResultNonlabTemplateID = ? AND
|
|
Nonlab_TemplateResultIsActive = 'Y' ";
|
|
//echo $query;
|
|
$query = $this->db_onedev->query($query, array($doctorid, $nat_testid, $template_id));
|
|
//echo $this->db_onedev->last_query();
|
|
if (!$query) {
|
|
$message = $this->db_onedev->error();
|
|
$message['qry'] = $this->db_onedev->last_query();
|
|
$this->sys_error($message);
|
|
exit;
|
|
}
|
|
|
|
$rows = $query->result_array();
|
|
if (count($rows) > 0) {
|
|
foreach ($rows as $k => $v) {
|
|
$sql = "SELECT NonlabTemplateResultDetailNonlabTemplateDetailID as template_detail_id,
|
|
NonlabTemplateResultDetailResult as value
|
|
FROM nonlab_template_result_detail
|
|
WHERE NonlabTemplateResultDetailNonlab_TemplateResultID = {$v['id']} AND
|
|
NonlabTemplateResultDetailIsActive = 'Y'";
|
|
$query = $this->db_onedev->query($sql);
|
|
if (!$query) {
|
|
$message = $this->db_onedev->error();
|
|
$message['qry'] = $this->db_onedev->last_query();
|
|
$this->sys_error($message);
|
|
exit;
|
|
}
|
|
$rows[$k]['details'] = $query->result_array();
|
|
}
|
|
}
|
|
$result = array(
|
|
"total" => count($rows),
|
|
"records" => $rows
|
|
);
|
|
|
|
$this->sys_ok($result);
|
|
exit;
|
|
}
|
|
|
|
/**
|
|
* Fungsi untuk mengambil detail transaksi result entry
|
|
* Dipanggil ketika user klik selectMe/select_transaction di frontend
|
|
*/
|
|
function get_detail()
|
|
{
|
|
if (!$this->isLogin) {
|
|
$this->sys_error("Invalid Token");
|
|
exit;
|
|
}
|
|
|
|
$prm = $this->sys_input;
|
|
$trx_id = isset($prm['trx_id']) ? $prm['trx_id'] : 0;
|
|
$typeresult = isset($prm['typeresult']) ? $prm['typeresult'] : 'Rontgen';
|
|
|
|
if ($trx_id == 0) {
|
|
$this->sys_error("Parameter trx_id is required");
|
|
exit;
|
|
}
|
|
|
|
// Log untuk debugging
|
|
error_log("get_detail called with trx_id: " . $trx_id . ", typeresult: " . $typeresult);
|
|
|
|
$rst_details = array();
|
|
$arr_status = array();
|
|
|
|
try {
|
|
$sql = "SELECT
|
|
So_ResultEntryID as trx_id,
|
|
T_OrderDetailT_OrderHeaderID as orderid,
|
|
T_OrderHeaderM_PatientID as patientid,
|
|
T_TestT_SampleTypeID as sampletypeid,
|
|
UPPER(T_TestName) as test_name,
|
|
T_TestNat_TestID as nat_testid,
|
|
T_TestID as test_id,
|
|
'' as language_id,
|
|
So_ResultEntryNonlab_TemplateID as template_id,
|
|
'' as status_result,
|
|
'' as status_result_arr,
|
|
CASE
|
|
WHEN So_ResultEntryStatus = 'NEW' THEN 'BARU'
|
|
WHEN So_ResultEntryStatus = 'VAL1' THEN 'VALIDASI 1'
|
|
WHEN So_ResultEntryStatus = 'VAL2' THEN 'VALIDASI 2'
|
|
END as status_name,
|
|
CASE
|
|
WHEN So_ResultEntryStatus = 'NEW' THEN 'BARU'
|
|
WHEN So_ResultEntryStatus = 'VAL1' AND T_OrderDetailPrintCount = 0 THEN 'VALIDASI 1'
|
|
WHEN So_ResultEntryStatus = 'VAL2' THEN 'VALIDASI 2'
|
|
WHEN T_OrderDetailPrintCount <> 0 THEN 'PRINTED'
|
|
END as status_header,
|
|
Group_ResultName as type,
|
|
'' as langs,
|
|
So_ResultEntryStatus as status,
|
|
'' as language_name,
|
|
IFNULL(M_DoctorID,0) as doctor_id,
|
|
CONCAT(IFNULL(M_DoctorPrefix,''),' ',IFNULL(M_DoctorPrefix2,''), ' ', IFNULL(M_DoctorName,''), ' ',IFNULL(M_DoctorSufix,''),' ', IFNULL(M_DoctorSufix2,''), ' ') as doctor_fullname,
|
|
'' as details,
|
|
'' as photos
|
|
FROM so_resultentry
|
|
JOIN t_orderdetail ON So_ResultEntryT_OrderDetailID = T_OrderDetailID AND
|
|
T_OrderDetailIsActive = 'Y' AND
|
|
So_ResultEntryT_OrderHeaderID = {$trx_id} AND
|
|
So_ResultEntryIsActive = 'Y'
|
|
JOIN t_test ON T_OrderDetailT_TestID = T_TestID
|
|
JOIN group_resultdetail ON Group_ResultDetailT_TestID = T_TestID AND
|
|
Group_ResultDetailIsActive = 'Y'
|
|
JOIN group_result ON Group_ResultDetailGroup_ResultID = Group_ResultID
|
|
AND Group_ResultName = '{$typeresult}'
|
|
JOIN t_orderheader ON So_ResultEntryT_OrderHeaderID = T_OrderHeaderID
|
|
LEFT JOIN m_doctor ON So_ResultEntryM_DoctorID = M_DoctorID
|
|
JOIN t_samplingso ON T_SamplingSoT_OrderHeaderID = T_OrderDetailT_OrderHeaderID AND T_SamplingSoT_TestID = T_TestID
|
|
GROUP BY So_ResultEntryID";
|
|
|
|
error_log("get_detail SQL: " . $sql);
|
|
|
|
$query_rst = $this->db_onedev->query($sql);
|
|
|
|
// Check for query error
|
|
if ($query_rst === FALSE) {
|
|
$message = $this->db_onedev->error();
|
|
$message['qry'] = $this->db_onedev->last_query();
|
|
$this->sys_error($message);
|
|
exit;
|
|
}
|
|
|
|
$rst_details = $query_rst->result_array();
|
|
|
|
// If no results found, return empty but valid response
|
|
if (empty($rst_details)) {
|
|
$result = array(
|
|
"total" => 0,
|
|
"records" => array(
|
|
"details" => array(),
|
|
"deliveries" => "",
|
|
"status" => array()
|
|
)
|
|
);
|
|
$this->sys_ok($result);
|
|
exit;
|
|
}
|
|
|
|
foreach ($rst_details as $ki => $vi) {
|
|
array_push($arr_status, $vi['status_header']);
|
|
$xstatus_result = array();
|
|
|
|
// Get status result
|
|
$sql = "SELECT NonlabConclusionDetailID as id, NonlabConclusionDetailName as name, NonlabConclusionDetailIsNormal AS isNormal
|
|
FROM so_resultentry_category_result
|
|
JOIN nonlab_conclusion_detail ON So_ResultEntryCategoryNonlabConclusionDetailID = NonlabConclusionDetailID AND
|
|
NonlabConclusionDetailIsActive = 'Y'
|
|
WHERE
|
|
So_ResultEntryCategoryResultSo_ResultEntryID = {$vi['trx_id']} AND
|
|
So_ResultEntryCategoryResultIsActive = 'Y'
|
|
";
|
|
$get_status_result = $this->db_onedev->query($sql)->result_array();
|
|
if ($get_status_result) {
|
|
$xstatus_result = $get_status_result;
|
|
}
|
|
|
|
$rst_details[$ki]['status_result'] = $xstatus_result;
|
|
|
|
// Get status result array
|
|
$sql = "SELECT NonlabConclusionDetailID AS id, NonlabConclusionDetailName as name, NonlabConclusionDetailIsNormal AS isNormal
|
|
FROM nonlab_conclusion_detail d1
|
|
JOIN (SELECT * FROM nonlab_conclusion WHERE NonlabConclusionIsActive = 'Y' LIMIT 1) d2
|
|
ON d1.NonlabConclusionDetailNonlabConclusionID = d2.NonlabConclusionID";
|
|
$data_status_result_array = $this->db_onedev->query($sql)->result_array();
|
|
|
|
$sql = "SELECT NonlabConclusionDetailID AS id , NonlabConclusionDetailName as name, NonlabConclusionDetailIsNormal AS isNormal
|
|
FROM nonlab_conclusion_mapping
|
|
JOIN nonlab_conclusion_detail ON NonlabConclusionMappingNonlabConclusionID = NonlabConclusionDetailNonlabConclusionID AND NonlabConclusionDetailIsActive ='Y'
|
|
JOIN nonlab_conclusion ON NonlabConclusionMappingNonlabConclusionID = NonlabConclusionID AND NonlabConclusionIsActive = 'Y'
|
|
WHERE NonlabConclusionMappingNat_TestID = {$vi['nat_testid']}";
|
|
$data_status_result_array_other = $this->db_onedev->query($sql)->result_array();
|
|
if ($data_status_result_array_other) {
|
|
$data_status_result_array = $data_status_result_array_other;
|
|
}
|
|
|
|
$rst_details[$ki]['status_result_arr'] = $data_status_result_array;
|
|
$rst_details[$ki]['status_result'] = $xstatus_result;
|
|
|
|
// Get result entry details
|
|
$sql = "SELECT
|
|
So_ResultEntryDetailID as trx_id,
|
|
So_ResultEntryDetailNonlab_TemplateDetailID as template_detail_id,
|
|
So_ResultEntryDetailNonlab_TemplateDetailName as result_label,
|
|
So_ResultEntryDetailResult as result_value,
|
|
So_ResultEntryDetailFlagPrint as flag_print,
|
|
So_ResultEntryDetailResult as result_value_before
|
|
FROM so_resultentrydetail
|
|
JOIN nonlab_template_detail ON So_ResultEntryDetailNonlab_TemplateDetailID = NonlabTemplateDetailID
|
|
WHERE
|
|
So_ResultEntryDetailSo_ResultEntryID = {$vi['trx_id']} AND So_ResultEntryDetailisActive = 'Y'
|
|
ORDER BY NonlabTemplateDetailCode ASC
|
|
";
|
|
$query_details = $this->db_onedev->query($sql);
|
|
|
|
// Check for query error (not empty result)
|
|
if ($query_details === FALSE) {
|
|
$message = $this->db_onedev->error();
|
|
$message['qry'] = $this->db_onedev->last_query();
|
|
$this->sys_error($message);
|
|
exit;
|
|
}
|
|
|
|
$rst_details[$ki]['details'] = $query_details->result_array();
|
|
$rst_details[$ki]['langs'] = "";
|
|
$rst_details[$ki]['photos'] = "";
|
|
}
|
|
|
|
// Get deliveries
|
|
$deliveries = $this->getdeliveries($trx_id, $typeresult);
|
|
|
|
$result = array(
|
|
"total" => 1,
|
|
"records" => array(
|
|
"details" => $rst_details,
|
|
"deliveries" => $deliveries,
|
|
"status" => $arr_status
|
|
)
|
|
);
|
|
|
|
$this->sys_ok($result);
|
|
exit;
|
|
} catch (Exception $e) {
|
|
error_log("get_detail exception: " . $e->getMessage());
|
|
$this->sys_error("Error: " . $e->getMessage());
|
|
exit;
|
|
}
|
|
}
|
|
|
|
function getdeliverybyorder()
|
|
{
|
|
if (!$this->isLogin) {
|
|
$this->sys_error("Invalid Token");
|
|
exit;
|
|
}
|
|
$prm = $this->sys_input;
|
|
$orderid = isset($prm['orderid']) ? $prm['orderid'] : 0;
|
|
|
|
$sql = "SELECT
|
|
md.M_DeliveryName,
|
|
mdt.M_DeliveryTypeID,
|
|
mdt.M_DeliveryTypeCode
|
|
FROM t_orderdelivery tod
|
|
JOIN m_delivery md
|
|
ON md.M_DeliveryID = tod.T_OrderDeliveryM_DeliveryID
|
|
JOIN m_deliverytype mdt
|
|
ON mdt.M_DeliveryTypeID = md.M_DeliveryM_DeliveryTypeID
|
|
WHERE tod.T_OrderDeliveryT_OrderHeaderID = ?";
|
|
|
|
$rows = $this->db_onedev->query($sql, array($orderid))->result_array();
|
|
|
|
$result = array("total" => count($rows), "records" => $rows);
|
|
$this->sys_ok($result);
|
|
exit;
|
|
}
|
|
|
|
function get_report_url_by_code()
|
|
{
|
|
if (!$this->isLogin) {
|
|
$this->sys_error("Invalid Token");
|
|
return;
|
|
}
|
|
|
|
$prm = $this->sys_input;
|
|
$report_code = isset($prm['code']) ? $prm['code'] : '';
|
|
$params = isset($prm['params']) ? $prm['params'] : [];
|
|
|
|
if (empty($report_code)) {
|
|
$this->sys_error("Report code is required");
|
|
return;
|
|
}
|
|
|
|
$sql = "SELECT * FROM print_transaction WHERE Print_TransactionCode = ? LIMIT 1";
|
|
$row = $this->db_onedev->query($sql, [$report_code])->row_array();
|
|
|
|
if (!$row) {
|
|
$this->sys_error("Report code not found: " . $report_code);
|
|
return;
|
|
}
|
|
|
|
$final_url = $row['Print_TransactionUrl'];
|
|
|
|
// Jika params tidak diberikan, gunakan default
|
|
if (empty($params) || !is_array($params)) {
|
|
$params = [
|
|
'PUsername' => urlencode($this->sys_user['M_StaffName']),
|
|
'PT_OrderHeaderID' => '0',
|
|
'TS' => round(microtime(true) * 1000)
|
|
];
|
|
}
|
|
|
|
// Replace parameters in URL
|
|
foreach ($params as $key => $value) {
|
|
$final_url = str_replace($key, $value, $final_url);
|
|
}
|
|
|
|
$this->sys_ok([
|
|
'status' => true,
|
|
'url' => $final_url,
|
|
'report_code' => $report_code,
|
|
'original_url' => $row['Print_TransactionUrl']
|
|
]);
|
|
}
|
|
}
|