1201 lines
43 KiB
PHP
1201 lines
43 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'));
|
|
}
|
|
|
|
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 CONCAT(M_DeliveryName)
|
|
WHEN T_OrderDeliveryM_DeliveryID = 2 THEN CONCAT(M_DeliveryName)
|
|
WHEN ( T_OrderDeliveryM_DeliveryID = 7 OR T_OrderDeliveryM_DeliveryID = 9 ) THEN CONCAT(M_DeliveryName)
|
|
WHEN ( T_OrderDeliveryM_DeliveryID = 6 OR T_OrderDeliveryM_DeliveryID = 8 ) THEN CONCAT(M_DeliveryName)
|
|
ELSE
|
|
CONCAT(M_DeliveryName,' ( ',T_OrderDeliveryDestination,' )')
|
|
END as label,
|
|
CASE
|
|
WHEN T_OrderDeliveryM_DeliveryID = 1 THEN ''
|
|
WHEN T_OrderDeliveryM_DeliveryID = 4 THEN M_DoctorAddressDescription
|
|
WHEN T_OrderDeliveryM_DeliveryID = 2 THEN M_PatientAddressDescription
|
|
WHEN ( T_OrderDeliveryM_DeliveryID = 7 OR T_OrderDeliveryM_DeliveryID = 9 ) THEN M_DoctorHP
|
|
WHEN ( T_OrderDeliveryM_DeliveryID = 6 OR T_OrderDeliveryM_DeliveryID = 8 ) THEN M_PatientHP
|
|
ELSE
|
|
T_OrderDeliveryDestination
|
|
END as destination,
|
|
CASE
|
|
WHEN T_OrderDeliveryM_DeliveryID = 4 THEN M_DoctorAddressID
|
|
WHEN T_OrderDeliveryM_DeliveryID = 2 THEN M_PatientAddressID
|
|
ELSE
|
|
0
|
|
END as addressid,
|
|
'pink' as color
|
|
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 .'; ';
|
|
$rows = $this->db_onedev->query($query)->result_array();
|
|
//echo $this->db_onedev->last_query();
|
|
$rst = '';
|
|
foreach($rows as $k => $v){
|
|
if($rst != '')
|
|
$rst .= ", ";
|
|
|
|
if($v['typedeliveryid'] == '3'){
|
|
$xtype = $typeresult;
|
|
if($typeresult == 'xray')
|
|
$xtype = 'Rontgen';
|
|
|
|
|
|
$sql = "SELECT *
|
|
FROM t_email_nonlab
|
|
WHERE
|
|
T_EmailNonLabT_OrderHeaderID = {$orderid} AND T_EmailNonLabType = '{$xtype}'";
|
|
$row_format = $this->db_onedev->query($sql)->row_array();
|
|
if($row_format){
|
|
$rows[$k]['color'] = 'teal';
|
|
$rows[$k]['label'] = $v["label"]." : ".$row_format['T_EmailNonLabFormat'];
|
|
}
|
|
else{
|
|
$rows[$k]['label'] = $v["label"]." : Belum Pilih Format";
|
|
}
|
|
}
|
|
|
|
|
|
$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;
|
|
}
|
|
|
|
$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 = "WHERE company_id <> {$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"]:'xray';
|
|
$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}'";
|
|
$sql_where = "WHERE So_ResultEntryIsActive = 'Y' $filter_date";
|
|
|
|
$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 = " WHERE ( T_OrderHeaderLabNumber like '%$search%' OR T_OrderHeaderLabNumberExt like '%$search%' OR M_PatientName like '%$search%' ) AND So_ResultEntryIsActive = 'Y' $filter_date";
|
|
}
|
|
|
|
|
|
$sql = " SELECT count(*) as total
|
|
FROM (
|
|
SELECT So_ResultEntryID, M_CompanyID as company_id
|
|
FROM so_resultentry
|
|
JOIN t_orderdetail ON So_ResultEntryT_OrderDetailID = T_OrderDetailID
|
|
JOIN t_test ON T_OrderDetailT_TestID = T_TestID
|
|
JOIN t_orderheader ON So_ResultEntryT_OrderHeaderID = T_OrderHeaderID
|
|
JOIN m_company ON T_OrderHeaderM_CompanyID = M_CompanyID $filter_company
|
|
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 m_lang ON So_ResultEntryM_LangID = M_LangID
|
|
JOIN t_orderpromise ON T_OrderDetailT_OrderPromiseID = T_OrderPromiseID
|
|
JOIN t_samplingso ON T_SamplingSoT_OrderHeaderID = T_OrderHeaderID
|
|
JOIN documentation_group_detail ON DocumentationGroupDetailNat_SubGroupID = T_TestNat_SubGroupID
|
|
JOIN documentation_group ON DocumentationGroupDetailDocumentationGroupID = DocumentationGroupID AND DocumentationGroupName = '{$typeresult}'
|
|
$join_group
|
|
$join_subgroup
|
|
$sql_where
|
|
GROUP BY T_OrderHeaderID
|
|
) x
|
|
$filter_company_exclude ";
|
|
//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
|
|
So_ResultEntryID as re_id,
|
|
T_OrderHeaderID as trx_id,
|
|
M_PatientID as patientid,
|
|
T_OrderHeaderLabNumber as ordernumber,
|
|
T_OrderHeaderLabNumberExt as ordernumber_ext,
|
|
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_LangID as language_id,
|
|
M_LangName as languange_name,
|
|
M_CompanyID as company_id,
|
|
UPPER(M_CompanyName) as company_name,
|
|
CONCAT(M_DoctorPrefix,M_DoctorPrefix2,' ',M_DoctorName,' ','...') as doctor_sender,
|
|
'' 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,
|
|
T_OrderHeaderIsCito as iscito,
|
|
IFNULL(T_OrderHeaderFoNote,'') as fo_note,
|
|
fn_getstaffname(T_OrderHeaderFoNoteM_UserID) as fo_note_user,
|
|
IFNULL(T_OrderHeaderVerificationNote,'') as fo_ver_note,
|
|
fn_getstaffname(T_OrderHeaderVerificationNoteM_UserID) 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
|
|
FROM so_resultentry
|
|
JOIN t_orderdetail ON So_ResultEntryT_OrderDetailID = T_OrderDetailID AND T_OrderDetailIsActive = 'Y'
|
|
JOIN t_test ON T_OrderDetailT_TestID = T_TestID
|
|
JOIN t_orderheader ON So_ResultEntryT_OrderHeaderID = T_OrderHeaderID
|
|
LEFT JOIN m_user userfo ON T_OrderHeaderFoNoteM_UserID = userfo.M_UserID
|
|
LEFT JOIN m_user userfover ON T_OrderHeaderVerificationNoteM_UserID = userfover.M_UserID
|
|
LEFT JOIN m_user usersampling ON T_OrderHeaderSamplingNoteM_UserID = usersampling.M_UserID
|
|
JOIN m_company ON T_OrderHeaderM_CompanyID = M_CompanyID $filter_company
|
|
LEFT JOIN m_doctor ON T_OrderHeaderSenderM_DoctorID = M_DoctorID
|
|
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 m_lang ON So_ResultEntryM_LangID = M_LangID
|
|
JOIN t_orderpromise ON T_OrderDetailT_OrderPromiseID = T_OrderPromiseID
|
|
JOIN t_samplingso ON T_SamplingSoT_OrderHeaderID = T_OrderHeaderID
|
|
JOIN documentation_group_detail ON DocumentationGroupDetailNat_SubGroupID = T_TestNat_SubGroupID
|
|
JOIN documentation_group ON DocumentationGroupDetailDocumentationGroupID = DocumentationGroupID AND DocumentationGroupName = '{$typeresult}'
|
|
$join_group
|
|
$join_subgroup
|
|
$sql_where
|
|
GROUP BY T_OrderHeaderID
|
|
ORDER BY iscito DESC,T_OrderHeaderID ASC
|
|
limit $number_limit offset $number_offset
|
|
) x
|
|
$filter_company_exclude";
|
|
//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){
|
|
$arr_status = array();
|
|
|
|
$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_TestID as test_id,
|
|
M_LangID as language_id,
|
|
So_ResultEntrySo_TemplateID as template_id,
|
|
IF(T_OrderHeaderAddOnPatientMcu = 'Y' OR T_OrderHeaderAddOnPatientMcu = 'Y','Y','N') as is_mcu,
|
|
So_ResultEntryIsNormal as status_result,
|
|
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,
|
|
DocumentationGroupName as type,
|
|
'' as langs,
|
|
So_ResultEntryStatus as status,
|
|
M_LangName as language_name,
|
|
IFNULL(M_DoctorID,0) as doctor_id,
|
|
CONCAT(M_DoctorPrefix,M_DoctorPrefix2,' ',M_DoctorName,'...') 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 t_orderheaderaddon ON T_OrderHeaderAddOnT_OrderHeaderID = T_OrderHeaderID
|
|
JOIN m_mou ON T_OrderHeaderM_MouID = M_MouID
|
|
JOIN t_test ON T_OrderDetailT_TestID = T_TestID
|
|
JOIN documentation_group_detail ON DocumentationGroupDetailNat_SubGroupID = T_TestNat_SubGroupID
|
|
JOIN documentation_group ON DocumentationGroupDetailDocumentationGroupID = DocumentationGroupID AND DocumentationGroupName = '{$typeresult}'
|
|
JOIN m_lang ON So_ResultEntryM_LangID = M_LangID
|
|
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_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('id'=>'X','name'=>'Belum ditentukan');
|
|
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');
|
|
}
|
|
$rst_details[$ki]['status_result'] = $xstatus_result;
|
|
$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,
|
|
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'
|
|
ORDER BY So_ResultEntryDetailSo_TemplateDetailPriority ASC";
|
|
//echo $sql;
|
|
$rst_details[$ki]['details'] = $this->db_onedev->query($sql)->result_array();
|
|
$rst_details[$ki]['langs'] = $this->getlangs($vi['orderid']);
|
|
$rst_details[$ki]['photos'] = $this->getphotos($vi['orderid'],$vi['sampletypeid']);
|
|
}
|
|
$rows[$k]['details'] = $rst_details;
|
|
$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;
|
|
}
|
|
}
|
|
|
|
|
|
//$this->_add_address($rows);
|
|
$result = array("total" => $tot_page, "records" => $rows, "sql"=> $this->db_onedev->last_query());
|
|
$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']}%";
|
|
$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;
|
|
}
|
|
$prm = $this->sys_input;
|
|
$userid = $this->sys_user["M_UserID"];
|
|
|
|
if($prm['act'] === 'save'){
|
|
$sql = "UPDATE so_resultentry
|
|
SET
|
|
So_ResultEntryIsNormal = '{$prm['trx']['status_result']['id']}',
|
|
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_ResultEntryIsNormal = '{$prm['trx']['status_result']['id']}',
|
|
So_ResultEntryUserID = {$userid}
|
|
WHERE
|
|
So_ResultEntryID = {$prm['trx']['trx_id']}";
|
|
$this->db_onedev->query($sql);
|
|
//echo $this->db_onedev->last_query();
|
|
$this->broadcast("result-radiodiagnostic-v1");
|
|
}
|
|
|
|
if($prm['act'] === 'unval1'){
|
|
$sql = "UPDATE so_resultentry SET
|
|
So_ResultEntryValidation1 = 'N',
|
|
So_ResultEntryStatus = 'NEW',
|
|
So_ResultEntryIsNormal = '{$prm['trx']['status_result']['id']}',
|
|
So_ResultEntryUserID = {$userid}
|
|
WHERE So_ResultEntryID = {$prm['trx']['trx_id']}";
|
|
$this->db_onedev->query($sql);
|
|
}
|
|
|
|
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);
|
|
}
|
|
}
|
|
}
|
|
|
|
$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_ResultEntryDetailUserID = {$userid}
|
|
WHERE So_ResultEntryDetailID = {$v['trx_id']}";
|
|
$this->db_onedev->query($sql);
|
|
//echo $this->db_onedev->last_query();
|
|
}
|
|
}
|
|
else{
|
|
//echo 2;
|
|
foreach($prm['trx']['details'] as $k => $v){
|
|
if($v['trx_id'] == 0 || $v['trx_id'] === '0'){
|
|
$sql = "SELECT *
|
|
FROM so_templatedetail
|
|
WHERE
|
|
So_TemplateDetailID = {$v['template_detail_id']}";
|
|
$rows_template_detail = $this->db_onedev->query($sql)->row_array();
|
|
$results = str_replace("'", "\\'", $v['result_value']);
|
|
$sql = "
|
|
INSERT so_resultentrydetail_other(
|
|
So_ResultEntryDetailOtherM_LangID,
|
|
So_ResultEntryDetailOtherSo_ResultEntryID,
|
|
So_ResultEntryDetailOtherSo_TemplateDetailID,
|
|
So_ResultEntryDetailOtherSo_TemplateDetailName,
|
|
So_ResultEntryDetailOtherSo_TemplateDetailPriority,
|
|
So_ResultEntryDetailOtherSo_TemplateDetailUnit,
|
|
So_ResultEntryDetailOtherResult,
|
|
So_ResultEntryDetailOtherCreated,
|
|
So_ResultEntryDetailOtherUserID
|
|
)
|
|
VALUES(
|
|
{$prm['trx']['language_id']},
|
|
{$prm['trx']['trx_id']},
|
|
{$v['template_detail_id']},
|
|
'{$rows_template_detail['So_TemplateDetailName']}',
|
|
'{$rows_template_detail['So_TemplateDetailPriority']}',
|
|
'{$rows_template_detail['So_TemplateDetailUnit']}',
|
|
'{$results}',
|
|
NOW(),
|
|
{$userid}
|
|
)
|
|
";
|
|
}
|
|
else{
|
|
$results = str_replace("'", "\\'", $v['result_value']);
|
|
//echo $results;
|
|
$sql = "UPDATE so_resultentrydetail_other SET
|
|
So_ResultEntryDetailOtherResult = '{$results}',
|
|
So_ResultEntryDetailOtherUserID = {$userid}
|
|
WHERE So_ResultEntryDetailOtherID = {$v['trx_id']}";
|
|
//echo $sql;
|
|
}
|
|
$this->db_onedev->query($sql);
|
|
//echo $this->db_onedev->last_query();
|
|
}
|
|
}
|
|
|
|
|
|
|
|
$last_id = $prm['trx']['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();
|
|
$sql = "SELECT * FROM so_resultentrydetail_other WHERE So_ResultEntryDetailOtherSo_ResultEntryID = {$last_id}";
|
|
$data_log_other_details = $this->db_onedev->query($sql)->result();
|
|
|
|
$data_log = json_encode(array('header'=>$data_log_header,'details'=>$data_log_details,'details_other'=>$data_log_other_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')
|
|
);
|
|
$this->sys_ok($result);
|
|
exit;
|
|
}
|
|
|
|
|
|
|
|
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 * FROM so_resultentry WHERE So_ResultEntryID = '{$trx_id}'";
|
|
$orderdetail_id = $this->db_onedev->query($sql)->row()->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);
|
|
$result = array(
|
|
"total" => 1 ,
|
|
"records" => $prm
|
|
);
|
|
$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['selected_trx']['language_id']){
|
|
$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;
|
|
}
|
|
|
|
} |