431 lines
19 KiB
PHP
431 lines
19 KiB
PHP
<?php
|
|
class Histerimahasil extends MY_Controller
|
|
{
|
|
var $db;
|
|
|
|
public function index()
|
|
{
|
|
echo "HIS TERIMA HASIL";
|
|
}
|
|
|
|
public function __construct()
|
|
{
|
|
parent::__construct();
|
|
}
|
|
|
|
function get_result_patient($id)
|
|
{
|
|
try {
|
|
$sql_header = "SELECT
|
|
concat(M_TitleName, ' ',
|
|
ifnull(M_PatientPrefix,' '),
|
|
M_PatientName,
|
|
ifnull(M_PatientSuffix,'')
|
|
)
|
|
as PatientFullName,
|
|
M_PatientM_SexID,
|
|
IFNULL(DATE_FORMAT(M_PatientDOB,'%Y%m%d'),'') as M_PatientDOB,
|
|
fn_get_doctor_fullname(M_DoctorID) as M_DoctorFullName,
|
|
M_DoctorCode,
|
|
IFNULL(T_OrderHeaderLabNumberExt,'') as T_OrderHeaderLabNumberExt,
|
|
IFNULL(T_OrderHeaderLabNumber,'') as T_OrderHeaderLabNumber,
|
|
IFNULL(DATE_FORMAT(T_OrderHeaderDate,'%d-%m-%Y %H:%i:%s'),'') as T_OrderHeaderDate,
|
|
IFNULL(T_OrderHeaderID,'') as T_OrderHeaderID,
|
|
IFNULL(T_OrderHeaderSenderM_DoctorID,'') as T_OrderHeaderSenderM_DoctorID,
|
|
'' as M_BranchID,
|
|
'' as M_BranchCode,
|
|
T_OrderHeaderHisMedRec as medRec,
|
|
T_OrderHeaderHisSourceCode as sourceCode,
|
|
T_OrderHeaderHisSourceName as sourceName,
|
|
T_OrderHeaderHisSourceRoomNumber as sourceRoomNumber
|
|
from t_orderheader
|
|
JOIN t_orderheader_his
|
|
ON T_OrderHeaderLabNumberExt = T_OrderHeaderHisRegLab
|
|
AND T_OrderHeaderHisIsActive = 'Y'
|
|
join m_patient on T_OrderHeaderID = ?
|
|
and T_OrderHeaderM_PatientID = M_PatientID
|
|
join m_title on M_PatientM_TitleID = M_TitleID
|
|
join m_doctor
|
|
ON T_OrderHeaderSenderM_DoctorID = M_DoctorID
|
|
AND M_DoctorIsActive = 'Y'";
|
|
|
|
$query_header = $this->db->query($sql_header, [
|
|
$id
|
|
]);
|
|
if (!$query_header) {
|
|
$this->sys_error_db("get header failed", $this->db);
|
|
exit;
|
|
}
|
|
|
|
$rows_header = $query_header->result_array();
|
|
if (count($rows_header) == 0) {
|
|
$this->sys_error('Header Tidak Ditemukan');
|
|
exit;
|
|
}
|
|
|
|
$r_header = $rows_header[0];
|
|
|
|
// pemeriksaan atau test
|
|
// query detail periksa
|
|
$sql_detail_periksa = "SELECT
|
|
T_OrderHeaderID,
|
|
T_OrderDetailID,
|
|
T_TestT_SampleTypeID,
|
|
IFNULL(T_TestSasCode,'') as test_cd,
|
|
IFNULL(T_TestName,'') as test_nm,
|
|
'' as data_type,
|
|
IFNULL(T_OrderDetailResult,'') as result_value,
|
|
IFNULL(T_OrderDetailNat_UnitName,'') as unit,
|
|
IFNULL(T_OrderDetailResultFlag,'') as flag,
|
|
IFNULL(T_OrderDetailNormalValueNote,'') as ref_range,
|
|
'' as status,
|
|
'' as test_comment,
|
|
T_OrderDetailT_TestID as order_testid,
|
|
T_OrderDetailT_TestName as order_testnm,
|
|
IFNULL(Nat_SubGroupName,'') as test_group,
|
|
'' as item_parent,
|
|
IFNULL(T_TestSasCode,'') as T_TestSasCode,
|
|
IFNULL(Nat_SubGroupName,'') as Nat_SubGroupName,
|
|
IFNULL(Nat_SubSubGroupName,'') as Nat_SubSubGroupName,
|
|
IFNULL(T_TestName,'') as T_TestName,
|
|
IFNULL(T_OrderDetailT_TestName,'') as T_OrderDetailT_TestName,
|
|
if(fn_itf_isnumber(T_OrderDetailResult) = '0', T_OrderDetailResult , fn_rpt_format_number(T_OrderDetailResult) ) as T_OrderDetailResult,
|
|
IFNULL(T_OrderDetailNat_UnitName,'') as T_OrderDetailNat_UnitName,
|
|
IFNULL(T_OrderDetailNormalValueNote,'') as T_OrderDetailNormalValueNote,
|
|
IFNULL(T_OrderdetailNat_MethodeName,'') as T_OrderdetailNat_MethodeName,
|
|
T_OrderDetailT_TestID,
|
|
IFNULL(T_TestIsPrintResult,'') as T_TestIsPrintResult,
|
|
IFNULL(T_TestIsResult,'') as T_TestIsResult,
|
|
IFNULL(T_OrderDetailValidation,'') as T_OrderDetailValidation,
|
|
T_TestID,
|
|
T_OrderDetailResultFlag
|
|
from t_orderheader
|
|
join m_patient
|
|
on T_OrderHeaderID = ?
|
|
and T_OrderHeaderM_PatientID = M_PatientID
|
|
join m_title
|
|
on M_PatientM_TitleID = M_TitleID
|
|
join t_orderdetail
|
|
ON T_OrderHeaderID = T_OrderDetailT_OrderHeaderID
|
|
AND T_OrderDetailIsActive = 'Y'
|
|
join t_test
|
|
ON T_OrderDetailT_TestID = T_TestID
|
|
AND T_TestIsActive = 'Y'
|
|
join nat_test
|
|
ON T_TestNat_TestID = Nat_TestID
|
|
join nat_group
|
|
ON Nat_TestNat_GroupID = Nat_GroupID
|
|
AND Nat_GroupIsActive = 'Y'
|
|
join nat_subgroup
|
|
ON Nat_TestNat_SubgroupID = Nat_SubGroupID
|
|
AND Nat_SubGroupIsActive = 'Y'
|
|
join nat_subsubgroup
|
|
ON Nat_TestNat_SubSubGroupID = Nat_SubSubGroupID
|
|
AND Nat_SubSubGroupIsActive = 'Y'
|
|
where T_OrderHeaderIsActive = 'Y'
|
|
order by T_TestSasCode asc";
|
|
|
|
$query_detail_periksa = $this->db->query($sql_detail_periksa, [
|
|
$id
|
|
]);
|
|
if (!$query_detail_periksa) {
|
|
$message = $this->db->error();
|
|
$this->sys_error($message);
|
|
exit;
|
|
}
|
|
|
|
$rows = $query_detail_periksa->result_array();
|
|
|
|
$data_detail = [];
|
|
foreach ($rows as $key => $r) {
|
|
$xid = $r['T_OrderHeaderID'] . "-" . $r['T_TestT_SampleTypeID'];
|
|
|
|
// if(in_array())
|
|
$detailID = $r['T_OrderDetailID'];
|
|
$data_detail[] = [
|
|
'test_cd' => $r['T_TestSasCode'],
|
|
'test_nm' => $r['T_TestName'],
|
|
'data_type' => $r['data_type'],
|
|
'result_value' => $r['T_OrderDetailResult'],
|
|
'unit' => $r['T_OrderDetailNat_UnitName'],
|
|
'flag' => $r['T_OrderDetailResultFlag'],
|
|
'ref_range' => $r['T_OrderDetailNormalValueNote'],
|
|
'status' => $r['status'],
|
|
'test_comment' => $r['test_comment'],
|
|
"disp_seq" => '',
|
|
"order_testid" => $r['order_testid'],
|
|
"order_testnm" => $r['order_testnm'],
|
|
"test_group" => $r['Nat_SubGroupName'],
|
|
"item_parent" => null,
|
|
"spesimen" => $this->get_sample($id, $r['T_TestID']),
|
|
"release" => $this->get_release($detailID),
|
|
"authorise" => $this->get_authorize($detailID),
|
|
"phoned" => $this->get_phoned($detailID),
|
|
"his_code" => $this->get_his_code($detailID)
|
|
];
|
|
}
|
|
|
|
|
|
if (count($rows_header) == 0) {
|
|
echo json_encode(
|
|
array(
|
|
"order_patient_id" => 0,
|
|
"patient" => [],
|
|
"result" => [],
|
|
"sample" => []
|
|
)
|
|
);
|
|
} else {
|
|
$arrResult = array(
|
|
"reglab" => $r_header['T_OrderHeaderLabNumber'],
|
|
"medrec" => $r_header['medRec'],
|
|
"name" => $rows_header[0]['PatientFullName'],
|
|
"birt_dt" => $rows_header[0]['M_PatientDOB'],
|
|
"sex" => $rows_header[0]['M_PatientM_SexID'],
|
|
"source" => [
|
|
"code" => $rows_header[0]['sourceCode'],
|
|
"name" => $rows_header[0]['sourceName'],
|
|
"room_no" => $rows_header[0]['sourceRoomNumber']
|
|
],
|
|
"clinican" => [
|
|
"code" => $rows_header[0]['M_DoctorCode'],
|
|
"name" => $rows_header[0]['M_DoctorFullName']
|
|
],
|
|
"comment" => "",
|
|
"detail" => $data_detail,
|
|
|
|
);
|
|
// echo json_encode(
|
|
// $arrResult
|
|
// );
|
|
$this->sys_ok($arrResult);
|
|
}
|
|
} catch (Exception $exc) {
|
|
$message = $exc->getMessage();
|
|
$this->sys_error($message);
|
|
exit;
|
|
}
|
|
}
|
|
|
|
function process()
|
|
{
|
|
try {
|
|
$prm = $this->sys_input;
|
|
$no_lab = isset($prm['no_lab']) && $prm['no_lab'] != '' ? $prm['no_lab'] : '';
|
|
|
|
$sql_t_orderheader = "SELECT T_OrderHeaderID
|
|
FROM t_orderheader
|
|
WHERE T_OrderHeaderLabNumberExt = ?";
|
|
|
|
$qry_t_orderheader = $this->db->query($sql_t_orderheader, [
|
|
$no_lab
|
|
]);
|
|
|
|
if (!$qry_t_orderheader) {
|
|
$this->sys_error_db(["status" => "ERR", "message" => "select m_patient info | " .
|
|
$this->db->error()["message"], "debug" => $this->db->last_query()]);
|
|
exit;
|
|
}
|
|
|
|
$data_t_orderheader = $qry_t_orderheader->result_array();
|
|
if (count($data_t_orderheader) == 0) {
|
|
$this->sys_error('Header Tidak Ditemukan');
|
|
exit;
|
|
}
|
|
|
|
$T_OrderHeaderID = $data_t_orderheader[0]['T_OrderHeaderID'];
|
|
|
|
|
|
$data_patient = $this->get_result_patient($T_OrderHeaderID);
|
|
} catch (Exception $exc) {
|
|
$message = $exc->getMessage();
|
|
$this->sys_error($message);
|
|
exit;
|
|
}
|
|
}
|
|
|
|
function get_sample($T_OrderHeaderID, $testID)
|
|
{
|
|
try {
|
|
// sample
|
|
$sql_sample = "SELECT
|
|
T_OrderSampleT_OrderHeaderID,
|
|
T_SampleTypeID,
|
|
T_OrderSampleT_SampleTypeID,
|
|
IFNULL(T_SampleTypeCode,'') as T_SampleTypeCode,
|
|
IFNULL(T_SampleTypeName,'') as T_SampleTypeName,
|
|
IFNULL(DATE_FORMAT(T_OrderSampleSamplingDate,'%Y%m%d'),'') as T_OrderSampleSamplingDate,
|
|
T_OrderSampleSamplingTime,
|
|
T_OrderSampleSamplingUserID,
|
|
M_UserUsername
|
|
FROM t_test
|
|
JOIN t_ordersample
|
|
ON T_TestT_SampleTypeID = T_OrderSampleT_SampleTypeID
|
|
AND T_OrderSampleIsActive = 'Y'
|
|
AND T_OrderSampleT_OrderHeaderID = ?
|
|
JOIN t_sampletype
|
|
ON T_OrderSampleT_SampleTypeID = T_SampleTypeID
|
|
AND T_SampleTypeIsActive = 'Y'
|
|
JOIN nat_bahan
|
|
ON T_SampleTypeT_BahanID = Nat_BahanID
|
|
AND Nat_BahanIsActive = 'Y'
|
|
JOIN m_user
|
|
ON T_OrderSampleSamplingUserID = M_UserID
|
|
AND M_UserIsActive = 'Y'
|
|
WHERE T_TestIsActive = 'Y'
|
|
AND T_TestID = ?
|
|
ORDER BY T_OrderSampleT_OrderHeaderID, T_SampleTypeID,
|
|
T_OrderSampleSamplingDate, T_OrderSampleSamplingTime desc LIMIT 1";
|
|
|
|
$qry_sample = $this->db->query($sql_sample, [$T_OrderHeaderID, $testID]);
|
|
|
|
if (!$qry_sample) {
|
|
$message = $this->db->error();
|
|
$this->sys_error($message);
|
|
exit;
|
|
}
|
|
|
|
$rows = $qry_sample->row_array();
|
|
$arr_spesimen = [
|
|
"code" => $rows['T_SampleTypeCode'],
|
|
"name" => $rows['T_SampleTypeName'],
|
|
"user_id" => $rows['T_OrderSampleSamplingUserID'],
|
|
"user_name" => $rows['M_UserUsername'],
|
|
"date" => $rows['T_OrderSampleSamplingDate'] . str_replace(":", "", $rows['T_OrderSampleSamplingTime'])
|
|
];
|
|
|
|
|
|
// $output = [];
|
|
// $keys = [];
|
|
|
|
// foreach ($arr_spesimen as $item) {
|
|
// $key = $item['code'] . $item['date'];
|
|
// if (!in_array($key, $keys)) {
|
|
// array_push($output, $item);
|
|
// array_push($keys, $key);
|
|
// }
|
|
// }
|
|
|
|
// echo json_encode($output);
|
|
|
|
return $arr_spesimen;
|
|
} catch (Exception $exc) {
|
|
$message = $exc->getMessage();
|
|
$this->sys_error($message);
|
|
exit;
|
|
}
|
|
}
|
|
|
|
function get_release($orderDetailID)
|
|
{
|
|
try {
|
|
$sql = "SELECT T_OrderDetailVerification,
|
|
T_OrderDetailVerDate,
|
|
T_OrderDetailVerUserID,
|
|
M_UserFullName
|
|
FROM t_orderdetail
|
|
JOIN m_user
|
|
ON T_OrderDetailVerUserID = M_UserID
|
|
AND M_UserIsActive = 'Y'
|
|
WHERE T_OrderDetailID = ?";
|
|
$qry = $this->db->query($sql, [$orderDetailID]);
|
|
|
|
if (!$qry) {
|
|
$this->sys_error_db("Get release error", $this->db);
|
|
exit;
|
|
}
|
|
$result = $qry->row_array();
|
|
return [
|
|
"user_id" => $result['T_OrderDetailVerUserID'],
|
|
"user_name" => $result['M_UserFullName'],
|
|
"date" => str_replace([":", '-', ' '], "", $result['T_OrderDetailVerDate'])
|
|
];
|
|
} catch (Exception $exc) {
|
|
$message = $exc->getMessage();
|
|
$this->sys_error($message);
|
|
exit;
|
|
}
|
|
}
|
|
function get_authorize($orderDetailID)
|
|
{
|
|
try {
|
|
$sql = "SELECT T_OrderDetailValidation,
|
|
T_OrderDetailValDate,
|
|
T_OrderDetailValUserID,
|
|
M_UserFullName
|
|
FROM t_orderdetail
|
|
JOIN m_user
|
|
ON T_OrderDetailValUserID = M_UserID
|
|
AND M_UserIsActive = 'Y'
|
|
WHERE T_OrderDetailID = ?";
|
|
$qry = $this->db->query($sql, [$orderDetailID]);
|
|
|
|
if (!$qry) {
|
|
$this->sys_error_db("Get release error", $this->db);
|
|
exit;
|
|
}
|
|
$result = $qry->row_array();
|
|
return [
|
|
"user_id" => $result['T_OrderDetailValUserID'],
|
|
"user_name" => $result['M_UserFullName'],
|
|
"date" => str_replace([":", '-', ' '], "", $result['T_OrderDetailValDate'])
|
|
];
|
|
} catch (Exception $exc) {
|
|
$message = $exc->getMessage();
|
|
$this->sys_error($message);
|
|
exit;
|
|
}
|
|
}
|
|
function get_phoned($orderDetailID)
|
|
{
|
|
try {
|
|
$sql = "SELECT CriticalValueReportedM_UserID,
|
|
CriticalValueReportedDate,
|
|
M_UserFullName
|
|
FROM critical_value
|
|
JOIN m_user
|
|
ON CriticalValueReportedM_UserID = M_UserID
|
|
AND M_UserIsActive = 'Y'
|
|
WHERE CriticalValueT_OrderDetailID= ?";
|
|
$qry = $this->db->query($sql, [$orderDetailID]);
|
|
|
|
if (!$qry) {
|
|
$this->sys_error_db("Get release error", $this->db);
|
|
exit;
|
|
}
|
|
$result = $qry->row_array();
|
|
return [
|
|
"user_id" => $result['CriticalValueReportedM_UserID'],
|
|
"user_name" => $result['M_UserFullName'],
|
|
"date" => str_replace([":", '-', ' '], "", $result['CriticalValueReportedDate'])
|
|
];
|
|
} catch (Exception $exc) {
|
|
$message = $exc->getMessage();
|
|
$this->sys_error($message);
|
|
exit;
|
|
}
|
|
}
|
|
function get_his_code($orderDetailID)
|
|
{
|
|
try {
|
|
$sql = "SELECT T_OrderDetailT_TestID, service_code,T_OrderDetailID FROM t_orderdetail
|
|
LEFT JOIN one_his.service_test ON T_OrderDetailT_TestID = service_test.T_TestID
|
|
AND service_test.service_testIsActive = 'Y'
|
|
LEFT JOIN one_his.service ON service_test.service_id = service.service_id
|
|
WHERE T_OrderDetailID = ?";
|
|
$qry = $this->db->query($sql, [$orderDetailID]);
|
|
|
|
if (!$qry) {
|
|
$this->sys_error_db("Get his code error", $this->db);
|
|
exit;
|
|
}
|
|
$result = $qry->row_array();
|
|
return $result['service_code'];
|
|
} catch (Exception $exc) {
|
|
$message = $exc->getMessage();
|
|
$this->sys_error($message);
|
|
exit;
|
|
}
|
|
}
|
|
}
|