db_onedev = $this->load->database("onedev", true); $this->load->helper(array('form', 'url')); $this->load->library('Nonlabtemplate'); $this->load->library("Soresultlog"); } 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 .'; '; $rows = $this->db_onedev->query($query)->result_array(); //echo $this->db_onedev->last_query(); $rst = ''; foreach ($rows as $k => $v) { if ($rst != '') $rst .= ", "; $rows[$k]['url'] = array(); 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; $status_payment = $this->db_onedev->query($sql)->row()->xpayment; $rows[$k]['status_payment'] = $status_payment; if ($status_payment == 'Y') { $xtype = $typeresult; if ($typeresult == 'xray') $xtype = 'Rontgen'; if ($typeresult == 'bdm') $xtype = 'BMD'; $sql = "SELECT t_email_nonlab.*, T_OrderDetailT_TestName as test_name FROM t_email_nonlab LEFT JOIN so_resultentry ON T_EmailNonLabResultEntryID = So_ResultEntryID LEFT JOIN t_orderdetail ON So_ResultEntryT_OrderDetailID = T_OrderDetailID WHERE T_EmailNonLabT_OrderHeaderID = {$orderid} AND T_EmailNonLabType = '{$xtype}'"; $row_format = $this->db_onedev->query($sql)->result_array(); if ($row_format) { $format = array(); $url = array(); foreach ($row_format as $k_f => $v_f) { array_push($format, $v_f['T_EmailNonLabFormat']); $xurl = array('test' => $v_f['test_name'], 'url' => $v_f['T_EmailNonLabUrl']); array_push($url, $xurl); } $join_format = join(",", $format); $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 CorporateID <> {$companyid}"; if (($companyid != 0 || $companyid != '0') && !$prm["switch_exclude"]) { $filter_company = " AND T_OrderHeaderCorporateID = {$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, CorporateID 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 = 'D' $filter_date AND T_SamplingSoT_TestID = T_TestID JOIN m_patient ON T_OrderHeaderM_PatientID = M_PatientID $sql_where JOIN corporate ON T_OrderHeaderCorporateID = CorporateID $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_DoctorSuffix,' ', M_DoctorSuffix2, ' ') doctorName, T_OrderHeaderLabNumber as ordernumber, UPPER(CONCAT(IFNULL(M_TitleName,''),' ',M_PatientName)) as patient_fullname, CASE WHEN UPPER(M_PatientGender) = 'MALE' THEN 'LAKI - LAKI' WHEN UPPER(M_PatientGender) = 'FEMALE' THEN 'PEREMPUAN' END 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, CorporateID as company_id, UPPER(CorporateName) 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 = 'D' $filter_date AND T_SamplingSoT_TestID = T_TestID JOIN m_patient ON T_OrderHeaderM_PatientID = M_PatientID $sql_where JOIN corporate ON T_OrderHeaderCorporateID = CorporateID $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); 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) { // 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']; $rows[$k]['re_id'] = $v['re_id']; $v['status_name'] = 'NEW'; $rows[$k]['status_name'] = $v['status_name']; } } $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_DoctorSuffix,' ', M_DoctorSuffix2, ' ') 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 = {$v['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 JOIN mgm_mcu ON T_OrderHeaderMgm_McuID = Mgm_McuID 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 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(); $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; $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; //$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 JOIN nonlab_template_detail ON So_ResultEntryDetailNonlab_TemplateDetailID = NonlabTemplateDetailID WHERE So_ResultEntryDetailSo_ResultEntryID = {$vi['trx_id']} AND So_ResultEntryDetailisActive = 'Y' ORDER BY NonlabTemplateDetailCode ASC "; //echo $sql; $rst_details[$ki]['details'] = $this->db_onedev->query($sql)->result_array(); if (!$rst_details[$ki]['details']) { echo "IN"; $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) { //echo "IN 2"; $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) { //echo "IN 3"; $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; // print_r($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; } } //$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 CorporateID AS id, CorporateName as name FROM corporate WHERE CorporateName LIKE ? AND CorporateIsActive = 'Y' ORDER BY CorporateName 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 getattachments() { if (!$this->isLogin) { $this->sys_error("Invalid Token"); exit; } $prm = $this->sys_input; $rows = []; $t_sampling_so_id = $prm['T_SamplingSOID']; $query = " SELECT * FROM `t_nonlabdocument` JOIN t_orderheader ON T_NonlabDocumentT_OrderHeaderID = T_OrderHeaderID JOIN m_patient ON T_OrderHeaderM_PatientID = M_PatientID WHERE `T_NonlabDocumentT_SamplingSoID` = ? AND `T_NonlabDocumentIsActive` = 'Y' ORDER BY `T_NonlabDocumentID` DESC"; //echo $query; $rst = $this->db_onedev->query($query, [$t_sampling_so_id])->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 = "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; } //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(); } // } 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)->row_array(); $sql = "SELECT * FROM so_resultentrydetail WHERE So_ResultEntryDetailSo_ResultEntryID = {$last_id}"; $data_log_details = $this->db_onedev->query($sql)->result_array(); // $sql = "SELECT * FROM so_resultentrydetail_other WHERE So_ResultEntryDetailOtherSo_ResultEntryID = {$last_id}"; // $data_log_other_details = $this->db_onedev->query($sql)->result(); // if (!$data_log_other_details) { // $message = $this->db_onedev->error(); // $message['qry'] = $this->db_onedev->last_query(); // $this->sys_error($message); // exit; // } // $data_log = json_encode(array('header' => $data_log_header, 'details' => $data_log_details, 'details_other' => $data_log_other_details)); $act = "UPDATE_ACT"; if ($prm['act'] === 'val1') $act = "VALIDATION"; if ($prm['act'] === 'unval1') $act = "UNVALIDATION"; $this->soresultlog->step_action($act, $last_id, $userid); $data_log = json_encode(array('header' => $data_log_header, 'details' => $data_log_details)); $this->soresultlog->log_result($data_log, $last_id, $userid); $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['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_DoctorSuffix, M_DoctorSuffix2, M_DoctorCode , CONCAT(M_DoctorPrefix,' ',M_DoctorPrefix2, ' ', M_DoctorName, ' ',M_DoctorSuffix,' ', M_DoctorSuffix2, ' ') doctorName FROM m_doctor WHERE M_DoctorIsActive = 'Y' AND CONCAT(M_DoctorPrefix,' ',M_DoctorPrefix2, ' ', M_DoctorName, ' ',M_DoctorSuffix,' ', M_DoctorSuffix2, ' ') 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, CorporateID 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 corporate ON T_OrderHeaderCorporateID = CorporateID 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_DoctorSuffix,' ', M_DoctorSuffix2, ' ') doctorName, T_OrderHeaderLabNumber as ordernumber, UPPER(CONCAT(M_TitleName,' ',M_PatientName)) as patient_fullname, CASE WHEN UPPER(M_PatientGender) = 'MALE' THEN 'LAKI - LAKI' WHEN UPPER(M_PatientGender) = 'FEMALE' THEN 'PEREMPUAN' END 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, CorporateID as company_id, UPPER(CorporateName) 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 corporate ON T_OrderHeaderCorporateID = CorporateID 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_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_DoctorSuffix,' ', M_DoctorSuffix2, ' ') 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 = '{$vi['doctorID']}' 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_MenuID = 459"; $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; } }